Newer
Older
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* 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
*
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
*
* 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 "otbClampROIFilter.h"
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
namespace otb
{
namespace Wrapper
{
/**
* Application that fills margins to 0.
*
* This application is similar to ExtractROI with the difference the margin is
* kept, and filled with 0.
*
* This application is used to implement the _cut_ processing in S1Tiling
* chain.
*
* \author Luc Hermitte (CS Group)
* \copyright CNES
*/
class ClampROI : public Application
{
public:
using Self = ClampROI;
using Pointer = itk::SmartPointer<Self>;
itkNewMacro(Self);
itkTypeMacro(ClampROI, otb::Wrapper::Application);
private:
void DoInit() override
{
SetName("ClampROI");
SetDescription("This is the ClampROI application");
SetDocLongDescription(
"This application is similar to ExtractROI in the sense it extracts a Region of Interrest.\n"
"However, the region outside of the ROI isn't trimmed, but set to 0.\n"
"\n"
"The filter set lines of index < threshold.y, and of index >= threshold.y to 0\n"
"The filter set columns of index < threshold.x, and of index >= threshold.x to 0");
SetDocLimitations("This application only works on scalar (and complex) images.");
SetDocAuthors("Luc Hermitte (CS Group)");
SetDocSeeAlso("ManageNoData, ExtractROI");
AddParameter(ParameterType_InputImage, "in", "Input image");
SetParameterDescription("in", "Scalar Input image");
AddParameter(ParameterType_OutputImage, "out", "Output Image");
SetParameterDescription("out", "Scalar Output image");
AddParameter(ParameterType_Group, "threshold", "threshold group");
AddParameter(ParameterType_Group, "threshold.y", "threshold group");
MandatoryOff("threshold");
MandatoryOff("threshold.y");
AddParameter(ParameterType_Int, "threshold.x", "Column index threshold");
SetParameterDescription("threshold.x", "Column index threshold");
SetDefaultParameterInt("threshold.x", 0);
AddParameter(ParameterType_Int, "threshold.y.start", "Top line index threshold");
SetParameterDescription("threshold.y.start", "Top line index threshold");
SetDefaultParameterInt("threshold.y.start", 0);
AddParameter(ParameterType_Int, "threshold.y.end", "Bottom line index threshold");
SetParameterDescription("threshold.y.end", "Bottom line index threshold");
SetDefaultParameterInt("threshold.y.end", 0);
SetMinimumParameterIntValue("threshold.x", 0);
SetMinimumParameterIntValue("threshold.y.start", 0);
SetMinimumParameterIntValue("threshold.y.end", 0);
SetDocExampleParameterValue("in", "ClampROIInput100x100.tiff");
SetDocExampleParameterValue("threshold.x", "10");
SetDocExampleParameterValue("threshold.y.start", "12");
SetDocExampleParameterValue("threshold.y.end", "25");
SetDocExampleParameterValue("out", "ClampROI.tiff");
SetOfficialDocLink();
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
}
void DoUpdateParameters() override
{}
void DoExecute() override
{
auto const thrX = GetParameterInt("threshold.x");
auto const thrYtop = GetParameterInt("threshold.y.start");
auto const thrYbot = GetParameterInt("threshold.y.end");
if (thrX < 0)
itkExceptionMacro("The column threshold is expected to be positive");
if (thrYtop < 0)
itkExceptionMacro("The top line threshold is expected to be positive");
if (thrYbot < 0)
itkExceptionMacro("The bottom line threshold is expected to be positive");
if (thrX == 0 && thrYtop == 0 && thrYbot == 0)
itkExceptionMacro("Don't use ClampROI to clamp nothing!");
auto filter = ClampROIFilter<FloatImageType>::New();
assert(thrX >= 0);
assert(thrYtop >= 0);
assert(thrYbot >= 0);
filter->SetThresholdX(thrX);
filter->SetThresholdYtop(thrYtop);
filter->SetThresholdYbot(thrYbot);
filter->SetInput(GetParameterFloatImage("in"));
SetParameterOutputImage("out", filter->GetOutput());
RegisterPipeline();
}
};
} // otb::Wrapper namespace
} // otb namespace
OTB_APPLICATION_EXPORT(otb::Wrapper::ClampROI)