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

ENH: Remove CartesianMeanWithMeanPerLine Application/Functor

parent bf33edd9
No related branches found
No related tags found
No related merge requests found
......@@ -59,11 +59,6 @@ OTB_CREATE_APPLICATION(NAME SARCartesianMeanEstimation
LINK_LIBRARIES ${${otb-module}_LIBRARIES}
)
OTB_CREATE_APPLICATION(NAME SARCartesianMeanWithMeanPerLineEstimation
SOURCES otbSARCartesianMeanWithMeanPerLineEstimation.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES}
)
OTB_CREATE_APPLICATION(NAME SARInterferogram
SOURCES otbSARInterferogram.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES}
......
/*
* Copyright (C) 2005-2018 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbSARDEMPolygonsAnalysisImageFilter.h"
#include "otbSARCartesianMeanWithMeanPerLineFunctor.h"
#include "otbWrapperOutputImageParameter.h"
#include <iostream>
#include <string>
#include <fstream>
namespace otb
{
namespace Wrapper
{
class SARCartesianMeanWithMeanPerLineEstimation : public Application
{
public:
typedef SARCartesianMeanWithMeanPerLineEstimation Self;
typedef itk::SmartPointer<Self> Pointer;
itkNewMacro(Self);
itkTypeMacro(SARCartesianMeanWithMeanPerLineEstimation, otb::Wrapper::Application);
// Pixels
typedef typename FloatVectorImageType::PixelType ImageInPixelType;
typedef typename DoubleVectorImageType::PixelType ImageOutPixelType;
// Function
typedef otb::Function::SARCartesianMeanWithMeanPerLineFunctor<ImageInPixelType, ImageOutPixelType> CartesianMeanFunctorType;
// Filters
typedef otb::SARDEMPolygonsAnalysisImageFilter < FloatVectorImageType, DoubleVectorImageType, FloatImageType, ComplexFloatImageType, CartesianMeanFunctorType > FilterType;
private:
void DoInit() override
{
SetName("SARCartesianMeanWithMeanPerLineEstimation");
SetDescription("SAR Cartesian Mean estimation thanks to the associated DEM.");
SetDocLongDescription("This application estimates a cartesian image per pixel and per line thanks to a DEM file.");
//Optional descriptors
SetDocLimitations("Only Sentinel 1 products are supported for now.");
SetDocAuthors("OTB-Team");
SetDocSeeAlso(" ");
AddDocTag(Tags::SAR);
//Parameter declarations
AddParameter(ParameterType_InputImage, "indemproj", "Input vector of DEM projected into SAR geometry");
SetParameterDescription("indemproj", "Input vector image for cartesian mean estimation.");
AddParameter(ParameterType_InputImage, "indem", "Input DEM");
SetParameterDescription("indem", "DEM to extract DEM geometry.");
AddParameter(ParameterType_InputImage, "insar", "Input SAR image");
SetParameterDescription("insar", "SAR Image to extract SAR geometry.");
AddParameter(ParameterType_Int, "indirectiondemc", "Range direction for DEM scan");
SetParameterDescription("indirectiondemc", "Range direction for DEM scan.");
SetDefaultParameterInt("indirectiondemc", 1);
MandatoryOff("indirectiondemc");
AddParameter(ParameterType_Int, "indirectiondeml", "Azimut direction for DEM scan");
SetParameterDescription("indirectiondeml", "Azimut direction for DEM scan.");
SetDefaultParameterInt("indirectiondeml", 1);
MandatoryOff("indirectiondeml");
AddParameter(ParameterType_Int, "mlran", "Averaging on distance (output geometry)");
SetParameterDescription("mlran","Averaging on distance (output geometry)");
SetDefaultParameterInt("mlran", 3);
SetMinimumParameterIntValue("mlran", 1);
MandatoryOff("mlran");
AddParameter(ParameterType_Int, "mlazi", "Averaging on azimut (output geometry)");
SetParameterDescription("mlazi","Averaging on azimut (output geometry)");
SetDefaultParameterInt("mlazi", 3);
SetMinimumParameterIntValue("mlazi", 1);
MandatoryOff("mlazi");
AddParameter(ParameterType_OutputImage, "out", "Output cartesian (mean) Image for DEM Projection");
SetParameterDescription("out","Output cartesian (mean) Image for DEM Projection.");
AddParameter(ParameterType_OutputImage, "outopt", "Optionnal Output cartesian (mean) Per line");
SetParameterDescription("outopt","Optionnal Output cartesian (mean) Per line.");
AddRAMParameter();
SetDocExampleParameterValue("indemproj","CLZY_S21E055.tiff");
SetDocExampleParameterValue("indem","S21E055.hgt");
SetDocExampleParameterValue("insar","s1a-s4-slc-vv-20160818t014650-20160818t014715-012648-013db1-002_SLC.tiff");
SetDocExampleParameterValue("out","s1a-s4-simu-cartMean.tiff");
SetDocExampleParameterValue("outopt","s1a-s4-simu-cartMeanPerLine.tiff");
}
void DoUpdateParameters() override
{
// Nothing to do here : all parameters are independent
}
void DoExecute() override
{
// Get numeric parameters : ML factors and directions for DEM scan
int mlRan = GetParameterInt("mlran");
int mlAzi = GetParameterInt("mlazi");
int DEMScanDirectionC = GetParameterInt("indirectiondemc");
int DEMScanDirectionL = GetParameterInt("indirectiondeml");
otbAppLogINFO(<<"ML Range : "<<mlRan);
otbAppLogINFO(<<"ML Azimut : "<<mlAzi);
otbAppLogINFO(<<"Direction (DEM scan) in range : "<<DEMScanDirectionC);
otbAppLogINFO(<<"Direction (DEM scan) in azimut : "<<DEMScanDirectionL);
// Start the first pipelines (Read SAR and DEM image metedata)
ComplexFloatImageType::Pointer SARPtr = GetParameterComplexFloatImage("insar");
FloatImageType::Pointer DEMPtr = GetParameterFloatImage("indem");
// CartesianMeanEstimation Filter (use SARDEMPolygonsAnalysisImageFilter with SARCartesianMeanEstimationFunctor
// to estimate cartesian mean image per pixel and per line)
FilterType::Pointer filterCartesianMeanEstimation = FilterType::New();
m_Ref.push_back(filterCartesianMeanEstimation.GetPointer());
filterCartesianMeanEstimation->SetSARImageKeyWorList(SARPtr->GetImageKeywordlist());
filterCartesianMeanEstimation->SetSARImagePtr(SARPtr);
filterCartesianMeanEstimation->SetDEMImagePtr(DEMPtr);
filterCartesianMeanEstimation->SetDEMInformation(0, DEMScanDirectionC, DEMScanDirectionL);
filterCartesianMeanEstimation->initializeMarginAndRSTransform();
// Function Type : SARCartesianMeanEstimationFunctor
int nbThreads = filterCartesianMeanEstimation->GetNumberOfThreads();
CartesianMeanFunctorType::Pointer functor = CartesianMeanFunctorType::New(nbThreads, mlRan, mlAzi);
filterCartesianMeanEstimation->SetFunctorPtr(functor);
// Define the main pipeline (controlled with extended FileName)
std::string origin_FileName = GetParameterString("out");
// Check if FileName is extended (with the ? caracter)
// If not extended then override the FileName
if (origin_FileName.find("?") == std::string::npos && !origin_FileName.empty())
{
std::string extendedFileName = origin_FileName;
// Get the ram value (in MB)
int ram = GetParameterInt("ram");
// Define with the ram value, the number of lines for the streaming
int nbColSAR = SARPtr->GetLargestPossibleRegion().GetSize()[0];
int nbLinesSAR = SARPtr->GetLargestPossibleRegion().GetSize()[1];
// To determine the number of lines :
// nbColSAR * nbLinesStreaming * sizeof(OutputPixel) = RamValue/2 (/2 to be sure)
// OutputPixel are float => sizeof(OutputPixel) = 4 (Bytes)
long int ram_In_KBytes = (ram/2) * 1024;
long int nbLinesStreaming = (ram_In_KBytes / (nbColSAR)) * (1024/4);
// Check the value of nbLinesStreaming
int nbLinesStreamingMax = 15000;
if (nbLinesStreamingMax > nbLinesSAR)
{
nbLinesStreamingMax = nbLinesSAR;
}
if (nbLinesStreaming <= 0 || nbLinesStreaming > nbLinesStreamingMax)
{
nbLinesStreaming = nbLinesStreamingMax;
}
// Construct the extendedPart
std::ostringstream os;
os << "?&streaming:type=stripped&streaming:sizevalue=" << nbLinesStreaming;
// Add the extendedPart
std::string extendedPart = os.str();
extendedFileName.append(extendedPart);
// Set the new FileName with extended options
SetParameterString("out", extendedFileName);
}
// Execute the main Pipeline
filterCartesianMeanEstimation->SetInput(GetParameterImage<FloatVectorImageType>("indemproj"));
SetParameterOutputImage<DoubleVectorImageType>("out", filterCartesianMeanEstimation->GetOutput());
SetParameterOutputImage<DoubleVectorImageType>("outopt", filterCartesianMeanEstimation->GetOptionnalOutput());
}
// Vector for filters
std::vector<itk::ProcessObject::Pointer> m_Ref;
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::SARCartesianMeanWithMeanPerLineEstimation)
/*
* Copyright (C) 2005-2018 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbSARCartesianMeanWithMeanPerLineFunctor_h
#define otbSARCartesianMeanWithMeanPerLineFunctor_h
#include <cassert>
#include "itkVariableLengthVector.h"
#include "itkRGBPixel.h"
#include "itkRGBAPixel.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
#include "otbSARPolygonsFunctor.h"
#include "otbSARCartesianMeanFunctor.h"
namespace otb
{
namespace Function
{
/** \class SARCartesianMeanWithMeanPerLineFunctor
* \brief Catesian mean estimation for each output pixel and output line.
*
* This functor spreads SARCartesianMeanFunctor. It estimates the Cartesian coordonates mean image and
* an optionnal image (Cartesian coordonates mean for each output line).
*
* The characteristics are the following :
* _ Output Geometry : ML (defined by ML factors)
* _ Seven required components : L, C, Y, Z, XCart, YCart and ZCart
* _ Three estimated component : Mean of XCart, YCart and ZCart
* _ Optionnal image : Yes (dimension 1 x nbLineOfMainOutput)
*
* \ingroup DiapOTBModule
*/
template <class TInputPixel, class TOutputPixel>
class SARCartesianMeanWithMeanPerLineFunctor : public SARCartesianMeanFunctor<TInputPixel, TOutputPixel>
{
public:
/** Standard class typedefs */
typedef SARCartesianMeanWithMeanPerLineFunctor Self;
typedef SARCartesianMeanFunctor<TInputPixel, TOutputPixel> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Runtime information */
itkTypeMacro(SARCartesianMeanWithMeanPerLineFunctor, itk::Object);
/**
* Method synthetize (override)
*/
// Synthetize to apply on XCart, YCart and Zcart the counter of polygons
void synthetize(int nbElt, TOutputPixel * outValue, int threadId=1) override
{
// ReInitialize m_OutMeanByLine and m_CountPolygonsPerLine
m_OutMeanByLine[threadId][0] = 0;
m_OutMeanByLine[threadId][1] = 0;
m_OutMeanByLine[threadId][2] = 0;
m_CountPolygonsPerLine[threadId] = 0;
//////// Mean by line ////////
for(int ind = 0; ind < nbElt; ind++)
{
m_OutMeanByLine[threadId][0] += outValue[ind][0];
m_OutMeanByLine[threadId][1] += outValue[ind][1];
m_OutMeanByLine[threadId][2] += outValue[ind][2];
m_CountPolygonsPerLine[threadId] += this->m_CountPolygons[threadId][ind];
}
if (m_CountPolygonsPerLine[threadId] != 0)
{
m_OutMeanByLine[threadId][0] /= m_CountPolygonsPerLine[threadId];
m_OutMeanByLine[threadId][1] /= m_CountPolygonsPerLine[threadId];
m_OutMeanByLine[threadId][2] /= m_CountPolygonsPerLine[threadId];
}
//////// Mean by pixel ////////
for(int ind = 0; ind < nbElt; ind++)
{
if (this->m_CountPolygons[threadId][ind] !=0)
{
outValue[ind][0] /= this->m_CountPolygons[threadId][ind];
outValue[ind][1] /= this->m_CountPolygons[threadId][ind];
outValue[ind][2] /= this->m_CountPolygons[threadId][ind];
}
}
}
/**
* Method estimateOptionnalImage (override)
*/
void estimateOptionnalImage(TOutputPixel * outValue, int threadId=1) override
{
// Allocation of Components
outValue[0].Reserve(4);
// Assignate (only one element per line for this functor)
outValue[0][0] = m_OutMeanByLine[threadId][0];
outValue[0][1] = m_OutMeanByLine[threadId][1];
outValue[0][2] = m_OutMeanByLine[threadId][2];
// IsData always to 1
outValue[0][3] = 1;
}
/** Constructor */ //
SARCartesianMeanWithMeanPerLineFunctor(int nbThreads, unsigned int mlran = 1, unsigned int mlazi = 1) : Superclass(nbThreads, mlran, mlazi)
{
// Specific argument
m_CountPolygonsPerLine = new int[this->m_NbThreads];
// Allocate the buffer of polygons for each thread
for (int i = 0; i < this->m_NbThreads; i++)
{
m_CountPolygonsPerLine[i] = 0;
}
// Set optionnal output (MeanPerline Image) to true
this->SetWithOptionnalOutput(true);
// Allocate the MeanPerline Buffer
m_OutMeanByLine = new TOutputPixel[this->m_NbThreads];
for (int i = 0; i < this->m_NbThreads; i++)
{
m_OutMeanByLine[i].Reserve(4);
m_OutMeanByLine[i][0] = 0;
m_OutMeanByLine[i][1] = 0;
m_OutMeanByLine[i][2] = 0;
m_OutMeanByLine[i][3] = 0;
}
}
// Redefinition to use construction with NumberOfThreads (Functor used in Multi-Threading)
static Pointer New(int nbThreads, unsigned int mlran = 1, unsigned int mlazi = 1)
{
Pointer smartPtr = ::itk::ObjectFactory< Self >::Create();
if ( smartPtr == nullptr )
{
smartPtr = new Self(nbThreads, mlran, mlazi);
}
smartPtr->UnRegister();
return smartPtr;
}
/** Destructor */
~SARCartesianMeanWithMeanPerLineFunctor() override
{
// free Memory
delete m_CountPolygonsPerLine;
for (int i = 0; i < this->m_NbThreads; i++)
{
m_OutMeanByLine[i].DestroyExistingData(); // TOutputPixel a itk::VariableLengthVector
}
}
private :
int * m_CountPolygonsPerLine;
TOutputPixel * m_OutMeanByLine;
int m_CountLine;
};
}
}
#endif
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