Commit 1be32986 authored by Cédric Traizet's avatar Cédric Traizet
Browse files

REFAC: use RegisterPipeline() In ManageNoData for better memory management

parent 46641ea6
Pipeline #8928 passed with stages
in 94 minutes and 49 seconds
......@@ -133,31 +133,31 @@ private:
{
FloatVectorImageType::Pointer inputPtr = this->GetParameterImage("in");
m_Filter = FilterType::New();
m_Filter->SetInsideValue(this->GetParameterFloat("mode.buildmask.inv"));
m_Filter->SetOutsideValue(this->GetParameterFloat("mode.buildmask.outv"));
m_Filter->SetNaNIsNoData(GetParameterInt("usenan"));
m_Filter->SetInput(inputPtr);
m_ChangeNoDataFilter = ChangeNoDataFilterType::New();
m_ChangeNoDataFilter->SetInput(inputPtr);
m_ChangeNoDataFilter->SetNaNIsNoData(GetParameterInt("usenan"));
std::vector<double> newNoData(inputPtr->GetNumberOfComponentsPerPixel(), GetParameterFloat("mode.changevalue.newv"));
m_ChangeNoDataFilter->SetNewNoDataValues(newNoData);
if (GetParameterString("mode") == "buildmask")
{
SetParameterOutputImage("out", m_Filter->GetOutput());
auto filter = FilterType::New();
filter->SetInsideValue(this->GetParameterFloat("mode.buildmask.inv"));
filter->SetOutsideValue(this->GetParameterFloat("mode.buildmask.outv"));
filter->SetNaNIsNoData(GetParameterInt("usenan"));
filter->SetInput(inputPtr);
SetParameterOutputImage("out", filter->GetOutput());
RegisterPipeline();
}
else if (GetParameterString("mode") == "changevalue")
{
SetParameterOutputImage("out", m_ChangeNoDataFilter->GetOutput());
auto changeNoDataFilter = ChangeNoDataFilterType::New();
changeNoDataFilter->SetInput(inputPtr);
changeNoDataFilter->SetNaNIsNoData(GetParameterInt("usenan"));
std::vector<double> newNoData(inputPtr->GetNumberOfComponentsPerPixel(), GetParameterFloat("mode.changevalue.newv"));
changeNoDataFilter->SetNewNoDataValues(newNoData);
SetParameterOutputImage("out", changeNoDataFilter->GetOutput());
RegisterPipeline();
}
else if (GetParameterString("mode") == "apply")
{
m_MaskFilters.clear();
UInt8ImageType::Pointer maskPtr = this->GetParameterUInt8Image("mode.apply.mask");
unsigned int nbBands = inputPtr->GetNumberOfComponentsPerPixel();
const auto & imd = inputPtr->GetImageMetadata();
......@@ -170,11 +170,12 @@ private:
values = std::vector<double>(nbBands, GetParameterFloat("mode.apply.ndval"));
}
m_V2L = VectorToListFilterType::New();
m_V2L->SetInput(inputPtr);
ImageListType::Pointer inputList = m_V2L->GetOutput();
auto V2L = VectorToListFilterType::New();
V2L->SetInput(inputPtr);
ImageListType::Pointer inputList = V2L->GetOutput();
inputList->UpdateOutputInformation();
ImageListType::Pointer outputList = ImageListType::New();
std::vector<MaskFilterType::Pointer> maskFilters;
for (unsigned int i = 0; i < nbBands; ++i)
{
if (flags[i])
......@@ -185,30 +186,25 @@ private:
masker->SetMaskingValue(0);
masker->SetOutsideValue(values[i]);
outputList->PushBack(masker->GetOutput());
m_MaskFilters.push_back(masker);
maskFilters.push_back(masker);
}
else
{
outputList->PushBack(inputList->GetNthElement(i));
}
}
m_L2V = ListToVectorFilterType::New();
m_L2V->SetInput(outputList);
auto L2V = ListToVectorFilterType::New();
L2V->SetInput(outputList);
if (!ret)
{
// write the new NoData values in the output metadata (mode.apply.ndval)
m_L2V->UpdateOutputInformation();
otb::WriteNoDataFlags(flags, values, m_L2V->GetOutput()->GetImageMetadata());
L2V->UpdateOutputInformation();
otb::WriteNoDataFlags(flags, values, L2V->GetOutput()->GetImageMetadata());
}
SetParameterOutputImage("out", m_L2V->GetOutput());
SetParameterOutputImage("out", L2V->GetOutput());
RegisterPipeline();
}
}
FilterType::Pointer m_Filter;
ChangeNoDataFilterType::Pointer m_ChangeNoDataFilter;
std::vector<MaskFilterType::Pointer> m_MaskFilters;
VectorToListFilterType::Pointer m_V2L;
ListToVectorFilterType::Pointer m_L2V;
};
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment