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 
46 #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  /**
65  * @class FakePointCloudProvider
66  * @ingroup VisionX-Components
67  * @brief A brief description
68  *
69  * Detailed Description
70  */
72  virtual public FakePointCloudProviderInterface,
73  virtual public CapturingPointCloudProvider,
74  virtual public ImageProvider,
76  {
77  public:
78 
79  /// @see armarx::ManagedIceObject::getDefaultName()
80  std::string getDefaultName() const override;
81 
82  protected:
83 
84  /// @see visionx::PointCloudProviderBase::onInitPointCloudProvider()
85  void onInitCapturingPointCloudProvider() override;
86 
87  /// @see visionx::PointCloudProviderBase::onExitPointCloudProvider()
88  void onExitCapturingPointCloudProvider() override;
89 
90  /// @see visionx::PointCloudProviderBase::onStartCapture()
91  void onStartCapture(float frameRate) override;
92 
93  /// @see visionx::PointCloudProviderBase::onStopCapture()
94  void onStopCapture() override;
95 
96  /// @see visionx::PointCloudProviderBase::doCapture()
97  bool doCapture() override;
98 
99  MetaPointCloudFormatPtr getDefaultPointCloudFormat() override;
100 
101  /// @see visionx::CapturingImageProvider::onInitImageProvider()
102  void onInitImageProvider() override;
103 
104  /// @see visionx::CapturingImageProvider::onExitImageProvider()
105  void onExitImageProvider() override;
106 
107  StereoCalibration getStereoCalibration(const Ice::Current& = Ice::emptyCurrent) override;
108 
109  bool getImagesAreUndistorted(const Ice::Current& = Ice::emptyCurrent) override;
110 
111  std::string getReferenceFrame(const Ice::Current& = Ice::emptyCurrent) override;
112 
113 
114  // mixed inherited stuff
115  void onInitComponent() override;
116  void onConnectComponent() override;
117  void onDisconnectComponent() override;
118  void onExitComponent() override;
119 
120  /// @see PropertyUser::createPropertyDefinitions()
122 
123  void setPointCloudFilename(const std::string& filename, const ::Ice::Current& = Ice::emptyCurrent) override;
124 
125  bool hasSharedMemorySupport(const Ice::Current& = Ice::emptyCurrent) override;
126 
127 
128  private:
129 
130  bool loadPointCloud(const std::string& fileName);
131  bool loadPointCloudDirectory(const std::string& directoryName);
132  bool loadCalibrationFile(std::string fileName, visionx::CameraParameters& calibration);
133 
134  template<typename PointT>
135  bool processAndProvide(const pcl::PCLPointCloud2Ptr& pointCloud);
136  bool processRGBImage(const pcl::PCLPointCloud2Ptr& pointCloud);
137 
138 
139  armarx::RemoteGui::WidgetPtr buildGui();
140  void processGui(armarx::RemoteGui::TabProxy& prx);
141  private:
142 
143  std::string pointCloudFileName;
144  /// Assume point cloud was stored in this frame.
145  std::string sourceFrameName;
146  /// Frame in which point cloud is provided. (armarx::GlobalFrame by default.)
147  std::string targetFrameName;
148  std::string providedPointCloudFormat;
149  std::string robotStateComponentName;
150 
151  std::mutex pointCloudMutex;
152  std::vector<pcl::PCLPointCloud2Ptr> pointClouds;
153 
154  std::atomic_int counter = 0;
155 
156  std::atomic_bool rewind = false;
157  std::atomic_bool removeNAN = false;
158  std::atomic<float> scaleFactor = 0;
159  std::atomic_bool freezeImage = false;
160  std::atomic_int freezeImageIdx = 0;
161 
162  StereoCalibration calibration;
163  CByteImage** rgbImages = nullptr;
164 
165  armarx::RobotStateComponentInterfacePrx robotStateComponent;
166  VirtualRobot::RobotPtr localRobot;
167  };
168 }
visionx::FakePointCloudProvider::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: FakePointCloudProvider.cpp:123
CapturingPointCloudProvider.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::FakePointCloudProvider
A brief description.
Definition: FakePointCloudProvider.h:71
visionx::FakePointCloudProviderPropertyDefinitions
Definition: FakePointCloudProvider.h:56
visionx::FakePointCloudProvider::onExitImageProvider
void onExitImageProvider() override
Definition: FakePointCloudProvider.cpp:552
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
visionx::FakePointCloudProvider::onInitImageProvider
void onInitImageProvider() override
Definition: FakePointCloudProvider.cpp:302
visionx::FakePointCloudProvider::onStopCapture
void onStopCapture() override
Definition: FakePointCloudProvider.cpp:330
visionx::FakePointCloudProvider::onExitCapturingPointCloudProvider
void onExitCapturingPointCloudProvider() override
Definition: FakePointCloudProvider.cpp:274
visionx::FakePointCloudProvider::setPointCloudFilename
void setPointCloudFilename(const std::string &filename, const ::Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:417
armarx::RemoteGui::TabProxy
Definition: WidgetProxy.h:17
visionx::FakePointCloudProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: FakePointCloudProvider.cpp:412
visionx::CapturingPointCloudProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingPointCloudProvider.h:214
visionx::FakePointCloudProvider::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:427
visionx::FakePointCloudProvider::getStereoCalibration
StereoCalibration getStereoCalibration(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:562
visionx::CapturingPointCloudProviderPropertyDefinitions
Definition: CapturingPointCloudProvider.h:38
filename
std::string filename
Definition: VisualizationRobot.cpp:84
armarx::RemoteGuiComponentPluginUser
Definition: RemoteGuiComponentPlugin.h:240
Component.h
visionx::CapturingPointCloudProvider
The CapturingPointCloudProvider provides a callback function to trigger the capturing of point clouds...
Definition: CapturingPointCloudProvider.h:56
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
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:314
IceUtil::Handle< class PropertyDefinitionContainer >
IceInternal::ProxyHandle<::IceProxy::armarx::RobotStateComponentInterface >
visionx::FakePointCloudProviderPropertyDefinitions::FakePointCloudProviderPropertyDefinitions
FakePointCloudProviderPropertyDefinitions(std::string prefix)
Definition: FakePointCloudProvider.cpp:57
visionx::FakePointCloudProvider::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: FakePointCloudProvider.cpp:105
visionx::FakePointCloudProvider::onInitCapturingPointCloudProvider
void onInitCapturingPointCloudProvider() override
Definition: FakePointCloudProvider.cpp:129
visionx::FakePointCloudProvider::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: FakePointCloudProvider.cpp:117
visionx::FakePointCloudProvider::getDefaultPointCloudFormat
MetaPointCloudFormatPtr getDefaultPointCloudFormat() override
default point cloud format used to initialize shared memory
Definition: FakePointCloudProvider.cpp:279
visionx::FakePointCloudProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:567
visionx::FakePointCloudProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &=Ice::emptyCurrent) override
Definition: FakePointCloudProvider.cpp:572
visionx::FakePointCloudProvider::getDefaultName
std::string getDefaultName() const override
Definition: FakePointCloudProvider.cpp:94
visionx::FakePointCloudProvider::doCapture
bool doCapture() override
Definition: FakePointCloudProvider.cpp:334
RemoteGuiComponentPlugin.h
ArmarXDataPath.h
ImageProvider.h
visionx::FakePointCloudProvider::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: FakePointCloudProvider.cpp:99
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18