ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkQuadEdgeMeshToQuadEdgeMeshFilter.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 __itkQuadEdgeMeshToQuadEdgeMeshFilter_h
00019 #define __itkQuadEdgeMeshToQuadEdgeMeshFilter_h
00020 
00021 #include "itkMeshToMeshFilter.h"
00022 
00023 namespace itk
00024 {
00035 template< typename TInputMesh, typename TOutputMesh >
00036 class ITK_EXPORT QuadEdgeMeshToQuadEdgeMeshFilter:
00037   public MeshToMeshFilter< TInputMesh, TOutputMesh >
00038 {
00039 public:
00041   typedef QuadEdgeMeshToQuadEdgeMeshFilter            Self;
00042   typedef MeshToMeshFilter< TInputMesh, TOutputMesh > Superclass;
00043   typedef SmartPointer< Self >                        Pointer;
00044   typedef SmartPointer< const Self >                  ConstPointer;
00045 
00047   typedef TInputMesh                              InputMeshType;
00048   typedef typename InputMeshType::Pointer         InputMeshPointer;
00049   typedef typename InputMeshType::ConstPointer    InputMeshConstPointer;
00050   typedef typename InputMeshType::CoordRepType    InputCoordRepType;
00051   typedef typename InputMeshType::PointType       InputPointType;
00052   typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
00053   typedef typename InputMeshType::QEPrimal        InputQEPrimal;
00054   typedef typename InputMeshType::VectorType      InputVectorType;
00055 
00056   typedef typename InputMeshType::PointDataContainer InputPointDataContainer;
00057   typedef typename InputMeshType::CellDataContainer  InputCellDataContainer;
00058 
00059   typedef typename InputPointDataContainer::ConstPointer
00060   InputPointDataContainerConstPointer;
00061   typedef typename InputMeshType::PointsContainerConstIterator
00062   InputPointsContainerConstIterator;
00063   typedef typename InputMeshType::PointsContainerConstPointer
00064   InputPointsContainerConstPointer;
00065   typedef typename InputMeshType::CellsContainerConstIterator
00066   InputCellsContainerConstIterator;
00067   typedef typename InputMeshType::CellsContainerConstPointer
00068   InputCellsContainerConstPointer;
00069 
00070   typedef typename InputMeshType::EdgeCellType    InputEdgeCellType;
00071   typedef typename InputMeshType::PolygonCellType InputPolygonCellType;
00072   typedef typename InputMeshType::PointIdList     InputPointIdList;
00073   typedef typename InputMeshType::CellTraits      InputCellTraits;
00074   typedef typename InputCellTraits::PointIdInternalIterator
00075   InputPointsIdInternalIterator;
00076 
00077   typedef typename InputQEPrimal::IteratorGeom InputQEIterator;
00078 
00080   typedef TOutputMesh                              OutputMeshType;
00081   typedef typename OutputMeshType::Pointer         OutputMeshPointer;
00082   typedef typename OutputMeshType::ConstPointer    OutputMeshConstPointer;
00083   typedef typename OutputMeshType::CoordRepType    OutputCoordRepType;
00084   typedef typename OutputMeshType::PointType       OutputPointType;
00085   typedef typename OutputMeshType::PointIdentifier OutputPointIdentifier;
00086   typedef typename OutputMeshType::QEPrimal        OutputQEPrimal;
00087   typedef typename OutputMeshType::VectorType      OutputVectorType;
00088   typedef typename OutputQEPrimal::IteratorGeom    OutputQEIterator;
00089   typedef typename OutputMeshType::PointsContainerIterator
00090   OutputPointsContainerIterator;
00091   typedef typename OutputMeshType::PointsContainerPointer
00092   OutputPointsContainerPointer;
00093   typedef typename OutputMeshType::PointsContainerConstPointer
00094   OutputPointsContainerConstPointer;
00095 
00096   typedef typename OutputMeshType::PointDataContainer OutputPointDataContainer;
00097   typedef typename OutputMeshType::CellDataContainer  OutputCellDataContainer;
00098 public:
00099   itkNewMacro(Self);
00100   itkTypeMacro(QuadEdgeMeshToQuadEdgeMeshFilter, MeshToMeshFilter);
00101 protected:
00102   QuadEdgeMeshToQuadEdgeMeshFilter();
00103   virtual ~QuadEdgeMeshToQuadEdgeMeshFilter() {}
00104 
00105   virtual void CopyMeshToMesh(const TInputMesh *in, TOutputMesh *out);
00106 
00107   virtual void CopyInputMeshToOutputMesh();
00108 
00109   virtual void CopyInputMeshToOutputMeshGeometry();
00110 
00111   virtual void CopyInputMeshToOutputMeshPoints();
00112 
00113   virtual void CopyInputMeshToOutputMeshCells();
00114 
00115   virtual void CopyInputMeshToOutputMeshEdgeCells();
00116 
00117   virtual void CopyInputMeshToOutputMeshFieldData();
00118 
00119   virtual void CopyInputMeshToOutputMeshPointData();
00120 
00121   virtual void CopyInputMeshToOutputMeshCellData();
00122 
00123 private:
00124   QuadEdgeMeshToQuadEdgeMeshFilter(const Self &); // Not impl.
00125   void operator=(const Self &);                   // Not impl.
00126 };
00127 
00128 //
00129 // Helper functions that copy selected pieces of a Mesh.
00130 // These functions should be templated here in order to
00131 // facilitate their reuse in multiple scenarios.
00132 //
00133 
00134 // ---------------------------------------------------------------------
00135 template< class TInputMesh, class TOutputMesh >
00136 void CopyMeshToMeshCellData(const TInputMesh *in, TOutputMesh *out)
00137 {
00138   typedef typename TInputMesh::CellDataContainer        InputCellDataContainer;
00139   typedef typename TOutputMesh::CellDataContainer       OutputCellDataContainer;
00140   typedef typename InputCellDataContainer::ConstPointer InputCellDataContainerConstPointer;
00141   typedef typename OutputCellDataContainer::Pointer     OutputCellDataContainerPointer;
00142 
00143   InputCellDataContainerConstPointer inputCellData = in->GetCellData();
00144 
00145   if ( inputCellData.IsNull() )
00146     {
00147     // There is nothing to copy
00148     return;
00149     }
00150 
00151   OutputCellDataContainerPointer outputCellData = OutputCellDataContainer::New();
00152   outputCellData->Reserve( inputCellData->Size() );
00153 
00154   // Copy point data
00155   typedef typename InputCellDataContainer::ConstIterator InputCellDataContainerConstIterator;
00156   InputCellDataContainerConstIterator inIt = inputCellData->Begin();
00157   while ( inIt != inputCellData->End() )
00158     {
00159     outputCellData->SetElement( inIt.Index(), inIt.Value() );
00160     inIt++;
00161     }
00162 
00163   out->SetCellData(outputCellData);
00164 }
00165 
00166 // ---------------------------------------------------------------------
00167 template< class TInputMesh, class TOutputMesh >
00168 void CopyMeshToMeshPointData(const TInputMesh *in, TOutputMesh *out)
00169 {
00170   typedef typename TOutputMesh::PointDataContainer   OutputPointDataContainer;
00171   typedef typename OutputPointDataContainer::Pointer OutputPointDataContainerPointer;
00172   typedef typename TInputMesh::PointDataContainer    InputPointDataContainer;
00173 
00174   const InputPointDataContainer *inputPointData = in->GetPointData();
00175 
00176   if ( inputPointData == NULL )
00177     {
00178     // There is nothing to copy
00179     return;
00180     }
00181 
00182   OutputPointDataContainerPointer outputPointData = OutputPointDataContainer::New();
00183   outputPointData->Reserve( inputPointData->Size() );
00184 
00185   // Copy point data
00186   typedef typename InputPointDataContainer::ConstIterator InputPointDataContainerConstIterator;
00187   InputPointDataContainerConstIterator inIt = inputPointData->Begin();
00188   while ( inIt != inputPointData->End() )
00189     {
00190     outputPointData->SetElement( inIt.Index(), inIt.Value() );
00191     inIt++;
00192     }
00193 
00194   out->SetPointData(outputPointData);
00195 }
00196 
00197 // ---------------------------------------------------------------------
00198 template< class TInputMesh, class TOutputMesh >
00199 void CopyMeshToMeshCells(const TInputMesh *in, TOutputMesh *out)
00200 {
00201   // Copy cells
00202   typedef typename TInputMesh::CellsContainer         InputCellsContainer;
00203   typedef typename InputCellsContainer::ConstPointer  InputCellsContainerConstPointer;
00204   typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
00205   typedef typename TInputMesh::PolygonCellType        InputPolygonCellType;
00206   typedef typename TInputMesh::PointIdList            InputPointIdList;
00207   typedef typename TInputMesh::CellTraits             InputCellTraits;
00208   typedef typename InputCellTraits::PointIdInternalIterator
00209   InputPointsIdInternalIterator;
00210 
00211   out->SetCellsAllocationMethod(TOutputMesh::CellsAllocatedDynamicallyCellByCell);
00212 
00213   InputCellsContainerConstPointer inCells = in->GetCells();
00214 
00215   if ( inCells )
00216     {
00217     InputCellsContainerConstIterator cIt = inCells->Begin();
00218     while ( cIt != inCells->End() )
00219       {
00220       InputPolygonCellType *pe = dynamic_cast< InputPolygonCellType * >( cIt.Value() );
00221       if ( pe )
00222         {
00223         InputPointIdList              points;
00224         InputPointsIdInternalIterator pit = pe->InternalPointIdsBegin();
00225         while ( pit != pe->InternalPointIdsEnd() )
00226           {
00227           points.push_back( ( *pit ) );
00228           ++pit;
00229           }
00230         out->AddFaceWithSecurePointList(points, false);
00231         }
00232       cIt++;
00233       }
00234     }
00235 }
00236 
00237 // ---------------------------------------------------------------------
00238 template< class TInputMesh, class TOutputMesh >
00239 void CopyMeshToMeshEdgeCells(const TInputMesh *in, TOutputMesh *out)
00240 {
00241   // Copy Edge Cells
00242   typedef typename TInputMesh::CellsContainer         InputCellsContainer;
00243   typedef typename InputCellsContainer::ConstPointer  InputCellsContainerConstPointer;
00244   typedef typename InputCellsContainer::ConstIterator InputCellsContainerConstIterator;
00245   typedef typename TInputMesh::EdgeCellType           InputEdgeCellType;
00246 
00247   InputCellsContainerConstPointer inEdgeCells = in->GetEdgeCells();
00248 
00249   if ( inEdgeCells )
00250     {
00251     InputCellsContainerConstIterator ecIt = inEdgeCells->Begin();
00252     while ( ecIt != inEdgeCells->End() )
00253       {
00254       InputEdgeCellType *pe = dynamic_cast< InputEdgeCellType * >( ecIt.Value() );
00255       if ( pe )
00256         {
00257         out->AddEdgeWithSecurePointList( pe->GetQEGeom()->GetOrigin(),
00258                                          pe->GetQEGeom()->GetDestination() );
00259         }
00260       ecIt++;
00261       }
00262     }
00263 }
00264 
00265 // ---------------------------------------------------------------------
00266 template< class TInputMesh, class TOutputMesh >
00267 void CopyMeshToMeshPoints(const TInputMesh *in, TOutputMesh *out)
00268 {
00269   // Copy points
00270   typedef typename TInputMesh::PointsContainer         InputPointsContainer;
00271   typedef typename InputPointsContainer::ConstPointer  InputPointsContainerConstPointer;
00272   typedef typename InputPointsContainer::ConstIterator InputPointsContainerConstIterator;
00273   typedef typename TOutputMesh::PointType              OutputPointType;
00274 
00275   InputPointsContainerConstPointer inPoints = in->GetPoints();
00276 
00277   if ( inPoints )
00278     {
00279     InputPointsContainerConstIterator inIt = inPoints->Begin();
00280     OutputPointType                   pOut;
00281 
00282     while ( inIt != inPoints->End() )
00283       {
00284       pOut.CastFrom( inIt.Value() );
00285       out->SetPoint(inIt.Index(), pOut);
00286       inIt++;
00287       }
00288     }
00289 }
00290 } // end namespace itk
00291 
00292 #ifndef ITK_MANUAL_INSTANTIATION
00293 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.hxx"
00294 #endif
00295 
00296 #endif
00297