SimoxObjectShape.cpp
Go to the documentation of this file.
1 #include "SimoxObjectShape.h"
2 
3 #include <SimoxUtility/shapes/AxisAlignedBoundingBox.h>
4 
5 #include <VirtualRobot/ManipulationObject.h>
6 #include <VirtualRobot/math/Helpers.h>
7 #include <VirtualRobot/Visualization/TriMeshModel.h>
8 
9 
10 namespace armarx::semantic
11 {
12 
14 
15  SimoxObjectShape::SimoxObjectShape(const VirtualRobot::ManipulationObjectPtr& object,
16  const std::string& objectClassName)
17  : object(object)
18  , objectClassName(objectClassName)
19  { }
20 
21  Eigen::Vector3f SimoxObjectShape::getPosition() const
22  {
23  return object->getGlobalPosition();
24  }
25 
26  void SimoxObjectShape::setPosition(const Eigen::Vector3f& position)
27  {
28  Eigen::Matrix4f pose = object->getGlobalPose();
29  math::Helpers::Position(pose) = position;
30  object->setGlobalPose(pose);
31  }
32 
34  {
35  return Eigen::Quaternionf(object->getGlobalOrientation());
36  }
37 
39  {
40  Eigen::Matrix4f pose = object->getGlobalPose();
41  math::Helpers::Orientation(pose) = Eigen::Matrix3f(orientation);
42  object->setGlobalPose(pose);
43  }
44 
45  semrel::TriMesh SimoxObjectShape::getTriMeshLocal() const
46  {
47  VirtualRobot::TriMeshModelPtr triMesh = object->getCollisionModel()->getTriMeshModel();
48 
49  std::vector<VirtualRobot::MathTools::TriangleFace> const& faces = triMesh->faces;
50  std::vector<Eigen::Vector3f> const& vertices = triMesh->vertices;
51  //std::vector<Eigen::Vector3f> const& normals = triMesh->normals;
52 
53  semrel::TriMesh result;
54 
55  for (VirtualRobot::MathTools::TriangleFace const& face : faces)
56  {
57  Eigen::Vector3f v0 = vertices.at(face.id1);
58  Eigen::Vector3f v1 = vertices.at(face.id2);
59  Eigen::Vector3f v2 = vertices.at(face.id3);
60 
61  Eigen::Vector3f normal = face.normal;
62 
63  semrel::TriMesh::Triangle triangle;
64  triangle.v0 = result.numVertices();
65  result.addVertex(v0);
66  triangle.v1 = result.numVertices();
67  result.addVertex(v1);
68  triangle.v2 = result.numVertices();
69  result.addVertex(v2);
70 
71  int n = result.numNormals();
72  triangle.n0 = n;
73  triangle.n1 = n;
74  triangle.n2 = n;
75  result.addNormal(normal);
76 
77  result.addTriangle(triangle);
78  }
79 
80  return result;
81  }
82 
83 
85  {
86  const VirtualRobot::BoundingBox& bb = object->getCollisionModel()->getTriMeshModel()->boundingBox;
87  return { bb.getMin(), bb.getMax() };
88  }
89 
90 
92  {
93  const std::vector<Eigen::Vector3f> vertices = object->getCollisionModel()->getModelVeticesGlobal();
94 
96  for (Eigen::Vector3f v : vertices)
97  {
98  aabb.expand_to(v);
99  }
100 
101  return { aabb.limits() };
102  }
103 
104  std::shared_ptr<btCollisionShape> SimoxObjectShape::getBulletCollisionShape(float margin) const
105  {
106  (void) margin;
107  return nullptr;
108  }
109 
110  void SimoxObjectShape::addMargin(float margin)
111  {
112  // TODO: Implement
113  (void) margin;
114  }
115 
116  std::string SimoxObjectShape::tagPrefix() const
117  {
118  return object->getName();
119  }
120 
121 
122 }
armarx::semantic::SimoxObjectShape::setPosition
void setPosition(Eigen::Vector3f const &position) override
Definition: SimoxObjectShape.cpp:26
armarx::semantic::SimoxObjectShape::addMargin
void addMargin(float margin) override
Definition: SimoxObjectShape.cpp:110
armarx::semantic::SimoxObjectShape::setOrientation
void setOrientation(Eigen::Quaternionf const &orientation) override
Definition: SimoxObjectShape.cpp:38
GfxTL::Orientation
ScalarT Orientation(const VectorXD< 2, ScalarT > &p1, const VectorXD< 2, ScalarT > &p2, const VectorXD< 2, ScalarT > &c)
Definition: Orientation.h:9
armarx::semantic::SimoxObjectShape::getOrientation
Eigen::Quaternionf getOrientation() const override
Definition: SimoxObjectShape.cpp:33
armarx::semantic::SimoxObjectShape::getAABB
semrel::AxisAlignedBoundingBox getAABB() const override
Definition: SimoxObjectShape.cpp:91
armarx::semantic::SimoxObjectShape::getAABBLocal
semrel::AxisAlignedBoundingBox getAABBLocal() const override
Definition: SimoxObjectShape.cpp:84
armarx::aron::simox::arondto::AxisAlignedBoundingBox
::simox::arondto::AxisAlignedBoundingBox AxisAlignedBoundingBox
Definition: simox.h:14
armarx::semantic::SimoxObjectShape::getTriMeshLocal
semrel::TriMesh getTriMeshLocal() const override
Definition: SimoxObjectShape.cpp:45
Eigen::Quaternionf
Quaternion< float, 0 > Quaternionf
Definition: EigenForwardDeclarations.h:61
armarx::semantic::SimoxObjectShape::getPosition
Eigen::Vector3f getPosition() const override
Definition: SimoxObjectShape.cpp:21
armarx::semantic::SimoxObjectShape::tagPrefix
std::string tagPrefix() const override
Definition: SimoxObjectShape.cpp:116
armarx::semantic::SimoxObjectShape::getBulletCollisionShape
std::shared_ptr< btCollisionShape > getBulletCollisionShape(float margin) const override
Definition: SimoxObjectShape.cpp:104
armarx::semantic
Definition: ShapesSupportRelations.cpp:32
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::semantic::SimoxObjectShape::SimoxObjectShape
SimoxObjectShape()
armarx::Quaternion< float, 0 >
armarx::navigation::core::Position
Eigen::Vector3f Position
Definition: basic_types.h:36
SimoxObjectShape.h
armarx::semantic::SimoxObjectShape::object
VirtualRobot::ManipulationObjectPtr object
Definition: SimoxObjectShape.h:40