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

ENH: add caching for path length computation

parent 8e3d70e3
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,8 @@ public:
*/
virtual double GetLength() const;
void AddVertex (const ContinuousIndexType &vertex);
protected:
/** Constructor */
PolyLineParametricPathWithValue();
......@@ -95,10 +97,14 @@ protected:
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
virtual void ComputeLength() const;
private:
PolyLineParametricPathWithValue(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
std::string m_Key;
mutable double m_Length;
mutable bool m_LengthIsValid;
};
}// End namespace otb
......
......@@ -32,11 +32,33 @@ PolyLineParametricPathWithValue<TValue,VDimension>
itk::MetaDataDictionary & dict = this->GetMetaDataDictionary();
m_Key = "Value";
itk::EncapsulateMetaData<ValueType>(dict,m_Key,0);
m_LengthIsValid = false;
m_Length = -1.0;
}
template < class TValue,unsigned int VDimension>
void PolyLineParametricPathWithValue<TValue,VDimension>
::AddVertex(const ContinuousIndexType &vertex)
{
Superclass::AddVertex(vertex);
m_LengthIsValid=false;
}
template < class TValue,unsigned int VDimension>
double PolyLineParametricPathWithValue<TValue,VDimension>
::GetLength() const
{
if (!m_LengthIsValid)
{
ComputeLength();
}
return m_Length;
}
template < class TValue,unsigned int VDimension>
void
PolyLineParametricPathWithValue<TValue,VDimension>
::ComputeLength() const
{
double length = 0.0;
VertexListConstIteratorType it = this->GetVertexList()->Begin();
......@@ -68,7 +90,8 @@ double PolyLineParametricPathWithValue<TValue,VDimension>
length = 0.0;
}
return length;
m_Length = length;
m_LengthIsValid = true;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment