Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Cabieces
otb
Commits
0d3f8566
Commit
0d3f8566
authored
5 years ago
by
Antoine Regimbeau
Browse files
Options
Downloads
Patches
Plain Diff
ENH: refactor bandmathx application
parent
5ae5a17d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Modules/Applications/AppMathParserX/app/otbBandMathX.cxx
+49
-64
49 additions, 64 deletions
Modules/Applications/AppMathParserX/app/otbBandMathX.cxx
with
49 additions
and
64 deletions
Modules/Applications/AppMathParserX/app/otbBandMathX.cxx
+
49
−
64
View file @
0d3f8566
...
...
@@ -246,54 +246,42 @@ private:
void
DoUpdateParameters
()
override
{
// check if input context should be used
bool
useC
ontext
=
this
->
ContextCheck
();
bool
c
ontext
_exists
=
this
->
ContextCheck
();
// Check if the expression is correctly set
if
(
HasValue
(
"il"
)
&&
HasValue
(
"exp"
))
{
this
->
LiveCheck
(
useContext
);
}
BandMathImageFilterType
::
Pointer
math_filter
=
BandMathImageFilterType
::
New
();
math_filter
->
SetManyExpressions
(
false
);
// first thing, load context if there is one
if
(
context_exists
)
math_filter
->
ImportContext
(
GetParameterString
(
"incontext"
));
// Only one expression is allowed '-exp'>'-incontext'
if
(
!
HasValue
(
"exp"
)
)
SetParameterString
(
"exp"
,
math_filter
->
GetExpression
(
0
));
if
(
HasValue
(
"il"
)
&&
HasValue
(
"exp"
)
)
{
math_filter
->
ClearExpression
();
// remove expression set by context
math_filter
->
SetExpression
(
GetParameterString
(
"exp"
));
//set expression
LiveCheck
(
math_filter
);
}
}
// Check if the given filename is valid
bool
ContextCheck
(
void
)
{
bool
useC
ontext
=
false
;
{
bool
c
ontext
_exists
=
false
;
if
(
IsParameterEnabled
(
"incontext"
)
&&
HasValue
(
"incontext"
))
{
{
std
::
string
contextPath
=
GetParameterString
(
"incontext"
);
// check that file exists
if
(
itksys
::
SystemTools
::
FileExists
(
contextPath
,
true
))
{
BandMathImageFilterType
::
Pointer
dummyFilter
=
BandMathImageFilterType
::
New
();
dummyFilter
->
SetManyExpressions
(
false
);
try
{
dummyFilter
->
ImportContext
(
contextPath
);
useContext
=
true
;
}
catch
(
itk
::
ExceptionObject
&
err
)
{
//trick to prevent unreferenced local variable warning on MSVC
(
void
)
err
;
// silent catch
useContext
=
false
;
}
if
(
useContext
)
{
// only set the first expression, 'ManyExpression' is disabled.
this
->
SetParameterString
(
"exp"
,
dummyFilter
->
GetExpression
(
0
));
}
}
{
context_exists
=
true
;
}
return
useContext
;
}
return
context_exists
;
}
void
LiveCheck
(
bool
useContext
=
false
)
void
LiveCheck
(
BandMathImageFilterType
::
Pointer
math_filter
)
{
BandMathImageFilterType
::
Pointer
dummyFilter
=
BandMathImageFilterType
::
New
();
dummyFilter
->
SetManyExpressions
(
false
);
std
::
vector
<
MultiChannelExtractorType
::
Pointer
>
extractors
;
FloatVectorImageListType
::
Pointer
inList
=
GetParameterImageList
(
"il"
);
for
(
unsigned
int
i
=
0
;
i
<
inList
->
Size
();
i
++
)
...
...
@@ -314,19 +302,11 @@ private:
{
extract
->
SetChannel
(
j
+
1
);
}
dummyFilter
->
SetNthInput
(
i
,
extract
->
GetOutput
());
}
if
(
useContext
)
{
dummyFilter
->
ImportContext
(
GetParameterString
(
"incontext"
));
}
else
{
dummyFilter
->
SetExpression
(
GetParameterString
(
"exp"
));
math_filter
->
SetNthInput
(
i
,
extract
->
GetOutput
());
}
try
{
dummyF
ilter
->
Update
OutputInformation
();
math_f
ilter
->
Update
();
SetParameterDescription
(
"exp"
,
"Valid expression"
);
}
catch
(
itk
::
ExceptionObject
&
err
)
...
...
@@ -334,6 +314,9 @@ private:
// Change the parameter description to be able to have the
// parser errors in the tooltip
SetParameterDescription
(
"exp"
,
err
.
GetDescription
());
// std::string error_string(err.GetDescription());
// otbAppLogINFO("There was an error while parsing the expression giving "
// "its input:" + error_string );
}
}
...
...
@@ -352,11 +335,11 @@ private:
if
(
(
!
IsParameterEnabled
(
"exp"
))
&&
(
!
IsParameterEnabled
(
"incontext"
))
)
{
itkExceptionMacro
(
"No expression set...; please set and enable at least one
one
expression"
);
itkExceptionMacro
(
"No expression set...; please set and enable at least one expression"
);
}
m_Filter
=
BandMathImageFilterType
::
New
();
m
_F
ilter
->
SetManyExpressions
(
false
);
BandMathImageFilterType
::
Pointer
math_filter
=
BandMathImageFilterType
::
New
();
m
ath_f
ilter
->
SetManyExpressions
(
false
);
for
(
unsigned
int
i
=
0
;
i
<
nbImages
;
i
++
)
{
...
...
@@ -367,31 +350,33 @@ private:
<<
currentImage
->
GetNumberOfComponentsPerPixel
()
<<
" components"
);
m
_F
ilter
->
SetNthInput
(
i
,
currentImage
);
m
ath_f
ilter
->
SetNthInput
(
i
,
currentImage
);
}
bool
useContext
=
this
->
ContextCheck
();
bool
context_exists
=
this
->
ContextCheck
();
// first thing, load context if there is one
if
(
context_exists
)
{
std
::
string
context_string
=
GetParameterString
(
"incontext"
);
math_filter
->
ImportContext
(
context_string
);
otbAppLogINFO
(
"Using Context: "
<<
context_string
<<
" for variables (and expression if no parameter -exp has been given)."
);
}
// Only one expression is allowed '-exp'>'-incontext'
math_filter
->
ClearExpression
();
// remove expression set by context
std
::
string
expStr
=
GetParameterString
(
"exp"
);
if
(
useContext
)
{
otbAppLogINFO
(
"Using input context: "
<<
expStr
);
m_Filter
->
ImportContext
(
GetParameterString
(
"incontext"
));
}
else
{
otbAppLogINFO
(
"Using expression: "
<<
expStr
);
m_Filter
->
SetExpression
(
expStr
);
}
otbAppLogINFO
(
"Using expression: "
<<
expStr
);
math_filter
->
SetExpression
(
expStr
);
if
(
IsParameterEnabled
(
"outcontext"
)
&&
HasValue
(
"outcontext"
)
)
m
_F
ilter
->
ExportContext
(
GetParameterString
(
"outcontext"
));
m
ath_f
ilter
->
ExportContext
(
GetParameterString
(
"outcontext"
));
// Set the output image
SetParameterOutputImage
(
"out"
,
m_Filter
->
GetOutput
());
SetParameterOutputImage
(
"out"
,
math_filter
->
GetOutput
());
RegisterPipeline
();
}
BandMathImageFilterType
::
Pointer
m_Filter
;
};
}
// namespace Wrapper
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment