Commit 2e89a95d authored by OTB Bot's avatar OTB Bot
Browse files

STYLE

No related merge requests found
Showing with 308 additions and 308 deletions
+308 -308
......@@ -29,14 +29,14 @@ namespace Wrapper
/** \class AddProcessToWatchEvent
* \brief This class implements an event storing a pointer to
* itk::ProcessObject and a string describing the process.
*
*
*/
class ITK_EXPORT AddProcessToWatchEvent: public itk::EventObject
{
public:
typedef AddProcessToWatchEvent Self;
typedef itk::EventObject Superclass;
typedef AddProcessToWatchEvent Self;
typedef itk::EventObject Superclass;
AddProcessToWatchEvent(){}
AddProcessToWatchEvent(const Self& s) :itk::EventObject(s){};
......@@ -66,7 +66,7 @@ public:
/** Virtual pure method to implement */
virtual itk::EventObject* MakeObject() const
{
return new Self;
return new Self;
}
virtual const char* GetEventName() const
......@@ -75,7 +75,7 @@ public:
}
virtual bool CheckEvent(const itk::EventObject* e) const
{
return dynamic_cast<const Self*>(e);
return dynamic_cast<const Self*>(e);
}
private:
......
/*=========================================================================
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 __otbSpectralResponse_txx
#define __otbSpectralResponse_txx
#include "itkNumericTraits.h"
#include "otbSpectralResponse.h"
#include <algorithm>
namespace otb
{
template <class TPrecision, class TValuePrecision>
SpectralResponse<TPrecision, TValuePrecision>
::SpectralResponse()
{
m_SensitivityThreshold = 0.01;
m_IntervalComputed = false;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::Load(const std::string & filename, ValuePrecisionType coefNormalization)
{
//Parse JPL file spectral response (ASCII file)
//Begin line 27
std::ifstream fin(filename.c_str());
if ( fin.fail() ) {
itkExceptionMacro(<<"Error opening file" << filename);
}
int NumLigne = 26; // Go to the line 27
//Ignore first 26th lines which are metadatas informations
for (int i = 0; i < NumLigne; ++i)
fin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
while(! fin.eof() )
{
//For each
std::pair<TPrecision, TValuePrecision > currentPair;
fin >> currentPair.first;
fin >> currentPair.second;
currentPair.second = currentPair.second / coefNormalization;
if ( currentPair.first != itk::NumericTraits<TPrecision>::ZeroValue() && currentPair.second != itk::NumericTraits<TValuePrecision>::ZeroValue() )
//Add not null pair of values to the vector
m_Response.push_back(currentPair);
}
fin.close();
//Sort the vector using the specific functor sort_pair
std::sort(m_Response.begin(), m_Response.end(), sort_pair());
m_IntervalComputed = false;
}
template <class TPrecision, class TValuePrecision>
bool
SpectralResponse<TPrecision, TValuePrecision>
::Clear()
{
m_Response.clear();
m_IntervalComputed = false;
return true;
}
template <class TPrecision, class TValuePrecision>
unsigned int
SpectralResponse<TPrecision, TValuePrecision>
::Size() const
{
return m_Response.size();
}
template <class TPrecision, class TValuePrecision>
inline typename SpectralResponse<TPrecision, TValuePrecision>::ValuePrecisionType
SpectralResponse<TPrecision, TValuePrecision>
::operator()(const PrecisionType & lambda)
{
//Suppose that the vector is sorted
//Guess a starting lambda
if (m_Response.size() <= 1)
{
itkExceptionMacro(<<"ERROR spectral response need at least 2 value to perform interpolation.");
}
typename VectorPairType::const_iterator beg = m_Response.begin();
typename VectorPairType::const_iterator last = m_Response.end();
--last;
PrecisionType lambdaMin = (*beg).first;
PrecisionType lambdaMax = (*last).first;
if (lambda <= lambdaMin) return lambdaMin;
if (lambda >= lambdaMax) return lambdaMax;
unsigned int lambdaPosGuess = static_cast<unsigned int> ((lambda - lambdaMin) / (lambdaMax - lambdaMin)
* m_Response.size());
//this test should be always true since
// lambda<=lambdaMin and lambda>=lambdaMax have been just tested
assert(!(lambdaPosGuess < 0) || (lambdaPosGuess > m_Response.size()));
// TODO JGU : test algorithm
//lambdaPosGuess calculus have been modified (initially lambdaPosGuess = static_cast<unsigned int> ((lambda - lambdaMin) / (lambdaMax - lambdaMin)
//* m_Response.size() -1). lambdaPosGuess = 0 for lambda contained in m_Response first bin
// thus lambdaPosGuess -1 = -1 for those values !!!!
for (typename VectorPairType::const_iterator it = beg + lambdaPosGuess; it <= last; ++it)
{
// if the guess was too high
if ((*it).first >= lambda)
{
return (*it).second;
}
// if the guess is just right
else
if ((*it).first < lambda && (*(it + 1)).first >= lambda)
{
return ((*it).second + (*(it + 1)).second) / 2.0;
}
}
//Value not available
return 0;
}
template <class TPrecision, class TValuePrecision>
typename SpectralResponse<TPrecision, TValuePrecision>::ImagePointerType
SpectralResponse<TPrecision, TValuePrecision>
::GetImage(ImagePointerType image) const
{
typename ImageType::IndexType start;
start[0] = 0;
start[1] = 0;
typename ImageType::SizeType size;
// size[0] = this->Size();
size[0] = 1;
size[1] = 1;
typename ImageType::PointType origin;
origin[0] = 0;
origin[1] = 0;
typename ImageType::SpacingType spacing;
spacing[0] = 1;
spacing[1] = 1;
typename ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
image->SetRegions( region );
image->SetNumberOfComponentsPerPixel( this->Size() );
image->Allocate();
typename ImageType::IndexType idx;
typename ImageType::PixelType pixel;
pixel.SetSize(this->Size());
for ( unsigned int j=0; j<this->Size(); ++j )
{
pixel[j]=m_Response[j].second;
}
idx[0]=0;
idx[1]=0;
image->SetPixel(idx, pixel);
return image;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::SetFromImage(ImagePointerType image)
{
typename ImageType::IndexType idx;
idx[0]=0;
idx[1]=0;
for ( unsigned int j=0; j<this->Size(); ++j )
{
m_Response[j].second = image->GetPixel(idx)[j];
}
m_IntervalComputed = false;
}
template <class TPrecision, class TValuePrecision>
typename SpectralResponse<TPrecision, TValuePrecision>::FilterFunctionValuesPointerType
SpectralResponse<TPrecision, TValuePrecision>
::GetFilterFunctionValues(double step) const
{
//Assume that the SR is sorted
typename FilterFunctionValuesType::ValuesVectorType valuesVector;
for (double i =m_Response.front()->first; i <= m_Response.back()->first; i+=step)
{
valuesVector.push_back=(*this)(i);
}
FilterFunctionValuesPointerType functionValues = FilterFunctionValuesType::New();
functionValues->SetFilterFunctionValues(valuesVector);
functionValues->SetMinSpectralValue(m_Response.front().first);
functionValues->SetMaxSpectralValue(m_Response.back().first);
functionValues->SetUserStep( step );
return functionValues;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::ComputeInterval()
{
typename VectorPairType::const_iterator it = m_Response.begin();
while ((*it).second <= m_SensitivityThreshold)
{
++it;
if (it == m_Response.end())
{
m_Interval.first = static_cast<TPrecision> (0.0);
m_Interval.second = static_cast<TPrecision> (0.0);
m_IntervalComputed = true;
return;
}
}
m_Interval.first = (*it).first;
while ((*it).second > m_SensitivityThreshold)
{
if (it == m_Response.end())
{
m_Interval.second = (*it).first;
return;
}
++it;
}
m_Interval.second = (*it).first;
m_IntervalComputed = true;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os<<std::endl;
os <<indent << "[Wavelength (micrometers), Reflectance (percent)]" << std::endl;
for(typename VectorPairType::const_iterator it = m_Response.begin(); it != m_Response.end(); ++it)
{
os <<indent << "Num "<< it - m_Response.begin() << ": [" << (*it).first << ","<< (*it).second << "]" << std::endl;
}
}
} // end namespace otb
#endif
/*=========================================================================
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 __otbSpectralResponse_txx
#define __otbSpectralResponse_txx
#include "itkNumericTraits.h"
#include "otbSpectralResponse.h"
#include <algorithm>
namespace otb
{
template <class TPrecision, class TValuePrecision>
SpectralResponse<TPrecision, TValuePrecision>
::SpectralResponse()
{
m_SensitivityThreshold = 0.01;
m_IntervalComputed = false;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::Load(const std::string & filename, ValuePrecisionType coefNormalization)
{
//Parse JPL file spectral response (ASCII file)
//Begin line 27
std::ifstream fin(filename.c_str());
if ( fin.fail() ) {
itkExceptionMacro(<<"Error opening file" << filename);
}
int NumLigne = 26; // Go to the line 27
//Ignore first 26th lines which are metadatas informations
for (int i = 0; i < NumLigne; ++i)
fin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
while(! fin.eof() )
{
//For each
std::pair<TPrecision, TValuePrecision > currentPair;
fin >> currentPair.first;
fin >> currentPair.second;
currentPair.second = currentPair.second / coefNormalization;
if ( currentPair.first != itk::NumericTraits<TPrecision>::ZeroValue() && currentPair.second != itk::NumericTraits<TValuePrecision>::ZeroValue() )
//Add not null pair of values to the vector
m_Response.push_back(currentPair);
}
fin.close();
//Sort the vector using the specific functor sort_pair
std::sort(m_Response.begin(), m_Response.end(), sort_pair());
m_IntervalComputed = false;
}
template <class TPrecision, class TValuePrecision>
bool
SpectralResponse<TPrecision, TValuePrecision>
::Clear()
{
m_Response.clear();
m_IntervalComputed = false;
return true;
}
template <class TPrecision, class TValuePrecision>
unsigned int
SpectralResponse<TPrecision, TValuePrecision>
::Size() const
{
return m_Response.size();
}
template <class TPrecision, class TValuePrecision>
inline typename SpectralResponse<TPrecision, TValuePrecision>::ValuePrecisionType
SpectralResponse<TPrecision, TValuePrecision>
::operator()(const PrecisionType & lambda)
{
//Suppose that the vector is sorted
//Guess a starting lambda
if (m_Response.size() <= 1)
{
itkExceptionMacro(<<"ERROR spectral response need at least 2 value to perform interpolation.");
}
typename VectorPairType::const_iterator beg = m_Response.begin();
typename VectorPairType::const_iterator last = m_Response.end();
--last;
PrecisionType lambdaMin = (*beg).first;
PrecisionType lambdaMax = (*last).first;
if (lambda <= lambdaMin) return lambdaMin;
if (lambda >= lambdaMax) return lambdaMax;
unsigned int lambdaPosGuess = static_cast<unsigned int> ((lambda - lambdaMin) / (lambdaMax - lambdaMin)
* m_Response.size());
//this test should be always true since
// lambda<=lambdaMin and lambda>=lambdaMax have been just tested
assert(!(lambdaPosGuess < 0) || (lambdaPosGuess > m_Response.size()));
// TODO JGU : test algorithm
//lambdaPosGuess calculus have been modified (initially lambdaPosGuess = static_cast<unsigned int> ((lambda - lambdaMin) / (lambdaMax - lambdaMin)
//* m_Response.size() -1). lambdaPosGuess = 0 for lambda contained in m_Response first bin
// thus lambdaPosGuess -1 = -1 for those values !!!!
for (typename VectorPairType::const_iterator it = beg + lambdaPosGuess; it <= last; ++it)
{
// if the guess was too high
if ((*it).first >= lambda)
{
return (*it).second;
}
// if the guess is just right
else
if ((*it).first < lambda && (*(it + 1)).first >= lambda)
{
return ((*it).second + (*(it + 1)).second) / 2.0;
}
}
//Value not available
return 0;
}
template <class TPrecision, class TValuePrecision>
typename SpectralResponse<TPrecision, TValuePrecision>::ImagePointerType
SpectralResponse<TPrecision, TValuePrecision>
::GetImage(ImagePointerType image) const
{
typename ImageType::IndexType start;
start[0] = 0;
start[1] = 0;
typename ImageType::SizeType size;
// size[0] = this->Size();
size[0] = 1;
size[1] = 1;
typename ImageType::PointType origin;
origin[0] = 0;
origin[1] = 0;
typename ImageType::SpacingType spacing;
spacing[0] = 1;
spacing[1] = 1;
typename ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
image->SetRegions( region );
image->SetNumberOfComponentsPerPixel( this->Size() );
image->Allocate();
typename ImageType::IndexType idx;
typename ImageType::PixelType pixel;
pixel.SetSize(this->Size());
for ( unsigned int j=0; j<this->Size(); ++j )
{
pixel[j]=m_Response[j].second;
}
idx[0]=0;
idx[1]=0;
image->SetPixel(idx, pixel);
return image;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::SetFromImage(ImagePointerType image)
{
typename ImageType::IndexType idx;
idx[0]=0;
idx[1]=0;
for ( unsigned int j=0; j<this->Size(); ++j )
{
m_Response[j].second = image->GetPixel(idx)[j];
}
m_IntervalComputed = false;
}
template <class TPrecision, class TValuePrecision>
typename SpectralResponse<TPrecision, TValuePrecision>::FilterFunctionValuesPointerType
SpectralResponse<TPrecision, TValuePrecision>
::GetFilterFunctionValues(double step) const
{
//Assume that the SR is sorted
typename FilterFunctionValuesType::ValuesVectorType valuesVector;
for (double i =m_Response.front()->first; i <= m_Response.back()->first; i+=step)
{
valuesVector.push_back=(*this)(i);
}
FilterFunctionValuesPointerType functionValues = FilterFunctionValuesType::New();
functionValues->SetFilterFunctionValues(valuesVector);
functionValues->SetMinSpectralValue(m_Response.front().first);
functionValues->SetMaxSpectralValue(m_Response.back().first);
functionValues->SetUserStep( step );
return functionValues;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::ComputeInterval()
{
typename VectorPairType::const_iterator it = m_Response.begin();
while ((*it).second <= m_SensitivityThreshold)
{
++it;
if (it == m_Response.end())
{
m_Interval.first = static_cast<TPrecision> (0.0);
m_Interval.second = static_cast<TPrecision> (0.0);
m_IntervalComputed = true;
return;
}
}
m_Interval.first = (*it).first;
while ((*it).second > m_SensitivityThreshold)
{
if (it == m_Response.end())
{
m_Interval.second = (*it).first;
return;
}
++it;
}
m_Interval.second = (*it).first;
m_IntervalComputed = true;
}
template <class TPrecision, class TValuePrecision>
void
SpectralResponse<TPrecision, TValuePrecision>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
os<<std::endl;
os <<indent << "[Wavelength (micrometers), Reflectance (percent)]" << std::endl;
for(typename VectorPairType::const_iterator it = m_Response.begin(); it != m_Response.end(); ++it)
{
os <<indent << "Num "<< it - m_Response.begin() << ": [" << (*it).first << ","<< (*it).second << "]" << std::endl;
}
}
} // end namespace otb
#endif
......@@ -394,7 +394,7 @@ CommandLineLauncher::LoadParameters()
outPixType = ImagePixelType_float;
else if( values[1] == "double" )
outPixType = ImagePixelType_double;
else
else
{
return WRONGPARAMETERVALUE;
}
......@@ -419,9 +419,9 @@ CommandLineLauncher::LoadParameters()
// Single value parameter
if( type == ParameterType_Choice || type == ParameterType_Float
|| type == ParameterType_Int || type == ParameterType_Radius
|| type == ParameterType_Directory || type == ParameterType_String
|| type == ParameterType_Directory || type == ParameterType_String
|| type == ParameterType_Filename || type == ParameterType_InputComplexImage
|| type == ParameterType_InputImage || type == ParameterType_InputVectorData
|| type == ParameterType_InputImage || type == ParameterType_InputVectorData
|| type == ParameterType_OutputVectorData )
{
m_Application->SetParameterString( paramKey, values[0] );
......@@ -659,7 +659,7 @@ CommandLineLauncher::DisplayParameterHelp( const Parameter::Pointer & param, con
}
else
{
if( type == ParameterType_OutputImage )
if( type == ParameterType_OutputImage )
{
oss << "\t Default value: filename: none"<< std::endl;
oss << "\t pixel type: float"<< std::endl;
......
......@@ -43,12 +43,12 @@ namespace Wrapper
*
* To be valid, the expression must be as follow:
* ModuleName --attribut1_Key attribut1_Value --attribut2_Key
* attribut2_Value
* attribut2_Value
* After the attribut key, if the user give several values (expression
* without \"--\" separated by space), it will automacally be
* interpreted as a list.
* The module name can be set as the first element of the expression
* or in the expression with the key --moduleName.
* or in the expression with the key --moduleName.
* The exe path have to be set in with the option --modulePath.
*/
......@@ -90,19 +90,19 @@ public:
/** Launch the process, using the Execute application method
* The method will check if the user asked for help (looking at
* --help key) before loading parameter and launching process.
* --help key) before loading parameter and launching process.
**/
bool Execute();
/** Launch the process, using the ExecuteAndWriteOutput application
* method
* method
* The method will check if the user asked for help (looking at
* --help key) before loading parameter and launching process.
* --help key) before loading parameter and launching process.
*/
bool ExecuteAndWriteOutput();
/** Gather the code process to do before Execute and
* ExecuteAndWriteOutput
* ExecuteAndWriteOutput
* Returns false if a problem occurs, true otherwise.
*/
bool BeforeExecute();
......@@ -120,25 +120,25 @@ protected:
virtual ~CommandLineLauncher();
/** Load the executable path. It looks for the key --modulePath,
* extract and interpret as path the following strings.
*/
* extract and interpret as path the following strings.
*/
bool LoadPath();
/** Load the application calling the CreateApplication method of the
* ApplicationRegistry classes.
* ApplicationRegistry classes.
* Pay attention, the executable paths have to be loaded or set in
* the environment before calling the function.
*/
* the environment before calling the function.
*/
void LoadApplication();
/** Parse the user expression, extract the key and the associated
* string and set it as value of each corresonding application
* parameter.
*/
* parameter.
*/
CommandLineLauncher::ParamResultType LoadParameters();
/** Create and display the help of the application */
std::string DisplayParameterHelp( const Parameter::Pointer & param,
std::string DisplayParameterHelp( const Parameter::Pointer & param,
const std::string paramKey );
/** Check if each key is unique in the expression. */
......
Supports Markdown
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