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