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
31namespace 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
62
63 void
67
68 void
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
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
108 std::transform(
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
205
206 std::string
208 {
209 return GetDefaultName();
210 }
211
213
214
215} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
#define VAROUT(x)
constexpr T c
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Brief description of class FilterKnownObjects.
void RemoteGui_update() override
After calling RemoteGui_startRunningTask, this function is called periodically in a separate thread.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void onExitPointCloudProcessor() override
void onConnectPointCloudProcessor() override
void onDisconnectPointCloudProcessor() override
static std::string GetDefaultName()
void onInitPointCloudProcessor() override
void createRemoteGuiTab()
This function should be called once in onConnect() or when you need to re-create the Remote GUI tab.
std::string getDefaultName() const override
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
std::string getName() const
Retrieve name of object.
DerivedT & pose(Eigen::Matrix4f const &pose)
Definition ElementOps.h:176
DerivedT & color(Color color)
Definition ElementOps.h:218
void enableResultPointClouds(std::string resultProviderName="")
Enables visualization.
int getPointClouds(const PointCloudPtrT &pointCloudPtr)
Poll PointClouds from provider.
bool waitForPointClouds(int milliseconds=1000)
Wait for new PointClouds.
void provideResultPointClouds(const PointCloudPtrT &pointClouds, std::string providerName="")
sends result PointClouds for visualization
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
This file offers overloads of toIce() and fromIce() functions for STL container types.
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
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void RemoteGui_createTab(std::string const &name, RemoteGui::Client::Widget const &rootWidget, RemoteGui::Client::Tab *tab)
GridLayout & add(Widget const &child, Pos pos, Span span=Span{1, 1})
Definition Widgets.cpp:438
An object pose as stored by the ObjectPoseStorage.
Definition ObjectPose.h:34
Box & size(Eigen::Vector3f const &s)
Definition Elements.h:52
void add(ElementT const &element)
Definition Layer.h:31