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
35namespace visionx
36{
38 {
39 public:
42 {
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
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 */
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 {
157 return sharedMemoryProvider->getScopedWriteLock();
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 */
202
203 /**
204 * FPS manager
205 */
207
208 /**
209 * Indicates that capturing is enabled and running
210 */
212 };
213} // namespace visionx
constexpr T c
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
The CapturingImageProvider provides a callback function to trigger the capturing of images with diffe...
virtual void onStopCapture()=0
This is called when the image provider capturing has been stopped.
virtual void onStartCapturingImageProvider()
This is called when the Component::onConnectComponent() setup is called.
ImageSyncMode getImageSyncMode()
Returns the image sync mode.
virtual void onInitCapturingImageProvider()=0
This is called when the Component::onInitComponent() is called.
virtual bool capture(void **ppImageBuffers)=0
Main capturing function.
void stopCapture(const Ice::Current &c=Ice::emptyCurrent) override
Stops image capturing.
void startCapture(float framesPerSecond, const Ice::Current &c=Ice::emptyCurrent) override
Starts image capturing.
void setImageSyncMode(ImageSyncMode imageSyncMode)
Sets the image synchronization mode.
armarx::SharedMemoryScopedWriteLockPtr getScopedWriteLock()
Retrieve scoped lock for writing to the memory.
virtual void onExitCapturingImageProvider()=0
This is called when the Component::onExitComponent() setup is called.
virtual void onStartCapture(float framesPerSecond)=0
This is called when the image provider capturing has been started.
armarx::RunningTask< CapturingImageProvider >::pointer_type captureTask
Capture thread.
std::mutex captureMutex
mutex for capturing for proper exit
ImageSyncMode imageSyncMode
Image synchronization information.
bool captureEnabled
Indicates that capturing is enabled and running.
The FPSCounter class provides methods for calculating the frames per second (FPS) count in periodic t...
Definition FPSCounter.h:37
ImageProvider abstract class defines a component which provide images via ice or shared memory.
armarx::IceSharedMemoryProvider< unsignedchar >::pointer_type sharedMemoryProvider
shared memory provider
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< SharedMemoryScopedWriteLock > SharedMemoryScopedWriteLockPtr
ArmarX headers.