VoxelGridCSpace.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2017, 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 ArmarX
19 * @author Mirko Waechter( mirko.waechter at kit dot edu)
20 * @date 2018
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "VoxelGridCSpace.h"
25
26#include <Eigen/Core>
27
28#include <VirtualRobot/CollisionDetection/CollisionModel.h>
29#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
30#include <VirtualRobot/Visualization/TriMeshUtils.h>
31#include <VirtualRobot/Visualization/VisualizationFactory.h>
32
35#include <ArmarXCore/interface/core/BasicVectorTypes.h>
36
37using namespace armarx;
38
39VoxelGridCSpace::VoxelGridCSpace(visionx::VoxelGridProviderInterfacePrx voxelGridProvider,
40 memoryx::CommonStorageInterfacePrx cs,
42 float stationaryObjectMargin) :
43 SimoxCSpace(cs, loadVisualizationModel, stationaryObjectMargin)
44{
45 this->voxelGridProvider = voxelGridProvider;
46}
47
48VirtualRobot::SceneObjectPtr
50{
51 auto gridPositionsEigen = armarx::transform(
52 gridPositions,
53 +[](armarx::Vector3f const& data) { return Eigen::Vector3f(data.e0, data.e1, data.e2); });
54
55
56 auto gridMesh = VirtualRobot::TriMeshUtils::CreateSparseBoxGrid(
57 Eigen::Matrix4f::Identity(),
58 gridPositionsEigen,
59 gridSize,
60 gridSize,
61 gridSize,
62 VirtualRobot::VisualizationFactory::Color::Blue());
63 gridMesh->mergeVertices(10);
64 gridMesh->fattenShrink(stationaryObjectMargin);
65 Eigen::Matrix4f id = Eigen::Matrix4f::Identity();
66 auto visu =
67 VirtualRobot::CoinVisualizationFactory().createTriMeshModelVisualization(gridMesh, id);
68 VirtualRobot::SceneObjectPtr obst(new VirtualRobot::SceneObject(
69 "PointCloudMeshGrid",
70 visu,
71 VirtualRobot::CollisionModelPtr(new VirtualRobot::CollisionModel(
72 visu, "PointCloudMeshGridCollisionModel", agentSceneObj->getCollisionChecker())),
73 VirtualRobot::SceneObject::Physics(),
74 const_cast<VirtualRobot::CDManager*>(&cd)->getCollisionChecker()));
75 return obst;
76}
77
78armarx::CSpaceBasePtr
79VoxelGridCSpace::clone(const Ice::Current&)
80{
81 return VoxelGridCSpaceBasePtr(new VoxelGridCSpace(*this));
82}
83
84void
86{
88 if (gridPositions.empty())
89 {
90 gridPositions = voxelGridProvider->getFilledGridPositions();
91 ARMARX_INFO << "Got grid with size: " << gridPositions.size();
92 gridSize = voxelGridProvider->getGridSize();
93 }
94 auto obst = createGridObstacle();
95 ARMARX_INFO << "Adding scene object with grid element count: " << gridPositions.size();
96 stationaryObjectSet->addSceneObject(obst);
97
98
99 ARMARX_INFO << "SceneObjects: "
101 stationaryObjectSet->getSceneObjects(),
102 +[](VirtualRobot::SceneObjectPtr const& obj) { return obj->getName(); });
103 if (!cd.hasSceneObjectSet(stationaryObjectSet))
104 {
105 cd.addCollisionModel(stationaryObjectSet);
106 }
107}
108
109CSpaceBasePtr
111{
112 // TIMING_START(SimoxCSpaceClone);
113 // VoxelGridCSpacePtr cloned = VoxelGridCSpacePtr::dynamicCast(clone(Ice::emptyCurrent));
114 VoxelGridCSpacePtr cloned =
115 new VoxelGridCSpace(voxelGridProvider, commonStorage, loadVisualizationModel);
116 cloned->gridPositions = gridPositions;
117 cloned->gridSize = gridSize;
118 cloned->stationaryObjectMargin = stationaryObjectMargin;
119 for (const auto& obj : stationaryObjects)
120 {
121 cloned->addStationaryObject(obj);
122 }
123 cloned->agentInfo = agentInfo;
125 cloned->initAgent();
126 // TIMING_END(SimoxCSpaceClone);
127 return cloned;
128}
constexpr T c
VirtualRobot::CDManager cd
The collision checker.
VirtualRobot::RobotPtr agentSceneObj
bool loadVisualizationModel
Whether the visualization model of objects/agents sould be loaded.
VirtualRobot::SceneObjectSetPtr stationaryObjectSet
The scene objects for stationary objects.
void initCollisionTest(const Ice::Current &=Ice::emptyCurrent) override
Initializes the collision test.
SimoxCSpace(memoryx::CommonStorageInterfacePrx commonStoragePrx, bool loadVisualizationModel=false, float stationaryObjectMargin=0.0f)
ctor
void initCollisionTest(const Ice::Current &) override
VirtualRobot::SceneObjectPtr createGridObstacle() const
armarx::CSpaceBasePtr clone(const Ice::Current &) override
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< VoxelGridCSpace > VoxelGridCSpacePtr
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