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