CD_Simplex.hxx
Go to the documentation of this file.
1 
2 
3 inline CD_Simplex::CD_Simplex(const Point3 & p) : type_(CD_Point), s1_(p) {}
4 
5 inline CD_Simplex::CD_Simplex(const Point3 & p1, const Point3 & p2) : type_(CD_Segment), s1_(p1), s2_(p2) {}
6 
7 inline CD_Simplex::CD_Simplex(const Point3 & p1, const Point3 & p2, const Point3 & p3)
8 : type_(CD_Triangle), s1_(p1), s2_(p2), s3_(p3)
9 {
10 }
11 
12 inline CD_Simplex::CD_Simplex(const Point3 & p1, const Point3 & p2, const Point3 & p3, const Point3 & p4)
13 : type_(CD_Tetrahedron), s1_(p1), s2_(p2), s3_(p3), s4_(p4)
14 {
15 }
16 
17 template<typename T>
18 inline void CD_SimplexExchangeTest(T & a, T & b, T & c)
19 {
20  if(&a != &b)
21  {
22  c = a;
23  a = b;
24  b = c;
25  }
26 }
27 
28 template<typename T>
29 inline void CD_SimplexExchange(T & a, T & b, T & c)
30 {
31  c = a;
32  a = b;
33  b = c;
34 }
35 
36 inline const Vector3 & CD_Simplex::AB() const
37 {
38  return ab_;
39 }
40 
41 inline const Vector3 & CD_Simplex::AC() const
42 {
43  return ac_;
44 }
45 
46 inline const Vector3 & CD_Simplex::AD() const
47 {
48  return ad_;
49 }
50 
52 {
53  switch(type_)
54  {
55  case CD_Tetrahedron:
56  {
57  ab_ = s1_ - s4_;
58  ac_ = s2_ - s4_;
59  ad_ = s3_ - s4_;
60  return;
61  }
62  case CD_Segment:
63  ab_ = s1_ - s2_;
64  return;
65  case CD_Triangle:
66  {
67  ab_ = s1_ - s3_;
68  ac_ = s2_ - s3_;
69  return;
70  }
71 
72  default:
73  return;
74  }
75 }
76 
78 {
79  return type_;
80 }
81 
82 inline Point3 & CD_Simplex::operator[](unsigned char i)
83 {
84  return ((i == 0) ? s1_ : (i == 1) ? s2_ : (i == 2) ? s3_ : s4_);
85 }
86 
87 inline const Point3 & CD_Simplex::operator[](unsigned char i) const
88 {
89  return ((i == 0) ? s1_ : (i == 1) ? s2_ : (i == 2) ? s3_ : s4_);
90 }
91 
93 {
94  *this = rhs;
95 }
96 
98 {
99  type_ = s.type_;
100  switch(type_)
101  {
102  case CD_Triangle:
103  s1_ = s.s1_;
104  s2_ = s.s2_;
105  s3_ = s.s3_;
106  ab_ = s.ab_;
107  ac_ = s.ac_;
108  return *this;
109  case CD_Segment:
110  s1_ = s.s1_;
111  s2_ = s.s2_;
112  ab_ = s.ab_;
113  return *this;
114  case CD_Point:
115  s1_ = s.s1_;
116  return *this;
117  default:
118  s1_ = s.s1_;
119  s2_ = s.s2_;
120  s3_ = s.s3_;
121  s4_ = s.s4_;
122  ab_ = s.ab_;
123  ac_ = s.ac_;
124  ad_ = s.ad_;
125  return *this;
126  }
127 }
128 
130 {
131  type_ = CD_Point;
132  s1_ = p;
133  return *this;
134 }
135 
136 inline bool CD_Simplex::operator==(const CD_Simplex & s)
137 {
138  if(type_ != s.type_) return false;
139  switch(type_)
140  {
141  case CD_Triangle:
142  return (s1_ == s.s1_) && (s2_ == s.s2_) && (s3_ == s.s3_);
143  case CD_Segment:
144  return (s1_ == s.s1_) && (s2_ == s.s2_);
145  case CD_Point:
146  return (s1_ == s.s1_);
147  default:
148  return (s1_ == s.s1_) && (s2_ == s.s2_) && (s3_ == s.s3_) && (s4_ == s.s4_);
149  }
150 }
151 
152 inline bool CD_Simplex::operator!=(const CD_Simplex & s)
153 {
154  return !((*this) == s);
155 }
156 
158 {
159 
160  switch(type_)
161  {
162  case CD_Point:
163  s2_ = p;
164  type_ = CD_Segment;
165  return *this;
166  case CD_Segment:
167  s3_ = p;
168  type_ = CD_Triangle;
169  return *this;
170  default:
171  s4_ = p;
173  return *this;
174  }
175  return *this;
176 }
177 
178 inline CD_Simplex CD_Simplex::operator+(const Point3 & p) const
179 {
180 
181  if(type_ == CD_Point)
182  {
183  return CD_Simplex(s1_, p);
184  }
185  else if(type_ == CD_Segment)
186  {
187  return CD_Simplex(s1_, s2_, p);
188  }
189  else if(type_ == CD_Triangle)
190  {
191  return CD_Simplex(s1_, s2_, s3_, p);
192  }
193  return *this;
194 }
195 
197 {
198 
199  switch(f.type)
200  {
201  case CD_None:
202  return;
203 
204  case CD_Segment:
205  {
206  type_ = CD_Segment;
207  Vector3 cache;
208  char a[] = {0, 1, 2, 3};
209  char b;
210  CD_SimplexExchangeTest<Vector3>(s1_, (*this)[f.b1], cache);
211  CD_SimplexExchange<char>(a[0], a[(int)f.b1], b);
212 
213  s2_ = (*this)[a[(int)f.b2]];
214  return;
215  }
216  case CD_Triangle:
217  {
218  type_ = CD_Triangle;
219  Vector3 cache;
220  char a[] = {0, 1, 2, 3};
221  char b;
222  CD_SimplexExchangeTest<Vector3>(s1_, (*this)[(int)f.b1], cache);
223  CD_SimplexExchange<char>(a[0], a[(int)f.b1], b);
224 
225  CD_SimplexExchangeTest<Vector3>(s2_, (*this)[a[(int)f.b2]], cache);
226  CD_SimplexExchange<char>(a[(int)a[1]], a[(int)a[(int)f.b2]], b);
227 
228  s3_ = (*this)[a[(int)f.b3]];
229  return;
230  }
231  case CD_Point:
232  {
233  Vector3 cache;
234  type_ = CD_Point;
235  s1_ = (*this)[(int)f.b1];
236  return;
237  }
238  default:
239  {
241  Vector3 cache;
242  char a[] = {0, 1, 2, 3};
243  char b;
244  CD_SimplexExchangeTest<Vector3>(s1_, (*this)[(int)f.b1], cache);
245  CD_SimplexExchange<char>(a[0], a[(int)f.b1], b);
246 
247  CD_SimplexExchangeTest<Vector3>(s2_, (*this)[a[(int)f.b2]], cache);
248  CD_SimplexExchange<char>(a[(int)a[1]], a[(int)a[(int)f.b2]], b);
249 
250  CD_SimplexExchangeTest<Vector3>(s3_, (*this)[a[(int)f.b3]], cache);
251  CD_SimplexExchange<char>(a[(int)a[2]], a[(int)a[(int)f.b3]], b);
252 
253  s4_ = (*this)[a[(int)f.b4]];
254  return;
255  }
256  }
257 }
258 
260 {
261  switch(type_)
262  {
263  case CD_Point:
264  return s1_.normsquared();
265 
266  default:
267  Scalar d(v * s2_);
268  return d * d / v.normsquared();
269  }
270 }
sch::CD_Simplex::ac_
Vector3 ac_
Definition: CD_Simplex.h:125
sch::CD_Simplex::operator+=
SCH_API CD_Simplex & operator+=(const Point3 &)
Adds a point to a simplex to transform it in a higher dimemsion simplex (doesn't work with tetrahedro...
Definition: CD_Simplex.hxx:157
sch::CD_SimplexKeptPoints
Definition: CD_Simplex.h:27
sch::CD_Simplex::AC
const SCH_API Vector3 & AC() const
Returns AC vector.
Definition: CD_Simplex.hxx:41
CD_Matrix::Vector3T::normsquared
T normsquared() const
Definition: SmallVector3T.h:308
sch::Point3
Vector3 Point3
Definition: SCH_Types.h:26
sch::CD_Simplex::ab_
Vector3 ab_
Definition: CD_Simplex.h:125
sch::CD_Simplex::operator[]
const SCH_API Point3 & operator[](unsigned char) const
sch::CD_Simplex::getType
SCH_API CD_SimplexType getType() const
Definition: CD_Simplex.hxx:77
CD_SimplexExchange
void CD_SimplexExchange(T &a, T &b, T &c)
Definition: CD_Simplex.hxx:29
sch::CD_Simplex::operator+
SCH_API CD_Simplex operator+(const Point3 &) const
Adds a point to a simplex to transform it in a higher dimemsion simplex (doesn't work with tetrahedro...
Definition: CD_Simplex.hxx:178
sch::CD_Triangle
@ CD_Triangle
Definition: CD_Simplex.h:19
sch::CD_Segment
@ CD_Segment
Definition: CD_Simplex.h:18
sch::CD_SimplexKeptPoints::b4
char b4
Definition: CD_Simplex.h:29
sch::CD_Simplex::operator==
SCH_API bool operator==(const CD_Simplex &s)
Definition: CD_Simplex.hxx:136
sch::CD_Simplex::operator!=
SCH_API bool operator!=(const CD_Simplex &s)
Definition: CD_Simplex.hxx:152
sch::CD_Simplex::s4_
Point3 s4_
Definition: CD_Simplex.h:124
sch::CD_SimplexKeptPoints::b2
char b2
Definition: CD_Simplex.h:29
sch::CD_SimplexKeptPoints::b1
char b1
Definition: CD_Simplex.h:29
sch::CD_Simplex::AB
const SCH_API Vector3 & AB() const
Returns AB vector.
Definition: CD_Simplex.hxx:36
sch::CD_Simplex::CD_Simplex
SCH_API CD_Simplex(const CD_Simplex &rhs)
Definition: CD_Simplex.hxx:92
sch::CD_Simplex::AD
const SCH_API Vector3 & AD() const
Returns AD vector.
Definition: CD_Simplex.hxx:46
sch::CD_Simplex::ad_
Vector3 ad_
Definition: CD_Simplex.h:125
sch::CD_Simplex::filter
virtual SCH_API void filter(const CD_SimplexKeptPoints &k)
Updates the simplex by supressing some vertexes and/or change their order according to a filter.
Definition: CD_Simplex.hxx:196
sch::CD_Simplex::squareDistanceAtOrigin
SCH_API Scalar squareDistanceAtOrigin(const Vector3 &v) const
Gives the distance squared at the origin for a simplex, and according the direction v.
Definition: CD_Simplex.hxx:259
sch::CD_SimplexType
CD_SimplexType
Definition: CD_Simplex.h:15
sch::CD_SimplexKeptPoints::type
CD_SimplexType type
Definition: CD_Simplex.h:31
CD_Matrix::Vector3T< Scalar, false >
sch::CD_None
@ CD_None
Definition: CD_Simplex.h:21
CD_SimplexExchangeTest
void CD_SimplexExchangeTest(T &a, T &b, T &c)
Definition: CD_Simplex.hxx:18
sch::CD_Simplex::s2_
Point3 s2_
Definition: CD_Simplex.h:124
sch::CD_SimplexKeptPoints::b3
char b3
Definition: CD_Simplex.h:29
sch::CD_Simplex::updateVectors
SCH_API void updateVectors()
Updates AB,AC,AD vectors. A is the last vertex inserted and B, C and D are previous vertexes.
Definition: CD_Simplex.hxx:51
sch::CD_Simplex::s3_
Point3 s3_
Definition: CD_Simplex.h:124
sch::Scalar
double Scalar
Definition: SCH_Types.h:23
sch::CD_Simplex
Definition: CD_Simplex.h:54
sch::CD_Simplex::s1_
Point3 s1_
Definition: CD_Simplex.h:124
sch::CD_Point
@ CD_Point
Definition: CD_Simplex.h:17
sch::CD_Simplex::type_
CD_SimplexType type_
Definition: CD_Simplex.h:122
sch::CD_Tetrahedron
@ CD_Tetrahedron
Definition: CD_Simplex.h:20
sch::CD_Simplex::operator=
SCH_API CD_Simplex & operator=(const CD_Simplex &s)
Definition: CD_Simplex.hxx:97