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

ENH: caching BoundingRegion computation in Polygon and Polyline

parent c5929c19
Branches
Tags
No related merge requests found
...@@ -97,8 +97,8 @@ template < class TValue,unsigned int VDimension=2> ...@@ -97,8 +97,8 @@ template < class TValue,unsigned int VDimension=2>
* Compute the path bounding region. * Compute the path bounding region.
* \return The region. * \return The region.
*/ */
RegionType GetBoundingRegion(void); RegionType GetBoundingRegion(void) const;
protected: protected:
/** Constructor */ /** Constructor */
PolyLineParametricPathWithValue(); PolyLineParametricPathWithValue();
...@@ -109,13 +109,18 @@ protected: ...@@ -109,13 +109,18 @@ protected:
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void ComputeLength() const; virtual void ComputeLength() const;
virtual void ComputeBoundingRegion() const;
virtual void Modified();
private: private:
PolyLineParametricPathWithValue(const Self&); //purposely not implemented PolyLineParametricPathWithValue(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented
std::string m_Key; std::string m_Key;
mutable double m_Length; mutable double m_Length;
mutable bool m_LengthIsValid; mutable bool m_LengthIsValid;
mutable RegionType m_BoundingRegion;
mutable bool m_BoundingRegionIsValid;
}; };
}// End namespace otb }// End namespace otb
......
...@@ -27,13 +27,12 @@ namespace otb ...@@ -27,13 +27,12 @@ namespace otb
*/ */
template < class TValue,unsigned int VDimension> template < class TValue,unsigned int VDimension>
PolyLineParametricPathWithValue<TValue,VDimension> PolyLineParametricPathWithValue<TValue,VDimension>
::PolyLineParametricPathWithValue() ::PolyLineParametricPathWithValue() :
m_Key("Value"),m_Length(-1.0),m_LengthIsValid(false),
m_BoundingRegion(),m_BoundingRegionIsValid(false)
{ {
itk::MetaDataDictionary & dict = this->GetMetaDataDictionary(); itk::MetaDataDictionary & dict = this->GetMetaDataDictionary();
m_Key = "Value";
itk::EncapsulateMetaData<ValueType>(dict,m_Key,0); itk::EncapsulateMetaData<ValueType>(dict,m_Key,0);
m_LengthIsValid = false;
m_Length = -1.0;
} }
template < class TValue,unsigned int VDimension> template < class TValue,unsigned int VDimension>
...@@ -41,7 +40,7 @@ void PolyLineParametricPathWithValue<TValue,VDimension> ...@@ -41,7 +40,7 @@ void PolyLineParametricPathWithValue<TValue,VDimension>
::AddVertex(const ContinuousIndexType &vertex) ::AddVertex(const ContinuousIndexType &vertex)
{ {
Superclass::AddVertex(vertex); Superclass::AddVertex(vertex);
m_LengthIsValid=false; this->Modified();
} }
template < class TValue,unsigned int VDimension> template < class TValue,unsigned int VDimension>
...@@ -56,7 +55,7 @@ double PolyLineParametricPathWithValue<TValue,VDimension> ...@@ -56,7 +55,7 @@ double PolyLineParametricPathWithValue<TValue,VDimension>
} }
template < class TValue,unsigned int VDimension> template < class TValue,unsigned int VDimension>
void void
PolyLineParametricPathWithValue<TValue,VDimension> PolyLineParametricPathWithValue<TValue,VDimension>
::ComputeLength() const ::ComputeLength() const
{ {
...@@ -113,16 +112,27 @@ PolyLineParametricPathWithValue<TValue,VDimension> ...@@ -113,16 +112,27 @@ PolyLineParametricPathWithValue<TValue,VDimension>
os << std::endl; os << std::endl;
} }
template < class TValue,unsigned int VDimension>
typename PolyLineParametricPathWithValue<TValue,VDimension>
::RegionType
PolyLineParametricPathWithValue<TValue,VDimension>
::GetBoundingRegion() const
{
if (!m_BoundingRegionIsValid)
{
ComputeBoundingRegion();
}
return m_BoundingRegion;
}
/** /**
* Bounding Box computation * Bounding Box computation
*/ */
template < class TValue,unsigned int VDimension> template < class TValue,unsigned int VDimension>
typename PolyLineParametricPathWithValue<TValue,VDimension> void
::RegionType PolyLineParametricPathWithValue<TValue,VDimension>
PolyLineParametricPathWithValue<TValue,VDimension> ::ComputeBoundingRegion() const
::GetBoundingRegion()
{ {
RegionType region;
SizeType size; SizeType size;
IndexType index; IndexType index;
...@@ -174,9 +184,18 @@ PolyLineParametricPathWithValue<TValue,VDimension> ...@@ -174,9 +184,18 @@ PolyLineParametricPathWithValue<TValue,VDimension>
size[0] = maxId[0] - index[0]; size[0] = maxId[0] - index[0];
size[1] = maxId[1] - index[1]; size[1] = maxId[1] - index[1];
} }
region.SetSize(size); m_BoundingRegion.SetSize(size);
region.SetIndex(index); m_BoundingRegion.SetIndex(index);
return region; m_BoundingRegionIsValid = true;
}
template < class TValue,unsigned int VDimension>
void
PolyLineParametricPathWithValue<TValue,VDimension>
::Modified()
{
m_LengthIsValid=false;
m_BoundingRegionIsValid=false;
} }
} // end namespace otb } // end namespace otb
......
...@@ -157,6 +157,7 @@ protected: ...@@ -157,6 +157,7 @@ protected:
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const; virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void ComputeArea() const; virtual void ComputeArea() const;
virtual void Modified();
private: private:
Polygon(const Self&); //purposely not implemented Polygon(const Self&); //purposely not implemented
......
...@@ -529,6 +529,14 @@ double Polygon<TValue> ...@@ -529,6 +529,14 @@ double Polygon<TValue>
return length; return length;
} }
template <class TValue>
void
Polygon<TValue>
::Modified()
{
Superclass::Modified();
m_AreaIsValid=false;
}
/** /**
* PrintSelf Method * PrintSelf Method
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment