ConstPerFaceAttributeHandle

This commit is contained in:
alemuntoni 2021-03-23 16:12:04 +01:00
parent 7c601cc837
commit e0ccec2fc8
3 changed files with 91 additions and 55 deletions

View File

@ -1423,7 +1423,8 @@ public:
public:
/*! \brief Check if an handle to a Per-Vertex Attribute is valid
/**
* @brief Checks if a handle to a Per-Vertex Attribute is valid
*/
template <class ATTR_TYPE>
static
@ -1434,7 +1435,8 @@ public:
return false;
}
/*! \brief Check if a const handle to a Per-Vertex Attribute is valid
/**
* @brief Checks if a const handle to a Per-Vertex Attribute is valid
*/
template <class ATTR_TYPE>
static
@ -1501,12 +1503,8 @@ public:
template <class ATTR_TYPE>
static
typename MeshType::template ConstPerVertexAttributeHandle<ATTR_TYPE>
GetConstPerVertexAttribute( const MeshType & m, std::string name = std::string("")){
typename MeshType::template ConstPerVertexAttributeHandle<ATTR_TYPE> h;
if(!name.empty()){
return FindConstPerVertexAttribute<ATTR_TYPE>(m,name);
}
return typename MeshType:: template ConstPerVertexAttributeHandle<ATTR_TYPE>(nullptr,0);
GetPerVertexAttribute( const MeshType & m, std::string name = std::string("")){
return FindPerVertexAttribute<ATTR_TYPE>(m,name);
}
/*! \brief Try to retrieve an handle to an attribute with a given name and ATTR_TYPE
@ -1537,23 +1535,26 @@ public:
}
/**
* Same as the one above, but without modifying the attribute if it is found.
* (A "find" function should never modify the container in which is looking for..)
* Input mesh is const.
* @brief Try to retrieve a const handle to an attribute with a given name
* and ATTR_TYPE, from the given const mesh.
* If not found, an invalid handle will be returned.
* Check it with the function IsValidHandle
*/
template <class ATTR_TYPE>
static typename MeshType::template ConstPerVertexAttributeHandle<ATTR_TYPE>
FindConstPerVertexAttribute( const MeshType & m, const std::string & name)
FindPerVertexAttribute( const MeshType & m, const std::string & name)
{
assert(!name.empty());
if(!name.empty()){
PointerToAttribute h1; h1._name = name;
typename std::set<PointerToAttribute > :: iterator i;
i =m.vert_attr.find(h1);
if(i!=m.vert_attr.end())
if(i!=m.vert_attr.end()){
if((*i)._sizeof == sizeof(ATTR_TYPE) ){
return typename MeshType::template ConstPerVertexAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
}
}
}
return typename MeshType:: template ConstPerVertexAttributeHandle<ATTR_TYPE>(nullptr,0);
}
@ -1568,7 +1569,7 @@ public:
if(!(*i)._name.empty())
{
typename MeshType:: template ConstPerVertexAttributeHandle<ATTR_TYPE> hh;
hh = Allocator<MeshType>:: template FindConstPerVertexAttribute <ATTR_TYPE>(m,(*i)._name);
hh = Allocator<MeshType>:: template FindPerVertexAttribute <ATTR_TYPE>(m,(*i)._name);
if(IsValidHandle<ATTR_TYPE>(m,hh))
all.push_back((*i)._name);
}
@ -1742,6 +1743,9 @@ public:
}
/// Per Face Attributes
/**
* @brief Checks if a handle to a Per-Face attribute is valid
*/
template <class ATTR_TYPE>
static
bool IsValidHandle( const MeshType & m, const typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> & a){
@ -1751,6 +1755,18 @@ public:
return false;
}
/**
* @brief Checks if a const handle to a Per-Face attribute is valid
*/
template <class ATTR_TYPE>
static
bool IsValidHandle( const MeshType & m, const typename MeshType::template ConstPerFaceAttributeHandle<ATTR_TYPE> & a){
if(a._handle == nullptr) return false;
for(AttrIterator i = m.face_attr.begin(); i!=m.face_attr.end();++i)
if ( (*i).n_attr == a.n_attr ) return true;
return false;
}
template <class ATTR_TYPE>
static
typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>
@ -1803,14 +1819,10 @@ public:
*/
template <class ATTR_TYPE>
static
typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>
typename MeshType::template ConstPerFaceAttributeHandle<ATTR_TYPE>
GetPerFaceAttribute( const MeshType & m, std::string name = std::string("")){
typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE> h;
if(!name.empty()){
return FindPerFaceAttribute<ATTR_TYPE>(m,name);
}
return typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE>(nullptr,0);
}
template <class ATTR_TYPE>
static
@ -1837,24 +1849,27 @@ public:
}
/**
* Same as the one above, but without modifying the attribute if it is found.
* (A "find" function should never modify the container in which is looking for..)
* Input mesh is const.
* @brief Try to retrieve a const handle to an attribute with a given name
* and ATTR_TYPE, from the given const mesh.
* If not found, an invalid handle will be returned.
* Check it with the function IsValidHandle
*/
template <class ATTR_TYPE>
static
typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>
typename MeshType::template ConstPerFaceAttributeHandle<ATTR_TYPE>
FindPerFaceAttribute( const MeshType & m, const std::string & name){
assert(!name.empty());
if(!name.empty()){
PointerToAttribute h1; h1._name = name;
typename std::set<PointerToAttribute > ::iterator i;
i =m.face_attr.find(h1);
if(i!=m.face_attr.end())
if(i!=m.face_attr.end()){
if((*i)._sizeof == sizeof(ATTR_TYPE) ){
return typename MeshType::template PerFaceAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
return typename MeshType::template ConstPerFaceAttributeHandle<ATTR_TYPE>((*i)._handle,(*i).n_attr);
}
return typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE>(nullptr,0);
}
}
return typename MeshType:: template ConstPerFaceAttributeHandle<ATTR_TYPE>(nullptr,0);
}
template <class ATTR_TYPE>
@ -1864,7 +1879,7 @@ public:
for(i = m.face_attr.begin(); i != m.face_attr.end(); ++i )
if(!(*i)._name.empty())
{
typename MeshType:: template PerFaceAttributeHandle<ATTR_TYPE> hh;
typename MeshType:: template ConstPerFaceAttributeHandle<ATTR_TYPE> hh;
hh = Allocator<MeshType>:: template FindPerFaceAttribute <ATTR_TYPE>(m,(*i)._name);
if(IsValidHandle<ATTR_TYPE>(m,hh))
all.push_back((*i)._name);

View File

@ -330,7 +330,6 @@ public:
ConstPerVertexAttributeHandle( const void *ah,const int & n):ConstAttributeHandle<ATTR_TYPE,VertContainer>(ah,n){}
};
template <class ATTR_TYPE>
class PerFaceAttributeHandle: public AttributeHandle<ATTR_TYPE,FaceContainer>{
public:
@ -338,6 +337,13 @@ public:
PerFaceAttributeHandle( void *ah,const int & n):AttributeHandle<ATTR_TYPE,FaceContainer>(ah,n){}
};
template <class ATTR_TYPE>
class ConstPerFaceAttributeHandle: public ConstAttributeHandle<ATTR_TYPE,FaceContainer>{
public:
ConstPerFaceAttributeHandle():ConstAttributeHandle<ATTR_TYPE,FaceContainer>(){}
ConstPerFaceAttributeHandle( void *ah,const int & n):ConstAttributeHandle<ATTR_TYPE,FaceContainer>(ah,n){}
};
template <class ATTR_TYPE>
class PerEdgeAttributeHandle: public AttributeHandle<ATTR_TYPE,EdgeContainer>{
public:
@ -345,6 +351,13 @@ public:
PerEdgeAttributeHandle( void *ah,const int & n):AttributeHandle<ATTR_TYPE,EdgeContainer>(ah,n){}
};
template <class ATTR_TYPE>
class ConstPerEdgeAttributeHandle: public ConstAttributeHandle<ATTR_TYPE,EdgeContainer>{
public:
ConstPerEdgeAttributeHandle():ConstAttributeHandle<ATTR_TYPE,EdgeContainer>(){}
ConstPerEdgeAttributeHandle( void *ah,const int & n):ConstAttributeHandle<ATTR_TYPE,EdgeContainer>(ah,n){}
};
template <class ATTR_TYPE>
class PerTetraAttributeHandle : public AttributeHandle<ATTR_TYPE, TetraContainer>
{
@ -353,6 +366,14 @@ public:
PerTetraAttributeHandle(void *ah, const int &n) : AttributeHandle<ATTR_TYPE, TetraContainer>(ah, n) {}
};
template <class ATTR_TYPE>
class ConstPerTetraAttributeHandle : public ConstAttributeHandle<ATTR_TYPE, TetraContainer>
{
public:
ConstPerTetraAttributeHandle() : ConstAttributeHandle<ATTR_TYPE, TetraContainer>() {}
ConstPerTetraAttributeHandle(void *ah, const int &n) : ConstAttributeHandle<ATTR_TYPE, TetraContainer>(ah, n) {}
};
template <class ATTR_TYPE>
class PerMeshAttributeHandle{
public:

View File

@ -374,22 +374,22 @@ namespace vcg {
assert(vcg::tri::HasPerVertexAttribute(m,pi.VertAttrNameVec[i]));
switch (pi.VertDescriptorVec[i].stotype1)
{
case ply::T_FLOAT : thfv[i] = vcg::tri::Allocator<SaveMeshType>::template FindConstPerVertexAttribute<float>(m,pi.VertAttrNameVec[i]); break;
case ply::T_DOUBLE : thdv[i] = vcg::tri::Allocator<SaveMeshType>::template FindConstPerVertexAttribute<double>(m,pi.VertAttrNameVec[i]); break;
case ply::T_INT : thiv[i] = vcg::tri::Allocator<SaveMeshType>::template FindConstPerVertexAttribute<int >(m,pi.VertAttrNameVec[i]); break;
case ply::T_SHORT : thsv[i] = vcg::tri::Allocator<SaveMeshType>::template FindConstPerVertexAttribute<short >(m,pi.VertAttrNameVec[i]); break;
case ply::T_CHAR : thcv[i] = vcg::tri::Allocator<SaveMeshType>::template FindConstPerVertexAttribute<char>(m,pi.VertAttrNameVec[i]); break;
case ply::T_UCHAR : thuv[i] = vcg::tri::Allocator<SaveMeshType>::template FindConstPerVertexAttribute<unsigned char>(m,pi.VertAttrNameVec[i]); break;
case ply::T_FLOAT : thfv[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerVertexAttribute<float>(m,pi.VertAttrNameVec[i]); break;
case ply::T_DOUBLE : thdv[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerVertexAttribute<double>(m,pi.VertAttrNameVec[i]); break;
case ply::T_INT : thiv[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerVertexAttribute<int >(m,pi.VertAttrNameVec[i]); break;
case ply::T_SHORT : thsv[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerVertexAttribute<short >(m,pi.VertAttrNameVec[i]); break;
case ply::T_CHAR : thcv[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerVertexAttribute<char>(m,pi.VertAttrNameVec[i]); break;
case ply::T_UCHAR : thuv[i] = vcg::tri::Allocator<SaveMeshType>::template FindPerVertexAttribute<unsigned char>(m,pi.VertAttrNameVec[i]); break;
default : assert(0);
}
}
}
std::vector<typename SaveMeshType:: template PerFaceAttributeHandle<float > > thff(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template PerFaceAttributeHandle<double> > thdf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template PerFaceAttributeHandle<int > > thif(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template PerFaceAttributeHandle<short > > thsf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template PerFaceAttributeHandle<char > > thcf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template PerFaceAttributeHandle<unsigned char> > thuf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<float > > thff(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<double> > thdf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<int > > thif(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<short > > thsf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<char > > thcf(pi.FaceDescriptorVec.size());
std::vector<typename SaveMeshType:: template ConstPerFaceAttributeHandle<unsigned char> > thuf(pi.FaceDescriptorVec.size());
for(size_t i=0;i<pi.FaceDescriptorVec.size();i++)
{