FilterKnownObjects.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package VisionX::ArmarXObjects::FilterKnownObjects
17  * @author Markus Grotz ( markus dot grotz at kit dot edu )
18  * @date 2022
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #include "FilterKnownObjects.h"
24 
25 #include <Eigen/Core>
26 
28 
30 
31 namespace armarx
32 {
33 
36  {
39  def->optional(properties.visualization, "Visualization");
40  def->optional(properties.resizeOBBFactor, "ResizeOBBFactor");
41  return def;
42  }
43 
44  void
46  {
47  filter.setNegative(true);
48  // filter.setKeepOrganized(true);
49  }
50 
51  void
53  {
54  enableResultPointClouds<PointT>(getName() + "Result");
55  enableResultPointClouds<PointT>(getName() + "RemovedObjects");
56 
57  {
60  }
61  }
62 
63  void
65  {
66  }
67 
68  void
70  {
71  }
72 
73  void
75  {
76  // Fetch input point cloud.
77  pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
78  pcl::PointCloud<PointT>::Ptr removedObjects(new pcl::PointCloud<PointT>());
79 
80  if (waitForPointClouds())
81  {
82  getPointClouds(inputCloud);
83  }
84  else
85  {
86  ARMARX_VERBOSE << "Timeout or error while waiting for point cloud data.";
87  return;
88  }
89 
90 
91  viz::Layer layer = arviz.layer("OBBB");
92  std::vector<std::string> objects_removed;
93 
94  const std::vector<objpose::ObjectPose> objectPoses = ObjectPoseClient::getObjectPoses();
95  for (const objpose::ObjectPose& objectPose : objectPoses)
96  {
97 
98 
99  if (!objectPose.oobbGlobal().has_value())
100  {
101  ARMARX_INFO << "no object bounding box";
102  continue;
103  }
104 
105 
106  std::string s = objectPose.objectID.str();
107 
109  s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
110 
111  if (s.find("building") != std::string::npos)
112  {
113  continue;
114  }
115 
116  if (s.find("interior") != std::string::npos)
117  {
118  continue;
119  }
120 
121  if (s.find("workbench") != std::string::npos)
122  {
123  continue;
124  }
125 
126 
127  objects_removed.push_back(objectPose.objectID.str());
128 
129  const Eigen::Matrix4f globalPose = objectPose.objectPoseGlobal;
130 
131  const simox::OrientedBoxf localOOBB = objectPose.localOOBB.value();
132 
133  Eigen::Vector3f dim = localOOBB.dimensions();
134  dim += Eigen::Vector3f::Ones() * properties.resizeOBBFactor;
135 
136  Eigen::Vector3f maxPt = dim / 2.0;
137  Eigen::Vector3f minPt = -1.0 * maxPt;
138 
139  Eigen::Matrix4f m = globalPose * localOOBB.transformation_centered();
140  Eigen::Affine3f transform;
141  transform.matrix() = m;
142 
143  filter.setTransform(transform.inverse());
144  filter.setMin(Eigen::Vector4f(minPt.x(), minPt.y(), minPt.z(), 1.0));
145  filter.setMax(Eigen::Vector4f(maxPt.x(), maxPt.y(), maxPt.z(), 1.0));
146 
147  filter.setInputCloud(inputCloud);
148 
149  filter.setNegative(false);
150  pcl::PointCloud<PointT>::Ptr object(new pcl::PointCloud<PointT>());
151  filter.filter(*object);
152  (*removedObjects) += (*object);
153 
154  filter.setNegative(true);
155  filter.filter(*inputCloud);
156 
157  if (properties.visualization)
158  {
159  viz::Box b("oobb" + s);
160  b.pose(m);
161  b.size(dim);
162  b.color(simox::Color::blue(128, 128));
163  layer.add(b);
164  }
165 
166  //const simox::OrientedBoxf globalOOBB = objectPose.oobbGlobal().value();
167  //layer.add(viz::Box("box_" + s).set(globalOOBB).color(simox::Color::red(128, 128)));
168  }
169  ARMARX_INFO << deactivateSpam(5) << "removed " << VAROUT(objects_removed)
170  << " from point cloud";
171 
172  if (properties.visualization)
173  {
174  arviz.commit(layer);
175  }
176 
177  // Publish result point cloud.
178  provideResultPointClouds(inputCloud, getName() + "Result");
179  provideResultPointClouds(removedObjects, getName() + "RemovedObjects");
180  }
181 
182  void
184  {
185  using namespace armarx::RemoteGui::Client;
186 
187  // Setup the layout.
188 
189  GridLayout grid;
190  int row = 0;
191  {
192 
193  grid.add(tab.extractGrasps, {row, 0}, {2, 1});
194  ++row;
195  }
196 
197  VBoxLayout root = {grid, VSpacer()};
198  RemoteGui_createTab(getName(), root, &tab);
199  }
200 
201  void
203  {
204  }
205 
206  std::string
208  {
209  return GetDefaultName();
210  }
211 
213 
214 
215 } // namespace armarx
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:89
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::FilterKnownObjects
Brief description of class FilterKnownObjects.
Definition: FilterKnownObjects.h:52
armarx::FilterKnownObjects::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:45
armarx::RemoteGui::Client::VBoxLayout
Definition: Widgets.h:167
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
Pose.h
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:438
armarx::FilterKnownObjects::RemoteGui_update
void RemoteGui_update() override
After calling RemoteGui_startRunningTask, this function is called periodically in a separate thread.
Definition: FilterKnownObjects.cpp:202
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:31
armarx::RemoteGui::Client::VSpacer
Definition: Widgets.h:204
FilterKnownObjects.h
armarx::FilterKnownObjects::process
void process() override
Definition: FilterKnownObjects.cpp:74
armarx::FilterKnownObjects::getDefaultName
std::string getDefaultName() const override
Definition: FilterKnownObjects.cpp:207
armarx::RemoteGui::Client::GridLayout
Definition: Widgets.h:186
armarx_add_component
armarx_add_component(COMPONENT_LIBS ArmarXCoreInterfaces ArmarXCore ${Boost_LIBRARIES} SOURCES ExternalApplicationManager.cpp ExternalApplicationManagerStarter.cpp ExternalApplicationManagerDependency.cpp HEADERS ExternalApplicationManager.h ExternalApplicationManagerStarter.h ExternalApplicationManagerDependency.h) target_include_directories(ExternalApplicationManager PUBLIC $
Definition: CMakeLists.txt:11
visionx::PointCloudProcessor::provideResultPointClouds
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
Definition: PointCloudProcessor.h:288
armarx::ARMARX_REGISTER_COMPONENT_EXECUTABLE
ARMARX_REGISTER_COMPONENT_EXECUTABLE(RemoteGuiExample2, RemoteGuiExample2::GetDefaultName())
armarx::FilterKnownObjects::createRemoteGuiTab
void createRemoteGuiTab()
This function should be called once in onConnect() or when you need to re-create the Remote GUI tab.
Definition: FilterKnownObjects.cpp:183
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:458
armarx::viz::Box
Definition: Elements.h:47
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:166
armarx::FilterKnownObjects::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: FilterKnownObjects.cpp:35
visionx::PointCloudProcessor::getPointClouds
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
Definition: PointCloudProcessor.h:380
armarx::transform
auto transform(const Container< InputT, Alloc > &in, OutputT(*func)(InputT const &)) -> Container< OutputT, typename std::allocator_traits< Alloc >::template rebind_alloc< OutputT >>
Convenience function (with less typing) to transform a container of type InputT into the same contain...
Definition: algorithm.h:351
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:119
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
Decoupled.h
armarx::FilterKnownObjects::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:64
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::viz::ElementOps::pose
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition: ElementOps.h:176
armarx::ArVizComponentPluginUser::arviz
armarx::viz::Client arviz
Definition: ArVizComponentPlugin.h:42
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:198
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_createTab
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
Definition: LightweightRemoteGuiComponentPlugin.cpp:103
IceUtil::Handle
Definition: forward_declarations.h:30
armarx::viz::Box::size
Box & size(Eigen::Vector3f const &s)
Definition: Elements.h:52
armarx::viz::ElementOps::color
DerivedT & color(Color color)
Definition: ElementOps.h:218
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:99
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:80
armarx::FilterKnownObjects::GetDefaultName
static std::string GetDefaultName()
Definition: FilterKnownObjects.h:66
armarx::RemoteGui::Client
Definition: EigenWidgets.cpp:8
armarx::viz::Layer
Definition: Layer.h:12
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::FilterKnownObjects::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:52
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:33
armarx::ObjectPoseClientPluginUser::getObjectPoses
objpose::ObjectPoseSeq getObjectPoses()
Definition: ObjectPoseClientPlugin.cpp:76
armarx::FilterKnownObjects::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:69