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 #include <ArmarXCore/interface/core/BasicVectorTypes.h>
28 #include <VirtualRobot/Visualization/TriMeshUtils.h>
31 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
32 #include <VirtualRobot/Visualization/VisualizationFactory.h>
33 
34 using namespace armarx;
35 
36 VoxelGridCSpace::VoxelGridCSpace(visionx::VoxelGridProviderInterfacePrx voxelGridProvider, memoryx::CommonStorageInterfacePrx cs, bool loadVisualizationModel, float stationaryObjectMargin)
37  : SimoxCSpace(cs, loadVisualizationModel, stationaryObjectMargin)
38 {
39  this->voxelGridProvider = voxelGridProvider;
40 }
41 
43 {
44  auto gridPositionsEigen = armarx::transform(gridPositions, +[](armarx::Vector3f const & data)
45  {
46  return Eigen::Vector3f(data.e0, data.e1, data.e2);
47  });
48 
49 
50 
51  auto gridMesh = VirtualRobot::TriMeshUtils::CreateSparseBoxGrid(Eigen::Matrix4f::Identity(), gridPositionsEigen,
52  gridSize, gridSize, gridSize,
53  VirtualRobot::VisualizationFactory::Color::Blue()
54  );
55  gridMesh->mergeVertices(10);
56  gridMesh->fattenShrink(stationaryObjectMargin);
58  auto visu = VirtualRobot::CoinVisualizationFactory().createTriMeshModelVisualization(gridMesh, id);
59  VirtualRobot::SceneObjectPtr obst(new VirtualRobot::SceneObject("PointCloudMeshGrid", visu,
60  VirtualRobot::CollisionModelPtr(new VirtualRobot::CollisionModel(visu, "PointCloudMeshGridCollisionModel", agentSceneObj->getCollisionChecker())),
61  VirtualRobot::SceneObject::Physics(), const_cast<VirtualRobot::CDManager*>(&cd)->getCollisionChecker()));
62  return obst;
63 }
64 
65 
66 
67 armarx::CSpaceBasePtr VoxelGridCSpace::clone(const Ice::Current&)
68 {
69  return VoxelGridCSpaceBasePtr(new VoxelGridCSpace(*this));
70 }
71 
72 void VoxelGridCSpace::initCollisionTest(const Ice::Current& c)
73 {
75  if (gridPositions.empty())
76  {
77  gridPositions = voxelGridProvider->getFilledGridPositions();
78  ARMARX_INFO << "Got grid with size: " << gridPositions.size();
79  gridSize = voxelGridProvider->getGridSize();
80 
81  }
82  auto obst = createGridObstacle();
83  ARMARX_INFO << "Adding scene object with grid element count: " << gridPositions.size();
84  stationaryObjectSet->addSceneObject(obst);
85 
86 
87  ARMARX_INFO << "SceneObjects: " << armarx::transform(stationaryObjectSet->getSceneObjects(), +[](VirtualRobot::SceneObjectPtr const & obj)
88  {
89  return obj->getName();
90  });
91  if (!cd.hasSceneObjectSet(stationaryObjectSet))
92  {
93  cd.addCollisionModel(stationaryObjectSet);
94  }
95 }
96 
97 
98 CSpaceBasePtr armarx::VoxelGridCSpace::clone(bool loadVisualizationModel)
99 {
100  // TIMING_START(SimoxCSpaceClone);
101  // VoxelGridCSpacePtr cloned = VoxelGridCSpacePtr::dynamicCast(clone(Ice::emptyCurrent));
102  VoxelGridCSpacePtr cloned = new VoxelGridCSpace(voxelGridProvider, commonStorage, loadVisualizationModel);
103  cloned->gridPositions = gridPositions;
104  cloned->gridSize = gridSize;
105  cloned->stationaryObjectMargin = stationaryObjectMargin;
106  for (const auto& obj : stationaryObjects)
107  {
108  cloned->addStationaryObject(obj);
109  }
110  cloned->agentInfo = agentInfo;
111  ARMARX_CHECK_EXPRESSION(agentSceneObj);
112  cloned->initAgent();
113  // TIMING_END(SimoxCSpaceClone);
114  return cloned;
115 }
algorithm.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::VoxelGridCSpace::clone
armarx::CSpaceBasePtr clone(const Ice::Current &) override
Definition: VoxelGridCSpace.cpp:67
IceInternal::Handle
Definition: forward_declarations.h:8
VoxelGridCSpace.h
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:523
armarx::VoxelGridCSpace::createGridObstacle
VirtualRobot::SceneObjectPtr createGridObstacle() const
Definition: VoxelGridCSpace.cpp:42
armarx::VoxelGridCSpace
Definition: VoxelGridCSpace.h:33
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::VoxelGridCSpace::initCollisionTest
void initCollisionTest(const Ice::Current &) override
Definition: VoxelGridCSpace.cpp:72
NotImplementedYetException.h
armarx::SimoxCSpace::initCollisionTest
void initCollisionTest(const Ice::Current &=Ice::emptyCurrent) override
Initializes the collision test.
Definition: SimoxCSpace.cpp:192
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
armarx::SimoxCSpace::stationaryObjectSet
VirtualRobot::SceneObjectSetPtr stationaryObjectSet
The scene objects for stationary objects.
Definition: SimoxCSpace.h:285
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
scene3D::SceneObjectPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr
Definition: PointerDefinitions.h:40
armarx::SimoxCSpace::cd
VirtualRobot::CDManager cd
The collision checker.
Definition: SimoxCSpace.h:280
armarx::SimoxCSpace::agentSceneObj
VirtualRobot::RobotPtr agentSceneObj
Definition: SimoxCSpace.h:289
armarx::SimoxCSpace
The SimoxCSpace contains a set of stationary obstacles and an agent.
Definition: SimoxCSpace.h:67
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28