13 #include "omplapp/geometry/detail/assimpUtil.h"
17 void ompl::app::scene::inferBounds(base::RealVectorBounds &bounds,
const std::vector<aiVector3D> &vertices,
double multiply,
double add)
19 double minX = std::numeric_limits<double>::infinity();
25 for (
const auto & vertex : vertices)
27 if (minX > vertex.x) minX = vertex.x;
28 if (maxX < vertex.x) maxX = vertex.x;
29 if (minY > vertex.y) minY = vertex.y;
30 if (maxY < vertex.y) maxY = vertex.y;
31 if (minZ > vertex.z) minZ = vertex.z;
32 if (maxZ < vertex.z) maxZ = vertex.z;
39 OMPL_WARN(
"The multiplicative factor in the bounds computation process should be larger than 1.0");
44 OMPL_WARN(
"The additive factor in the bounds computation process should be larger than 0.0");
47 double dx = (maxX - minX) * multiply + add;
48 double dy = (maxY - minY) * multiply + add;
49 double dz = (maxZ - minZ) * multiply + add;
50 bounds.low[0] = minX - dx; bounds.low[1] = minY - dy; bounds.low[2] = minZ - dz;
51 bounds.high[0] = maxX + dx; bounds.high[1] = maxY + dy; bounds.high[2] = maxZ + dz;
63 void extractVerticesAux(
const aiScene *scene,
const aiNode *node, aiMatrix4x4 transform,
64 std::vector<aiVector3D> &vertices)
66 transform *= node->mTransformation;
67 for (
unsigned int i = 0 ; i < node->mNumMeshes; ++i)
69 const aiMesh* a = scene->mMeshes[node->mMeshes[i]];
70 for (
unsigned int i = 0 ; i < a->mNumVertices ; ++i)
71 vertices.push_back(transform * a->mVertices[i]);
74 for (
unsigned int n = 0; n < node->mNumChildren; ++n)
75 extractVerticesAux(scene, node->mChildren[n], transform, vertices);
78 void extractTrianglesAux(
const aiScene *scene,
const aiNode *node, aiMatrix4x4 transform,
79 std::vector<aiVector3D> &triangles)
81 transform *= node->mTransformation;
82 for (
unsigned int i = 0 ; i < node->mNumMeshes; ++i)
84 const aiMesh* a = scene->mMeshes[node->mMeshes[i]];
85 for (
unsigned int i = 0 ; i < a->mNumFaces ; ++i)
86 if (a->mFaces[i].mNumIndices == 3)
88 triangles.push_back(transform * a->mVertices[a->mFaces[i].mIndices[0]]);
89 triangles.push_back(transform * a->mVertices[a->mFaces[i].mIndices[1]]);
90 triangles.push_back(transform * a->mVertices[a->mFaces[i].mIndices[2]]);
94 for (
unsigned int n = 0; n < node->mNumChildren; ++n)
95 extractTrianglesAux(scene, node->mChildren[n], transform, triangles);
102 void ompl::app::scene::extractVertices(
const aiScene *scene, std::vector<aiVector3D> &vertices)
105 if ((scene !=
nullptr) && scene->HasMeshes())
106 extractVerticesAux(scene, scene->mRootNode, aiMatrix4x4(), vertices);
109 void ompl::app::scene::sceneCenter(
const aiScene *scene, aiVector3D ¢er)
111 std::vector<aiVector3D> vertices;
112 extractVertices(scene, vertices);
114 for (
auto & vertex : vertices)
116 center /= (float)vertices.size();
119 void ompl::app::scene::extractTriangles(
const aiScene *scene, std::vector<aiVector3D> &triangles)
122 if ((scene !=
nullptr) && scene->HasMeshes())
123 extractTrianglesAux(scene, scene->mRootNode, aiMatrix4x4(), triangles);
126 double ompl::app::scene::shortestEdge(
const aiScene *scene)
128 std::vector<aiVector3D> triangles;
129 extractTriangles(scene, triangles);
130 double s = std::numeric_limits<double>::infinity();
131 for (
unsigned int i = 0 ; i < triangles.size() / 3 ; ++i)
133 double d = (triangles[3 * i] - triangles[3 * i + 1]).Length();
135 d = (triangles[3 * i] - triangles[3 * i + 2]).Length();
137 d = (triangles[3 * i + 1] - triangles[3 * i + 2]).Length();