loader.cpp
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, CNRS - LAAS
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Open Source Robotics Foundation nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
39 
40 #include <boost/filesystem.hpp>
41 
42 #ifdef COAL_HAS_OCTOMAP
43 #include "coal/octree.h"
44 #endif
45 
46 #include "coal/BV/BV.h"
47 
48 namespace coal {
50  const CachedMeshLoader::Key& a = *this;
51  for (int i = 0; i < 3; ++i) {
52  if (a.scale[i] < b.scale[i])
53  return true;
54  else if (a.scale[i] > b.scale[i])
55  return false;
56  }
57  return std::less<std::string>()(a.filename, b.filename);
58 }
59 
60 template <typename BV>
61 BVHModelPtr_t _load(const std::string& filename, const Vec3s& scale) {
62  shared_ptr<BVHModel<BV> > polyhedron(new BVHModel<BV>);
63  loadPolyhedronFromResource(filename, scale, polyhedron);
64  return polyhedron;
65 }
66 
68  const Vec3s& scale) {
69  switch (bvType_) {
70  case BV_AABB:
71  return _load<AABB>(filename, scale);
72  case BV_OBB:
73  return _load<OBB>(filename, scale);
74  case BV_RSS:
75  return _load<RSS>(filename, scale);
76  case BV_kIOS:
77  return _load<kIOS>(filename, scale);
78  case BV_OBBRSS:
79  return _load<OBBRSS>(filename, scale);
80  case BV_KDOP16:
81  return _load<KDOP<16> >(filename, scale);
82  case BV_KDOP18:
83  return _load<KDOP<18> >(filename, scale);
84  case BV_KDOP24:
85  return _load<KDOP<24> >(filename, scale);
86  default:
87  COAL_THROW_PRETTY("Unhandled bouding volume type.",
88  std::invalid_argument);
89  }
90 }
91 
93 #ifdef COAL_HAS_OCTOMAP
94  shared_ptr<octomap::OcTree> octree(new octomap::OcTree(filename));
96 #else
97  COAL_THROW_PRETTY("Coal compiled without OctoMap. Cannot create OcTrees.",
98  std::logic_error);
99 #endif
100 }
101 
103  const Vec3s& scale) {
104  Key key(filename, scale);
105 
106  std::time_t mtime = 0;
107  try {
108  mtime = boost::filesystem::last_write_time(filename);
109 
110  Cache_t::const_iterator _cached = cache_.find(key);
111  if (_cached != cache_.end() && _cached->second.mtime == mtime)
112  // File found in cache and mtime is the same
113  return _cached->second.model;
114  } catch (boost::filesystem::filesystem_error&) {
115  // Could not stat. Make sure we will try to load the file so that
116  // there will be a file not found error.
117  }
118 
119  BVHModelPtr_t geom = MeshLoader::load(filename, scale);
120  Value val;
121  val.model = geom;
122  val.mtime = mtime;
123  cache_[key] = val;
124  return geom;
125 }
126 } // namespace coal
coal::MeshLoader::loadOctree
virtual CollisionGeometryPtr_t loadOctree(const std::string &filename)
Definition: loader.cpp:92
octree.h
coal::BV_AABB
@ BV_AABB
Definition: coal/collision_object.h:66
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
coal::BV_KDOP24
@ BV_KDOP24
Definition: coal/collision_object.h:73
coal::BV_kIOS
@ BV_kIOS
Definition: coal/collision_object.h:69
coal::loadPolyhedronFromResource
void loadPolyhedronFromResource(const std::string &resource_path, const coal::Vec3s &scale, const shared_ptr< BVHModel< BoundingVolume > > &polyhedron)
Read a mesh file and convert it to a polyhedral mesh.
Definition: coal/mesh_loader/assimp.h:116
coal::BV_OBBRSS
@ BV_OBBRSS
Definition: coal/collision_object.h:70
coal::MeshLoader::load
virtual BVHModelPtr_t load(const std::string &filename, const Vec3s &scale=Vec3s::Ones())
Definition: loader.cpp:67
val
val
loader.h
coal::BV_RSS
@ BV_RSS
Definition: coal/collision_object.h:68
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::CachedMeshLoader::load
virtual BVHModelPtr_t load(const std::string &filename, const Vec3s &scale)
Definition: loader.cpp:102
coal::CachedMeshLoader::cache_
Cache_t cache_
Definition: coal/mesh_loader/loader.h:98
octree
Definition: octree.py:1
coal::BV_KDOP18
@ BV_KDOP18
Definition: coal/collision_object.h:72
BV.h
a
list a
coal::_load
BVHModelPtr_t _load(const std::string &filename, const Vec3s &scale)
Definition: loader.cpp:61
collision-bench.filename
filename
Definition: collision-bench.py:6
COAL_THROW_PRETTY
#define COAL_THROW_PRETTY(message, exception)
Definition: include/coal/fwd.hh:64
coal::MeshLoader::bvType_
const NODE_TYPE bvType_
Definition: coal/mesh_loader/loader.h:66
coal::BVHModelPtr_t
shared_ptr< BVHModelBase > BVHModelPtr_t
Definition: include/coal/fwd.hh:141
assimp.h
generate_distance_plot.b
float b
Definition: generate_distance_plot.py:7
coal::BVHModel
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: coal/BVH/BVH_model.h:314
coal::CachedMeshLoader::Value
Definition: coal/mesh_loader/loader.h:89
coal::OcTree
Octree is one type of collision geometry which can encode uncertainty information in the sensor data.
Definition: coal/octree.h:53
coal::CachedMeshLoader::Key::operator<
bool operator<(const CachedMeshLoader::Key &b) const
Definition: loader.cpp:49
coal::BV_OBB
@ BV_OBB
Definition: coal/collision_object.h:67
coal::CollisionGeometryPtr_t
shared_ptr< CollisionGeometry > CollisionGeometryPtr_t
Definition: include/coal/fwd.hh:134
coal::BV_KDOP16
@ BV_KDOP16
Definition: coal/collision_object.h:71
coal::CachedMeshLoader::Key
Definition: coal/mesh_loader/loader.h:81


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:58