convex.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-2016, Open Source Robotics Foundation
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Open Source Robotics Foundation nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
39 #ifndef FCL_SHAPE_CONVEX_H
40 #define FCL_SHAPE_CONVEX_H
41 
42 #include <ostream>
43 #include <memory>
44 #include <string>
45 #include <vector>
46 
48 
49 namespace fcl
50 {
51 
83 template <typename S_>
84 class FCL_EXPORT Convex : public ShapeBase<S_>
85 {
86 public:
87 
88  using S = S_;
89 
90  // TODO(SeanCurtis-TRI): A huge shopping list of issues with this class are
91  // enumerated in https://github.com/flexible-collision-library/fcl/issues/326.
92 
110  Convex(const std::shared_ptr<const std::vector<Vector3<S>>>& vertices,
111  int num_faces, const std::shared_ptr<const std::vector<int>>& faces,
112  bool throw_if_invalid = false);
113 
115  Convex(const Convex& other);
116 
117  ~Convex() = default;
118 
120  void computeLocalAABB() override;
121 
123  NODE_TYPE getNodeType() const override;
124 
126  const std::vector<Vector3<S>>& getVertices() const { return *vertices_; }
127 
129  int getFaceCount() const { return num_faces_; }
130 
152  const std::vector<int>& getFaces() const { return *faces_; }
153 
156  const Vector3<S>& getInteriorPoint() const { return interior_point_; }
157 
158  // Documentation inherited.
159  Matrix3<S> computeMomentofInertia() const override;
160 
161  // Documentation inherited.
162  Vector3<S> computeCOM() const override;
163 
164  // Documentation inherited.
165  S computeVolume() const override;
166 
169  std::vector<Vector3<S>> getBoundVertices(const Transform3<S>& tf) const;
170 
177  const Vector3<S>& findExtremeVertex(const Vector3<S>& v_C) const;
178 
184  std::string representation(int precision = 20) const;
185 
186  friend
187  std::ostream& operator<<(std::ostream& out, const Convex& convex) {
188  out << "Convex(v count: " << convex.vertices_->size() << ", f count: "
189  << convex.getFaceCount() << ")";
190  return out;
191  }
192 
193  private:
194  // Test utility to examine Convex internal state.
195  friend class ConvexTester;
196 
197  // TODO(SeanCurtis-TRI): Complete the validation.
198  // *Partially* validate the mesh. The following properties are validated:
199  // - Confirms mesh is water tight (see IsWaterTight).
200  // - Confirms that all vertices are included in a face.
201  // The following properties still need to be validated:
202  // - There are at least four vertices (the minimum to enclose a *volume*.)
203  // - the vertices associated with each face are planar.
204  // - For each face, all vertices *not* forming the face lie "on" or "behind"
205  // the face.
206  //
207  // Invoking this *can* have side effects. Internal configuration can change
208  // based on failed validation tests. For example, the performance of
209  // findExtremeVertex() depends on the mesh being "valid" -- an invalid mesh
210  // can be used, but will use a slower algorithm as a result of being found
211  // invalid.
212  //
213  // @param throw_on_error If `true` and the convex is shown to be invalid, an
214  // exception is thrown.
215  void ValidateMesh(bool throw_on_error);
216 
217  // Reports if the mesh is watertight and that every vertex is part of a face.
218  // The mesh is watertight if every edge is shared by two different faces.
219  //
220  // As a side effect, if this fails, find_extreme_via_neighbors_ is set to
221  // false because a water tight mesh is a prerequisite to being able to find
222  // extremal points by following edges.
223  //
224  // @param throw_on_error If `true` and the convex is shown to be invalid, an
225  // exception is thrown.
226  // @pre FindVertexNeighbors() must have been called already.
227  void ValidateTopology(bool throw_on_error);
228 
229  // Analyzes the convex specification and builds the map of vertex ->
230  // neighboring vertices.
231  void FindVertexNeighbors();
232 
233  const std::shared_ptr<const std::vector<Vector3<S>>> vertices_;
234  const int num_faces_;
235  const std::shared_ptr<const std::vector<int>> faces_;
236  // This is stored to support representation().
237  const bool throw_if_invalid_{};
239 
240  /* The encoding of vertex adjacency in the mesh. The encoding is as follows:
241  Entries [0, V-1] encode the location in `neighbors_` where the adjacency
242  data for the ith vertex lies in the array.
243  Following those offsets is the compact representation of each vertex's
244  neighbors as: number of neighbors, n0, n1, ....
245 
246  The figure below shows that for vertex j, entry j tells us to jump into
247  the vector at neighbors_[j]. The value mⱼ -- the number of vertices adjacent
248  to j -- is stored at that location. The next mⱼ entries starting at
249  neighbors_[j] + 1 are the *indices* of those vertices adjacent to vertex j.
250 
251  Index where
252  vertex j's Vertex j's
253  data lies neighbor count
254  ↓ ↓
255  |_|...|_|_|_|......┃mⱼ┃n₁┃n₂┃...┃nₘ┃mⱼ₊₁|...|
256  0 ... j ↑ ↑ ... ↑
257  Indices of vertex j's
258  neighboring vertices.
259 
260  A modicum testing indicated that this compact representation led to
261  measurably improved performance for findExtremeVertex() -- initial
262  hypothesis attributes it to improved cache hits. */
263  std::vector<int> neighbors_;
264 
265  // If true, findExtremeVertex() can reliably use neighbor_vertices_ to walk
266  // along the surface of the mesh. If false, it must linearly search.
267  bool find_extreme_via_neighbors_{false};
268 
269  // Empirical evidence suggests that finding the extreme vertex by walking the
270  // edges of the mesh is only more efficient if there are more than 32
271  // vertices.
272  static constexpr int kMinVertCountForEdgeWalking = 32;
273 };
274 
275 // Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728 which
276 // should be moved back into the class definition once we no longer need to
277 // support GCC versions prior to 6.3.
278 template <typename S>
279 Convex<S>::Convex(const Convex<S>& other) = default;
280 
283 
284 } // namespace fcl
285 
287 
288 #endif
Convex(const std::shared_ptr< const std::vector< Vector3< S >>> &vertices, int num_faces, const std::shared_ptr< const std::vector< int >> &faces, bool throw_if_invalid=false)
Constructor.
Definition: convex-inl.h:60
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18, kDOP24), basic shape (box, sphere, ellipsoid, capsule, cone, cylinder, convex, plane, halfspace, triangle), and octree
Main namespace.
Base class for all basic geometric shapes.
Definition: shape_base.h:48
Eigen::Transform< S, 3, Eigen::Isometry > Transform3
Definition: types.h:91
const std::shared_ptr< const std::vector< Vector3< S > > > vertices_
Definition: convex.h:233
const std::shared_ptr< const std::vector< int > > faces_
Definition: convex.h:235
Eigen::Matrix< S, 3, 3 > Matrix3
Definition: types.h:85
Eigen::Matrix< S, 3, 1 > Vector3
Definition: types.h:70
const int num_faces_
Definition: convex.h:234
const std::vector< Vector3< S > > & getVertices() const
Gets the vertex positions in the geometry&#39;s frame G.
Definition: convex.h:126
const std::vector< int > & getFaces() const
Gets the representation of the faces of the convex hull.
Definition: convex.h:152
std::vector< int > neighbors_
Definition: convex.h:263
const Vector3< S > & getInteriorPoint() const
A point guaranteed to be on the interior of the convex polytope, used for collision.
Definition: convex.h:156
Vector3< S > interior_point_
Definition: convex.h:238
int getFaceCount() const
Gets the total number of faces in the convex mesh.
Definition: convex.h:129
A convex polytope.
Definition: convex.h:84
friend std::ostream & operator<<(std::ostream &out, const Convex &convex)
Definition: convex.h:187


fcl_catkin
Author(s):
autogenerated on Thu Mar 23 2023 03:00:18