21 #ifndef otbImageToGenericRSOutputParameters_hxx 22 #define otbImageToGenericRSOutputParameters_hxx 27 #include "itkContinuousIndex.h" 32 template <
class TImage>
35 m_Transform = GenericRSTransformType::New();
36 m_ForceSpacing =
false;
38 m_EstimateIsotropicSpacing =
false;
44 template <
class TImage>
49 itkExceptionMacro(<<
"The input is null , please set a non null input image");
51 if (m_Input->GetProjectionRef().empty() && m_Input->GetImageKeywordlist().GetSize() == 0)
52 itkExceptionMacro(<<
"No information in the metadata, please set an image with non empty metadata");
56 this->UpdateTransform();
59 this->EstimateOutputImageExtent();
63 this->EstimateOutputSpacing();
66 this->EstimateOutputSize();
69 this->EstimateOutputOrigin();
73 template <
class TImage>
76 m_Transform->SetOutputDictionary(this->GetInput()->GetMetaDataDictionary());
77 m_Transform->SetOutputProjectionRef(this->GetInput()->GetProjectionRef());
78 m_Transform->SetOutputKeywordList(this->GetInput()->GetImageKeywordlist());
79 m_Transform->InstantiateTransform();
87 template <
class TImage>
92 m_Transform->GetInverse(invTransform);
96 std::vector<itk::ContinuousIndex<double, 2>> vindex;
97 std::vector<PointType> voutput;
99 itk::ContinuousIndex<double, 2> index1(m_Input->GetLargestPossibleRegion().GetIndex());
102 itk::ContinuousIndex<double, 2> index2(index1);
103 itk::ContinuousIndex<double, 2> index3(index1);
104 itk::ContinuousIndex<double, 2> index4(index1);
107 SizeType size = m_Input->GetLargestPossibleRegion().GetSize();
110 index2[0] += size[0];
111 index3[0] += size[0];
112 index3[1] += size[1];
113 index4[1] += size[1];
115 vindex.push_back(index1);
116 vindex.push_back(index2);
117 vindex.push_back(index3);
118 vindex.push_back(index4);
120 for (
unsigned int i = 0; i < vindex.size(); ++i)
123 m_Input->TransformContinuousIndexToPhysicalPoint(vindex[i], physicalPoint);
124 voutput.push_back(invTransform->TransformPoint(physicalPoint));
128 double minX = voutput[0][0];
129 double maxX = voutput[0][0];
130 double minY = voutput[0][1];
131 double maxY = voutput[0][1];
133 for (
unsigned int i = 0; i < voutput.size(); ++i)
136 if (minX > voutput[i][0])
137 minX = voutput[i][0];
138 if (minY > voutput[i][1])
139 minY = voutput[i][1];
142 if (maxX < voutput[i][0])
143 maxX = voutput[i][0];
145 if (maxY < voutput[i][1])
146 maxY = voutput[i][1];
150 m_OutputExtent.maxX = maxX;
151 m_OutputExtent.minX = minX;
152 m_OutputExtent.maxY = maxY;
153 m_OutputExtent.minY = minY;
161 template <
class TImage>
167 origin[0] = m_OutputExtent.minX + 0.5 * this->GetOutputSpacing()[0];
168 origin[1] = m_OutputExtent.maxY + 0.5 * this->GetOutputSpacing()[1];
169 this->SetOutputOrigin(origin);
177 template <
class TImage>
181 double sizeCartoX = std::abs(m_OutputExtent.maxX - m_OutputExtent.minX);
182 double sizeCartoY = std::abs(m_OutputExtent.minY - m_OutputExtent.maxY);
186 o[0] = m_OutputExtent.minX;
187 o[1] = m_OutputExtent.maxY;
196 PointType io = m_Transform->TransformPoint(o);
197 PointType ioX = m_Transform->TransformPoint(oX);
198 PointType ioY = m_Transform->TransformPoint(oY);
202 m_Input->TransformPhysicalPointToIndex(io, ioIndex);
203 m_Input->TransformPhysicalPointToIndex(ioX, ioXIndex);
204 m_Input->TransformPhysicalPointToIndex(ioY, ioYIndex);
207 double OxLength, OyLength;
209 OxLength = std::sqrt(std::pow((
double)ioIndex[0] - (
double)ioXIndex[0], 2) + std::pow((
double)ioIndex[1] - (
double)ioXIndex[1], 2));
211 OyLength = std::sqrt(std::pow((
double)ioIndex[0] - (
double)ioYIndex[0], 2) + std::pow((
double)ioIndex[1] - (
double)ioYIndex[1], 2));
217 if (m_EstimateIsotropicSpacing)
219 double isotropicSpacing = std::min(sizeCartoX / OxLength, sizeCartoY / OyLength);
220 outputSpacing[0] = isotropicSpacing;
221 outputSpacing[1] = -isotropicSpacing;
225 outputSpacing[0] = sizeCartoX / OxLength;
226 outputSpacing[1] = -sizeCartoY / OyLength;
229 this->SetOutputSpacing(outputSpacing);
236 template <
class TImage>
240 double sizeCartoX = std::abs(m_OutputExtent.maxX - m_OutputExtent.minX);
241 double sizeCartoY = std::abs(m_OutputExtent.minY - m_OutputExtent.maxY);
246 outputSize[0] =
static_cast<unsigned int>(std::floor(std::abs(sizeCartoX / this->GetOutputSpacing()[0])));
247 outputSize[1] =
static_cast<unsigned int>(std::floor(std::abs(sizeCartoY / this->GetOutputSpacing()[1])));
253 this->SetOutputSize(outputSize);
258 outputSpacing[0] = this->GetOutputSpacing()[0] * outputSize[0] / this->GetOutputSize()[0];
259 outputSpacing[1] = this->GetOutputSpacing()[1] * outputSize[1] / this->GetOutputSize()[1];
260 this->SetOutputSpacing(outputSpacing);
262 this->UpdateTransform();
GenericRSTransformType::Pointer GenericRSTransformPointerType
ImageType::PointType PointType
ImageType::SpacingType SpacingType
void EstimateOutputSpacing()
void EstimateOutputImageExtent()
void EstimateOutputSize()
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
void EstimateOutputOrigin()
ImageToGenericRSOutputParameters()
ImageType::IndexType IndexType
ImageType::SizeType SizeType