triangle_3d.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 #ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_TRIANGLE_3D_INL
00046 #define LASS_GUARDIAN_OF_INCLUSION_PRIM_SIMPLE_TRIANGLE_3D_INL
00047
00048 #include "prim_common.h"
00049 #include "triangle_3d.h"
00050
00051 namespace lass
00052 {
00053 namespace prim
00054 {
00055
00056
00057
00058
00059 template <typename T>
00060 Triangle3D<T>::Triangle3D()
00061 {
00062 }
00063
00064
00065
00066
00067
00068 template <typename T>
00069 Triangle3D<T>::Triangle3D(const TPoint& iA, const TPoint& iB, const TPoint& iC)
00070 {
00071 vertices_[0] = iA;
00072 vertices_[1] = iB;
00073 vertices_[2] = iC;
00074 }
00075
00076
00077
00078
00079
00080 template <typename T>
00081 const typename Triangle3D<T>::TPoint&
00082 Triangle3D<T>::operator[](int iIndexOfVertex) const
00083 {
00084 LASS_ASSERT(isInRange(iIndexOfVertex));
00085 return vertices_[iIndexOfVertex];
00086 }
00087
00088
00089
00090
00091
00092 template <typename T>
00093 typename Triangle3D<T>::TPoint&
00094 Triangle3D<T>::operator[](int iIndexOfVertex)
00095 {
00096 LASS_ASSERT(isInRange(iIndexOfVertex));
00097 return vertices_[iIndexOfVertex];
00098 }
00099
00100
00101
00102
00103
00104 template <typename T>
00105 const typename Triangle3D<T>::TPoint&
00106 Triangle3D<T>::at(int iIndexOfVertex) const
00107 {
00108 const int i = num::mod(iIndexOfVertex, static_cast<unsigned>(size_));
00109 LASS_ASSERT(isInRange(i));
00110 return vertices_[i];
00111 }
00112
00113
00114
00115
00116
00117 template <typename T>
00118 typename Triangle3D<T>::TPoint&
00119 Triangle3D<T>::at(int iIndexOfVertex)
00120 {
00121 const int i = num::mod(iIndexOfVertex, static_cast<unsigned>(size_));
00122 LASS_ASSERT(isInRange(i));
00123 return vertices_[i];
00124 }
00125
00126
00127
00128
00129
00130 template <typename T>
00131 const typename Triangle3D<T>::TLineSegment
00132 Triangle3D<T>::edge(int iIndexOfTailVertex) const
00133 {
00134 return TLineSegment(at(iIndexOfTailVertex), at(iIndexOfTailVertex + 1));
00135 }
00136
00137
00138
00139
00140
00141 template <typename T>
00142 const typename Triangle3D<T>::TVector
00143 Triangle3D<T>::vector(int iIndexOfTailVertex) const
00144 {
00145 return at(iIndexOfTailVertex + 1) - at(iIndexOfTailVertex);
00146 }
00147
00148
00149
00150
00151
00152 template <typename T>
00153 const typename Triangle3D<T>::TPlane
00154 Triangle3D<T>::plane() const
00155 {
00156 return TPlane(vertices_[0], vertices_[1], vertices_[2]);
00157 }
00158
00159
00160
00161
00162
00163
00164
00165 template <typename T>
00166 const bool Triangle3D<T>::isEmpty() const
00167 {
00168 return vertices_[0] == vertices_[1] && vertices_[0] == vertices_[2];
00169 }
00170
00171
00172
00173
00174
00175 template <typename T>
00176 const int Triangle3D<T>::size() const
00177 {
00178 return size_;
00179 }
00180
00181
00182
00183
00184
00185
00186 template <typename T>
00187 const typename Triangle3D<T>::TValue
00188 Triangle3D<T>::squaredArea() const
00189 {
00190 LASS_ASSERT(size_ == 3);
00191 return cross(vertices_[1] - vertices_[0], vertices_[2] - vertices_[0]).squaredNorm() / 4;
00192 }
00193
00194
00195
00196
00197
00198 template <typename T>
00199 const typename Triangle3D<T>::TValue
00200 Triangle3D<T>::area() const
00201 {
00202 return num::sqrt(squaredArea());
00203 }
00204
00205
00206
00207
00208
00209 template <typename T>
00210 const typename Triangle3D<T>::TValue
00211 Triangle3D<T>::perimeter() const
00212 {
00213 return distance(vertices_[0], vertices_[1]) +
00214 distance(vertices_[1], vertices_[2]) +
00215 distance(vertices_[2], vertices_[0]);
00216 }
00217
00218
00219
00220
00221
00222 template <typename T>
00223 const typename Triangle3D<T>::TPointH
00224 Triangle3D<T>::vertexCentroid() const
00225 {
00226 TPointH result = vertices_[0] + vertices_[1] + vertices_[2];
00227 return result;
00228 }
00229
00230
00231
00232
00233
00234 template <typename T> inline
00235 const typename Triangle3D<T>::TPointH
00236 Triangle3D<T>::surfaceCentroid() const
00237 {
00238 return vertexCentroid();
00239 }
00240
00241
00242
00243
00244
00245
00246
00247 template <typename T>
00248 const bool Triangle3D<T>::isSimple() const
00249 {
00250 return true;
00251 }
00252
00253
00254
00255
00256
00257
00258
00259 template <typename T>
00260 const bool Triangle3D<T>::isConvex() const
00261 {
00262 return true;
00263 }
00264
00265
00266
00267
00268
00269
00270
00271 template <typename T>
00272 const bool Triangle3D<T>::isReflex(int iIndexOfVertex) const
00273 {
00274 return false;
00275 }
00276
00277
00278
00279
00280
00281
00282
00283 template <typename T>
00284 const bool Triangle3D<T>::isInRange(int iIndexOfVertex) const
00285 {
00286 return iIndexOfVertex >= 0 && iIndexOfVertex < size_;
00287 }
00288
00289
00290
00291
00292
00293
00294
00295 template <typename T>
00296 io::XmlOStream& operator<<(io::XmlOStream& ioOStream, const Triangle3D<T>& iTriangle)
00297 {
00298 LASS_ENFORCE_STREAM(ioOStream) << "<Triangle3D>\n";
00299 for (unsigned i = 0; i < 3; ++i)
00300 {
00301 ioOStream << "<vertex id='" << i << "'>" << iTriangle[i] << "</vertex>\n";
00302 }
00303 ioOStream << "</Triangle3D>\n";
00304 return ioOStream;
00305 }
00306
00307
00308
00309
00310
00311 template <typename T>
00312 std::ostream& operator<<(std::ostream& ioOStream, const Triangle3D<T>& iTriangle)
00313 {
00314 LASS_ENFORCE_STREAM(ioOStream)
00315 << "{" << iTriangle[0] << ", " << iTriangle[1] << ", " << iTriangle[2] << "}";
00316 return ioOStream;
00317 }
00318
00319
00320
00321 }
00322
00323 }
00324
00325 #endif
00326
00327