util.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 Navigation::ArmarXObjects::util
17  * @author Fabian Reister ( fabian dot reister at kit dot edu )
18  * @author Christian R. G. Dreher ( c dot dreher at kit dot edu )
19  * @date 2021
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "util.h"
25 
26 #include <string>
27 
28 #include <Eigen/Geometry>
29 
30 #include <VirtualRobot/CollisionDetection/CollisionModel.h>
31 #include <VirtualRobot/SceneObject.h>
32 #include <VirtualRobot/SceneObjectSet.h>
33 #include <VirtualRobot/VirtualRobot.h>
34 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
35 
37 
41 
43 {
44 
45  VirtualRobot::SceneObjectSetPtr
47  const OccupancyGridHelper::Params& params)
48  {
49  const OccupancyGridHelper ocHelper(occupancyGrid, params);
50  const auto obstacles = ocHelper.obstacles();
51 
52  const float boxSize = occupancyGrid.resolution;
53  const float resolution = occupancyGrid.resolution;
54 
55  VirtualRobot::SceneObjectSetPtr sceneObjects(new VirtualRobot::SceneObjectSet);
56 
57  ARMARX_CHECK_EQUAL(occupancyGrid.frame, GlobalFrame)
58  << "Only occupancy grid in global frame supported.";
59 
60  VirtualRobot::CoinVisualizationFactory factory;
61 
62  const Eigen::Isometry3f& world_T_map = occupancyGrid.pose;
63 
64  for (int x = 0; x < obstacles.rows(); x++)
65  {
66  for (int y = 0; y < obstacles.cols(); y++)
67  {
68  if (obstacles(x, y))
69  {
70  const Eigen::Vector3f pos{
71  static_cast<float>(x * resolution), static_cast<float>(y * resolution), 0};
72 
73  Eigen::Isometry3f map_T_obj = Eigen::Isometry3f::Identity();
74  map_T_obj.translation() = pos;
75 
76  Eigen::Isometry3f world_T_obj = world_T_map * map_T_obj;
77 
78  auto cube = factory.createBox(boxSize, boxSize, boxSize);
79 
80  VirtualRobot::CollisionModelPtr collisionModel(
81  new VirtualRobot::CollisionModel(cube));
82 
83  VirtualRobot::SceneObjectPtr sceneObject(new VirtualRobot::SceneObject(
84  "box_" + std::to_string(sceneObjects->getSize()), cube, collisionModel));
85  sceneObject->setGlobalPose(world_T_obj.matrix());
86 
87  sceneObjects->addSceneObject(sceneObject);
88  }
89  }
90  }
91 
92  return sceneObjects;
93  }
94 } // namespace armarx::navigation::util
armarx::armem::vision::OccupancyGrid
Definition: types.h:36
armarx::navigation::util
This file is part of ArmarX.
Definition: geometry.cpp:12
armarx::GlobalFrame
const std::string GlobalFrame
Definition: FramedPose.h:65
armarx::OccupancyGridHelper
Definition: OccupancyGridHelper.h:23
armarx::armem::vision::OccupancyGrid::frame
std::string frame
Definition: types.h:40
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
util.h
FramedPose.h
armarx::navigation::util::asSceneObjects
VirtualRobot::SceneObjectSetPtr asSceneObjects(const armem::vision::OccupancyGrid &occupancyGrid, const OccupancyGridHelper::Params &params)
Definition: util.cpp:46
armarx::detail::OccupancyGridHelperParams
Definition: OccupancyGridHelper.h:16
armarx::OccupancyGridHelper::obstacles
BinaryArray obstacles() const
Definition: OccupancyGridHelper.cpp:34
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
armarx::armem::vision::OccupancyGrid::resolution
float resolution
Definition: types.h:38
ExpressionException.h
types.h
OccupancyGridHelper.h
scene3D::SceneObjectPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr
Definition: PointerDefinitions.h:40
ARMARX_CHECK_EQUAL
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
Definition: ExpressionException.h:130
armarx::armem::vision::OccupancyGrid::pose
Eigen::Isometry3f pose
Definition: types.h:41