Skip to content
Snippets Groups Projects
Commit d0532277 authored by Julien Malik's avatar Julien Malik
Browse files

ENH: add AttributesMapMeasurementFunctor to otbAttributesMapLabelObject.h, and...

ENH: add AttributesMapMeasurementFunctor to otbAttributesMapLabelObject.h, and make it compatible with std::vector
parent 1c7da38c
Branches
Tags
No related merge requests found
......@@ -77,6 +77,65 @@ private:
std::string m_AttributeName;
};
/** \class AttributesMapMeasurementFunctor
* \brief This class allows to build a measurement vector from an AttributesMapLabelObject
*
* It Allows to select only a subset of the available attributes.
*/
template<class TLabelObject,class TMeasurementVector>
class AttributesMapMeasurementFunctor
{
public:
typedef std::vector<std::string> AttributesListType;
inline TMeasurementVector operator()(const TLabelObject * object) const
{
TMeasurementVector newSample(m_Attributes.size());
unsigned int attrIndex = 0;
typename AttributesListType::const_iterator attrIt = m_Attributes.begin();
while(attrIt != m_Attributes.end())
{
newSample[attrIndex] = object->GetAttribute(attrIt->c_str());
++attrIt;
++attrIndex;
}
return newSample;
}
/** Add an attribute to the exported attributes list */
void AddAttribute(const char * attr)
{
m_Attributes.push_back(attr);
}
/** Remove an attribute from the exported attributes list */
void RemoveAttribute(const char * attr)
{
AttributesListType::iterator elt = std::find(m_Attributes.begin(),m_Attributes.end(),attr);
if(elt!=m_Attributes.end())
{
m_Attributes.erase(elt);
}
}
/** Remove all attributes from the exported attributes list */
void ClearAttributes()
{
m_Attributes.clear();
}
/** Get The number of exported attributes */
unsigned int GetNumberOfAttributes()
{
return m_Attributes.size();
}
private:
AttributesListType m_Attributes;
};
} // end namespace Functor
/** \class AttributesMapLabelObject
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment