ImageProviderDynamicSimulation.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2013-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
19  * @author Nikolaus Vahrenkamp
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 #include <mutex>
28 #include <string>
29 
31 
33 #include <VisionX/interface/components/Calibration.h>
34 #include <VisionX/interface/core/DataTypes.h>
35 
36 // IVT
37 #include <VirtualRobot/Robot.h>
38 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
39 
41 
43 #include <ArmarXSimulation/interface/simulator/SimulatorInterface.h>
44 
45 #include <Calibration/StereoCalibration.h>
46 #include <Image/ByteImage.h>
47 
48 namespace armarx
49 {
52  {
53  public:
56  {
57  defineOptionalProperty<float>("FrameRate", 30.0f, "Frames per second")
58  .setMatchRegex("\\d+(.\\d*)?")
59  .setMin(0.0f)
60  .setMax(60.0f);
61  defineOptionalProperty<visionx::ImageDimension>(
62  "ImageSize",
63  visionx::ImageDimension(640, 480),
64  "Target resolution of the images. Captured images will be converted to this size.")
65  .setCaseInsensitive(true)
66  .map("320x240", visionx::ImageDimension(320, 240))
67  .map("640x480", visionx::ImageDimension(640, 480))
68  .map("800x600", visionx::ImageDimension(800, 600))
69  .map("768x576", visionx::ImageDimension(768, 576))
70  .map("1024x768", visionx::ImageDimension(1024, 768))
71  .map("1280x960", visionx::ImageDimension(1280, 960))
72  .map("1600x1200", visionx::ImageDimension(1600, 1200))
73  .map("none", visionx::ImageDimension(0, 0));
74  //defineOptionalProperty<std::string>("SimulatorControlName", "ArmarXSimulatorControl", "Name of the simulator control component that should be used");
75  defineOptionalProperty<std::string>("RobotName", "Armar3", "The robot");
76  defineOptionalProperty<std::string>("RobotNodeLeftCamera",
77  "EyeLeftCameraSim",
78  "The coordinate system of the left camera");
79  defineOptionalProperty<std::string>("RobotNodeRightCamera",
80  "EyeRightCameraSim",
81  "The coordinate system of the right camera");
82  defineOptionalProperty<std::string>(
83  "CalibrationFile",
84  "",
85  "Camera calibration file, will be made available in the SLICE interface");
86  defineOptionalProperty<std::string>(
87  "ReferenceFrame",
88  "EyeLeftCameraSim",
89  "Reference frame in the robot model of this stereo camera system.");
90  }
91  };
92 
93  /**
94  * Image provider captures images from the simulator and broadcasts
95  * notifications at a specified frame rate.
96  *
97  * It supports the following image transmission formats:
98  *
99  * - RGB
100  * - Gray Scale
101  *
102  */
104  virtual public visionx::CapturingImageProvider,
105  virtual public visionx::StereoCalibrationCaptureProviderInterface
106  {
107  public:
108  std::string
109  getDefaultName() const override
110  {
111  return "DynamicSimulationImageProvider";
112  }
113 
114 
115  protected:
116  /**
117  * @see visionx::CapturingImageProvider::onInitCapturingImageProvider()
118  */
119  void onInitCapturingImageProvider() override;
120 
121  /**
122  * @see visionx::CapturingImageProvider::onExitCapturingImageProvider()
123  */
124  void onExitCapturingImageProvider() override;
125 
126  /**
127  * @see visionx::CapturingImageProvider::onStartCapture(float frameRate)
128  */
129  void onStartCapture(float frameRate) override;
130 
131  /**
132  * @see visionx::CapturingImageProvider::onStopCapture()
133  */
134  void onStopCapture() override;
135 
136  bool capture(void** ppImageBuffers) override;
137 
138 
139  /**
140  * Returns the StereoCalibration as provided in configuration
141  *
142  * @return visionx::StereoCalibration
143  */
144  visionx::StereoCalibration
145  getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
146 
147  /**
148  * Returns whether images are undistorted
149  *
150  * @return bool
151  */
152  bool getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override;
153  std::string getReferenceFrame(const ::Ice::Current& = Ice::emptyCurrent) override;
154 
155  /**
156  * @see PropertyUser::createPropertyDefinitions()
157  */
160  {
161  auto props = armarx::PropertyDefinitionsPtr(
164 
165  props->defineOptionalProperty<float>("focalLength", 600, "The focal length.");
166 
167  return props;
168  }
169 
170  CByteImage** images;
171  CByteImage** resizedImages;
172 
173  std::mutex captureMutex;
174 
175  //VirtualRobot::RobotNodePtr leftCameraNode;
176  //VirtualRobot::RobotNodePtr rightCameraNode;
177 
181 
182  //RemoteRobotPtr remoteRobot;
183 
185 
186  //SimulatorControlInterfacePrx simulatorProxy;
187  /*std::string memoryNameLeft;
188  std::string memoryNameRight;
189  SharedMemoryConsumer<unsigned char>::pointer_type sharedMemoryConsumerLeft;
190  SharedMemoryConsumer<unsigned char>::pointer_type sharedMemoryConsumerRight;*/
191 
192  std::shared_ptr<SoOffscreenRenderer> rendererLeft;
193  std::shared_ptr<SoOffscreenRenderer> rendererRight;
194 
195  std::string robotName;
196  std::string leftNodeName;
197  std::string rightNodeName;
198  VirtualRobot::RobotNodePtr cameraNodeL;
199  VirtualRobot::RobotNodePtr cameraNodeR;
200 
201  float focalLength;
202 
203  std::optional<visionx::StereoCalibration> stereoCalibration;
204 
205  bool setupCameraRendering(const std::string& robotName,
206  const std::string& cameraSensorNameLeft,
207  const std::string& cameraSensorNameRight);
208  bool updateCameraRendering();
209 
210  void initStereoCalib();
211 
212  private:
213  };
214 
215 } // namespace armarx
armarx::ImageProviderDynamicSimulation::renderImg_bpp
int renderImg_bpp
Definition: ImageProviderDynamicSimulation.h:178
RemoteRobot.h
armarx::ImageProviderDynamicSimulation
Image provider captures images from the simulator and broadcasts notifications at a specified frame r...
Definition: ImageProviderDynamicSimulation.h:103
armarx::ImageProviderDynamicSimulation::initStereoCalib
void initStereoCalib()
Definition: ImageProviderDynamicSimulation.cpp:427
armarx::ImageProviderDynamicSimulation::onStartCapture
void onStartCapture(float frameRate) override
Definition: ImageProviderDynamicSimulation.cpp:175
armarx::ImageProviderDynamicSimulation::simVisu
ArmarXPhysicsWorldVisualizationPtr simVisu
Definition: ImageProviderDynamicSimulation.h:184
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:201
armarx::ImageProviderDynamicSimulation::images
CByteImage ** images
Definition: ImageProviderDynamicSimulation.h:170
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
armarx::ImageSequenceProviderDynamicSimulationPropertyDefinitions::ImageSequenceProviderDynamicSimulationPropertyDefinitions
ImageSequenceProviderDynamicSimulationPropertyDefinitions(std::string prefix)
Definition: ImageProviderDynamicSimulation.h:54
armarx::ImageProviderDynamicSimulation::cameraNodeL
VirtualRobot::RobotNodePtr cameraNodeL
Definition: ImageProviderDynamicSimulation.h:198
armarx::ImageProviderDynamicSimulation::resizedImages
CByteImage ** resizedImages
Definition: ImageProviderDynamicSimulation.h:171
armarx::ImageProviderDynamicSimulation::onInitCapturingImageProvider
void onInitCapturingImageProvider() override
Definition: ImageProviderDynamicSimulation.cpp:53
armarx::ImageProviderDynamicSimulation::renderImg_height
int renderImg_height
Definition: ImageProviderDynamicSimulation.h:180
armarx::ImageProviderDynamicSimulation::rendererLeft
std::shared_ptr< SoOffscreenRenderer > rendererLeft
Definition: ImageProviderDynamicSimulation.h:192
IceInternal::Handle< ArmarXPhysicsWorldVisualization >
armarx::ImageProviderDynamicSimulation::updateCameraRendering
bool updateCameraRendering()
Definition: ImageProviderDynamicSimulation.cpp:243
ArmarXPhysicsWorldVisualization.h
armarx::ImageProviderDynamicSimulation::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ImageProviderDynamicSimulation.h:109
SharedMemoryConsumer.h
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
armarx::ImageProviderDynamicSimulation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ImageProviderDynamicSimulation.h:159
armarx::ImageProviderDynamicSimulation::renderImg_width
int renderImg_width
Definition: ImageProviderDynamicSimulation.h:179
armarx::ImageProviderDynamicSimulation::leftNodeName
std::string leftNodeName
Definition: ImageProviderDynamicSimulation.h:196
armarx::ImageProviderDynamicSimulation::setupCameraRendering
bool setupCameraRendering(const std::string &robotName, const std::string &cameraSensorNameLeft, const std::string &cameraSensorNameRight)
Definition: ImageProviderDynamicSimulation.cpp:200
armarx::ImageProviderDynamicSimulation::stereoCalibration
std::optional< visionx::StereoCalibration > stereoCalibration
Definition: ImageProviderDynamicSimulation.h:203
armarx::ImageProviderDynamicSimulation::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Returns whether images are undistorted.
Definition: ImageProviderDynamicSimulation.cpp:498
armarx::ImageProviderDynamicSimulation::focalLength
float focalLength
Definition: ImageProviderDynamicSimulation.h:201
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
CapturingImageProvider.h
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
armarx::ImageProviderDynamicSimulation::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Returns the StereoCalibration as provided in configuration.
Definition: ImageProviderDynamicSimulation.cpp:487
armarx::ImageProviderDynamicSimulation::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
Definition: ImageProviderDynamicSimulation.cpp:144
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ImageProviderDynamicSimulation::getReferenceFrame
std::string getReferenceFrame(const ::Ice::Current &=Ice::emptyCurrent) override
Definition: ImageProviderDynamicSimulation.cpp:504
armarx::ImageProviderDynamicSimulation::onStopCapture
void onStopCapture() override
Definition: ImageProviderDynamicSimulation.cpp:371
armarx::ImageProviderDynamicSimulation::rightNodeName
std::string rightNodeName
Definition: ImageProviderDynamicSimulation.h:197
armarx::ImageProviderDynamicSimulation::cameraNodeR
VirtualRobot::RobotNodePtr cameraNodeR
Definition: ImageProviderDynamicSimulation.h:199
armarx::ImageProviderDynamicSimulation::robotName
std::string robotName
Definition: ImageProviderDynamicSimulation.h:195
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
armarx::ImageProviderDynamicSimulation::captureMutex
std::mutex captureMutex
Definition: ImageProviderDynamicSimulation.h:173
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::ImageProviderDynamicSimulation::rendererRight
std::shared_ptr< SoOffscreenRenderer > rendererRight
Definition: ImageProviderDynamicSimulation.h:193
armarx::ImageSequenceProviderDynamicSimulationPropertyDefinitions
Definition: ImageProviderDynamicSimulation.h:50