CapturingPointCloudProvider.h
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 
25 #pragma once
26 
27 
29 
30 #include "PointCloudProvider.h"
32 
33 #include <mutex>
34 
35 namespace visionx
36 {
37 
40  {
41  public:
44  {
45  defineOptionalProperty<float>("framerate", 30.0f, "framerate for the point clouds").setMin(0.0f).setMax(60.0f);
46  defineOptionalProperty<bool>("isEnabled", true, "enable the capturing process immediately");
47  }
48  };
49 
50 
51 
52  /**
53  * The CapturingPointCloudProvider provides a callback function to trigger
54  * the capturing of point clouds with different synchronization modes.
55  */
57  virtual public PointCloudProvider,
58  virtual public CapturingPointCloudProviderInterface
59  {
60  public:
61  // ================================================================== //
62  // == CapturingPointCloudProvider ice interface ========================== //
63  // ================================================================== //
64  /**
65  * Starts point cloud capturing.
66  *
67  *
68  * @throw visionx::PointCloudProviderResolutionNotSupportedException
69  * @throw visionx::PointCloudProviderStartingCaptureFailedException
70  */
71  void startCapture(const Ice::Current& c = Ice::emptyCurrent) override;
72 
73  /**
74  * Starts point cloud capturing.
75  *
76  * @param numFrames Automatically stop capture after this amount of captured frames
77  *
78  * @throw visionx::PointCloudProviderResolutionNotSupportedException
79  * @throw visionx::PointCloudProviderStartingCaptureFailedException
80  */
81  void startCaptureForNumFrames(int numFrames, const Ice::Current& c = Ice::emptyCurrent) override;
82 
83  /**
84  * Stops point cloud capturing. The Capturing can be started again by re-calling
85  * startCapture(...).
86  */
87  void stopCapture(const Ice::Current& c = Ice::emptyCurrent) override;
88 
89 
90  /**
91  * set a new frame rate
92  *
93  * @param framesPerSecond Frames per second to capture.
94  * @throw visionx::PointCloudProviderFrameRateNotSupportedException
95  */
96  void changeFrameRate(Ice::Float framesPerSecond, const Ice::Current& c = Ice::emptyCurrent) override;
97 
98 
99  bool isCaptureEnabled(const Ice::Current& c = Ice::emptyCurrent) override;
100 
101 
102  protected:
103 
104  // ================================================================== //
105  // == Interface of PointCloudProvider ================================= //
106  // ================================================================== //
107  /**
108  * This is called when the Component::onInitComponent() is called.
109  *
110  * Implement this method in the PointCloudProvider in order to setup its
111  * parameters. Use this to set the Point cloud format.
112  */
113  virtual void onInitCapturingPointCloudProvider() = 0;
114 
115  /**
116  * This is called when the Component::onConnectComponent() setup is called
117  */
119 
120  /**
121  * This is called when the Component::onExitComponent() setup is called
122  *
123  * Implement this method in the PointCloudProvider in order clean up right
124  * before terminating.
125  */
126  virtual void onExitCapturingPointCloudProvider() = 0;
127 
128  /**
129  * This is called when the point cloud provider capturing has been started.
130  *
131  * Implement this method in the PointCloudProvider in order to reset
132  * prvider's state.
133  *
134  * @param framesPerSecond capturing fps
135  *
136  * @throw visionx::PointCloudProviderResolutionNotSupportedException
137  * @throw visionx::PointCloudProviderFrameRateNotSupportedException
138  * @throw visionx::PointCloudProviderStartingCaptureFailedException
139  */
140  virtual void onStartCapture(float framesPerSecond) = 0;
141 
142  /**
143  * This is called when the point cloud provider capturing has been stopped.
144  *
145  * Implement this method in the PointCloudProvider in order to clean up after stopping.
146  */
147  virtual void onStopCapture() = 0;
148 
149  /**
150  * Main capturing function.
151  *
152  * @param ppPointCloudBuffers Point cloud pointer array where the captured point clouds need to be copied into
153  */
154  virtual bool doCapture() = 0;
155 
156  // ================================================================== //
157  // == Utility methods for PointCloudProviders ============================ //
158  // ================================================================== //
159  /**
160  * Sets the point cloud synchronization mode
161  *
162  * @param pointCloudSyncMode point cloud synchronization mode
163  */
164  void setPointCloudSyncMode(ImageSyncMode pointCloudSyncMode);
165 
166  /**
167  * Returns the point cloud sync mode
168  */
169  ImageSyncMode getPointCloudSyncMode();
170 
171 
172  // ================================================================== //
173  // == RunningComponent implementation =============================== //
174  // ================================================================== //
175  /**
176  * @see Component::onInitComponent()
177  */
178  void onInitPointCloudProvider() override;
179 
180  /**
181  * @see Component::onConnectComponent()
182  */
183  void onConnectPointCloudProvider() override;
184 
185  /**
186  * @see Component::onExitComponent()
187  */
188  void onExitPointCloudProvider() override;
189 
190  /**
191  * @see capture method issued by RunningTask
192  */
193  virtual void capture();
194 
195  protected:
196  /**
197  * Capture thread
198  */
200 
201  /**
202  * Point cloud synchronization information
203  */
204  ImageSyncMode pointCloudSyncMode;
205 
206  /**
207  * mutex for capturing for proper exit
208  */
209  mutable std::mutex captureMutex;
210 
211  /**
212  * Required frame rate
213  */
214  float frameRate;
215 
216  /**
217  * FPS manager
218  */
220 
221  /**
222  * Indicates that capturing is enabled and running
223  */
224  std::atomic_bool captureEnabled;
225 
226  /**
227  * Number of frames to capture
228  */
230  };
231 }
232 
visionx::CapturingPointCloudProvider::pointCloudSyncMode
ImageSyncMode pointCloudSyncMode
Point cloud synchronization information.
Definition: CapturingPointCloudProvider.h:204
visionx::CapturingPointCloudProvider::onStopCapture
virtual void onStopCapture()=0
This is called when the point cloud provider capturing has been stopped.
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
visionx::CapturingPointCloudProvider::startCaptureForNumFrames
void startCaptureForNumFrames(int numFrames, const Ice::Current &c=Ice::emptyCurrent) override
Starts point cloud capturing.
Definition: CapturingPointCloudProvider.cpp:50
visionx::CapturingPointCloudProvider::onInitCapturingPointCloudProvider
virtual void onInitCapturingPointCloudProvider()=0
This is called when the Component::onInitComponent() is called.
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CapturingPointCloudProvider::onInitPointCloudProvider
void onInitPointCloudProvider() override
Definition: CapturingPointCloudProvider.cpp:90
visionx::CapturingPointCloudProvider::setPointCloudSyncMode
void setPointCloudSyncMode(ImageSyncMode pointCloudSyncMode)
Sets the point cloud synchronization mode.
Definition: CapturingPointCloudProvider.cpp:190
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::CapturingPointCloudProvider::isCaptureEnabled
bool isCaptureEnabled(const Ice::Current &c=Ice::emptyCurrent) override
Definition: CapturingPointCloudProvider.cpp:81
visionx::CapturingPointCloudProvider::onStartCapture
virtual void onStartCapture(float framesPerSecond)=0
This is called when the point cloud provider capturing has been started.
PointCloudProvider.h
visionx::CapturingPointCloudProvider::onExitPointCloudProvider
void onExitPointCloudProvider() override
Definition: CapturingPointCloudProvider.cpp:132
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
RunningTask.h
visionx::CapturingPointCloudProvider::onExitCapturingPointCloudProvider
virtual void onExitCapturingPointCloudProvider()=0
This is called when the Component::onExitComponent() setup is called.
visionx::CapturingPointCloudProvider::captureMutex
std::mutex captureMutex
mutex for capturing for proper exit
Definition: CapturingPointCloudProvider.h:209
visionx::CapturingPointCloudProvider::capture
virtual void capture()
Definition: CapturingPointCloudProvider.cpp:147
visionx::CapturingPointCloudProviderPropertyDefinitions::CapturingPointCloudProviderPropertyDefinitions
CapturingPointCloudProviderPropertyDefinitions(std::string prefix)
Definition: CapturingPointCloudProvider.h:42
visionx::CapturingPointCloudProvider::captureEnabled
std::atomic_bool captureEnabled
Indicates that capturing is enabled and running.
Definition: CapturingPointCloudProvider.h:224
visionx::CapturingPointCloudProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingPointCloudProvider.h:214
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:38
visionx::PointCloudProviderPropertyDefinitions
Definition: PointCloudProvider.h:42
visionx::CapturingPointCloudProvider::captureTask
armarx::RunningTask< CapturingPointCloudProvider >::pointer_type captureTask
Capture thread.
Definition: CapturingPointCloudProvider.h:199
visionx::CapturingPointCloudProvider::startCapture
void startCapture(const Ice::Current &c=Ice::emptyCurrent) override
Starts point cloud capturing.
Definition: CapturingPointCloudProvider.cpp:37
visionx::CapturingPointCloudProvider
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
Definition: CapturingPointCloudProvider.h:56
visionx::CapturingPointCloudProvider::changeFrameRate
void changeFrameRate(Ice::Float framesPerSecond, const Ice::Current &c=Ice::emptyCurrent) override
set a new frame rate
Definition: CapturingPointCloudProvider.cpp:73
visionx::CapturingPointCloudProvider::fpsCounter
FPSCounter fpsCounter
FPS manager.
Definition: CapturingPointCloudProvider.h:219
visionx::CapturingPointCloudProvider::getPointCloudSyncMode
ImageSyncMode getPointCloudSyncMode()
Returns the point cloud sync mode.
Definition: CapturingPointCloudProvider.cpp:197
visionx::CapturingPointCloudProvider::onConnectPointCloudProvider
void onConnectPointCloudProvider() override
Definition: CapturingPointCloudProvider.cpp:116
IceUtil::Handle
Definition: forward_declarations.h:29
visionx::CapturingPointCloudProvider::numFramesToCapture
int numFramesToCapture
Number of frames to capture.
Definition: CapturingPointCloudProvider.h:229
visionx::CapturingPointCloudProvider::doCapture
virtual bool doCapture()=0
Main capturing function.
visionx::CapturingPointCloudProvider::onStartCapturingPointCloudProvider
virtual void onStartCapturingPointCloudProvider()
This is called when the Component::onConnectComponent() setup is called.
Definition: CapturingPointCloudProvider.h:118
FPSCounter.h
visionx::PointCloudProvider
PointCloudProvider abstract class defines a component which provide point clouds via ice or shared me...
Definition: PointCloudProvider.h:58
visionx::FPSCounter
The FPSCounter class provides methods for calculating the frames per second (FPS) count in periodic t...
Definition: FPSCounter.h:36
visionx::CapturingPointCloudProvider::stopCapture
void stopCapture(const Ice::Current &c=Ice::emptyCurrent) override
Stops point cloud capturing.
Definition: CapturingPointCloudProvider.cpp:63