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
a2378fb9
Commit
a2378fb9
authored
13 years ago
by
Julien Malik
Browse files
Options
Downloads
Patches
Plain Diff
ENH: add spectral angle in MaskMuParserFunctor
parent
d2a06dc0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Code/BasicFilters/otbMaskMuParserFunctor.h
+31
-79
31 additions, 79 deletions
Code/BasicFilters/otbMaskMuParserFunctor.h
Code/BasicFilters/otbMaskMuParserFunctor.txx
+139
-0
139 additions, 0 deletions
Code/BasicFilters/otbMaskMuParserFunctor.txx
with
170 additions
and
79 deletions
Code/BasicFilters/otbMaskMuParserFunctor.h
+
31
−
79
View file @
a2378fb9
...
...
@@ -29,6 +29,8 @@
#include
"itkLightObject.h"
#include
"itkObjectFactory.h"
#include
"otbBinarySpectralAngleFunctor.h"
namespace
otb
{
/** \class MaskMuParserFunctor
...
...
@@ -54,104 +56,47 @@ namespace otb
namespace
Functor
{
template
<
class
TInput
>
template
<
class
TInput
Pixel
>
class
ITK_EXPORT
MaskMuParserFunctor
:
public
itk
::
LightObject
{
public:
typedef
Parser
ParserType
;
typedef
MaskMuParserFunctor
Self
;
typedef
itk
::
LightObject
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
MaskMuParserFunctor
Self
;
typedef
itk
::
LightObject
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Method for creation through the object factory. */
itkNewMacro
(
Self
)
;
itkNewMacro
(
Self
);
/** Run-time type information (and related methods). */
itkTypeMacro
(
MaskMuParserFunctor
,
itk
::
LightObject
)
;
inline
bool
operator
()(
const
TInput
&
p
)
{
double
value
;
itkTypeMacro
(
MaskMuParserFunctor
,
itk
::
LightObject
);
if
(
p
.
Size
()
!=
m_NbOfBands
)
{
this
->
SetNumberOfBands
(
p
.
GetSize
());
}
// we fill the buffer
for
(
unsigned
int
i
=
0
;
i
<
m_NbOfBands
;
i
++
)
{
m_AImage
[
i
]
=
static_cast
<
double
>
(
p
[
i
]);
}
// user defined variables
m_Intensity
=
0.0
;
for
(
unsigned
int
i
=
0
;
i
<
m_NbOfBands
;
++
i
)
{
m_Intensity
+=
p
[
i
];
}
m_Intensity
=
m_Intensity
/
(
static_cast
<
double
>
(
m_NbOfBands
));
value
=
m_Parser
->
Eval
();
typedef
TInputPixel
PixelType
;
typedef
Parser
ParserType
;
return
static_cast
<
bool
>
(
value
)
;
typedef
BinarySpectralAngleFunctor
<
PixelType
,
PixelType
,
double
>
SpectralAngleFunctorType
;
}
bool
operator
()(
const
PixelType
&
p
);
const
std
::
map
<
std
::
string
,
Parser
::
ValueType
*>&
GetVar
()
const
{
return
this
->
m_Parser
->
GetVar
();
}
const
std
::
map
<
std
::
string
,
Parser
::
ValueType
*>&
GetVar
()
const
;
void
SetExpression
(
const
std
::
string
&
expression
)
{
m_Expression
=
expression
;
m_Parser
->
SetExpr
(
m_Expression
);
}
void
SetExpression
(
const
std
::
string
&
expression
);
/** Return the expression to be parsed */
std
::
string
GetExpression
()
const
{
return
m_Expression
;
}
std
::
string
GetExpression
()
const
;
void
SetNumberOfBands
(
unsigned
int
NbOfBands
)
{
void
SetNumberOfBands
(
unsigned
int
NbOfBands
);
m_NbOfBands
=
NbOfBands
;
std
::
ostringstream
varName
;
m_AImage
.
resize
(
NbOfBands
,
0.0
);
for
(
unsigned
int
i
=
0
;
i
<
NbOfBands
;
i
++
)
{
varName
<<
"b"
<<
i
+
1
;
m_Parser
->
DefineVar
(
varName
.
str
(),
&
(
m_AImage
[
i
]));
varName
.
str
(
""
);
}
// customized data
m_Parser
->
DefineVar
(
"intensity"
,
&
m_Intensity
);
}
/** Set the reference pixel used to compute the "spectralangle" parser variable */
void
SetSpectralAngleReferencePixel
(
const
PixelType
&
refPixel
);
/** Check the expression */
bool
CheckExpression
()
{
return
m_Parser
->
CheckExpr
();
}
bool
CheckExpression
();
protected:
MaskMuParserFunctor
()
{
m_Parser
=
ParserType
::
New
();
m_NbOfBands
=
0
;
}
MaskMuParserFunctor
();
virtual
~
MaskMuParserFunctor
()
{
}
virtual
~
MaskMuParserFunctor
();
private:
...
...
@@ -168,12 +113,19 @@ private:
//user defined variables
double
m_Intensity
;
double
m_SpectralAngle
;
}
;
}
// end of Functor namespace
PixelType
m_SpectralAngleReferencePixel
;
SpectralAngleFunctorType
m_SpectralAngleFunctor
;
};
}
// end of Functor namespace
}
//end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include
"otbMaskMuParserFunctor.txx"
#endif
#endif
This diff is collapsed.
Click to expand it.
Code/BasicFilters/otbMaskMuParserFunctor.txx
0 → 100644
+
139
−
0
View file @
a2378fb9
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbMaskMuParserFunctor_txx
#define __otbMaskMuParserFunctor_txx
#include "otbMaskMuParserFunctor.h"
namespace otb
{
namespace Functor
{
// constructor
template<class TInputPixel>
MaskMuParserFunctor<TInputPixel>::MaskMuParserFunctor()
: m_Parser(ParserType::New()),
m_NbOfBands(0),
m_ParserResult(0),
m_Intensity(0),
m_SpectralAngle(0)
{
}
// Destructor
template<class TInputPixel>
MaskMuParserFunctor<TInputPixel>::~MaskMuParserFunctor()
{
}
template<class TInputPixel>
bool MaskMuParserFunctor<TInputPixel>::operator()(const PixelType &p)
{
double value;
if (p.Size() != m_NbOfBands)
{
this->SetNumberOfBands(p.GetSize());
}
// we fill the buffer
for (unsigned int i = 0; i < m_NbOfBands; i++)
{
m_AImage[i] = static_cast<double> (p[i]);
}
// user defined variables
m_Intensity = 0.0;
for (unsigned int i = 0; i < m_NbOfBands; ++i)
{
m_Intensity += p[i];
}
m_Intensity = m_Intensity / (static_cast<double> (m_NbOfBands));
m_SpectralAngle = m_SpectralAngleFunctor(p, m_SpectralAngleReferencePixel);
value = m_Parser->Eval();
return static_cast<bool> (value);
}
template<class TInputPixel>
const std::map<std::string, Parser::ValueType*>&
MaskMuParserFunctor<TInputPixel>::GetVar() const
{
return this->m_Parser->GetVar();
}
template<class TInputPixel>
void
MaskMuParserFunctor<TInputPixel>::SetExpression(const std::string& expression)
{
m_Expression = expression;
m_Parser->SetExpr(m_Expression);
}
/** Return the expression to be parsed */
template<class TInputPixel>
std::string
MaskMuParserFunctor<TInputPixel>::GetExpression() const
{
return m_Expression;
}
template<class TInputPixel>
void
MaskMuParserFunctor<TInputPixel>::SetNumberOfBands(unsigned int NbOfBands)
{
m_NbOfBands = NbOfBands;
std::ostringstream varName;
m_AImage.resize(NbOfBands, 0.0);
for (unsigned int i = 0; i < NbOfBands; i++)
{
varName << "b" << i + 1;
m_Parser->DefineVar(varName.str(), &(m_AImage[i]));
varName.str("");
}
// customized data
m_Parser->DefineVar("intensity", &m_Intensity);
m_Parser->DefineVar("spectralangle", &m_SpectralAngle);
}
/** Set the reference pixel used to compute the "spectralangle" parser variable */
template<class TInputPixel>
void
MaskMuParserFunctor<TInputPixel>::SetSpectralAngleReferencePixel(const PixelType& refPixel)
{
m_SpectralAngleReferencePixel = refPixel;
}
/** Check the expression */
template<class TInputPixel>
bool
MaskMuParserFunctor<TInputPixel>::CheckExpression()
{
return m_Parser->CheckExpr();
}
} // end namespace Functor
} // end namespace otb
#endif
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