GteConvexPolyhedron3.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.5.0 (2016/11/25)
7 
8 #pragma once
9 
10 #include <Mathematics/GteVector4.h>
12 #include <cstdint>
13 #include <vector>
14 
15 namespace gte
16 {
17 
18 template <typename Real>
20 {
21 public:
22  // Construction. The convex polyhedra represented by this class has
23  // triangle faces that are counterclockwise ordered when viewed from
24  // outside the polyhedron. No attempt is made to verify that the
25  // polyhedron is convex; the caller is responsible for enforcing this.
26  // The constructors move (not copy!) the input arrays. The constructor
27  // succeeds when the number of vertices is at least 4 and the number of
28  // indices is at least 12. If the constructor fails, no move occurs
29  // and the member arrays have no elements.
30  //
31  // To support geometric algorithms that are formulated using convex
32  // quadratic programming (such as computing the distance from a point to
33  // a convex polyhedron), it is necessary to know the planes of the faces
34  // and an axis-aligned bounding box. If you want either the faces or the
35  // box, pass 'true' to the appropriate parameters. When planes are
36  // generated, the normals are not created to be unit length in order to
37  // support queries using exact rational arithmetic. If a normal to a
38  // face is N = (n0,n1,n2) and V is a vertex of the face, the plane is
39  // Dot(N,X-V) = 0 and is stored as Dot(n0,n1,n2,-Dot(N,V)). The normals
40  // are computed to be outer pointing.
42  ConvexPolyhedron3(std::vector<Vector3<Real>>&& inVertices, std::vector<int>&& inIndices,
43  bool wantPlanes, bool wantAlignedBox);
44 
45  // If you modifty the vertices or indices and you want the new face
46  // planes or aligned box computed, call these functions.
47  void GeneratePlanes();
48  void GenerateAlignedBox();
49 
50  std::vector<Vector3<Real>> vertices;
51  std::vector<int> indices;
52  std::vector<Vector4<Real>> planes;
54 };
55 
56 
57 template <typename Real>
59 {
60 }
61 
62 template <typename Real>
64  std::vector<int>&& inIndices, bool wantPlanes, bool wantAlignedBox)
65 {
66  if (inVertices.size() >= 4 && inIndices.size() >= 12)
67  {
68  vertices = std::move(inVertices);
69  indices = std::move(inIndices);
70 
71  if (wantPlanes)
72  {
74  }
75 
76  if (wantAlignedBox)
77  {
79  }
80  }
81 }
82 
83 template <typename Real>
85 {
86  if (vertices.size() > 0 && indices.size() > 0)
87  {
88  uint32_t const numTriangles = static_cast<uint32_t>(indices.size()) / 3;
89  planes.resize(numTriangles);
90  for (uint32_t t = 0, i = 0; t < numTriangles; ++t)
91  {
92  Vector3<Real> V0 = vertices[indices[i++]];
93  Vector3<Real> V1 = vertices[indices[i++]];
94  Vector3<Real> V2 = vertices[indices[i++]];
95  Vector3<Real> E1 = V1 - V0;
96  Vector3<Real> E2 = V2 - V0;
97  Vector3<Real> N = Cross(E1, E2);
98  planes[t] = HLift(N, -Dot(N, V0));
99  }
100  }
101 }
102 
103 template <typename Real>
105 {
106  if (vertices.size() > 0 && indices.size() > 0)
107  {
108  ComputeExtremes(static_cast<int>(vertices.size()), vertices.data(),
109  alignedBox.min, alignedBox.max);
110  }
111 }
112 
113 }
std::vector< Vector3< Real > > vertices
AlignedBox3< Real > alignedBox
std::vector< Vector4< Real > > planes
GVector< Real > HLift(GVector< Real > const &v, Real last)
Definition: GteGVector.h:574
GLsizei GLenum const void * indices
Definition: glcorearb.h:401
std::vector< int > indices
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
GLdouble GLdouble t
Definition: glext.h:239
DualQuaternion< Real > Cross(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
bool ComputeExtremes(int numVectors, GVector< Real > const *v, GVector< Real > &vmin, GVector< Real > &vmax)
Definition: GteGVector.h:537


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59