CapturingPointCloudProvider.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package VisionX::Core
19 * @author David Gonzalez Aguirre (david dot gonzalez at kit dot edu)
20 * @date 2014
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26
27#include <string>
28
30
31using namespace armarx;
32
33namespace visionx
34{
35 // ================================================================== //
36 // == PointCloudProvider ice interface ============================== //
37 // ================================================================== //
38 void
40 {
42 std::unique_lock lock(captureMutex);
43
45 fpsCounter.reset();
47 captureEnabled = true;
48
49 ARMARX_INFO << "Starting point cloud capture with framerate " << frameRate;
50 }
51
52 void
53 CapturingPointCloudProvider::startCaptureForNumFrames(int numFrames, const Ice::Current& c)
54 {
56 std::unique_lock lock(captureMutex);
57
59 fpsCounter.reset();
60 numFramesToCapture = numFrames;
61 captureEnabled = true;
62
63 ARMARX_INFO << "Starting point cloud capture with framerate " << frameRate << " (capture "
64 << numFramesToCapture << " frames)";
65 }
66
67 void
69 {
71 std::unique_lock lock(captureMutex);
72
73 captureEnabled = false;
74 ARMARX_INFO << "Stopping point cloud capture";
76 }
77
78 void
79 CapturingPointCloudProvider::changeFrameRate(float framesPerSecond, const Ice::Current& ctx)
80 {
82 std::unique_lock lock(captureMutex);
83
84 frameRate = framesPerSecond;
85 }
86
87 bool
89 {
90 return captureEnabled;
91 }
92
93 // ================================================================== //
94 // == Component implementation ====================================== //
95 // ====================================t============================== //
96 void
98 {
100 captureEnabled = false;
101 frameRate = getProperty<float>("framerate").getValue();
102
103 if (frameRate > 0)
104 {
105 setPointCloudSyncMode(eFpsSynchronization);
106 }
107 else
108 {
109 ARMARX_INFO << "framerate is zero. ignoring";
110 setPointCloudSyncMode(eCaptureSynchronization);
111 }
112
113
114 // call setup of point clouds provider implementation to setup point clouds size
116
117 // capture task
120 }
121
122 void
124 {
127
128 captureTask->start();
129
130 bool isEnabled = getProperty<bool>("isEnabled").getValue();
131
132 if (isEnabled)
133 {
134 startCapture();
135 }
136 }
137
138 void
140 {
142 // TODO: hack stop capturing
143 stopCapture();
144
145 if (captureTask)
146 {
147 captureTask->stop();
148 }
149
151 }
152
153 void
155 {
157 ARMARX_INFO << "Starting point clouds Provider: " << getName() << flush;
158
159 // main loop of component
160 std::chrono::milliseconds td(1);
161
162 while (!captureTask->isStopped() && !isExiting())
163 {
164 if (captureEnabled)
165 {
166 std::unique_lock lock(captureMutex);
167
168 doCapture();
169
170 if (numFramesToCapture > 0)
171 {
173 }
174 if (numFramesToCapture == 0)
175 {
176 captureEnabled = false;
177 continue;
178 }
179
180 if (pointCloudSyncMode == eFpsSynchronization)
181 {
182 fpsCounter.assureFPS(frameRate);
183 }
184 }
185 else
186 {
187 std::this_thread::sleep_for(td);
188 }
189 }
190
191 ARMARX_INFO << "Stopping point clouds Provider" << flush;
192 }
193
194 // ================================================================== //
195 // == Utility methods for CapturingPointCloudProviders =================== //
196 // ================================================================== //
197 void
199 {
200 std::unique_lock lock(captureMutex);
201
202 this->pointCloudSyncMode = pointCloudSyncMode;
203 }
204
205 ImageSyncMode
207 {
208 std::unique_lock lock(captureMutex);
209
210 return pointCloudSyncMode;
211 }
212} // namespace visionx
constexpr T c
Property< PropertyType > getProperty(const std::string &name)
std::string getName() const
Retrieve name of object.
virtual void onStopCapture()=0
This is called when the point cloud provider capturing has been stopped.
virtual void onInitCapturingPointCloudProvider()=0
This is called when the Component::onInitComponent() is called.
ImageSyncMode pointCloudSyncMode
Point cloud synchronization information.
ImageSyncMode getPointCloudSyncMode()
Returns the point cloud sync mode.
bool isCaptureEnabled(const Ice::Current &c=Ice::emptyCurrent) override
virtual void onExitCapturingPointCloudProvider()=0
This is called when the Component::onExitComponent() setup is called.
void stopCapture(const Ice::Current &c=Ice::emptyCurrent) override
Stops point cloud capturing.
void startCapture(const Ice::Current &c=Ice::emptyCurrent) override
Starts point cloud capturing.
std::atomic_bool captureEnabled
Indicates that capturing is enabled and running.
void setPointCloudSyncMode(ImageSyncMode pointCloudSyncMode)
Sets the point cloud synchronization mode.
void startCaptureForNumFrames(int numFrames, const Ice::Current &c=Ice::emptyCurrent) override
Starts point cloud capturing.
virtual void onStartCapture(float framesPerSecond)=0
This is called when the point cloud provider capturing has been started.
void changeFrameRate(Ice::Float framesPerSecond, const Ice::Current &c=Ice::emptyCurrent) override
set a new frame rate
std::mutex captureMutex
mutex for capturing for proper exit
int numFramesToCapture
Number of frames to capture.
virtual bool doCapture()=0
Main capturing function.
armarx::RunningTask< CapturingPointCloudProvider >::pointer_type captureTask
Capture thread.
virtual void onStartCapturingPointCloudProvider()
This is called when the Component::onConnectComponent() setup is called.
bool isExiting() const
Retrieve whether provider is exiting.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
const LogSender::manipulator flush
Definition LogSender.h:251
ArmarX headers.
#define ARMARX_TRACE
Definition trace.h:77