Skip to content
Snippets Groups Projects
Commit e0ef022e authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: add caching for polygon surface computation

parent c0da41c6
No related branches found
No related tags found
No related merge requests found
...@@ -134,11 +134,16 @@ public: ...@@ -134,11 +134,16 @@ public:
*/ */
virtual double GetLength() const; virtual double GetLength() const;
void AddVertex (const ContinuousIndexType &vertex);
protected: protected:
/** Constructor */ /** Constructor */
Polygon() Polygon()
{ {
m_Epsilon = 0.000001; m_Epsilon = 0.000001;
m_Surface = -1.0;
surfaceValid = false;
}; };
/** Destructor */ /** Destructor */
...@@ -147,12 +152,15 @@ protected: ...@@ -147,12 +152,15 @@ protected:
/**PrintSelf method */ /**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void ComputeSurface() const;
private: private:
Polygon(const Self&); //purposely not implemented Polygon(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented
double m_Epsilon; double m_Epsilon;
mutable double m_Surface;
mutable bool surfaceValid;
}; };
}// End namespace otb }// End namespace otb
......
...@@ -22,6 +22,16 @@ PURPOSE. See the above copyright notices for more information. ...@@ -22,6 +22,16 @@ PURPOSE. See the above copyright notices for more information.
namespace otb namespace otb
{ {
template<class TValue>
void
Polygon<TValue>
::AddVertex(const ContinuousIndexType &vertex)
{
Superclass::AddVertex(vertex);
surfaceValid=false;
}
/** /**
* Check wether point is strictly inside the polygon. * Check wether point is strictly inside the polygon.
* \param point The point to check. * \param point The point to check.
...@@ -478,9 +488,9 @@ Polygon<TValue> ...@@ -478,9 +488,9 @@ Polygon<TValue>
* Surface computation (for non convex polygons as well) * Surface computation (for non convex polygons as well)
*/ */
template<class TValue> template<class TValue>
double void
Polygon<TValue> Polygon<TValue>
::GetSurface() const ::ComputeSurface() const
{ {
double m_Surface; double m_Surface;
m_Surface = 0.0; m_Surface = 0.0;
...@@ -515,9 +525,25 @@ Polygon<TValue> ...@@ -515,9 +525,25 @@ Polygon<TValue>
m_Surface = 0.0; m_Surface = 0.0;
} }
surfaceValid = true;
}
/**
* Get surface
*/
template<class TValue>
double
Polygon<TValue>
::GetSurface() const
{
if (!surfaceValid)
{
ComputeSurface();
}
return m_Surface; return m_Surface;
} }
/** /**
* Lenght computation (difference with path is in the last addition) * Lenght computation (difference with path is in the last addition)
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment