Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
vhacdVector.h
Go to the documentation of this file.
1/* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
2 All rights reserved.
3
4
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
6 following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9 disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12 disclaimer in the documentation and/or other materials provided with the distribution.
13
14 3. The names of the contributors may not be used to endorse or promote products derived from this software without
15 specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#pragma once
26
27#include <iostream>
28#include <math.h>
29
30namespace tesseract_collision
31{
32namespace VHACD
33{
35template <typename T>
36class Vec3
37{
38public:
39 T& operator[](size_t i) { return m_data[i]; }
40 const T& operator[](size_t i) const { return m_data[i]; }
41 T& X();
42 T& Y();
43 T& Z();
44 const T& X() const;
45 const T& Y() const;
46 const T& Z() const;
47 void Normalize();
48 T GetNorm() const;
49 void operator=(const Vec3& rhs);
50 void operator+=(const Vec3& rhs);
51 void operator-=(const Vec3& rhs);
52 void operator-=(T a);
53 void operator+=(T a);
54 void operator/=(T a);
55 void operator*=(T a);
56 Vec3 operator^(const Vec3& rhs) const;
57 T operator*(const Vec3& rhs) const;
58 Vec3 operator+(const Vec3& rhs) const;
59 Vec3 operator-(const Vec3& rhs) const;
60 Vec3 operator-() const;
61 Vec3 operator*(T rhs) const;
62 Vec3 operator/(T rhs) const;
63 bool operator<(const Vec3& rhs) const;
64 bool operator>(const Vec3& rhs) const;
65 Vec3();
66 Vec3(T a);
67 Vec3(T x, T y, T z);
68 Vec3(const Vec3& rhs);
69 /*virtual*/ ~Vec3(void);
70
71 // Compute the center of this bounding box and return the diagonal length
72 T GetCenter(const Vec3& bmin, const Vec3& bmax)
73 {
74 X() = (bmin.X() + bmax.X()) * 0.5;
75 Y() = (bmin.Y() + bmax.Y()) * 0.5;
76 Z() = (bmin.Z() + bmax.Z()) * 0.5;
77 T dx = bmax.X() - bmin.X();
78 T dy = bmax.Y() - bmin.Y();
79 T dz = bmax.Z() - bmin.Z();
80 T diagonal = T(sqrt(dx * dx + dy * dy + dz * dz));
81 return diagonal;
82 }
83
84 // Update the min/max values relative to this point
85 void UpdateMinMax(Vec3& bmin, Vec3& bmax) const
86 {
87 if (X() < bmin.X())
88 {
89 bmin.X() = X();
90 }
91 if (Y() < bmin.Y())
92 {
93 bmin.Y() = Y();
94 }
95 if (Z() < bmin.Z())
96 {
97 bmin.Z() = Z();
98 }
99 if (X() > bmax.X())
100 {
101 bmax.X() = X();
102 }
103 if (X() > bmax.X())
104 {
105 bmax.X() = X();
106 }
107 if (Y() > bmax.Y())
108 {
109 bmax.Y() = Y();
110 }
111 if (Z() > bmax.Z())
112 {
113 bmax.Z() = Z();
114 }
115 }
116
117 // Returns the squared distance between these two points
118 T GetDistanceSquared(const Vec3& p) const
119 {
120 T dx = X() - p.X();
121 T dy = Y() - p.Y();
122 T dz = Z() - p.Z();
123 return dx * dx + dy * dy + dz * dz;
124 }
125
126 T GetDistance(const Vec3& p) const { return sqrt(GetDistanceSquared(p)); }
127 // Returns the raw vector data as a pointer
128 T* GetData(void) { return m_data; }
129
130private:
132};
134template <typename T>
135class Vec2
136{
137public:
138 T& operator[](size_t i) { return m_data[i]; }
139 const T& operator[](size_t i) const { return m_data[i]; }
140 T& X();
141 T& Y();
142 const T& X() const;
143 const T& Y() const;
144 void Normalize();
145 T GetNorm() const;
146 void operator=(const Vec2& rhs);
147 void operator+=(const Vec2& rhs);
148 void operator-=(const Vec2& rhs);
149 void operator-=(T a);
150 void operator+=(T a);
151 void operator/=(T a);
152 void operator*=(T a);
153 T operator^(const Vec2& rhs) const;
154 T operator*(const Vec2& rhs) const;
155 Vec2 operator+(const Vec2& rhs) const;
156 Vec2 operator-(const Vec2& rhs) const;
157 Vec2 operator-() const;
158 Vec2 operator*(T rhs) const;
159 Vec2 operator/(T rhs) const;
160 Vec2();
161 Vec2(T a);
162 Vec2(T x, T y);
163 Vec2(const Vec2& rhs);
164 /*virtual*/ ~Vec2(void);
165
166private:
168};
169
170template <typename T>
171bool Colinear(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& c);
172template <typename T>
173const T ComputeVolume4(const Vec3<T>& a, const Vec3<T>& b, const Vec3<T>& c, const Vec3<T>& d);
174} // namespace VHACD
175} // namespace tesseract_collision
176#include "vhacdVector.inl" // template implementation
Vector dim 2.
Definition: vhacdVector.h:136
void operator=(const Vec2 &rhs)
Definition: vhacdVector.inl:242
void operator*=(T a)
Definition: vhacdVector.inl:278
T & operator[](size_t i)
Definition: vhacdVector.h:138
void operator/=(T a)
Definition: vhacdVector.inl:272
void Normalize()
Definition: vhacdVector.inl:231
T & X()
Definition: vhacdVector.inl:211
Vec2 operator-() const
Definition: vhacdVector.inl:304
~Vec2(void)
Definition: vhacdVector.inl:337
void operator-=(const Vec2 &rhs)
Definition: vhacdVector.inl:254
T operator^(const Vec2 &rhs) const
Definition: vhacdVector.inl:284
T GetNorm() const
Definition: vhacdVector.inl:237
const T & operator[](size_t i) const
Definition: vhacdVector.h:139
Vec2 operator+(const Vec2 &rhs) const
Definition: vhacdVector.inl:294
Vec2 operator-(const Vec2 &rhs) const
T operator*(const Vec2 &rhs) const
Vec2 operator/(T rhs) const
Definition: vhacdVector.inl:315
T m_data[2]
Definition: vhacdVector.h:167
T & Y()
Definition: vhacdVector.inl:216
void operator+=(const Vec2 &rhs)
Definition: vhacdVector.inl:248
Vec2()
Definition: vhacdVector.inl:340
Vector dim 3.
Definition: vhacdVector.h:37
T & Y()
Definition: vhacdVector.inl:18
bool operator>(const Vec3 &rhs) const
Definition: vhacdVector.inl:193
T operator*(const Vec3 &rhs) const
~Vec3(void)
Definition: vhacdVector.inl:160
Vec3 operator+(const Vec3 &rhs) const
Definition: vhacdVector.inl:115
T GetNorm() const
Definition: vhacdVector.inl:49
T GetDistance(const Vec3 &p) const
Definition: vhacdVector.h:126
Vec3 operator-(const Vec3 &rhs) const
Vec3()
Definition: vhacdVector.inl:163
void operator-=(const Vec3 &rhs)
Definition: vhacdVector.inl:68
Vec3 operator/(T rhs) const
Definition: vhacdVector.inl:136
T & X()
Definition: vhacdVector.inl:13
void operator/=(T a)
Definition: vhacdVector.inl:89
T GetDistanceSquared(const Vec3 &p) const
Definition: vhacdVector.h:118
const T & operator[](size_t i) const
Definition: vhacdVector.h:40
void UpdateMinMax(Vec3 &bmin, Vec3 &bmax) const
Definition: vhacdVector.h:85
void Normalize()
Definition: vhacdVector.inl:43
Vec3 operator-() const
Definition: vhacdVector.inl:125
void operator+=(const Vec3 &rhs)
Definition: vhacdVector.inl:61
void operator*=(T a)
Definition: vhacdVector.inl:96
T & Z()
Definition: vhacdVector.inl:23
T & operator[](size_t i)
Definition: vhacdVector.h:39
Vec3 operator^(const Vec3 &rhs) const
Definition: vhacdVector.inl:103
void operator=(const Vec3 &rhs)
Definition: vhacdVector.inl:54
T * GetData(void)
Definition: vhacdVector.h:128
T GetCenter(const Vec3 &bmin, const Vec3 &bmax)
Definition: vhacdVector.h:72
bool operator<(const Vec3 &rhs) const
Definition: vhacdVector.inl:180
T m_data[3]
Definition: vhacdVector.h:131
Definition: polygon_mesh.h:46
const T ComputeVolume4(const Vec3< T > &a, const Vec3< T > &b, const Vec3< T > &c, const Vec3< T > &d)
Definition: vhacdVector.inl:174
bool Colinear(const Vec3< T > &a, const Vec3< T > &b, const Vec3< T > &c)
Definition: vhacdVector.inl:166
Definition: bullet_cast_bvh_manager.h:49
tesseract_geometry::PolygonMesh T
Definition: tesseract_geometry_unit.cpp:140