Commit 443b9e63 authored by Pierre Kraemer's avatar Pierre Kraemer

grosse mise a jour des Containers, AttributeHandler, etc..

parent 54d09f40
......@@ -536,44 +536,27 @@ void MyGlutWin::myKeyboard(unsigned char keycode, int x, int y)
case 'd':
{
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
myMap.removeAttribute<PFP::VEC3>(normal) ;
myMap.removeAttribute<PFP::VEC3>(laplacian) ;
AttributeHandler<PFP::VEC3> newPosition = myMap.addAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
Algo::Geometry::computeCentroidFaces<PFP>(myMap, position, newPosition) ;
std::vector<std::string> attrNames ;
for(unsigned int i = 0; i < NB_ORBITS; ++i)
{
AttributeContainer& cont = myMap.getAttributeContainer(i) ;
std::cout << "container " << i << " (" << cont.getNbAttributes() << ") :" << std::endl ;
cont.getAttributesNames(attrNames) ;
for(unsigned int j = 0; j < attrNames.size(); ++j)
std::cout << " -> " << attrNames[j] << std::endl ;
}
std::cout << std::endl ;
GLint t1 = glutGet(GLUT_ELAPSED_TIME);
Algo::Modelisation::computeDual<PFP>(myMap) ;
for(unsigned int i = 0; i < NB_ORBITS; ++i)
{
AttributeContainer& cont = myMap.getAttributeContainer(i) ;
std::cout << "container " << i << " (" << cont.getNbAttributes() << ") :" << std::endl ;
cont.getAttributesNames(attrNames) ;
for(unsigned int j = 0; j < attrNames.size(); ++j)
std::cout << " -> " << attrNames[j] << std::endl ;
}
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "dual computation: "<< seconds << "sec" << std::endl;
newPosition = myMap.getAttribute<PFP::VEC3>(FACE_ORBIT, "position") ;
myMap.removeAttribute<PFP::VEC3>(newPosition) ;
position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, "position") ;
normal = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "normal") ;
laplacian = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "laplacian") ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME);
GLfloat seconds = (t2 - t1) / 1000.0f;
std::cout << "dual computation: "<< seconds << "sec" << std::endl;
t1 = glutGet(GLUT_ELAPSED_TIME);
updateVBOprimitives(Algo::Render::VBO::TRIANGLES | Algo::Render::VBO::LINES | Algo::Render::VBO::POINTS) ;
updateVBOdata(Algo::Render::VBO::POSITIONS | Algo::Render::VBO::NORMALS) ;
......@@ -743,6 +726,7 @@ int main(int argc, char** argv)
std::cerr << "could not import " << filename << std::endl ;
return 1 ;
}
mgw->position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, attrNames[0]) ;
GLint t2 = glutGet(GLUT_ELAPSED_TIME) ;
GLfloat seconds = (t2 - t1) / 1000.0f ;
......
......@@ -211,7 +211,7 @@ public:
AttributeHandler_IHM() : AttributeHandler<T>()
{}
AttributeHandler_IHM(GenericMap* m, unsigned int idAttr) : AttributeHandler<T>(m, idAttr)
AttributeHandler_IHM(GenericMap* m, unsigned int orbit, unsigned int index) : AttributeHandler<T>(m, orbit, index)
{}
AttributeMultiVector<T>* getDataVector() const
......
......@@ -54,14 +54,14 @@ AttributeHandler_IHM<T> ImplicitHierarchicalMap::addAttribute(unsigned int orbit
amv[i] = EMBNULL ;
}
return AttributeHandler_IHM<T>(this, h.id()) ;
return AttributeHandler_IHM<T>(this, h.getOrbit(), h.getIndex()) ;
}
template <typename T>
AttributeHandler_IHM<T> ImplicitHierarchicalMap::getAttribute(unsigned int orbit, const std::string& nameAttr)
{
AttributeHandler<T> h = Map2::getAttribute<T>(orbit, nameAttr) ;
return AttributeHandler_IHM<T>(this, h.id()) ;
return AttributeHandler_IHM<T>(this, h.getOrbit(), h.getIndex()) ;
}
/***************************************************
......@@ -344,7 +344,7 @@ T& AttributeHandler_IHM<T>::operator[](Dart d)
assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;
unsigned int orbit = AttributeContainer::orbitAttr(this->m_id) ;
unsigned int orbit = this->m_orbit ;
unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
unsigned int index = m->getEmbedding(d, orbit) ;
......@@ -381,7 +381,7 @@ const T& AttributeHandler_IHM<T>::operator[](Dart d) const
assert(m->m_dartLevel[d] <= m->m_curLevel || !"Access to a dart introduced after current level") ;
assert(m->vertexInsertionLevel(d) <= m->m_curLevel || !"Access to the embedding of a vertex inserted after current level") ;
unsigned int orbit = AttributeContainer::orbitAttr(this->m_id) ;
unsigned int orbit = this->m_orbit ;
unsigned int nbSteps = m->m_curLevel - m->vertexInsertionLevel(d) ;
unsigned int index = m->getEmbedding(d, orbit) ;
......
......@@ -444,7 +444,7 @@ void computeDual(typename PFP::MAP& map, const FunctorSelect& selected)
for(Dart d = map.begin(); d != map.end(); map.next(d))
{
Dart dd = map.alpha1(d) ;
Dart dd = map.alpha_1(d) ;
new_phi1[d] = dd ;
new_phi_1[dd] = d ;
}
......@@ -469,7 +469,6 @@ template <typename PFP, typename EMBV, typename EMB>
void quadranguleFacesVolume(typename PFP::MAP& map, EMBV& attributs, const FunctorSelect& selected)
{
}
template <typename PFP, typename EMBV, typename EMB>
......
......@@ -36,8 +36,6 @@ namespace Render
namespace VBO
{
template <typename ATTR_HANDLER>
void MapRender_VBO::updateData(int upType, const ATTR_HANDLER& attrib, ConvertAttrib* conv)
{
......@@ -64,8 +62,6 @@ void MapRender_VBO::updateData(int upType, const ATTR_HANDLER& attrib, ConvertAt
fillBufferDirect(indexVBO, attrib) ;
}
template <typename ATTR_HANDLER>
void MapRender_VBO::fillBufferDirect(unsigned int indexVBO, const ATTR_HANDLER& attrib)
{
......@@ -73,7 +69,7 @@ void MapRender_VBO::fillBufferDirect(unsigned int indexVBO, const ATTR_HANDLER&
std::vector<void*> addr;
unsigned int byteTableSize;
unsigned int nbb = mv->getStartAddresses(addr, byteTableSize);
unsigned int nbb = mv->getBlocksPointers(addr, byteTableSize);
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[indexVBO]);
glBufferDataARB(GL_ARRAY_BUFFER, nbb * byteTableSize, 0, GL_STREAM_DRAW);
......@@ -88,7 +84,6 @@ void MapRender_VBO::fillBufferDirect(unsigned int indexVBO, const ATTR_HANDLER&
}
}
template <typename ATTR_HANDLER>
void MapRender_VBO::fillBufferConvert(unsigned int indexVBO, const ATTR_HANDLER& attrib, ConvertAttrib* conv)
{
......@@ -96,10 +91,10 @@ void MapRender_VBO::fillBufferConvert(unsigned int indexVBO, const ATTR_HANDLER&
std::vector<void*> addr;
unsigned int byteTableSize;
unsigned int nbb = mv->getStartAddresses(addr, byteTableSize);
unsigned int nbb = mv->getBlocksPointers(addr, byteTableSize);
// alloue la memoire pour le buffer et initialise le conv
conv->reserve(mv->BlockSize());
conv->reserve(mv->getBlockSize());
// bind buffer to update
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[indexVBO]);
......@@ -338,9 +333,6 @@ void MapRender_VBO::initPrimitives(typename PFP::MAP& map, const FunctorSelect&
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, size*sizeof(GLuint), &(tableIndices[0]), GL_STREAM_DRAW);
}
template<typename PFP>
void MapRender_VBO::initFlatTriangles(typename PFP::MAP& map, const FunctorSelect& good)
{
......@@ -393,13 +385,8 @@ void MapRender_VBO::initFlatTriangles(typename PFP::MAP& map, const FunctorSelec
//creating VBO for flat
glBindBufferARB(GL_ARRAY_BUFFER, m_VBOBuffers[FLAT_BUFFER]);
glBufferDataARB(GL_ARRAY_BUFFER, tableFlat.size() * sizeof(Geom::Vec3f), (char*)(&(tableFlat[0])), GL_STREAM_DRAW);
}
} // namespace VBO
} // namespace Render
......
......@@ -41,47 +41,56 @@ namespace CGoGN
class RegisteredBaseAttribute;
/**
* Container de stockage d'attributs par block de vecteur
* Les trous sont gérés automatiquement par ligne
* ie: on a tableau (multi-blocs) pour chaque attributs, mais
* Tous les tableaux ont le même nombre d'attributs et les
* trous (et les indices) sont les mêmes pour tous les attributs
* On peut ajouter et enlever des attributs a la volée
*/
* Container for AttributeMultiVectors
* All the attributes always have the same size and
* the management of holes is shared by all attributes
*/
class AttributeContainer
{
protected:
typedef std::map<std::string, unsigned int> MapNameId;
public:
/**
* vecteur des blocs qui gerent les cases libres
* constante d'attribut inconnu
*/
std::vector<HoleBlockRef*> m_holesBlocks;
static const unsigned int UNKNOWN = 0xffffffff;
/**
* tables of indices of block with free elts
* Taille du bloc
*/
std::vector<unsigned int> m_tableBlocksWithFree;
std::vector<unsigned int> m_tableBlocksEmpty;
static const unsigned int BlockSize = _BLOCKSIZE_;
protected:
/**
* vecteur de pointeur sur les gestionnaires d'attributs
* vector of pointers to AttributeMultiVectors
*/
std::vector<AttributeMultiVectorGen*> m_tableAttribs;
/**
* vector of free indices in the vector of AttributeMultiVectors
*/
std::vector<unsigned int> m_freeIndices;
/**
* map de correspondance string / indice pour les attributs
* vector of pointers to HoleBlockRef -> structure that manages holes and refs
*/
MapNameId m_attribNameMap;
std::vector<HoleBlockRef*> m_holesBlocks;
// std::vector<unsigned int> m_processAttribs;
/**
* vector of indices of blocks that have free space
*/
std::vector<unsigned int> m_tableBlocksWithFree;
/**
* vector of indices of blocks that are empty
*/
std::vector<unsigned int> m_tableBlocksEmpty;
/**
* nombre d'attributs
* orbit of the container
*/
unsigned int m_orbit;
/**
* number of attributes
*/
unsigned int m_nbAttributes;
......@@ -101,154 +110,123 @@ protected:
unsigned int m_maxSize;
/**
* Cout memoire d'une ligne
* memory cost of each line
*/
unsigned int m_lineCost;
/**
* load xmlpart of container
* map pointer (shared for all container of the same map) for attribute registration
*/
bool loadXmlHB(xmlNodePtr node);
std::map<std::string, RegisteredBaseAttribute*>* m_attributes_registry_map;
/**
* load xmlpart of container
*/
bool loadXmlBWF(xmlNodePtr node);
public:
AttributeContainer();
/**
* load xmlpart of container
*/
bool loadXmlAN(xmlNodePtr node, unsigned int nbb);
~AttributeContainer();
unsigned int getOrbit();
void setOrbit(unsigned int orbit);
void setRegistry(std::map<std::string, RegisteredBaseAttribute*>* re);
/**************************************
* BASIC FEATURES *
**************************************/
/**
* load xmlpart of container
* add a new attribute to the container
* @param T (template) type of the new attribute
* @param attribName name of the new attribute
* @return pointer to the new AttributeMultiVector
*/
bool loadXmlDL(xmlNodePtr node);
template <typename T>
AttributeMultiVector<T>* addAttribute(const std::string& attribName);
protected:
/**
* map ptr (shared for all container of the same map) for attribute registry
* add a new attribute with a given index (for load only)
* @param T (template) type of the new attribute
* @param attribName name of the new attribute
* @param typeName name of the new attribute's type
* @param index index of the new attribute
*/
std::map< std::string, RegisteredBaseAttribute* >* m_attributes_registry_map;
template <typename T>
void addAttribute(const std::string& attribName, const std::string& typeName, unsigned int index);
public:
/**
* constante d'attribut inconnu
* Remove an attribute (destroys data)
* @param attribName name of the attribute to remove
* @return removed or not
*/
static const unsigned int UNKNOWN = 0xffffffff;
bool removeAttribute(const std::string& attribName);
/**
* Taille du bloc
* Remove an attribute (destroys data)
* @param index index of the attribute to remove
* @return removed or not
*/
static const unsigned int BlockSize = _BLOCKSIZE_;
bool removeAttribute(unsigned int index);
/**************************************
* INFO ABOUT THE CONTAINER *
**************************************/
/**
* constructor
*/
AttributeContainer();
* Number of attributes of the container
*/
unsigned int getNbAttributes() const;
/**
* destructor
* Size of the container (number of lines)
*/
~AttributeContainer();
unsigned int size() const;
/**
* is the line used in the container
* Capacity of the container (number of lines including holes)
*/
inline bool used(unsigned int eltIdx) const;
unsigned int capacity() const;
/**
* set the registry map
*/
inline void setRegistry(std::map< std::string, RegisteredBaseAttribute* >* re);
* Total memory cost of container
*/
unsigned int memoryTotalSize() const;
/**
* swapping
*/
void swap(AttributeContainer&);
* is the line used in the container
*/
inline bool used(unsigned int index) const;
/**
* merge
*/
void merge(AttributeContainer& cont);
/**************************************
* CONTAINER TRAVERSAL *
**************************************/
/**
* extract orbit from code (orbit & id)
* return the index of the first line of the container
*/
inline static unsigned int orbitAttr(unsigned int idAttr)
{
return idAttr >> 24;
}
unsigned int begin() const;
/**
* extract index of attribute in container from code (orbit & id)
* return the index of the last line of the container
*/
inline static unsigned int indexAttr(unsigned int idAttr)
{
return idAttr & 0x00ffffff;
}
unsigned int end() const;
/**
* create an attrib Id based on the orbit and the index
* get the index of the line after it in the container
* MUST BE USED INSTEAD OF ++ !
*/
inline static unsigned int attrId(unsigned int orbit, unsigned int index)
{
return (orbit << 24) | index ;
}
/**
* ajout d'un attribut
* @param T (template) type de l'attribut a ajouter
* @return the id of attribute
*/
template <typename T>
unsigned int addAttribute(const std::string& attribName);
/**
* ajout d'un attribut avec identificateur (pour le chargement)
* @param T (template) type de l'attribut a ajouter
* @param attribName nom de l'attribut
* @param id index de l'attribut
*/
template <typename T>
unsigned int addAttribute(const std::string& attribName, const std::string& nametype, unsigned int id);
bool copyAttribute(unsigned int index_dst, unsigned int index_src);
void next(unsigned int &it) const;
bool swapAttributes(unsigned int index1, unsigned int index2);
/**************************************
* INFO ABOUT ATTRIBUTES *
**************************************/
/**
* recuperation du code d'un attribut
* @param attribName nom de l'attribut
* @return l'indice de l'attribut
* @return l'indice de l'attribut
*/
unsigned int getAttribute(const std::string& attribName);
/**
* Remove an attribute (destroys data)
* @param attribName name of the attribute to remove
*/
bool removeAttribute(const std::string& attribName);
/**
* Remove an attribute (destroys data)
* @param index index of the attribute to remove
* @return removed or not
*/
bool removeAttribute(unsigned int index);
/**
* teste si un attribut est valide (encore dans la map de noms)
* @param attr attribut a tester
* @return vrai attribut encore utilise dans le container
*/
bool isValidAttribute(unsigned int attr);
/**
* remplit un vecteur avec les noms des attributs du container.
* @param strings (OUT) tableau des noms d'attributs
* @return le nombre d'attributs
*/
unsigned int getAttributesNames(std::vector<std::string>& names);
unsigned int getAttributeIndex(const std::string& attribName);
/**
* get the name of an attribute, given its index in the container
......@@ -256,231 +234,177 @@ public:
const std::string& getAttributeName(unsigned int attrIndex);
/**
* return the number of attributes of the container
* fill a vector with pointers to the blocks of the given attribute
* @param attrIndex index of the attribute
* @param vect_addr (OUT) vector of pointers
* @param byteBlockSize (OUT) size in bytes of each block
* @return number of blocks
*/
unsigned int getNbAttributes();
/**
* insert une ligne vide dans tous les tableaux (compteur de referencements = 0)
* @return retourne un iterator sur la ligne (indice uint)
*/
unsigned int insertLine();
template<typename T>
unsigned int getAttributeBlocksPointers(unsigned int attrIndex, std::vector<T*>& vect_ptr, unsigned int& byteBlockSize);
/**
*
* fill a vector with attributes' names
* @param vector of names
* @return number of attribute
*/
void initLine(unsigned int idx);
unsigned int getAttributesNames(std::vector<std::string>& names);
/**
* Supprime une ligne d'attribut
* @param eltIdx iterator sur cette ligne
*/
void removeLine(unsigned int eltIdx);
/**************************************
* CONTAINER MANAGEMENT *
**************************************/
/**
*
* swap two containers
*/
void copyLine(unsigned int dstIdx, unsigned int srcIdx);
/**
* Incremente le compteur de reference de la ligne
* @param eltIdx iterator sur cette ligne
*/
void refLine(unsigned int eltIdx);
void swap(AttributeContainer& cont);
/**
* Decremente le compteur de reference de la ligne
* @param eltIdx iterator sur cette ligne
*/
bool unrefLine(unsigned int eltIdx);
void setRefLine(unsigned int eltIdx, unsigned int nb);
/**
* retourne une reference sur un attribut
* @param T type de l'attribut a recuperer
* @param codeAttrib code de l'attribut
* @param eltIdx indice de la ligne
* @return le pointeur sur l'attribut recherche
*/
template <typename T>
T& getData(unsigned int codeAttrib, unsigned int eltIdx);
* clear the container
* @param removeAttrib remove the attributes (not only their data)
*/
void clear(bool clearAttrib = false);
/**
* retourne une reference constnate sur un attribut
* @param T type de l'attribut a recuperer
* @param codeAttrib code de l'attribut
* @param eltIdx indice de la ligne
* @return le pointeur sur l'attribut recherche
*/
template <typename T>
const T& getData(unsigned int codeAttrib, unsigned int eltIdx) const;
* container compacting
* @param mapOldNew table that contains a map from old indices to new indices (holes -> 0xffffffff)
*/
void compact(std::vector<unsigned int>& mapOldNew);
/**
* affecte un attribut dans le container
* @param T type de l'attribut a affecter, compile souvent sans le mettre, mais danger: (cast implicites sur plusieurs niveaux de template ...)
* @param codeAttrib code de l'attribut
* @param eltIdx indice de la ligne
* @param data attribut a inserer
*/
template <typename T>
void setData(unsigned int codeAttrib, unsigned int eltIdx, const T& data);
/**************************************
* LINES MANAGEMENT *
**************************************/
/**
* Renvoit un pseudo vecteur d'attribut (operateur [])
* Attention plantage assure si l'attribut n'existe pas
* A utiliser apres un getAttribute et test du resultat
* @param codeAttrib code de l'attribut
* insert a line in the container
* @return index of the line
*/
template<typename T>
AttributeMultiVector<T>& getDataVector(unsigned int codeAttrib);
AttributeMultiVectorGen& getVirtualDataVector(unsigned int codeAttrib);
unsigned int insertLine();
/**
* Renvoit un pseudo vecteur d'attribut (operateur [])
* Attention plantage assure si l'attribut n'existe pas
* @param name nom de l'attribut
* remove a line in the container
* @param index index of the line to remove
*/
// template<typename T>
// AttributeMultiVector<T>& getAttributesVector(const std::string& name);
void removeLine(unsigned int index);
/**
* Renvoit un pseudo vecteur d'attribut (operateur [])
* Avantages: pas de plantage et pas besoin de mettre le parametre template si le type ptr est ok
* @param name nom de l'attribut
* @param ptr pointeur de pointeur du container
* @return vrai si OK faux si pb
*/
template<typename T>
bool getAttributesVector(const std::string& name, AttributeMultiVector<T>** ptr);