本文整理汇总了C++中Geometry::AllocateTris方法的典型用法代码示例。如果您正苦于以下问题:C++ Geometry::AllocateTris方法的具体用法?C++ Geometry::AllocateTris怎么用?C++ Geometry::AllocateTris使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Geometry
的用法示例。
在下文中一共展示了Geometry::AllocateTris方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadFile
Geometry* RawncFile::loadFile(const string& fileName)
{
bool zeroSeen = false, maxSeen = false;
//QFileInfo fileInfo(fileName);
//if (!fileInfo.exists()) {
// qDebug("File does not exist");
// return 0;
//}
struct stat fst;
if (stat(fileName.c_str(), &fst) == -1) {
printf("File does not exist\n");
return 0;
}
//QString absFilePath = fileInfo.absFilePath();
//FILE* fp = fopen(absFilePath, "r");
FILE* fp = fopen(fileName.c_str(), "r");
if (!fp) {
//qDebug("Error opening file");
printf("Error opening file\n");
return 0;
}
// get the number of verts and triangles
int numverts, numtris;
if (2!=fscanf(fp, "%d %d", &numverts, &numtris)) {
//qDebug("Error reading in number of verts and tris");
printf("Error reading in number of verts and tris\n");
fclose(fp);
return 0;
}
// make sure the number of verts & tris are positive
if (numverts<0 || numtris<0) {
//qDebug("Negative number of verts or tris");
printf("Negative number of verts or tris\n");
fclose(fp);
return 0;
}
// initialize the geometry
Geometry* geometry = new Geometry();
geometry->AllocateTris(numverts, numtris);
geometry->AllocateTriVertColors();
int c;
// read in the verts
for (c=0; c<numverts; c++) {
// read in a single vert, which includes
// position and normal
if (9!=fscanf(fp, "%f %f %f %f %f %f %f %f %f",
&(geometry->m_TriVerts[c*3+0]),
&(geometry->m_TriVerts[c*3+1]),
&(geometry->m_TriVerts[c*3+2]),
&(geometry->m_TriVertNormals[c*3+0]),
&(geometry->m_TriVertNormals[c*3+1]),
&(geometry->m_TriVertNormals[c*3+2]),
&(geometry->m_TriVertColors[c*3+0]),
&(geometry->m_TriVertColors[c*3+1]),
&(geometry->m_TriVertColors[c*3+2]))) {
//qDebug("Error reading in vert # %d", c);
printf("Error reading in vert # %d\n", c);
delete geometry;
fclose(fp);
return 0;
}
}
// read in the triangles
for (c=0; c<numtris; c++) {
// read in 3 integers for each triangle
if (3!=fscanf(fp, "%u %u %u",
&(geometry->m_Tris[c*3+0]),
&(geometry->m_Tris[c*3+1]),
&(geometry->m_Tris[c*3+2]))) {
//qDebug("Error reading in tri # %d", c);
printf("Error reading in tri # %d\n", c);
delete geometry;
fclose(fp);
return 0;
}
// the file might start indexing verts from 1 or 0
// check if indexes go up to the num of verts or if they
// start from 0
if (geometry->m_Tris[c*3+0]==0 || geometry->m_Tris[c*3+1]==0 || geometry->m_Tris[c*3+2]==0 ) {
zeroSeen = true;
}
if (geometry->m_Tris[c*3+0]==(unsigned int)numverts || geometry->m_Tris[c*3+1]==(unsigned int)numverts || geometry->m_Tris[c*3+2]==(unsigned int)numverts ) {
maxSeen = true;
}
// cant have both!
if (maxSeen && zeroSeen) {
//qDebug("Found 0 & max in tri # %d", c);
printf("Found 0 & max in tri # %d\n", c);
delete geometry;
fclose(fp);
return 0;
}
//.........这里部分代码省略.........
示例2: loadFile
Geometry* RawFile::loadFile(const string& fileName)
{
cvcraw_geometry::geometry_t geom;
try
{
cvcraw_geometry::read(geom, fileName);
}
catch(std::exception& e)
{
printf("Error: %s\n", e.what());
return 0;
}
bool haveColor = !geom.colors.empty();
Geometry *geometry = new Geometry();
if(!geom.lines.empty())
{
geometry->AllocateLines(geom.points.size(),
geom.lines.size());
for(unsigned int i = 0; i < geom.lines.size(); i++)
{
geometry->m_Lines[i*2+0] = geom.lines[i][0];
geometry->m_Lines[i*2+1] = geom.lines[i][1];
}
}
else if(!geom.tris.empty())
{
geometry->AllocateTris(geom.points.size(),
geom.tris.size());
for(unsigned int i = 0; i < geom.tris.size(); i++)
{
geometry->m_Tris[i*3+0] = geom.tris[i][0];
geometry->m_Tris[i*3+1] = geom.tris[i][1];
geometry->m_Tris[i*3+2] = geom.tris[i][2];
}
}
else if(!geom.quads.empty())
{
geometry->AllocateQuads(geom.points.size(),
geom.quads.size());
for(unsigned int i = 0; i < geom.quads.size(); i++)
{
geometry->m_Quads[i*4+0] = geom.quads[i][0];
geometry->m_Quads[i*4+1] = geom.quads[i][1];
geometry->m_Quads[i*4+2] = geom.quads[i][2];
geometry->m_Quads[i*4+3] = geom.quads[i][3];
}
}
else if(!geom.points.empty())
{
geometry->AllocatePoints(geom.points.size());
geometry->AllocatePointNormals();
geometry->AllocatePointColors();
}
for(unsigned int i = 0; i < geom.points.size(); i++)
{
geometry->m_Points[i*3+0] = geom.points[i][0];
geometry->m_Points[i*3+1] = geom.points[i][1];
geometry->m_Points[i*3+2] = geom.points[i][2];
}
if(!geom.normals.empty())
{
for(unsigned int i = 0; i < geom.points.size(); i++)
{
geometry->m_PointNormals[i*3+0] = geom.normals[i][0];
geometry->m_PointNormals[i*3+1] = geom.normals[i][1];
geometry->m_PointNormals[i*3+2] = geom.normals[i][2];
}
}
if(!geom.colors.empty())
{
for(unsigned int i = 0; i < geom.colors.size(); i++)
{
geometry->m_PointColors[i*3+0] = geom.colors[i][0];
geometry->m_PointColors[i*3+1] = geom.colors[i][1];
geometry->m_PointColors[i*3+2] = geom.colors[i][2];
}
}
return geometry;
#if 0
bool zeroSeen = false, maxSeen = false;
//QFileInfo fileInfo(fileName);
//if (!fileInfo.exists()) {
// qDebug("File does not exist");
// return 0;
//}
struct stat fst;
if (stat(fileName.c_str(), &fst) == -1) {
printf("File does not exist\n");
//.........这里部分代码省略.........