Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
otb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
273
Issues
273
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Main Repositories
otb
Commits
cd81060c
Commit
cd81060c
authored
Oct 15, 2014
by
Christophe Palmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: otbBandMathImageFilterX / otbParserX / otbParserXPlugins (all based on muParserX)
parent
b33fc2df
Changes
103
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
103 changed files
with
19299 additions
and
2 deletions
+19299
-2
CMake/FindMuParserX.cmake
CMake/FindMuParserX.cmake
+26
-0
CMake/ImportMuParserX.cmake
CMake/ImportMuParserX.cmake
+50
-0
CMake/otbIncludeDirectories.cmake
CMake/otbIncludeDirectories.cmake
+8
-0
CMakeLists.txt
CMakeLists.txt
+1
-0
Code/BasicFilters/CMakeLists.txt
Code/BasicFilters/CMakeLists.txt
+2
-1
Code/BasicFilters/otbBandMathImageFilterX.h
Code/BasicFilters/otbBandMathImageFilterX.h
+159
-0
Code/BasicFilters/otbBandMathImageFilterX.txx
Code/BasicFilters/otbBandMathImageFilterX.txx
+330
-0
Code/Common/CMakeLists.txt
Code/Common/CMakeLists.txt
+1
-1
Code/Common/otbParserX.cxx
Code/Common/otbParserX.cxx
+270
-0
Code/Common/otbParserX.h
Code/Common/otbParserX.h
+94
-0
Code/Common/otbParserXPlugins.h
Code/Common/otbParserXPlugins.h
+62
-0
Testing/Code/BasicFilters/CMakeLists.txt
Testing/Code/BasicFilters/CMakeLists.txt
+13
-0
Testing/Code/BasicFilters/otbBandMathImageFilterX.cxx
Testing/Code/BasicFilters/otbBandMathImageFilterX.cxx
+280
-0
Testing/Code/BasicFilters/otbBasicFiltersTests13.cxx
Testing/Code/BasicFilters/otbBasicFiltersTests13.cxx
+3
-0
Testing/Code/Common/CMakeLists.txt
Testing/Code/Common/CMakeLists.txt
+10
-0
Testing/Code/Common/otbCommonTests12.cxx
Testing/Code/Common/otbCommonTests12.cxx
+2
-0
Testing/Code/Common/otbParserXTest.cxx
Testing/Code/Common/otbParserXTest.cxx
+131
-0
Utilities/CMakeLists.txt
Utilities/CMakeLists.txt
+5
-0
Utilities/otbmuparserx/CMakeLists.txt
Utilities/otbmuparserx/CMakeLists.txt
+22
-0
Utilities/otbmuparserx/mpDefines.h
Utilities/otbmuparserx/mpDefines.h
+117
-0
Utilities/otbmuparserx/mpError.cpp
Utilities/otbmuparserx/mpError.cpp
+270
-0
Utilities/otbmuparserx/mpError.h
Utilities/otbmuparserx/mpError.h
+146
-0
Utilities/otbmuparserx/mpFuncCmplx.cpp
Utilities/otbmuparserx/mpFuncCmplx.cpp
+605
-0
Utilities/otbmuparserx/mpFuncCmplx.h
Utilities/otbmuparserx/mpFuncCmplx.h
+249
-0
Utilities/otbmuparserx/mpFuncCommon.cpp
Utilities/otbmuparserx/mpFuncCommon.cpp
+272
-0
Utilities/otbmuparserx/mpFuncCommon.h
Utilities/otbmuparserx/mpFuncCommon.h
+111
-0
Utilities/otbmuparserx/mpFuncMatrix.cpp
Utilities/otbmuparserx/mpFuncMatrix.cpp
+243
-0
Utilities/otbmuparserx/mpFuncMatrix.h
Utilities/otbmuparserx/mpFuncMatrix.h
+107
-0
Utilities/otbmuparserx/mpFuncNonCmplx.cpp
Utilities/otbmuparserx/mpFuncNonCmplx.cpp
+107
-0
Utilities/otbmuparserx/mpFuncNonCmplx.h
Utilities/otbmuparserx/mpFuncNonCmplx.h
+89
-0
Utilities/otbmuparserx/mpFuncStr.cpp
Utilities/otbmuparserx/mpFuncStr.cpp
+184
-0
Utilities/otbmuparserx/mpFuncStr.h
Utilities/otbmuparserx/mpFuncStr.h
+96
-0
Utilities/otbmuparserx/mpFwdDecl.h
Utilities/otbmuparserx/mpFwdDecl.h
+59
-0
Utilities/otbmuparserx/mpICallback.cpp
Utilities/otbmuparserx/mpICallback.cpp
+143
-0
Utilities/otbmuparserx/mpICallback.h
Utilities/otbmuparserx/mpICallback.h
+90
-0
Utilities/otbmuparserx/mpIOprt.cpp
Utilities/otbmuparserx/mpIOprt.cpp
+170
-0
Utilities/otbmuparserx/mpIOprt.h
Utilities/otbmuparserx/mpIOprt.h
+117
-0
Utilities/otbmuparserx/mpIPackage.cpp
Utilities/otbmuparserx/mpIPackage.cpp
+51
-0
Utilities/otbmuparserx/mpIPackage.h
Utilities/otbmuparserx/mpIPackage.h
+62
-0
Utilities/otbmuparserx/mpIPrecedence.h
Utilities/otbmuparserx/mpIPrecedence.h
+60
-0
Utilities/otbmuparserx/mpIToken.cpp
Utilities/otbmuparserx/mpIToken.cpp
+325
-0
Utilities/otbmuparserx/mpIToken.h
Utilities/otbmuparserx/mpIToken.h
+235
-0
Utilities/otbmuparserx/mpIValReader.cpp
Utilities/otbmuparserx/mpIValReader.cpp
+72
-0
Utilities/otbmuparserx/mpIValReader.h
Utilities/otbmuparserx/mpIValReader.h
+101
-0
Utilities/otbmuparserx/mpIValue.cpp
Utilities/otbmuparserx/mpIValue.cpp
+449
-0
Utilities/otbmuparserx/mpIValue.h
Utilities/otbmuparserx/mpIValue.h
+187
-0
Utilities/otbmuparserx/mpIfThenElse.cpp
Utilities/otbmuparserx/mpIfThenElse.cpp
+100
-0
Utilities/otbmuparserx/mpIfThenElse.h
Utilities/otbmuparserx/mpIfThenElse.h
+80
-0
Utilities/otbmuparserx/mpMatrix.h
Utilities/otbmuparserx/mpMatrix.h
+453
-0
Utilities/otbmuparserx/mpMatrixError.h
Utilities/otbmuparserx/mpMatrixError.h
+54
-0
Utilities/otbmuparserx/mpOprtBinAssign.cpp
Utilities/otbmuparserx/mpOprtBinAssign.cpp
+253
-0
Utilities/otbmuparserx/mpOprtBinAssign.h
Utilities/otbmuparserx/mpOprtBinAssign.h
+130
-0
Utilities/otbmuparserx/mpOprtBinCommon.cpp
Utilities/otbmuparserx/mpOprtBinCommon.cpp
+591
-0
Utilities/otbmuparserx/mpOprtBinCommon.h
Utilities/otbmuparserx/mpOprtBinCommon.h
+250
-0
Utilities/otbmuparserx/mpOprtCmplx.cpp
Utilities/otbmuparserx/mpOprtCmplx.cpp
+331
-0
Utilities/otbmuparserx/mpOprtCmplx.h
Utilities/otbmuparserx/mpOprtCmplx.h
+134
-0
Utilities/otbmuparserx/mpOprtIndex.cpp
Utilities/otbmuparserx/mpOprtIndex.cpp
+121
-0
Utilities/otbmuparserx/mpOprtIndex.h
Utilities/otbmuparserx/mpOprtIndex.h
+69
-0
Utilities/otbmuparserx/mpOprtMatrix.cpp
Utilities/otbmuparserx/mpOprtMatrix.cpp
+186
-0
Utilities/otbmuparserx/mpOprtMatrix.h
Utilities/otbmuparserx/mpOprtMatrix.h
+84
-0
Utilities/otbmuparserx/mpOprtNonCmplx.cpp
Utilities/otbmuparserx/mpOprtNonCmplx.cpp
+423
-0
Utilities/otbmuparserx/mpOprtNonCmplx.h
Utilities/otbmuparserx/mpOprtNonCmplx.h
+149
-0
Utilities/otbmuparserx/mpOprtPostfixCommon.cpp
Utilities/otbmuparserx/mpOprtPostfixCommon.cpp
+108
-0
Utilities/otbmuparserx/mpOprtPostfixCommon.h
Utilities/otbmuparserx/mpOprtPostfixCommon.h
+51
-0
Utilities/otbmuparserx/mpPackageCmplx.cpp
Utilities/otbmuparserx/mpPackageCmplx.cpp
+105
-0
Utilities/otbmuparserx/mpPackageCmplx.h
Utilities/otbmuparserx/mpPackageCmplx.h
+66
-0
Utilities/otbmuparserx/mpPackageCommon.cpp
Utilities/otbmuparserx/mpPackageCommon.cpp
+145
-0
Utilities/otbmuparserx/mpPackageCommon.h
Utilities/otbmuparserx/mpPackageCommon.h
+68
-0
Utilities/otbmuparserx/mpPackageMatrix.cpp
Utilities/otbmuparserx/mpPackageMatrix.cpp
+86
-0
Utilities/otbmuparserx/mpPackageMatrix.h
Utilities/otbmuparserx/mpPackageMatrix.h
+66
-0
Utilities/otbmuparserx/mpPackageNonCmplx.cpp
Utilities/otbmuparserx/mpPackageNonCmplx.cpp
+104
-0
Utilities/otbmuparserx/mpPackageNonCmplx.h
Utilities/otbmuparserx/mpPackageNonCmplx.h
+67
-0
Utilities/otbmuparserx/mpPackageStr.cpp
Utilities/otbmuparserx/mpPackageStr.cpp
+85
-0
Utilities/otbmuparserx/mpPackageStr.h
Utilities/otbmuparserx/mpPackageStr.h
+67
-0
Utilities/otbmuparserx/mpPackageUnit.cpp
Utilities/otbmuparserx/mpPackageUnit.cpp
+123
-0
Utilities/otbmuparserx/mpPackageUnit.h
Utilities/otbmuparserx/mpPackageUnit.h
+84
-0
Utilities/otbmuparserx/mpParser.cpp
Utilities/otbmuparserx/mpParser.cpp
+95
-0
Utilities/otbmuparserx/mpParser.h
Utilities/otbmuparserx/mpParser.h
+66
-0
Utilities/otbmuparserx/mpParserBase.cpp
Utilities/otbmuparserx/mpParserBase.cpp
+1324
-0
Utilities/otbmuparserx/mpParserBase.h
Utilities/otbmuparserx/mpParserBase.h
+229
-0
Utilities/otbmuparserx/mpParserMessageProvider.cpp
Utilities/otbmuparserx/mpParserMessageProvider.cpp
+182
-0
Utilities/otbmuparserx/mpParserMessageProvider.h
Utilities/otbmuparserx/mpParserMessageProvider.h
+61
-0
Utilities/otbmuparserx/mpRPN.cpp
Utilities/otbmuparserx/mpRPN.cpp
+191
-0
Utilities/otbmuparserx/mpRPN.h
Utilities/otbmuparserx/mpRPN.h
+80
-0
Utilities/otbmuparserx/mpScriptTokens.cpp
Utilities/otbmuparserx/mpScriptTokens.cpp
+78
-0
Utilities/otbmuparserx/mpScriptTokens.h
Utilities/otbmuparserx/mpScriptTokens.h
+72
-0
Utilities/otbmuparserx/mpStack.h
Utilities/otbmuparserx/mpStack.h
+158
-0
Utilities/otbmuparserx/mpTest.cpp
Utilities/otbmuparserx/mpTest.cpp
+1780
-0
Utilities/otbmuparserx/mpTest.h
Utilities/otbmuparserx/mpTest.h
+109
-0
Utilities/otbmuparserx/mpTokenReader.cpp
Utilities/otbmuparserx/mpTokenReader.cpp
+1018
-0
Utilities/otbmuparserx/mpTokenReader.h
Utilities/otbmuparserx/mpTokenReader.h
+141
-0
Utilities/otbmuparserx/mpTypes.h
Utilities/otbmuparserx/mpTypes.h
+411
-0
Utilities/otbmuparserx/mpValReader.cpp
Utilities/otbmuparserx/mpValReader.cpp
+347
-0
Utilities/otbmuparserx/mpValReader.h
Utilities/otbmuparserx/mpValReader.h
+142
-0
Utilities/otbmuparserx/mpValue.cpp
Utilities/otbmuparserx/mpValue.cpp
+830
-0
Utilities/otbmuparserx/mpValue.h
Utilities/otbmuparserx/mpValue.h
+147
-0
Utilities/otbmuparserx/mpValueCache.cpp
Utilities/otbmuparserx/mpValueCache.cpp
+109
-0
Utilities/otbmuparserx/mpValueCache.h
Utilities/otbmuparserx/mpValueCache.h
+77
-0
Utilities/otbmuparserx/mpVariable.cpp
Utilities/otbmuparserx/mpVariable.cpp
+399
-0
Utilities/otbmuparserx/mpVariable.h
Utilities/otbmuparserx/mpVariable.h
+117
-0
Utilities/otbmuparserx/suSortPred.h
Utilities/otbmuparserx/suSortPred.h
+69
-0
Utilities/otbmuparserx/suStringTokens.h
Utilities/otbmuparserx/suStringTokens.h
+180
-0
Utilities/otbmuparserx/utGeneric.h
Utilities/otbmuparserx/utGeneric.h
+68
-0
No files found.
CMake/FindMuParserX.cmake
0 → 100644
View file @
cd81060c
# - Find MuParserX
# Find the native MuParser includes and library
#
# MUPARSER_FOUND - True if MuParser found.
# MUPARSER_INCLUDE_DIR - where to find tinyxml.h, etc.
# MUPARSER_LIBRARIES - List of libraries when using MuParser.
#
if
(
MUPARSERX_INCLUDE_DIR
)
# Already in cache, be silent
set
(
MuParserX_FIND_QUIETLY TRUE
)
endif
()
find_path
(
MUPARSERX_INCLUDE_DIR mpParser.h
PATH_SUFFIXES mpParser
)
find_library
(
MUPARSERX_LIBRARIES
NAMES muparserx
PATH_SUFFIXES muparserx
)
# handle the QUIETLY and REQUIRED arguments and set MUPARSER_FOUND to TRUE if
# all listed variables are TRUE
include
(
FindPackageHandleStandardArgs
)
FIND_PACKAGE_HANDLE_STANDARD_ARGS
(
MuParserX DEFAULT_MSG MUPARSERX_LIBRARIES MUPARSERX_INCLUDE_DIR
)
mark_as_advanced
(
MUPARSERX_INCLUDE_DIR MUPARSERX_LIBRARIES
)
CMake/ImportMuParserX.cmake
0 → 100644
View file @
cd81060c
message
(
STATUS
"Importing MuParserX..."
)
find_package
(
MuParserX
)
if
(
MUPARSERX_FOUND
)
option
(
OTB_USE_EXTERNAL_MUPARSERX
"Use external MuParserX library."
ON
)
else
()
option
(
OTB_USE_EXTERNAL_MUPARSERX
"Use external MuParserX library."
OFF
)
endif
()
mark_as_advanced
(
OTB_USE_EXTERNAL_MUPARSERX
)
if
(
OTB_USE_EXTERNAL_MUPARSERX
)
if
(
MUPARSERX_FOUND
)
# Starting with muparser 2.0.0,
# intrinsic operators "and", "or", "xor" have been removed
# and intrinsic operators "&&" and "||" have been introduced as replacements
set
(
CMAKE_REQUIRED_INCLUDES
${
MUPARSERX_INCLUDE_DIR
}
)
set
(
CMAKE_REQUIRED_LIBRARIES
${
MUPARSERX_LIBRARIES
}
)
unset
(
CMAKE_REQUIRED_FLAGS
)
unset
(
CMAKE_REQUIRED_DEFINES
)
#file(READ ${CMAKE_CURRENT_SOURCE_DIR}/CMake/otbTestMuParserHasCxxLogicalOperators.cxx
# OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS_SOURCEFILE)
#check_cxx_source_runs(
# "${OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS_SOURCEFILE}"
# OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS
# )
unset
(
CMAKE_REQUIRED_INCLUDES
)
unset
(
CMAKE_REQUIRED_LIBRARIES
)
unset
(
CMAKE_REQUIRED_FLAGS
)
unset
(
CMAKE_REQUIRED_DEFINES
)
#if(OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS)
# message(STATUS " MuParser version is >= 2.0.0 : "
# "uses '&&' and '||' logical operators, and C++ like "
# "ternary if-then-else operator")
#else()
# message(STATUS " MuParser version is < 2.0.0 : "
# "uses 'and' and 'or' logical operators, and ternary "
# "operator 'if( ; ; )'")
#endif()
else
()
message
(
FATAL_ERROR
"Can't build OTB without MuParserX. Instal it "
"on your system, or disable the option "
"OTB_USE_EXTERNAL_MUPARSERX to use internal one"
)
endif
()
else
()
set
(
MUPARSERX_LIBRARIES otbmuparserx
)
#unset(OTB_MUPARSER_HAS_CXX_LOGICAL_OPERATORS) # internal version is < 2.0.0
message
(
STATUS
" Using MuParserX internal version "
)
endif
()
CMake/otbIncludeDirectories.cmake
View file @
cd81060c
...
...
@@ -95,6 +95,14 @@ else()
${
OTB_SOURCE_DIR
}
/Utilities/otbmuparser
)
endif
()
if
(
OTB_USE_EXTERNAL_MUPARSERX
)
set
(
OTB_INCLUDE_DIRS_BUILD_TREE
${
OTB_INCLUDE_DIRS_BUILD_TREE
}
${
MUPARSERX_INCLUDE_DIR
}
)
else
()
set
(
OTB_INCLUDE_DIRS_BUILD_TREE
${
OTB_INCLUDE_DIRS_BUILD_TREE
}
${
OTB_SOURCE_DIR
}
/Utilities/otbmuparserx
)
endif
()
if
(
OTB_USE_EXTERNAL_LIBKML
)
set
(
OTB_INCLUDE_DIRS_BUILD_TREE
${
OTB_INCLUDE_DIRS_BUILD_TREE
}
${
LIBKML_INCLUDE_DIR
}
)
...
...
CMakeLists.txt
View file @
cd81060c
...
...
@@ -216,6 +216,7 @@ include(ImportQt4)
include
(
ImportSiftFast
)
include
(
ImportTinyXML
)
include
(
ImportMuParser
)
include
(
ImportMuParserX
)
include
(
ImportLibKML
)
include
(
ImportOpenCV
)
#-----------------------------------------------------------------------------
...
...
Code/BasicFilters/CMakeLists.txt
View file @
cd81060c
...
...
@@ -3,8 +3,9 @@
file
(
GLOB OTBBasicFilters_SRCS
"*.cxx"
)
add_library
(
OTBBasicFilters
${
OTBBasicFilters_SRCS
}
)
target_link_libraries
(
OTBBasicFilters OTBCommon otbedison
${
MUPARSER_LIBRARIES
}
)
target_link_libraries
(
OTBBasicFilters OTBCommon otbedison
${
MUPARSER_LIBRARIES
}
${
MUPARSERX_LIBRARIES
}
)
# Explicit link to fftw is required
# The link of ITKFFT to fftw does not propagate well :
# in an external project using OTB with FFT features,
...
...
Code/BasicFilters/otbBandMathImageFilterX.h
0 → 100644
View file @
cd81060c
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.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 __otbBandMathImageFilterX_h
#define __otbBandMathImageFilterX_h
#include "itkInPlaceImageFilter.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkArray.h"
#include "otbParserX.h"
namespace
otb
{
/** \class BandMathImageFilterX
* \brief Performs a mathematical operation on the input images
* according to the formula specified by the user.
*
* This filter is based on the mathematical parser library muParser.
* The built in functions and operators list is available at:
* http://muparser.sourceforge.net/mup_features.html#idDef2
*
* OTB additional functions:
* ndvi(r, niri)
*
* OTB additional constants:
* e - log2e - log10e - ln2 - ln10 - pi - euler
*
* In order to use this filter, at least one input image is to be
* set. An associated variable name can be specified or not by using
* the corresponding SetNthInput method. For the nth input image, if
* no associated variable name has been spefified, a default variable
* name is given by concatenating the letter "b" (for band) and the
* corresponding input index.
* Next step is to set the expression according to the variable
* names. For example, in the default case with three input images the
* following expression is valid :
* "ndvi(b1, b2)*b3"
*
* As an additional functionality, the filter also granted access to
* indexes information under special virtual bands named idxX, idxY
* for the images indexes and idxPhyX, idxPhyY for the physical
* indexes.
* It allows the user to perform, for example a spatial processing
* aiming to suppress a determined area :
* "if(sqrt((idxPhyX-105.3)*(idxPhyX-105.3)+
* (idxPhyY-207.1)*(idxPhyY-207.1))>100, b1, 0)"
* This expression replace the physical zone around the point of
* physical index (105.3; 207.1) by a black area
* This functionality assumes that all the band involved have the same
* spacing and origin.
*
*
* \sa Parser
*
* \ingroup Streamed
* \ingroup Threaded
*/
template
<
class
TImage
>
class
ITK_EXPORT
BandMathImageFilterX
:
public
itk
::
InPlaceImageFilter
<
TImage
>
{
public:
/** Standard class typedefs. */
typedef
BandMathImageFilterX
<
TImage
>
Self
;
typedef
itk
::
InPlaceImageFilter
<
TImage
>
Superclass
;
typedef
itk
::
SmartPointer
<
Self
>
Pointer
;
typedef
itk
::
SmartPointer
<
const
Self
>
ConstPointer
;
/** Method for creation through the object factory. */
itkNewMacro
(
Self
);
/** Run-time type information (and related methods). */
itkTypeMacro
(
BandMathImageFilterX
,
InPlaceImageFilter
);
/** Some convenient typedefs. */
typedef
TImage
ImageType
;
typedef
typename
ImageType
::
ConstPointer
ImagePointer
;
typedef
typename
ImageType
::
RegionType
ImageRegionType
;
typedef
typename
ImageType
::
PixelType
PixelType
;
typedef
typename
ImageType
::
IndexType
IndexType
;
typedef
typename
ImageType
::
PointType
OrigineType
;
typedef
typename
ImageType
::
SpacingType
SpacingType
;
typedef
ParserX
ParserType
;
typedef
typename
ParserType
::
ValueType
ValueType
;
/** Set the nth filter input with or without a specified associated variable name */
void
SetNthInput
(
unsigned
int
idx
,
const
ImageType
*
image
);
void
SetNthInput
(
unsigned
int
idx
,
const
ImageType
*
image
,
const
std
::
string
&
varName
);
/** Change the nth filter input associated variable name */
void
SetNthInputName
(
unsigned
int
idx
,
const
std
::
string
&
expression
);
/** Set the expression to be parsed */
void
SetExpression
(
const
std
::
string
&
expression
);
/** Return the expression to be parsed */
std
::
string
GetExpression
()
const
;
/** Return the nth filter input associated variable name */
std
::
string
GetNthInputName
(
unsigned
int
idx
)
const
;
/** Return a pointer on the nth filter input */
ImageType
*
GetNthInput
(
unsigned
int
idx
);
protected
:
BandMathImageFilterX
();
virtual
~
BandMathImageFilterX
();
virtual
void
PrintSelf
(
std
::
ostream
&
os
,
itk
::
Indent
indent
)
const
;
void
BeforeThreadedGenerateData
();
void
ThreadedGenerateData
(
const
ImageRegionType
&
outputRegionForThread
,
itk
::
ThreadIdType
threadId
);
void
AfterThreadedGenerateData
();
private
:
BandMathImageFilterX
(
const
Self
&
);
//purposely not implemented
void
operator
=
(
const
Self
&
);
//purposely not implemented
std
::
string
m_Expression
;
std
::
vector
<
ParserType
::
Pointer
>
m_VParser
;
std
::
vector
<
std
::
vector
<
ValueType
>
>
m_AImage
;
std
::
vector
<
std
::
string
>
m_VVarName
;
unsigned
int
m_NbVar
;
SpacingType
m_Spacing
;
OrigineType
m_Origin
;
long
m_UnderflowCount
;
long
m_OverflowCount
;
itk
::
Array
<
long
>
m_ThreadUnderflow
;
itk
::
Array
<
long
>
m_ThreadOverflow
;
};
}
//end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbBandMathImageFilterX.txx"
#endif
#endif
Code/BasicFilters/otbBandMathImageFilterX.txx
0 → 100644
View file @
cd81060c
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
Some parts of this code are derived from ITK. See ITKCopyright.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 __otbBandMathImageFilterX_txx
#define __otbBandMathImageFilterX_txx
#include "otbBandMathImageFilterX.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkNumericTraits.h"
#include "itkProgressReporter.h"
#include "otbMacro.h"
#include <iostream>
#include <string>
namespace otb
{
/** Constructor */
template <class TImage>
BandMathImageFilterX<TImage>
::BandMathImageFilterX()
{
//This number will be incremented each time an image
//is added over the one minimumrequired
this->SetNumberOfRequiredInputs( 1 );
this->InPlaceOff();
m_UnderflowCount = 0;
m_OverflowCount = 0;
m_ThreadUnderflow.SetSize(1);
m_ThreadOverflow.SetSize(1);
}
/** Destructor */
template <class TImage>
BandMathImageFilterX<TImage>
::~BandMathImageFilterX()
{
}
template <class TImage>
void BandMathImageFilterX<TImage>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os << indent << "Expression: " << m_Expression << std::endl;
os << indent << "Computed values follow:" << std::endl;
os << indent << "UnderflowCount: " << m_UnderflowCount << std::endl;
os << indent << "OverflowCount: " << m_OverflowCount << std::endl;
os << indent << "itk::NumericTraits<PixelType>::NonpositiveMin() : "
<< itk::NumericTraits<PixelType>::NonpositiveMin() << std::endl;
os << indent << "itk::NumericTraits<PixelType>::max() : "
<< itk::NumericTraits<PixelType>::max() << std::endl;
}
template <class TImage>
void BandMathImageFilterX<TImage>
::SetNthInput(unsigned int idx, const ImageType * image)
{
this->SetInput(idx, const_cast<TImage *>( image ));
unsigned int nbInput = this->GetNumberOfInputs();
m_VVarName.resize(nbInput+4);
std::ostringstream varName;
varName << "b" << nbInput;
m_VVarName[idx] = varName.str();
m_VVarName[idx+1] = "idxX";
m_VVarName[idx+2] = "idxY";
m_VVarName[idx+3] = "idxPhyX";
m_VVarName[idx+4] = "idxPhyY";
}
template <class TImage>
void BandMathImageFilterX<TImage>
::SetNthInput(unsigned int idx, const ImageType * image, const std::string& varName)
{
this->SetInput(idx, const_cast<TImage *>( image ));
m_VVarName.resize(this->GetNumberOfInputs()+4);
m_VVarName[idx] = varName;
m_VVarName[idx+1] = "idxX";
m_VVarName[idx+2] = "idxY";
m_VVarName[idx+3] = "idxPhyX";
m_VVarName[idx+4] = "idxPhyY";
}
template <class TImage>
void BandMathImageFilterX<TImage>
::SetNthInputName(unsigned int idx, const std::string& varName)
{
m_VVarName[idx] = varName;
}
template <typename TImage>
TImage * BandMathImageFilterX<TImage>
::GetNthInput(unsigned int idx)
{
return const_cast<TImage *>(this->GetInput(idx));
}
template< typename TImage >
void BandMathImageFilterX<TImage>
::SetExpression(const std::string& expression)
{
if (m_Expression != expression)
m_Expression = expression;
this->Modified();
}
template< typename TImage >
std::string BandMathImageFilterX<TImage>
::GetExpression() const
{
return m_Expression;
}
template< typename TImage >
std::string BandMathImageFilterX<TImage>
::GetNthInputName(unsigned int idx) const
{
return m_VVarName.at(idx);
}
template< typename TImage >
void BandMathImageFilterX<TImage>
::BeforeThreadedGenerateData()
{
typename std::vector<ParserType::Pointer>::iterator itParser;
typename std::vector< std::vector<PixelType> >::iterator itVImage;
unsigned int nbThreads = this->GetNumberOfThreads();
unsigned int nbInputImages = this->GetNumberOfInputs();
unsigned int nbAccessIndex = 4; //to give access to image and physical index
unsigned int i, j;
unsigned int inputSize[2];
std::vector< std::string > tmpIdxVarNames;
tmpIdxVarNames.resize(nbAccessIndex);
tmpIdxVarNames.at(0) = "idxX";
tmpIdxVarNames.at(1) = "idxY";
tmpIdxVarNames.at(2) = "idxPhyX";
tmpIdxVarNames.at(3) = "idxPhyY";
// Check if input image dimensions matches
inputSize[0] = this->GetNthInput(0)->GetLargestPossibleRegion().GetSize(0);
inputSize[1] = this->GetNthInput(0)->GetLargestPossibleRegion().GetSize(1);
for(unsigned int p = 1; p < nbInputImages; p++)
{
if((inputSize[0] != this->GetNthInput(p)->GetLargestPossibleRegion().GetSize(0))
|| (inputSize[1] != this->GetNthInput(p)->GetLargestPossibleRegion().GetSize(1)))
{
itkExceptionMacro(<< "Input images must have the same dimensions." << std::endl
<< "band #1 is [" << inputSize[0] << ";" << inputSize[1] << "]" << std::endl
<< "band #" << p+1 << " is ["
<< this->GetNthInput(p)->GetLargestPossibleRegion().GetSize(0) << ";"
<< this->GetNthInput(p)->GetLargestPossibleRegion().GetSize(1) << "]");
}
}
// Store images specs
m_Spacing = this->GetNthInput(0)->GetSpacing();
m_Origin = this->GetNthInput(0)->GetOrigin();
// Allocate and initialize the thread temporaries
m_ThreadUnderflow.SetSize(nbThreads);
m_ThreadUnderflow.Fill(0);
m_ThreadOverflow.SetSize(nbThreads);
m_ThreadOverflow.Fill(0);
m_VParser.resize(nbThreads);
m_AImage.resize(nbThreads);
m_NbVar = nbInputImages+nbAccessIndex;
m_VVarName.resize(m_NbVar);
for(itParser = m_VParser.begin(); itParser < m_VParser.end(); itParser++)
{
*itParser = ParserType::New();
}
for(i = 0; i < nbThreads; ++i)
{
m_AImage.at(i).resize(m_NbVar);
m_VParser.at(i)->SetExpr(m_Expression);
for(j=0; j < nbInputImages; ++j)
{
m_VParser.at(i)->DefineVar(m_VVarName.at(j), &m_AImage.at(i).at(j));
}
for(j=nbInputImages; j < nbInputImages+nbAccessIndex; ++j)
{
m_VVarName.at(j) = tmpIdxVarNames.at(j-nbInputImages);
m_VParser.at(i)->DefineVar(m_VVarName.at(j), &m_AImage.at(i).at(j));
}
}
}
template< typename TImage >
void BandMathImageFilterX<TImage>
::AfterThreadedGenerateData()
{
unsigned int nbThreads = this->GetNumberOfThreads();
unsigned int i;
m_UnderflowCount = 0;
m_OverflowCount = 0;
// Accumulate counts for each thread
for(i = 0; i < nbThreads; ++i)
{
m_UnderflowCount += m_ThreadUnderflow[i];
m_OverflowCount += m_ThreadOverflow[i];
}
if((m_UnderflowCount != 0) || (m_OverflowCount!=0))
otbWarningMacro(<< std::endl
<< "The Following Parsed Expression : "
<< this->GetExpression() << std::endl
<< "Generated " << m_UnderflowCount << " Underflow(s) "
<< "And " << m_OverflowCount << " Overflow(s) " << std::endl
<< "The Parsed Expression, The Inputs And The Output "
<< "Type May Be Incompatible !");
}
template< typename TImage >
void BandMathImageFilterX<TImage>
::ThreadedGenerateData(const ImageRegionType& outputRegionForThread,
itk::ThreadIdType threadId)
{
double value;
unsigned int j;
unsigned int nbInputImages = this->GetNumberOfInputs();
typedef itk::ImageRegionConstIterator<TImage> ImageRegionConstIteratorType;
std::vector< ImageRegionConstIteratorType > Vit;
Vit.resize(nbInputImages);
for(j=0; j < nbInputImages; ++j)
{
Vit[j] = ImageRegionConstIteratorType (this->GetNthInput(j), outputRegionForThread);
}
itk::ImageRegionIterator<TImage> ot (this->GetOutput(), outputRegionForThread);
// support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
while(!Vit.at(0).IsAtEnd())
{
for(j=0; j < nbInputImages; ++j)
{
m_AImage.at(threadId).at(j) = static_cast<double>(Vit.at(j).Get());
}
// Image Indexes
for(j=0; j < 2; ++j)
{
m_AImage.at(threadId).at(nbInputImages+j) = static_cast<double>(Vit.at(0).GetIndex()[j]);
}
for(j=0; j < 2; ++j)
{
m_AImage.at(threadId).at(nbInputImages+2+j) = static_cast<double>(m_Origin[j])
+static_cast<double>(Vit.at(0).GetIndex()[j]) * static_cast<double>(m_Spacing[j]);
}
try
{
value = m_VParser.at(threadId)->Eval().GetFloat();
}
catch(itk::ExceptionObject& err)
{
itkExceptionMacro(<< err);
}
// Case value is equal to -inf or inferior to the minimum value
// allowed by the pixelType cast
if (value < double(itk::NumericTraits<PixelType>::NonpositiveMin()))
{
ot.Set(itk::NumericTraits<PixelType>::NonpositiveMin());
m_ThreadUnderflow[threadId]++;
}
// Case value is equal to inf or superior to the maximum value
// allowed by the pixelType cast
else if (value > double(itk::NumericTraits<PixelType>::max()))
{
ot.Set(itk::NumericTraits<PixelType>::max());
m_ThreadOverflow[threadId]++;
}
else
{
ot.Set(static_cast<PixelType>(value));
}
for(j=0; j < nbInputImages; ++j)
{
++(Vit.at(j));
}
++ot;
progress.CompletedPixel();
}
}
}// end namespace otb
#endif
Code/Common/CMakeLists.txt
View file @
cd81060c
...
...
@@ -12,7 +12,7 @@ add_library(OTBCommon ${OTBCommon_SRCS})
# PROPERTIES
# LINK_INTERFACE_LIBRARIES ""
#)