00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SURFACE_MESH_OF_TRIANGLES_HPP
00021 #define SURFACE_MESH_OF_TRIANGLES_HPP
00022
00023 #include <Vector.hpp>
00024 #include <Triangle.hpp>
00025
00026 #include <NormalManager.hpp>
00027 #include <SurfaceMesh.hpp>
00028
00029 #include <Connectivity.hpp>
00030
00031 #include <ErrorHandler.hpp>
00032 #include <EdgesBuilder.hpp>
00033
00044 class SurfaceMeshOfTriangles
00045 : public SurfaceMesh
00046 {
00047 public:
00048 typedef Triangle CellType;
00049 typedef Edge FaceType;
00050
00051 typedef SurfaceMeshOfTriangles Transformed;
00052
00053 typedef struct {} BorderMeshType;
00055 class iterator
00056 : public Mesh::T_iterator<SurfaceMeshOfTriangles, Triangle>
00057 {
00058 private:
00059 typedef Mesh::T_iterator<SurfaceMeshOfTriangles, Triangle> iterator_base;
00060
00061 public:
00062
00063 iterator&
00064 operator=(const iterator& i)
00065 {
00066 iterator_base::operator=(i);
00067 NormalManager::instance().update(__iterator);
00068
00069 return *this;
00070 }
00071
00072 iterator&
00073 operator=(CellType* cell)
00074 {
00075 iterator_base::operator=(cell);
00076 NormalManager::instance().update(__iterator);
00077
00078 return *this;
00079 }
00080
00081 inline iterator_base operator++(int)
00082 {
00083 iterator_base i = *this;
00084 (*this)++;
00085 return i;
00086 }
00087
00088 inline iterator& operator++()
00089 {
00090 this->iterator_base::operator++();
00091 NormalManager::instance().update(__iterator);
00092 return *this;
00093 }
00094
00095 iterator(SurfaceMeshOfTriangles& m,
00096 iterator_base::Position position = iterator_base::Begin)
00097 : iterator_base(m, position)
00098 {
00099 NormalManager::instance().subscribe(__iterator);
00100 }
00101
00102 iterator(SurfaceMeshOfTriangles& m,
00103 const size_t& cellNumber)
00104 : iterator_base(m,cellNumber)
00105 {
00106 NormalManager::instance().subscribe(__iterator);
00107 }
00108
00109 iterator(const iterator& i)
00110 : iterator_base(i)
00111 {
00112 NormalManager::instance().subscribe(__iterator);
00113 }
00114
00115 ~iterator()
00116 {
00117 NormalManager::instance().unsubscribe();
00118 }
00119 };
00120
00121 class const_iterator
00122 : public Mesh::T_iterator<const SurfaceMeshOfTriangles, const Triangle>
00123 {
00124 private:
00125 typedef Mesh::T_iterator<const SurfaceMeshOfTriangles, const Triangle> const_iterator_base;
00126
00127 public:
00128 const_iterator&
00129 operator=(const const_iterator& i)
00130 {
00131 const_iterator_base::operator=(i);
00132 NormalManager::instance().update(__iterator);
00133
00134 return *this;
00135 }
00136
00137 const_iterator&
00138 operator=(CellType* iterator)
00139 {
00140 const_iterator_base::operator=(iterator);
00141 NormalManager::instance().update(__iterator);
00142
00143 return *this;
00144 }
00145
00146 inline const_iterator_base operator++(int)
00147 {
00148 const_iterator_base i = *this;
00149 (*this)++;
00150 return i;
00151 }
00152
00153 inline const_iterator& operator++()
00154 {
00155 this->const_iterator_base::operator++();
00156 NormalManager::instance().update(__iterator);
00157 return *this;
00158 }
00159
00160 const_iterator(const SurfaceMeshOfTriangles& m,
00161 const_iterator_base::Position position = const_iterator_base::Begin)
00162 : const_iterator_base(m, position)
00163 {
00164 NormalManager::instance().subscribe(__iterator);
00165 }
00166
00167 const_iterator(SurfaceMeshOfTriangles& m,
00168 const size_t& cellNumber)
00169 : const_iterator_base(m,cellNumber)
00170 {
00171 NormalManager::instance().subscribe(__iterator);
00172 }
00173
00174 const_iterator(const const_iterator& i)
00175 : const_iterator_base(i)
00176 {
00177 NormalManager::instance().subscribe(__iterator);
00178 }
00179
00180 ~const_iterator()
00181 {
00182 NormalManager::instance().unsubscribe();
00183 }
00184 };
00185
00186 private:
00187 ReferenceCounting<Vector<Triangle> > __cells;
00189 Connectivity<SurfaceMeshOfTriangles> __connectivity;
00191 public:
00192 bool hasBorderMesh() const
00193 {
00194 return false;
00195 }
00196
00197 ConstReferenceCounting<Mesh> borderBaseMesh() const
00198 {
00199 throw ErrorHandler(__FILE__,__LINE__,
00200 "not implemented yet",
00201 ErrorHandler::unexpected);
00202
00203 return 0;
00204 }
00205
00206 std::string typeName() const
00207 {
00208 return "surface mesh of triangles";
00209 }
00210
00211 void buildEdges()
00212 {
00213 EdgesBuilder<SurfaceMeshOfTriangles> edgesBuilder(*this);
00214 __edgesSet = edgesBuilder.edgesSet();
00215 }
00216
00222 const Connectivity<SurfaceMeshOfTriangles>& connectivity() const
00223 {
00224 return __connectivity;
00225 }
00226
00232 Connectivity<SurfaceMeshOfTriangles>& connectivity()
00233 {
00234 return __connectivity;
00235 }
00236
00238 inline bool inside(const real_t& x, const real_t& y, const real_t& z) const
00239 {
00240 throw ErrorHandler(__FILE__,__LINE__,
00241 "Trying to find 3d point on a surface mesh",
00242 ErrorHandler::normal);
00243 return false;
00244 }
00245
00247 inline bool inside(const TinyVector<3>& p) const
00248 {
00249 return this->inside(p[0], p[1], p[2]);
00250 }
00251
00256 void computesFictitiousCells() const
00257 {
00258 this->__computesFictitiousCells<Triangle>(*__cells);
00259 }
00260
00268 Triangle& cell(size_t i)
00269 {
00270 return (*__cells)[i];
00271 }
00272
00280 const Triangle& cell(size_t i) const
00281 {
00282 return (*__cells)[i];
00283 }
00284
00290 inline void setNumberOfCells(const int n)
00291 {
00292 __cells = new Vector<Triangle>(n);
00293 }
00294
00301 inline const size_t& numberOfCells() const
00302 {
00303 return (*__cells).size();
00304 }
00305
00306 size_t cellNumber(const Triangle& t) const
00307 {
00308 return (*__cells).number(t);
00309 }
00310
00318 const FaceType& face(const size_t& i) const
00319 {
00320 return (*__edgesSet)[i];
00321 }
00322
00323 SurfaceMeshOfTriangles(const size_t theNumberOfCells)
00324 : SurfaceMesh(Mesh::surfaceMeshTriangles),
00325 __cells(new Vector<Triangle>(theNumberOfCells)),
00326 __connectivity(*this)
00327 {
00328 ;
00329 }
00330
00331 SurfaceMeshOfTriangles(ReferenceCounting<VerticesSet> vertices,
00332 ReferenceCounting<VerticesCorrespondance> correspondances,
00333 ReferenceCounting<Vector<Triangle> > triangles)
00334 : SurfaceMesh(Mesh::surfaceMeshTriangles,
00335 vertices,
00336 correspondances),
00337 __cells(triangles),
00338 __connectivity(*this)
00339 {
00340 ;
00341 }
00342
00347 SurfaceMeshOfTriangles()
00348 : SurfaceMesh(Mesh::surfaceMeshTriangles),
00349 __connectivity(*this)
00350 {
00351 ;
00352 }
00353
00358 ~SurfaceMeshOfTriangles()
00359 {
00360 ;
00361 }
00362 };
00363
00364 #endif // SURFACE_MESH_OF_TRIANGLES_HPP
00365