Skip to content
Snippets Groups Projects
Commit 4134a18d authored by Luc Hermitte's avatar Luc Hermitte
Browse files

REFACT: Modernize SARStreamingDEMInformationFilter

and make it compatible with OTB7 and OTB 8
parent 3d892f9c
No related branches found
No related tags found
1 merge request!4Resolve "Migrate code to OTB 8.x"
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
...@@ -28,12 +28,17 @@ ...@@ -28,12 +28,17 @@
#include "itkPoint.h" #include "itkPoint.h"
#include "otbPersistentFilterStreamingDecorator.h" #include "otbPersistentFilterStreamingDecorator.h"
#include "otbStringUtilities.h"
#include "otbSarSensorModel.h"
#include "otbImageMetadata.h" #if OTB_VERSION_MAJOR >= 8
# include "otbSarSensorModel.h"
# include "otbImageMetadata.h"
#else
# include "otbSarSensorModelAdapter.h"
# include "otbImageKeywordlist.h"
#endif
#include "otbGeocentricTransform.h" #include "otbGeocentricTransform.h"
#include <complex>
#include <cmath> #include <cmath>
namespace otb namespace otb
...@@ -57,10 +62,10 @@ public PersistentImageFilter<TInputImage, TInputImage> ...@@ -57,10 +62,10 @@ public PersistentImageFilter<TInputImage, TInputImage>
{ {
public: public:
/** Standard Self typedef */ /** Standard Self typedef */
typedef PersistentDEMInformationFilter Self; using Self = PersistentDEMInformationFilter;
typedef PersistentImageFilter<TInputImage, TInputImage> Superclass; using Superclass = PersistentImageFilter<TInputImage, TInputImage>;
typedef itk::SmartPointer<Self> Pointer; using Pointer = itk::SmartPointer<Self>;
typedef itk::SmartPointer<const Self> ConstPointer; using ConstPointer = itk::SmartPointer<const Self>;
/** Method for creation through the object factory. */ /** Method for creation through the object factory. */
itkNewMacro(Self); itkNewMacro(Self);
...@@ -69,15 +74,15 @@ public: ...@@ -69,15 +74,15 @@ public:
itkTypeMacro(PersistentDEMInformationFilter, PersistentImageFilter); itkTypeMacro(PersistentDEMInformationFilter, PersistentImageFilter);
/** Image related typedefs. */ /** Image related typedefs. */
typedef TInputImage ImageType; using ImageType = TInputImage;
typedef typename TInputImage::Pointer InputImagePointer; using InputImagePointer = typename TInputImage::Pointer;
typedef typename TInputImage::RegionType RegionType; using RegionType = typename TInputImage::RegionType;
typedef typename TInputImage::SizeType SizeType; using SizeType = typename TInputImage::SizeType;
typedef typename TInputImage::IndexType IndexType; using IndexType = typename TInputImage::IndexType;
typedef typename TInputImage::PixelType PixelType; using PixelType = typename TInputImage::PixelType;
typedef typename ImageType::IndexValueType IndexValueType; using IndexValueType = typename ImageType::IndexValueType;
typedef typename ImageType::SizeValueType SizeValueType; using SizeValueType = typename ImageType::SizeValueType;
itkStaticConstMacro(InputImageDimension, unsigned int, itkStaticConstMacro(InputImageDimension, unsigned int,
TInputImage::ImageDimension); TInputImage::ImageDimension);
...@@ -88,16 +93,16 @@ public: ...@@ -88,16 +93,16 @@ public:
/** Type to use for computations. */ /** Type to use for computations. */
// typedef typename itk::NumericTraits<PixelType>::RealType RealType; // typedef typename itk::NumericTraits<PixelType>::RealType RealType;
typedef typename itk::NumericTraits<double>::RealType RealType; using RealType = typename itk::NumericTraits<double>::RealType;
/** Smart Pointer type to a DataObject. */ /** Smart Pointer type to a DataObject. */
typedef typename itk::DataObject::Pointer DataObjectPointer; using DataObjectPointer = typename itk::DataObject::Pointer;
typedef itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType; using DataObjectPointerArraySizeType = itk::ProcessObject::DataObjectPointerArraySizeType;
/** Type of DataObjects used for scalar outputs */ /** Type of DataObjects used for scalar outputs */
typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType; using RealObjectType = itk::SimpleDataObjectDecorator<RealType>;
typedef itk::SimpleDataObjectDecorator<long> LongObjectType; using LongObjectType = itk::SimpleDataObjectDecorator<long>;
typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType; using PixelObjectType = itk::SimpleDataObjectDecorator<PixelType>;
/** Return the four sides of DEM to estiamte the gain. */ /** Return the four sides of DEM to estiamte the gain. */
PixelType GetSide_0_0() const PixelType GetSide_0_0() const
...@@ -144,7 +149,7 @@ public: ...@@ -144,7 +149,7 @@ public:
protected: protected:
PersistentDEMInformationFilter(); PersistentDEMInformationFilter();
~PersistentDEMInformationFilter() override {} ~PersistentDEMInformationFilter() override = default;
void PrintSelf(std::ostream& os, itk::Indent indent) const override; void PrintSelf(std::ostream& os, itk::Indent indent) const override;
...@@ -218,11 +223,10 @@ public PersistentFilterStreamingDecorator<PersistentDEMInformationFilter<TInputI ...@@ -218,11 +223,10 @@ public PersistentFilterStreamingDecorator<PersistentDEMInformationFilter<TInputI
{ {
public: public:
/** Standard Self typedef */ /** Standard Self typedef */
typedef SARStreamingDEMInformationFilter Self; using Self = SARStreamingDEMInformationFilter;
typedef PersistentFilterStreamingDecorator using Superclass = PersistentFilterStreamingDecorator <PersistentDEMInformationFilter<TInputImage> >;
<PersistentDEMInformationFilter<TInputImage> > Superclass; using Pointer = itk::SmartPointer<Self>;
typedef itk::SmartPointer<Self> Pointer; using ConstPointer = itk::SmartPointer<const Self>;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */ /** Type macro */
itkNewMacro(Self); itkNewMacro(Self);
...@@ -230,27 +234,32 @@ public: ...@@ -230,27 +234,32 @@ public:
/** Creation through object factory macro */ /** Creation through object factory macro */
itkTypeMacro(StreamingDEMInformationFilter, PersistentFilterStreamingDecorator); itkTypeMacro(StreamingDEMInformationFilter, PersistentFilterStreamingDecorator);
typedef typename Superclass::FilterType StatFilterType; using StatFilterType = typename Superclass::FilterType;
typedef typename StatFilterType::PixelType PixelType; using PixelType = typename StatFilterType::PixelType;
typedef typename StatFilterType::RealType RealType; using RealType = typename StatFilterType::RealType;
typedef TInputImage InputImageType; using InputImageType = TInputImage;
/** Type of DataObjects used for scalar outputs */ /** Type of DataObjects used for scalar outputs */
typedef itk::SimpleDataObjectDecorator<RealType> RealObjectType; using RealObjectType = itk::SimpleDataObjectDecorator<RealType>;
typedef itk::SimpleDataObjectDecorator<long> LongObjectType; using LongObjectType = itk::SimpleDataObjectDecorator<long>;
typedef itk::SimpleDataObjectDecorator<PixelType> PixelObjectType; using PixelObjectType = itk::SimpleDataObjectDecorator<PixelType>;
/** Image related typedefs. */ /** Image related typedefs. */
typedef TInputImage ImageType; using ImageType = TInputImage;
typedef typename TInputImage::Pointer InputImagePointer; using InputImagePointer = typename TInputImage::Pointer;
typedef typename TInputImage::RegionType RegionType; using RegionType = typename TInputImage::RegionType;
typedef typename TInputImage::SizeType SizeType; using SizeType = typename TInputImage::SizeType;
typedef typename TInputImage::IndexType IndexType; using IndexType = typename TInputImage::IndexType;
// Define Point2DType and Point3DType // Define Point2DType and Point3DType
#if OTB_VERSION_MAJOR >= 8
using Point2DType = SarSensorModel::Point2DType; using Point2DType = SarSensorModel::Point2DType;
using Point3DType = SarSensorModel::Point3DType; using Point3DType = SarSensorModel::Point3DType;
#else
using Point2DType = SarSensorModelAdapter::Point2DType;
using Point3DType = SarSensorModelAdapter::Point3DType;
#endif
using Superclass::SetInput; using Superclass::SetInput;
void SetInput(InputImageType * input) void SetInput(InputImageType * input)
...@@ -262,7 +271,6 @@ public: ...@@ -262,7 +271,6 @@ public:
return this->GetFilter()->GetInput(); return this->GetFilter()->GetInput();
} }
/** Return the side. */ /** Return the side. */
PixelType GetSide_0_0() const PixelType GetSide_0_0() const
{ {
...@@ -323,17 +331,35 @@ public: ...@@ -323,17 +331,35 @@ public:
double incidence[4]; double incidence[4];
// Retrive the DEM dimensions for the side // Retrive the DEM dimensions for the side
int nbColDEM = this->GetInput()->GetLargestPossibleRegion().GetSize()[0]; auto const size = this->GetInput()->GetLargestPossibleRegion().GetSize();
int nbLinesDEM = this->GetInput()->GetLargestPossibleRegion().GetSize()[1]; auto const nbColDEM = size[0];
auto const nbLinesDEM = size[1];
int nbColSAR = m_SarImageMetadata[MDNum::NumberOfColumns];
#if OTB_VERSION_MAJOR >= 8
int const nbColSAR = m_SarImageMetadata[MDNum::NumberOfColumns];
#else
int const nbColSAR = to<int>(
m_SarImageKwl.GetMetadataByKey("support_data.number_samples"),
"converting metadata 'support_data.number_samples'");
#endif
// Create and Initilaze the SarSensorModel // Create and Initilaze the SarSensorModel
#if OTB_VERSION_MAJOR >= 8
SarSensorModel sarSensorModel(m_SarImageMetadata); SarSensorModel sarSensorModel(m_SarImageMetadata);
#else
SarSensorModelAdapter::Pointer sarSensorModelAdapter = SarSensorModelAdapter::New();
bool const loadOk = sarSensorModelAdapter->LoadState(m_SarImageKwl);
if(!loadOk || !sarSensorModelAdapter->IsValidSensorModel())
{
itkExceptionMacro(<<"SAR image does not contain a valid SAR sensor model.");
}
SarSensorModelAdapter & sarSensorModel = * sarSensorModelAdapter;
#endif
// 4 sides of DEM // 4 sides of DEM
int ind_lines[4] = {0, nbLinesDEM-1, 0, nbLinesDEM-1}; unsigned long int const ind_lines[4] = {0, nbLinesDEM-1, 0, nbLinesDEM-1};
int ind_col[4] = {0, 0, nbColDEM-1, nbColDEM-1}; unsigned long int const ind_col[4] = {0, 0, nbColDEM-1, nbColDEM-1};
PixelType pixel_side[4]; PixelType pixel_side[4];
...@@ -343,7 +369,6 @@ public: ...@@ -343,7 +369,6 @@ public:
pixel_side[2] = this->GetFilter()->GetSide_nbCol_0_Output()->Get(); pixel_side[2] = this->GetFilter()->GetSide_nbCol_0_Output()->Get();
pixel_side[3] = this->GetFilter()->GetSide_nbCol_nbLines_Output()->Get(); pixel_side[3] = this->GetFilter()->GetSide_nbCol_nbLines_Output()->Get();
Point2DType mntLatLonPoint(0); Point2DType mntLatLonPoint(0);
Point3DType mntGeoPoint(0); Point3DType mntGeoPoint(0);
Point3DType MntPointCartesien(0); Point3DType MntPointCartesien(0);
...@@ -353,10 +378,6 @@ public: ...@@ -353,10 +378,6 @@ public:
Point2DType col_row(0); Point2DType col_row(0);
Point2DType y_z(0); Point2DType y_z(0);
double incidence_moy = 0.;
double coef1 = 0.;
double coef2 = 0.;
IndexType idCurrent; IndexType idCurrent;
std::map<std::string,int> DEMSidesOrder_Into_SARGeometry; std::map<std::string,int> DEMSidesOrder_Into_SARGeometry;
...@@ -401,7 +422,7 @@ public: ...@@ -401,7 +422,7 @@ public:
firstLine = col_row[1]; firstLine = col_row[1];
DEMSidesOrder_Into_SARGeometry["SideOf_L0"] = k; DEMSidesOrder_Into_SARGeometry["SideOf_L0"] = k;
} }
if (col_row[1] > lastLine) else if (col_row[1] > lastLine)
{ {
lastLine = col_row[1]; lastLine = col_row[1];
DEMSidesOrder_Into_SARGeometry["SideOf_Llast"] = k; DEMSidesOrder_Into_SARGeometry["SideOf_Llast"] = k;
...@@ -413,7 +434,7 @@ public: ...@@ -413,7 +434,7 @@ public:
firstY = y_z[0]; firstY = y_z[0];
DEMSidesOrder_Into_SARGeometry["SideOf_NR"] = k; DEMSidesOrder_Into_SARGeometry["SideOf_NR"] = k;
} }
if (y_z[0] > lastY) else if (y_z[0] > lastY)
{ {
lastY = y_z[0]; lastY = y_z[0];
DEMSidesOrder_Into_SARGeometry["SideOf_FR"] = k; DEMSidesOrder_Into_SARGeometry["SideOf_FR"] = k;
...@@ -424,42 +445,41 @@ public: ...@@ -424,42 +445,41 @@ public:
sarSensorModel.WorldToSatPositionAndVelocity(mntGeoPoint, SatPos, SatVel); sarSensorModel.WorldToSatPositionAndVelocity(mntGeoPoint, SatPos, SatVel);
// Cartesian conversion // Cartesian conversion
#if OTB_VERSION_MAJOR >= 8
MntPointCartesien = Projection::WorldToEcef(mntGeoPoint); MntPointCartesien = Projection::WorldToEcef(mntGeoPoint);
#else
otb::SarSensorModelAdapter::WorldToCartesian(mntGeoPoint, MntPointCartesien);
#endif
// Incidence // Incidence
R[0] = MntPointCartesien[0] - SatPos[0]; R[0] = MntPointCartesien[0] - SatPos[0];
R[1] = MntPointCartesien[1] - SatPos[1]; R[1] = MntPointCartesien[1] - SatPos[1];
R[2] = MntPointCartesien[2] - SatPos[2]; R[2] = MntPointCartesien[2] - SatPos[2];
double NormeS = sqrt(SatPos[0]*SatPos[0] + SatPos[1]*SatPos[1] + SatPos[2]*SatPos[2]); double const NormeS2 = SatPos[0]*SatPos[0] + SatPos[1]*SatPos[1] + SatPos[2]*SatPos[2];
double NormeCible = sqrt(MntPointCartesien[0]*MntPointCartesien[0] + double const NormeCible2 =
MntPointCartesien[1]*MntPointCartesien[1] + MntPointCartesien[0]*MntPointCartesien[0] +
MntPointCartesien[2]*MntPointCartesien[2]); MntPointCartesien[1]*MntPointCartesien[1] +
double NormeR = sqrt(R[0]*R[0] + R[1]*R[1] + R[2]*R[2]); MntPointCartesien[2]*MntPointCartesien[2];
double const NormeCible = std::sqrt(NormeCible2);
double const NormeR2 = R[0]*R[0] + R[1]*R[1] + R[2]*R[2];
double const NormeR = std::sqrt(NormeR2);
incidence[k] = acos((NormeS*NormeS - NormeR*NormeR - NormeCible *NormeCible) / incidence[k] = std::acos((NormeS2 - NormeR2 - NormeCible2) /
(2 * NormeCible * NormeR) ) * 180. / M_PI; (2 * NormeCible * NormeR) ) * 180. / M_PI;
} }
// Define the direction into DEM geometry in order to across SAR geometry from Near range to Far range // Define the direction into DEM geometry in order to across SAR geometry from Near range to Far range
int NR_side, FR_side; int const NR_side = DEMSidesOrder_Into_SARGeometry["SideOf_NR"];
NR_side = DEMSidesOrder_Into_SARGeometry["SideOf_NR"]; int const FR_side = DEMSidesOrder_Into_SARGeometry["SideOf_FR"];
FR_side = DEMSidesOrder_Into_SARGeometry["SideOf_FR"];
direction_toScan_DEMColunms = (ind_col[FR_side] > ind_col[NR_side]); direction_toScan_DEMColunms = ind_col[FR_side] > ind_col[NR_side] ? 1 : -1;
direction_toScan_DEMLines = (ind_lines[FR_side] > ind_lines[NR_side]); direction_toScan_DEMLines = ind_lines[FR_side] > ind_lines[NR_side] ? 1 : -1;
if (direction_toScan_DEMColunms == 0)
{
direction_toScan_DEMColunms = -1;
}
if (direction_toScan_DEMLines == 0)
{
direction_toScan_DEMLines = -1;
}
// Fit function // Fit function
double incidence_moy = 0.;
double coef1 = 0.;
double coef2 = 0.;
this->fit2(deltaC, incidence, 4, &incidence_moy, &coef1, &coef2); this->fit2(deltaC, incidence, 4, &incidence_moy, &coef1, &coef2);
// Gain Estimation // Gain Estimation
...@@ -467,10 +487,17 @@ public: ...@@ -467,10 +487,17 @@ public:
} }
void SetSARImageMetadata(ImageMetadata sarImageMetadata) #if OTB_VERSION_MAJOR >= 8
void SetSARImageMetadata(ImageMetadata const& sarImageMetadata)
{ {
m_SarImageMetadata = sarImageMetadata; m_SarImageMetadata = sarImageMetadata;
} }
#else
void SetSARImageKeyWorList(ImageKeywordlist const sarImageKWL)
{
m_SarImageKwl = sarImageKWL;
}
#endif
otbSetObjectMemberMacro(Filter, UserIgnoredValue, RealType); otbSetObjectMemberMacro(Filter, UserIgnoredValue, RealType);
otbGetObjectMemberMacro(Filter, UserIgnoredValue, RealType); otbGetObjectMemberMacro(Filter, UserIgnoredValue, RealType);
...@@ -486,45 +513,41 @@ private: ...@@ -486,45 +513,41 @@ private:
void operator =(const Self&) = delete; void operator =(const Self&) = delete;
// Function fit with a second polynome // Function fit with a second polynome
void fit2(double * x,double * y, int n, double * a, double * b, double * c) void fit2(double * x, double * y, int n, double * a, double * b, double * c)
{ {
double x1,x2,y1; *a=0.;
double s1,s2,s3,s4,r1,r2,r3,c1,c2,c3,c4,c5; *b=0.;
int i; *c=0.;
double s1 = 0.;
*a=0; double s2 = 0.;
*b=0; double s3 = 0.;
*c=0; double s4 = 0.;
s1=0; double r1 = 0.;
s2=0; double r2 = 0.;
s3=0; double r3 = 0.;
s4=0;
r1=0; for (int i=0; i<n; i++)
r2=0;
r3=0;
for (i=0; i<n; i++)
{ {
x1=x[i]; double const x1=x[i];
y1=y[i]; double const y1=y[i];
s1=s1+x1; double const x2=x1*x1;
x2=x1*x1; s1 += x1;
s2=s2+x2; s2 += x2;
s3=s3+x2*x1; s3 += x2*x1;
s4=s4+x2*x2; s4 += x2*x2;
r1=r1+y1; r1 += y1;
r2=r2+y1*x1; r2 += y1*x1;
r3=r3+y1*x2; r3 += y1*x2;
} }
if (s4 ==0) if (s4 ==0)
return; return;
c1=r1-r3*s2/s4; double const c1=r1-r3*s2/s4;
c2=s2-s3*s3/s4; double const c2=s2-s3*s3/s4;
c3=s1-s2*s3/s4; double const c3=s1-s2*s3/s4;
c4=r2-s3*r3/s4; double const c4=r2-s3*r3/s4;
c5=n-s2*s2/s4; double c5=n-s2*s2/s4;
c5=c5*c2-c3*c3; c5=c5*c2-c3*c3;
*a = (c1 * c2 - c3 * c4) / c5; *a = (c1 * c2 - c3 * c4) / c5;
...@@ -535,11 +558,14 @@ private: ...@@ -535,11 +558,14 @@ private:
*b = (c4 - (*a) * c3) / c2; *b = (c4 - (*a) * c3) / c2;
*c = (r3 - (*b) * s3 - (*a) * s2) / s4; *c = (r3 - (*b) * s3 - (*a) * s2) / s4;
} }
// SAR Image Metadata // SAR Image Metadata
#if OTB_VERSION_MAJOR >= 8
ImageMetadata m_SarImageMetadata; ImageMetadata m_SarImageMetadata;
#else
ImageKeywordlist m_SarImageKwl;
#endif
}; };
......
...@@ -47,12 +47,12 @@ PersistentDEMInformationFilter<TInputImage> ...@@ -47,12 +47,12 @@ PersistentDEMInformationFilter<TInputImage>
// allocate the data objects for the outputs which are // allocate the data objects for the outputs which are
// just decorators around pixel types // just decorators around pixel types
for (int i = 1; i <= 4; ++i) for (int i = 1; i <= 4; ++i)
{ {
typename PixelObjectType::Pointer output typename PixelObjectType::Pointer output
= static_cast<PixelObjectType*>(this->MakeOutput(1).GetPointer()); = static_cast<PixelObjectType*>(this->MakeOutput(1).GetPointer());
this->itk::ProcessObject::SetNthOutput(i, output.GetPointer()); this->itk::ProcessObject::SetNthOutput(i, output.GetPointer());
} }
this->GetSide_0_0_Output()->Set(itk::NumericTraits<PixelType>::Zero); this->GetSide_0_0_Output()->Set(itk::NumericTraits<PixelType>::Zero);
this->GetSide_0_nbLines_Output()->Set(itk::NumericTraits<PixelType>::Zero); this->GetSide_0_nbLines_Output()->Set(itk::NumericTraits<PixelType>::Zero);
this->GetSide_nbCol_0_Output()->Set(itk::NumericTraits<PixelType>::Zero); this->GetSide_nbCol_0_Output()->Set(itk::NumericTraits<PixelType>::Zero);
...@@ -67,7 +67,7 @@ PersistentDEMInformationFilter<TInputImage> ...@@ -67,7 +67,7 @@ PersistentDEMInformationFilter<TInputImage>
::MakeOutput(DataObjectPointerArraySizeType output) ::MakeOutput(DataObjectPointerArraySizeType output)
{ {
switch (output) switch (output)
{ {
case 0: case 0:
return static_cast<itk::DataObject*>(TInputImage::New().GetPointer()); return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
break; break;
...@@ -84,7 +84,7 @@ PersistentDEMInformationFilter<TInputImage> ...@@ -84,7 +84,7 @@ PersistentDEMInformationFilter<TInputImage>
// might as well make an image // might as well make an image
return static_cast<itk::DataObject*>(TInputImage::New().GetPointer()); return static_cast<itk::DataObject*>(TInputImage::New().GetPointer());
break; break;
} }
} }
template<class TInputImage> template<class TInputImage>
...@@ -158,15 +158,15 @@ PersistentDEMInformationFilter<TInputImage> ...@@ -158,15 +158,15 @@ PersistentDEMInformationFilter<TInputImage>
{ {
Superclass::GenerateOutputInformation(); Superclass::GenerateOutputInformation();
if (this->GetInput()) if (this->GetInput())
{ {
this->GetOutput()->CopyInformation(this->GetInput()); this->GetOutput()->CopyInformation(this->GetInput());
this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion()); this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetLargestPossibleRegion());
if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0) if (this->GetOutput()->GetRequestedRegion().GetNumberOfPixels() == 0)
{ {
this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion()); this->GetOutput()->SetRequestedRegion(this->GetOutput()->GetLargestPossibleRegion());
}
} }
}
} }
template<class TInputImage> template<class TInputImage>
void void
...@@ -186,31 +186,31 @@ PersistentDEMInformationFilter<TInputImage> ...@@ -186,31 +186,31 @@ PersistentDEMInformationFilter<TInputImage>
::Synthetize() ::Synthetize()
{ {
int numberOfThreads = this->GetNumberOfThreads(); int numberOfThreads = this->GetNumberOfThreads();
// Assign the side and set the outputs (if m_Threads* != 0) // Assign the side and set the outputs (if m_Threads* != 0)
for (int i = 0; i < numberOfThreads; ++i) for (int i = 0; i < numberOfThreads; ++i)
{
if (m_Thread_DEMSide_0_0[i] != itk::NumericTraits<PixelType>::Zero)
{ {
if (m_Thread_DEMSide_0_0[i] != itk::NumericTraits<PixelType>::Zero) this->GetSide_0_0_Output()->Set(m_Thread_DEMSide_0_0[i]);
{ }
this->GetSide_0_0_Output()->Set(m_Thread_DEMSide_0_0[i]);
} if (m_Thread_DEMSide_0_nbLines[i] != itk::NumericTraits<PixelType>::Zero)
{
if (m_Thread_DEMSide_0_nbLines[i] != itk::NumericTraits<PixelType>::Zero) this->GetSide_0_nbLines_Output()->Set(m_Thread_DEMSide_0_nbLines[i]);
{ }
this->GetSide_0_nbLines_Output()->Set(m_Thread_DEMSide_0_nbLines[i]);
} if (m_Thread_DEMSide_nbCol_0[i] != itk::NumericTraits<PixelType>::Zero)
{
if (m_Thread_DEMSide_nbCol_0[i] != itk::NumericTraits<PixelType>::Zero) this->GetSide_nbCol_0_Output()->Set(m_Thread_DEMSide_nbCol_0[i]);
{ }
this->GetSide_nbCol_0_Output()->Set(m_Thread_DEMSide_nbCol_0[i]);
} if (m_Thread_DEMSide_nbCol_nbLines[i] != itk::NumericTraits<PixelType>::Zero)
{
if (m_Thread_DEMSide_nbCol_nbLines[i] != itk::NumericTraits<PixelType>::Zero) this->GetSide_nbCol_nbLines_Output()->Set(m_Thread_DEMSide_nbCol_nbLines[i]);
{ }
this->GetSide_nbCol_nbLines_Output()->Set(m_Thread_DEMSide_nbCol_nbLines[i]);
} }
}
} }
...@@ -234,7 +234,7 @@ PersistentDEMInformationFilter<TInputImage> ...@@ -234,7 +234,7 @@ PersistentDEMInformationFilter<TInputImage>
} }
/** /**
* Method GenerateInputRequestedRegion * Method GenerateInputRequestedRegion
*/ */
template<class TInputImage> template<class TInputImage>
...@@ -246,7 +246,7 @@ PersistentDEMInformationFilter< TInputImage > ...@@ -246,7 +246,7 @@ PersistentDEMInformationFilter< TInputImage >
RegionType inputRequestedRegion = outputRequestedRegion; RegionType inputRequestedRegion = outputRequestedRegion;
InputImagePointer inputPtr = const_cast< ImageType * >( this->GetInput() ); InputImagePointer inputPtr = const_cast< ImageType * >( this->GetInput() );
inputPtr->SetRequestedRegion(inputRequestedRegion); inputPtr->SetRequestedRegion(inputRequestedRegion);
} }
...@@ -269,49 +269,49 @@ PersistentDEMInformationFilter<TInputImage> ...@@ -269,49 +269,49 @@ PersistentDEMInformationFilter<TInputImage>
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels()); itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
// Define/declare an iterator that will walk the input region for this // Define/declare an iterator that will walk the input region for this
// thread. // thread.
typedef itk::ImageScanlineConstIterator< ImageType > InputIterator; typedef itk::ImageScanlineConstIterator< ImageType > InputIterator;
InputIterator inIt(this->GetInput(), inputRegionForThread); InputIterator inIt(this->GetInput(), inputRegionForThread);
inIt.GoToBegin(); inIt.GoToBegin();
// Retrive the DEM dimensions for the side // Retrive the DEM dimensions for the side
int nbColDEM = this->GetInput()->GetLargestPossibleRegion().GetSize()[0]; int nbColDEM = this->GetInput()->GetLargestPossibleRegion().GetSize()[0];
int nbLinesDEM = this->GetInput()->GetLargestPossibleRegion().GetSize()[1]; int nbLinesDEM = this->GetInput()->GetLargestPossibleRegion().GetSize()[1];
// For each line // For each line
while ( !inIt.IsAtEnd()) while ( !inIt.IsAtEnd())
{ {
inIt.GoToBeginOfLine(); inIt.GoToBeginOfLine();
// For each column // For each column
while (!inIt.IsAtEndOfLine()) while (!inIt.IsAtEndOfLine())
{ {
// Get the Index // Get the Index
IndexType index_current = inIt.GetIndex(); IndexType index_current = inIt.GetIndex();
// Check if the current index is corresponding to a side :
// Check if the current index is corresponding to a side : // (0,0), (0,nbLinesDEM-1), (nbColDEM-1,0), (nbColDEM-1,nbLinesDEM-1)
// (0,0), (0,nbLinesDEM-1), (nbColDEM-1,0), (nbColDEM-1,nbLinesDEM-1)
if (index_current[0] == 0 && index_current[1] == 0) if (index_current[0] == 0 && index_current[1] == 0)
{ {
m_Thread_DEMSide_0_0[threadId] = inIt.Get(); m_Thread_DEMSide_0_0[threadId] = inIt.Get();
} }
if (index_current[0] == 0 && index_current[1] == nbLinesDEM-1) else if (index_current[0] == 0 && index_current[1] == nbLinesDEM-1)
{ {
m_Thread_DEMSide_0_nbLines[threadId] = inIt.Get(); m_Thread_DEMSide_0_nbLines[threadId] = inIt.Get();
} }
if (index_current[0] == nbColDEM-1 && index_current[1] == 0) else if (index_current[0] == nbColDEM-1 && index_current[1] == 0)
{ {
m_Thread_DEMSide_nbCol_0[threadId] = inIt.Get(); m_Thread_DEMSide_nbCol_0[threadId] = inIt.Get();
} }
if (index_current[0] == nbColDEM-1 && index_current[1] == nbLinesDEM-1) else if (index_current[0] == nbColDEM-1 && index_current[1] == nbLinesDEM-1)
{ {
m_Thread_DEMSide_nbCol_nbLines[threadId] = inIt.Get(); m_Thread_DEMSide_nbCol_nbLines[threadId] = inIt.Get();
} }
// TODO: No need to continue once all have been set...
// Next colunm
++inIt; // Next colunm
++inIt;
} }
// Next Line // Next Line
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment