diff --git a/Code/FeatureExtraction/otbOrientationPathFunction.h b/Code/FeatureExtraction/otbOrientationPathFunction.h new file mode 100644 index 0000000000000000000000000000000000000000..1ee838accf2eacfdca5d1da3df409981fd0ad457 --- /dev/null +++ b/Code/FeatureExtraction/otbOrientationPathFunction.h @@ -0,0 +1,86 @@ +/*========================================================================= + + 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 _otbOrientationPathFunction_h +#define _otbOrientationPathFunction_h + +#include "otbOrientationPathFunction.h" +#include "otbPathFunction.h" +#include "itkVectorContainer.h" + +namespace otb +{ + +/** + * \class OrientaionPathFunction + * \brief Calculate the orientation angle of a path defined by 2 points. + * The result value is in radian. + * + * \ingroup PathFunctions + */ + +template < class TInputPath, + class TOutput = double> +class ITK_EXPORT OrientationPathFunction : + public PathFunction< TInputPath, TOutput > +{ +public: + /** Standard class typedefs. */ + typedef OrientationPathFunction Self; + typedef PathFunction<TInputPath, TOutput> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Run-time type information (and related methods). */ + itkTypeMacro(OrientationPathFunction, PathFunction); + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** InputPathType typedef support. */ + typedef typename Superclass::InputPathType PathType; + typedef typename Superclass::InputPathConstPointer PathConstPointer; + typedef typename PathType::ContinuousIndexType VertexType; + typedef itk::VectorContainer< unsigned,VertexType > VertexListType; + typedef typename VertexListType::ConstPointer VertexListPointer; + typedef TOutput OutputType; + + typedef double RealType; + + + /** Evaluate the function at non-integer positions */ + virtual OutputType Evaluate( const PathType& path) const; + virtual OutputType Evaluate( ) const; + +protected: + OrientationPathFunction(){}; + ~OrientationPathFunction(){}; + void PrintSelf(std::ostream& os, itk::Indent indent) const; + +private: + OrientationPathFunction( const Self& ); //purposely not implemented + void operator=( const Self& ); //purposely not implemented + +}; + +} // namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbOrientationPathFunction.txx" +#endif + +#endif diff --git a/Code/FeatureExtraction/otbOrientationPathFunction.txx b/Code/FeatureExtraction/otbOrientationPathFunction.txx new file mode 100644 index 0000000000000000000000000000000000000000..7211764c2e164d2a21e11fc21fee0f98ff3d34f7 --- /dev/null +++ b/Code/FeatureExtraction/otbOrientationPathFunction.txx @@ -0,0 +1,94 @@ +/*========================================================================= + + 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 _otbOrientationPathFunction_txx +#define _otbOrientationPathFunction_txx + +#include "otbPathFunction.h" +#include "itkNumericTraits.h" +#include "otbMacro.h" + +namespace otb +{ + +template < class TInputPath, class TOutput> +void +OrientationPathFunction< TInputPath, TOutput > +::PrintSelf(std::ostream& os, itk::Indent indent) const +{ + this->Superclass::PrintSelf(os,indent); +} + + + +template < class TInputPath, class TOutput> +typename OrientationPathFunction<TInputPath, + TOutput>::OutputType +OrientationPathFunction<TInputPath,TOutput> +::Evaluate(const PathType& path) const +{ + typedef double RealType; + + VertexListPointer vertexList; + VertexType cindex; + VertexType IndexOut; + int nbPath; + RealType Theta; + + vertexList = path.GetVertexList(); + nbPath = vertexList->Size(); + + if(nbPath ==2) + { + cindex = vertexList->GetElement(0); + RealType x1 = cindex[0]; + RealType y1 = cindex[1]; + cindex = vertexList->GetElement(1); + RealType x2 = cindex[0]; + RealType y2 = cindex[1]; + + Theta = atan2(y2-y1,x2-x1); + } // IF loop + else + { + itkExceptionMacro(<<"OrientationPathFunction::Evaluate() FAILED -- path must have 2 points"); + } + return (static_cast<OutputType>(Theta) ); + +} + +template < class TInputPath, class TOutput> +typename OrientationPathFunction<TInputPath, + TOutput>::OutputType +OrientationPathFunction<TInputPath,TOutput> +::Evaluate() const +{ + if( !this->GetInputPath() ) + { + otbMsgDevMacro( << "Problem with GetInputPath" ); + return static_cast<OutputType>(itk::NumericTraits<OutputType>::max() ); + } + + OutputType Result = Evaluate( *(this->GetInputPath()) ); + + return Result; +} + + +} // namespace otb + +#endif diff --git a/Testing/Code/FeatureExtraction/CMakeLists.txt b/Testing/Code/FeatureExtraction/CMakeLists.txt index 1e4c82134d30253ffe2602a16816742e02bf1258..b22d9dcb456b8de27d216dc24150854860e9a2ed 100755 --- a/Testing/Code/FeatureExtraction/CMakeLists.txt +++ b/Testing/Code/FeatureExtraction/CMakeLists.txt @@ -98,6 +98,23 @@ ADD_TEST(feTuFlusserPathNew ${FEATUREEXTRACTION_TESTS} ADD_TEST(feTuFlusserPath ${FEATUREEXTRACTION_TESTS} otbFlusserPath) + +# ------- otb::OrientationPathFunction ------------------------ + +ADD_TEST(feTuOrientationPathNew ${FEATUREEXTRACTION_TESTS} + otbOrientationPathNew) + +ADD_TEST(feTuOrientationPath_000 ${FEATUREEXTRACTION_TESTS} + otbOrientationPath 0.0) + +ADD_TEST(feTuOrientationPath_045 ${FEATUREEXTRACTION_TESTS} + otbOrientationPath 45.0) + +ADD_TEST(feTuOrientationPath_090 ${FEATUREEXTRACTION_TESTS} + otbOrientationPath 90.0) + +ADD_TEST(feTuOrientationPath1_80 ${FEATUREEXTRACTION_TESTS} + otbOrientationPath 180.0) # ------- otb::TouziEdgeDetector ------------------------------ @@ -370,6 +387,8 @@ otbHuPathNew.cxx otbHuPath.cxx otbFlusserPathNew.cxx otbFlusserPath.cxx +otbOrientationPathNew.cxx +otbOrientationPath.cxx otbTouziEdgeDetectorNew.cxx otbTouziEdgeDetector.cxx otbTouziEdgeDetectorDirection.cxx diff --git a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx index f546dff364ed8e8f8f2352820c3daf3b3b1f56d8..6b72909562447ef2a287688f194762285cc82369 100755 --- a/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx +++ b/Testing/Code/FeatureExtraction/otbFeatureExtractionTests.cxx @@ -42,6 +42,8 @@ REGISTER_TEST(otbHuPathNew); REGISTER_TEST(otbHuPath); REGISTER_TEST(otbFlusserPathNew); REGISTER_TEST(otbFlusserPath); +REGISTER_TEST(otbOrientationPathNew); +REGISTER_TEST(otbOrientationPath); REGISTER_TEST(otbTouziEdgeDetectorNew); REGISTER_TEST(otbTouziEdgeDetector); REGISTER_TEST(otbTouziEdgeDetectorDirection); diff --git a/Testing/Code/FeatureExtraction/otbOrientationPath.cxx b/Testing/Code/FeatureExtraction/otbOrientationPath.cxx new file mode 100644 index 0000000000000000000000000000000000000000..72a7f32f27b96a1c33b9ffe730f2732723ee536e --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbOrientationPath.cxx @@ -0,0 +1,78 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbOrientationPathFunction.h" +#include "itkPolyLineParametricPath.h" +#include "itkExceptionObject.h" + +int otbOrientationPath( int argc, char * argv[] ) +{ + try + { + double Theta((double)::atof(argv[1])); + + unsigned int Number; + const unsigned int Dimension = 2; + typedef itk::PolyLineParametricPath< Dimension > PathType; + typedef otb::OrientationPathFunction<PathType> FunctionType; + typedef FunctionType::RealType RealType; + + PathType::ContinuousIndexType cindex; + PathType::Pointer pathElt = PathType::New(); + + Theta *= acos(-1.0)/180.; + + pathElt->Initialize(); + + cindex[0]=30; + cindex[1]=30; + pathElt->AddVertex(cindex); + cindex[0] += 100 * cos(Theta); + cindex[1] += 100 * sin(Theta); + pathElt->AddVertex(cindex); + + FunctionType::Pointer function =FunctionType::New(); + function->SetInputPath( pathElt ); + + RealType ResultTheta = function->Evaluate(); + std::cout << "Orientation found : " << ResultTheta <<std::endl; + if( ResultTheta != Theta ) + { + std::cout << "Error in Theta estimation :" << std::endl; + return EXIT_FAILURE; + } + + } + catch( itk::ExceptionObject & err ) + { + std::cout << "itk::ExceptionObject catch !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + catch( ... ) + { + std::cout << "unknown Exception catch !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} + diff --git a/Testing/Code/FeatureExtraction/otbOrientationPathNew.cxx b/Testing/Code/FeatureExtraction/otbOrientationPathNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..fa23fc86348827801f907debe92326fa0a4d5920 --- /dev/null +++ b/Testing/Code/FeatureExtraction/otbOrientationPathNew.cxx @@ -0,0 +1,51 @@ +/*========================================================================= + + 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. + +=========================================================================*/ + +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#include "otbOrientationPathFunction.h" +#include "itkPolyLineParametricPath.h" +#include "itkExceptionObject.h" + +int otbOrientationPathNew( int argc, char * argv[] ) +{ + try + { + const unsigned int Dimension = 2; + typedef itk::PolyLineParametricPath< Dimension > PathType; + typedef otb::OrientationPathFunction<PathType> FunctionType; + + FunctionType::Pointer function =FunctionType::New(); + + } + catch( itk::ExceptionObject & err ) + { + std::cout << "itk::ExceptionObject catch !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + catch( ... ) + { + std::cout << "Unknown exception catch !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} +