ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkDelaunayConformingQuadEdgeMeshFilter.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 __itkDelaunayConformingQuadEdgeMeshFilter_h
00019 #define __itkDelaunayConformingQuadEdgeMeshFilter_h
00020 
00021 #include "itkIntTypes.h"
00022 #include "itkPriorityQueueContainer.h"
00023 #include "itkQuadEdgeMeshToQuadEdgeMeshFilter.h"
00024 #include "itkQuadEdgeMeshEulerOperatorFlipEdgeFunction.h"
00025 #include "vcl_cmath.h"
00026 #include "vnl/vnl_math.h"
00027 
00028 namespace itk
00029 {
00037 template< class TInputMesh, class TOutputMesh=TInputMesh >
00038 class ITK_EXPORT DelaunayConformingQuadEdgeMeshFilter:
00039   public QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh, TOutputMesh >
00040 {
00041 public:
00042 
00044   typedef DelaunayConformingQuadEdgeMeshFilter Self;
00045   typedef QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh,
00046                                             TOutputMesh >                                           Superclass;
00047   typedef SmartPointer< Self >       Pointer;
00048   typedef SmartPointer< const Self > ConstPointer;
00049 
00051   typedef TInputMesh                              InputMeshType;
00052   typedef typename InputMeshType::Pointer         InputMeshPointer;
00053   typedef typename InputMeshType::CoordRepType    InputCoordRepType;
00054   typedef typename InputMeshType::PointType       InputPointType;
00055   typedef typename InputPointType::VectorType     InputPointVectorType;
00056   typedef typename InputMeshType::PointIdentifier InputPointIdentifier;
00057   typedef typename InputMeshType::QEType          InputQEType;
00058   typedef typename InputMeshType::VectorType      InputVectorType;
00059   typedef typename InputMeshType::EdgeListType    InputEdgeListType;
00060   typedef typename InputMeshType::PixelType       InputPixelType;
00061   typedef typename InputMeshType::Traits          InputTraits;
00062 
00063   itkStaticConstMacro(InputVDimension, unsigned int, InputMeshType::PointDimension);
00064 
00065   typedef typename InputMeshType::PointsContainer              InputPointsContainer;
00066   typedef typename InputMeshType::PointsContainerConstIterator InputPointsContainerConstIterator;
00067   typedef typename InputMeshType::CellsContainerConstIterator  InputCellsContainerConstIterator;
00068   typedef typename InputMeshType::EdgeCellType                 InputEdgeCellType;
00069   typedef typename InputMeshType::PolygonCellType              InputPolygonCellType;
00070   typedef typename InputMeshType::PointIdList                  InputPointIdList;
00071 
00072   typedef typename InputQEType::IteratorGeom InputQEIterator;
00073 
00075   typedef TOutputMesh                                      OutputMeshType;
00076   typedef typename OutputMeshType::Pointer                 OutputMeshPointer;
00077   typedef typename OutputMeshType::CoordRepType            OutputCoordRepType;
00078   typedef typename OutputMeshType::PointType               OutputPointType;
00079   typedef typename OutputMeshType::PointIdentifier         OutputPointIdentifier;
00080   typedef typename OutputMeshType::CellType                OutputCellType;
00081   typedef typename OutputMeshType::CellIdentifier          OutputCellIdentifier;
00082   typedef typename OutputMeshType::EdgeCellType            OutputEdgeCellType;
00083   typedef typename OutputMeshType::QEType                  OutputQEType;
00084   typedef typename OutputQEType::LineCellIdentifier        OutputLineCellIdentifier;
00085   typedef typename OutputMeshType::VectorType              OutputVectorType;
00086   typedef typename OutputQEType::IteratorGeom              OutputQEIterator;
00087   typedef typename OutputMeshType::PointsContainerPointer  OutputPointsContainerPointer;
00088   typedef typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator;
00089   typedef typename OutputMeshType::CellsContainer          OutputCellsContainer;
00090   typedef typename OutputMeshType::CellsContainerIterator  OutputCellsContainerIterator;
00091 
00092   itkStaticConstMacro(OutputVDimension, unsigned int, OutputMeshType::PointDimension);
00093 
00094   itkNewMacro(Self);
00095   itkTypeMacro(DelaunayConformingQuadEdgeMeshFilter, QuadEdgeMeshToQuadEdgeMeshFilter);
00096 
00097   itkGetConstMacro(NumberOfEdgeFlips, SizeValueType);
00098 public:
00099   typedef std::list< OutputEdgeCellType * >         OutputEdgeCellListType;
00100   typedef typename OutputEdgeCellListType::iterator OutputEdgeCellListIterator;
00101 
00102   typedef double                                CriterionValueType;
00103   typedef std::pair< bool, CriterionValueType > PriorityType;
00104 
00105   typedef MaxPriorityQueueElementWrapper<
00106     OutputEdgeCellType *, PriorityType, long >            PriorityQueueItemType;
00107 
00108   typedef PriorityQueueContainer< PriorityQueueItemType *,
00109                                   ElementWrapperPointerInterface< PriorityQueueItemType * >,
00110                                   PriorityType,
00111                                   long >   PriorityQueueType;
00112 
00113   typedef typename PriorityQueueType::Pointer                       PriorityQueuePointer;
00114   typedef std::map< OutputEdgeCellType *, PriorityQueueItemType * > QueueMapType;
00115   typedef typename QueueMapType::iterator                           QueueMapIterator;
00116 
00117   typedef QuadEdgeMeshEulerOperatorFlipEdgeFunction<
00118     OutputMeshType, OutputQEType >                                  FlipEdgeFunctionType;
00119   typedef typename FlipEdgeFunctionType::Pointer FlipEdgeFunctionPointer;
00120 
00121   void SetListOfConstrainedEdges(const OutputEdgeCellListType & iList)
00122   {
00123     m_ListOfConstrainedEdges = iList;
00124   }
00125 
00126 protected:
00127   DelaunayConformingQuadEdgeMeshFilter();
00128   virtual ~DelaunayConformingQuadEdgeMeshFilter();
00129   void PrintSelf(std::ostream & os, Indent indent) const;
00130 
00131   OutputEdgeCellListType m_ListOfConstrainedEdges;
00132   PriorityQueuePointer   m_PriorityQueue;
00133   QueueMapType           m_QueueMapper;
00134 
00135   SizeValueType           m_NumberOfEdgeFlips;
00136   FlipEdgeFunctionPointer m_FlipEdge;
00137 
00138   void GenerateData();
00139 
00140   void InitializePriorityQueue();
00141 
00142   void Process();
00143 
00144   inline CriterionValueType
00145   Dyer07Criterion(OutputMeshType *iMesh, OutputQEType *iEdge) const
00146   {
00147     OutputPointIdentifier id1 = iEdge->GetOrigin();
00148     OutputPointIdentifier id2 = iEdge->GetDestination();
00149 
00150     OutputPointIdentifier idA = iEdge->GetLnext()->GetDestination();
00151     OutputPointIdentifier idB = iEdge->GetRnext()->GetOrigin();
00152 
00153     OutputPointType pt1 = iMesh->GetPoint(id1);
00154     OutputPointType pt2 = iMesh->GetPoint(id2);
00155     OutputPointType ptA = iMesh->GetPoint(idA);
00156     OutputPointType ptB = iMesh->GetPoint(idB);
00157 
00158     OutputVectorType v1A = ptA - pt1;
00159     OutputVectorType v1B = ptB - pt1;
00160     OutputVectorType v2A = ptA - pt2;
00161     OutputVectorType v2B = ptB - pt2;
00162 
00163     OutputCoordRepType sq_norm1A = v1A * v1A;
00164     OutputCoordRepType sq_norm1B = v1B * v1B;
00165     OutputCoordRepType sq_norm2A = v2A * v2A;
00166     OutputCoordRepType sq_norm2B = v2B * v2B;
00167 
00168     CriterionValueType dotA = static_cast< CriterionValueType >( v1A * v2A );
00169     CriterionValueType dotB = static_cast< CriterionValueType >( v1B * v2B );
00170     CriterionValueType den  = static_cast< CriterionValueType >( sq_norm1A * sq_norm2A );
00171 
00172     if ( den != 0. )
00173       {
00174       dotA /= vcl_sqrt(den);
00175       }
00176 
00177     if ( dotA > 1. )
00178       {
00179       dotA = 1.;
00180       }
00181 
00182     if ( dotA < -1. )
00183       {
00184       dotA = -1.;
00185       }
00186 
00187     den = static_cast< CriterionValueType >( sq_norm1B * sq_norm2B );
00188 
00189     if ( den != 0. )
00190       {
00191       dotB /= vcl_sqrt(den);
00192       }
00193 
00194     if ( dotB > 1. )
00195       {
00196       dotB = 1.;
00197       }
00198 
00199     if ( dotB < -1. )
00200       {
00201       dotB = -1.;
00202       }
00203 
00204     return ( vcl_acos(dotA) + vcl_acos(dotB) - vnl_math::pi );
00205   }
00206 
00207 private:
00208 
00209   DelaunayConformingQuadEdgeMeshFilter(const Self &); // Purposely not
00210                                                       // implemented
00211   void operator=(const Self &);                       // Purposely not
00212                                                       // implemented
00213 };                                                    //
00214 } // end namespace itk
00215 
00216 #include "itkDelaunayConformingQuadEdgeMeshFilter.hxx"
00217 
00218 #endif
00219