From 33c8015472a312b222f134f05d9daf3c2e56494e Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Sat, 7 May 2011 18:04:02 -0700 Subject: [PATCH] ENH: Cleanup code --- Code/Common/otbCommandLineArgumentParser.cxx | 3 +- Code/Common/otbCommandLineArgumentParser.h | 6 - Code/Common/otbExtractROIBase.txx | 114 +++++++++---------- Code/Learning/otbSVMKernels.h | 47 ++++---- 4 files changed, 77 insertions(+), 93 deletions(-) diff --git a/Code/Common/otbCommandLineArgumentParser.cxx b/Code/Common/otbCommandLineArgumentParser.cxx index f360846df4..feea223fd4 100644 --- a/Code/Common/otbCommandLineArgumentParser.cxx +++ b/Code/Common/otbCommandLineArgumentParser.cxx @@ -16,10 +16,11 @@ =========================================================================*/ #include "otbCommandLineArgumentParser.h" -#include "itkMacro.h" #include <assert.h> #include <iostream> + +#include "itkMacro.h" #include "otbConfigure.h" // For OTB_VERSION_STRING generated by ccmake namespace otb diff --git a/Code/Common/otbCommandLineArgumentParser.h b/Code/Common/otbCommandLineArgumentParser.h index 10526ef19b..8b75d6dd3f 100644 --- a/Code/Common/otbCommandLineArgumentParser.h +++ b/Code/Common/otbCommandLineArgumentParser.h @@ -18,16 +18,10 @@ #ifndef __otbCommandLineArgumentParser_h #define __otbCommandLineArgumentParser_h -#if defined(_MSC_VER) -#pragma warning ( disable : 4786 ) -#pragma warning ( disable : 4503 ) -#endif - #include <iostream> #include <vector> #include <string> #include <map> -#include <cstdlib> #include "itkProcessObject.h" #include "otbMacro.h" diff --git a/Code/Common/otbExtractROIBase.txx b/Code/Common/otbExtractROIBase.txx index 75b537654c..da4dbf9ff1 100644 --- a/Code/Common/otbExtractROIBase.txx +++ b/Code/Common/otbExtractROIBase.txx @@ -234,86 +234,82 @@ ExtractROIBase<TInputImage, TOutputImage> phyData = dynamic_cast<const itk::ImageBase<InputImageDimension>*>(this->GetInput()); - if (phyData) + if (!phyData) { - // Copy what we can from the image from spacing and origin of the input - // This logic needs to be augmented with logic that select which - // dimensions to copy - unsigned int i; - const typename InputImageType::SpacingType& + // pointer could not be cast back down + itkExceptionMacro(<< "otb::ExtractROIBase::GenerateOutputInformation " + << "cannot cast input to " + << typeid(itk::ImageBase<InputImageDimension>*).name()); + } + + // Copy what we can from the image from spacing and origin of the input + // This logic needs to be augmented with logic that select which + // dimensions to copy + const typename InputImageType::SpacingType& inputSpacing = inputPtr->GetSpacing(); - const typename InputImageType::DirectionType& + const typename InputImageType::DirectionType& inputDirection = inputPtr->GetDirection(); - const typename InputImageType::PointType& + const typename InputImageType::PointType& inputOrigin = inputPtr->GetOrigin(); - typename OutputImageType::SpacingType outputSpacing; - typename OutputImageType::DirectionType outputDirection; - typename OutputImageType::PointType outputOrigin; + typename OutputImageType::SpacingType outputSpacing; + typename OutputImageType::DirectionType outputDirection; + typename OutputImageType::PointType outputOrigin; - if (static_cast<unsigned int>(OutputImageDimension) > - static_cast<unsigned int>(InputImageDimension)) + if (static_cast<unsigned int>(OutputImageDimension) > + static_cast<unsigned int>(InputImageDimension)) + { + unsigned int i; + // copy the input to the output and fill the rest of the + // output with zeros. + for (i = 0; i < InputImageDimension; ++i) { - // copy the input to the output and fill the rest of the - // output with zeros. - for (i = 0; i < InputImageDimension; ++i) + outputSpacing[i] = inputSpacing[i]; + outputOrigin[i] = inputOrigin[i] + static_cast<double>(m_ExtractionRegion.GetIndex()[i]) * outputSpacing[i]; + for (unsigned int dim = 0; dim < InputImageDimension; ++dim) { - outputSpacing[i] = inputSpacing[i]; - outputOrigin[i] = inputOrigin[i] + static_cast<double>(m_ExtractionRegion.GetIndex()[i]) * outputSpacing[i]; - for (unsigned int dim = 0; dim < InputImageDimension; ++dim) - { - outputDirection[i][dim] = inputDirection[i][dim]; - } + outputDirection[i][dim] = inputDirection[i][dim]; } - for (; i < OutputImageDimension; ++i) + } + for (; i < OutputImageDimension; ++i) + { + outputSpacing[i] = 1.0; + outputOrigin[i] = 0.0; + for (unsigned int dim = 0; dim < InputImageDimension; ++dim) { - outputSpacing[i] = 1.0; - outputOrigin[i] = 0.0; - for (unsigned int dim = 0; dim < InputImageDimension; ++dim) - { - outputDirection[i][dim] = 0.0; - } - outputDirection[i][i] = 1.0; + outputDirection[i][dim] = 0.0; } + outputDirection[i][i] = 1.0; } - else + } + else + { + // copy the non-collapsed part of the input spacing and origing to the output + int nonZeroCount = 0; + for (unsigned int i = 0; i < InputImageDimension; ++i) { - // copy the non-collapsed part of the input spacing and origing to the output - int nonZeroCount = 0; - for (i = 0; i < InputImageDimension; ++i) + if (m_ExtractionRegion.GetSize()[i] == 0) continue; + + outputSpacing[nonZeroCount] = inputSpacing[i]; + outputOrigin[nonZeroCount] = inputOrigin[i] + static_cast<double>(m_ExtractionRegion.GetIndex()[i]) * + outputSpacing[i]; + for (unsigned int dim = 0; dim < OutputImageDimension; ++dim) { - if (m_ExtractionRegion.GetSize()[i]) - { - outputSpacing[nonZeroCount] = inputSpacing[i]; - outputOrigin[nonZeroCount] = inputOrigin[i] + static_cast<double>(m_ExtractionRegion.GetIndex()[i]) * - outputSpacing[i]; - for (unsigned int dim = 0; dim < OutputImageDimension; ++dim) - { - outputDirection[nonZeroCount][dim] = - inputDirection[nonZeroCount][dim]; - } - nonZeroCount++; - } + outputDirection[nonZeroCount][dim] = + inputDirection[nonZeroCount][dim]; } + nonZeroCount++; } + } - // set the spacing and origin - outputPtr->SetSpacing(outputSpacing); - outputPtr->SetDirection(outputDirection); - outputPtr->SetOrigin(outputOrigin); + // set the spacing and origin + outputPtr->SetSpacing(outputSpacing); + outputPtr->SetDirection(outputDirection); + outputPtr->SetOrigin(outputOrigin); // THOMAS : dans ITK ce code est present, mais pas dans notre cas, car le nombre de composantes/pixel depend des canaux selectionnes par l'utilisateur // ce parametre est renseignes dans les classes sous-jacentes // outputPtr->SetNumberOfComponentsPerPixel( // inputPtr->GetNumberOfComponentsPerPixel() ); - } - else - { - // pointer could not be cast back down - itkExceptionMacro(<< "otb::ExtractROIBase::GenerateOutputInformation " - << "cannot cast input to " - << typeid(itk::ImageBase<InputImageDimension>*).name()); - } - } } // end namespace otb diff --git a/Code/Learning/otbSVMKernels.h b/Code/Learning/otbSVMKernels.h index c14b3b3a46..9fc82be88c 100644 --- a/Code/Learning/otbSVMKernels.h +++ b/Code/Learning/otbSVMKernels.h @@ -18,6 +18,10 @@ #ifndef __otbSVMKernels_h #define __otbSVMKernels_h +#include <vector> +#include <algorithm> // for std::find +#include <string.h> // for strpbrk + #include "itkNumericTraits.h" #include "otbMath.h" @@ -28,9 +32,6 @@ #include "otbMixturePolyRBFKernelFunctor.h" #include "svm.h" -#include <vector> -#include <algorithm> // for std::find -#include <string.h> // for strpbrk namespace otb { @@ -98,7 +99,7 @@ public: virtual double operator ()(const svm_node *x, const svm_node *y, const svm_parameter& param) const { - double mq = this->GetValue<double>("const_coef") + m_Custom(x, y, param); + double mq = this->GetValue<double>("const_coef") + m_Custom(x, y, param); if (mq == 0.0) { return itk::NumericTraits<double>::max(); @@ -329,7 +330,7 @@ public: virtual double operator ()(const svm_node *x, const svm_node *y, const svm_parameter& param) const { - double mq = this->GetValue<double>("const_coef") + m_Sam(x, y, param); + double mq = this->GetValue<double>("const_coef") + m_Sam(x, y, param); if (mq == 0.) { @@ -379,7 +380,7 @@ public: virtual double operator ()(const svm_node *x, const svm_node *y, const svm_parameter& param) const { - double mq = this->GetValue<double>("const_coef") + m_Sam(x, y, param); + double mq = this->GetValue<double>("const_coef") + m_Sam(x, y, param); if (mq == 0.) { @@ -429,7 +430,7 @@ public: virtual double operator ()(const svm_node *x, const svm_node *y, const svm_parameter& param) const { - double res = this->GetValue<double>("gamma_coef") * m_Custom(x, y, param); + double res = this->GetValue<double>("gamma_coef") * m_Custom(x, y, param); return vcl_exp(-res); } @@ -498,10 +499,8 @@ public: break; default: return (-2 * gamma * - ((degree - - 1) * - this->derivative(x, y, param, degree - 2, index, isAtEnd, - constValue) + + ((degree - 1) * + this->derivative(x, y, param, degree - 2, index, isAtEnd, constValue) + (yval - xval) * derivative(x, y, param, degree - 1, index, isAtEnd, constValue))); break; } @@ -577,8 +576,8 @@ private: class PolyRBFSAMKernelFunctor : public GenericKernelFunctorBase { public: - typedef PolyRBFSAMKernelFunctor Self; - typedef GenericKernelFunctorBase Superclass; + typedef PolyRBFSAMKernelFunctor Self; + typedef GenericKernelFunctorBase Superclass; PolyRBFSAMKernelFunctor() : GenericKernelFunctorBase() { @@ -624,8 +623,8 @@ private: class RBFDiffKernelFunctor : public GenericKernelFunctorBase { public: - typedef RBFDiffKernelFunctor Self; - typedef GenericKernelFunctorBase Superclass; + typedef RBFDiffKernelFunctor Self; + typedef GenericKernelFunctorBase Superclass; RBFDiffKernelFunctor() : GenericKernelFunctorBase() { @@ -654,14 +653,8 @@ public: } else { - if (x->index < y->index) - { - ++x; - } - else - { - ++y; - } + if (x->index < y->index) ++x; + else ++y; } } return total; @@ -785,13 +778,13 @@ public: while (xBuff->index != 1) { - sizeX++; + ++sizeX; ++xBuff; } while (yBuff->index != 1) { - sizeY++; + ++sizeY; ++yBuff; } @@ -967,13 +960,13 @@ public: while (xBuff->index != 1) { - sizeX++; + ++sizeX; ++xBuff; } while (yBuff->index != 1) { - sizeY++; + ++sizeY; ++yBuff; } -- GitLab