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"
25 
26 
27 #include <Eigen/Core>
28 
30 
31 
32 namespace armarx
33 {
34 
36  {
38  def->optional(properties.visualization, "Visualization");
39  def->optional(properties.resizeOBBFactor, "ResizeOBBFactor");
40  return def;
41  }
42 
43 
45  {
46  filter.setNegative(true);
47  // filter.setKeepOrganized(true);
48  }
49 
50 
52  {
53  enableResultPointClouds<PointT>(getName() + "Result");
54  enableResultPointClouds<PointT>(getName() + "RemovedObjects");
55 
56  {
59  }
60 
61  }
62 
63 
65  {
66  }
67 
69  {
70  }
71 
72 
74  {
75  // Fetch input point cloud.
76  pcl::PointCloud<PointT>::Ptr inputCloud(new pcl::PointCloud<PointT>());
77  pcl::PointCloud<PointT>::Ptr removedObjects(new pcl::PointCloud<PointT>());
78 
79  if (waitForPointClouds())
80  {
81  getPointClouds(inputCloud);
82  }
83  else
84  {
85  ARMARX_VERBOSE << "Timeout or error while waiting for point cloud data.";
86  return;
87  }
88 
89 
90  viz::Layer layer = arviz.layer("OBBB");
91  std::vector<std::string> objects_removed;
92 
93  const std::vector<objpose::ObjectPose> objectPoses = ObjectPoseClient::getObjectPoses();
94  for (const objpose::ObjectPose& objectPose : objectPoses)
95  {
96 
97 
98  if (!objectPose.oobbGlobal().has_value())
99  {
100  ARMARX_INFO << "no object bounding box";
101  continue;
102  }
103 
104 
105  std::string s = objectPose.objectID.str();
106 
107  std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c){
108  return std::tolower(c); });
109 
110  if(s.find("building") != std::string::npos)
111  {
112  continue;
113  }
114 
115  if(s.find("interior") != std::string::npos)
116  {
117  continue;
118  }
119 
120  if(s.find("workbench") != std::string::npos)
121  {
122  continue;
123  }
124 
125 
126  objects_removed.push_back(objectPose.objectID.str());
127 
128  const Eigen::Matrix4f globalPose = objectPose.objectPoseGlobal;
129 
130  const simox::OrientedBoxf localOOBB = objectPose.localOOBB.value();
131 
132  Eigen::Vector3f dim = localOOBB.dimensions();
133  dim += Eigen::Vector3f::Ones() * properties.resizeOBBFactor;
134 
135  Eigen::Vector3f maxPt = dim / 2.0;
136  Eigen::Vector3f minPt = -1.0 * maxPt;
137 
138  Eigen::Matrix4f m = globalPose * localOOBB.transformation_centered();
139  Eigen::Affine3f transform;
140  transform.matrix() = m;
141 
142  filter.setTransform(transform.inverse());
143  filter.setMin(Eigen::Vector4f(minPt.x(), minPt.y(), minPt.z(), 1.0));
144  filter.setMax(Eigen::Vector4f(maxPt.x(), maxPt.y(), maxPt.z(), 1.0));
145 
146  filter.setInputCloud(inputCloud);
147 
148  filter.setNegative(false);
149  pcl::PointCloud<PointT>::Ptr object(new pcl::PointCloud<PointT>());
150  filter.filter(*object);
151  (*removedObjects) += (*object);
152 
153  filter.setNegative(true);
154  filter.filter(*inputCloud);
155 
156  if (properties.visualization)
157  {
158  viz::Box b("oobb" + s);
159  b.pose(m);
160  b.size(dim);
161  b.color(simox::Color::blue(128, 128));
162  layer.add(b);
163  }
164 
165  //const simox::OrientedBoxf globalOOBB = objectPose.oobbGlobal().value();
166  //layer.add(viz::Box("box_" + s).set(globalOOBB).color(simox::Color::red(128, 128)));
167  }
168  ARMARX_INFO << deactivateSpam(5) << "removed " << VAROUT(objects_removed) << " from point cloud";
169 
170  if (properties.visualization)
171  {
172  arviz.commit(layer);
173  }
174 
175  // Publish result point cloud.
176  provideResultPointClouds(inputCloud, getName() + "Result");
177  provideResultPointClouds(removedObjects, getName() + "RemovedObjects");
178  }
179 
180 
182  {
183  using namespace armarx::RemoteGui::Client;
184 
185  // Setup the layout.
186 
187  GridLayout grid;
188  int row = 0;
189  {
190 
191  grid.add(tab.extractGrasps, {row, 0}, {2, 1});
192  ++row;
193  }
194 
195  VBoxLayout root = {grid, VSpacer()};
196  RemoteGui_createTab(getName(), root, &tab);
197  }
198 
199 
201  {
202 
203  }
204 
206  {
207  return GetDefaultName();
208  }
209 
210 
212 
213 
214 
215 } // namespace armarx
armarx::viz::Client::commit
CommitResult commit(StagedCommit const &commit)
Definition: Client.cpp:80
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::FilterKnownObjects
Brief description of class FilterKnownObjects.
Definition: FilterKnownObjects.h:53
armarx::FilterKnownObjects::onInitPointCloudProcessor
void onInitPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:44
armarx::RemoteGui::Client::VBoxLayout
Definition: Widgets.h:167
Pose.h
armarx::RemoteGui::Client::GridLayout::add
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition: Widgets.cpp:412
armarx::FilterKnownObjects::RemoteGui_update
void RemoteGui_update() override
After calling RemoteGui_startRunningTask, this function is called periodically in a separate thread.
Definition: FilterKnownObjects.cpp:200
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::viz::Layer::add
void add(ElementT const &element)
Definition: Layer.h:29
armarx::RemoteGui::Client::VSpacer
Definition: Widgets.h:204
FilterKnownObjects.h
armarx::FilterKnownObjects::process
void process() override
Definition: FilterKnownObjects.cpp:73
armarx::FilterKnownObjects::getDefaultName
std::string getDefaultName() const override
Definition: FilterKnownObjects.cpp:205
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:286
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:181
visionx::PointCloudProcessor::waitForPointClouds
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
Definition: PointCloudProcessor.cpp:433
armarx::viz::Box
Definition: Elements.h:51
visionx::PointCloudProcessorPropertyDefinitions
Properties of PointCloudProcessor.
Definition: PointCloudProcessor.h:173
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:373
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_startRunningTask
void RemoteGui_startRunningTask()
Definition: LightweightRemoteGuiComponentPlugin.cpp:110
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
Decoupled.h
armarx::FilterKnownObjects::onDisconnectPointCloudProcessor
void onDisconnectPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:64
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::viz::ElementOps::pose
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition: ElementOps.h:159
armarx::ArVizComponentPluginUser::arviz
armarx::viz::Client arviz
Definition: ArVizComponentPlugin.h:43
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
armarx::LightweightRemoteGuiComponentPluginUser::RemoteGui_createTab
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
Definition: LightweightRemoteGuiComponentPlugin.cpp:95
IceUtil::Handle< class PropertyDefinitionContainer >
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:315
armarx::viz::Box::size
Box & size(Eigen::Vector3f const &s)
Definition: Elements.h:55
armarx::viz::ElementOps::color
DerivedT & color(Color color)
Definition: ElementOps.h:195
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:92
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:107
armarx::viz::Client::layer
Layer layer(std::string const &name) const
Definition: Client.cpp:73
armarx::FilterKnownObjects::GetDefaultName
static std::string GetDefaultName()
Definition: FilterKnownObjects.h:67
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:28
armarx::FilterKnownObjects::onConnectPointCloudProcessor
void onConnectPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:51
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:36
armarx::ObjectPoseClientPluginUser::getObjectPoses
objpose::ObjectPoseSeq getObjectPoses()
Definition: ObjectPoseClientPlugin.cpp:70
armarx::FilterKnownObjects::onExitPointCloudProcessor
void onExitPointCloudProcessor() override
Definition: FilterKnownObjects.cpp:68