From d9a24459c6590286da860974bdb8fba9c7878f22 Mon Sep 17 00:00:00 2001 From: Patrick Imbo <patrick.imbo@c-s.fr> Date: Mon, 28 Aug 2006 09:22:56 +0000 Subject: [PATCH] =?UTF-8?q?OrientationPathFunction=20:=20impl=C3=A9mentati?= =?UTF-8?q?on=20de=20la=20classe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../otbOrientationPathFunction.h | 86 +++++++++++++++++ .../otbOrientationPathFunction.txx | 94 +++++++++++++++++++ Testing/Code/FeatureExtraction/CMakeLists.txt | 19 ++++ .../otbFeatureExtractionTests.cxx | 2 + .../FeatureExtraction/otbOrientationPath.cxx | 78 +++++++++++++++ .../otbOrientationPathNew.cxx | 51 ++++++++++ 6 files changed, 330 insertions(+) create mode 100644 Code/FeatureExtraction/otbOrientationPathFunction.h create mode 100644 Code/FeatureExtraction/otbOrientationPathFunction.txx create mode 100644 Testing/Code/FeatureExtraction/otbOrientationPath.cxx create mode 100644 Testing/Code/FeatureExtraction/otbOrientationPathNew.cxx diff --git a/Code/FeatureExtraction/otbOrientationPathFunction.h b/Code/FeatureExtraction/otbOrientationPathFunction.h new file mode 100644 index 0000000000..1ee838accf --- /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 0000000000..7211764c2e --- /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 1e4c82134d..b22d9dcb45 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 f546dff364..6b72909562 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 0000000000..72a7f32f27 --- /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 0000000000..fa23fc8634 --- /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; +} + -- GitLab