Skip to content
Snippets Groups Projects
Commit 3030bfd0 authored by Gaëlle USSEGLIO's avatar Gaëlle USSEGLIO
Browse files

ENH: Cleaning into SARDEMPolygonsAnalysis Filter/Application

parent 25b87f67
1 merge request!19Cleaning
......@@ -159,16 +159,6 @@ public:
// Initialize margin and GenericRSTransform
void initializeMarginAndRSTransform();
/** Returns the const image */
const TImageOut * GetOutput() const;
/** Returns the image */
TImageOut * GetOutput();
/** Returns the const optionnal output image */
//const ImageOptionnalType * GetImageOptionnalTypeOutput() const;
/** Returns the optionnal output image */
ImageOptionnalType * GetOptionnalOutput();
protected:
// Constructor
......@@ -201,20 +191,7 @@ protected:
* OutputRegionToInputRegion returns the input region. This input region corresponds to the outputRegion.
*/
ImageInRegionType OutputRegionToInputRegion(const ImageOutRegionType& outputRegion) const;
/**
* SARDEMPolygonsAnalysisImageFilter can produce an optionnal image according to the functor. The requested
* region for this optionnal output is set to the largest possible region.
*/
void EnlargeOutputRequestedRegion( itk::DataObject *output ) ITK_OVERRIDE;
/**
* SARDEMPolygonsAnalysisImageFilter can produce an optionnal image according to the functor. An allocation of
* this optionnal output is made into BeforeThreadedGenerateData.
*/
void BeforeThreadedGenerateData() ITK_OVERRIDE;
/**
* SARDEMPolygonsAnalysisImageFilter can be implemented as a multithreaded filter.
* Therefore, this implementation provides a ThreadedGenerateData() routine
......@@ -295,10 +272,7 @@ protected:
// Store optionnalImage
ImageOutPixelType * m_OptionnalResults;
int m_OutputCounter;
// Mutex for optionnalImage
MutexType * m_Mutex;
// RSTransform (for inverse localisation)
RSTransformType2D::Pointer m_RSTransform;
......
......@@ -43,54 +43,8 @@ namespace otb
SARDEMPolygonsAnalysisImageFilter< TImageIn ,TImageOut, TImageDEM, TImageSAR, TFunction >::SARDEMPolygonsAnalysisImageFilter()
: m_SarSensorModelAdapter(ITK_NULLPTR), m_Gain(100.), m_Margin(0), m_NoData(-32768), m_MLRan(1), m_MLAzi(1)
{
// Outputs required and/or needed (one required and one optionnal)
this->SetNumberOfRequiredOutputs(1);
this->SetNumberOfIndexedOutputs(2);
this->SetNthOutput(0, ImageOutType::New());
this->SetNthOutput(1, ImageOptionnalType::New());
m_OutputCounter = 0;
m_Mutex = new MutexType();
}
template <class TImageIn, class TImageOut, class TImageDEM, class TImageSAR, class TFunction>
TImageOut *
SARDEMPolygonsAnalysisImageFilter< TImageIn ,TImageOut, TImageDEM, TImageSAR, TFunction >
::GetOutput()
{
if (this->GetNumberOfOutputs() < 1)
{
return ITK_NULLPTR;
}
return static_cast<ImageOutType *>(this->itk::ProcessObject::GetOutput(0));
}
template <class TImageIn, class TImageOut, class TImageDEM, class TImageSAR, class TFunction>
const TImageOut *
SARDEMPolygonsAnalysisImageFilter< TImageIn ,TImageOut, TImageDEM, TImageSAR, TFunction >
::GetOutput() const
{
if (this->GetNumberOfOutputs() < 1)
{
return 0;
}
return static_cast<ImageOutType *>(this->itk::ProcessObject::GetOutput(0));
}
template <class TImageIn, class TImageOut, class TImageDEM, class TImageSAR, class TFunction>
typename SARDEMPolygonsAnalysisImageFilter< TImageIn ,TImageOut, TImageDEM, TImageSAR, TFunction >::ImageOptionnalType *
SARDEMPolygonsAnalysisImageFilter< TImageIn ,TImageOut, TImageDEM, TImageSAR, TFunction >
::GetOptionnalOutput()
{
if (this->GetNumberOfOutputs() < 2)
{
return ITK_NULLPTR;
}
return static_cast<ImageOptionnalType *>(this->itk::ProcessObject::GetOutput(1));
}
/**
* Set Sar Image keyWordList
*/
......@@ -369,70 +323,6 @@ namespace otb
outputKwl.AddKey(key, std::to_string(i));
}
outputPtr->SetImageKeywordList(outputKwl);
////////// Check if the optionnal output is required //////////
if (m_FunctionOnPolygon->GetWithOptionnalOutput())
{
// This output is just a vector with 1xNbLine_MainOutput pixels.
// Pixels are the same nature than Main Output
ImageOptionnalPointer outputOptionnalPtr = this->GetOptionnalOutput();
if (numberOfEstimatedComponents > 1)
{
// Set the number of Components
outputOptionnalPtr->SetNumberOfComponentsPerPixel(numberOfEstimatedComponents);
}
ImageOptionnalRegionType region = outputPtr->GetLargestPossibleRegion();
ImageOptionnalSizeType sizeRegion;
sizeRegion[0] = 1;
sizeRegion[1] = outputPtr->GetLargestPossibleRegion().GetSize()[1];
region.SetSize(sizeRegion);
outputOptionnalPtr->SetLargestPossibleRegion(region);
outputOptionnalPtr->SetOrigin(outputPtr->GetOrigin());
outputOptionnalPtr->SetSpacing(outputPtr->GetSpacing());
// Complete Optionnal Output KeyWordList
ImageKeywordlist outputOptionnalKwl;
for (unsigned int i = 0; i < vecEstimatedComponents.size(); i++)
{
std::string key = BandKey + vecEstimatedComponents.at(i);
outputOptionnalKwl.AddKey(key, std::to_string(i));
}
outputOptionnalPtr->SetImageKeywordList(outputOptionnalKwl);
if (m_OutputCounter == 0)
{
// Allocate optionnal Results (Vector)
int nbLineOptionnal = this->GetOptionnalOutput()->GetLargestPossibleRegion().GetSize()[1];
m_OptionnalResults = new ImageOutPixelType[nbLineOptionnal];
}
}
// Increment Output Counter
++m_OutputCounter;
}
/**
* Method EnlargeOutputRequestedRegion
*/
template<class TImageIn, class TImageOut, class TImageDEM, class TImageSAR, class TFunction>
void
SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TFunction >
::EnlargeOutputRequestedRegion( itk::DataObject *itkNotUsed(output) )
{
// This filter requires all of the optionnal output image (Nth Output = 1). The output is
// vector with 1xNbLines_Main_Output as size
if (m_FunctionOnPolygon->GetWithOptionnalOutput())
{
if ( this->itk::ProcessObject::GetOutput(1) )
{
this->itk::ProcessObject::GetOutput(1)->SetRequestedRegionToLargestPossibleRegion();
}
}
}
/**
......@@ -603,26 +493,6 @@ namespace otb
///////////// Set Output Requestion Region (Strips) ///////////////
ImageOutRegionType outputRequestedRegion = this->GetOutput()->GetRequestedRegion();
// if (m_FunctionOnPolygon->GetWithOptionnalOutput())
// {
// if (outputRequestedRegion.GetIndex()[0] != 0 &&
// outputRequestedRegion.GetSize()[0] != this->GetOutput()->GetLargestPossibleRegion().GetSize()[0])
// {
// ImageOutIndexType outputIndex;
// outputIndex[0] = 0;
// outputIndex[1] = outputRequestedRegion.GetIndex()[1];
// ImageOutSizeType outputSize;
// outputSize[0] = this->GetOutput()->GetLargestPossibleRegion().GetSize()[0];
// outputSize[1] = outputRequestedRegion.GetSize()[1];
// // Region affectation (with Crop to respect image dimension)
// outputRequestedRegion.SetSize(outputSize);
// outputRequestedRegion.SetIndex(outputIndex);
// //outputRequestedRegion.Crop(this->GetOutput()->GetLargestPossibleRegion());
// this->GetOutput()->SetRequestedRegion(outputRequestedRegion);
// }
// }
///////////// With the new output requested region, find the region into Projeted DEM /////////////
ImageInRegionType inputRequestedRegion = OutputRegionToInputRegion(outputRequestedRegion);
ImageInPointer inputPtr = const_cast< ImageInType * >( this->GetInput() );
......@@ -964,25 +834,6 @@ namespace otb
}
}
/**
* Method ThreadedGenerateData
*/
template<class TImageIn, class TImageOut, class TImageDEM, class TImageSAR, class TFunction>
void
SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TFunction >
::BeforeThreadedGenerateData()
{
// Allocation for the optionnal image (if needed)
if (m_FunctionOnPolygon->GetWithOptionnalOutput())
{
// Allocate optionnal output
ImageOptionnalPointer outputOptionnalPtr = this->GetOptionnalOutput();
outputOptionnalPtr->SetBufferedRegion(outputOptionnalPtr->GetRequestedRegion() );
outputOptionnalPtr->Allocate();
}
}
/**
* Method ThreadedGenerateData
*/
......@@ -1216,30 +1067,6 @@ namespace otb
// Next Line
OutIt.NextLine();
/// Optionnal Output ////
if (m_FunctionOnPolygon->GetWithOptionnalOutput())
{
// Assignate the optionnal image
ImageOutIndexType indexOptionnalImage;
indexOptionnalImage[0] = 0; // Always 0 since optionnal image is a vector
indexOptionnalImage[1] = ind_Line;
// Estimate the value for the current ind_Line and store it into m_OptionnalResults
// If first output => Estimate ans store results if second => copy and write into optionnal image
// m_OptionnalResults is threadSafe because of mutex lock and unlock
m_Mutex->Lock();
if (m_OutputCounter == 1)
{
m_FunctionOnPolygon->estimateOptionnalImage(&m_OptionnalResults[ind_Line], threadId);
}
else
{
this->GetOptionnalOutput()->SetPixel(indexOptionnalImage, m_OptionnalResults[ind_Line]);
}
m_Mutex->Unlock();
}
} // End lines (Main output)
delete [] Polygon_SideInUp_VecLine;
......
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