KWStyle - itkCellInterface.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkCellInterface.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:33 $
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      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 #ifndef __itkCellInterface_h
18 #define __itkCellInterface_h
19
20 #include "itkObject.h"
21 #include "itkObjectFactory.h"
22 #include <map>
23 #include "itkCellInterfaceVisitor.h"
24 #include "itkAutoPointer.h"
25 #include "itkArray.h"
26
27
28 // Define a macro for CellInterface sub-classes to use
29 // to define the Accept and GetTopologyId virtuals used
30 // by the MultiVisitor class
31 #define itkCellVisitMacro(TopologyId) \
32 IND **static int GetTopologyId() {return TopologyId;}\
33 LEN,IND **virtual void Accept(unsigned long cellid, typename CellInterface<PixelType, CellTraits>::MultiVisitor* mv)\
34 IND ****{\
35 LEN,IND ******typename CellInterfaceVisitor<PixelType, CellTraits>::Pointer v = mv->GetVisitor(TopologyId);\
36 IND ******if(v)\
37 IND ********{\
38 IND ********v->VisitFromCell(cellid, this);\
39 IND ********}\
40 IND ****}
41
42
43 EML
44 // Define a macro for the common typedefs required by the 
45 // classes deriving form CellInterface (included).
46 // This wouldn't be necessary if SGI compilers 
47 // were able to inherit types.
48 #define itkCellCommonTypedefs( celltype ) \
49 IND **typedef celltype                  Self;   \
50 IND **typedef AutoPointer<const Self>   ConstSelfAutoPointer;  \
51 IND **typedef AutoPointer<Self>         SelfAutoPointer;   \
52 IND **typedef Self *                    RawPointer;        \
53 IND **typedef const Self *              ConstRawPointer;   \
54 IND **SelfAutoPointer   New(void) {                        \
55 IND ****************SelfAutoPointer ptr( new celltype );   \
56 IND ****************ptr.TakeOwnership();                   \
57 IND ****************return ptr;                            \
58 IND ****************}                                      \
59
60
61 // Define a macro for the common typedefs required by the 
62 // classes deriving form CellInterface (excluded).
63 // This wouldn't be necessary if SGI compilers 
64 // were able to inherit types.
65 #define itkCellInheritedTypedefs( superclassArg ) \
66 IND **typedef superclassArg                                Superclass; \
67 IND **typedef typename Superclass::PixelType               PixelType;  \
68 IND **typedef typename Superclass::CellType                CellType;  \
69 IND **typedef typename Superclass::CellAutoPointer         CellAutoPointer;  \
70 IND **typedef typename Superclass::CellConstAutoPointer    CellConstAutoPointer;  \
71 IND **typedef typename Superclass::CellRawPointer          CellRawPointer;  \
72 IND **typedef typename Superclass::CellConstRawPointer     CellConstRawPointer;  \
73 IND **typedef typename Superclass::CellTraits              CellTraits;  \
74 IND **typedef typename Superclass::CoordRepType            CoordRepType;  \
75 LEN,IND **typedef typename Superclass::InterpolationWeightType InterpolationWeightType; \
76 IND **typedef typename Superclass::PointIdentifier         PointIdentifier; \
77 IND **typedef typename Superclass::PointIdIterator         PointIdIterator; \
78 IND **typedef typename Superclass::PointIdConstIterator    PointIdConstIterator; \
79 IND **typedef typename Superclass::CellIdentifier          CellIdentifier; \
80 IND **typedef typename Superclass::CellFeatureIdentifier   CellFeatureIdentifier; \
81 IND **typedef typename Superclass::CellFeatureIdentifier   CellFeatureCount; \
82 IND **typedef typename Superclass::PointType               PointType; \
83 IND **typedef typename Superclass::PointsContainer         PointsContainer; \
84 IND **typedef typename Superclass::UsingCellsContainer     UsingCellsContainer; \
85 IND **typedef typename Superclass::CellGeometry            CellGeometry;  \
86 LEN,TDA,IND **typedef typename Superclass::ParametricCoordArrayType  ParametricCoordArrayType;  \
87 LEN,TDA,IND **typedef typename Superclass::ShapeFunctionsArrayType   ShapeFunctionsArrayType;  \
88 IND **itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension)
89  
90
91
92 EML
93 namespace itk
94 {
95
96 /** \class CellInterface
97  * Define an abstract interface for cells.  Actual cell types derive from
98  * this class.
99  *
100  * Template parameters for Cell:
101  *
102  * TPixelType = The type stored with an entity (cell, point, or boundary).
103  *
104  * TCellTraits = Type information for cell.
105  *
106  * \ingroup MeshObjects
107  */
108 template <
109   typename TPixelType,
110   typename TCellTraits
111 IND **>
112 class CellInterface
113 {
114 public:
115
116   /** Standard class typedefs. */
117   itkCellCommonTypedefs(CellInterface);
118
119 IND ***/** Save the PixelType template parameter. */
120   typedef TPixelType                                PixelType;
121   
122   /** Save the CellTraits template parameter. */
123   typedef TCellTraits                                 CellTraits;
124
125   /** Save type information for this cell. */
126   typedef typename CellTraits::CoordRepType            CoordRepType;
127   typedef typename CellTraits::InterpolationWeightType InterpolationWeightType;
128   typedef typename CellTraits::PointIdentifier         PointIdentifier;
129   typedef typename CellTraits::PointIdIterator         PointIdIterator;
130   typedef typename CellTraits::PointIdConstIterator    PointIdConstIterator;
131   typedef typename CellTraits::CellIdentifier          CellIdentifier;
132   typedef typename CellTraits::CellFeatureIdentifier   CellFeatureIdentifier;
133   typedef typename CellTraits::PointType               PointType;
134   typedef typename CellTraits::PointsContainer         PointsContainer;
135   typedef typename CellTraits::UsingCellsContainer     UsingCellsContainer;
136     
137   /** Save the dimension from the template parameters. */
138   itkStaticConstMacro(PointDimension, unsigned int,CellTraits::PointDimension);
139
140   /** An iterator through the UsingCellsContainer. */
141   typedef typename UsingCellsContainer::iterator  UsingCellsContainerIterator;
142
143   /** Give this and all derived classes quick access to the base cell type. */
144   typedef CellInterface         CellType;
145   typedef SelfAutoPointer       CellAutoPointer;
146   typedef ConstSelfAutoPointer  CellConstAutoPointer;
147   typedef RawPointer            CellRawPointer;
148   typedef ConstRawPointer       CellConstRawPointer;
149   
150   /** A useful rename. */
151   typedef CellFeatureIdentifier  CellFeatureCount;
152
153   /**  Cell Visitor interfaces */
154 LEN   enum CellGeometry {VERTEX_CELL=0, LINE_CELL, TRIANGLE_CELL, QUADRILATERAL_CELL, 
155 IND ********POLYGON_CELL, TETRAHEDRON_CELL, HEXAHEDRON_CELL, 
156 IND ********QUADRATIC_EDGE_CELL, QUADRATIC_TRIANGLE_CELL,
157 IND ********LAST_ITK_CELL, MAX_ITK_CELLS=255};
158
159   /** Types needed to contour the cells */
160   typedef Array<CoordRepType>                 ParametricCoordArrayType;
161   typedef Array<InterpolationWeightType>      ShapeFunctionsArrayType;
162
163   static int GetNextUserCellId(); // never return > MAX_INTERFACE
164
165   /** \brief A visitor that can visit different cell types in a mesh.
166    * CellInterfaceVisitor instances can be registered for each
167    * type of cell that needs to be visited.
168    *
169    * \ingroup MeshAccess */
170 MCM   class MultiVisitor : public LightObject
171 IND **{ 
172   public:
173     /**  Visitor type, because VisualC++ 6.0 does not like
174      *  Visitor being a nested type of CellInterfaceVisitor   */
175     typedef CellInterfaceVisitor<TPixelType, TCellTraits> VisitorType;
176
177     /** Standard class typedefs.   */
178     typedef MultiVisitor       Self;
179 TDA     typedef SmartPointer<Self>  Pointer;
180       
181     /** Method for creation through the object factory.   */
182     //itkNewMacro(Self);
183     static  Pointer New(void) { return new Self; }
184   
185     /** Run-time type information (and related methods).   */
186     itkTypeMacro(MultiVisitor,LightObject);
187   
188     /** Typedefs for the visitor class.   */
189     typedef typename VisitorType::Pointer VisitorPointer;
190 LEN,TDA     typedef typename std::map<int, VisitorPointer>::value_type VisitorPointerValueType;
191
192   public:
193     VisitorType * GetVisitor(int id)
194       {
195 IND ********if(id <= LAST_ITK_CELL)
196           {
197           return m_Visitors[id];
198           }
199         else
200           {
201           typename std::map<int, ITK_TYPENAME VisitorType::Pointer>::iterator
202 IND ************pos = m_UserDefined.find(id);
203 IND **********if(pos != m_UserDefined.end())
204 IND ************{
205 IND ************return (*pos).second;
206 IND ************}
207 IND **********}
208 IND ********return 0;
209       }
210     void AddVisitor(VisitorType* v)
211       {
212 IND ********int id = v->GetCellTopologyId();
213 IND ********if(id <= LAST_ITK_CELL)
214           {
215           m_Visitors[id] = v;
216           }
217         else
218           {
219           m_UserDefined.insert(VisitorPointerValueType(id,v));
220           }
221       }
222     virtual ~MultiVisitor() {}
223   protected:
224 LEN     VisitorPointer m_Visitors[LAST_ITK_CELL]; // fixed array set to the size from the enum
225 LEN     std::map<int,VisitorPointer> m_UserDefined; // user defined cell types go here
226 IND **};
227
228   /** This must be implemented by all sub-classes of CellInterface */
229   virtual void Accept(unsigned long cellId, MultiVisitor*)= 0; 
230   
231 LEN   /**  Return the type of the cell (one of the CellGeometry enums listed above). */
232   virtual CellGeometry GetType(void) const =0;
233
234   /** Create a new copy of this cell.  This is provided so that a copy can
235    * be made without knowing the cell type. */
236   virtual void MakeCopy( CellAutoPointer & ) const = 0;
237   
238   /** Get the topological dimension of this cell. */
239   virtual unsigned int GetDimension(void) const=0;
240
241   /** Get the interpolation order of the cell.  Usually linear. */
242   virtual unsigned int GetInterpolationOrder(void) const;
243   
244   /** Get the number of points required to define the cell. */
245   virtual unsigned int GetNumberOfPoints(void) const=0;
246   
247   /** Get the number of boundary features of a given dimension on this cell. */
248   virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const =0;
249   
250   /** Get the boundary feature corresponding to the given dimension and Id. */
251 LEN   virtual bool GetBoundaryFeature(int dimension, CellFeatureIdentifier, CellAutoPointer & )=0;
252
253   /** Get the point id list used by the cell in a form suitable to pass to
254    * SetPointIds(first) on another cell.  This is equivalent to
255    * PointIdsBegin() const. */
256   virtual PointIdConstIterator GetPointIds(void) const;
257   
258   /** Set the point id list used by the cell.  It is assumed that the given
259    * iterator can be incremented and safely de-referenced enough times to 
260    * get all the point ids needed by the cell. */
261   virtual void SetPointIds(PointIdConstIterator first)=0;
262   
263   /** Set the point id list used by the cell.  It is assumed that the range
264    * of iterators [first, last) contains the correct number of points needed to
265    * define the cell.  The position *last is NOT referenced, so it can safely
266    * be one beyond the end of an array or other container. */
267   virtual void SetPointIds(PointIdConstIterator first,
268                            PointIdConstIterator last)=0;
269   
270 LEN   /** Set the point identifier for a given spot in the point list for the cell. */
271   virtual void SetPointId(int localId, PointIdentifier)=0;
272   
273   /** Get a begin iterator to the list of point identifiers used by the cell. */
274   virtual PointIdIterator PointIdsBegin(void)=0;
275
276   /** Get a const begin iterator to the list of point identifiers used
277    * by the cell. */
278   virtual PointIdConstIterator PointIdsBegin(void) const =0;
279
280   /** Get an end iterator to the list of point identifiers used by the cell. */
281   virtual PointIdIterator PointIdsEnd(void)=0;
282
283   /** Get a const end iterator to the list of point identifiers used
284    * by the cell. */
285   virtual PointIdConstIterator PointIdsEnd(void) const =0;
286
287   /** Given the parametric coordinates of a point in the cell
288    * (pCoords[CellDimension]), get the closest cell boundary feature of
289    * topological dimension CellDimension-1.  If the "inside" pointer is not
290    * NULL, the flag is set to indicate whether the point is inside the cell. */
291   virtual bool GetClosestBoundary(CoordRepType [], bool* , CellAutoPointer &) 
292     {return false;}
293
294   /** Given the geometric coordinates of a point (coord[PointDimension]),
295    * return whether it is inside the cell.  Also perform the following
296    * calculations, if the corresponding result pointers are not NULL:
297    *
298    *  - Find the closest point in or on the cell to the given point
299    *     (Returns through pointer to array: closestPoint[PointDimension]).
300    *
301    *  - Get the cell's parametric coordinates for the given point
302    *     (Returns through pointer to array: pCoords[CellDimension]).
303    *
304    *  - Get the square of the distance between the point and the cell
305    *     (this is the distance from the point to the closest point,
306    *      returned through "dist2" pointer).
307    *
308    *  - Get the interpolation weights for the cell
309    *     (Returns through pointer to array: weights[NumberOfPoints]). */
310   virtual bool EvaluatePosition(CoordRepType* ,
311                                 PointsContainer* ,
312                                 CoordRepType* ,
313                                 CoordRepType [],
314                                 double *,
315                                 InterpolationWeightType*)
316     {return bool();}
317   
318   /** Given the parametric coordinates of a point in the cell
319    *  determine the value of its Shape Functions
320    *  returned through an itkArray<InterpolationWeightType>).  */
321   virtual void EvaluateShapeFunctions( 
322                           const ParametricCoordArrayType &,
323                                 ShapeFunctionsArrayType  &) const {}
324
325   /** Intersect the cell with a line given by an origin (origin[PointDimension])
326    * and direction (direction[PointDimension]).  The intersection point
327    * found will be within the given tolerance of the real intersection.
328    * Get the following results if the corresponding pointers are not NULL:
329    *
330    *  - The intersection point's geometric coordinates (returned through
331    *     pointer to array: coords[PointDimension]).
332    *
333    *  - The line's parametric coordinate of the intersection point
334    *     (returned through "t" pointer).
335    *
336    *  - The cell's parametric coordinates of the intersection point
337    *     (returned through pointer to array: pCoords[CellDimension]).
338    *
339    * Returns whether an intersection exists within the given tolerance. */
340   virtual bool IntersectWithLine(CoordRepType [PointDimension],
341                                  CoordRepType [PointDimension],
342                                  CoordRepType ,
343                                  CoordRepType [PointDimension],
344                                  CoordRepType*,
345                                  CoordRepType []) {return bool();}
346   
347   /** Compute cell bounding box and store in the user-provided array.
348    * Array is ordered (xmin, xmax,  ymin, ymax, ....).  A pointer to the
349    * array is returned for convenience.  This allows code like:
350    * "CoordRep* bounds = cell->GetBoundingBox(new CoordRep[6]);". */
351   CoordRepType* GetBoundingBox(CoordRepType [PointDimension*2]) {return NULL;}
352
353   /** Compute the square of the diagonal length of the bounding box. */
354   CoordRepType GetBoundingBoxDiagonalLength2(void) {return NULL;}
355
356   /** Intersect the given bounding box (bounds[PointDimension*2]) with a line
357    * given by an origin (origin[PointDimension]) and direction
358    * (direction[PointDimension]). Get the following results if the
359    * corresponding pointers are not NULL:
360    *
361    *  - The intersection point's geometric coordinates (returned through
362    *     pointer to array: coords[PointDimension]).
363    *
364    *  - The line's parametric coordinate of the intersection point
365    *     (returned through "t" pointer).
366    *
367    * Returns whether an intersection exists. */
368   virtual bool IntersectBoundingBoxWithLine(CoordRepType [PointDimension*2],
369                                             CoordRepType [PointDimension],
370                                             CoordRepType [PointDimension],
371                                             CoordRepType [PointDimension],
372                                             CoordRepType* ) {return bool();}
373   
374   /** Interface to the boundary form of the cell to set/get UsingCells.
375    * See the boundary wrapper source for more information. */
376
377   /** Returns true if the cell has been explicitly assigned as a
378    *  boundary, false otherwise. */
379   virtual bool IsExplicitBoundary(void);
380
381   /**
382    * Register the fact that this cell is a part of the boundary of the
383    * cell \a cellId, by adding \a cellId to the UsingCellsContainer.
384    */
385   virtual void AddUsingCell(CellIdentifier cellId);
386
387   /**
388    * Remove a cell from the UsingCellsContainer.
389    */
390   virtual void RemoveUsingCell(CellIdentifier cellId);
391
392   /**
393    * Test if a cell is in the UsingCellsContainer.  A result of \c true
394    * indicates that this cell is part of the boundary of the cell \a
395    * cellId, assuming that boundary information has been recorded.
396    */
397   virtual bool IsUsingCell(CellIdentifier cellId);
398
399   /**
400    * Get the number of cells in the UsingCellsContainer.
401    */
402   virtual unsigned int GetNumberOfUsingCells(void);
403
404   /**
405    * Get a begin iterator for the UsingCellsContainer.
406    */
407   virtual UsingCellsContainerIterator UsingCellsBegin(void);
408
409   /**
410    * Get an end iterator for the UsingCellsContainer.
411    */
412   virtual UsingCellsContainerIterator UsingCellsEnd(void);
413     
414   /** Standard part of every itk Object. */
415   itkTypeMacro(CellInterface, LightObject);
416
417 public:
418   CellInterface() {}
419   virtual ~CellInterface() {}
420   /** Cell internal utility routines. */
421
422   /** Get the geometric position of a point. */
423 IND //  bool GetPointPosition(PointsContainer*, int localId, Point*)=0;
424
425 protected:
426   /** Store the set of cells using this boundary. */
427   UsingCellsContainer m_UsingCells;
428
429 private:
430   CellInterface(const Self&); //purposely not implemented
431   void operator=(const Self&); //purposely not implemented  
432 };
433
434
435 /**
436  * \brief A simple utility class to define the cell type inside a mesh type
437  * structure definition.  This just makes a copy of existing type information
438  * that is needed for a cell type template parameter.
439  *
440  * During a mesh type definition, after the appropriate types and values
441  * have been defined, just have the line:
442 IND *\verbatim
443 IND *typedef itkMakeCellTraitsMacro  CellTraits;
444 IND *\endverbatim
445  *
446  * itkMakeCellTraitsMacro is a macro front-end to automatically fill in the 
447  * template parameters for the CellTraitsInfo structure inside a mesh 
448  * type structure definition.
449  *
450  * \ingroup MeshObjects
451  */
452 template <int VPointDimension, typename TCoordRep,
453   typename TInterpolationWeight, typename TPointIdentifier,
454   typename TCellIdentifier, typename TCellFeatureIdentifier,
455   typename TPoint, typename TPointsContainer,
456   typename TUsingCellsContainer>
457 class CellTraitsInfo
458 MCM {
459 public:
460   itkStaticConstMacro(PointDimension, unsigned int, VPointDimension);
461   typedef TCoordRep               CoordRepType;
462   typedef TInterpolationWeight    InterpolationWeightType;
463   typedef TPointIdentifier        PointIdentifier;
464   typedef TCellIdentifier         CellIdentifier;
465   typedef TCellFeatureIdentifier  CellFeatureIdentifier;
466   typedef TPoint                  PointType;
467   typedef TPointsContainer        PointsContainer;
468   typedef TUsingCellsContainer    UsingCellsContainer;
469   typedef PointIdentifier*        PointIdIterator;
470   typedef const PointIdentifier*  PointIdConstIterator;  
471 };
472
473 #define itkMakeCellTraitsMacro \
474 IND **CellTraitsInfo<itkGetStaticConstMacro(PointDimension), CoordRepType, \
475                InterpolationWeightType,  \
476                PointIdentifier, CellIdentifier, CellFeatureIdentifier, \
477                PointType, PointsContainer, UsingCellsContainer>
478
479 // end namespace itk
480
481 #ifndef ITK_MANUAL_INSTANTIATION
482 #include "itkCellInterface.txx"
483 #endif
484
485 #endif
486

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