vtf-logo

SimpMeshRed.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__geom_mesh_simplicial_SimpMeshRed_h__)
00009 #define __geom_mesh_simplicial_SimpMeshRed_h__
00010 
00011 #include "SmrNode.h"
00012 #include "SmrCell.h"
00013 #include "FaceIterator.h"
00014 #include "EdgeIterator.h"
00015 
00016 #include "../iss/IndSimpSetIncAdj.h"
00017 #include "../simplex/Simplex.h"
00018 
00019 #include "../../../ads/functor/composite_compare.h"
00020 #include "../../../ads/iterator/MemFunIterator.h"
00021 #include "../../../ads/algorithm/Triplet.h"
00022 
00023 #include <list>
00024 #include <set>
00025 #include <map>
00026 
00027 #include <cassert>
00028 
00029 BEGIN_NAMESPACE_GEOM
00030 
00032 
00040 template<int _N, 
00041          int _M = _N,
00042          typename T = double,
00043          template<class> class _Node = SmrNode,
00044          template<class> class _Cell = SmrCell,
00045          // CONTINUE
00046          // Had to add the allocator class to appease MSVC++.
00047          // See notes below.
00048          template<class _Elem,
00049                   class = std::allocator<_Elem> > class Container =
00050          std::list>
00051 class SimpMeshRed {
00052   //
00053   // Enumerations.
00054   //
00055 
00056 public:
00057 
00059   enum {N = _N, M = _M};
00060   
00061   //
00062   // Types.
00063   //
00064 
00065 private:
00066 
00067   // CONTINUE
00068   // I should be able to do this more cleanly.  See page 112 of
00069   // "C++ Templates, The Complete Guide".  I have to add the allocator to
00070   // get MSVC++ to compile it.
00071   typedef Container<_Node<SimpMeshRed>, 
00072                     std::allocator<_Node<SimpMeshRed> > > NodeContainer;
00073   typedef Container<_Cell<SimpMeshRed>,
00074                     std::allocator<_Cell<SimpMeshRed> > > CellContainer;
00075 
00076 public:
00077 
00078   //
00079   // Nodes.
00080   //
00081 
00083   typedef typename NodeContainer::value_type Node;
00085   typedef typename NodeContainer::iterator NodeIterator;
00087   typedef typename NodeContainer::const_iterator NodeConstIterator;
00088 
00089   //
00090   // Cells.
00091   //
00092 
00094   typedef typename CellContainer::value_type Cell;
00096   typedef typename CellContainer::iterator CellIterator;
00098   typedef typename CellContainer::const_iterator CellConstIterator;
00099 
00100   //
00101   // Faces.
00102   //
00103   
00105   typedef std::pair<CellConstIterator,int> ConstFace;
00107   typedef FaceIterator<M,ConstFace,CellConstIterator> 
00108   FaceConstIterator;
00110   typedef std::pair<CellIterator,int> Face;
00112   typedef FaceIterator<M,Face,CellIterator> FaceIterator;
00113 
00114   //
00115   // Edges.
00116   //
00117 
00119   typedef ads::Triplet<CellConstIterator,int,int> ConstEdge;
00121   typedef EdgeIterator<SimpMeshRed,true> EdgeConstIterator;
00123   typedef ads::Triplet<CellIterator,int,int> Edge;
00125   typedef EdgeIterator<SimpMeshRed,false> EdgeIterator;
00126 
00127   //
00128   // Miscellaneous.
00129   //
00130 
00132   typedef T Number;
00134   typedef typename Node::Vertex Vertex;
00136   typedef BBox<N,Number> BBox;
00137 
00139   typedef int SizeType;
00141   typedef typename NodeContainer::difference_type DifferenceType;
00142 
00143   //
00144   // Simplex
00145   //
00146 
00148   typedef Simplex<M,int> IndexedSimplex;
00150   typedef Simplex<M,Vertex> Simplex;
00151 
00152   //
00153   // Node member function iterators.
00154   //
00155 
00157   typedef ads::MemFunIterator<NodeConstIterator,Node, const Vertex&,true>
00158   VertexIterator;
00160   typedef ads::MemFunIterator<NodeConstIterator,Node,int,true>
00161   NodeIdentifierIterator;
00163   typedef ads::MemFunIterator<CellConstIterator,Cell,int,true>
00164   CellIdentifierIterator;
00165 
00166   //
00167   // Indexed simplex iterator.
00168   //
00169 
00170 #define __geom_mesh_simplicial_SMR_IndSimpIter_ipp__
00171 #include "SMR_IndSimpIter.ipp"
00172 #undef __geom_mesh_simplicial_SMR_IndSimpIter_ipp__
00173 
00175   typedef IndSimpIter IndexedSimplexIterator;
00176 
00177   //
00178   // Simplex iterator.
00179   //
00180 
00181 #define __geom_mesh_simplicial_SMR_SimpIter_ipp__
00182 #include "SMR_SimpIter.ipp"
00183 #undef __geom_mesh_simplicial_SMR_SimpIter_ipp__
00184 
00186   typedef SimpIter SimplexIterator;
00187 
00189   struct NodeIteratorCompare : 
00190     public std::binary_function<NodeIterator, NodeIterator, bool> {
00192     bool
00193     operator()(const NodeIterator& x, const NodeIterator& y) const {
00194       return x->getIdentifier() < y->getIdentifier();
00195     }
00196   };
00197 
00199   struct CellIteratorCompare : 
00200     public std::binary_function<CellIterator, CellIterator, bool> {
00202     bool
00203     operator()(const CellIterator& x, const CellIterator& y) const {
00204       return x->getIdentifier() < y->getIdentifier();
00205     }
00206   };
00207 
00209   struct FaceCompare : 
00210     public std::binary_function<Face, Face, bool> {
00212     bool
00213     operator()(const Face& x, const Face& y) const {
00214       return x.first->getIdentifier() < y.first->getIdentifier() ||
00215         (x.first->getIdentifier() == y.first->getIdentifier() &&
00216           x.second < y.second);
00217     }
00218   };
00219 
00221   struct FaceIteratorCompare : 
00222     public std::binary_function<FaceIterator, FaceIterator, bool> {
00224     bool
00225     operator()(const FaceIterator& x, const FaceIterator& y) const {
00226       return x->first->getIdentifier() < y->first->getIdentifier() ||
00227         (x->first->getIdentifier() == y->first->getIdentifier() &&
00228           x->second < y->second);
00229     }
00230   };
00231 
00233   typedef std::set<NodeIterator, NodeIteratorCompare> NodeIteratorSet;
00235   typedef std::set<CellIterator, CellIteratorCompare> CellIteratorSet;
00237   typedef std::set<Face, FaceCompare> FaceSet;
00239   typedef std::set<FaceIterator, FaceIteratorCompare> FaceIteratorSet;
00240 
00241 
00242   //
00243   // Data
00244   //
00245     
00246 private:
00247       
00249   NodeContainer _nodes;
00251   CellContainer _cells;
00252      
00253 public:
00254 
00255   //--------------------------------------------------------------------------
00258 
00260   SimpMeshRed() :
00261     _nodes(),
00262     _cells()
00263   {}
00264 
00266   SimpMeshRed(const SimpMeshRed& other) :
00267     _nodes(other._nodes),
00268     _cells(other._cells)
00269   {}
00270 
00272   template< bool A, typename V, typename IS >
00273   SimpMeshRed(const IndSimpSet<N,M,A,Number,V,IS>& iss) :
00274     _nodes(),
00275     _cells() {
00276     build(iss);
00277   }
00278 
00280   SimpMeshRed& 
00281   operator=(const SimpMeshRed& other) {
00282     if (&other != this) {
00283       _nodes = other._nodes;
00284       _cells = other._cells;
00285     }
00286     return *this;
00287   }
00288 
00290 
00294   template<typename VertInIter, typename SimpInIter>
00295   void
00296   build(VertInIter verticesBeginning, VertInIter verticesEnd, 
00297         SimpInIter simplicesBeginning, SimpInIter simplicesEnd);
00298   
00300   template< bool A, typename V, typename IS >
00301   void
00302   build(const IndSimpSet<N,M,A,Number,V,IS>& iss) {
00303     build(iss.getVerticesBeginning(), iss.getVerticesEnd(),
00304           iss.getIndexedSimplicesBeginning(), iss.getIndexedSimplicesEnd());
00305   }
00306 
00308   void
00309   swap(SimpMeshRed& x) {
00310     _nodes.swap(x._nodes);
00311     _cells.swap(x._cells);
00312   }
00313 
00315   void
00316   clear() {
00317     _nodes.clear();
00318     _cells.clear();
00319   }
00320 
00322   ~SimpMeshRed()
00323   {}
00324 
00326   //--------------------------------------------------------------------------
00329 
00331   int
00332   getSpaceDimension() const {
00333     return N;
00334   }
00335 
00337   int
00338   getSimplexDimension() const {
00339     return M;
00340   }
00341   
00343   //--------------------------------------------------------------------------
00346 
00348   bool
00349   areNodesEmpty() const {
00350     return _nodes.empty();
00351   }
00352 
00354 
00357   SizeType
00358   computeNodesSize() const {
00359     return SizeType(_nodes.size());
00360   }
00361 
00363   NodeConstIterator
00364   getNodesBeginning() const {
00365     return _nodes.begin();
00366   }
00367 
00369   NodeConstIterator
00370   getNodesEnd() const {
00371     return _nodes.end();
00372   }
00373 
00375   VertexIterator
00376   getVerticesBeginning() const {
00377     return VertexIterator(&Node::getVertex, _nodes.begin());
00378   }
00379 
00381   VertexIterator
00382   getVerticesEnd() const {
00383     return VertexIterator(&Node::getVertex, _nodes.end());
00384   }
00385 
00387   NodeIdentifierIterator
00388   getNodeIdentifiersBeginning() const {
00389     return NodeIdentifierIterator(&Node::getIdentifier, _nodes.begin());
00390   }
00391 
00393   NodeIdentifierIterator
00394   getNodeIdentifiersEnd() const {
00395     return NodeIdentifierIterator(&Node::getIdentifier, _nodes.end());
00396   }
00397 
00399 
00403   int
00404   computeMaximumNodeIdentifier() const {
00405     if (areNodesEmpty()) {
00406       // Return -1 because one more than the "maximum" is then 0.
00407       return -1;
00408     }
00409     return *std::max_element(getNodeIdentifiersBeginning(),
00410                              getNodeIdentifiersEnd());
00411   }
00412 
00414   //--------------------------------------------------------------------------
00417 
00419   bool
00420   areCellsEmpty() const {
00421     return _cells.empty();
00422   }
00423 
00425 
00428   SizeType
00429   computeCellsSize() const {
00430     return SizeType(_cells.size());
00431   }
00432 
00434   CellConstIterator
00435   getCellsBeginning() const {
00436     return _cells.begin();
00437   }
00438 
00440   CellConstIterator
00441   getCellsEnd() const {
00442     return _cells.end();
00443   }
00444 
00446   void
00447   getSimplex(CellConstIterator i, Simplex* s) const {
00448     for (int m = 0; m != M+1; ++m) {
00449       (*s)[m] = i->getNode(m)->getVertex();
00450     }
00451   }
00452 
00454   CellIdentifierIterator
00455   getCellIdentifiersBeginning() const {
00456     return CellIdentifierIterator(&Cell::getIdentifier, _cells.begin());
00457   }
00458 
00460   CellIdentifierIterator
00461   getCellIdentifiersEnd() const {
00462     return CellIdentifierIterator(&Cell::getIdentifier, _cells.end());
00463   }
00464 
00466 
00470   int
00471   computeMaximumCellIdentifier() const {
00472     if (areCellsEmpty()) {
00473       // Return -1 because one more than the "maximum" is then 0.
00474       return -1;
00475     }
00476     return *std::max_element(getCellIdentifiersBeginning(),
00477                              getCellIdentifiersEnd());
00478   }
00479 
00481   //--------------------------------------------------------------------------
00484 
00486   IndexedSimplexIterator
00487   getIndexedSimplicesBeginning() const {
00488     return IndexedSimplexIterator(getCellsBeginning());
00489   }
00490 
00492   IndexedSimplexIterator
00493   getIndexedSimplicesEnd() const {
00494     return IndexedSimplexIterator(getCellsEnd());
00495   }
00496 
00498   SimplexIterator
00499   getSimplicesBeginning() const {
00500     return SimplexIterator(getCellsBeginning());
00501   }
00502 
00504   SimplexIterator
00505   getSimplicesEnd() const {
00506     return SimplexIterator(getCellsEnd());
00507   }
00508 
00510   //--------------------------------------------------------------------------
00513 
00515 
00518   SizeType
00519   computeFacesSize() const {
00520     return SizeType(std::distance(getFacesBeginning(), getFacesEnd()));
00521   }
00522 
00524   FaceConstIterator
00525   getFacesBeginning() const {
00526     FaceConstIterator x(getCellsBeginning(), getCellsEnd());
00527     return x;
00528   }
00529 
00531   FaceConstIterator
00532   getFacesEnd() const {
00533     return FaceConstIterator(getCellsEnd(), getCellsEnd());
00534   }
00535 
00537   //--------------------------------------------------------------------------
00540 
00542 
00545   SizeType
00546   computeEdgesSize() const {
00547     return std::distance(getEdgesBeginning(), getEdgesEnd());
00548   }
00549 
00551   EdgeConstIterator
00552   getEdgesBeginning() const {
00553     EdgeConstIterator x(getCellsBeginning(), getCellsEnd());
00554     return x;
00555   }
00556 
00558   EdgeConstIterator
00559   getEdgesEnd() const {
00560     return EdgeConstIterator(getCellsEnd(), getCellsEnd());
00561   }
00562 
00564   //--------------------------------------------------------------------------
00567 
00569   NodeIterator
00570   getNodesBeginning() {
00571     return _nodes.begin();
00572   }
00573 
00575   NodeIterator
00576   getNodesEnd() {
00577     return _nodes.end();
00578   }
00579 
00581 
00585   void
00586   setNodeIdentifiers() const;
00587 
00589   template<typename VertexInIter>
00590   void
00591   setVertices(VertexInIter begin, VertexInIter end) {
00592     for (NodeIterator i = getNodesBeginning(); i != getNodesEnd(); 
00593          ++i, ++begin) {
00594 #ifdef DEBUG_SimpMeshRed
00595       assert(begin != end);
00596 #endif
00597       i->setVertex(*begin);
00598     }
00599     assert(begin == end);
00600   }
00601 
00603   //--------------------------------------------------------------------------
00606 
00608   CellIterator
00609   getCellsBeginning() {
00610     return _cells.begin();
00611   }
00612 
00614   CellIterator
00615   getCellsEnd() {
00616     return _cells.end();
00617   }
00618   
00620 
00624   void
00625   setCellIdentifiers() const;
00626 
00628   //--------------------------------------------------------------------------
00631 
00633   FaceIterator
00634   getFacesBeginning() {
00635     return FaceIterator(getCellsBeginning(), getCellsEnd());
00636   }
00637 
00639   FaceIterator
00640   getFacesEnd() {
00641     return FaceIterator(getCellsEnd(), getCellsEnd());
00642   }
00643 
00645   //--------------------------------------------------------------------------
00648 
00650   EdgeIterator
00651   getEdgesBeginning() {
00652     return EdgeIterator(getCellsBeginning(), getCellsEnd());
00653   }
00654 
00656   EdgeIterator
00657   getEdgesEnd() {
00658     return EdgeIterator(getCellsEnd(), getCellsEnd());
00659   }
00660 
00662   //--------------------------------------------------------------------------
00665 
00667 
00670   NodeIterator
00671   insertNode(const Node& node = Node());
00672 
00674   NodeIterator
00675   insertNode(const NodeIterator node) {
00676     return insert_vertex(*node);
00677   }
00678 
00680 
00683   void
00684   eraseNode(const NodeIterator node) {
00685     _nodes.erase(node);
00686   }
00687 
00689 
00692   void
00693   merge(NodeIterator x, NodeIterator y) {
00694 #if 0
00695     // CONTINUE
00696     std::cerr << "Merge " << x->getIdentifier() << " "
00697               << y->getIdentifier() << "\n";
00698 #endif
00699     assert(x != y);
00700     // Merge the vertex-simplex incidences.
00701     x->insertCells(y->getCellIteratorsBeginning(), y->getCellIteratorsEnd());
00702     // Fix the simplex-vertex incidences.
00703     y->replace(x);
00704     // Erase the second vertex.
00705     eraseNode(y);
00706   }
00707 
00709   //--------------------------------------------------------------------------
00712 
00714   CellIterator
00715   insertCell(const Cell& c = Cell());
00716 
00718   CellIterator
00719   insertCell(const CellIterator c) {
00720     return insertCell(*c);
00721   }
00722 
00724 
00727   void
00728   eraseCell(const CellIterator c) {
00729     c->unlink();
00730     _cells.erase(c);
00731   }
00732 
00734 
00739   template<typename InIter>
00740   void
00741   eraseCells(InIter begin, InIter end) {
00742     for (; begin != end; ++begin) {
00743       eraseCell(*begin);
00744     }
00745   }
00746 
00748 
00749 private:
00750 
00751   /* CONTINUE REMOVE
00752   template<class Map>
00753   void
00754   map_NodeIterators_to_indices(Map& x) const;
00755   */
00756 
00757   void
00758   buildCellAdjacencies();
00759   
00760 };
00761 
00762 END_NAMESPACE_GEOM
00763 
00764 #define __geom_mesh_simplicial_SimpMeshRed_ipp__
00765 #include "SimpMeshRed.ipp"
00766 #undef __geom_mesh_simplicial_SimpMeshRed_ipp__
00767 
00768 #endif

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