Implemented the correct management of per edge attribute. It was half done...

This commit is contained in:
Paolo Cignoni 2011-12-15 07:23:51 +00:00
parent 9779f0f8c7
commit 3b61972116
1 changed files with 75 additions and 40 deletions

View File

@ -954,12 +954,9 @@ public:
assert(new_i.second); assert(new_i.second);
i = new_i.first; i = new_i.first;
} }
return typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr); return typename MeshType::template PerVertexAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
} }
return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0); return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0);
} }
template <class ATTR_TYPE> template <class ATTR_TYPE>
@ -1028,8 +1025,8 @@ public:
} }
h._sizeof = sizeof(ATTR_TYPE); h._sizeof = sizeof(ATTR_TYPE);
h._padding = 0; h._padding = 0;
h._typename = typeid(ATTR_TYPE).name(); // h._typename = typeid(ATTR_TYPE).name();
h._handle = (void*) new SimpleTempData<EdgeContainer,ATTR_TYPE>(m.edge); h._handle = new SimpleTempData<EdgeContainer,ATTR_TYPE>(m.edge);
m.attrn++; m.attrn++;
h.n_attr = m.attrn; h.n_attr = m.attrn;
std::pair < AttrIterator , bool> res = m.edge_attr.insert(h); std::pair < AttrIterator , bool> res = m.edge_attr.insert(h);
@ -1046,18 +1043,28 @@ public:
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static
typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE> typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE>
GetPerEdgeAttribute( const MeshType & m, const std::string & name){ GetPerEdgeAttribute( MeshType & m, const std::string & name){
assert(!name.empty()); assert(!name.empty());
PointerToAttribute h1; h1._name = name; PointerToAttribute h1; h1._name = name;
typename std::set<PointerToAttribute > ::const_iterator i; typename std::set<PointerToAttribute > ::const_iterator i;
i =m.edge_attr.find(h1); i =m.edge_attr.find(h1);
if(i!=m.edge_attr.end()) if(i!=m.edge_attr.end())
if((*i)._typename == typeid(ATTR_TYPE).name() ) if((*i)._sizeof == sizeof(ATTR_TYPE) ){
return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0); if( (*i)._padding != 0 ){
PointerToAttribute attr = (*i); // copy the PointerToAttribute
m.edge_attr.erase(i); // remove it from the set
FixPaddedPerEdgeAttribute<ATTR_TYPE>(m,attr);
std::pair<AttrIterator,bool> new_i = m.edge_attr.insert(attr); // insert the modified PointerToAttribute
assert(new_i.second);
i = new_i.first;
}
return typename MeshType::template PerEdgeAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
}
// if((*i)._typename == typeid(ATTR_TYPE).name() )
// return typename MeshType:: template PerVertexAttributeHandle<ATTR_TYPE>(NULL,0);
return typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE>(NULL,0); return typename MeshType:: template PerEdgeAttributeHandle<ATTR_TYPE>(NULL,0);
} }
template <class ATTR_TYPE> template <class ATTR_TYPE>
@ -1313,6 +1320,34 @@ public:
// zero the padding // zero the padding
pa._padding = 0; pa._padding = 0;
} }
template <class ATTR_TYPE>
static
void FixPaddedPerEdgeAttribute (MeshType & m, PointerToAttribute & pa){
// create the container of the right type
SimpleTempData<EdgeContainer,ATTR_TYPE>* _handle = new SimpleTempData<EdgeContainer,ATTR_TYPE>(m.edge);
// copy the padded container in the new one
_handle->Resize(m.edge.size());
for(unsigned int i = 0; i < m.edge.size(); ++i){
ATTR_TYPE * dest = &(*_handle)[i];
char * ptr = (char*)( ((SimpleTempDataBase *)pa._handle)->DataBegin());
memcpy((void*)dest ,
(void*) &(ptr[i * pa._sizeof ]) ,sizeof(ATTR_TYPE));
}
// remove the padded container
delete ((SimpleTempDataBase*) pa._handle);
// update the pointer to data
pa._sizeof = sizeof(ATTR_TYPE);
// update the pointer to data
pa._handle = _handle;
// zero the padding
pa._padding = 0;
}
template <class ATTR_TYPE> template <class ATTR_TYPE>
static static