Commit 231a23d9 authored by OTB Bot's avatar OTB Bot

STYLE

parent 2ab61527

Too many changes to show.

To preserve performance only 359 of 359+ files are displayed.

......@@ -26,81 +26,81 @@
namespace otb
{
namespace Functor
{
/**
* \class AmplitudePhaseToRGBFunctor
* \brief Function object to compute a color representation of a radar image.
*
* This class is useful for visualizing radar images with a combination of
* the phase and the amplitude at the same time.
*
* The amplitude is used to represent the intensity of the pixel and the phase
* to represent it's hue.
*
* Amplitude and phase can be obtained using the itk::ComplexToModulusImageFilter
* and itk::ComplexToPhaseImageFilter for example.
*
*/
template< class TInput1, class TInput2=TInput1, class TInput3=TInput1, class TOutput=TInput1>
class ITK_EXPORT AmplitudePhaseToRGBFunctor
namespace Functor
{
/**
* \class AmplitudePhaseToRGBFunctor
* \brief Function object to compute a color representation of a radar image.
*
* This class is useful for visualizing radar images with a combination of
* the phase and the amplitude at the same time.
*
* The amplitude is used to represent the intensity of the pixel and the phase
* to represent it's hue.
*
* Amplitude and phase can be obtained using the itk::ComplexToModulusImageFilter
* and itk::ComplexToPhaseImageFilter for example.
*
*/
template<class TInput1, class TInput2 = TInput1, class TInput3 = TInput1, class TOutput = TInput1>
class ITK_EXPORT AmplitudePhaseToRGBFunctor
{
public:
typedef TOutput RGBPixelType;
typedef typename RGBPixelType::ValueType RGBComponentType;
typedef HSVToRGBFunctor<RGBPixelType> HSVToRGBFunctorType;
typedef TInput1 ScalarType;
AmplitudePhaseToRGBFunctor()
{
public:
typedef TOutput RGBPixelType;
typedef typename RGBPixelType::ValueType RGBComponentType;
typedef HSVToRGBFunctor<RGBPixelType> HSVToRGBFunctorType;
typedef TInput1 ScalarType;
AmplitudePhaseToRGBFunctor()
{
m_Minimum = 0;
m_Maximum = itk::NumericTraits<ScalarType>::max();
};
~AmplitudePhaseToRGBFunctor(){};
void SetMaximum(ScalarType max)
{
this->m_Maximum = max;
}
void SetMinimum(ScalarType min)
{
this->m_Minimum = min;
}
inline TOutput operator()( const TInput1 & amplitude, const TInput2 & coherence, const TInput3 & phase) const
{
// std::cout << amplitude << " - " << phase << std::endl;
double hinc, sinc, vinc;
hinc=0.6/(CONST_2PI);
sinc=0.0;
vinc=0.0;
double hue, sat, val;
hue = 0.6 - (phase+CONST_PI)*hinc;
sat = 0.6*coherence+0.3;
val = itk::NumericTraits<RGBComponentType>::max()/2
* ( (amplitude-m_Minimum)/(m_Maximum-m_Minimum)+1.0);
if (amplitude < m_Minimum)
{
val = 0;
}
if (amplitude > m_Maximum)
{
val = itk::NumericTraits<RGBComponentType>::max();
}
return m_HSVToRGBFunctor(hue, sat, val);
}
private:
ScalarType m_Maximum;
ScalarType m_Minimum;
HSVToRGBFunctorType m_HSVToRGBFunctor;
m_Minimum = 0;
m_Maximum = itk::NumericTraits<ScalarType>::max();
};
~AmplitudePhaseToRGBFunctor(){}
void SetMaximum(ScalarType max)
{
this->m_Maximum = max;
}
void SetMinimum(ScalarType min)
{
this->m_Minimum = min;
}
inline TOutput operator ()(const TInput1& amplitude, const TInput2& coherence, const TInput3& phase) const
{
// std::cout << amplitude << " - " << phase << std::endl;
double hinc, sinc, vinc;
hinc = 0.6 / (CONST_2PI);
sinc = 0.0;
vinc = 0.0;
double hue, sat, val;
hue = 0.6 - (phase + CONST_PI) * hinc;
sat = 0.6 * coherence + 0.3;
val = itk::NumericTraits<RGBComponentType>::max() / 2
* ((amplitude - m_Minimum) / (m_Maximum - m_Minimum) + 1.0);
if (amplitude < m_Minimum)
{
val = 0;
}
if (amplitude > m_Maximum)
{
val = itk::NumericTraits<RGBComponentType>::max();
}
return m_HSVToRGBFunctor(hue, sat, val);
}
private:
ScalarType m_Maximum;
ScalarType m_Minimum;
HSVToRGBFunctorType m_HSVToRGBFunctor;
};
}
}
#endif
......@@ -36,29 +36,29 @@ namespace otb
*/
template <class TInputImage, class TOutputImage>
class ITK_EXPORT BSplineDecompositionImageFilter :
public itk::ImageToImageFilter<TInputImage,TOutputImage>
public itk::ImageToImageFilter<TInputImage, TOutputImage>
{
public:
/** Standard class typedefs. */
typedef BSplineDecompositionImageFilter Self;
typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef BSplineDecompositionImageFilter Self;
typedef itk::ImageToImageFilter<TInputImage, TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(BSplineDecompositionImageFilter, ImageToImageFilter);
/** New macro for creation of through a Smart Pointer */
itkNewMacro( Self );
itkNewMacro(Self);
/** Inherit input and output image types from Superclass. */
typedef typename Superclass::InputImageType InputImageType;
typedef typename Superclass::InputImagePointer InputImagePointer;
typedef typename Superclass::InputImageType InputImageType;
typedef typename Superclass::InputImagePointer InputImagePointer;
typedef typename Superclass::InputImageConstPointer InputImageConstPointer;
typedef typename Superclass::OutputImagePointer OutputImagePointer;
typedef typename Superclass::OutputImagePointer OutputImagePointer;
/** Dimension underlying input image. */
itkStaticConstMacro(ImageDimension, unsigned int,TInputImage::ImageDimension);
itkStaticConstMacro(ImageDimension, unsigned int, TInputImage::ImageDimension);
itkStaticConstMacro(OutputImageDimension, unsigned int,
TOutputImage::ImageDimension);
......@@ -72,24 +72,23 @@ public:
protected:
BSplineDecompositionImageFilter();
virtual ~BSplineDecompositionImageFilter() {};
virtual ~BSplineDecompositionImageFilter() {}
void PrintSelf(std::ostream& os, itk::Indent indent) const;
void GenerateData( );
void GenerateData();
/** These are needed by the smoothing spline routine. */
std::vector<double> m_Scratch; // temp storage for processing of Coefficients
typename TInputImage::SizeType m_DataLength; // Image size
unsigned int m_SplineOrder; // User specified spline order (3rd or cubic is the default)
double m_SplinePoles[3];// Poles calculated for a given spline order
int m_NumberOfPoles; // number of poles
double m_Tolerance; // Tolerance used for determining initial causal coefficient
unsigned int m_IteratorDirection; // Direction for iterator incrementing
std::vector<double> m_Scratch; // temp storage for processing of Coefficients
typename TInputImage::SizeType m_DataLength; // Image size
unsigned int m_SplineOrder; // User specified spline order (3rd or cubic is the default)
double m_SplinePoles[3]; // Poles calculated for a given spline order
int m_NumberOfPoles; // number of poles
double m_Tolerance; // Tolerance used for determining initial causal coefficient
unsigned int m_IteratorDirection; // Direction for iterator incrementing
private:
BSplineDecompositionImageFilter( const Self& ); //purposely not implemented
void operator=( const Self& ); //purposely not implemented
BSplineDecompositionImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
/** Determines the poles given the Spline Order. */
virtual void SetPoles();
......@@ -111,14 +110,13 @@ private:
void CopyImageToImage();
/** Copies a vector of data from the Coefficients image to the m_Scratch vector. */
void CopyCoefficientsToScratch( OutputLinearIterator & );
void CopyCoefficientsToScratch(OutputLinearIterator&);
/** Copies a vector of data from m_Scratch to the Coefficients image. */
void CopyScratchToCoefficients( OutputLinearIterator & );
void CopyScratchToCoefficients(OutputLinearIterator&);
};
} // namespace itk
#ifndef OTB_MANUAL_INSTANTIATION
......@@ -126,4 +124,3 @@ private:
#endif
#endif
......@@ -40,7 +40,6 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
this->SetSplineOrder(SplineOrder);
}
/**
* Standard "PrintSelf" method
*/
......@@ -51,12 +50,11 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
std::ostream& os,
itk::Indent indent) const
{
Superclass::PrintSelf( os, indent );
Superclass::PrintSelf(os, indent);
os << indent << "Spline Order: " << m_SplineOrder << std::endl;
}
template <class TInputImage, class TOutputImage>
bool
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
......@@ -69,63 +67,61 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
double c0 = 1.0;
if (m_DataLength[m_IteratorDirection] == 1) //Required by mirror boundaries
{
{
return false;
}
}
// Compute overall gain
for (int k = 0; k < m_NumberOfPoles; ++k)
{
{
// Note for cubic splines lambda = 6
c0 = c0 * (1.0 - m_SplinePoles[k]) * (1.0 - 1.0 / m_SplinePoles[k]);
}
}
// apply the gain
for (unsigned int n = 0; n < m_DataLength[m_IteratorDirection]; ++n)
{
{
m_Scratch[n] *= c0;
}
}
// loop over all poles
for (int k = 0; k < m_NumberOfPoles; ++k)
{
{
// causal initialization
this->SetInitialCausalCoefficient(m_SplinePoles[k]);
// causal recursion
for (unsigned int n = 1; n < m_DataLength[m_IteratorDirection]; ++n)
{
{
m_Scratch[n] += m_SplinePoles[k] * m_Scratch[n - 1];
}
}
// anticausal initialization
this->SetInitialAntiCausalCoefficient(m_SplinePoles[k]);
// anticausal recursion
for ( int n = m_DataLength[m_IteratorDirection] - 2; 0 <= n; n--)
{
for (int n = m_DataLength[m_IteratorDirection] - 2; 0 <= n; n--)
{
m_Scratch[n] = m_SplinePoles[k] * (m_Scratch[n + 1] - m_Scratch[n]);
}
}
}
return true;
}
template <class TInputImage, class TOutputImage>
void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
::SetSplineOrder(unsigned int SplineOrder)
{
if (SplineOrder == m_SplineOrder)
{
{
return;
}
}
m_SplineOrder = SplineOrder;
this->SetPoles();
this->Modified();
}
template <class TInputImage, class TOutputImage>
void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
......@@ -135,7 +131,7 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
// See also, Handbook of Medical Imaging, Processing and Analysis, Ed. Isaac N. Bankman,
// 2000, pg. 416.
switch (m_SplineOrder)
{
{
case 3:
m_NumberOfPoles = 1;
m_SplinePoles[0] = vcl_sqrt(3.0) - 2.0;
......@@ -165,14 +161,13 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
default:
// SplineOrder not implemented yet.
itk::ExceptionObject err(__FILE__, __LINE__);
err.SetLocation( ITK_LOCATION);
err.SetDescription( "SplineOrder must be between 0 and 5. Requested spline order has not been implemented yet." );
err.SetLocation(ITK_LOCATION);
err.SetDescription("SplineOrder must be between 0 and 5. Requested spline order has not been implemented yet.");
throw err;
break;
}
}
}
template <class TInputImage, class TOutputImage>
void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
......@@ -181,45 +176,44 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
/* begining InitialCausalCoefficient */
/* See Unser, 1999, Box 2 for explaination */
double sum, zn, z2n, iz;
unsigned long horizon;
double sum, zn, z2n, iz;
unsigned long horizon;
/* this initialization corresponds to mirror boundaries */
horizon = m_DataLength[m_IteratorDirection];
zn = z;
if (m_Tolerance > 0.0)
{
horizon = (long)vcl_ceil(log(m_Tolerance) / vcl_log(fabs(z)));
}
{
horizon = (long) vcl_ceil(log(m_Tolerance) / vcl_log(fabs(z)));
}
if (horizon < m_DataLength[m_IteratorDirection])
{
{
/* accelerated loop */
sum = m_Scratch[0]; // verify this
for (unsigned int n = 1; n < horizon; ++n)
{
{
sum += zn * m_Scratch[n];
zn *= z;
}
}
m_Scratch[0] = sum;
}
}
else
{
{
/* full loop */
iz = 1.0 / z;
z2n = vcl_pow(z, (double)(m_DataLength[m_IteratorDirection] - 1L));
z2n = vcl_pow(z, (double) (m_DataLength[m_IteratorDirection] - 1L));
sum = m_Scratch[0] + z2n * m_Scratch[m_DataLength[m_IteratorDirection] - 1L];
z2n *= z2n * iz;
for (unsigned int n = 1; n <= (m_DataLength[m_IteratorDirection] - 2); ++n)
{
{
sum += (zn + z2n) * m_Scratch[n];
zn *= z;
z2n *= iz;
}
}
m_Scratch[0] = sum / (1.0 - zn * zn);
}
}
}
template <class TInputImage, class TOutputImage>
void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
......@@ -233,7 +227,6 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
(z * m_Scratch[m_DataLength[m_IteratorDirection] - 2] + m_Scratch[m_DataLength[m_IteratorDirection] - 1]);
}
template <class TInputImage, class TOutputImage>
void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
......@@ -250,20 +243,19 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
// Initialize coeffient array
this->CopyImageToImage(); // Coefficients are initialized to the input data
for (unsigned int n=0; n < ImageDimension; ++n)
{
for (unsigned int n = 0; n < ImageDimension; ++n)
{
m_IteratorDirection = n;
// Loop through each dimension
// Initialize iterators
OutputLinearIterator CIterator( output, output->GetBufferedRegion() );
CIterator.SetDirection( m_IteratorDirection );
OutputLinearIterator CIterator(output, output->GetBufferedRegion());
CIterator.SetDirection(m_IteratorDirection);
// For each data vector
while ( !CIterator.IsAtEnd() )
{
while (!CIterator.IsAtEnd())
{
// Copy coefficients to scratch
this->CopyCoefficientsToScratch( CIterator );
this->CopyCoefficientsToScratch(CIterator);
// Perform 1D BSpline calculations
this->DataToCoefficients1D();
......@@ -271,14 +263,13 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
// Copy scratch back to coefficients.
// Brings us back to the end of the line we were working on.
CIterator.GoToBeginOfLine();
this->CopyScratchToCoefficients( CIterator ); // m_Scratch = m_Image;
this->CopyScratchToCoefficients(CIterator); // m_Scratch = m_Image;
CIterator.NextLine();
progress.CompletedPixel();
}
}
}
}
/**
* Copy the input image into the output image
*/
......@@ -288,61 +279,59 @@ BSplineDecompositionImageFilter<TInputImage, TOutputImage>
::CopyImageToImage()
{
typedef itk::ImageRegionConstIteratorWithIndex< TInputImage > InputIterator;
typedef itk::ImageRegionIterator< TOutputImage > OutputIterator;
typedef typename TOutputImage::PixelType OutputPixelType;
typedef itk::ImageRegionConstIteratorWithIndex<TInputImage> InputIterator;
typedef itk::ImageRegionIterator<TOutputImage> OutputIterator;
typedef typename TOutputImage::PixelType OutputPixelType;
InputIterator inIt( this->GetInput(), this->GetInput()->GetBufferedRegion() );
OutputIterator outIt( this->GetOutput(), this->GetOutput()->GetBufferedRegion() );
InputIterator inIt(this->GetInput(), this->GetInput()->GetBufferedRegion());
OutputIterator outIt(this->GetOutput(), this->GetOutput()->GetBufferedRegion());
inIt = inIt.Begin();
outIt = outIt.Begin();
while ( !outIt.IsAtEnd() )
{
outIt.Set( static_cast<OutputPixelType>( inIt.Get() ) );
while (!outIt.IsAtEnd())
{
outIt.Set(static_cast<OutputPixelType>(inIt.Get()));
++inIt;
++outIt;
}
}
}
/**
* Copy the scratch to one line of the output image
*/
template <class TInputImage, class TOutputImage>
void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
::CopyScratchToCoefficients(OutputLinearIterator & Iter)
::CopyScratchToCoefficients(OutputLinearIterator& Iter)
{
typedef typename TOutputImage::PixelType OutputPixelType;
unsigned long j = 0;
while ( !Iter.IsAtEndOfLine() )
{
Iter.Set( static_cast<OutputPixelType>( m_Scratch[j] ) );
while (!Iter.IsAtEndOfLine())
{
Iter.Set(static_cast<OutputPixelType>(m_Scratch[j]));
++Iter;
++j;
}
}
}
/**
* Copy one line of the output image to the scratch
*/
template <class TInputImage, class TOutputImage>
void
BSplineDecompositionImageFilter<TInputImage, TOutputImage>
::CopyCoefficientsToScratch(OutputLinearIterator & Iter)
::CopyCoefficientsToScratch(OutputLinearIterator& Iter)
{
unsigned long j = 0;
while ( !Iter.IsAtEndOfLine() )
{
m_Scratch[j] = static_cast<double>( Iter.Get() );
while (!Iter.IsAtEndOfLine())
{