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 
29 
32 
33 #include <mutex>
34 
35 namespace visionx
36 {
38  {
39  public:
42  {
43  defineOptionalProperty<float>("FPS", 30.0f, "Frames per second with that the capture function is called.");
44  }
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  // ================================================================== //
80  // == Interface of ImageProvider ================================= //
81  // ================================================================== //
82  /**
83  * This is called when the Component::onInitComponent() is called.
84  *
85  * Implement this method in the ImageProvider in order to setup its
86  * parameters. Use this to set the image format.
87  */
88  virtual void onInitCapturingImageProvider() = 0;
89 
90  /**
91  * This is called when the Component::onConnectComponent() setup is called
92  */
93  virtual void onStartCapturingImageProvider() { }
94 
95  /**
96  * This is called when the Component::onExitComponent() setup is called
97  *
98  * Implement this method in the ImageProvider in order clean up right
99  * before terminating.
100  */
101  virtual void onExitCapturingImageProvider() = 0;
102 
103  /**
104  * This is called when the image provider capturing has been started.
105  *
106  * Implement this method in the ImageProvider in order to reset
107  * prvider's state.
108  *
109  * @param framesPerSecond capturing fps
110  *
111  * @throw visionx::FrameRateNotSupportedException
112  * @throw visionx::StartingCaptureFailedException
113  */
114  virtual void onStartCapture(float framesPerSecond) = 0;
115 
116  /**
117  * This is called when the image provider capturing has been stopped.
118  *
119  * Implement this method in the ImageProvider in order to clean up after
120  * stopping.
121  */
122  virtual void onStopCapture() = 0;
123 
124  /**
125  * Main capturing function.
126  *
127  * @param ppImageBuffers Image pointer array where the captured images
128  * need to be copied into
129  */
130  virtual bool capture(void** ppImageBuffers) = 0;
131 
132  // ================================================================== //
133  // == Utility methods for ImageProviders ============================ //
134  // ================================================================== //
135  /**
136  * Sets the image synchronization mode
137  *
138  * @param imageSyncMode image synchronization mode
139  */
140  void setImageSyncMode(ImageSyncMode imageSyncMode);
141 
142  /**
143  * Returns the image sync mode
144  */
145  ImageSyncMode getImageSyncMode();
146 
147  /**
148  * Retrieve scoped lock for writing to the memory.
149  *
150  * @return the scoped lock
151  */
153  {
155  }
156 
157  // ================================================================== //
158  // == RunningComponent implementation =============================== //
159  // ================================================================== //
160  /**
161  * @see Component::onInitComponent()
162  */
163  void onInitImageProvider() override;
164 
165  /**
166  * @see Component::onConnectComponent()
167  */
168  void onConnectImageProvider() override;
169 
170  /**
171  * @see Component::onExitComponent()
172  */
173  void onExitImageProvider() override;
174 
175  /**
176  * @see capture method issued by RunningTask
177  */
178  virtual void capture();
179 
180  protected:
181  /**
182  * Capture thread
183  */
185 
186  /**
187  * Image synchronization information
188  */
189  ImageSyncMode imageSyncMode;
190 
191  /**
192  * mutex for capturing for proper exit
193  */
194  std::mutex captureMutex;
195  /**
196  * Required frame rate
197  */
198  float frameRate;
199 
200  /**
201  * FPS manager
202  */
204 
205  /**
206  * Indicates that capturing is enabled and running
207  */
209  };
210 }
211 
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:156
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:198
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:92
visionx::CapturingImageProvider::onInitImageProvider
void onInitImageProvider() override
Definition: CapturingImageProvider.cpp:63
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::CapturingImageProvider::captureTask
armarx::RunningTask< CapturingImageProvider >::pointer_type captureTask
Capture thread.
Definition: CapturingImageProvider.h:184
visionx::CapturingImageProvider::stopCapture
void stopCapture(const Ice::Current &c=Ice::emptyCurrent) override
Stops image capturing.
Definition: CapturingImageProvider.cpp:53
armarx::SharedMemoryScopedWriteLockPtr
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
Definition: SharedMemoryProvider.h:46
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:256
visionx::CapturingImageProvider::fpsCounter
FPSCounter fpsCounter
FPS manager.
Definition: CapturingImageProvider.h:203
visionx::CapturingImageProvider::imageSyncMode
ImageSyncMode imageSyncMode
Image synchronization information.
Definition: CapturingImageProvider.h:189
visionx::CapturingImageProvider::captureEnabled
bool captureEnabled
Indicates that capturing is enabled and running.
Definition: CapturingImageProvider.h:208
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:106
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:81
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:166
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle
Definition: forward_declarations.h:29
visionx::CapturingImageProviderPropertyDefinitions
Definition: CapturingImageProvider.h:37
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
visionx::CapturingImageProvider::startCapture
void startCapture(float framesPerSecond, const Ice::Current &c=Ice::emptyCurrent) override
Starts image capturing.
Definition: CapturingImageProvider.cpp:40
visionx::CapturingImageProvider::getImageSyncMode
ImageSyncMode getImageSyncMode()
Returns the image sync mode.
Definition: CapturingImageProvider.cpp:171
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:28
visionx::CapturingImageProvider::getScopedWriteLock
armarx::SharedMemoryScopedWriteLockPtr getScopedWriteLock()
Retrieve scoped lock for writing to the memory.
Definition: CapturingImageProvider.h:152
visionx::CapturingImageProvider::captureMutex
std::mutex captureMutex
mutex for capturing for proper exit
Definition: CapturingImageProvider.h:194
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