本文整理汇总了C++中NormsIndexesTableType::currentSize方法的典型用法代码示例。如果您正苦于以下问题:C++ NormsIndexesTableType::currentSize方法的具体用法?C++ NormsIndexesTableType::currentSize怎么用?C++ NormsIndexesTableType::currentSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NormsIndexesTableType
的用法示例。
在下文中一共展示了NormsIndexesTableType::currentSize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FromFbxMesh
//.........这里部分代码省略.........
//import polygons
{
for (int i=0; i<polyCount; ++i)
{
int pSize = fbxMesh->GetPolygonSize(i);
if (pSize > 4)
{
//not handled for the moment
continue;
}
//we split quads into two triangles
//vertex indices
int i1 = fbxMesh->GetPolygonVertex(i, 0);
int i2 = fbxMesh->GetPolygonVertex(i, 1);
int i3 = fbxMesh->GetPolygonVertex(i, 2);
mesh->addTriangle(i1,i2,i3);
int i4 = -1;
if (pSize == 4)
{
i4 = fbxMesh->GetPolygonVertex(i, 3);
mesh->addTriangle(i1,i3,i4);
}
if (hasTexUV)
{
if (texUVTable)
{
assert(perVertexUV >= 0);
int uvIndex = static_cast<int>(texUVTable->currentSize());
for (int j=0; j<pSize; ++j)
{
int lTextureUVIndex = fbxMesh->GetTextureUVIndex(i, j);
FbxGeometryElementUV* leUV = fbxMesh->GetElementUV(perVertexUV);
FbxVector2 uv = leUV->GetDirectArray().GetAt(lTextureUVIndex);
//convert to CC-structure
float uvf[2] = {static_cast<float>(uv.Buffer()[0]),
static_cast<float>(uv.Buffer()[1])};
texUVTable->addElement(uvf);
}
mesh->addTriangleTexCoordIndexes(uvIndex,uvIndex+1,uvIndex+2);
if (pSize == 4)
mesh->addTriangleTexCoordIndexes(uvIndex,uvIndex+2,uvIndex+3);
}
else
{
mesh->addTriangleTexCoordIndexes(i1,i2,i3);
if (pSize == 4)
mesh->addTriangleTexCoordIndexes(i1,i3,i4);
}
}
//per-triangle normals
if (normsTable)
{
int nIndex = static_cast<int>(normsTable->currentSize());
for (int j=0; j<pSize; ++j)
{
FbxVector4 N;
fbxMesh->GetPolygonVertexNormal(i, j, N);
CCVector3 Npc( static_cast<PointCoordinateType>(N.Buffer()[0]),
static_cast<PointCoordinateType>(N.Buffer()[1]),
示例2: ToFbxMesh
// Converts a CC mesh to an FBX mesh
static FbxNode* ToFbxMesh(ccGenericMesh* mesh, FbxScene* pScene)
{
if (!mesh)
return 0;
FbxMesh* lMesh = FbxMesh::Create(pScene, qPrintable(mesh->getName()));
ccGenericPointCloud* cloud = mesh->getAssociatedCloud();
if (!cloud)
return 0;
unsigned vertCount = cloud->size();
unsigned faceCount = mesh->size();
// Create control points.
{
lMesh->InitControlPoints(vertCount);
FbxVector4* lControlPoints = lMesh->GetControlPoints();
for (unsigned i=0; i<vertCount; ++i)
{
const CCVector3* P = cloud->getPoint(i);
lControlPoints[i] = FbxVector4(P->x,P->y,P->z);
}
}
ccMesh* asCCMesh = 0;
if (mesh->isA(CC_MESH))
asCCMesh = static_cast<ccMesh*>(mesh);
// normals
if (mesh->hasNormals())
{
FbxGeometryElementNormal* lGeometryElementNormal = lMesh->CreateElementNormal();
if (mesh->hasTriNormals())
{
// We want to have one normal per vertex of each polygon,
// so we set the mapping mode to eByPolygonVertex.
lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
lGeometryElementNormal->GetIndexArray().SetCount(faceCount*3);
if (asCCMesh)
{
NormsIndexesTableType* triNorms = asCCMesh->getTriNormsTable();
assert(triNorms);
for (unsigned i=0; i<triNorms->currentSize(); ++i)
{
const PointCoordinateType* N = ccNormalVectors::GetNormal(triNorms->getValue(i));
FbxVector4 Nfbx(N[0],N[1],N[2]);
lGeometryElementNormal->GetDirectArray().Add(Nfbx);
}
for (unsigned j=0; j<faceCount; ++j)
{
int i1,i2,i3;
asCCMesh->getTriangleNormalIndexes(j,i1,i2,i3);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+0, i1);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+1, i2);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+2, i3);
}
}
else
{
for (unsigned j=0; j<faceCount; ++j)
{
//we can't use the 'NormsIndexesTable' so we save all the normals of all the vertices
CCVector3 Na,Nb,Nc;
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(Na.x,Na.y,Na.z));
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(Nb.x,Nb.y,Nb.z));
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(Nc.x,Nc.y,Nc.z));
mesh->getTriangleNormals(j,Na,Nb,Nc);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+0, static_cast<int>(j)*3+0);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+1, static_cast<int>(j)*3+1);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+2, static_cast<int>(j)*3+2);
}
}
}
else
{
// We want to have one normal for each vertex (or control point),
// so we set the mapping mode to eByControlPoint.
lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByControlPoint);
// The first method is to set the actual normal value
// for every control point.
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eDirect);
for (unsigned i=0; i<vertCount; ++i)
{
const PointCoordinateType* N = cloud->getPointNormal(i);
FbxVector4 Nfbx(N[0],N[1],N[2]);
lGeometryElementNormal->GetDirectArray().Add(Nfbx);
}
}
}
else
{
ccLog::Warning("[FBX] Mesh has no normal! You can manually compute them (select it then call \"Edit > Normals > Compute\")");
}
// colors
//.........这里部分代码省略.........
示例3: saveToFile
CC_FILE_ERROR ObjFilter::saveToFile(ccHObject* entity, QString filename, SaveParameters& parameters)
{
if (!entity)
return CC_FERR_BAD_ARGUMENT;
if (!entity->isKindOf(CC_TYPES::MESH))
{
ccLog::Warning("[OBJ] This filter can only save one mesh (optionally with sub-meshes) at a time!");
return CC_FERR_BAD_ENTITY_TYPE;
}
//mesh
ccGenericMesh* mesh = ccHObjectCaster::ToGenericMesh(entity);
if (!mesh || mesh->size() == 0)
{
ccLog::Warning("[OBJ] Input mesh is empty!");
return CC_FERR_NO_SAVE;
}
//vertices
ccGenericPointCloud* vertices = mesh->getAssociatedCloud();
if (!vertices || vertices->size() == 0)
{
ccLog::Warning("[OBJ] Input mesh has no vertices?!");
return CC_FERR_NO_SAVE;
}
unsigned nbPoints = vertices->size();
//try to open file for saving
QFile file(filename);
if (!file.open(QFile::Text | QFile::WriteOnly))
return CC_FERR_WRITING;
//progress
ccProgressDialog pdlg(true);
unsigned numberOfTriangles = mesh->size();
CCLib::NormalizedProgress nprogress(&pdlg,numberOfTriangles);
pdlg.setMethodTitle(qPrintable(QString("Saving mesh [%1]").arg(mesh->getName())));
pdlg.setInfo(qPrintable(QString("Triangles: %1").arg(numberOfTriangles)));
pdlg.start();
QTextStream stream(&file);
stream.setRealNumberPrecision(sizeof(PointCoordinateType) == 4 ? 8 : 12);
stream << "#OBJ Generated by CloudCompare (TELECOM PARISTECH/EDF R&D)" << endl;
if (file.error() != QFile::NoError)
return CC_FERR_WRITING;
for (unsigned i=0; i<nbPoints; ++i)
{
const CCVector3* P = vertices->getPoint(i);
CCVector3d Pglobal = vertices->toGlobal3d<PointCoordinateType>(*P);
stream << "v " << Pglobal.x << " " << Pglobal.y << " " << Pglobal.z << endl;
if (file.error() != QFile::NoError)
return CC_FERR_WRITING;
}
//normals
bool withTriNormals = mesh->hasTriNormals();
bool withVertNormals = vertices->hasNormals();
bool withNormals = withTriNormals || withVertNormals;
if (withNormals)
{
//per-triangle normals
if (withTriNormals)
{
NormsIndexesTableType* normsTable = mesh->getTriNormsTable();
if (normsTable)
{
for (unsigned i=0; i<normsTable->currentSize(); ++i)
{
const CCVector3& normalVec = ccNormalVectors::GetNormal(normsTable->getValue(i));
stream << "vn " << normalVec.x << " " << normalVec.y << " " << normalVec.z << endl;
if (file.error() != QFile::NoError)
return CC_FERR_WRITING;
}
}
else
{
assert(false);
withTriNormals = false;
}
}
//per-vertices normals
else //if (withVertNormals)
{
for (unsigned i=0; i<nbPoints; ++i)
{
const CCVector3& normalVec = vertices->getPointNormal(i);
stream << "vn " << normalVec.x << " " << normalVec.y << " " << normalVec.z << endl;
if (file.error() != QFile::NoError)
return CC_FERR_WRITING;
}
}
}
//materials
const ccMaterialSet* materials = mesh->getMaterialSet();
bool withMaterials = (materials && mesh->hasMaterials());
if (withMaterials)
//.........这里部分代码省略.........
示例4: loadFile
//.........这里部分代码省略.........
if (tokens.size() < 4)
{
objWarnings[INVALID_LINE] = true;
error = true;
break;
}
CCVector3d Pd( tokens[1].toDouble(), tokens[2].toDouble(), tokens[3].toDouble() );
//first point: check for 'big' coordinates
if (pointsRead == 0)
{
if (HandleGlobalShift(Pd,Pshift,parameters))
{
vertices->setGlobalShift(Pshift);
ccLog::Warning("[OBJ] Cloud has been recentered! Translation: (%.2f,%.2f,%.2f)",Pshift.x,Pshift.y,Pshift.z);
}
}
//shifted point
CCVector3 P = CCVector3::fromArray((Pd + Pshift).u);
vertices->addPoint(P);
++pointsRead;
}
/*** new vertex texture coordinates ***/
else if (tokens.front() == "vt")
{
//create and reserve memory for tex. coords container if necessary
if (!texCoords)
{
texCoords = new TextureCoordsContainer();
texCoords->link();
}
if (texCoords->currentSize() == texCoords->capacity())
{
if (!texCoords->reserve(texCoords->capacity() + MAX_NUMBER_OF_ELEMENTS_PER_CHUNK))
{
objWarnings[NOT_ENOUGH_MEMORY] = true;
error = true;
break;
}
}
//malformed line?
if (tokens.size() < 2)
{
objWarnings[INVALID_LINE] = true;
error = true;
break;
}
float T[2] = { T[0] = tokens[1].toFloat(), 0 };
if (tokens.size() > 2) //OBJ specification allows for only one value!!!
{
T[1] = tokens[2].toFloat();
}
texCoords->addElement(T);
++texCoordsRead;
}
/*** new vertex normal ***/
else if (tokens.front() == "vn") //--> in fact it can also be a facet normal!!!
{
//create and reserve memory for normals container if necessary
if (!normals)
示例5: ToFbxMesh
// Converts a CC mesh to an FBX mesh
static FbxNode* ToFbxMesh(ccGenericMesh* mesh, FbxScene* pScene, QString filename, size_t meshIndex)
{
if (!mesh)
return 0;
FbxNode* lNode = FbxNode::Create(pScene,qPrintable(mesh->getName()));
FbxMesh* lMesh = FbxMesh::Create(pScene, qPrintable(mesh->getName()));
lNode->SetNodeAttribute(lMesh);
ccGenericPointCloud* cloud = mesh->getAssociatedCloud();
if (!cloud)
return 0;
unsigned vertCount = cloud->size();
unsigned faceCount = mesh->size();
// Create control points.
{
lMesh->InitControlPoints(vertCount);
FbxVector4* lControlPoints = lMesh->GetControlPoints();
for (unsigned i=0; i<vertCount; ++i)
{
const CCVector3* P = cloud->getPoint(i);
lControlPoints[i] = FbxVector4(P->x,P->y,P->z);
//lControlPoints[i] = FbxVector4(P->x,P->z,-P->y); //DGM: see loadFile (Y and Z are inverted)
}
}
ccMesh* asCCMesh = 0;
if (mesh->isA(CC_TYPES::MESH))
asCCMesh = static_cast<ccMesh*>(mesh);
// normals
if (mesh->hasNormals())
{
FbxGeometryElementNormal* lGeometryElementNormal = lMesh->CreateElementNormal();
if (mesh->hasTriNormals())
{
// We want to have one normal per vertex of each polygon,
// so we set the mapping mode to eByPolygonVertex.
lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByPolygonVertex);
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
lGeometryElementNormal->GetIndexArray().SetCount(faceCount*3);
if (asCCMesh)
{
NormsIndexesTableType* triNorms = asCCMesh->getTriNormsTable();
assert(triNorms);
for (unsigned i=0; i<triNorms->currentSize(); ++i)
{
const CCVector3& N = ccNormalVectors::GetNormal(triNorms->getValue(i));
FbxVector4 Nfbx(N.x,N.y,N.z);
lGeometryElementNormal->GetDirectArray().Add(Nfbx);
}
for (unsigned j=0; j<faceCount; ++j)
{
int i1,i2,i3;
asCCMesh->getTriangleNormalIndexes(j,i1,i2,i3);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+0, i1);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+1, i2);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+2, i3);
}
}
else
{
for (unsigned j=0; j<faceCount; ++j)
{
//we can't use the 'NormsIndexesTable' so we save all the normals of all the vertices
CCVector3 Na,Nb,Nc;
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(Na.x,Na.y,Na.z));
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(Nb.x,Nb.y,Nb.z));
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(Nc.x,Nc.y,Nc.z));
mesh->getTriangleNormals(j,Na,Nb,Nc);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+0, static_cast<int>(j)*3+0);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+1, static_cast<int>(j)*3+1);
lGeometryElementNormal->GetIndexArray().SetAt(static_cast<int>(j)*3+2, static_cast<int>(j)*3+2);
}
}
}
else
{
// We want to have one normal for each vertex (or control point),
// so we set the mapping mode to eByControlPoint.
lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByControlPoint);
// The first method is to set the actual normal value
// for every control point.
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eDirect);
for (unsigned i=0; i<vertCount; ++i)
{
const CCVector3& N = cloud->getPointNormal(i);
FbxVector4 Nfbx(N.x,N.y,N.z);
lGeometryElementNormal->GetDirectArray().Add(Nfbx);
}
}
}
else
{
//.........这里部分代码省略.........
示例6: if
//.........这里部分代码省略.........
}
for (unsigned i=0; i<addedVertCount; ++i)
{
if (vertIndexes[i] < 0)
{
vertIndexes[i] = static_cast<int>(vertCount++);
vertices->addPoint(P[i]);
}
}
}
//number of triangles to add
unsigned addTriCount = (addedVertCount == 3 ? 1 : 2);
//now add the corresponding face(s)
if (!m_faces->reserve(m_faces->size() + addTriCount))
{
ccLog::Error("[DxfImporter] Not enough memory!");
return;
}
m_faces->addTriangle(vertIndexes[0], vertIndexes[1], vertIndexes[2]);
if (addedVertCount == 4)
m_faces->addTriangle(vertIndexes[0], vertIndexes[2], vertIndexes[3]);
//add per-triangle normals
{
//normals table
NormsIndexesTableType* triNormsTable = m_faces->getTriNormsTable();
bool firstTime = false;
if (!triNormsTable)
{
triNormsTable = new NormsIndexesTableType();
m_faces->setTriNormsTable(triNormsTable);
m_faces->addChild(triNormsTable);
firstTime = true;
}
//add 1 or 2 new entries
unsigned triNormCount = triNormsTable->currentSize();
if (!triNormsTable->reserve(triNormsTable->currentSize() + addTriCount))
{
ccLog::Error("[DxfImporter] Not enough memory!");
return;
}
CCVector3 N = (P[1]-P[0]).cross(P[2]-P[0]);
N.normalize();
triNormsTable->addElement(ccNormalVectors::GetNormIndex(N.u));
if (addTriCount == 2)
{
N = (P[2]-P[0]).cross(P[3]-P[0]);
N.normalize();
triNormsTable->addElement(ccNormalVectors::GetNormIndex(N.u));
}
//per-triangle normals indexes
if (firstTime)
{
if (!m_faces->reservePerTriangleNormalIndexes())
{
ccLog::Error("[DxfImporter] Not enough memory!");
return;
}
m_faces->showNormals(true);
}
int n1 = static_cast<int>(triNormCount);
m_faces->addTriangleNormalIndexes(n1, n1, n1);
if (addTriCount == 2)
{
int n2 = static_cast<int>(triNormCount+1);
m_faces->addTriangleNormalIndexes(n2, n2, n2);
}
}
//and now for the color
if (faceCol)
{
//RGB field already instantiated?
if (vertices->hasColors())
{
for (unsigned i=0; i<createdVertCount; ++i)
vertices->addRGBColor(faceCol);
}
//otherwise, reserve memory and set all previous points to white by default
else if (vertices->setRGBColor(ccColor::white))
{
//then replace the last color(s) by the current one
for (unsigned i=0; i<createdVertCount; ++i)
vertices->setPointColor(vertCount-1-i,faceCol);
m_faces->showColors(true);
}
}
else if (vertices->hasColors())
{
//add default color if none is defined!
for (unsigned i=0; i<createdVertCount; ++i)
vertices->addRGBColor(ccColor::white);
}
}