21 #ifndef otbRemoteSensingRegion_h
22 #define otbRemoteSensingRegion_h
27 #include "OTBImageBaseExport.h"
29 #include "itkImageRegion.h"
58 template <
class TType>
87 return Superclass::ITK_STRUCTURED_REGION;
103 m_Size[0] = region.GetSize()[0];
104 m_Size[1] = region.GetSize()[1];
105 m_Index[0] = region.GetIndex()[0];
106 m_Index[1] = region.GetIndex()[1];
117 typename ImageRegionType::IndexType irIndex;
118 typename ImageRegionType::SizeType irSize;
120 irIndex[0] =
static_cast<unsigned long>(std::floor(m_Index[0]));
121 irIndex[1] =
static_cast<unsigned long>(std::floor(m_Index[1]));
122 irSize[0] =
static_cast<unsigned long>(std::ceil(m_Size[0]));
123 irSize[1] =
static_cast<unsigned long>(std::ceil(m_Size[1]));
125 imageRegion.SetIndex(irIndex);
126 imageRegion.SetSize(irSize);
140 m_Index[0] = index[0];
141 m_Index[1] = index[1];
207 return m_ImageMetadata;
215 m_ImageMetadata = imd;
222 same = (m_Index == region.
m_Index);
223 same = same && (m_Size == region.
m_Size);
232 same = (m_Index == region.
m_Index);
233 same = same && (m_Size == region.
m_Size);
241 for (
unsigned int i = 0; i < IndexType::IndexDimension; ++i)
243 if ((index[i] < m_Index[i]) && (index[i] < m_Index[i] + m_Size[i]))
247 if ((index[i] >= m_Index[i]) && (index[i] >= m_Index[i] + m_Size[i]))
259 m_InputProjectionRef = projection;
264 return m_InputProjectionRef;
273 bool cropPossible =
true;
276 for (
unsigned int i = 0; i < IndexType::IndexDimension && cropPossible; ++i)
279 if (((region.
GetOrigin()[i] <= m_Index[i]) && (region.
GetOrigin()[i] <= m_Index[i] +
static_cast<Type>(m_Size[i])) &&
282 ((region.
GetOrigin()[i] >= m_Index[i]) && (region.
GetOrigin()[i] >= m_Index[i] +
static_cast<Type>(m_Size[i])) &&
291 for (
unsigned int i = 0; i < IndexType::IndexDimension; ++i)
297 crop = region.
GetOrigin()[i] - m_Index[i];
301 m_Size[i] -=
static_cast<Type>(crop);
310 m_Size[i] -=
static_cast<Type>(crop);
318 void PrintSelf(std::ostream& os, itk::Indent indent)
const override
320 os << std::setprecision(15);
321 os << indent <<
"RemoteSensingRegion" << std::endl;
322 os << indent <<
"Index:" << this->m_Index << std::endl;
323 os << indent <<
"Size:" << this->m_Size << std::endl;
324 os << indent <<
"Projection:" << this->m_InputProjectionRef << std::endl;
325 os << indent <<
"ImageMetadata: " << this->m_ImageMetadata << std::endl;
337 template <
class TType>
344 template <
class ImageType,
class RemoteSensingRegionType>
347 typename ImageType::RegionType outputRegion;
348 typename ImageType::RegionType::IndexType index;
349 typename ImageType::RegionType::IndexType index2;
351 typename ImageType::PointType point;
352 point[0] = region.GetIndex()[0];
353 point[1] = region.GetIndex()[1];
354 image->TransformPhysicalPointToIndex(point, index);
356 point[0] = region.GetIndex()[0] + region.GetSize()[0];
357 point[1] = region.GetIndex()[1] + region.GetSize()[1];
358 image->TransformPhysicalPointToIndex(point, index2);
360 typename ImageType::RegionType::SizeType size;
361 size[0] = std::abs(index2[0] - index[0]);
362 size[1] = std::abs(index2[1] - index[1]);
364 index[0] = std::min(index2[0], index[0]);
365 index[1] = std::min(index2[1], index[1]);
367 outputRegion.SetIndex(index);
368 outputRegion.SetSize(size);