diff --git a/Code/Common/otbPolyLineParametricPathWithValue.h b/Code/Common/otbPolyLineParametricPathWithValue.h index ffabc0caafd0df7f3d66e4a0a9ebbb36d0b175e7..7c87da7fb4bd0270d96fed002176f9c5691f948a 100644 --- a/Code/Common/otbPolyLineParametricPathWithValue.h +++ b/Code/Common/otbPolyLineParametricPathWithValue.h @@ -20,6 +20,7 @@ PURPOSE. See the above copyright notices for more information. #include "itkPolyLineParametricPath.h" #include "itkMetaDataObject.h" +#include "itkImageRegion.h" #include "otbMacro.h" namespace otb @@ -32,10 +33,10 @@ namespace otb * \sa itk::PolyLineParametricPath. */ template < class TValue,unsigned int VDimension=2> -class ITK_EXPORT PolyLineParametricPathWithValue - : public itk::PolyLineParametricPath<VDimension> + class ITK_EXPORT PolyLineParametricPathWithValue + : public itk::PolyLineParametricPath<VDimension> { -public: + public: /** Standard typedefs */ typedef PolyLineParametricPathWithValue Self; typedef itk::PolyLineParametricPath<VDimension> Superclass; @@ -57,6 +58,10 @@ public: typedef typename Superclass::ContinuousIndexType ContinuousIndexType; typedef typename VertexListType::ConstIterator VertexListConstIteratorType; + typedef itk::ImageRegion<2> RegionType; + typedef typename RegionType::SizeType SizeType; + typedef typename RegionType::IndexType IndexType; + itkGetMacro(Key,std::string); void SetValue(ValueType value) @@ -87,6 +92,12 @@ public: virtual double GetLength() const; void AddVertex (const ContinuousIndexType &vertex); + + /** + * Compute the path bounding region. + * \return The region. + */ + RegionType GetBoundingRegion(void); protected: /** Constructor */ diff --git a/Code/Common/otbPolyLineParametricPathWithValue.txx b/Code/Common/otbPolyLineParametricPathWithValue.txx index 5031fb4a3126815880e981c4b0c6cd73b7a0929f..962a33c2bc21ee521bd1fdc3a0f3b2656d54a3b5 100644 --- a/Code/Common/otbPolyLineParametricPathWithValue.txx +++ b/Code/Common/otbPolyLineParametricPathWithValue.txx @@ -113,5 +113,71 @@ PolyLineParametricPathWithValue<TValue,VDimension> os << std::endl; } +/** + * Bounding Box computation + */ +template < class TValue,unsigned int VDimension> +typename PolyLineParametricPathWithValue<TValue,VDimension> +::RegionType +PolyLineParametricPathWithValue<TValue,VDimension> +::GetBoundingRegion() +{ + RegionType region; + SizeType size; + IndexType index; + + size.Fill(0); + index.Fill(0); + + IndexType maxId; + maxId.Fill(0); + + VertexListConstIteratorType it = this->GetVertexList()->Begin(); + + long int x,y; + + if (this->GetVertexList()->Size()>0) + { + x = static_cast<long int>(it.Value()[0]); + y = static_cast<long int>(it.Value()[1]); + index[0] = x; + index[1] = y; + + ++it; + while (it != this->GetVertexList()->End()) + { + x = static_cast<long int>(it.Value()[0]); + y = static_cast<long int>(it.Value()[1]); + + // Index search + if ( x < index[0] ) + { + index[0] = x; + } + if ( y < index[1] ) + { + index[1] = y; + } + // Max Id search for size computation + if ( x > maxId[0] ) + { + maxId[0] = x; + } + if ( y > maxId[1] ) + { + maxId[1] = y; + } + + ++it; + } + + size[0] = maxId[0] - index[0]; + size[1] = maxId[1] - index[1]; + } + region.SetSize(size); + region.SetIndex(index); + return region; +} + } // end namespace otb #endif diff --git a/Code/Common/otbPolygon.h b/Code/Common/otbPolygon.h index 853f265b4412cf34d621436adaecb1c606134126..335e1fdaa5b535b4667c9694023e301719d1930f 100644 --- a/Code/Common/otbPolygon.h +++ b/Code/Common/otbPolygon.h @@ -19,7 +19,7 @@ PURPOSE. See the above copyright notices for more information. #define __otbPolygon_h #include "otbPolyLineParametricPathWithValue.h" -#include "itkImageRegion.h" + namespace otb { @@ -59,9 +59,7 @@ public: typedef typename Superclass::ContinuousIndexType ContinuousIndexType; typedef typename Superclass::VertexListConstIteratorType VertexListConstIteratorType; - typedef itk::ImageRegion<2> RegionType; - typedef typename RegionType::SizeType SizeType; - typedef typename RegionType::IndexType IndexType; + itkSetMacro(Epsilon,double); itkGetMacro(Epsilon,double); @@ -116,11 +114,7 @@ public: */ bool IsTouching(VertexType a1, VertexType a2, VertexType b1, VertexType b2) const; - /** - * Compute the polygon bounding region. - * \return The region. - */ - RegionType GetBoundingRegion(void); + /** * Return the polygon surface. diff --git a/Code/Common/otbPolygon.txx b/Code/Common/otbPolygon.txx index 0cdeab82a177cec3a09e7953d614c0f95876767a..cbcf7658a4b3e741074959d7318ce99834793b4d 100644 --- a/Code/Common/otbPolygon.txx +++ b/Code/Common/otbPolygon.txx @@ -418,70 +418,7 @@ Polygon<TValue> return resp; } -/** - * Bounding Box computation - */ -template<class TValue> -typename Polygon<TValue>::RegionType -Polygon<TValue> -::GetBoundingRegion() -{ - RegionType region; - SizeType size; - IndexType index; - - size.Fill(0); - index.Fill(0); - IndexType maxId; - maxId.Fill(0); - - VertexListConstIteratorType it = this->GetVertexList()->Begin(); - - long int x,y; - - if (this->GetVertexList()->Size()>0) - { - x = static_cast<long int>(it.Value()[0]); - y = static_cast<long int>(it.Value()[1]); - index[0] = x; - index[1] = y; - - ++it; - while (it != this->GetVertexList()->End()) - { - x = static_cast<long int>(it.Value()[0]); - y = static_cast<long int>(it.Value()[1]); - - // Index search - if ( x < index[0] ) - { - index[0] = x; - } - if ( y < index[1] ) - { - index[1] = y; - } - // Max Id search for size computation - if ( x > maxId[0] ) - { - maxId[0] = x; - } - if ( y > maxId[1] ) - { - maxId[1] = y; - } - - ++it; - } - - size[0] = maxId[0] - index[0]; - size[1] = maxId[1] - index[1]; - } - region.SetSize(size); - region.SetIndex(index); - return region; -} /**