diff --git a/Code/Common/otbDrawPathListFilter.h b/Code/Common/otbDrawPathListFilter.h index 833129e53d89ff70bd5f5f01d0c8c067b34f0811..e05ce2d24cede89f5cdaa536f532365cb5f36db6 100644 --- a/Code/Common/otbDrawPathListFilter.h +++ b/Code/Common/otbDrawPathListFilter.h @@ -18,27 +18,42 @@ #ifndef __otbDrawPathListFilter_h #define __otbDrawPathListFilter_h -#include "otbPathListSource.h" -#include "itkImageSource.h" +#include "itkImageToImageFilter.h" #include "itkConceptChecking.h" +#include "otbObjectList.h" namespace otb { /** \class DrawPathListFilter - * \brief Classe de base pour inserer dans une image les segments de lignes dans une image. + * \brief This class can be used to draw Path on an image. * + * This filter first copy the input image to the output, with default casting operators. + * It then uses itk::LineIterator to draw each segment of each PolyLine. This iterator uses + * the general Bresenham algorithm known to be efficient in segment drawing. * + * Please note that the method SetInputPath accepts two types of input. The first is of type + * otb::ObjectList<TInputPath>. The second is of type TInputPath* and is provided for convenience only. + * In this case the path is simply added to a new otb::ObjectList<TInputPath> and passed to the conventional + * method. + * + * If the UsePathInternalValue is toggled, the filter check if the metadata dictionnary of the input path has a "Value" key. + * If it is the case, it will use this value to draw the Path instead of the default value. If not, it will use the default + * value. + * + * \sa PolyLineParametricPathWithValue + * \sa MetaDataDictionary + * * \ingroup PathListFilters * \ingroup PathLists */ template <class TInputImage, class TInputPath,class TOutputImage> -class ITK_EXPORT DrawPathListFilter : public PathListSource<TInputPath> +class ITK_EXPORT DrawPathListFilter : public itk::ImageToImageFilter<TInputImage,TOutputImage> { public: /** Standard class typedefs. */ typedef DrawPathListFilter Self; - typedef PathListSource<TInputPath> Superclass; + typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; @@ -46,7 +61,7 @@ public: itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro(DrawPathListFilter, PathListSource); + itkTypeMacro(DrawPathListFilter,ImageToImageFilter); /** Some convenient typedefs. */ typedef TInputImage InputImageType; @@ -57,12 +72,12 @@ public: typedef typename InputImageType::SizeType InputImageSizeType; typedef typename InputImageType::ValueType InputImageValueType; - typedef typename Superclass::OutputPathType InputPathType; - typedef typename Superclass::OutputPathListType InputPathListType; - typedef typename Superclass::OutputPathListPointerType InputPathListPointerType; - typedef typename Superclass::OutputPathListConstPointerType InputPathListConstPointerType; - - + typedef TInputPath InputPathType; + typedef typename InputPathType::Pointer InputPathPointerType; + typedef otb::ObjectList<InputPathType> InputPathListType; + typedef typename InputPathListType::ConstPointer InputPathListConstPointerType; + typedef typename InputPathListType::Pointer InputPathListPointerType; + typedef TOutputImage OutputImageType; typedef typename OutputImageType::Pointer OutputImagePointerType; typedef typename OutputImageType::ConstPointer OutputImageConstPointerType; @@ -71,40 +86,39 @@ public: typedef typename OutputImageType::SizeType OutputImageSizeType; typedef typename OutputImageType::ValueType OutputImageValueType; typedef typename OutputImageType::IndexType OutputImageIndexType; - - typedef itk::ProcessObject ProcessObjectType; + + typedef itk::ProcessObject ProcessObjectType; + + itkGetMacro(UseInternalPathValue,bool); + itkSetMacro(UseInternalPathValue,bool); + itkBooleanMacro(UseInternalPathValue); /** ImageDimension constants */ itkStaticConstMacro(InputImageDimension, unsigned int, TInputImage::ImageDimension); - /** Set/Get the image input of this process object. */ - virtual void SetImageInput(const InputImageType *image); - const InputImageType * GetImageInput(void); - /** Set/Get the path input of this process object. */ - virtual void SetPathInput(InputPathListType *path); - InputPathListType * GetPathInput(void); - - /** Get the image output of this process object. */ - virtual void SetImageOutput(OutputImageType *image); - OutputImageType * GetImageOutput(void); + virtual void SetInputPath(InputPathListType *path); + InputPathListType * GetInputPath(void); + virtual void SetInputPath(InputPathType * path); protected: + /** Constructor */ DrawPathListFilter(); + /** Desctructor */ virtual ~DrawPathListFilter() {}; - + /** Printself method */ virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; + /** Main computation method */ virtual void GenerateData(); private: DrawPathListFilter(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented - OutputImagePixelType m_PathValue; - - - InputPathListType * m_PathList; - + /** Default value to draw */ + OutputImagePixelType m_PathValue; + /** If set to true, the algorithm try to use path internal metadatadictionnary value */ + bool m_UseInternalPathValue; }; } // end namespace otb diff --git a/Code/Common/otbDrawPathListFilter.txx b/Code/Common/otbDrawPathListFilter.txx index bfa5985e074b0f4af9c7f4795de7361b8e94eb5b..6fa2de57b4427eb956a24d07876df67af6ffcdd8 100644 --- a/Code/Common/otbDrawPathListFilter.txx +++ b/Code/Common/otbDrawPathListFilter.txx @@ -21,259 +21,126 @@ #include "otbDrawPathListFilter.h" -#include "itkContinuousIndex.h" -#include "itkVectorContainer.h" -#include "itkImage.h" -#include "itkImageIteratorWithIndex.h" -#include "itkImageConstIteratorWithIndex.h" -#include "itkImageIteratorWithIndex.h" -#include "itkImageRegionIteratorWithIndex.h" -#include "itkImageRegionConstIteratorWithIndex.h" -#include "otbMacro.h" +#include "itkImageRegionIterator.h" +#include "itkImageRegionConstIterator.h" +#include "itkLineIterator.h" +#include "itkMetaDataObject.h" + namespace otb { - /** - * + * Constructor */ template <class TInputImage, class TInputPath,class TOutputImage> DrawPathListFilter<TInputImage,TInputPath,TOutputImage> ::DrawPathListFilter() { - // Modify superclass default values, can be overridden by subclasses -// this->SetNumberOfRequiredInputs(2); -// this->SetNumberOfRequiredOutputs(1); - m_PathValue = static_cast<OutputImagePixelType>(250.0); -} - -/** - * - */ -template <class TInputImage, class TInputPath,class TOutputImage> -void -DrawPathListFilter<TInputImage,TInputPath,TOutputImage> -::SetImageInput(const InputImageType *image) -{ - this->ProcessObjectType::SetNthInput(0, - const_cast< InputImageType * >( image ) ); + this->SetNumberOfRequiredInputs(2); + this->SetNumberOfRequiredOutputs(1); + m_PathValue = static_cast<OutputImagePixelType>(255.0); + m_UseInternalPathValue = false; } template <class TInputImage, class TInputPath,class TOutputImage> -const typename DrawPathListFilter<TInputImage,TInputPath,TOutputImage>::InputImageType * +void DrawPathListFilter<TInputImage,TInputPath,TOutputImage> -::GetImageInput(void) +::SetInputPath( InputPathListType *path) { - if (this->GetNumberOfInputs() < 2) - { - return 0; - } - - return static_cast<const InputImageType *> - (this->ProcessObjectType::GetInput(0) ); + this->ProcessObjectType::SetNthInput(1,const_cast<InputPathListType *>(path)); } - template <class TInputImage, class TInputPath,class TOutputImage> void DrawPathListFilter<TInputImage,TInputPath,TOutputImage> -::SetPathInput( InputPathListType *path) +::SetInputPath( InputPathType * path) { -// this->ProcessObjectType::SetNthInput(1, -// const_cast< InputPathListType * >( path ) ); - -// Attention: A modifier - this->ProcessObjectType::SetNthInput(1,NULL); - m_PathList = path; + InputPathListPointerType list = InputPathListType::New(); + list->PushBack(path); + this->ProcessObjectType::SetNthInput(1,static_cast<InputPathListType *>(list)); } - template <class TInputImage, class TInputPath,class TOutputImage> typename DrawPathListFilter<TInputImage,TInputPath,TOutputImage>::InputPathListType * DrawPathListFilter<TInputImage,TInputPath,TOutputImage> -::GetPathInput(void) +::GetInputPath(void) { if (this->GetNumberOfInputs() < 2) { return 0; } - InputPathListType * ptr; -// ptr = this->otb::PathListSource::GetOutput(); - ptr = this->GetOutput(); - - return (ptr); - -// return static_cast<const TInputPath * > -// (this->ProcessObjectType::GetInput(1) ); -} - - - -template <class TInputImage, class TInputPath,class TOutputImage> -void -DrawPathListFilter<TInputImage,TInputPath,TOutputImage> -::SetImageOutput(OutputImageType *image) -{ - this->ProcessObjectType::SetNthOutput(0, - static_cast< OutputImageType * >( image ) ); -} - - -template <class TInputImage, class TInputPath,class TOutputImage> -typename DrawPathListFilter<TInputImage,TInputPath,TOutputImage>::OutputImageType * -DrawPathListFilter<TInputImage,TInputPath,TOutputImage> -::GetImageOutput(void) -{ - if (this->GetNumberOfOutputs() < 1) - { - return 0; - } - - return static_cast<OutputImageType * > - (this->ProcessObjectType::GetOutput(0) ); + return static_cast<const InputPathListType *>(this->ProcessObjectType::GetInput(1)); } - - +/** + * Main computation method + */ template <class TInputImage, class TInputPath,class TOutputImage> void DrawPathListFilter<TInputImage,TInputPath,TOutputImage> ::GenerateData(void) { - OutputImagePointerType OutputImage = OutputImageType::New(); - this->SetImageOutput(OutputImage); - - - - InputImageConstPointerType InputImage = this->GetImageInput(); -// InputPathListPointerType InputPath = this->GetPathInput(); - InputPathListPointerType InputPath = m_PathList; -// OutputImagePointerType OutputImage = this->GetImageOutput(); - - InputImageSizeType Taille; - OutputImageIndexType IndexOut; - typedef double RealType; - typedef typename InputPathType::ContinuousIndexType VertexType; -// typedef itk::ContinuousIndex<RealType,2> VertexType; - typedef itk::VectorContainer< unsigned,VertexType > VertexListType; - typedef typename VertexListType::ConstPointer VertexListTypePointer; - typedef itk::ImageRegionIteratorWithIndex< OutputImageType > OutputIteratorType; - typedef itk::ImageRegionConstIteratorWithIndex< InputImageType > InputIteratorType; - - VertexListTypePointer vertexList; - VertexType cindex; - Taille = InputImage->GetLargestPossibleRegion().GetSize(); - - - typename OutputImageType::RegionType region; - - region.SetSize(InputImage->GetLargestPossibleRegion().GetSize()); - region.SetIndex(InputImage->GetLargestPossibleRegion().GetIndex()); - OutputImage->SetRegions( region ); - OutputImage->SetOrigin(InputImage->GetOrigin()); - OutputImage->SetSpacing(InputImage->GetSpacing()); - OutputImage->Allocate(); - - OutputIteratorType outputIt( OutputImage, OutputImage->GetRequestedRegion() ); - InputIteratorType inputIt( InputImage, OutputImage->GetRequestedRegion() ); - - outputIt.GoToBegin(); - inputIt.GoToBegin(); - - for ( outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt,++inputIt) + OutputImagePointerType outputPtr = this->GetOutput(); + InputImageConstPointerType inputPtr = this->GetInput(); + InputPathListConstPointerType pathListPtr = this->GetInputPath(); + outputPtr->SetRegions(inputPtr->GetLargestPossibleRegion()); + outputPtr->Allocate(); + outputPtr->FillBuffer(0); + + // First, we copy input to output + typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType; + typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType; + typedef typename InputPathListType::ConstIterator PathListIteratorType; + typedef itk::LineIterator<OutputImageType> LineIteratorType; + typedef typename InputPathType::VertexListType VertexListType; + typedef typename VertexListType::ConstIterator VertexIteratorType; + + OutputIteratorType outIt(outputPtr,outputPtr->GetLargestPossibleRegion()); + InputIteratorType inIt(inputPtr,inputPtr->GetLargestPossibleRegion()); + + for(outIt.GoToBegin(),inIt.GoToBegin(); + (!outIt.IsAtEnd() && !inIt.IsAtEnd()); + ++outIt,++inIt) { - outputIt.Set( inputIt.Get() ); + outIt.Set(static_cast<OutputImagePixelType>(inIt.Get())); } - - int nbPath = InputPath->Size(); - otbMsgDevMacro( <<"nbPath: " <<nbPath); - - for(int i =0 ; i<nbPath ;i++) - { - vertexList = InputPath->GetNthElement(i)->GetVertexList(); - cindex = vertexList->GetElement(0); - RealType x1 = cindex[0]; - RealType y1 = cindex[1]; - cindex = vertexList->GetElement(1); - RealType x2 = cindex[0]; - RealType y2 = cindex[1]; - - /*RealType DeltaX = std::abs(x1-x2); - RealType DeltaY = std::abs(y1-y2); - RealType Xmin = std::min( x1 , x2 ); - RealType Xmax = std::max( x1 , x2 ); - RealType Ymin = std::min( y1 , y2 ); - RealType Ymax = std::max( y1 , y2 );*/ - RealType DeltaX = fabs(x1-x2); - RealType DeltaY = fabs(y1-y2); - RealType Xmin = x1<x2 ? x1 : x2; - RealType Xmax = x1>x2 ? x1 : x2; - RealType Ymin = y1<y2 ? y1 : y2; - RealType Ymax = y1>y2 ? y1 : y2; - - if(DeltaX>0 && DeltaY>0) - { - if(DeltaX>DeltaY) - { - RealType Alpha = (y2-y1) / (x2-x1) ; - for(RealType j = Xmin; j<=Xmax;j++) - { - IndexOut[0] = static_cast<int>(j) ; - IndexOut[1] = static_cast<int>(Alpha * (j-x1) + y1) ; - if(IndexOut[0]>=0 && IndexOut[0]<(int)Taille[0] && - IndexOut[1]>=0 && IndexOut[1]<(int)Taille[1]) - OutputImage->SetPixel(IndexOut,m_PathValue); - } - } - else - { - RealType Alpha = (x2-x1) / (y2-y1) ; - for(RealType j = Ymin; j<=Ymax;j++) + // Then we use itk::LineIterator to draw polylines + OutputImageIndexType source, target; + VertexIteratorType vertexIt; + OutputImagePixelType value; + for(PathListIteratorType plIt = pathListPtr->Begin(); plIt!=pathListPtr->End();++plIt) + { + if(m_UseInternalPathValue && plIt.Get()->GetMetaDataDictionary().HasKey("Value")) + { + itk::ExposeMetaData<OutputImagePixelType>(plIt.Get()->GetMetaDataDictionary(),"Value",value); + } + else + { + value = static_cast<OutputImagePixelType>(m_PathValue); + } + vertexIt = plIt.Get()->GetVertexList()->Begin(); + source[0] = static_cast<unsigned int>( (vertexIt.Value())[0]); + source[1] = static_cast<unsigned int>( (vertexIt.Value())[1]); + ++vertexIt; + while(vertexIt!=plIt.Get()->GetVertexList()->End()) + { + target[0]=static_cast<unsigned int>((vertexIt.Value())[0]); + target[1]=static_cast<unsigned int>((vertexIt.Value())[1]); + LineIteratorType lineIt(outputPtr,source,target); + lineIt.GoToBegin(); + while(!lineIt.IsAtEnd()) { - IndexOut[0] = static_cast<int>(Alpha * (j-y1) + x1) ; - IndexOut[1] = static_cast<int>(j); - if(IndexOut[0]>=0 && IndexOut[0]<(int)Taille[0] && - IndexOut[1]>=0 && IndexOut[1]<(int)Taille[1]) - OutputImage->SetPixel(IndexOut,m_PathValue); + lineIt.Set(value); + ++lineIt; } - - } - } - else - { - if(DeltaX>0) - { - IndexOut[1] = static_cast<int>(Ymin); - for(RealType j = Xmin; j<=Xmax;j++) - { - IndexOut[0]=static_cast<int>(j); - if(IndexOut[0]>=0 && IndexOut[0]<(int)Taille[0] && - IndexOut[1]>=0 && IndexOut[1]<(int)Taille[1]) - OutputImage->SetPixel(IndexOut,m_PathValue); - - } - } - else - { - IndexOut[0] = static_cast<int>(Xmin); - for(RealType j = Ymin; j<=Ymax;j++) - { - IndexOut[1]=static_cast<int>(j); - if(IndexOut[0]>=0 && IndexOut[0]<(int)Taille[0] && - IndexOut[1]>=0 && IndexOut[1]<(int)Taille[1]) - OutputImage->SetPixel(IndexOut,m_PathValue); - } - } - } - } - - + source=target; + ++vertexIt; + } + } } - - /** - * + * Printself method */ template <class TInputImage, class TInputPath,class TOutputImage> void @@ -282,8 +149,6 @@ DrawPathListFilter<TInputImage,TInputPath,TOutputImage> { Superclass::PrintSelf(os, indent); } - - } // end namespace otb #endif diff --git a/Code/Common/otbPolyLineParametricPathWithValue.h b/Code/Common/otbPolyLineParametricPathWithValue.h new file mode 100644 index 0000000000000000000000000000000000000000..67ac024cde31ddcbd7913dd709e7c9b5d3b7b42b --- /dev/null +++ b/Code/Common/otbPolyLineParametricPathWithValue.h @@ -0,0 +1,97 @@ +/*========================================================================= + +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 _otbPolyLineParametricPathWithValue_h +#define _otbPolyLineParametricPathWithValue_h + +#include "itkPolyLineParametricPath.h" +#include "itkMetaDataObject.h" +#include "otbMacro.h" + +namespace otb +{ +/** \class PolyLineParametricPathWithValue + * \brief + * + * \ingroup + * \ingroup + */ +template < class TValue,unsigned int VDimension=2> +class ITK_EXPORT PolyLineParametricPathWithValue + : public itk::PolyLineParametricPath<VDimension> +{ + public: + /** Standard typedefs */ + typedef PolyLineParametricPathWithValue Self; + typedef itk::PolyLineParametricPath<VDimension> Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + + /** Type macro */ + itkNewMacro(Self); + + /** Creation through object factory macro */ + itkTypeMacro(PolyLineParametricPath, MySuperclass); + + /** Template parameters typedefs */ + typedef TValue ValueType; + + itkGetMacro(Key,std::string); + + void SetValue(ValueType value) + { + itk::MetaDataDictionary & dict = this->GetMetaDataDictionary(); + itk::EncapsulateMetaData<ValueType>(dict,m_Key,value); + } + + ValueType GetValue(void) + { + itk::MetaDataDictionary & dict = this->GetMetaDataDictionary(); + if(dict.HasKey(m_Key)) + { + ValueType resp; + itk::ExposeMetaData<ValueType>(dict,m_Key,resp); + } + else + { + itkGenericExceptionMacro(<<"Key "<<m_Key<<" not found in metadata dictionary !"); + } + } + +protected: + /** Constructor */ + PolyLineParametricPathWithValue() + { + itk::MetaDataDictionary & dict = this->GetMetaDataDictionary(); + m_Key = "Value"; + itk::EncapsulateMetaData<ValueType>(dict,m_Key,0); + }; + /** Destructor */ + virtual ~PolyLineParametricPathWithValue() + { } + /**PrintSelf method */ + virtual void PrintSelf(std::ostream& os, itk::Indent indent) const + { + Superclass::PrintSelf(os,indent); + } + private: + PolyLineParametricPathWithValue(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + std::string m_Key; +}; +}// End namespace otb +#endif diff --git a/Testing/Code/Common/CMakeLists.txt b/Testing/Code/Common/CMakeLists.txt index caee4ff88c342040a28c74d7dbf0bf518487b9e4..98ce7efe6a255b080e9465a0d6325f5ec1c4db4c 100644 --- a/Testing/Code/Common/CMakeLists.txt +++ b/Testing/Code/Common/CMakeLists.txt @@ -323,6 +323,42 @@ ADD_TEST(coTuArcSpatialObjectNew ${COMMON_TESTS} ADD_TEST(coTuPathListToPathListFilterNew ${COMMON_TESTS} otbPathListToPathListFilterNew) +# ------- otb::PolyLineParametricPathWithValue ------------------------------------------- +ADD_TEST(coTuPolyLineParametricPathWithValueNew ${COMMON_TESTS} + otbPolyLineParametricPathWithValueNew) + +# ------- otb::DrawPathListFilter ------------------------------------------- + +ADD_TEST(coTuDrawPathListFilterNew ${COMMON_TESTS} + otbDrawPathListFilterNew) + +ADD_TEST(coTvDrawPathListFilter ${COMMON_TESTS} +--compare-image ${TOL} + ${BASELINE}/coTvDrawPathListFilterOutput.png + ${TEMP}/coTvDrawPathListFilterOutput.png + otbDrawPathListFilter + 512 512 20 + ${TEMP}/coTvDrawPathListFilterOutput.png +) +ADD_TEST(coTvDrawPathListFilterSingle ${COMMON_TESTS} +--compare-image ${TOL} + ${BASELINE}/coTvDrawPathListFilterSingleOutput.png + ${TEMP}/coTvDrawPathListFilterSingleOutput.png + otbDrawPathListFilterSingle + 512 512 20 + ${TEMP}/coTvDrawPathListFilterSingleOutput.png +) + +ADD_TEST(coTvDrawPathListFilterWithValue ${COMMON_TESTS} +--compare-image ${TOL} + ${BASELINE}/coTvDrawPathListFilterWithValueOutput.png + ${TEMP}/coTvDrawPathListFilterWithValueOutput.png + otbDrawPathListFilterWithValue + 512 512 20 + ${TEMP}/coTvDrawPathListFilterWithValueOutput.png +) + + # ------- Fichiers sources CXX ----------------------------------- SET(BasicCommon_SRCS otbSystemTest.cxx @@ -365,6 +401,11 @@ otbSpatialObjectSourceNew.cxx otbLineSpatialObjectNew.cxx otbArcSpatialObjectNew.cxx otbPathListToPathListFilterNew.cxx +otbDrawPathListFilterNew.cxx +otbDrawPathListFilter.cxx +otbDrawPathListFilterSingle.cxx +otbDrawPathListFilterWithValue.cxx +otbPolyLineParametricPathWithValueNew.cxx ) diff --git a/Testing/Code/Common/otbCommonTests.cxx b/Testing/Code/Common/otbCommonTests.cxx index 3790bfaddcab3a99fbaf7786cdc076d3f11cb894..1e5c639d85fd7976e63cd743cfd69a589abdb1bf 100644 --- a/Testing/Code/Common/otbCommonTests.cxx +++ b/Testing/Code/Common/otbCommonTests.cxx @@ -66,4 +66,9 @@ REGISTER_TEST(otbSpatialObjectSourceNew); REGISTER_TEST(otbLineSpatialObjectNew); REGISTER_TEST(otbArcSpatialObjectNew); REGISTER_TEST(otbPathListToPathListFilterNew); +REGISTER_TEST(otbDrawPathListFilterNew); +REGISTER_TEST(otbDrawPathListFilter); +REGISTER_TEST(otbDrawPathListFilterSingle); +REGISTER_TEST(otbDrawPathListFilterWithValue); +REGISTER_TEST(otbPolyLineParametricPathWithValueNew); } diff --git a/Testing/Code/Common/otbDrawPathListFilter.cxx b/Testing/Code/Common/otbDrawPathListFilter.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6fdb28b304e1df804f2cd7773b4cf7716fdd9c5b --- /dev/null +++ b/Testing/Code/Common/otbDrawPathListFilter.cxx @@ -0,0 +1,112 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbDrawPathListFilter.h" +#include "otbImageFileWriter.h" +#include "otbImage.h" +#include "itkPolyLineParametricPath.h" + +int otbDrawPathListFilter(int argc, char * argv[]) +{ + try + { + if(argc!=5) + { + std::cout<<"Usgage: "<<argv[0]<<" sizex sizey nbpoints outfname"<<std::endl; + return EXIT_SUCCESS; + } + const unsigned int sizex = atoi(argv[1]); + const unsigned int sizey = atoi(argv[2]); + const unsigned int nbpoints = atoi(argv[3]); + const char * outfname = argv[4]; + + const unsigned int Dimension = 2; + typedef unsigned char PixelType; + typedef otb::Image<PixelType,Dimension> ImageType; + typedef itk::PolyLineParametricPath<Dimension> PathType; + typedef PathType::VertexType VertexType; + typedef otb::DrawPathListFilter<ImageType, PathType, ImageType> DrawPathListFilterType; + typedef DrawPathListFilterType::InputPathListType PathListType; + typedef otb::ImageFileWriter<ImageType> WriterType; + + ImageType::SizeType size; + size[0] = sizex; + size[1] = sizey; + ImageType::IndexType index; + index.Fill(0); + ImageType::RegionType region; + region.SetSize(size); + region.SetIndex(index); + ImageType::Pointer image = ImageType::New(); + image->SetRegions(region); + image->Allocate(); + image->FillBuffer(0); + + PathType::Pointer path1 = PathType::New(); + + for(unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=0; + vertex1[1]=i*sizey/nbpoints; + vertex2[0]=i*sizex/nbpoints; + vertex2[1]=0; + path1->AddVertex(vertex1); + path1->AddVertex(vertex2); + } + + PathType::Pointer path2 = PathType::New(); + for(unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=i*sizex/nbpoints; + vertex1[1]=sizey-1; + vertex2[0]=sizex-1; + vertex2[1]=i*sizey/nbpoints; + path2->AddVertex(vertex1); + path2->AddVertex(vertex2); + } + + PathListType::Pointer pl = PathListType::New(); + pl->PushBack(path1); + pl->PushBack(path2); + + DrawPathListFilterType::Pointer filter = DrawPathListFilterType::New(); + filter->SetInput(image); + filter->SetInputPath(pl); + + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(filter->GetOutput()); + writer->SetFileName(outfname); + writer->Update(); + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Common/otbDrawPathListFilterNew.cxx b/Testing/Code/Common/otbDrawPathListFilterNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..feb1c6bb59dda12bf98b56b850d3f79ad68d42b0 --- /dev/null +++ b/Testing/Code/Common/otbDrawPathListFilterNew.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. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbDrawPathListFilter.h" +#include "otbImage.h" +#include "itkPolyLineParametricPath.h" + +int otbDrawPathListFilterNew(int argc, char * argv[]) +{ + try + { + const unsigned int Dimension = 2; + typedef unsigned char PixelType; + typedef otb::Image<PixelType,Dimension> ImageType; + typedef itk::PolyLineParametricPath<Dimension> PathType; + typedef otb::DrawPathListFilter<ImageType, PathType, ImageType> DrawPathListFilterType; + + // Instantiating object + DrawPathListFilterType::Pointer object = DrawPathListFilterType::New(); + } + + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Common/otbDrawPathListFilterSingle.cxx b/Testing/Code/Common/otbDrawPathListFilterSingle.cxx new file mode 100644 index 0000000000000000000000000000000000000000..41bb91648c727ce571fd4e31b36ddcfaec964548 --- /dev/null +++ b/Testing/Code/Common/otbDrawPathListFilterSingle.cxx @@ -0,0 +1,105 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbDrawPathListFilter.h" +#include "otbImageFileWriter.h" +#include "otbImage.h" +#include "itkPolyLineParametricPath.h" + +int otbDrawPathListFilterSingle(int argc, char * argv[]) +{ + try + { + if(argc!=5) + { + std::cout<<"Usgage: "<<argv[0]<<" sizex sizey nbpoints outfname"<<std::endl; + return EXIT_SUCCESS; + } + const unsigned int sizex = atoi(argv[1]); + const unsigned int sizey = atoi(argv[2]); + const unsigned int nbpoints = atoi(argv[3]); + const char * outfname = argv[4]; + + const unsigned int Dimension = 2; + typedef unsigned char PixelType; + typedef otb::Image<PixelType,Dimension> ImageType; + typedef itk::PolyLineParametricPath<Dimension> PathType; + typedef PathType::VertexType VertexType; + typedef otb::DrawPathListFilter<ImageType, PathType, ImageType> DrawPathListFilterType; + typedef otb::ImageFileWriter<ImageType> WriterType; + + ImageType::SizeType size; + size[0] = sizex; + size[1] = sizey; + ImageType::IndexType index; + index.Fill(0); + ImageType::RegionType region; + region.SetSize(size); + region.SetIndex(index); + ImageType::Pointer image = ImageType::New(); + image->SetRegions(region); + image->Allocate(); + image->FillBuffer(0); + + PathType::Pointer path = PathType::New(); + + for(unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=0; + vertex1[1]=i*sizey/nbpoints; + vertex2[0]=i*sizex/nbpoints; + vertex2[1]=0; + path->AddVertex(vertex1); + path->AddVertex(vertex2); + } + for(unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=i*sizex/nbpoints; + vertex1[1]=sizey-1; + vertex2[0]=sizex-1; + vertex2[1]=i*sizey/nbpoints; + path->AddVertex(vertex1); + path->AddVertex(vertex2); + } + + DrawPathListFilterType::Pointer filter = DrawPathListFilterType::New(); + filter->SetInput(image); + filter->SetInputPath(path); + + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(filter->GetOutput()); + writer->SetFileName(outfname); + writer->Update(); + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Common/otbDrawPathListFilterWithValue.cxx b/Testing/Code/Common/otbDrawPathListFilterWithValue.cxx new file mode 100644 index 0000000000000000000000000000000000000000..fcd18ffbb9304ff991a37e2d3e69466d058d1d69 --- /dev/null +++ b/Testing/Code/Common/otbDrawPathListFilterWithValue.cxx @@ -0,0 +1,115 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbDrawPathListFilter.h" +#include "otbImageFileWriter.h" +#include "otbImage.h" +#include "otbPolyLineParametricPathWithValue.h" + +int otbDrawPathListFilterWithValue(int argc, char * argv[]) +{ + try + { + if(argc!=5) + { + std::cout<<"Usgage: "<<argv[0]<<" sizex sizey nbpoints outfname"<<std::endl; + return EXIT_SUCCESS; + } + const unsigned int sizex = atoi(argv[1]); + const unsigned int sizey = atoi(argv[2]); + const unsigned int nbpoints = atoi(argv[3]); + const char * outfname = argv[4]; + + const unsigned int Dimension = 2; + typedef unsigned char PixelType; + typedef otb::Image<PixelType,Dimension> ImageType; + typedef otb::PolyLineParametricPathWithValue<PixelType,Dimension> PathType; + typedef PathType::VertexType VertexType; + typedef otb::DrawPathListFilter<ImageType, PathType, ImageType> DrawPathListFilterType; + typedef DrawPathListFilterType::InputPathListType PathListType; + typedef otb::ImageFileWriter<ImageType> WriterType; + + ImageType::SizeType size; + size[0] = sizex; + size[1] = sizey; + ImageType::IndexType index; + index.Fill(0); + ImageType::RegionType region; + region.SetSize(size); + region.SetIndex(index); + ImageType::Pointer image = ImageType::New(); + image->SetRegions(region); + image->Allocate(); + image->FillBuffer(0); + + PathType::Pointer path1 = PathType::New(); + + for(unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=0; + vertex1[1]=i*sizey/nbpoints; + vertex2[0]=i*sizex/nbpoints; + vertex2[1]=0; + path1->AddVertex(vertex1); + path1->AddVertex(vertex2); + } + + PathType::Pointer path2 = PathType::New(); + for(unsigned int i =1; i<nbpoints;i++) + { + VertexType vertex1,vertex2; + vertex1[0]=i*sizex/nbpoints; + vertex1[1]=sizey-1; + vertex2[0]=sizex-1; + vertex2[1]=i*sizey/nbpoints; + path2->AddVertex(vertex1); + path2->AddVertex(vertex2); + } + + PathListType::Pointer pl = PathListType::New(); + path1->SetValue(200); + pl->PushBack(path1); + path2->SetValue(50); + pl->PushBack(path2); + + DrawPathListFilterType::Pointer filter = DrawPathListFilterType::New(); + filter->SetInput(image); + filter->SetInputPath(pl); + filter->SetUseInternalPathValue(true); + + WriterType::Pointer writer = WriterType::New(); + writer->SetInput(filter->GetOutput()); + writer->SetFileName(outfname); + writer->Update(); + } + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/Testing/Code/Common/otbPolyLineParametricPathWithValueNew.cxx b/Testing/Code/Common/otbPolyLineParametricPathWithValueNew.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2670187d2bfbdba1bd6ef399fc99e1c933df3fb8 --- /dev/null +++ b/Testing/Code/Common/otbPolyLineParametricPathWithValueNew.cxx @@ -0,0 +1,48 @@ +/*========================================================================= + + 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. + +=========================================================================*/ +#include "itkExceptionObject.h" + +#include "otbPolyLineParametricPathWithValue.h" + +int otbPolyLineParametricPathWithValueNew(int argc, char * argv[]) +{ + try + { + const unsigned int Dimension = 2; + typedef double ValueType; + typedef otb::PolyLineParametricPathWithValue<ValueType, Dimension> PolyLineParametricPathWithValueType; + + // Instantiating object + PolyLineParametricPathWithValueType::Pointer object = PolyLineParametricPathWithValueType::New(); + object->SetValue(0); + } + + catch( itk::ExceptionObject & err ) + { + std::cout << "Exception itk::ExceptionObject thrown !" << std::endl; + std::cout << err << std::endl; + return EXIT_FAILURE; + } + + catch( ... ) + { + std::cout << "Unknown exception thrown !" << std::endl; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +}