Skip to content
Snippets Groups Projects
Commit 744250ff authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

Ajout d'une methode de calcul de boite englobante dans la classe Polygon.

parent 8725d028
No related branches found
No related tags found
No related merge requests found
......@@ -56,8 +56,17 @@ class ITK_EXPORT Polygon
typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
typedef typename VertexListType::ConstIterator VertexListIteratorType;
itkSetMacro(Epsilon,double);
itkGetMacro(Epsilon,double);
typedef itk::Size<2> SizeType;
typedef itk::Index<2> IndexType;
itkSetMacro(Epsilon,double);
itkGetMacro(Epsilon,double);
itkGetMacro(BoundingBoxIndex, IndexType);
itkSetMacro(BoundingBoxIndex, IndexType);
itkGetMacro(BoundingBoxSize, SizeType);
itkSetMacro(BoundingBoxSize, SizeType);
/**
* Check wether point is strictly inside the polygon.
......@@ -109,6 +118,11 @@ class ITK_EXPORT Polygon
*/
bool IsTouching(VertexType a1, VertexType a2, VertexType b1, VertexType b2);
/**
* Compute the polygon bounding box
*/
void ComputeBoundingBox();
protected:
/** Constructor */
Polygon()
......@@ -125,6 +139,10 @@ private:
void operator=(const Self&); //purposely not implemented
double m_Epsilon;
// Polygon bounding box index
IndexType m_BoundingBoxIndex;
// Polygon bounding box size
SizeType m_BoundingBoxSize;
};
}// End namespace otb
......
......@@ -407,6 +407,57 @@ Polygon<TValue>
}
return resp;
}
/**
* Bounding Box computation
*/
template<class TValue>
void
Polygon<TValue>
::ComputeBoundingBox()
{
VertexListIteratorType it = this->GetVertexList()->Begin();
long int x = static_cast<long int>(it.Value()[0]);
long int y = static_cast<long int>(it.Value()[1]);
IndexType maxId;
maxId.Fill(0);
m_BoundingBoxIndex[0] = x;
m_BoundingBoxIndex[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 < m_BoundingBoxIndex[0] )
{
m_BoundingBoxIndex[0] = x;
}
if ( y < m_BoundingBoxIndex[1] )
{
m_BoundingBoxIndex[1] = y;
}
// Max Id search for size computation
if ( x > maxId[0] )
{
maxId[0] = x;
}
if ( y > maxId[1] )
{
maxId[1] = y;
}
++it;
}
m_BoundingBoxSize[0] = maxId[0] - m_BoundingBoxIndex[0];
m_BoundingBoxSize[1] = maxId[1] - m_BoundingBoxIndex[1];
}
/**
* PrintSelf Method
*/
......@@ -417,6 +468,8 @@ Polygon<TValue>
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
......@@ -59,6 +59,7 @@ int otbPolygon(int argc, char * argv[])
}
}
IteratorType begin1 = polygon1->GetVertexList()->Begin();
IteratorType end1 = polygon1->GetVertexList()->End();
IteratorType begin2 = polygon2->GetVertexList()->Begin();
......@@ -120,6 +121,16 @@ int otbPolygon(int argc, char * argv[])
file<<"polygon2->NbCrossing("<<current<<", "<<firstVertex<<") = "<<polygon2->NbCrossing(current,firstVertex)<<std::endl;
file<<"polygon2->NbTouching("<<current<<", "<<firstVertex<<") = "<<polygon2->NbTouching(current,firstVertex)<<std::endl;
file<<std::endl<<std::endl;
file<<"Bounding Boxs computation : "<<std::endl;
polygon1->ComputeBoundingBox();
file<<"Bounding Box 1"<<std::endl;
file<<"Index : "<<polygon1->GetBoundingBoxIndex()<<" , Size : "<<polygon1->GetBoundingBoxSize()<<std::endl;
polygon2->ComputeBoundingBox();
file<<"Bounding Box 2"<<std::endl;
file<<"Index : "<<polygon2->GetBoundingBoxIndex()<<" , Size : "<<polygon2->GetBoundingBoxSize()<<std::endl;
file.close();
}
......
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