ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshPolygonCell.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkQuadEdgeMeshPolygonCell_h
00019 #define __itkQuadEdgeMeshPolygonCell_h
00020 
00021 #include "itkTriangleCell.h"
00022 #include "itkQuadEdgeMeshLineCell.h"
00023 namespace itk
00024 {
00037 template< class TCellInterface >
00038 class ITK_EXPORT QuadEdgeMeshPolygonCell:public TCellInterface
00039 {
00040 public:
00042   // itkCellCommonTypedefs
00043   typedef QuadEdgeMeshPolygonCell   Self;
00044   typedef AutoPointer< const Self > ConstSelfAutoPointer;
00045   typedef AutoPointer< Self >       SelfAutoPointer;
00046   typedef Self *                    RawPointer;
00047   typedef const Self *              ConstRawPointer;
00048 
00049   // itkCellInheritedTypedefs
00050   typedef TCellInterface                                Superclass;
00051   typedef typename Superclass::PixelType                PixelType;
00052   typedef typename Superclass::CellType                 CellType;
00053   typedef typename Superclass::CellAutoPointer          CellAutoPointer;
00054   typedef typename Superclass::CellConstAutoPointer     CellConstAutoPointer;
00055   typedef typename Superclass::CellRawPointer           CellRawPointer;
00056   typedef typename Superclass::CellConstRawPointer      CellConstRawPointer;
00057   typedef typename Superclass::CellTraits               CellTraits;
00058   typedef typename Superclass::CoordRepType             CoordRepType;
00059   typedef typename Superclass::InterpolationWeightType  InterpolationWeightType;
00060   typedef typename Superclass::PointIdentifier          PointIdentifier;
00061   typedef typename Superclass::CellIdentifier           CellIdentifier;
00062   typedef typename Superclass::CellFeatureIdentifier    CellFeatureIdentifier;
00063   typedef typename Superclass::CellFeatureIdentifier    CellFeatureCount;
00064   typedef typename Superclass::PointType                PointType;
00065   typedef typename Superclass::PointsContainer          PointsContainer;
00066   typedef typename Superclass::UsingCellsContainer      UsingCellsContainer;
00067   typedef typename Superclass::CellGeometry             CellGeometry;
00068   typedef typename Superclass::ParametricCoordArrayType ParametricCoordArrayType;
00069   typedef typename Superclass::ShapeFunctionsArrayType  ShapeFunctionsArrayType;
00070   itkStaticConstMacro(PointDimension, unsigned int, Superclass::PointDimension);
00071   itkStaticConstMacro(CellDimension, unsigned int, 2);
00072 
00074   typedef typename CellType::MultiVisitor MultiVisitor;
00075 
00076   typedef QuadEdgeMeshLineCell< CellType > EdgeCellType;
00077   typedef std::vector< EdgeCellType * >    EdgeCellListType;
00078 
00080   typedef typename CellTraits::PointIdIterator              PointIdIterator;
00081   typedef typename CellTraits::PointIdConstIterator         PointIdConstIterator;
00082   typedef typename CellTraits::PointIdInternalIterator      PointIdInternalIterator;
00083   typedef typename CellTraits::PointIdInternalConstIterator PointIdInternalConstIterator;
00084 
00086   typedef typename CellTraits::QuadEdgeType        QuadEdgeType;
00087   typedef typename QuadEdgeType::OriginRefType     VertexRefType;
00088   typedef typename QuadEdgeType::DualOriginRefType FaceRefType;
00089   typedef typename QuadEdgeType::PrimalDataType    PrimalDataType;
00090   typedef typename QuadEdgeType::DualDataType      DualDataType;
00091   typedef typename QuadEdgeType::DualType          QEDual;
00092 public:
00093 
00095   itkTypeMacro(QuadEdgeMeshPolygonCell, TCellInterface);
00096 
00098   QuadEdgeMeshPolygonCell(PointIdentifier nPoints = 0);
00099   QuadEdgeMeshPolygonCell(QuadEdgeType *e);
00100   virtual ~QuadEdgeMeshPolygonCell();
00102 
00104   void SetIdent(CellIdentifier cid) { m_Ident = cid; }
00105   CellIdentifier GetIdent()          { return ( m_Ident ); }
00107 
00109   QuadEdgeType * GetEdgeRingEntry() const { return ( m_EdgeRingEntry ); }
00110   void SetEdgeRingEntry(QuadEdgeType *entry) { m_EdgeRingEntry = entry; }
00112 
00114   SelfAutoPointer New();
00115 
00117   virtual void Accept(CellIdentifier cellId, MultiVisitor *mv);
00118 
00119   virtual CellGeometry GetType() const { return ( Superclass::POLYGON_CELL ); }
00120 
00122   static int GetTopologyId()
00123   {
00124     return ( Superclass::POLYGON_CELL );
00125   }
00126 
00127   virtual unsigned int GetDimension() const
00128   {
00129     return ( Self::CellDimension );
00130   }
00131 
00132   virtual unsigned int GetNumberOfPoints() const;
00133 
00134   virtual CellFeatureCount GetNumberOfBoundaryFeatures(int dimension) const;
00135 
00136   virtual bool GetBoundaryFeature(int dimension,
00137                                   CellFeatureIdentifier cellId,
00138                                   CellAutoPointer & cell);
00139 
00141   virtual void MakeCopy(CellAutoPointer & cell) const
00142   {
00143     const PointIdentifier numberOfPoints = this->GetNumberOfPoints();
00144     Self *                newPolygonCell = new Self(numberOfPoints);
00146 
00147     cell.TakeOwnership(newPolygonCell);
00148     if ( numberOfPoints )
00149       {
00150       for ( PointIdentifier i = 0; i < numberOfPoints; i++ )
00151         {
00152         newPolygonCell->SetPointId( i, this->GetPointId(i) );
00153         }
00154       }
00155   }
00156 
00158   virtual void SetPointIds(PointIdConstIterator first);
00159 
00160   virtual void SetPointIds(PointIdConstIterator first,
00161                            PointIdConstIterator last);
00162 
00163   virtual void SetPointId(int localId, PointIdentifier pId);
00164 
00165   virtual PointIdentifier GetPointId(int localId) const;
00166 
00167   virtual PointIdIterator PointIdsBegin()
00168   {
00169     // NOTE ALEX: should update the array on the fly to make it faster
00170     MakePointIds();
00171     if ( m_PointIds.size() == 0 )
00172       {
00173       return ( static_cast< PointIdIterator >( 0 ) );
00174       }
00175     else
00176       {
00177       return &*( m_PointIds.begin() );
00178       }
00179   }
00180 
00181   virtual PointIdIterator PointIdsEnd()
00182   {
00183     // NOTE ALEX: should update the array on the fly to make it faster
00184     if ( m_PointIds.size() == 0 )
00185       {
00186       return ( static_cast< PointIdIterator >( 0 ) );
00187       }
00188     else
00189       {
00190       return &m_PointIds[m_PointIds.size() - 1] + 1;
00191       }
00192   }
00193 
00194   virtual PointIdConstIterator PointIdsBegin() const
00195   {
00196     // NOTE ALEX: should update the array on the fly to make it faster
00197     MakePointIds();
00198     if ( m_PointIds.size() == 0 )
00199       {
00200       return ( static_cast< PointIdIterator >( 0 ) );
00201       }
00202     else
00203       {
00204       return &*( m_PointIds.begin() );
00205       }
00206   }
00207 
00208   virtual PointIdConstIterator PointIdsEnd() const
00209   {
00210     // NOTE ALEX: should update the array on the fly to make it faster
00211     if ( m_PointIds.size() == 0 )
00212       {
00213       return ( static_cast< PointIdIterator >( 0 ) );
00214       }
00215     else
00216       {
00217       return &m_PointIds[m_PointIds.size() - 1] + 1;
00218       }
00219   }
00220 
00222   virtual void InternalSetPointIds(PointIdInternalConstIterator first);
00223 
00224   virtual void InternalSetPointIds(PointIdInternalConstIterator first,
00225                                    PointIdInternalConstIterator last);
00226 
00227   virtual PointIdInternalIterator InternalPointIdsBegin();
00228 
00229   virtual PointIdInternalIterator InternalPointIdsEnd();
00230 
00231   virtual PointIdInternalConstIterator InternalGetPointIds() const;
00232 
00233   virtual PointIdInternalConstIterator InternalPointIdsBegin() const;
00234 
00235   virtual PointIdInternalConstIterator InternalPointIdsEnd() const;
00236 
00237 protected:
00238   typedef std::vector< PointIdentifier > PointIDListType;
00239   mutable PointIDListType m_PointIds;
00240 private:
00241   QuadEdgeMeshPolygonCell(const Self &); // Not impl.
00242   void operator=(const Self &);          // Not impl.
00243 
00244   void MakePointIds() const
00245   {
00246     if ( !this->GetNumberOfPoints() )
00247       {
00248       return;
00249       }
00250 
00251     // NOTE ALEX: very inefficient way of doing it ...
00252     // you wanna support old API, you pay for it.
00253     m_PointIds.clear();
00254     for ( PointIdentifier i = 0; i < this->GetNumberOfPoints(); i++ )
00255       {
00256       m_PointIds.push_back( GetPointId(i) );
00257       }
00258   }
00259 
00263   CellIdentifier m_Ident;
00264 
00268   QuadEdgeType *m_EdgeRingEntry;
00269 
00273   EdgeCellListType m_EdgeCellList;
00274 };
00275 } // end namespace itk
00276 
00277 #ifndef ITK_MANUAL_INSTANTIATION
00278 #include "itkQuadEdgeMeshPolygonCell.hxx"
00279 #endif
00280 
00281 #endif
00282