21 #ifndef otbVectorDataIntoImageProjectionFilter_hxx
22 #define otbVectorDataIntoImageProjectionFilter_hxx
32 template <
class TInputVectorData,
class TInputImage>
35 m_OutputSpacing.Fill(1);
36 m_OutputOrigin.Fill(0);
37 m_UseOutputSpacingAndOriginFromImage =
false;
40 m_VdExtractFilter = VectorDataExtractROIType::New();
41 m_VdProjFilter = VectorDataProjectionFilterType::New();
43 m_VdProjFilter->SetInput(m_VdExtractFilter->GetOutput());
46 template <
class TInputVectorData,
class TInputImage>
49 m_UseOutputSpacingAndOriginFromImage = flag;
53 template <
class TInputVectorData,
class TOutputVectorData>
56 itkDebugMacro(
"setting Spacing to " << spacing);
57 if (this->m_OutputSpacing != spacing)
59 this->m_OutputSpacing = spacing;
65 template <
class TInputVectorData,
class TOutputVectorData>
69 this->SetOutputSpacing(s);
73 template <
class TInputVectorData,
class TOutputVectorData>
76 itk::Vector<float, 2> sf(spacing);
79 this->SetOutputSpacing(s);
83 template <
class TInputVectorData,
class TOutputVectorData>
87 this->SetOutputOrigin(p);
91 template <
class TInputVectorData,
class TOutputVectorData>
94 itk::Point<float, 2> of(origin);
97 this->SetOutputOrigin(p);
104 template <
class TInputVectorData,
class TInputImage>
107 m_VdExtractFilter->SetInput(this->GetInput());
109 typedef typename ImageType::PointType PointType;
110 typedef typename ImageType::SizeType SizeType;
112 if (m_InputImage.IsNull())
114 itkExceptionMacro(
"Invalid input image.");
124 PointType pul, pur, pll, plr;
125 itk::ContinuousIndex<double, 2> ul(m_InputImage->GetLargestPossibleRegion().GetIndex());
129 itk::ContinuousIndex<double, 2> ur(ul);
130 itk::ContinuousIndex<double, 2> ll(ul);
131 itk::ContinuousIndex<double, 2> lr(ul);
133 SizeType size = m_InputImage->GetLargestPossibleRegion().GetSize();
142 m_InputImage->TransformContinuousIndexToPhysicalPoint(ul, pul);
143 m_InputImage->TransformContinuousIndexToPhysicalPoint(ur, pur);
144 m_InputImage->TransformContinuousIndexToPhysicalPoint(ll, pll);
145 m_InputImage->TransformContinuousIndexToPhysicalPoint(lr, plr);
152 rsOrigin[0] = std::min(pul[0], plr[0]);
153 rsOrigin[1] = std::min(pul[1], plr[1]);
154 rsSize[0] = std::abs(pul[0] - plr[0]);
155 rsSize[1] = std::abs(pul[1] - plr[1]);
160 if (m_InputImage->GetProjectionRef().empty() || boost::algorithm::istarts_with(m_InputImage->GetProjectionRef(),
"LOCAL_CS"))
173 m_VdExtractFilter->SetRegion(rsRegion);
176 m_VdProjFilter->SetInputProjectionRef(this->GetInput()->GetProjectionRef());
178 if (m_InputImage->GetProjectionRef().empty() || boost::algorithm::istarts_with(m_InputImage->GetProjectionRef(),
"LOCAL_CS"))
180 m_VdProjFilter->SetOutputImageMetadata(&m_InputImage->GetImageMetadata());
184 m_VdProjFilter->SetOutputProjectionRef(m_InputImage->GetProjectionRef());
187 if (m_UseOutputSpacingAndOriginFromImage)
189 m_VdProjFilter->SetOutputOrigin(m_InputImage->GetOrigin());
190 m_VdProjFilter->SetOutputSpacing(m_InputImage->GetSignedSpacing());
194 m_VdProjFilter->SetOutputOrigin(this->GetOutputOrigin());
195 m_VdProjFilter->SetOutputSpacing(this->GetOutputSpacing());
198 m_VdProjFilter->Update();
219 if (m_UseOutputSpacingAndOriginFromImage)
221 m_VdProjFilter->GetOutput()->SetProjectionRef(
"");
224 this->GraftOutput(m_VdProjFilter->GetOutput());
225 this->UpdateProgress(1.0f);