Commit e069adeb authored by Sylvain Thery's avatar Sylvain Thery

add addAttribute with type in string

parent f80538a5
...@@ -55,7 +55,7 @@ void testVAbyNames(MAP& map, const std::string& name) ...@@ -55,7 +55,7 @@ void testVAbyNames(MAP& map, const std::string& name)
if (testPos.isValid()) if (testPos.isValid())
std::cout << "Attribute "<< name <<" valid"<< std::endl; std::cout << "Attribute "<< name <<" valid"<< std::endl;
else else
std::cout << "Attribute "<< name <<"invalid"<< std::endl; std::cout << "Attribute "<< name <<" invalid"<< std::endl;
} }
/** /**
...@@ -240,6 +240,7 @@ int main() ...@@ -240,6 +240,7 @@ int main()
computeNewPositions(myMap,positionAtt); computeNewPositions(myMap,positionAtt);
dumpAttribute(positionAtt); dumpAttribute(positionAtt);
//check if there is a Vertex Attribute of VEC3 named position => yes //check if there is a Vertex Attribute of VEC3 named position => yes
testVAbyNames(myMap,"position"); testVAbyNames(myMap,"position");
...@@ -247,7 +248,29 @@ int main() ...@@ -247,7 +248,29 @@ int main()
myMap.removeAttribute(positionAtt); myMap.removeAttribute(positionAtt);
//check if there is a Vertex Attribute of VEC3 named position => no //check if there is a Vertex Attribute of VEC3 named position => no
std::cout << "after removing position"<< std::endl;
testVAbyNames(myMap,"position"); testVAbyNames(myMap,"position");
// its also possible to add an attribute only with name of type in a string (if type has been registred)
if (myMap.addAttribute<VERTEX>("double", "pipo_double"))
{
VertexAttribute<double, MAP> position_double = myMap.getAttribute<double, VERTEX, MAP>("pipo_double");
position_double[v] = 3.1415926;
}
if (!myMap.addAttribute<VERTEX>("double", "pipo_double"))
{
std::cout << "problem"<< std::endl;
}
if (!myMap.addAttribute<VERTEX>("triple", "pipo_triple"))
{
std::cout << "problem"<< std::endl;
}
return 0; return 0;
} }
...@@ -161,6 +161,15 @@ public: ...@@ -161,6 +161,15 @@ public:
template <typename T> template <typename T>
AttributeMultiVector<T>* addAttribute(const std::string& attribName); AttributeMultiVector<T>* addAttribute(const std::string& attribName);
/**
* add a new attribute to the container
* @param typeName type of the new attribute in a string
* @param attribName name of the new attribute
* @return pointer to the new AttributeMultiVectorGen (unknown type inside)
*/
AttributeMultiVectorGen* addAttribute(const std::string& typeName, const std::string& attribName);
protected: protected:
/** /**
* add a new attribute with a given index (for load only) * add a new attribute with a given index (for load only)
......
...@@ -49,6 +49,8 @@ public: ...@@ -49,6 +49,8 @@ public:
*/ */
const std::string& getTypeName() { return m_name; } const std::string& getTypeName() { return m_name; }
virtual unsigned int size() = 0;
/** /**
* Ajout de l'attribut au container (A IMPLEMENTER) * Ajout de l'attribut au container (A IMPLEMENTER)
*/ */
...@@ -75,6 +77,11 @@ public: ...@@ -75,6 +77,11 @@ public:
// or existing one // or existing one
return container.getDataVector<T>(id); return container.getDataVector<T>(id);
} }
unsigned int size()
{
return sizeof(T);
}
}; };
} // namespace CGoGN } // namespace CGoGN
......
...@@ -125,6 +125,16 @@ public: ...@@ -125,6 +125,16 @@ public:
* ATTRIBUTES MANAGEMENT * * ATTRIBUTES MANAGEMENT *
****************************************/ ****************************************/
/**
* Create an attribute for a given orbit
* @param typeName type in aa string
* @param nameAttr attribute name
* @return true if created
*/
template <unsigned int ORBIT>
bool addAttribute(const std::string& typeName, const std::string& nameAttr);
/** /**
* Create an attribute for a given orbit * Create an attribute for a given orbit
* @param nameAttr attribute name * @param nameAttr attribute name
......
...@@ -166,6 +166,19 @@ void MapCommon<MAP_IMPL>::boundaryUnmarkAll() ...@@ -166,6 +166,19 @@ void MapCommon<MAP_IMPL>::boundaryUnmarkAll()
* ATTRIBUTES MANAGEMENT * * ATTRIBUTES MANAGEMENT *
****************************************/ ****************************************/
template <typename MAP_IMPL>
template <unsigned int ORBIT>
inline bool MapCommon<MAP_IMPL>::addAttribute(const std::string& typeName, const std::string& nameAttr)
{
if(!this->template isOrbitEmbedded<ORBIT>())
this->template addEmbedding<ORBIT>() ;
AttributeMultiVectorGen* amv = this->m_attribs[ORBIT].addAttribute(typeName,nameAttr) ;
return amv != NULL;
}
template <typename MAP_IMPL> template <typename MAP_IMPL>
template <typename T, unsigned int ORBIT, typename MAP> template <typename T, unsigned int ORBIT, typename MAP>
inline AttributeHandler<T, ORBIT, MAP> MapCommon<MAP_IMPL>::addAttribute(const std::string& nameAttr) inline AttributeHandler<T, ORBIT, MAP> MapCommon<MAP_IMPL>::addAttribute(const std::string& nameAttr)
......
...@@ -925,5 +925,33 @@ void AttributeContainer::dumpByLines() const ...@@ -925,5 +925,33 @@ void AttributeContainer::dumpByLines() const
} }
AttributeMultiVectorGen* AttributeContainer::addAttribute(const std::string& typeName, const std::string& attribName)
{
// first check if attribute already exist
unsigned int index = UNKNOWN ;
if (attribName != "")
{
index = getAttributeIndex(attribName) ;
if (index != UNKNOWN)
{
CGoGNerr << "attribute " << attribName << " already found.." << CGoGNendl ;
return NULL ;
}
}
// create the new attribute
std::map<std::string, RegisteredBaseAttribute*>::iterator itAtt = m_attributes_registry_map->find(typeName);
if (itAtt == m_attributes_registry_map->end())
{
CGoGNerr << "type " << typeName << " not registred.." << CGoGNendl ;
return NULL ;
}
RegisteredBaseAttribute* ra = itAtt->second;
AttributeMultiVectorGen* amv = ra->addAttribute(*this, attribName);
return amv ;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment