FakePointCloudProvider.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::ArmarXObjects::FakePointCloudProvider
19  * @author Markus Grotz ( markus-grotz at web dot de )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
27 #include <cmath>
28 #include <filesystem>
29 #include <mutex>
30 #include <vector>
31 
32 #include <pcl/common/transforms.h>
33 #include <pcl/filters/filter.h>
34 #include <pcl/io/pcd_io.h>
35 #include <pcl/point_types.h>
36 
37 #include <VirtualRobot/Robot.h>
38 
41 
43 
44 #include <RobotAPI/interface/core/RobotState.h>
45 
48 #include <VisionX/interface/components/FakePointCloudProviderInterface.h>
49 
50 
51 class CByteImage;
52 
53 namespace visionx
54 {
55  /// @class FakePointCloudProviderPropertyDefinitions
58  {
59  public:
61  };
62 
63  /**
64  * @class FakePointCloudProvider
65  * @ingroup VisionX-Components
66  * @brief A brief description
67  *
68  * Detailed Description
69  */
71  virtual public FakePointCloudProviderInterface,
72  virtual public CapturingPointCloudProvider,
73  virtual public ImageProvider,
75  {
76  public:
77  /// @see armarx::ManagedIceObject::getDefaultName()
78  std::string getDefaultName() const override;
79 
80  protected:
81  /// @see visionx::PointCloudProviderBase::onInitPointCloudProvider()
82  void onInitCapturingPointCloudProvider() override;
83 
84  /// @see visionx::PointCloudProviderBase::onExitPointCloudProvider()
85  void onExitCapturingPointCloudProvider() override;
86 
87  /// @see visionx::PointCloudProviderBase::onStartCapture()
88  void onStartCapture(float frameRate) override;
89 
90  /// @see visionx::PointCloudProviderBase::onStopCapture()
91  void onStopCapture() override;
92 
93  /// @see visionx::PointCloudProviderBase::doCapture()
94  bool doCapture() override;
95 
96  MetaPointCloudFormatPtr getDefaultPointCloudFormat() override;
97 
98  /// @see visionx::CapturingImageProvider::onInitImageProvider()
99  void onInitImageProvider() override;
100 
101  /// @see visionx::CapturingImageProvider::onExitImageProvider()
102  void onExitImageProvider() override;
103 
104  StereoCalibration getStereoCalibration(const Ice::Current& = Ice::emptyCurrent) override;
105 
106  bool getImagesAreUndistorted(const Ice::Current& = Ice::emptyCurrent) override;
107 
108  std::string getReferenceFrame(const Ice::Current& = Ice::emptyCurrent) override;
109 
110 
111  // mixed inherited stuff
112  void onInitComponent() override;
113  void onConnectComponent() override;
114  void onDisconnectComponent() override;
115  void onExitComponent() override;
116 
117  /// @see PropertyUser::createPropertyDefinitions()
119 
120  void setPointCloudFilename(const std::string& filename,
121  const ::Ice::Current& = Ice::emptyCurrent) override;
122 
123  bool hasSharedMemorySupport(const Ice::Current& = Ice::emptyCurrent) override;
124 
125 
126  private:
127  bool loadPointCloud(const std::string& fileName);
128  bool loadPointCloudDirectory(const std::string& directoryName);
129  bool loadCalibrationFile(std::string fileName, visionx::CameraParameters& calibration);
130 
131  template <typename PointT>
132  bool processAndProvide(const pcl::PCLPointCloud2Ptr& pointCloud);
133  bool processRGBImage(const pcl::PCLPointCloud2Ptr& pointCloud);
134 
135 
136  armarx::RemoteGui::WidgetPtr buildGui();
137  void processGui(armarx::RemoteGui::TabProxy& prx);
138 
139  private:
140  std::string pointCloudFileName;
141  /// Assume point cloud was stored in this frame.
142  std::string sourceFrameName;
143  /// Frame in which point cloud is provided. (armarx::GlobalFrame by default.)
144  std::string targetFrameName;
145  std::string providedPointCloudFormat;
146  std::string robotStateComponentName;
147 
148  std::mutex pointCloudMutex;
149  std::vector<pcl::PCLPointCloud2Ptr> pointClouds;
150 
151  std::atomic_int counter = 0;
152 
153  std::atomic_bool rewind = false;
154  std::atomic_bool removeNAN = false;
155  std::atomic<float> scaleFactor = 0;
156  std::atomic_bool freezeImage = false;
157  std::atomic_int freezeImageIdx = 0;
158 
159  StereoCalibration calibration;
160  CByteImage** rgbImages = nullptr;
161 
162  armarx::RobotStateComponentInterfacePrx robotStateComponent;
163  VirtualRobot::RobotPtr localRobot;
164  };
165 } // namespace visionx
visionx::FakePointCloudProvider::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: FakePointCloudProvider.cpp:140
CapturingPointCloudProvider.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::FakePointCloudProvider
A brief description.
Definition: FakePointCloudProvider.h:70
visionx::FakePointCloudProviderPropertyDefinitions
Definition: FakePointCloudProvider.h:56
visionx::FakePointCloudProvider::onExitImageProvider
void onExitImageProvider() override
Definition: FakePointCloudProvider.cpp:609
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
visionx::FakePointCloudProvider::onInitImageProvider
void onInitImageProvider() override
Definition: FakePointCloudProvider.cpp:343
visionx::FakePointCloudProvider::onStopCapture
void onStopCapture() override
Definition: FakePointCloudProvider.cpp:373
visionx::FakePointCloudProvider::onExitCapturingPointCloudProvider
void onExitCapturingPointCloudProvider() override
Definition: FakePointCloudProvider.cpp:313
visionx::FakePointCloudProvider::setPointCloudFilename
void setPointCloudFilename(const std::string &filename, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:467
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
visionx::FakePointCloudProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: FakePointCloudProvider.cpp:460
visionx::CapturingPointCloudProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingPointCloudProvider.h:220
visionx::FakePointCloudProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:478
visionx::FakePointCloudProvider::getStereoCalibration
StereoCalibration getStereoCalibration(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:620
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:39
filename
std::string filename
Definition: VisualizationRobot.cpp:86
armarx::RemoteGuiComponentPluginUser
Definition: RemoteGuiComponentPlugin.h:221
Component.h
visionx::CapturingPointCloudProvider
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
Definition: CapturingPointCloudProvider.h:58
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:67
visionx::ImageProvider
ImageProvider abstract class defines a component which provide images via ice or shared memory.
Definition: ImageProvider.h:66
visionx::FakePointCloudProvider::onStartCapture
void onStartCapture(float frameRate) override
Definition: FakePointCloudProvider.cpp:356
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
visionx::FakePointCloudProviderPropertyDefinitions::FakePointCloudProviderPropertyDefinitions
FakePointCloudProviderPropertyDefinitions(std::string prefix)
Definition: FakePointCloudProvider.cpp:55
visionx::FakePointCloudProvider::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: FakePointCloudProvider.cpp:119
visionx::FakePointCloudProvider::onInitCapturingPointCloudProvider
void onInitCapturingPointCloudProvider() override
Definition: FakePointCloudProvider.cpp:147
visionx::FakePointCloudProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: FakePointCloudProvider.cpp:133
visionx::FakePointCloudProvider::getDefaultPointCloudFormat
MetaPointCloudFormatPtr getDefaultPointCloudFormat() override
default point cloud format used to initialize shared memory
Definition: FakePointCloudProvider.cpp:319
visionx::FakePointCloudProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:626
visionx::FakePointCloudProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:632
visionx::FakePointCloudProvider::getDefaultName
std::string getDefaultName() const override
Definition: FakePointCloudProvider.cpp:106
visionx::FakePointCloudProvider::doCapture
bool doCapture() override
Definition: FakePointCloudProvider.cpp:378
RemoteGuiComponentPlugin.h
ArmarXDataPath.h
ImageProvider.h
visionx::FakePointCloudProvider::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: FakePointCloudProvider.cpp:112
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19