hpp-fcl  1.6.0
HPP fork of FCL -- The Flexible Collision Library
assimp.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2015, Open Source Robotics Foundation
6  * Copyright (c) 2016-2019, CNRS - LAAS
7  * Copyright (c) 2019, INRIA
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of Open Source Robotics Foundation nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef HPP_FCL_MESH_LOADER_ASSIMP_H
39 #define HPP_FCL_MESH_LOADER_ASSIMP_H
40 
41 #include <hpp/fcl/config.hh>
42 #include <hpp/fcl/BV/OBBRSS.h>
43 #include <hpp/fcl/BVH/BVH_model.h>
44 
45 struct aiScene;
46 namespace Assimp {
47  class Importer;
48 }
49 
50 namespace hpp
51 {
52 namespace fcl
53 {
54 
55 namespace internal
56 {
57 
59 {
60  std::vector <fcl::Vec3f> vertices_;
61  std::vector <fcl::Triangle> triangles_;
62 };
63 
65  Loader ();
66  ~Loader ();
67 
68  void load (const std::string& resource_path);
69 
70  Assimp::Importer* importer;
71  aiScene const* scene;
72 };
73 
82 HPP_FCL_DLLAPI void buildMesh (const fcl::Vec3f & scale,
83  const aiScene* scene,
84  unsigned vertices_offset,
85  TriangleAndVertices & tv);
86 
94 template<class BoundingVolume>
95 inline void meshFromAssimpScene(
96  const fcl::Vec3f & scale,
97  const aiScene* scene,
98  const boost::shared_ptr < BVHModel<BoundingVolume> > & mesh)
99 {
101 
102  int res = mesh->beginModel ();
103 
104  if (res != fcl::BVH_OK)
105  {
106  std::ostringstream error;
107  error << "fcl BVHReturnCode = " << res;
108  throw std::runtime_error (error.str ());
109  }
110 
111  buildMesh (scale, scene, (unsigned) mesh->num_vertices, tv);
112  mesh->addSubModel (tv.vertices_, tv.triangles_);
113 
114  mesh->endModel ();
115 }
116 
117 } // namespace internal
118 
126 template<class BoundingVolume>
127 inline void loadPolyhedronFromResource (const std::string & resource_path,
128  const fcl::Vec3f & scale,
129  const boost::shared_ptr < BVHModel<BoundingVolume> > & polyhedron)
130 {
131  internal::Loader scene;
132  scene.load (resource_path);
133 
134  internal::meshFromAssimpScene (scale, scene.scene, polyhedron);
135 }
136 
137 } // namespace fcl
138 } // namespace hpp
139 
140 #endif // HPP_FCL_MESH_LOADER_ASSIMP_H
Definition: assimp.h:64
Definition: assimp.h:46
Main namespace.
Definition: AABB.h:43
void buildMesh(const fcl::Vec3f &scale, const aiScene *scene, unsigned vertices_offset, TriangleAndVertices &tv)
Recursive procedure for building a mesh.
void loadPolyhedronFromResource(const std::string &resource_path, const fcl::Vec3f &scale, const boost::shared_ptr< BVHModel< BoundingVolume > > &polyhedron)
Read a mesh file and convert it to a polyhedral mesh.
Definition: assimp.h:127
std::vector< fcl::Triangle > triangles_
Definition: assimp.h:61
Definition: BVH_internal.h:65
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: BVH_model.h:269
aiScene const * scene
Definition: assimp.h:71
void meshFromAssimpScene(const fcl::Vec3f &scale, const aiScene *scene, const boost::shared_ptr< BVHModel< BoundingVolume > > &mesh)
Convert an assimp scene to a mesh.
Definition: assimp.h:95
std::vector< fcl::Vec3f > vertices_
Definition: assimp.h:60
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
void load(const std::string &resource_path)
Assimp::Importer * importer
Definition: assimp.h:70
#define HPP_FCL_DLLAPI
Definition: config.hh:64