Commit 978ca92c authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: const, style, minor doc corrections

parent b3d519db
......@@ -20,10 +20,6 @@
#ifndef __otbGamma_h
#define __otbGamma_h
#ifdef _MSC_VER
#pragma warning ( disable : 4290 )
#endif
#include "otbMath.h"
namespace otb
......
......@@ -42,7 +42,7 @@ namespace otb
*
* References :
* "Unsupervised Endmember Extraction of Martian Hyperspectral Images",
* B.Luo, J. Chanussot, S. Doute' and X. Ceamanos,
* B.Luo, J. Chanussot, S. Dout\'e and X. Ceamanos,
* IEEE Whispers 2009, Grenoble France, 2009
*
* "Unsupervised classification of hyperspectral images by using linear unmixing algorithm",
......
......@@ -20,6 +20,7 @@ for details.
=========================================================================*/
#ifndef __otbEigenvalueLikelihoodMaximisation_txx
#define __otbEigenvalueLikelihoodMaximisation_txx
#include "otbEigenvalueLikelihoodMaximisation.h"
#include <vcl_algorithm.h>
......@@ -63,7 +64,7 @@ EigenvalueLikelihoodMaximisation<TInputImage>
const unsigned int nl = nbBands - i;
VectorType sigma(nl), t(nl);
for (unsigned int j = 0; j < nl; j++ )
for (unsigned int j = 0; j < nl; ++j )
{
PrecisionType r = eigenCorrelation[j + i];
PrecisionType k = eigenCovariance[j + i];
......@@ -82,7 +83,8 @@ EigenvalueLikelihoodMaximisation<TInputImage>
unsigned int iMax = 0;
for (unsigned int i = 1; i < m_Likelihood.size() - 1; i++)
{
if ( m_Likelihood[i] > m_Likelihood[i - 1] && m_Likelihood[i] > m_Likelihood[i + 1] )
if ( (m_Likelihood[i] > m_Likelihood[i - 1])
&& (m_Likelihood[i] > m_Likelihood[i + 1]) )
{
max = m_Likelihood[i];
iMax = i;
......
......@@ -168,7 +168,7 @@ protected:
virtual void ForwardGenerateData();
virtual void ReverseGenerateData();
/** this is the specifical part of FastICA */
/** this is the specific part of FastICA */
virtual void GenerateTransformationMatrix();
unsigned int m_NumberOfPrincipalComponentsRequired;
......@@ -188,8 +188,8 @@ protected:
TransformFilterPointerType m_TransformFilter;
private:
FastICAImageFilter ( const Self & );
void operator= ( const Self & );
FastICAImageFilter( const Self & ); //purposely not implemented
void operator =( const Self & ); //purposely not implemented
}; // end of class
} // end of namespace otb
......
......@@ -17,6 +17,7 @@
=========================================================================*/
#ifndef __otbFastICAImageFilter_txx
#define __otbFastICAImageFilter_txx
#include "otbFastICAImageFilter.h"
#include "otbMacro.h"
......@@ -285,9 +286,13 @@ FastICAImageFilter< TInputImage, TOutputImage, TDirectionOfTransformation >
} // end of while loop
if ( size != this->GetNumberOfPrincipalComponentsRequired() )
{
this->m_TransformationMatrix = W.get_n_rows( 0, this->GetNumberOfPrincipalComponentsRequired() );
}
else
{
this->m_TransformationMatrix = W;
}
otbMsgDebugMacro( << "Final convergence " << convergence
<< " after " << iteration << " iterations" );
......
......@@ -93,7 +93,7 @@ private:
* \brief Performs fully constrained least squares on each pixel of a VectorImage
*
* This filter takes as input a multiband image and a matrix.
* If the matrix is called $A$, it solves, for each pixel $p$, the system
* If the matrix is called \f$A\f$, it solves, for each pixel \f$p\f$, the system
* \f$A \cdot x = p\f$ in the least square sense, with additionnal constraints on the solution
* \f$\hat{x}\f$ ensuring positivity (each component is positive) and additivity (the sum of
* all components is 1).
......
......@@ -2,9 +2,8 @@
Program: ORFEO Toolbox
Language: C++
Date: 2011/01/24
Version: V1.0
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
......@@ -44,69 +43,69 @@ public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Standard class typedefs. */
typedef LocalRxDetectorFilter Self;
typedef itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(LocalRxDetectorFilter, ImageToImageFilter);
/** typedef related to input and output images */
typedef TInputImage InputImageType;
typedef typename InputImageType::Pointer InputPointerType;
typedef typename InputImageType::ConstPointer InputConstPointerType;
typedef typename InputImageType::IndexType InputIndexType;
typedef typename InputImageType::SizeType InputSizeType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::Pointer OutputPointerType;
typedef typename OutputImageType::IndexType OutputIndexType;
typedef typename OutputImageType::OffsetType OutputOffsetType;
typedef typename OutputImageType::SizeType OutputSizeType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
/** typedef related to iterators */
typedef itk::ConstShapedNeighborhoodIterator<InputImageType> ConstShapedNeighborhoodIteratorType;
typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> VectorFaceCalculatorType;
typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<OutputImageType> FaceCalculatorType;
typedef itk::ImageRegionIterator<OutputImageType> ImageRegionIteratorType;
/** typedef related to statistics */
typedef typename InputImageType::PixelType VectorMeasurementType;
typedef itk::Statistics::ListSample<VectorMeasurementType> ListSampleType;
typedef itk::Statistics::MeanCalculator<ListSampleType> MeanCalculatorType;
typedef itk::Statistics::CovarianceCalculator<ListSampleType> CovarianceCalculatorType;
typedef typename CovarianceCalculatorType::OutputType MatrixType;
/** Getter and Setter */
itkSetMacro(InternalRadius, int);
itkGetMacro(InternalRadius, int);
itkSetMacro(ExternalRadius, int);
itkGetMacro(ExternalRadius, int);
/** Main computation method */
virtual void GenerateInputRequestedRegion();
/** Standard class typedefs. */
typedef LocalRxDetectorFilter Self;
typedef itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(LocalRxDetectorFilter, ImageToImageFilter);
/** typedef related to input and output images */
typedef TInputImage InputImageType;
typedef typename InputImageType::Pointer InputPointerType;
typedef typename InputImageType::ConstPointer InputConstPointerType;
typedef typename InputImageType::IndexType InputIndexType;
typedef typename InputImageType::SizeType InputSizeType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::Pointer OutputPointerType;
typedef typename OutputImageType::IndexType OutputIndexType;
typedef typename OutputImageType::OffsetType OutputOffsetType;
typedef typename OutputImageType::SizeType OutputSizeType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
/** typedef related to iterators */
typedef itk::ConstShapedNeighborhoodIterator<InputImageType> ConstShapedNeighborhoodIteratorType;
typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<InputImageType> VectorFaceCalculatorType;
typedef itk::NeighborhoodAlgorithm::ImageBoundaryFacesCalculator<OutputImageType> FaceCalculatorType;
typedef itk::ImageRegionIterator<OutputImageType> ImageRegionIteratorType;
/** typedef related to statistics */
typedef typename InputImageType::PixelType VectorMeasurementType;
typedef itk::Statistics::ListSample<VectorMeasurementType> ListSampleType;
typedef itk::Statistics::MeanCalculator<ListSampleType> MeanCalculatorType;
typedef itk::Statistics::CovarianceCalculator<ListSampleType> CovarianceCalculatorType;
typedef typename CovarianceCalculatorType::OutputType MatrixType;
/** Getter and Setter */
itkSetMacro(InternalRadius, int);
itkGetMacro(InternalRadius, int);
itkSetMacro(ExternalRadius, int);
itkGetMacro(ExternalRadius, int);
/** Main computation method */
virtual void GenerateInputRequestedRegion();
// virtual void GenerateData();
virtual void BeforeThreadedGenerateData();
virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId);
virtual void BeforeThreadedGenerateData();
virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId);
protected:
LocalRxDetectorFilter();
virtual ~LocalRxDetectorFilter() {}
void PrintSelf(std::ostream& os, itk::Indent indent) const;
LocalRxDetectorFilter();
virtual ~LocalRxDetectorFilter() {}
void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
LocalRxDetectorFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
LocalRxDetectorFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
int m_InternalRadius;
int m_ExternalRadius;
int m_InternalRadius;
int m_ExternalRadius;
};
......
/*=========================================================================
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 __otbLocalRxDetectorFilter_txx
#define __otbLocalRxDetectorFilter_txx
#include "otbLocalRxDetectorFilter.h"
namespace otb
......@@ -13,7 +29,7 @@ namespace otb
template <class TInputImage, class TOutputImage>
LocalRxDetectorFilter<TInputImage, TOutputImage>
::LocalRxDetectorFilter()
: m_ExternalRadius(2), m_InternalRadius(1)
: m_ExternalRadius(2), m_InternalRadius(1)
{
}
......@@ -39,11 +55,11 @@ void
LocalRxDetectorFilter<TInputImage, TOutputImage>
::BeforeThreadedGenerateData()
{
// Get the input and output pointers
OutputPointerType outputPtr = this->GetOutput();
// Get the input and output pointers
OutputPointerType outputPtr = this->GetOutput();
// Fill the buffer with black pixels
outputPtr->FillBuffer(0);
// Fill the buffer with black pixels
outputPtr->FillBuffer(0);
}
/**
......@@ -55,121 +71,121 @@ LocalRxDetectorFilter<TInputImage, TOutputImage>
::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
int threadId)
{
// Get the input and output pointers
InputConstPointerType inputPtr = this->GetInput();
OutputPointerType outputPtr = this->GetOutput();
// Get the input and output pointers
InputConstPointerType inputPtr = this->GetInput();
OutputPointerType outputPtr = this->GetOutput();
// Support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
// Support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
// Compute input region for thread
typename TInputImage::RegionType inputRegionForThread;
inputRegionForThread = outputRegionForThread;
inputRegionForThread.PadByRadius(m_ExternalRadius);
inputRegionForThread.Crop(inputPtr->GetLargestPossibleRegion());
// Compute input region for thread
typename TInputImage::RegionType inputRegionForThread;
inputRegionForThread = outputRegionForThread;
inputRegionForThread.PadByRadius(m_ExternalRadius);
inputRegionForThread.Crop(inputPtr->GetLargestPossibleRegion());
// Iterator on input region
typename ConstShapedNeighborhoodIteratorType::RadiusType radius;
radius.Fill(m_ExternalRadius);
// Iterator on input region
typename ConstShapedNeighborhoodIteratorType::RadiusType radius;
radius.Fill(m_ExternalRadius);
VectorFaceCalculatorType vectorFaceCalculator;
typename VectorFaceCalculatorType::FaceListType vectorFaceList;
typename VectorFaceCalculatorType::FaceListType::iterator vectorFit;
VectorFaceCalculatorType vectorFaceCalculator;
typename VectorFaceCalculatorType::FaceListType vectorFaceList;
typename VectorFaceCalculatorType::FaceListType::iterator vectorFit;
vectorFaceList = vectorFaceCalculator(inputPtr, inputRegionForThread, radius);
vectorFaceList = vectorFaceCalculator(inputPtr, inputRegionForThread, radius);
vectorFit = vectorFaceList.begin(); // Only the first face is used
vectorFit = vectorFaceList.begin(); // Only the first face is used
ConstShapedNeighborhoodIteratorType inputIt(radius, inputPtr, *vectorFit);
ConstShapedNeighborhoodIteratorType inputIt(radius, inputPtr, *vectorFit);
// Neighborhood Configuration
typename ConstShapedNeighborhoodIteratorType::OffsetType off;
// Neighborhood Configuration
typename ConstShapedNeighborhoodIteratorType::OffsetType off;
for (int y = -m_ExternalRadius; y <= m_ExternalRadius; y++)
{
off[1] = y;
for (int x = -m_ExternalRadius; x <= m_ExternalRadius; x++)
{
off[0] = x;
if ((abs(x) > m_InternalRadius) || (abs(y) > m_InternalRadius))
{
inputIt.ActivateOffset(off);
}
}
}
for (int y = -m_ExternalRadius; y <= m_ExternalRadius; y++)
{
off[1] = y;
for (int x = -m_ExternalRadius; x <= m_ExternalRadius; x++)
{
off[0] = x;
if ((abs(x) > m_InternalRadius) || (abs(y) > m_InternalRadius))
{
inputIt.ActivateOffset(off);
}
}
}
// iterator on output region
FaceCalculatorType faceCalculator;
typename FaceCalculatorType::FaceListType faceList;
typename FaceCalculatorType::FaceListType::iterator fit;
// iterator on output region
FaceCalculatorType faceCalculator;
typename FaceCalculatorType::FaceListType faceList;
typename FaceCalculatorType::FaceListType::iterator fit;
faceList = faceCalculator(outputPtr, inputRegionForThread, radius);
fit = faceList.begin(); // Only the first face is used
faceList = faceCalculator(outputPtr, inputRegionForThread, radius);
fit = faceList.begin(); // Only the first face is used
ImageRegionIteratorType outputIt(outputPtr, *fit);
ImageRegionIteratorType outputIt(outputPtr, *fit);
// Run Input Image
int j = 0;
// Run Input Image
int j = 0;
for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt)
{
for (inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt)
{
// Create ListSample
typename ListSampleType::Pointer listSample = ListSampleType::New();
listSample->SetMeasurementVectorSize(inputPtr->GetNumberOfComponentsPerPixel());
// Create ListSample
typename ListSampleType::Pointer listSample = ListSampleType::New();
listSample->SetMeasurementVectorSize(inputPtr->GetNumberOfComponentsPerPixel());
// Run neighborhood
typename ConstShapedNeighborhoodIteratorType::ConstIterator ci;
for (ci = inputIt.Begin(); !ci.IsAtEnd(); ++ci)
{
// Pushback element in listSample
listSample->PushBack(ci.Get());
}
// Run neighborhood
typename ConstShapedNeighborhoodIteratorType::ConstIterator ci;
for (ci = inputIt.Begin(); !ci.IsAtEnd(); ++ci)
{
// Pushback element in listSample
listSample->PushBack(ci.Get());
}
// Compute Mean vector
typename MeanCalculatorType::Pointer meanCalculator = MeanCalculatorType::New();
meanCalculator->SetInputSample(listSample);
meanCalculator->Update();
// Compute Mean vector
typename MeanCalculatorType::Pointer meanCalculator = MeanCalculatorType::New();
meanCalculator->SetInputSample(listSample);
meanCalculator->Update();
typename MeanCalculatorType::OutputType *meanVector;
meanVector = meanCalculator->GetOutput();
typename MeanCalculatorType::OutputType *meanVector;
meanVector = meanCalculator->GetOutput();
// Compute covariance matrix
typename CovarianceCalculatorType::Pointer covarianceCalculator = CovarianceCalculatorType::New();
covarianceCalculator->SetInputSample(listSample);
covarianceCalculator->SetMean(meanVector);
covarianceCalculator->Update();
// Compute covariance matrix
typename CovarianceCalculatorType::Pointer covarianceCalculator = CovarianceCalculatorType::New();
covarianceCalculator->SetInputSample(listSample);
covarianceCalculator->SetMean(meanVector);
covarianceCalculator->Update();
const typename CovarianceCalculatorType::OutputType *covarianceMatrix = covarianceCalculator->GetOutput();
const typename CovarianceCalculatorType::OutputType *covarianceMatrix = covarianceCalculator->GetOutput();
// Compute RX value
MatrixType invCovMat;
invCovMat = covarianceMatrix->GetInverse();
// Compute RX value
MatrixType invCovMat;
invCovMat = covarianceMatrix->GetInverse();
VectorMeasurementType testPixVec;
testPixVec = inputPtr->GetPixel(inputIt.GetIndex());
VectorMeasurementType testPixVec;
testPixVec = inputPtr->GetPixel(inputIt.GetIndex());
VectorMeasurementType meanVec(meanVector->GetNumberOfElements());
for(unsigned int i = 0; i < meanVector->GetNumberOfElements(); i++)
{
meanVec.SetElement(i, meanVector->GetElement(i));
}
VectorMeasurementType meanVec(meanVector->GetNumberOfElements());
for(unsigned int i = 0; i < meanVector->GetNumberOfElements(); i++)
{
meanVec.SetElement(i, meanVector->GetElement(i));
}
typename MatrixType::InternalMatrixType centeredTestPixMat(meanVector->GetNumberOfElements(), 1);
for (unsigned int i = 0; i < centeredTestPixMat.rows(); i++)
{
centeredTestPixMat.put(i, 0, (testPixVec.GetElement(i) - meanVector->GetElement(i)));
}
typename MatrixType::InternalMatrixType centeredTestPixMat(meanVector->GetNumberOfElements(), 1);
for (unsigned int i = 0; i < centeredTestPixMat.rows(); i++)
{
centeredTestPixMat.put(i, 0, (testPixVec.GetElement(i) - meanVector->GetElement(i)));
}
typename MatrixType::InternalMatrixType rxValue = centeredTestPixMat.transpose() * invCovMat.GetVnlMatrix() * centeredTestPixMat;
typename MatrixType::InternalMatrixType rxValue = centeredTestPixMat.transpose() * invCovMat.GetVnlMatrix() * centeredTestPixMat;
outputIt.Set(rxValue.get(0, 0));
}
outputIt.Set(rxValue.get(0, 0));
}
}
/**
......@@ -180,48 +196,48 @@ void
LocalRxDetectorFilter<TInputImage, TOutputImage>
::GenerateInputRequestedRegion()
{
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// get pointers to the input and output
InputPointerType inputPtr =
const_cast< InputImageType * >( this->GetInput());
OutputPointerType outputPtr = this->GetOutput();
if ( !inputPtr || !outputPtr )
{
return;
}
// get a copy of the input requested region (should equal the output
// requested region)
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = inputPtr->GetRequestedRegion();
// pad the input requested region by the operator radius
inputRequestedRegion.PadByRadius( m_ExternalRadius );
// crop the input requested region at the input's largest possible region
if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
{
inputPtr->SetRequestedRegion( inputRequestedRegion );
return;
}
else
{
// Couldn't crop the region (requested region is outside the largest
// possible region). Throw an exception.
// store what we tried to request (prior to trying to crop)
inputPtr->SetRequestedRegion( inputRequestedRegion );
// build an exception
itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
e.SetDataObject(inputPtr);
throw e;
}
// call the superclass' implementation of this method
Superclass::GenerateInputRequestedRegion();
// get pointers to the input and output
InputPointerType inputPtr =
const_cast< InputImageType * >( this->GetInput());
OutputPointerType outputPtr = this->GetOutput();
if ( !inputPtr || !outputPtr )
{
return;
}
// get a copy of the input requested region (should equal the output
// requested region)
typename TInputImage::RegionType inputRequestedRegion;
inputRequestedRegion = inputPtr->GetRequestedRegion();
// pad the input requested region by the operator radius
inputRequestedRegion.PadByRadius( m_ExternalRadius );
// crop the input requested region at the input's largest possible region
if ( inputRequestedRegion.Crop(inputPtr->GetLargestPossibleRegion()) )
{
inputPtr->SetRequestedRegion( inputRequestedRegion );
return;
}
else
{
// Couldn't crop the region (requested region is outside the largest
// possible region). Throw an exception.
// store what we tried to request (prior to trying to crop)
inputPtr->SetRequestedRegion( inputRequestedRegion );
// build an exception
itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
e.SetLocation(ITK_LOCATION);
e.SetDescription("Requested region is (at least partially) outside the largest possible region.");
e.SetDataObject(inputPtr);
throw e;
}
}
} // end namespace otb
......
......@@ -2,9 +2,8 @@
Program: ORFEO Toolbox
Language: C++
Date: 2011/01/24
Version: V1.0
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
......@@ -40,73 +39,73 @@ namespace otb
*/
template <class TInputImage, class TOutputImage>
class ITK_EXPORT LocalRxDetectorNonThreadFilter:
public itk::ImageToImageFilter<TInputImage, TOutputImage>
public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Standard class typedefs. */
typedef LocalRxDetectorNonThreadFilter Self;
typedef itk::ImageToImageFilter< TInputImage, TOutputImage > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;