added PerMeshAttribute
This commit is contained in:
parent
86c880176d
commit
db1c99cdf9
|
@ -682,6 +682,61 @@ public:
|
|||
m.face_attr.erase(i);
|
||||
}
|
||||
|
||||
/// Per Mesh Attributes
|
||||
template <class ATTR_TYPE>
|
||||
static
|
||||
typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>
|
||||
AddPerMeshAttribute( MeshType & m, std::string name){
|
||||
HWIte i;
|
||||
HandlesWrapper h;
|
||||
h._name = name;
|
||||
if(!name.empty()){
|
||||
i = m.mesh_attr.find(h);
|
||||
assert(i ==m.mesh_attr.end() );// an attribute with this name exists
|
||||
}
|
||||
h._handle = (void*) new Attribute<ATTR_TYPE>();
|
||||
std::pair < HandlesIterator , bool> res = m.mesh_attr.insert(h);
|
||||
return typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>(res.first->_handle);
|
||||
}
|
||||
|
||||
template <class ATTR_TYPE>
|
||||
static
|
||||
typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>
|
||||
GetPerMeshAttribute( const MeshType & m, const std::string & name){
|
||||
assert(!name.empty());
|
||||
HandlesWrapper h1; h1._name = name;
|
||||
typename std::set<HandlesWrapper > ::const_iterator i;
|
||||
|
||||
i =m.mesh_attr.find(h1);
|
||||
if(i!=m.mesh_attr.end())
|
||||
return typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE>((*i)._handle);
|
||||
else
|
||||
return typename MeshType:: template PerMeshAttributeHandle<ATTR_TYPE>(NULL);
|
||||
}
|
||||
|
||||
template <class ATTR_TYPE>
|
||||
static
|
||||
void
|
||||
DeletePerMeshAttribute( MeshType & m,typename MeshType::template PerMeshAttributeHandle<ATTR_TYPE> & h){
|
||||
typename std::set<HandlesWrapper > ::iterator i;
|
||||
for( i = m.mesh_attr.begin(); i != m.mesh_attr.end(); ++i)
|
||||
if( (*i)._handle == h._handle ){
|
||||
delete (( Attribute<ATTR_TYPE> *)(*i)._handle);
|
||||
m.mesh_attr.erase(i);
|
||||
return;}
|
||||
assert(0);
|
||||
}
|
||||
|
||||
template <class ATTR_TYPE >
|
||||
static
|
||||
void DeletePerMeshAttribute( MeshType & m, std::string name){
|
||||
HandlesIterator i;
|
||||
HandlesWrapper h1; h1._name = name;
|
||||
i = m.mesh_attr.find(h1);
|
||||
assert(i!=m.mesh_attr.end());
|
||||
delete ((Attribute<ATTR_TYPE> *)(*i)._handle);
|
||||
m.mesh_attr.erase(i);
|
||||
}
|
||||
}; // end class
|
||||
|
||||
|
||||
|
|
|
@ -222,9 +222,17 @@ class TriMesh{
|
|||
ATTR_TYPE & operator [](const RefType & i){return (*_handle)[i];}
|
||||
};
|
||||
|
||||
template <class ATTR_TYPE>
|
||||
class PerMeshAttributeHandle{
|
||||
public:
|
||||
PerMeshAttributeHandle(void *ah):_handle ( (Attribute<ATTR_TYPE> *)ah ){}
|
||||
Attribute<ATTR_TYPE> * _handle;
|
||||
ATTR_TYPE & operator ()(){ return *((Attribute<ATTR_TYPE> *)_handle)->attribute;}
|
||||
};
|
||||
|
||||
std::set< HandlesWrapper> vert_attr;
|
||||
std::set< HandlesWrapper> face_attr;
|
||||
std::set< HandlesWrapper > vert_attr;
|
||||
std::set< HandlesWrapper > face_attr;
|
||||
std::set< HandlesWrapper > mesh_attr;
|
||||
|
||||
/// La camera
|
||||
Camera<ScalarType> camera; // intrinsic
|
||||
|
@ -261,17 +269,26 @@ public:
|
|||
delete ((SimpleTempDataBase<VertContainer>*)(*i)._handle);
|
||||
for( i = face_attr.begin(); i != face_attr.end(); ++i)
|
||||
delete ((SimpleTempDataBase<FaceContainer>*)(*i)._handle);
|
||||
for( i = mesh_attr.begin(); i != mesh_attr.end(); ++i)
|
||||
delete ((AttributeBase*)(*i)._handle);
|
||||
}
|
||||
|
||||
inline int MemUsed() const
|
||||
{
|
||||
return sizeof(MeshType)+sizeof(VertexType)*vert.size()+sizeof(FaceType)*face.size();
|
||||
}
|
||||
int Mem(const int & nv, const int & nf) const {
|
||||
typename std::set< HandlesWrapper>::const_iterator i;
|
||||
int size = 0;
|
||||
size += sizeof(TriMesh)+sizeof(VertexType)*nv+sizeof(FaceType)*nf;
|
||||
|
||||
inline int MemNeeded() const
|
||||
{
|
||||
return sizeof(MeshType)+sizeof(VertexType)*vn+sizeof(FaceType)*fn;
|
||||
for( i = vert_attr.begin(); i != vert_attr.end(); ++i)
|
||||
size += ((SimpleTempDataBase<VertContainer>*)(*i)._handle)->SizeOf()*nv;
|
||||
for( i = face_attr.begin(); i != face_attr.end(); ++i)
|
||||
size += ((SimpleTempDataBase<FaceContainer>*)(*i)._handle)->SizeOf()*nf;
|
||||
for( i = mesh_attr.begin(); i != mesh_attr.end(); ++i)
|
||||
size += ((AttributeBase*)(*i)._handle)->SizeOf();
|
||||
|
||||
return size;
|
||||
}
|
||||
int MemUsed() const {return Mem(vert.size(),face.size());}
|
||||
inline int MemNeeded() const {return Mem(vn,fn);}
|
||||
|
||||
|
||||
|
||||
|
@ -459,6 +476,15 @@ bool HasPerFaceAttribute(const MESH_TYPE &m, std::string name){
|
|||
return (ai!= m.face_attr.end() ) ;
|
||||
}
|
||||
|
||||
template <class MESH_TYPE>
|
||||
bool HasPerMeshAttribute(const MESH_TYPE &m, std::string name){
|
||||
typename std::set< typename MESH_TYPE::HandlesWrapper>::const_iterator ai;
|
||||
typename MESH_TYPE::HandlesWrapper h;
|
||||
h._name = name;
|
||||
ai = m.mesh_attr.find(h);
|
||||
return (ai!= m.mesh_attr.end() ) ;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
/*@}*/
|
||||
} // end namespace
|
||||
|
|
Loading…
Reference in New Issue