ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkQuadricDecimationQuadEdgeMeshFilter.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 __itkQuadricDecimationQuadEdgeMeshFilter_h
00019 #define __itkQuadricDecimationQuadEdgeMeshFilter_h
00020 
00021 #include "itkEdgeDecimationQuadEdgeMeshFilter.h"
00022 #include "itkQuadEdgeMeshDecimationQuadricElementHelper.h"
00023 
00024 namespace itk
00025 {
00031 template< class TInput, class TOutput, class TCriterion >
00032 class ITK_EXPORT QuadricDecimationQuadEdgeMeshFilter:
00033   public EdgeDecimationQuadEdgeMeshFilter< TInput, TOutput, TCriterion >
00034 {
00035 public:
00036   typedef QuadricDecimationQuadEdgeMeshFilter Self;
00037   typedef SmartPointer< Self >                Pointer;
00038   typedef SmartPointer< const Self >          ConstPointer;
00039   typedef EdgeDecimationQuadEdgeMeshFilter<
00040     TInput, TOutput, TCriterion >             Superclass;
00041 
00043   itkTypeMacro(QuadricDecimationQuadEdgeMeshFilter, EdgeDecimationQuadEdgeMeshFilter);
00044 
00046   itkNewMacro(Self);
00047 
00048   typedef TInput                          InputMeshType;
00049   typedef typename InputMeshType::Pointer InputMeshPointer;
00050 
00051   typedef TOutput                                          OutputMeshType;
00052   typedef typename OutputMeshType::Pointer                 OutputMeshPointer;
00053   typedef typename OutputMeshType::PointIdentifier         OutputPointIdentifier;
00054   typedef typename OutputMeshType::PointType               OutputPointType;
00055   typedef typename OutputPointType::CoordRepType           OutputCoordType;
00056   typedef typename OutputMeshType::QEType                  OutputQEType;
00057   typedef typename OutputMeshType::EdgeCellType            OutputEdgeCellType;
00058   typedef typename OutputMeshType::CellsContainerIterator  OutputCellsContainerIterator;
00059   typedef typename OutputMeshType::PointsContainerPointer  OutputPointsContainerPointer;
00060   typedef typename OutputMeshType::PointsContainerIterator OutputPointsContainerIterator;
00061 
00062   itkStaticConstMacro(OutputPointDimension, unsigned int, OutputMeshType::PointDimension);
00063 
00064   typedef TCriterion                          CriterionType;
00065   typedef typename CriterionType::MeasureType MeasureType;
00066 
00067   typedef typename Superclass::PriorityType          PriorityType;
00068   typedef typename Superclass::PriorityQueueItemType PriorityQueueItemType;
00069   typedef typename Superclass::PriorityQueueType     PriorityQueueType;
00070   typedef typename Superclass::PriorityQueuePointer  PriorityQueuePointer;
00071 
00072   typedef typename Superclass::QueueMapType     QueueMapType;
00073   typedef typename Superclass::QueueMapIterator QueueMapIterator;
00074 
00075   typedef typename Superclass::OperatorType    OperatorType;
00076   typedef typename Superclass::OperatorPointer OperatorPointer;
00077 
00078   typedef QuadEdgeMeshDecimationQuadricElementHelper< OutputPointType >
00079   QuadricElementType;
00080 
00081   typedef std::map< OutputPointIdentifier, QuadricElementType >
00082   QuadricElementMapType;
00083 
00084   typedef typename QuadricElementMapType::iterator QuadricElementMapIterator;
00085 
00086 protected:
00088   QuadricDecimationQuadEdgeMeshFilter();
00089 
00091   virtual ~QuadricDecimationQuadEdgeMeshFilter();
00092 
00097   inline void QuadricAtOrigin(OutputQEType *iEdge, QuadricElementType & oQ)
00098   {
00099     OutputMeshPointer output = this->GetOutput();
00100 
00101     OutputPointIdentifier id[3];
00102 
00103     id[0] = iEdge->GetOrigin();
00104     id[1] = iEdge->GetDestination();
00105     id[2] = iEdge->GetOnext()->GetDestination();
00106 
00107     OutputPointType p[3];
00108 
00109     for ( int i = 0; i < 3; i++ )
00110       {
00111       p[i] = output->GetPoint(id[i]);
00112       }
00113 
00114     oQ.AddTriangle(p[0], p[1], p[2]);
00115   }
00116 
00121   inline MeasureType MeasureEdge(OutputQEType *iEdge)
00122   {
00123     OutputPointIdentifier id_org = iEdge->GetOrigin();
00124     OutputPointIdentifier id_dest = iEdge->GetDestination();
00125     QuadricElementType    Q = m_Quadric[id_org] + m_Quadric[id_dest];
00126 
00127     OutputMeshPointer output = this->GetOutput();
00128 
00129     OutputPointType org = output->GetPoint(id_org);
00130     OutputPointType dest = output->GetPoint(id_dest);
00131 
00132     OutputPointType mid;
00133 
00134     mid.SetToMidPoint(org, dest);
00135     OutputPointType p = Q.ComputeOptimalLocation(mid);
00136 
00137     return static_cast< MeasureType >( Q.ComputeError(p) );
00138   }
00139 
00144   virtual void DeletePoint(const OutputPointIdentifier & iIdToBeDeleted,
00145                            const OutputPointIdentifier & iRemaining);
00146 
00151   OutputPointType Relocate(OutputQEType *iEdge);
00152 
00154   virtual void Initialize();
00155 
00156 private:
00157   QuadricDecimationQuadEdgeMeshFilter(const Self &); // purposely not implemented
00158   void operator=(const Self &); // purposely not implemented
00159 
00160   QuadricElementMapType m_Quadric;
00161 };
00162 }
00163 #ifndef ITK_MANUAL_INSTANTIATION
00164 #include "itkQuadricDecimationQuadEdgeMeshFilter.hxx"
00165 #endif
00166 #endif
00167