CapturingImageProvider.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 Kai Welke (kai dot welke at kit dot edu)
20  * @date 2012
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 
34 
35 namespace visionx
36 {
38  {
39  public:
42  {
43  defineOptionalProperty<float>(
44  "FPS", 30.0f, "Frames per second with that the capture function is called.");
45  }
46  };
47 
48  /**
49  * The CapturingImageProvider provides a callback function to trigger
50  * the capturing of images with different synchronization modes.
51  */
53  virtual public ImageProvider,
54  virtual public CapturingImageProviderInterface
55  {
56  public:
57  // ================================================================== //
58  // == CapturingImageProvider ice interface ========================== //
59  // ================================================================== //
60  /**
61  * Starts image capturing.
62  *
63  * @param framesPerSecond Frames per second to capture.
64  *
65  * @throw visionx::FrameRateNotSupportedException
66  * @throw visionx::StartingCaptureFailedException
67  */
68  void startCapture(float framesPerSecond,
69  const Ice::Current& c = Ice::emptyCurrent) override;
70 
71  /**
72  * Stops image capturing. The Capturing can be started anew by calling
73  * startCapture(...) again.
74  */
75  void stopCapture(const Ice::Current& c = Ice::emptyCurrent) override;
76 
77  protected:
78  // ================================================================== //
79  // == Interface of ImageProvider ================================= //
80  // ================================================================== //
81  /**
82  * This is called when the Component::onInitComponent() is called.
83  *
84  * Implement this method in the ImageProvider in order to setup its
85  * parameters. Use this to set the image format.
86  */
87  virtual void onInitCapturingImageProvider() = 0;
88 
89  /**
90  * This is called when the Component::onConnectComponent() setup is called
91  */
92  virtual void
94  {
95  }
96 
97  /**
98  * This is called when the Component::onExitComponent() setup is called
99  *
100  * Implement this method in the ImageProvider in order clean up right
101  * before terminating.
102  */
103  virtual void onExitCapturingImageProvider() = 0;
104 
105  /**
106  * This is called when the image provider capturing has been started.
107  *
108  * Implement this method in the ImageProvider in order to reset
109  * prvider's state.
110  *
111  * @param framesPerSecond capturing fps
112  *
113  * @throw visionx::FrameRateNotSupportedException
114  * @throw visionx::StartingCaptureFailedException
115  */
116  virtual void onStartCapture(float framesPerSecond) = 0;
117 
118  /**
119  * This is called when the image provider capturing has been stopped.
120  *
121  * Implement this method in the ImageProvider in order to clean up after
122  * stopping.
123  */
124  virtual void onStopCapture() = 0;
125 
126  /**
127  * Main capturing function.
128  *
129  * @param ppImageBuffers Image pointer array where the captured images
130  * need to be copied into
131  */
132  virtual bool capture(void** ppImageBuffers) = 0;
133 
134  // ================================================================== //
135  // == Utility methods for ImageProviders ============================ //
136  // ================================================================== //
137  /**
138  * Sets the image synchronization mode
139  *
140  * @param imageSyncMode image synchronization mode
141  */
142  void setImageSyncMode(ImageSyncMode imageSyncMode);
143 
144  /**
145  * Returns the image sync mode
146  */
147  ImageSyncMode getImageSyncMode();
148 
149  /**
150  * Retrieve scoped lock for writing to the memory.
151  *
152  * @return the scoped lock
153  */
156  {
158  }
159 
160  // ================================================================== //
161  // == RunningComponent implementation =============================== //
162  // ================================================================== //
163  /**
164  * @see Component::onInitComponent()
165  */
166  void onInitImageProvider() override;
167 
168  /**
169  * @see Component::onConnectComponent()
170  */
171  void onConnectImageProvider() override;
172 
173  /**
174  * @see Component::onExitComponent()
175  */
176  void onExitImageProvider() override;
177 
178  /**
179  * @see capture method issued by RunningTask
180  */
181  virtual void capture();
182 
183  protected:
184  /**
185  * Capture thread
186  */
188 
189  /**
190  * Image synchronization information
191  */
192  ImageSyncMode imageSyncMode;
193 
194  /**
195  * mutex for capturing for proper exit
196  */
197  std::mutex captureMutex;
198  /**
199  * Required frame rate
200  */
201  float frameRate;
202 
203  /**
204  * FPS manager
205  */
207 
208  /**
209  * Indicates that capturing is enabled and running
210  */
212  };
213 } // namespace visionx
visionx::CapturingImageProvider::onStartCapture
virtual void onStartCapture(float framesPerSecond)=0
This is called when the image provider capturing has been started.
armarx::IceSharedMemoryProvider::getScopedWriteLock
SharedMemoryScopedWriteLockPtr getScopedWriteLock() const
Retrieve scoped lock for writing to the memory.
Definition: IceSharedMemoryProvider.h:166
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:201
visionx::CapturingImageProvider::onInitCapturingImageProvider
virtual void onInitCapturingImageProvider()=0
This is called when the Component::onInitComponent() is called.
visionx::CapturingImageProvider::onExitImageProvider
void onExitImageProvider() override
Definition: CapturingImageProvider.cpp:95
visionx::CapturingImageProvider::onInitImageProvider
void onInitImageProvider() override
Definition: CapturingImageProvider.cpp:65
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::CapturingImageProvider::captureTask
armarx::RunningTask< CapturingImageProvider >::pointer_type captureTask
Capture thread.
Definition: CapturingImageProvider.h:187
visionx::CapturingImageProvider::stopCapture
void stopCapture(const Ice::Current &c=Ice::emptyCurrent) override
Stops image capturing.
Definition: CapturingImageProvider.cpp:54
armarx::SharedMemoryScopedWriteLockPtr
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
Definition: SharedMemoryProvider.h:47
RunningTask.h
visionx::CapturingImageProvider::onStartCapturingImageProvider
virtual void onStartCapturingImageProvider()
This is called when the Component::onConnectComponent() setup is called.
Definition: CapturingImageProvider.h:93
visionx::ImageProvider::sharedMemoryProvider
armarx::IceSharedMemoryProvider< unsigned char >::pointer_type sharedMemoryProvider
shared memory provider
Definition: ImageProvider.h:286
visionx::CapturingImageProvider::fpsCounter
FPSCounter fpsCounter
FPS manager.
Definition: CapturingImageProvider.h:206
visionx::CapturingImageProvider::imageSyncMode
ImageSyncMode imageSyncMode
Image synchronization information.
Definition: CapturingImageProvider.h:192
visionx::CapturingImageProvider::captureEnabled
bool captureEnabled
Indicates that capturing is enabled and running.
Definition: CapturingImageProvider.h:211
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:109
visionx::CapturingImageProvider
The CapturingImageProvider provides a callback function to trigger the capturing of images with diffe...
Definition: CapturingImageProvider.h:52
visionx::CapturingImageProvider::onExitCapturingImageProvider
virtual void onExitCapturingImageProvider()=0
This is called when the Component::onExitComponent() setup is called.
visionx::CapturingImageProvider::onConnectImageProvider
void onConnectImageProvider() override
Definition: CapturingImageProvider.cpp:84
visionx::ImageProvider
ImageProvider abstract class defines a component which provide images via ice or shared memory.
Definition: ImageProvider.h:66
visionx::CapturingImageProvider::setImageSyncMode
void setImageSyncMode(ImageSyncMode imageSyncMode)
Sets the image synchronization mode.
Definition: CapturingImageProvider.cpp:175
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle
Definition: forward_declarations.h:30
visionx::CapturingImageProviderPropertyDefinitions
Definition: CapturingImageProvider.h:37
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:35
visionx::CapturingImageProvider::startCapture
void startCapture(float framesPerSecond, const Ice::Current &c=Ice::emptyCurrent) override
Starts image capturing.
Definition: CapturingImageProvider.cpp:42
visionx::CapturingImageProvider::getImageSyncMode
ImageSyncMode getImageSyncMode()
Returns the image sync mode.
Definition: CapturingImageProvider.cpp:181
ImageProvider.h
visionx::CapturingImageProvider::onStopCapture
virtual void onStopCapture()=0
This is called when the image provider capturing has been stopped.
FPSCounter.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
visionx::CapturingImageProvider::getScopedWriteLock
armarx::SharedMemoryScopedWriteLockPtr getScopedWriteLock()
Retrieve scoped lock for writing to the memory.
Definition: CapturingImageProvider.h:155
visionx::CapturingImageProvider::captureMutex
std::mutex captureMutex
mutex for capturing for proper exit
Definition: CapturingImageProvider.h:197
visionx::FPSCounter
The FPSCounter class provides methods for calculating the frames per second (FPS) count in periodic t...
Definition: FPSCounter.h:36
visionx::CapturingImageProviderPropertyDefinitions::CapturingImageProviderPropertyDefinitions
CapturingImageProviderPropertyDefinitions(std::string prefix)
Definition: CapturingImageProvider.h:40