本文整理汇总了C++中VertexAttribute::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ VertexAttribute::isValid方法的具体用法?C++ VertexAttribute::isValid怎么用?C++ VertexAttribute::isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VertexAttribute
的用法示例。
在下文中一共展示了VertexAttribute::isValid方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: computeNormal
void Surface_DifferentialProperties_Plugin::computeNormal(
const QString& mapName,
const QString& positionAttributeName,
const QString& normalAttributeName,
bool autoUpdate)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
if(mh == NULL)
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
if(!position.isValid())
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> normal = mh->getAttribute<PFP2::VEC3, VERTEX>(normalAttributeName);
if(!normal.isValid())
normal = mh->addAttribute<PFP2::VEC3, VERTEX>(normalAttributeName);
PFP2::MAP* map = mh->getMap();
Algo::Surface::Geometry::computeNormalVertices<PFP2>(*map, position, normal);
computeNormalLastParameters[mapName] =
ComputeNormalParameters(positionAttributeName, normalAttributeName, autoUpdate);
mh->notifyAttributeModification(normal);
}
示例2: CCSubdivision
void Surface_Subdivision_Plugin::CCSubdivision(
const QString& mapName,
const QString& positionAttributeName, bool interp)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
if(mh == NULL)
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
if(!position.isValid())
return;
pythonRecording("CCSubdivision", "", mapName, positionAttributeName,interp);
PFP2::MAP* map = mh->getMap();
if (interp)
Algo::Surface::Modelisation::CatmullClarkInterpolSubdivision<PFP2>(*map, position);
else
Algo::Surface::Modelisation::CatmullClarkSubdivision<PFP2>(*map, position);
mh->notifyAttributeModification(position);
mh->notifyConnectivityModification();
foreach(View* view, mh->getLinkedViews())
view->updateGL();
}
示例3: testVAbyNames
/**
* @brief test if map has a Vertex Attribute of VEC3 named name
* @param map the map
* @param name name of attribute
*/
void testVAbyNames(MAP& map, const std::string& name)
{
VertexAttribute<VEC3, MAP> testPos = map.getAttribute<VEC3, VERTEX, MAP>(name);
if (testPos.isValid())
std::cout << "Attribute "<< name <<" valid"<< std::endl;
else
std::cout << "Attribute "<< name <<"invalid"<< std::endl;
}
示例4:
void UniversalLoader<MapType, AttrTypeLoader>::UnpackOnVertex(MapType& map, const unsigned int* verticesId, const AHEMHeader* hdr, const char* attrName, const void* buffer) const
{
VertexAttribute<typename AttrTypeLoader::ATTR_TYPE> attr = map.template getAttribute<typename AttrTypeLoader::ATTR_TYPE, VERTEX>(attrName);
if (!attr.isValid())
attr = map.template addAttribute<typename AttrTypeLoader::ATTR_TYPE, VERTEX>(attrName);
char* p = (char*)buffer;
for(unsigned int i = 0 ; i < hdr->meshHdr.vxCount ; i++)
{
AttrTypeLoader::Extract(&attr[verticesId[i]], p);
p += AttrTypeLoader::TYPE_SIZE_IN_BUFFER;
}
}
示例5:
void AHEMImporter<PFP>::LoadPosition(AHEMAttributeDescriptor* posDescr)
{
VertexAttribute<typename PFP::VEC3, typename PFP::MAP> position = map->template getAttribute<typename PFP::VEC3, VERTEX, typename PFP::MAP>("position");
if (!position.isValid())
position = map->template addAttribute<typename PFP::VEC3, VERTEX, typename PFP::MAP>("position");
f.seekg(posDescr->fileStartOffset, std::ios_base::beg);
f.read(buffer, posDescr->attributeChunkSize);
float* q = (float*)buffer;
for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++)
{
position[verticesId[i]] = typename PFP::VEC3(q[0], q[1], q[2]);
q += 3;
}
}
示例6: fp
bool MeshTablesVolume<PFP>::importTs(const std::string& filename, std::vector<std::string>& attrNames)
{
//
VertexAttribute<VEC3> position = m_map.template getAttribute<VEC3, VERTEX>("position") ;
if (!position.isValid())
position = m_map.template addAttribute<VEC3, VERTEX>("position") ;
attrNames.push_back(position.name()) ;
//
VertexAttribute<REAL> scalar = m_map.template getAttribute<REAL, VERTEX>("scalar");
if (!scalar.isValid())
scalar = m_map.template addAttribute<REAL, VERTEX>("scalar") ;
attrNames.push_back(scalar.name()) ;
//
AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
// open file
std::ifstream fp(filename.c_str(), std::ios::in);
if (!fp.good())
{
CGoGNerr << "Unable to open file " << filename << CGoGNendl;
return false;
}
std::string ligne;
// reading number of vertices/tetrahedra
std::getline (fp, ligne);
std::stringstream oss(ligne);
oss >> m_nbVertices;
oss >> m_nbVolumes;
//reading vertices
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
for(unsigned int i = 0; i < m_nbVertices; ++i)
{
do
{
std::getline (fp, ligne);
} while (ligne.size() == 0);
std::stringstream oss(ligne);
float x,y,z;
oss >> x;
oss >> y;
oss >> z;
VEC3 pos(x,y,z);
unsigned int id = container.insertLine();
position[id] = pos;
verticesID.push_back(id);
float scal;
oss >> scal;
scalar[id] = scal;
}
//Read and embed all tetrahedrons
for(unsigned int i = 0; i < m_nbVolumes ; ++i)
{
do
{
std::getline(fp,ligne);
} while(ligne.size() == 0);
std::stringstream oss(ligne);
m_nbFaces.push_back(4);
int s0,s1,s2,s3,nbe;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
typename PFP::VEC3 P = position[verticesID[s0]];
typename PFP::VEC3 A = position[verticesID[s1]];
typename PFP::VEC3 B = position[verticesID[s2]];
typename PFP::VEC3 C = position[verticesID[s3]];
if(Geom::testOrientation3D<typename PFP::VEC3>(P,A,B,C) == Geom::UNDER)
{
int ui = s1;
s1 = s2;
s2 = ui;
}
//if regions are defined use this number
//.........这里部分代码省略.........
示例7: fnode
bool MeshTablesVolume<PFP>::importNodeWithELERegions(const std::string& filenameNode, const std::string& filenameELE, std::vector<std::string>& attrNames)
{
VertexAttribute<VEC3> position = m_map.template getAttribute<VEC3, VERTEX>("position") ;
if (!position.isValid())
position = m_map.template addAttribute<VEC3, VERTEX>("position") ;
attrNames.push_back(position.name()) ;
AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
//open file
std::ifstream fnode(filenameNode.c_str(), std::ios::in);
if (!fnode.good())
{
CGoGNerr << "Unable to open file " << filenameNode << CGoGNendl;
return false;
}
std::ifstream fele(filenameELE.c_str(), std::ios::in);
if (!fele.good())
{
CGoGNerr << "Unable to open file " << filenameELE << CGoGNendl;
return false;
}
std::string line;
//Reading NODE file
//First line: [# of points] [dimension (must be 3)] [# of attributes] [# of boundary markers (0 or 1)]
unsigned int nbe;
{
do
{
std::getline(fnode,line);
}while(line.size() == 0);
std::stringstream oss(line);
oss >> m_nbVertices;
oss >> nbe;
oss >> nbe;
oss >> nbe;
}
//Reading number of tetrahedra in ELE file
unsigned int nbv;
{
do
{
std::getline(fele,line);
}while(line.size() == 0);
std::stringstream oss(line);
oss >> m_nbVolumes;
oss >> nbv ;
oss >> nbv;
}
//Reading vertices
std::map<unsigned int,unsigned int> verticesMapID;
for(unsigned int i = 0 ; i < m_nbVertices ; ++i)
{
do
{
std::getline(fnode,line);
}while(line.size() == 0);
std::stringstream oss(line);
int idv;
oss >> idv;
float x,y,z;
oss >> x;
oss >> y;
oss >> z;
//we can read colors informations if exists
VEC3 pos(x,y,z);
unsigned int id = container.insertLine();
position[id] = pos;
verticesMapID.insert(std::pair<unsigned int, unsigned int>(idv,id));
}
// reading tetrahedra
m_nbFaces.reserve(m_nbVolumes*4);
m_emb.reserve(m_nbVolumes*12);
for(unsigned i = 0; i < m_nbVolumes ; ++i)
{
do
{
std::getline(fele,line);
} while(line.size() == 0);
std::stringstream oss(line);
oss >> nbe;
m_nbFaces.push_back(4);
//.........这里部分代码省略.........
示例8: foff
bool MeshTablesVolume<PFP>::importOFFWithELERegions(const std::string& filenameOFF, const std::string& filenameELE, std::vector<std::string>& attrNames)
{
VertexAttribute<VEC3> position = m_map.template getAttribute<VEC3, VERTEX>("position") ;
if (!position.isValid())
position = m_map.template addAttribute<VEC3, VERTEX>("position") ;
attrNames.push_back(position.name()) ;
AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
// open files
std::ifstream foff(filenameOFF.c_str(), std::ios::in);
if (!foff.good())
{
CGoGNerr << "Unable to open OFF file " << CGoGNendl;
return false;
}
std::ifstream fele(filenameELE.c_str(), std::ios::in);
if (!fele.good())
{
CGoGNerr << "Unable to open ELE file " << CGoGNendl;
return false;
}
std::string line;
//OFF reading
std::getline(foff, line);
if(line.rfind("OFF") == std::string::npos)
{
CGoGNerr << "Problem reading off file: not an off file"<<CGoGNendl;
CGoGNerr << line << CGoGNendl;
return false;
}
//Reading number of vertex/faces/edges in OFF file
unsigned int nbe;
{
do
{
std::getline(foff,line);
}while(line.size() == 0);
std::stringstream oss(line);
oss >> m_nbVertices;
oss >> nbe;
oss >> nbe;
oss >> nbe;
}
//Reading number of tetrahedra in ELE file
unsigned int nbv;
{
do
{
std::getline(fele,line);
}while(line.size() == 0);
std::stringstream oss(line);
oss >> m_nbVolumes;
oss >> nbv ;
oss >> nbv;
}
//Reading vertices
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
for(unsigned int i = 0 ; i < m_nbVertices ; ++i)
{
do
{
std::getline(foff,line);
}while(line.size() == 0);
std::stringstream oss(line);
float x,y,z;
oss >> x;
oss >> y;
oss >> z;
//we can read colors informations if exists
VEC3 pos(x,y,z);
unsigned int id = container.insertLine();
position[id] = pos;
verticesID.push_back(id);
}
// reading tetrahedra
m_nbFaces.reserve(m_nbVolumes*4);
m_emb.reserve(m_nbVolumes*12);
for(unsigned i = 0; i < m_nbVolumes ; ++i)
{
do
{
std::getline(fele,line);
//.........这里部分代码省略.........
示例9: fp
bool MeshTablesVolume<PFP>::importTet(const std::string& filename, std::vector<std::string>& attrNames)
{
VertexAttribute<VEC3, MAP> position = m_map.template getAttribute<VEC3, VERTEX, MAP>("position") ;
if (!position.isValid())
position = m_map.template addAttribute<VEC3, VERTEX, MAP>("position") ;
attrNames.push_back(position.name()) ;
AttributeContainer& container = m_map.template getAttributeContainer<VERTEX>() ;
//open file
std::ifstream fp(filename.c_str(), std::ios::in);
if (!fp.good())
{
CGoGNerr << "Unable to open file " << filename << CGoGNendl;
return false;
}
std::string ligne;
// reading number of vertices
std::getline (fp, ligne);
std::stringstream oss(ligne);
oss >> m_nbVertices;
// reading number of tetrahedra
std::getline (fp, ligne);
std::stringstream oss2(ligne);
oss2 >> m_nbVolumes;
//reading vertices
std::vector<unsigned int> verticesID;
verticesID.reserve(m_nbVertices);
for(unsigned int i = 0; i < m_nbVertices; ++i)
{
do
{
std::getline (fp, ligne);
} while (ligne.size() == 0);
std::stringstream oss(ligne);
float x,y,z;
oss >> x;
oss >> y;
oss >> z;
// TODO : if required read other vertices attributes here
VEC3 pos(x,y,z);
unsigned int id = container.insertLine();
position[id] = pos;
verticesID.push_back(id);
}
// reading volumes
m_nbFaces.reserve(m_nbVolumes*4);
m_emb.reserve(m_nbVolumes*12);
unsigned int nbc = 0;
for (unsigned int i = 0; i < m_nbVolumes ; ++i)
{
do
{
std::getline (fp, ligne);
} while (ligne.size()==0);
std::stringstream oss(ligne);
int n;
oss >> n; // type of volumes
if(!oss.good())
{
oss.clear();
char dummy;
oss >> dummy; // type of volumes
oss >> dummy;
if(dummy == 'C')// connector
{
++nbc;
m_nbFaces.push_back(3);
int s0,s1,s2,s3;
oss >> s0;
oss >> s1;
oss >> s2;
oss >> s3;
//std::cout << "connector " << s0 << " " << s1 << " " << s2 << " " << s3 << std::endl;
m_emb.push_back(verticesID[s0]);
m_emb.push_back(verticesID[s1]);
m_emb.push_back(verticesID[s2]);
m_emb.push_back(verticesID[s3]);
//.........这里部分代码省略.........
示例10: sizeof
void AHEMImporter<PFP>::LoadTopology()
{
// Allocate vertices
AttributeContainer& vxContainer = map->template getAttributeContainer<VERTEX>();
verticesId = new unsigned int[hdr.meshHdr.vxCount];
for(unsigned int i = 0 ; i < hdr.meshHdr.vxCount ; i++)
verticesId[i] = vxContainer.insertLine();
// Ensure vertices are created by querying the position attribute
VertexAttribute<typename PFP::VEC3, typename PFP::MAP> position = map->template getAttribute<typename PFP::VEC3, VERTEX, typename PFP::MAP>("position");
if (!position.isValid())
position = map->template addAttribute<typename PFP::VEC3, VERTEX, typename PFP::MAP>("position");
// Read faces stream and create faces [only intra-face links]
HESorter* addedHE = new HESorter[hdr.meshHdr.heCount];
facesId = new Dart[hdr.meshHdr.faceCount];
f.read(buffer, hdr.meshHdr.meshChunkSize);
char* batch = buffer;
unsigned int fId = 0;
unsigned int heId = 0;
while(fId < hdr.meshHdr.faceCount)
{
AHEMFaceBatchDescriptor* fbd = (AHEMFaceBatchDescriptor*)batch;
stUInt32* ix = (stUInt32*)(batch + sizeof(AHEMFaceBatchDescriptor));
for(unsigned int i = 0 ; i < fbd->batchLength ; i++)
{
Dart d = map->newFace(fbd->batchFaceSize); // create face
facesId[fId++] = d;
unsigned int firstVx = verticesId[*ix++]; // setup face's vertices up to last HE
unsigned int prevVx = firstVx;
for(unsigned int k = 0 ; k < fbd->batchFaceSize - 1 ; k++)
{
addedHE[heId].d = d;
addedHE[heId].vxIdFrom = prevVx;
addedHE[heId].vxIdTo = verticesId[*ix];
map->setDartEmbedding<VERTEX>(d, prevVx);
d = map->phi1(d);
prevVx = *ix++;
heId++;
}
// last HE
addedHE[heId].d = d;
addedHE[heId].vxIdFrom = prevVx;
addedHE[heId].vxIdTo = firstVx;
map->setDartEmbedding<VERTEX>(d, prevVx);
heId++;
}
batch = (char*)ix;
}
// Sort the HE for fast retrieval
std::sort(addedHE, addedHE + hdr.meshHdr.heCount);
// Sew faces [inter-face links]
for(unsigned int i = 0 ; i < hdr.meshHdr.heCount ; i++)
{
HESorter* opposite = (HESorter*)bsearch(addedHE + i, addedHE, hdr.meshHdr.heCount, sizeof(HESorter), OppositeSearch);
if(opposite && opposite->d == map->phi2(opposite->d))
map->sewFaces(addedHE[i].d, opposite->d);
}
}
示例11: computeCurvature
void Surface_DifferentialProperties_Plugin::computeCurvature(
const QString& mapName,
const QString& positionAttributeName,
const QString& normalAttributeName,
const QString& KmaxAttributeName,
const QString& kmaxAttributeName,
const QString& KminAttributeName,
const QString& kminAttributeName,
const QString& KnormalAttributeName,
bool compute_kmean,
bool compute_kgaussian,
bool autoUpdate)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
if(mh == NULL)
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
if(!position.isValid())
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> normal = mh->getAttribute<PFP2::VEC3, VERTEX>(normalAttributeName);
if(!normal.isValid())
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> Kmax = mh->getAttribute<PFP2::VEC3, VERTEX>(KmaxAttributeName);
if(!Kmax.isValid())
Kmax = mh->addAttribute<PFP2::VEC3, VERTEX>(KmaxAttributeName);
VertexAttribute<PFP2::REAL, PFP2::MAP> kmax = mh->getAttribute<PFP2::REAL, VERTEX>(kmaxAttributeName);
if(!kmax.isValid())
kmax = mh->addAttribute<PFP2::REAL, VERTEX>(kmaxAttributeName);
VertexAttribute<PFP2::VEC3, PFP2::MAP> Kmin = mh->getAttribute<PFP2::VEC3, VERTEX>(KminAttributeName);
if(!Kmin.isValid())
Kmin = mh->addAttribute<PFP2::VEC3, VERTEX>(KminAttributeName);
VertexAttribute<PFP2::REAL, PFP2::MAP> kmin = mh->getAttribute<PFP2::REAL, VERTEX>(kminAttributeName);
if(!kmin.isValid())
kmin = mh->addAttribute<PFP2::REAL, VERTEX>(kminAttributeName);
VertexAttribute<PFP2::VEC3, PFP2::MAP> Knormal = mh->getAttribute<PFP2::VEC3, VERTEX>(KnormalAttributeName);
if(!Knormal.isValid())
Knormal = mh->addAttribute<PFP2::VEC3, VERTEX>(KnormalAttributeName);
EdgeAttribute<PFP2::REAL, PFP2::MAP> edgeAngle = mh->getAttribute<PFP2::REAL, EDGE>("edgeAngle");
if(!edgeAngle.isValid())
edgeAngle = mh->addAttribute<PFP2::REAL, EDGE>("edgeAngle");
PFP2::MAP* map = mh->getMap();
Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP2>(*map, position, edgeAngle);
Algo::Surface::Geometry::computeCurvatureVertices_NormalCycles_Projected<PFP2>(*map, 0.01f * mh->getBBdiagSize(), position, normal, edgeAngle, kmax, kmin, Kmax, Kmin, Knormal);
computeCurvatureLastParameters[mapName] =
ComputeCurvatureParameters(
positionAttributeName, normalAttributeName,
KmaxAttributeName, kmaxAttributeName, KminAttributeName, kminAttributeName, KnormalAttributeName,
compute_kmean, compute_kgaussian, autoUpdate);
mh->notifyAttributeModification(Kmax);
mh->notifyAttributeModification(kmax);
mh->notifyAttributeModification(Kmin);
mh->notifyAttributeModification(kmin);
mh->notifyAttributeModification(Knormal);
if(compute_kmean)
{
VertexAttribute<PFP2::REAL, PFP2::MAP> kmean = mh->getAttribute<PFP2::REAL, VERTEX>("kmean");
if(!kmean.isValid())
kmean = mh->addAttribute<PFP2::REAL, VERTEX>("kmean");
for(unsigned int i = kmin.begin(); i != kmin.end(); kmin.next(i))
kmean[i] = (kmin[i] + kmax[i]) / 2.0;
mh->notifyAttributeModification(kmean);
}
if(compute_kgaussian)
{
VertexAttribute<PFP2::REAL, PFP2::MAP> kgaussian = mh->getAttribute<PFP2::REAL, VERTEX>("kgaussian");
if(!kgaussian.isValid())
kgaussian = mh->addAttribute<PFP2::REAL, VERTEX>("kgaussian");
for(unsigned int i = kmin.begin(); i != kmin.end(); kmin.next(i))
kgaussian[i] = kmin[i] * kmax[i];
mh->notifyAttributeModification(kgaussian);
}
}
示例12: main
int main()
{
// declare a map to handle the mesh
MAP myMap;
// add position attribute on vertices and get handler on it
VertexAttribute<VEC3, MAP> positionAtt = myMap.addAttribute<VEC3, VERTEX, MAP>("position");
if (!positionAtt.isValid())
std::cerr << "impossible to create an attribute with name position (already used ?)"<< std::endl;
// create a topo grid of 2x2 squares
Algo::Surface::Tilings::Square::Grid<PFP> grid(myMap, 2, 2, true);
// and embed it using position attribute
grid.embedIntoGrid(positionAtt, 1.,1.,0.);
VertexGeneric(myMap,positionAtt);
// ATTRIBUTE DECLARATION
// add an attribute of type float on orbit EDGE
EdgeAttribute<float, MAP> lengthAtt = myMap.addAttribute<float, EDGE, MAP>("length");
if (!lengthAtt.isValid())
std::cerr << "impossible to create the attribute"<< std::endl;
computeLengthEdges(myMap,positionAtt,lengthAtt);
// add an attribute of type std::string on orbit FACE
FaceAttribute<std::string, MAP> nameAtt = myMap.addAttribute<std::string, FACE, MAP>("name");
if (!nameAtt.isValid())
std::cerr << "impossible to create the attribute"<< std::endl;
// for complex type use following template (function nameOfType not applicable)
EdgeAttribute< NoTypeNameAttribute< std::vector<int> >, MAP> vectAtt = myMap.addAttribute< NoTypeNameAttribute< std::vector<int> >, EDGE, MAP>("vector_of_int");
if (!vectAtt.isValid())
std::cerr << "impossible to create the attribute"<< std::endl;
Dart d = myMap.begin();
// define a vertex from a dart
Vertex v(d);
// define a face from a dart
Face f(d);
// ATTRIBUTE ACCESS
// [] operator can take a dart, a cell (only same off attribute), or an unsigned inf
// access to any attributes with darts
std::cout << positionAtt[d]<< std::endl;
nameAtt[d] = "Hello";
lengthAtt[myMap.phi1(d)] = 54.0f;
std::vector<int> vi = {3,5,7,9,11};
vectAtt[d]= vi;
vectAtt[d].push_back(11);
// access to VertexAttribute with a Vertex
std::cout << positionAtt[v]<< std::endl;
// access to FaceAttribute with a Face
std::cout << nameAtt[f]<< std::endl;
// following line does not compile because of wrong cell type
// std::cout << positionAtt[f]<< std::endl;
// possible to bypass using dart access
std::cout << positionAtt[f.dart]<< std::endl;
// access with unsigned int is dangerous, index must be obtain with begin/end/next (see dumpAttribute)
// COPY, REMOVE, SWAP
// possible to have any number of attribute a same ORBIT
VertexAttribute<VEC3, MAP> position2Att = myMap.addAttribute<VEC3, VERTEX, MAP>("other_position");
// copy of attribute of same type (linear complexity)
myMap.copyAttribute(position2Att,positionAtt);
positionAtt[v] += VEC3(0,0,1);
computeNewPositions(myMap,positionAtt);
dumpAttribute(positionAtt);
//check if there is a Vertex Attribute of VEC3 named position => yes
testVAbyNames(myMap,"position");
// remove the attribute
myMap.removeAttribute(positionAtt);
//check if there is a Vertex Attribute of VEC3 named position => no
testVAbyNames(myMap,"position");
return 0;
}
示例13: decimate
void Surface_Radiance_Plugin::decimate(const QString& mapName, const QString& positionAttributeName, const QString& normalAttributeName, float decimationGoal, bool halfCollapse, bool exportMeshes)
{
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
if(mh == NULL)
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
if(!position.isValid())
return;
VertexAttribute<PFP2::VEC3, PFP2::MAP> normal = mh->getAttribute<PFP2::VEC3, VERTEX>(normalAttributeName);
if(!normal.isValid())
return;
PFP2::MAP* map = mh->getMap();
unsigned int nbVertices = Algo::Topo::getNbOrbits<VERTEX>(*map);
MapParameters& mapParams = h_mapParameterSet[mh];
if (halfCollapse)
{
if (mapParams.positionApproximator == NULL)
{
mapParams.positionApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>(*map, position);
}
if (mapParams.normalApproximator == NULL)
{
mapParams.normalApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, PFP2::VEC3>(*map, normal);
}
if (mapParams.radianceApproximator == NULL)
{
mapParams.radianceApproximator = new Algo::Surface::Decimation::Approximator_HalfCollapse<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(*map, mapParams.radiance);
}
if (mapParams.selector == NULL)
{
mapParams.selector = new HalfEdgeSelector_Radiance<PFP2>(
*map,
position,
normal,
mapParams.radiance,
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, DART>*)(mapParams.positionApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, DART>*)(mapParams.normalApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, DART>*)(mapParams.radianceApproximator)
);
}
}
else
{
if (mapParams.positionApproximator == NULL)
{
mapParams.positionApproximator = new Algo::Surface::Decimation::Approximator_QEM<PFP2>(*map, position);
}
if (mapParams.normalApproximator == NULL)
{
mapParams.normalApproximator =
new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, PFP2::VEC3>(
*map,
normal,
position,
((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
);
}
if (mapParams.radianceApproximator == NULL)
{
mapParams.radianceApproximator =
new Algo::Surface::Decimation::Approximator_InterpolateAlongEdge<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3> >(
*map,
mapParams.radiance,
position,
((Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator))->getApproximationResultAttribute()
);
}
if (mapParams.selector == NULL)
{
mapParams.selector =
new EdgeSelector_Radiance<PFP2>(
*map,
position,
normal,
mapParams.radiance,
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.normalApproximator),
*(Algo::Surface::Decimation::Approximator<PFP2, Utils::SphericalHarmonics<PFP2::REAL, PFP2::VEC3>, EDGE>*)(mapParams.radianceApproximator)
);
mapParams.selector =
new Algo::Surface::Decimation::EdgeSelector_QEM<PFP2>(
*map,
position,
*(Algo::Surface::Decimation::Approximator<PFP2, PFP2::VEC3, EDGE>*)(mapParams.positionApproximator)
);
}
}
//.........这里部分代码省略.........
示例14: exportPLY
void Surface_Radiance_Plugin::exportPLY(
const QString& mapName,
const QString& positionAttributeName,
const QString& normalAttributeName,
const QString& filename)
{
typedef PFP2::MAP MAP;
typedef PFP2::REAL REAL;
typedef PFP2::VEC3 VEC3;
MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_schnapps->getMap(mapName));
if(mh == NULL)
return;
VertexAttribute<VEC3, MAP> position = mh->getAttribute<VEC3, VERTEX>(positionAttributeName);
if(!position.isValid())
return;
VertexAttribute<VEC3, MAP> normal = mh->getAttribute<VEC3, VERTEX>(normalAttributeName);
if(!normal.isValid())
return;
VertexAttribute<Utils::SphericalHarmonics<REAL, VEC3>, MAP> radiance = h_mapParameterSet[mh].radiance;
if(!radiance.isValid())
return;
// open file
std::ofstream out ;
out.open(filename.toStdString(), std::ios::out | std::ios::binary) ;
if (!out.good())
{
CGoGNerr << "Unable to open file " << CGoGNendl ;
return ;
}
MAP* map = mh->getMap();
unsigned int nbDarts = map->getNbDarts() ;
std::vector<unsigned int> facesSize ;
std::vector<std::vector<unsigned int> > facesIdx ;
facesSize.reserve(nbDarts/3) ;
facesIdx.reserve(nbDarts/3) ;
std::map<unsigned int, unsigned int> vIndex ;
unsigned int vCpt = 0 ;
std::vector<unsigned int> vertices ;
vertices.reserve(nbDarts/6) ;
// Go over all faces
CellMarker<MAP, VERTEX> markV(*map) ;
TraversorF<MAP> t(*map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
{
std::vector<unsigned int> fidx ;
fidx.reserve(8) ;
unsigned int degree = 0 ;
Traversor2FV<MAP> tfv(*map, d) ;
for(Dart it = tfv.begin(); it != tfv.end(); it = tfv.next())
{
++degree ;
unsigned int vNum = map->getEmbedding<VERTEX>(it) ;
if(!markV.isMarked(it))
{
markV.mark(it) ;
vIndex[vNum] = vCpt++ ;
vertices.push_back(vNum) ;
}
fidx.push_back(vIndex[vNum]) ;
}
facesSize.push_back(degree) ;
facesIdx.push_back(fidx) ;
}
// Start writing the file
out << "ply" << std::endl ;
// test endianness
union
{
uint32_t i ;
char c[4] ;
} bint = {0x01020304} ;
if (bint.c[0] == 1) // big endian
out << "format binary_big_endian 1.0" << std::endl ;
else
out << "format binary_little_endian 1.0" << std::endl ;
out << "comment File generated by the CGoGN library" << std::endl ;
out << "comment See : http://cgogn.unistra.fr/" << std::endl ;
out << "comment or contact : [email protected]" << std::endl ;
// Vertex elements
out << "element vertex " << vertices.size() << std::endl ;
std::string nameOfTypePly_REAL(nameOfTypePly(position[0][0])) ;
out << "property " << nameOfTypePly_REAL << " x" << std::endl ;
out << "property " << nameOfTypePly_REAL << " y" << std::endl ;
out << "property " << nameOfTypePly_REAL << " z" << std::endl ;
//.........这里部分代码省略.........