Skip to content
Snippets Groups Projects
Commit 4b0c3088 authored by Otmane Lahlou's avatar Otmane Lahlou
Browse files

ENH: put the method GetBoundingRegion in PolyLineParametricPathWithValue class

parent d817523b
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......
......@@ -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
......@@ -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.
......
......@@ -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;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment