Commit f50472ad authored by Rémi Cresson's avatar Rémi Cresson

REFAC: apply clang-format

parent 73bf52a1
Pipeline #2660 failed with stages
in 80 minutes and 23 seconds
......@@ -27,9 +27,11 @@
#include "vnl/vnl_matrix.h"
#include "vcl_compiler.h"
namespace otb{
namespace otb
{
namespace Functor{
namespace Functor
{
/**
* \class RGB2LAB Functor
......@@ -37,71 +39,80 @@ namespace Functor{
*
* \ingroup OTBMosaic
*/
template< class TInput, class TOutput>
template <class TInput, class TOutput>
class RGB2LAB
{
public:
RGB2LAB() {
M.set_size(3,3);
M[0][0] = 0.3811; M[0][1] = 0.5783; M[0][2] = 0.0406;
M[1][0] = 0.1967; M[1][1] = 0.7244; M[1][2] = 0.0790;
M[2][0] = 0.0241; M[2][1] = 0.1288; M[2][2] = 0.8531;
D1.set_size(3,3);
RGB2LAB()
{
M.set_size(3, 3);
M[0][0] = 0.3811;
M[0][1] = 0.5783;
M[0][2] = 0.0406;
M[1][0] = 0.1967;
M[1][1] = 0.7244;
M[1][2] = 0.0790;
M[2][0] = 0.0241;
M[2][1] = 0.1288;
M[2][2] = 0.8531;
D1.set_size(3, 3);
D1.fill(0.0);
D1[0][0] = 1.0 / vcl_sqrt(3.0);
D1[1][1] = 1.0 / vcl_sqrt(6.0);
D1[2][2] = 1.0 / vcl_sqrt(2.0);
D2.set_size(3,3);
D2.set_size(3, 3);
D2.fill(1.0);
D2[1][2] = -2.0;
D2[2][1] = -1.0;
D2[2][2] = 0.0;
}
~RGB2LAB() {
~RGB2LAB()
{
}
bool operator!=( const RGB2LAB & ) const {
bool operator!=(const RGB2LAB&) const
{
return false;
}
bool operator==( const RGB2LAB & other ) const {
bool operator==(const RGB2LAB& other) const
{
return !(*this != other);
}
inline TOutput operator()( const TInput & A ) const
inline TOutput operator()(const TInput& A) const
{
TOutput output;
output.SetSize(3);
if (A[0] == 0 && A[1] == 0 && A[2] == 0)
{
{
output.Fill(0);
return output;
}
}
// RGB
vnl_matrix<double> rgb(3,1);
vnl_matrix<double> rgb(3, 1);
rgb[0][0] = A[0];
rgb[1][0] = A[1];
rgb[2][0] = A[2];
// LMS
vnl_matrix<double> lms(3,1);
lms = M*rgb;
vnl_matrix<double> lms(3, 1);
lms = M * rgb;
// LMS (log10)
const double log10 = vcl_log(10);
lms[0][0] = vcl_log( lms[0][0] ) / log10;
lms[1][0] = vcl_log( lms[1][0] ) / log10;
lms[2][0] = vcl_log( lms[2][0] ) / log10;
lms[0][0] = vcl_log(lms[0][0]) / log10;
lms[1][0] = vcl_log(lms[1][0]) / log10;
lms[2][0] = vcl_log(lms[2][0]) / log10;
// LAB
vnl_matrix<double> lab(3,1);
lab = D1*(D2*lms);
vnl_matrix<double> lab(3, 1);
lab = D1 * (D2 * lms);
output[0] = lab[0][0];
output[1] = lab[1][0];
......@@ -110,15 +121,15 @@ public:
return output;
}
size_t OutputSize(const std::array<size_t,1> &) const {
size_t OutputSize(const std::array<size_t, 1>&) const
{
return 3;
}
}
private:
vnl_matrix<double> M;
vnl_matrix<double> D1;
vnl_matrix<double> D2;
};
/**
......@@ -129,70 +140,77 @@ private:
*
* \ingroup OTBMosaic
*/
template< class TInput, class TOutput>
template <class TInput, class TOutput>
class LAB2RGB
{
public:
LAB2RGB() {
M.set_size(3,3);
M[0][0] = 4.4687; M[0][1] = -3.5887; M[0][2] = 0.1197;
M[1][0] = -1.2197; M[1][1] = 2.3831; M[1][2] = -0.1626;
M[2][0] = 0.0579; M[2][1] = -0.2584; M[2][2] = 1.1934;
D1.set_size(3,3);
LAB2RGB()
{
M.set_size(3, 3);
M[0][0] = 4.4687;
M[0][1] = -3.5887;
M[0][2] = 0.1197;
M[1][0] = -1.2197;
M[1][1] = 2.3831;
M[1][2] = -0.1626;
M[2][0] = 0.0579;
M[2][1] = -0.2584;
M[2][2] = 1.1934;
D1.set_size(3, 3);
D1.fill(0.0);
D1[0][0] = 1.0 / vcl_sqrt(3.0);
D1[1][1] = 1.0 / vcl_sqrt(6.0);
D1[2][2] = 1.0 / vcl_sqrt(2.0);
D2.set_size(3,3);
D2.set_size(3, 3);
D2.fill(1.0);
D2[1][2] = -1.0;
D2[2][1] = -2.0;
D2[2][2] = 0.0;
}
~LAB2RGB() {
~LAB2RGB()
{
}
bool operator!=( const LAB2RGB & ) const
bool operator!=(const LAB2RGB&) const
{
return false;
}
bool operator==( const LAB2RGB & other ) const
bool operator==(const LAB2RGB& other) const
{
return !(*this != other);
}
inline TOutput operator()( const TInput & A ) const
inline TOutput operator()(const TInput& A) const
{
TOutput output;
output.SetSize(3);
if (A[0] == 0 && A[1] == 0 && A[2] == 0)
{
{
output.Fill(0);
return output;
}
}
// LAB
vnl_matrix<double> lab(3,1);
vnl_matrix<double> lab(3, 1);
lab[0][0] = A[0];
lab[1][0] = A[1];
lab[2][0] = A[2];
// LMS
vnl_matrix<double> lms(3,1);
lms = D2*(D1*lab);
vnl_matrix<double> lms(3, 1);
lms = D2 * (D1 * lab);
lms[0][0] = vcl_pow(10.0, lms[0][0]);
lms[1][0] = vcl_pow(10.0, lms[1][0]);
lms[2][0] = vcl_pow(10.0, lms[2][0]);
// RGB
vnl_matrix<double> rgb(3,1);
rgb = M*lms;
vnl_matrix<double> rgb(3, 1);
rgb = M * lms;
output[0] = rgb[0][0];
output[1] = rgb[1][0];
......@@ -201,7 +219,8 @@ public:
return output;
}
inline size_t OutputSize(const std::array<size_t,1> &) const {
inline size_t OutputSize(const std::array<size_t, 1>&) const
{
return 3;
}
......@@ -209,7 +228,6 @@ private:
vnl_matrix<double> M;
vnl_matrix<double> D1;
vnl_matrix<double> D2;
};
} // namespace functor
......
......@@ -50,10 +50,10 @@ class ITK_EXPORT PersistentMosaicFilter : public otb::StreamingMosaicFilterBase<
{
public:
/** Standard typedefs */
typedef PersistentMosaicFilter Self;
typedef PersistentMosaicFilter Self;
typedef otb::StreamingMosaicFilterBase<TInputImage, TOutputImage, TPrecisionType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Creation through object factory macro */
itkTypeMacro(PersistentMosaicFilter, StreamingMosaicFilterBase);
......@@ -103,9 +103,13 @@ public:
protected:
/** Constructor */
PersistentMosaicFilter() {}
PersistentMosaicFilter()
{
}
/** Destructor */
~PersistentMosaicFilter() override {}
~PersistentMosaicFilter() override
{
}
/**PrintSelf method */
void PrintSelf(std::ostream& os, itk::Indent indent) const override
{
......@@ -113,11 +117,10 @@ protected:
}
private:
PersistentMosaicFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
PersistentMosaicFilter(const Self&); // purposely not implemented
void operator=(const Self&); // purposely not implemented
};
} // End namespace otb
#endif /* MODULES_REMOTE_MOSAIC_INCLUDE_OTBPERSISTENTMOSAICFILTER_H_ */
......@@ -29,7 +29,8 @@
#include <vnl/vnl_matrix.h>
#include "vnl/algo/vnl_solve_qp.h"
namespace otb {
namespace otb
{
/**
* \class QuadraticallyConstrainedSimpleSolver
......@@ -62,11 +63,10 @@ namespace otb {
* \ingroup OTBMosaic
*/
template<class ValueType>
template <class ValueType>
class ITK_EXPORT QuadraticallyConstrainedSimpleSolver : public itk::LightObject
{
public:
/** Standard class typedef */
typedef QuadraticallyConstrainedSimpleSolver Self;
typedef itk::LightObject Superclass;
......@@ -80,39 +80,66 @@ public:
itkNewMacro(Self);
/** Typedefs */
typedef vnl_matrix<ValueType> RealMatrixType;
typedef vnl_vector<ValueType> RealVectorType;
typedef vnl_matrix<double> DoubleMatrixType;
typedef vnl_vector<double> DoubleVectorType;
typedef std::vector <unsigned int> ListIndexType;
typedef vnl_matrix<ValueType> RealMatrixType;
typedef vnl_vector<ValueType> RealVectorType;
typedef vnl_matrix<double> DoubleMatrixType;
typedef vnl_vector<double> DoubleVectorType;
typedef std::vector<unsigned int> ListIndexType;
/** Enum for objective function type */
enum ObjectiveFunctionType
{
{
Cost_Function_rmse, // Root mean square error based
Cost_Function_musig, // Mean and standard deviation based
Cost_Function_mu, // Mean based
Cost_Function_weighted_musig // Mean and weighted standard deviation based
};
};
/** Mean-in-overlaps matrix */
void SetMeanInOverlaps(const RealMatrixType & matrix) { m_MeanInOverlaps = RealMatrixType(matrix); }
const RealMatrixType GetMeanInOverlaps() { return m_MeanInOverlaps; }
void SetMeanInOverlaps(const RealMatrixType& matrix)
{
m_MeanInOverlaps = RealMatrixType(matrix);
}
const RealMatrixType GetMeanInOverlaps()
{
return m_MeanInOverlaps;
}
/** Standard-deviation-in-overlaps matrix */
void SetStandardDeviationInOverlaps(const RealMatrixType & matrix) { m_StandardDeviationInOverlaps = RealMatrixType(matrix); }
const RealMatrixType GetStandardDeviationInOverlaps() { return m_StandardDeviationInOverlaps; }
void SetStandardDeviationInOverlaps(const RealMatrixType& matrix)
{
m_StandardDeviationInOverlaps = RealMatrixType(matrix);
}
const RealMatrixType GetStandardDeviationInOverlaps()
{
return m_StandardDeviationInOverlaps;
}
/** Area-in-overlaps matrix */
void SetAreaInOverlaps(const RealMatrixType & matrix) { m_AreaInOverlaps = RealMatrixType(matrix); }
const RealMatrixType GetAreaInOverlaps() { return m_AreaInOverlaps; }
void SetAreaInOverlaps(const RealMatrixType& matrix)
{
m_AreaInOverlaps = RealMatrixType(matrix);
}
const RealMatrixType GetAreaInOverlaps()
{
return m_AreaInOverlaps;
}
/** Mean-of-pixels-products-in-overlaps matrix */
void SetMeanOfProductsInOverlaps(const RealMatrixType & matrix) { m_MeanOfProductsInOverlaps = RealMatrixType(matrix); }
const RealMatrixType GetMeanOfProductsInOverlaps() { return m_MeanOfProductsInOverlaps; }
void SetMeanOfProductsInOverlaps(const RealMatrixType& matrix)
{
m_MeanOfProductsInOverlaps = RealMatrixType(matrix);
}
const RealMatrixType GetMeanOfProductsInOverlaps()
{
return m_MeanOfProductsInOverlaps;
}
/** Output correction model */
const RealVectorType GetOutputCorrectionModel() { return m_OutputCorrectionModel; }
const RealVectorType GetOutputCorrectionModel()
{
return m_OutputCorrectionModel;
}
/**
* STD weight in harmonization
......@@ -120,37 +147,53 @@ public:
* if value is 1, importance is the same than MEAN
* if value is higher than 1, importance is accorder to STD
*/
void SetWeightOfStandardDeviationTerm(ValueType weight) { m_WeightOfStandardDeviationTerm = weight; }
ValueType GetWeightOfStandardDeviationTerm() { return m_WeightOfStandardDeviationTerm; }
void SetWeightOfStandardDeviationTerm(ValueType weight)
{
m_WeightOfStandardDeviationTerm = weight;
}
ValueType GetWeightOfStandardDeviationTerm()
{
return m_WeightOfStandardDeviationTerm;
}
/** Solving routine */
void Solve();
/** Set the cost function type */
void SetMeanBased() { oft = Cost_Function_mu; }
void SetMeanAndStandardDeviationBased() { oft = Cost_Function_musig; }
void SetRMSEBased() { oft = Cost_Function_rmse; }
void SetWeightedMeanAndStandardDeviationBased() { oft = Cost_Function_weighted_musig; }
void SetMeanBased()
{
oft = Cost_Function_mu;
}
void SetMeanAndStandardDeviationBased()
{
oft = Cost_Function_musig;
}
void SetRMSEBased()
{
oft = Cost_Function_rmse;
}
void SetWeightedMeanAndStandardDeviationBased()
{
oft = Cost_Function_weighted_musig;
}
protected:
QuadraticallyConstrainedSimpleSolver();
virtual ~QuadraticallyConstrainedSimpleSolver();
private:
// Check inputs
void CheckInputs(void) const;
// Deep First Search
void DFS(std::vector<bool> & marked, unsigned int s) const;
void DFS(std::vector<bool>& marked, unsigned int s) const;
// Compute the objective matrix
const DoubleMatrixType GetQuadraticObjectiveMatrix(const DoubleMatrixType & areas,
const DoubleMatrixType & means, const DoubleMatrixType & stds, const DoubleMatrixType & mops);
const DoubleMatrixType GetQuadraticObjectiveMatrix(const DoubleMatrixType& areas, const DoubleMatrixType& means, const DoubleMatrixType& stds,
const DoubleMatrixType& mops);
// Extract a sub matrix from indices list
const DoubleMatrixType ExtractMatrix(const RealMatrixType & mat, const ListIndexType & idx);
const DoubleMatrixType ExtractMatrix(const RealMatrixType& mat, const ListIndexType& idx);
// Input
RealMatrixType m_MeanInOverlaps;
......@@ -166,7 +209,6 @@ private:
// objective funciton type (enum)
ObjectiveFunctionType oft;
};
} /* namespace otb */
......
......@@ -51,19 +51,15 @@ namespace otb
*
* \ingroup OTBMosaic
*/
template <class TInputImage, class TOutputImage, class TDistanceImage, class TInternalValueType=double>
class ITK_EXPORT StreamingFeatherMosaicFilter :
public StreamingMosaicFilterWithBlendingBase<TInputImage, TOutputImage, TDistanceImage, TInternalValueType>
template <class TInputImage, class TOutputImage, class TDistanceImage, class TInternalValueType = double>
class ITK_EXPORT StreamingFeatherMosaicFilter : public StreamingMosaicFilterWithBlendingBase<TInputImage, TOutputImage, TDistanceImage, TInternalValueType>
{
public:
/** Standard Self typedef */
typedef StreamingFeatherMosaicFilter Self;
typedef StreamingMosaicFilterWithBlendingBase<TInputImage, TOutputImage, TDistanceImage,
TInternalValueType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self>
ConstPointer;
typedef StreamingMosaicFilterWithBlendingBase<TInputImage, TOutputImage, TDistanceImage, TInternalValueType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
......@@ -106,18 +102,16 @@ public:
typedef typename Superclass::StreamingTraitsType StreamingTraitsType;
/** Distance image typedefs */
typedef TDistanceImage DistanceImageType;
typedef typename DistanceImageType::Pointer DistanceImagePointer;
typedef typename DistanceImageType::ConstPointer DistanceImageConstPointer;
typedef typename DistanceImageType::PointType DistanceImagePointType;
typedef typename DistanceImageType::PixelType DistanceImagePixelType;
typedef typename DistanceImageType::InternalPixelType DistanceImageInternalPixelType;
typedef typename DistanceImageType::RegionType DistanceImageRegionType;
typedef typename itk::InterpolateImageFunction<DistanceImageType>
DistanceImageInterpolatorType;
typedef typename itk::LinearInterpolateImageFunction<DistanceImageType>
DistanceImageDefaultInterpolatorType;
typedef typename DistanceImageInterpolatorType::Pointer DistanceImageInterpolatorPointer;
typedef TDistanceImage DistanceImageType;
typedef typename DistanceImageType::Pointer DistanceImagePointer;
typedef typename DistanceImageType::ConstPointer DistanceImageConstPointer;
typedef typename DistanceImageType::PointType DistanceImagePointType;
typedef typename DistanceImageType::PixelType DistanceImagePixelType;
typedef typename DistanceImageType::InternalPixelType DistanceImageInternalPixelType;
typedef typename DistanceImageType::RegionType DistanceImageRegionType;
typedef typename itk::InterpolateImageFunction<DistanceImageType> DistanceImageInterpolatorType;
typedef typename itk::LinearInterpolateImageFunction<DistanceImageType> DistanceImageDefaultInterpolatorType;
typedef typename DistanceImageInterpolatorType::Pointer DistanceImageInterpolatorPointer;
/** Feathering transition distance accessors */
itkSetMacro(FeatheringTransitionDistance, InternalValueType);
......@@ -129,11 +123,12 @@ public:
protected:
StreamingFeatherMosaicFilter();
virtual ~StreamingFeatherMosaicFilter() {
virtual ~StreamingFeatherMosaicFilter()
{
}
/** Overrided methods */
virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
virtual void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId);
private:
InternalValueType m_FeatheringTransitionDistance; // feathering transition
......
......@@ -25,32 +25,32 @@
#include "otbStreamingFeatherMosaicFilter.h"
namespace otb {
namespace otb
{
template <class TInputImage, class TOutputImage, class TDistanceImage, class TInternalValueType>
StreamingFeatherMosaicFilter<TInputImage, TOutputImage, TDistanceImage, TInternalValueType>
::StreamingFeatherMosaicFilter(){
StreamingFeatherMosaicFilter<TInputImage, TOutputImage, TDistanceImage, TInternalValueType>::StreamingFeatherMosaicFilter()
{
m_FeatheringTransitionDistance = 500;
m_FeatheringSmoothness = 1.5;
m_FeatheringSmoothness = 1.5;
}
/**
* Processing
*/
template <class TInputImage, class TOutputImage, class TDistanceImage, class TInternalValueType>
void
StreamingFeatherMosaicFilter<TInputImage, TOutputImage, TDistanceImage, TInternalValueType>
::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
void StreamingFeatherMosaicFilter<TInputImage, TOutputImage, TDistanceImage, TInternalValueType>::ThreadedGenerateData(
const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
{
// Debug info
itkDebugMacro(<<"Actually executing thread " << threadId << " in region " << outputRegionForThread);
itkDebugMacro(<< "Actually executing thread " << threadId << " in region " << outputRegionForThread);
// Support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels() );
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
// Get output pointer
OutputImageType * mosaicImage = this->GetOutput();
OutputImageType* mosaicImage = this->GetOutput();
// Get number of used inputs
const unsigned int nbOfUsedInputImages = Superclass::GetNumberOfUsedInputImages();
......@@ -62,12 +62,12 @@ StreamingFeatherMosaicFilter<TInputImage, TOutputImage, TDistanceImage, TInterna
IteratorType outputIt(mosaicImage, outputRegionForThread);
// Prepare input pointers, interpolators, and valid regions (input images)
typename std::vector<InputImageType *> currentImage;
typename std::vector<InputImageType*> currentImage;
typename std::vector<InterpolatorPointerType> interp;
Superclass::PrepareImageAccessors(currentImage, interp);
// Prepare input pointers, interpolators, and valid regions (distances images)
typename std::vector<DistanceImageType *> currentDistanceImage;
typename std::vector<DistanceImageType*> currentDistanceImage;
typename std::vector<DistanceImageInterpolatorPointer> distanceInterpolator;
Superclass::PrepareDistanceImageAccessors(currentDistanceImage, distanceInterpolator);
......@@ -85,10 +85,10 @@ StreamingFeatherMosaicFilter<TInputImage, TOutputImage, TDistanceImage, TInterna
unsigned int band, i;
for ( outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt )
{
for (outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt)
{
// Current pixel --> Geographical point
mosaicImage->TransformIndexToPhysicalPoint (outputIt.GetIndex(), geoPoint) ;
mosaicImage->TransformIndexToPhysicalPoint(outputIt.GetIndex(), geoPoint);
// Presence of at least one non-null pixel of the used input images
isDataInCurrentOutputPixel = false;
......@@ -97,103 +97,102 @@ StreamingFeatherMosaicFilter<TInputImage, TOutputImage, TDistanceImage, TInterna
tempOutputPixel.Fill(0.0);
// Loop on used input images
for (i = 0 ; i < nbOfUsedInputImages ; i++)
{
for (i = 0; i < nbOfUsedInputImages; i++)
{
// Check if the point is inside the transformed thread region
// (i.e. the region in the current input image which match the thread
// region)
if (interp[i]->IsInsideBuffer(geoPoint) )
{
if (interp[i]->IsInsideBuffer(geoPoint))
{
// Compute the interpolated pixel value
interpolatedPixel = interp[i]->Evaluate(geoPoint);
// Check that interpolated pixel is not empty
if (Superclass::IsPixelNotEmpty(interpolatedPixel) )
{
if (Superclass::IsPixelNotEmpty(interpolatedPixel))
{
// Geographical point (current pixel) --> Continuous index (from
// current input image)
if (distanceInterpolator[i]->IsInsideBuffer(geoPoint) )
{
if (distanceInterpolator[i]->IsInsideBuffer(geoPoint))
{
distanceImagePixel = distanceInterpolator[i]->Evaluate(geoPoint);
distanceImagePixel -= Superclass::GetDistanceOffset();
// Check that the distance is positive (i.e. we are inside the valid
// area of the image)
if (distanceImagePixel> 0 || !isDataInCurrentOutputPixel)
{
if (distanceImagePixel > 0 || !isDataInCurrentOutputPixel)
{
// Two possibility: distance < buffer or not
InternalValueType coef1, coef2;
if (distanceImagePixel<m_FeatheringTransitionDistance && isDataInCurrentOutputPixel)
{
if (distanceImagePixel < m_FeatheringTransitionDistance && isDataInCurrentOutputPixel)
{
// Feather the image
coef1 = distanceImagePixel/m_FeatheringTransitionDistance;
coef1 = vcl_pow(coef1,m_FeatheringSmoothness);
coef1 = distanceImagePixel / m_FeatheringTransitionDistance;
coef1 = vcl_pow(coef1, m_FeatheringSmoothness);
coef2 = 1.0 - coef1;
}
}
else
{
{