vtf-logo

SmrNode.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__geom_mesh_simplicial_SmrNode_h__)
00009 #define __geom_mesh_simplicial_SmrNode_h__
00010 
00011 #if defined(DEBUG_geom) && !defined(DEBUG_SmrNode)
00012 #define DEBUG_SmrNode
00013 #endif
00014 
00015 #ifdef DEBUG_SmrNode
00016 #ifndef DEBUG_Node_VertSelfId
00017 // Debug the base class.
00018 #define DEBUG_Node_VertSelfId
00019 #endif
00020 #endif
00021 
00022 #include "Node_VertSelfId.h"
00023 
00024 #include "../../../ads/iterator/IndirectIterator.h"
00025 
00026 #include <vector>
00027 
00028 BEGIN_NAMESPACE_GEOM
00029 
00031 
00037 template<class SMR>
00038 class SmrNode {
00039   //
00040   // Enumerations.
00041   //
00042 
00043 public:
00044 
00046   enum {N = SMR::N};
00047 
00048   //
00049   // Public types.
00050   //
00051 
00052 public:
00053 
00055   typedef SMR Mesh;
00056 
00058   typedef typename Mesh::CellIterator CellIterator;
00060   typedef typename Mesh::CellConstIterator CellConstIterator;
00061 
00063   typedef typename Mesh::NodeIterator NodeIterator;
00065   typedef typename Mesh::NodeConstIterator NodeConstIterator;
00066 
00068   typedef typename Mesh::Number Number;
00070   typedef ads::FixedArray<N,Number> Vertex;
00071 
00072   //
00073   // Private types.
00074   //
00075 
00076 private:
00077 
00079   typedef std::vector<CellIterator> CellIteratorContainer;
00080 
00081   //
00082   // More public types.
00083   //
00084 
00085 public:
00086 
00088   typedef typename CellIteratorContainer::iterator CellIteratorIterator;
00090   typedef typename CellIteratorContainer::const_iterator 
00091   CellIteratorConstIterator;
00092 
00094   typedef ads::IndirectIterator<typename CellIteratorContainer::iterator> 
00095   CellIncidentToNodeIterator;
00097   typedef ads::IndirectIterator<typename 
00098   CellIteratorContainer::const_iterator> 
00099   CellIncidentToNodeConstIterator;
00100 
00101   //
00102   // Data
00103   //
00104       
00105 private:
00106       
00108   Vertex _vertex;
00110   NodeIterator _self;
00112   mutable int _identifier;
00114   CellIteratorContainer _cells;
00115 
00116 public:
00117 
00118   //--------------------------------------------------------------------------
00121 
00123   SmrNode() :
00124     _vertex(),
00125     _self( 0 ),
00126     _identifier(-1),
00127     _cells()
00128   {}
00129 
00131   SmrNode(const Vertex& vertex, const int identifier = -1) :
00132     _vertex(vertex),
00133     _self(0),
00134     _identifier(identifier),
00135     _cells()
00136   {}
00137 
00139   void
00140   build(const Vertex& vertex, const int identifier = -1,
00141         const NodeIterator self = 0) {
00142     _vertex = vertex;
00143     _self = self;
00144     _identifier = identifier;
00145     _cells.clear();
00146   }
00147 
00149   SmrNode(const SmrNode& other) :
00150     _vertex(other._vertex),
00151     _self(other._self),
00152     _identifier(other._identifier),
00153     _cells(other._cells)
00154   {}
00155 
00157   ~SmrNode()
00158   {}
00159 
00161   //--------------------------------------------------------------------------
00164       
00166   SmrNode& 
00167   operator=(const SmrNode& other) {
00168     if (&other != this) {
00169       _vertex = other._vertex;
00170       _self = other._self;
00171       _identifier = other._identifier;
00172       _cells = other._cells;
00173     }
00174     return *this;
00175   }
00176 
00178   //--------------------------------------------------------------------------
00181 
00183   const Vertex&
00184   getVertex() const { 
00185     return _vertex;
00186   }
00187 
00189 
00193   int
00194   getIdentifier() const {
00195     return _identifier;
00196   }
00197 
00199   NodeConstIterator
00200   getSelf() const { 
00201     return _self;
00202   }
00203 
00205   CellConstIterator
00206   getCell() const {
00207     // If there are no incident cells.
00208     if (_cells.empty()) {
00209       // Return a null iterator.
00210       return CellConstIterator(0);
00211     }
00212     // Return the first adjacent cell in the container.
00213     return _cells.front();
00214   }
00215 
00217   int
00218   getCellsSize() const {
00219     return int(_cells.size());
00220   }
00221 
00223   CellIncidentToNodeConstIterator
00224   getCellsBeginning() const {
00225     return CellIncidentToNodeConstIterator(_cells.begin());
00226   }
00227 
00229   CellIncidentToNodeConstIterator
00230   getCellsEnd() const {
00231     return CellIncidentToNodeConstIterator(_cells.end());
00232   }
00233 
00235   CellIteratorConstIterator
00236   getCellIteratorsBeginning() const {
00237     return _cells.begin();
00238   }
00239 
00241   CellIteratorConstIterator
00242   getCellIteratorsEnd() const {
00243     return _cells.end();
00244   }
00245 
00247   bool
00248   hasCell(const CellConstIterator cellIterator) const {
00249     for (CellIteratorConstIterator i = _cells.begin(); i != _cells.end(); 
00250          ++i) {
00251       if (*i == cellIterator) {
00252         return true;
00253       }
00254     }
00255     return false;
00256   }
00257 
00259 
00263   bool
00264   isOnBoundary() const {
00265     // For each simplex incident to this vertex.
00266     for (CellIteratorConstIterator cii = _cells.begin();
00267          cii != _cells.end(); ++cii) {
00268       // If this cell has a face incident to this vertex and on the boundary.
00269       if ((*cii)->hasIncidentBoundaryFace(getSelf())) {
00270         // This vertex is on the boundary.
00271         return true;
00272       }
00273     }
00274     // We did not encounter any incident boundary faces.
00275     return false;
00276   }
00277 
00278 
00280   //--------------------------------------------------------------------------
00283 
00285   void
00286   setVertex(const Vertex& vertex) { 
00287     _vertex = vertex;
00288   }
00289 
00291 
00295   void
00296   setIdentifier(const int identifier) const { 
00297     _identifier = identifier;
00298   }
00299 
00301   NodeIterator
00302   getSelf() { 
00303     return _self;
00304   }
00305 
00307   void
00308   setSelf(const NodeIterator self) { 
00309     _self = self;
00310   }
00311 
00313   CellIterator
00314   getCell() { 
00315     // If there are no incident cells.
00316     if (_cells.empty()) {
00317       // Return a null iterator.
00318       return CellIterator(0);
00319     }
00320     // Return the first adjacent cell in the container.
00321     return _cells.front();
00322   }
00323 
00325   void
00326   insertCell(const CellIterator c) {
00327     // The cell iterator should not be null.
00328     assert(c != 0);
00329 #ifdef DEBUG_SmrNode
00330     // The cell should not already be in the container of incident cells.
00331     // This test is a little expensive, so it is only checked in debugging 
00332     // mode.
00333     assert(! hasCell(c));
00334 #endif    
00335     _cells.push_back(c);
00336   }
00337 
00339   template<typename CellIterInIter>
00340   void
00341   insertCells(CellIterInIter begin, CellIterInIter end) {
00342     for (; begin != end; ++begin) {
00343       insertCell(*begin);
00344     }
00345   }
00346 
00348   void
00349   removeCell(const CellIterator c) {
00350     // Find the cell.
00351     CellIteratorIterator i;
00352     i = std::find(_cells.begin(), _cells.end(), c);
00353     // The specified cell must be incident to this vertex.
00354     assert(i != _cells.end());
00355     // Remove the incident cell.
00356     _cells.erase(i);
00357   }
00358 
00360   CellIncidentToNodeIterator
00361   getCellsBeginning() {
00362     return CellIncidentToNodeIterator(_cells.begin());
00363   }
00364 
00366   CellIncidentToNodeIterator
00367   getCellsEnd() {
00368     return CellIncidentToNodeIterator(_cells.end());
00369   }
00370 
00372   CellIteratorIterator
00373   getCellIteratorsBeginning() {
00374     return _cells.begin();
00375   }
00376 
00378   CellIteratorIterator
00379   getCellIteratorsEnd() {
00380     return _cells.end();
00381   }
00382 
00384 
00387   void
00388   replace(NodeIterator node) {
00389     // Vertex Index.
00390     int vertexIndex;
00391     // Loop over the incident cells.
00392     CellIncidentToNodeIterator i = getCellsBeginning();
00393     CellIncidentToNodeIterator iEnd = getCellsEnd();
00394     for (; i != iEnd; ++i) {
00395       // The index of this node.
00396       vertexIndex = i->getIndex(getSelf());
00397       // Replace this node with the specified one.
00398       i->setNode(vertexIndex, node);
00399     }
00400   }
00401 
00403   //--------------------------------------------------------------------------
00406   
00408   bool
00409   operator==(const SmrNode& x) const {
00410     return _self == x._self && _vertex == x._vertex && 
00411       _identifier == x._identifier && _cells == x._cells;
00412   }
00413 
00415   bool
00416   operator!=(const SmrNode& x) const {
00417     return ! operator==(x);
00418   }
00419 
00421   //--------------------------------------------------------------------------
00424 
00426   void
00427   put(std::ostream& out) const {
00428     // Write the point and the vertex identifier.
00429     out << "Vertex = " << _vertex << " Id = " << getIdentifier();
00430     // Write the incident cell identifiers.
00431     const int iEnd = int(_cells.size());
00432     // CONTINUE REMOVE
00433     out << " cells = ";
00434     for (int i = 0; i != iEnd; ++i) {
00435       out << " " << _cells[i]->getIdentifier();
00436     }
00437     out << "\n";
00438   }
00439 
00441 };
00442 
00443 END_NAMESPACE_GEOM
00444 
00445 #endif

Generated on Fri Aug 24 12:55:59 2007 for Computational Geometry Package by  doxygen 1.4.7