KWStyle - itkMesh.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkMesh.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:41 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 =========================================================================*/
20 #ifndef __itkMesh_h
21 #define __itkMesh_h
22
23 #if defined(_MSC_VER)
24 #pragma warning ( disable : 4786 )
25 #endif
26
27 #include "itkPointSet.h"
28 #include "itkCellInterface.h"
29 #include "itkMapContainer.h"
30 #include <vector>
31 #include <set>
32
33
34 namespace itk
35 {
36
37 /**
38  * Due to a bug in MSVC, an enum value cannot be accessed out of a template
39  * parameter until the template class opens.  In order for templated classes
40  * to access the dimension of an image template parameter in defining their
41  * own dimension, this class is needed as a work-around.
42  */
43 template <typename TMesh>
44 struct GetMeshDimension
45 {
46 LEN,IND itkStaticConstMacro(MaxTopologicalDimension, unsigned int, TMesh::MaxTopologicalDimension); 
47 IND itkStaticConstMacro(PointDimension, unsigned int,  TMesh::PointDimension);
48 }; 
49   
50
51 /** \class Mesh
52  * \brief Implements the N-dimensional mesh structure.
53  *
54  * \par Overview
55  * Mesh implements the N-dimensional mesh structure for ITK.  It provides
56  * an API to perform operations on points, cells, boundaries, etc., but
57  * does not tie down the underlying implementation and storage.  A
58  * "MeshTraits" structure is used to define the container and identifier
59  * types that will be used to access the mesh.  See DefaultStaticMeshTraits
60  * for the set of type definitions needed.  All types that are defined
61  * in the "MeshTraits" structure will have duplicate typedefs in the resulting
62  * mesh itself.
63  *
64  * Mesh is an adaptive, evolving structure. Typically points and cells
65  * are created, with the cells referring to their defining points. If 
66  * additional topological information is required, then BuildCellLinks() is
67  * called and links from the points back to the cells that use them are
68  * created. This allows implicit topological information about the faces
69  * and edges of the cells to be determined. (For example, a "face" neighbor
70  * to a cell can be determined by intersection the sets of cells that use
71  * the points defining the face. This is an inherent assumption on the
72  * manifold relationship of the cells in the mesh.) In some cases, either
73  * because the mesh is non-manifold, because we wish to explicitly store
74  * information with the faces and edges of the mesh, or because performance
75  * requirements demand that boundaries are explicitly represented (the set
76  * intersection does not need to be performed); then Mesh can be further
77  * extended by adding explicit boundary assignments.
78  *
79  * \par Usage
80  * Mesh has three template parameters.  The first is the pixel type, or the
81  * type of data stored (optionally) with points, cells, and/or boundaries.
82  * The second is the geometric dimension of the points defining the mesh. This
83  * also limits the maximum topological dimension of the cells that can be
84  * inserted. The third template parameter is the "MeshTraits" structure
85  * controlling type information for the mesh.  Most users will be happy 
86  * with the defaults, and will not have to worry about this third argument.
87  *  
88  * One of the most important parts of using this mesh is how to create
89  * cells to insert into it.  The cells for the mesh take two template
90  * parameters.  The first is the pixel type, and should correspond
91  * exactly to that type given to the mesh.  The second is a
92  * "CellTraits" which holds a sub-set of the "MeshTraits" structure
93  * definitions, and is also a member of them.  Any cell which is to be
94  * inserted to a mesh should have MeshTraits::CellTraits as its second
95  * template parameter.
96  *  
97  * Template parameters for Mesh:
98  *  
99  * TPixelType =
100  *     The type stored as data for an entity (cell, point, or boundary).
101  *  
102  * TMeshTraits =
103  *     Type information structure for the mesh.
104  *
105  * \par References
106  * No reference information is available.
107  *
108  * \ingroup MeshObjects
109  */
110 template <
111   typename TPixelType,
112   unsigned int VDimension = 3,
113 LEN   typename TMeshTraits = DefaultStaticMeshTraits< TPixelType , VDimension, VDimension >
114 IND **>
115 class ITK_EXPORT Mesh : public PointSet<TPixelType, VDimension, TMeshTraits>
116 {
117 public:
118   /** Standard typedefs. */
119   typedef Mesh                Self;
120 TDA   typedef PointSet<TPixelType, VDimension, TMeshTraits>  Superclass;
121   typedef SmartPointer<Self>  Pointer;
122 TDA   typedef SmartPointer<const Self>  ConstPointer;
123
124   typedef typename Superclass::RegionType RegionType;
125
126   /** Method for creation through the object factory. */
127   itkNewMacro(Self);
128
129   /** Standard part of every itk Object. */
130   itkTypeMacro(Mesh, PointSet);
131
132   /** Hold on to the type information specified by the template parameters. */
133   typedef TMeshTraits   MeshTraits;
134 TDA   typedef typename MeshTraits::PixelType                PixelType;  
135 TDA   typedef typename MeshTraits::CellPixelType            CellPixelType;  
136
137   /** Convenient constants obtained from TMeshTraits template parameter. */
138   itkStaticConstMacro(PointDimension, unsigned int,
139                       TMeshTraits::PointDimension);
140   itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
141                       TMeshTraits::MaxTopologicalDimension);
142
143   /** Enum defining the possible methods used to allocate memory for
144    * the Cells */
145   typedef  enum {     CellsAllocationMethodUndefined,
146 IND **********************CellsAllocatedAsStaticArray, 
147 IND **********************CellsAllocatedAsADynamicArray,
148 IND **********************CellsAllocatedDynamicallyCellByCell
149 IND ************************************************} CellsAllocationMethodType;
150
151   /** Convenient typedefs obtained from TMeshTraits template parameter. */
152   typedef typename MeshTraits::CoordRepType            CoordRepType;  
153   typedef typename MeshTraits::InterpolationWeightType InterpolationWeightType;
154   typedef typename MeshTraits::PointIdentifier         PointIdentifier;
155   typedef typename MeshTraits::CellIdentifier          CellIdentifier;
156   typedef typename MeshTraits::CellFeatureIdentifier   CellFeatureIdentifier;
157   typedef typename MeshTraits::PointType               PointType;
158   typedef typename MeshTraits::PointsContainer         PointsContainer;
159   typedef typename MeshTraits::CellTraits              CellTraits;
160   typedef typename MeshTraits::CellsContainer          CellsContainer;
161   typedef typename MeshTraits::PointCellLinksContainer PointCellLinksContainer;
162   typedef typename MeshTraits::CellLinksContainer      CellLinksContainer;
163   typedef typename MeshTraits::PointDataContainer      PointDataContainer;
164   typedef typename MeshTraits::CellDataContainer       CellDataContainer;  
165
166   /** Used to support geometric operations on the toolkit. */
167   typedef PointLocator<PointIdentifier,itkGetStaticConstMacro(PointDimension),
168                        CoordRepType,PointsContainer>  PointLocatorType;
169   typedef BoundingBox<PointIdentifier,itkGetStaticConstMacro(PointDimension),
170                       CoordRepType,PointsContainer>   BoundingBoxType;
171
172   /** Create types that are pointers to each of the container types. */
173   typedef typename PointsContainer::Pointer       PointsContainerPointer;
174   typedef typename CellsContainer::Pointer        CellsContainerPointer;
175   typedef typename CellLinksContainer::Pointer    CellLinksContainerPointer;
176   typedef typename PointDataContainer::Pointer    PointDataContainerPointer;
177   typedef typename CellDataContainer::Pointer     CellDataContainerPointer;
178   typedef typename PointLocatorType::Pointer      PointLocatorPointer;
179   typedef typename BoundingBoxType::Pointer       BoundingBoxPointer;
180
181   /** Create types that are iterators for each of the container types. */
182   typedef typename
183 IND **********PointsContainer::ConstIterator        PointsContainerConstIterator;
184   typedef typename
185 IND **********PointsContainer::Iterator             PointsContainerIterator;
186   typedef typename
187 IND **********CellsContainer::ConstIterator         CellsContainerConstIterator;
188   typedef typename
189 IND **********CellsContainer::Iterator              CellsContainerIterator;
190   typedef typename
191 IND **********CellLinksContainer::ConstIterator     CellLinksContainerIterator;
192   typedef typename
193 IND **********PointDataContainer::ConstIterator     PointDataContainerIterator;
194   typedef typename
195 IND **********CellDataContainer::ConstIterator      CellDataContainerIterator;
196   typedef typename
197 TDA,IND *****PointCellLinksContainer::const_iterator  PointCellLinksContainerIterator;
198
199   /** A useful rename. */
200   typedef CellFeatureIdentifier  CellFeatureCount;
201
202   /** The base cell type for cells in this mesh. */
203   typedef CellInterface<CellPixelType,CellTraits>  CellType;
204   typedef typename CellType::CellAutoPointer       CellAutoPointer;
205
206   /** Visiting cells. */
207   typedef typename CellType::MultiVisitor CellMultiVisitorType;
208
209
210 EML
211   /** An explicit cell boundary assignment can be accessed through the cell
212    *  identifier to which the assignment is made, and the feature Id of the
213    *  boundary feature within the cell that is being assigned.
214    *
215    *  This class provides a pair of these identifiers with appropriate
216    *  comparison operators available for use of the Ids in sorted container
217    *  classes.  */
218   class BoundaryAssignmentIdentifier
219 MCM,IND **{
220   public:
221     /** Create an alias to BoundaryAssignmentIdentifier. */
222     typedef BoundaryAssignmentIdentifier Self;
223
224     /** Constructor just takes the cell and feature identifiers, or defaults
225      *  to their individual default values.  */
226     BoundaryAssignmentIdentifier() {}
227     BoundaryAssignmentIdentifier(CellIdentifier cellId,
228                                  CellFeatureIdentifier featureId):
229 IND ******m_CellId(cellId), m_FeatureId(featureId) {}    
230
231     /** The Cell's identification. */
232     CellIdentifier m_CellId;
233
234     /** The identification of the feature within the cell. */
235     CellFeatureIdentifier  m_FeatureId;
236
237     /** Most containers require a "<" operator to be defined for their key
238      *  types.  */
239     bool operator < (const Self& r) const
240       {
241       return ((m_CellId < r.m_CellId) ||
242               ((m_CellId == r.m_CellId) && (m_FeatureId < r.m_FeatureId)));
243       }
244
245     /** Most containers require a "==" operator to be defined for their key
246      *  types.  */
247     bool operator == (const Self& r) const
248       {
249       return ((m_CellId == r.m_CellId) && (m_FeatureId == r.m_FeatureId));
250       }
251   }; // End Class: Mesh::BoundaryAssignmentIdentifier
252
253
254   /** Used for manipulating boundaries and boundary attributes.  A
255    * BoundaryAssignmentsContainerVector is indexed by dimension.  For
256    * each dimension, it points to a MapContainer indexed by a
257    * BoundaryAssignmentIdentifier, which encapsulates a cell
258    * identifier and a boundary feature identifier.  The boundary
259    * feature identifier distinguishes different boundary features for
260    * a given cell at a given dimension.  */
261   typedef MapContainer< BoundaryAssignmentIdentifier , CellIdentifier >
262 IND ********BoundaryAssignmentsContainer;
263   typedef typename BoundaryAssignmentsContainer::Pointer
264 IND ********BoundaryAssignmentsContainerPointer;
265   typedef std::vector< BoundaryAssignmentsContainerPointer >
266 IND ********BoundaryAssignmentsContainerVector;
267
268
269 protected:
270
271   /** Holds cells used by the mesh.  Individual cells are accessed
272    *  through cell identifiers.  */
273   CellsContainerPointer  m_CellsContainer;
274
275   /** An object containing data associated with the mesh's cells.
276    *  Optionally, this can be NULL, indicating that no data are associated
277    *  with the cells.  The data for a cell can be accessed through its cell
278    *  identifier.  */
279   CellDataContainerPointer  m_CellDataContainer;
280
281   /** An object containing parent cell links for each point.  Since a point
282    *  can be used by multiple cells, each point identifier accesses another
283    *  container which holds the cell identifiers */
284   CellLinksContainerPointer  m_CellLinksContainer;
285
286   /** A vector of objects containing explicit cell boundary assignments.
287    *  The vector is indexed by the topological dimension of the cell
288    *  boundary.  The container for each topological dimension holds
289    *  boundary identifiers of the assigned boundaries.  The containers are
290    *  keyed by BoundaryAssignmentIdentifier objects (see above).  The
291    *  boundary identifiers can be used to access the boundaries themselves
292    *  in the containers stored in the Boundaries vector.  They can also be
293    *  used to access the data stored by a particular boundary through the
294    *  containers in the BoundaryData vector.  */
295   BoundaryAssignmentsContainerVector  m_BoundaryAssignmentsContainers;
296
297 public:
298   /** Mesh-level operation interface. */
299   unsigned long GetNumberOfCells() const;
300   void PassStructure(Self* inputMesh);
301   virtual void Initialize();
302
303   /** Methods for managing Mesh filters that have internal mini-pipelines */
304   virtual void CopyInformation(const DataObject *data);
305   virtual void Graft(const DataObject *data);
306   
307   /** Access m_CellsLinksContainer, which contains parent cell links
308    * for each point.  Since a point can be used by multiple cells,
309    * each point identifier accesses another container which holds the
310    * cell identifiers */
311   void SetCellLinks(CellLinksContainer*);
312 #ifndef CABLE_CONFIGURATION
313   CellLinksContainerPointer GetCellLinks();
314   const CellLinksContainerPointer GetCellLinks() const;
315
316   /** Access m_CellsContainer, which holds cells used by the mesh.
317    *  Individual cells are accessed through cell identifiers.  */
318   void SetCells(CellsContainer*);
319
320   CellsContainerPointer GetCells();
321   const CellsContainerPointer GetCells() const;
322 #endif
323   /** Access m_CellDataContainer, which contains data associated with
324    *  the mesh's cells.  Optionally, this can be NULL, indicating that
325    *  no data are associated with the cells.  The data for a cell can
326    *  be accessed through its cell identifier.  */
327   void SetCellData(CellDataContainer*);
328   CellDataContainerPointer GetCellData();
329   const CellDataContainerPointer GetCellData() const;
330
331   /** 
332    * Set/get the BoundaryAssignmentsContainer for a given dimension.
333    * The BoundaryAssignmentsContainer is a MapContainer indexed by a
334    * BoundaryAssignmentIdentifier, which encapsulates a cell
335    * identifier and a boundary feature identifier.  The boundary
336    * feature identifier distinguishes different boundary features for
337    * a given cell at a given dimension.
338    */
339   void SetBoundaryAssignments(int dimension,
340                               BoundaryAssignmentsContainer*);
341 #ifndef CABLE_CONFIGURATION
342   BoundaryAssignmentsContainerPointer GetBoundaryAssignments(int dimension);
343   const BoundaryAssignmentsContainerPointer GetBoundaryAssignments(
344     int dimension) const;
345
346   /** Access routines to fill the Cells container (m_CellsContainer),
347    *  and get information from it.  If SetCell is used to overwrite a
348    *  cell currently in the mesh, it is the caller's responsibility to
349    *  release the memory for the cell currently at the CellIdentifier
350    *  position prior to calling SetCell. */
351   void SetCell(CellIdentifier, CellAutoPointer & );
352   bool GetCell(CellIdentifier, CellAutoPointer & ) const;
353 #endif
354   /** Access routines to fill the CellData container, and get information
355    *  from it.  */
356   void SetCellData(CellIdentifier, CellPixelType);
357   bool GetCellData(CellIdentifier, CellPixelType*) const;
358
359   /** 
360    * Explicitly assign \a boundaryId as a part of the boundary of \a
361    * cellId.  The identifiers \a boundaryId and \a cellId must
362    * identify cell objects already in the mesh.  The dimension of \a
363    * boundaryId must be specified by \a dimension, and a unique
364    * CellFeatureIdentifier \a featureId must be assigned for each
365    * distinct boundary feature of a given dimension.
366    * CellFeatureIdentifier is equivalent to <tt>unsigned long</tt> by
367    * default, and this typedef will not typically need to be changed.
368    * The UsingCells list of \a boundaryId is automatically updated to
369    * include \a cellId.
370    */
371   void SetBoundaryAssignment(int dimension, CellIdentifier cellId,
372                              CellFeatureIdentifier featureId,
373                              CellIdentifier boundaryId);
374
375   /** For the given cellId, get the identifier of a particular
376    * boundary feature of the given dimension.  The featureId
377    * determines which boundary feature of the specified dimension is
378    * returned.  For instance, if dimension is 1 and featureId is 0,
379    * then GetBoundaryAssignment finds the 0th edge of the given cell.
380    * The return value indicates whether a feature of the appropriate
381    * dimension and featureId exists.  If it does not, the
382    * BoundaryIdentifier pointer is left unchanged. */
383   bool GetBoundaryAssignment(int dimension, CellIdentifier cellId,
384                              CellFeatureIdentifier featureId,
385                              CellIdentifier* boundaryId) const;
386   bool RemoveBoundaryAssignment(int dimension, CellIdentifier cellId,
387                                 CellFeatureIdentifier featureId);
388
389   /** Interface to cells. */
390   CellFeatureCount GetNumberOfCellBoundaryFeatures(int dimension,
391                                                    CellIdentifier) const;
392
393 #ifndef CABLE_CONFIGURATION
394   /** Get the boundary feature of the given dimension of the given cell
395    * corresponding to the given feature identifier. */
396   bool GetCellBoundaryFeature(int dimension, CellIdentifier,
397                               CellFeatureIdentifier, CellAutoPointer& ) const;
398 #endif
399   /** Get the set of cells neighboring the given cell across the given boundary
400    * feature.  Returns the number of neighbors found.  If cellSet is not NULL,
401    * the set of cell pointers is filled in with identifiers of the neighboring
402    * cells. */
403   unsigned long GetCellBoundaryFeatureNeighbors(
404     int dimension, CellIdentifier, CellFeatureIdentifier,
405     std::set<CellIdentifier>* cellSet);
406
407   /** Get the set of cells having the given cell as part of their
408    *  boundary.  Returns the number of neighbors found.  If cellSet is
409    *  not NULL, the set of cell pointers is filled in with identifiers
410    *  of the neighboring cells. */
411   unsigned long GetCellNeighbors( CellIdentifier cellId,
412                                   std::set<CellIdentifier>* cellSet );
413 #ifndef CABLE_CONFIGURATION
414   /**
415    * Check if there is an explicitly assigned boundary feature for the
416    * given dimension and cell- and cell-feature-identifiers.  If there
417    * is, a pointer to it is given back through \a boundary (if \a
418    * boundary != NULL) and \c true is returned.  Otherwise, \c false is
419    * returned.
420    */
421   bool GetAssignedCellBoundaryIfOneExists(int dimension, CellIdentifier,
422                                           CellFeatureIdentifier,
423                                           CellAutoPointer& ) const;
424 #endif
425   /** Dynamically build the links from points back to their using cells.  This
426    * information is stored in the cell links container, not in the points. */
427   void BuildCellLinks();
428
429 #ifndef CABLE_CONFIGURATION
430   /** Get the bounding box of a cell in the mesh. The user
431    *  must supply the bounding box. The methods return a pointer to
432    *  the user-supplied bounding box as a convenience. */
433   BoundingBoxPointer GetCellBoundingBox(CellIdentifier cellId, 
434                                         BoundingBoxPointer bbox);
435
436   /** This method iterates over all the cells in the mesh and has
437    *  each cell Accept the MultiVisitor. See MultiVisitor for more 
438    *  information.  (Note, this follows the Visitor Design Pattern.) */
439   virtual void Accept(CellMultiVisitorType* mv);
440 #endif
441   /** Set/Get the identification of the method used to allocate cells
442 IND ******\warning Failure to call this method correctly will lead to memory leaks
443 IND ******and/or segmentation faults because the cell memory will not be erased or
444 IND ******will be erased with an improper method.  */
445   itkSetMacro( CellsAllocationMethod, CellsAllocationMethodType );  
446 LEN   itkGetConstReferenceMacro( CellsAllocationMethod, CellsAllocationMethodType );  
447
448 protected:
449   /** Constructor for use by New() method. */
450   Mesh();
451   ~Mesh();
452   void PrintSelf(std::ostream& os, Indent indent) const;
453
454   /** Release the memory allocated for the cells pointers. This is done
455 IND ******based on information provided by the user through the method
456 IND ******SetCellsAllocationMethod()   */
457   void ReleaseCellsMemory();
458
459 private:
460   Mesh(const Self&); //purposely not implemented
461   void operator=(const Self&); //purposely not implemented
462
463   CellsAllocationMethodType             m_CellsAllocationMethod;
464
465 }; // End Class: Mesh
466
467 // end namespace itk
468
469 #ifndef ITK_MANUAL_INSTANTIATION
470 #ifndef CABLE_CONFIGURATION
471 #include "itkMesh.txx"
472 #endif
473 #endif
474
475 #endif
476
477 EOF
478 EOF,EML
479 EOF,EML

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:22PM
© Kitware Inc.