Orfeo Toolbox  3.16
itkWarpMeshFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkWarpMeshFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-09-17 11:14:56 $
7  Version: $Revision: 1.3 $
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 __itkWarpMeshFilter_txx
18 #define __itkWarpMeshFilter_txx
19 
20 #include "itkWarpMeshFilter.h"
21 #include "itkExceptionObject.h"
22 
23 namespace itk
24 {
25 
29 template <class TInputMesh, class TOutputMesh, class TDeformationField>
32 {
33  // Setup the number of required inputs.
34  // This filter requires as input one Mesh and one Vector image.
35  this->SetNumberOfRequiredInputs( 2 );
36 }
37 
38 template <class TInputMesh, class TOutputMesh, class TDeformationField>
42 {
43  return static_cast<const DeformationFieldType *>
44  ( this->ProcessObject::GetInput( 1 ));
45 }
46 
47 template <class TInputMesh, class TOutputMesh, class TDeformationField>
48 void
51 {
52  // const cast is needed because the pipeline is not const-correct.
53  DeformationFieldType * input =
54  const_cast< DeformationFieldType * >( field );
55  this->ProcessObject::SetNthInput( 1, input );
56 }
57 
58 
62 template <class TInputMesh, class TOutputMesh, class TDeformationField>
63 void
65 ::PrintSelf(std::ostream& os, Indent indent) const
66 {
67  Superclass::PrintSelf(os,indent);
68 }
69 
70 
74 template <class TInputMesh, class TOutputMesh, class TDeformationField>
75 void
78 {
79 
80  typedef typename TInputMesh::PointsContainer InputPointsContainer;
81  typedef typename TOutputMesh::PointsContainer OutputPointsContainer;
82 
83  typedef typename TInputMesh::PointsContainerPointer InputPointsContainerPointer;
84  typedef typename TOutputMesh::PointsContainerPointer OutputPointsContainerPointer;
85 
86  const InputMeshType * inputMesh = this->GetInput();
87  OutputMeshPointer outputMesh = this->GetOutput();
88  DeformationFieldPointer fieldPtr = this->GetDeformationField();
89 
90  if( !inputMesh )
91  {
92  itkExceptionMacro(<<"Missing Input Mesh");
93  }
94 
95  if( !outputMesh )
96  {
97  itkExceptionMacro(<<"Missing Output Mesh");
98  }
99 
100  outputMesh->SetBufferedRegion( outputMesh->GetRequestedRegion() );
101 
102  const InputPointsContainer * inPoints = inputMesh->GetPoints();
103  OutputPointsContainerPointer outPoints = outputMesh->GetPoints();
104 
105  outPoints->Reserve( inputMesh->GetNumberOfPoints() );
106  outPoints->Squeeze(); // in case the previous mesh had
107  // allocated a larger memory
108 
109  typename InputPointsContainer::ConstIterator inputPoint = inPoints->Begin();
110  typename OutputPointsContainer::Iterator outputPoint = outPoints->Begin();
111 
112  typedef typename InputMeshType::PointType InputPointType;
113  typedef typename OutputMeshType::PointType OutputPointType;
114  typedef typename DeformationFieldType::IndexType IndexType;
115  IndexType index;
116 
117  OutputPointType displacedPoint;
118 
119  DisplacementType displacement;
120 
121  const unsigned int Dimension = fieldPtr->GetImageDimension();
122 
123  while( inputPoint != inPoints->End() )
124  {
125  const InputPointType & originalPoint = inputPoint.Value();
126  fieldPtr->TransformPhysicalPointToIndex( originalPoint, index );
127  displacement = fieldPtr->GetPixel( index );
128 
129  for(unsigned int i=0; i<Dimension; i++)
130  {
131  displacedPoint[i] = originalPoint[i] + displacement[i];
132  }
133 
134  outputPoint.Value() = displacedPoint;
135 
136  ++inputPoint;
137  ++outputPoint;
138  }
139 
140 
141  // Create duplicate references to the rest of data on the mesh
142 
143  this->CopyInputMeshToOutputMeshPointData();
144  this->CopyInputMeshToOutputMeshCells();
145  this->CopyInputMeshToOutputMeshCellLinks();
146  this->CopyInputMeshToOutputMeshCellData();
147 
148  unsigned int maxDimension = TInputMesh::MaxTopologicalDimension;
149 
150  for( unsigned int dim = 0; dim < maxDimension; dim++ )
151  {
152  outputMesh->SetBoundaryAssignments( dim,
153  inputMesh->GetBoundaryAssignments(dim) );
154  }
155 }
156 
157 } // end namespace itk
158 
159 #endif

Generated at Sun Feb 3 2013 00:14:30 for Orfeo Toolbox with doxygen 1.8.1.1