本文整理汇总了C++中NormsIndexesTableType::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ NormsIndexesTableType::reserve方法的具体用法?C++ NormsIndexesTableType::reserve怎么用?C++ NormsIndexesTableType::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NormsIndexesTableType
的用法示例。
在下文中一共展示了NormsIndexesTableType::reserve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applyGLTransformation
void ccGenericMesh::applyGLTransformation(const ccGLMatrix& trans)
{
//vertices should be handled another way!
//we must take care of the triangle normals!
if (m_triNormals && (!getParent() || !getParent()->isKindOf(CC_MESH)))
{
bool recoded = false;
//if there is more triangle normals than the size of the compressed
//normals array, we recompress the array instead of recompressing each normal
unsigned i,numTriNormals = m_triNormals->currentSize();
if (numTriNormals>ccNormalVectors::GetNumberOfVectors())
{
NormsIndexesTableType* newNorms = new NormsIndexesTableType;
if (newNorms->reserve(ccNormalVectors::GetNumberOfVectors()))
{
for (i=0; i<ccNormalVectors::GetNumberOfVectors(); i++)
{
CCVector3 new_n(ccNormalVectors::GetNormal(i));
trans.applyRotation(new_n);
normsType newNormIndex = ccNormalVectors::GetNormIndex(new_n.u);
newNorms->addElement(newNormIndex);
}
m_triNormals->placeIteratorAtBegining();
for (i=0; i<numTriNormals; i++)
{
m_triNormals->setValue(i,newNorms->getValue(m_triNormals->getCurrentValue()));
m_triNormals->forwardIterator();
}
recoded=true;
}
newNorms->clear();
newNorms->release();
newNorms=0;
}
//if there is less triangle normals than the compressed normals array size
//(or if there is not enough memory to instantiate the temporary array),
//we recompress each normal ...
if (!recoded)
{
//on recode direct chaque normale
m_triNormals->placeIteratorAtBegining();
for (i=0; i<numTriNormals; i++)
{
normsType* _theNormIndex = m_triNormals->getCurrentValuePtr();
CCVector3 new_n(ccNormalVectors::GetNormal(*_theNormIndex));
trans.applyRotation(new_n.u);
*_theNormIndex = ccNormalVectors::GetNormIndex(new_n.u);
m_triNormals->forwardIterator();
}
}
}
else
{
//TODO: process failed!
}
}
示例2: vertices
const ccGenericPrimitive& ccGenericPrimitive::operator += (const ccGenericPrimitive& prim)
{
ccPointCloud* verts = vertices();
unsigned vertCount = verts->size();
unsigned facesCount = size();
unsigned triFacesNormCount = (m_triNormals ? m_triNormals->currentSize() : 0);
//count new number of vertices & faces
unsigned newVertCount = vertCount + prim.getAssociatedCloud()->size();
unsigned newFacesCount = facesCount + prim.size();
bool primHasVertNorms = prim.getAssociatedCloud()->hasNormals();
bool primHasFaceNorms = prim.hasTriNormals();
//reserve memory
if (verts->reserve(newVertCount)
&& (!primHasVertNorms || verts->reserveTheNormsTable())
&& reserve(newFacesCount)
&& (!primHasFaceNorms || m_triNormalIndexes || reservePerTriangleNormalIndexes()))
{
//copy vertices & normals
ccGenericPointCloud* cloud = prim.getAssociatedCloud();
unsigned i;
for (i=0;i<cloud->size();++i)
{
verts->addPoint(*cloud->getPoint(i));
if (primHasVertNorms)
verts->addNormIndex(cloud->getPointNormalIndex(i));
}
//copy face normals
if (primHasFaceNorms)
{
const NormsIndexesTableType* primNorms = prim.getTriNormsTable();
assert(primNorms);
unsigned primTriNormCount = primNorms->currentSize();
NormsIndexesTableType* normsTable = (m_triNormals ? m_triNormals : new NormsIndexesTableType());
if (!normsTable || !normsTable->reserve(triFacesNormCount+primTriNormCount))
{
ccLog::Error("[ccGenericPrimitive::operator +] Not enough memory!");
return *this;
}
//attach table if not done already
if (!m_triNormals)
{
setTriNormsTable(normsTable);
assert(m_triNormals);
//primitives must have their normal table as child!
addChild(m_triNormals);
}
for (unsigned i=0; i<primTriNormCount; ++i)
normsTable->addElement(primNorms->getValue(i));
}
//copy faces
for (i=0;i<prim.size();++i)
{
const CCLib::TriangleSummitsIndexes* tsi = prim.getTriangleIndexes(i);
addTriangle(vertCount+tsi->i1,vertCount+tsi->i2,vertCount+tsi->i3);
if (primHasFaceNorms)
{
const int* normIndexes = prim.m_triNormalIndexes->getValue(i);
assert(normIndexes);
addTriangleNormalIndexes(triFacesNormCount+normIndexes[0],triFacesNormCount+normIndexes[1],triFacesNormCount+normIndexes[2]);
}
}
}
else
{
ccLog::Error("[ccGenericPrimitive::operator +] Not enough memory!");
}
return *this;
}
示例3: init
bool ccGenericPrimitive::init(unsigned vertCount, bool vertNormals, unsigned faceCounts, unsigned faceNormCounts)
{
ccPointCloud* verts = vertices();
assert(verts);
if (!verts)
return false;
/*** clear existing structures ***/
//clear vertices & normals
verts->clear(); //takes care of vertices normals
//clear triangles indexes
assert(m_triVertIndexes);
m_triVertIndexes->clear();
//clear per triangle normals
removePerTriangleNormalIndexes();
if (m_triNormals)
m_triNormals->clear();
//DGM: if we do this we'll have issues with the DB tree depending on where when we call this method!
//{
// removeChild(m_triNormals);
// setTriNormsTable(0);
// assert(!m_triNormals);
//}
/*** init necessary structures ***/
if (vertCount && !verts->reserve(vertCount))
return false;
if (vertNormals && !verts->reserveTheNormsTable())
{
verts->clear();
return false;
}
if (faceCounts && !reserve(faceCounts))
{
verts->clear();
return false;
}
if (faceNormCounts)
{
NormsIndexesTableType* normsTable = (m_triNormals ? m_triNormals : new NormsIndexesTableType());
if (!normsTable || !normsTable->reserve(faceNormCounts) || !reservePerTriangleNormalIndexes())
{
verts->clear();
m_triVertIndexes->clear();
if (normsTable)
delete normsTable;
return false;
}
//attach table if not done already
if (!m_triNormals)
{
setTriNormsTable(normsTable);
assert(m_triNormals);
//primitives must have their normal table as child!
addChild(m_triNormals);
}
}
return true;
}
示例4: FromFbxMesh
//converts a FBX mesh to a CC mesh
static ccMesh* FromFbxMesh(FbxMesh* fbxMesh, bool alwaysDisplayLoadDialog/*=true*/, bool* coordinatesShiftEnabled/*=0*/, CCVector3d* coordinatesShift/*=0*/)
{
if (!fbxMesh)
return 0;
int polyCount = fbxMesh->GetPolygonCount();
//fbxMesh->GetLayer(
unsigned triCount = 0;
unsigned polyVertCount = 0; //different from vertCount (vertices can be counted multiple times here!)
//as we can't load all polygons (yet ;) we already look if we can load any!
{
unsigned skipped = 0;
for (int i=0; i<polyCount; ++i)
{
int pSize = fbxMesh->GetPolygonSize(i);
if (pSize == 3)
{
++triCount;
polyVertCount += 3;
}
else if (pSize == 4)
{
triCount += 2;
polyVertCount += 4;
}
else
{
++skipped;
}
}
if (triCount == 0)
{
ccLog::Warning(QString("[FBX] No triangle or quad found in mesh '%1'! (polygons with more than 4 vertices are not supported for the moment)").arg(fbxMesh->GetName()));
return 0;
}
else if (skipped != 0)
{
ccLog::Warning(QString("[FBX] Some polygons in mesh '%1' were ignored (%2): polygons with more than 4 vertices are not supported for the moment)").arg(fbxMesh->GetName()).arg(skipped));
return 0;
}
}
int vertCount = fbxMesh->GetControlPointsCount();
if (vertCount <= 0)
{
ccLog::Warning(QString("[FBX] Mesh '%1' has no vetex or no polygon?!").arg(fbxMesh->GetName()));
return 0;
}
ccPointCloud* vertices = new ccPointCloud("vertices");
ccMesh* mesh = new ccMesh(vertices);
mesh->setName(fbxMesh->GetName());
mesh->addChild(vertices);
vertices->setEnabled(false);
if (!mesh->reserve(static_cast<unsigned>(triCount)) || !vertices->reserve(vertCount))
{
ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1'!").arg(fbxMesh->GetName()));
delete mesh;
return 0;
}
//colors
{
for (int l=0; l<fbxMesh->GetElementVertexColorCount(); l++)
{
FbxGeometryElementVertexColor* vertColor = fbxMesh->GetElementVertexColor(l);
//CC can only handle per-vertex colors
if (vertColor->GetMappingMode() == FbxGeometryElement::eByControlPoint)
{
if (vertColor->GetReferenceMode() == FbxGeometryElement::eDirect
|| vertColor->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
{
if (vertices->reserveTheRGBTable())
{
switch (vertColor->GetReferenceMode())
{
case FbxGeometryElement::eDirect:
{
for (int i=0; i<vertCount; ++i)
{
FbxColor c = vertColor->GetDirectArray().GetAt(i);
vertices->addRGBColor( static_cast<colorType>(c.mRed * MAX_COLOR_COMP),
static_cast<colorType>(c.mGreen * MAX_COLOR_COMP),
static_cast<colorType>(c.mBlue * MAX_COLOR_COMP) );
}
}
break;
case FbxGeometryElement::eIndexToDirect:
{
for (int i=0; i<vertCount; ++i)
{
int id = vertColor->GetIndexArray().GetAt(i);
FbxColor c = vertColor->GetDirectArray().GetAt(id);
vertices->addRGBColor( static_cast<colorType>(c.mRed * MAX_COLOR_COMP),
static_cast<colorType>(c.mGreen * MAX_COLOR_COMP),
static_cast<colorType>(c.mBlue * MAX_COLOR_COMP) );
//.........这里部分代码省略.........
示例5: loadFile
CC_FILE_ERROR ObjFilter::loadFile(QString filename, ccHObject& container, LoadParameters& parameters)
{
ccLog::Print(QString("[OBJ] ") + filename);
//open file
QFile file(filename);
if (!file.open(QFile::ReadOnly))
return CC_FERR_READING;
QTextStream stream(&file);
//current vertex shift
CCVector3d Pshift(0,0,0);
//vertices
ccPointCloud* vertices = new ccPointCloud("vertices");
int pointsRead = 0;
//facets
unsigned int facesRead = 0;
unsigned int totalFacesRead = 0;
int maxVertexIndex = -1;
//base mesh
ccMesh* baseMesh = new ccMesh(vertices);
baseMesh->setName(QFileInfo(filename).baseName());
//we need some space already reserved!
if (!baseMesh->reserve(128))
{
ccLog::Error("Not engouh memory!");
return CC_FERR_NOT_ENOUGH_MEMORY;
}
//groups (starting index + name)
std::vector<std::pair<unsigned,QString> > groups;
//materials
ccMaterialSet* materials = 0;
bool hasMaterial = false;
int currentMaterial = -1;
bool currentMaterialDefined = false;
bool materialsLoadFailed = true;
//texture coordinates
TextureCoordsContainer* texCoords = 0;
bool hasTexCoords = false;
int texCoordsRead = 0;
int maxTexCoordIndex = -1;
//normals
NormsIndexesTableType* normals = 0;
int normsRead = 0;
bool normalsPerFacet = false;
int maxTriNormIndex = -1;
//progress dialog
ccProgressDialog pDlg(true);
pDlg.setMethodTitle("OBJ file");
pDlg.setInfo("Loading in progress...");
pDlg.setRange(0,static_cast<int>(file.size()));
pDlg.show();
QApplication::processEvents();
//common warnings that can appear multiple time (we avoid to send too many messages to the console!)
enum OBJ_WARNINGS { INVALID_NORMALS = 0,
INVALID_INDEX = 1,
NOT_ENOUGH_MEMORY = 2,
INVALID_LINE = 3,
CANCELLED_BY_USER = 4,
};
bool objWarnings[5] = { false, false, false, false, false };
bool error = false;
try
{
unsigned lineCount = 0;
unsigned polyCount = 0;
QString currentLine = stream.readLine();
while (!currentLine.isNull())
{
if ((++lineCount % 2048) == 0)
{
if (pDlg.wasCanceled())
{
error = true;
objWarnings[CANCELLED_BY_USER] = true;
break;
}
pDlg.setValue(static_cast<int>(file.pos()));
QApplication::processEvents();
}
QStringList tokens = QString(currentLine).split(QRegExp("\\s+"),QString::SkipEmptyParts);
//skip comments & empty lines
if( tokens.empty() || tokens.front().startsWith('/',Qt::CaseInsensitive) || tokens.front().startsWith('#',Qt::CaseInsensitive) )
{
currentLine = stream.readLine();
continue;
}
//.........这里部分代码省略.........
示例6: createInternalRepresentation
bool ccFacet::createInternalRepresentation( CCLib::GenericIndexedCloudPersist* points,
const PointCoordinateType* planeEquation/*=0*/)
{
assert(points);
if (!points)
return false;
unsigned ptsCount = points->size();
if (ptsCount < 3)
return false;
CCLib::Neighbourhood Yk(points);
//get corresponding plane
if (!planeEquation)
{
planeEquation = Yk.getLSPlane();
if (!planeEquation)
{
ccLog::Warning("[ccFacet::createInternalRepresentation] Failed to compute the LS plane passing through the input points!");
return false;
}
}
memcpy(m_planeEquation, planeEquation, sizeof(PointCoordinateType) * 4);
//we project the input points on a plane
std::vector<CCLib::PointProjectionTools::IndexedCCVector2> points2D;
CCVector3 X, Y; //local base
if (!Yk.projectPointsOn2DPlane<CCLib::PointProjectionTools::IndexedCCVector2>(points2D, nullptr, &m_center, &X, &Y))
{
ccLog::Error("[ccFacet::createInternalRepresentation] Not enough memory!");
return false;
}
//compute resulting RMS
m_rms = CCLib::DistanceComputationTools::computeCloud2PlaneDistanceRMS(points, m_planeEquation);
//update the points indexes (not done by Neighbourhood::projectPointsOn2DPlane)
{
for (unsigned i = 0; i < ptsCount; ++i)
{
points2D[i].index = i;
}
}
//try to get the points on the convex/concave hull to build the contour and the polygon
{
std::list<CCLib::PointProjectionTools::IndexedCCVector2*> hullPoints;
if (!CCLib::PointProjectionTools::extractConcaveHull2D( points2D,
hullPoints,
m_maxEdgeLength*m_maxEdgeLength))
{
ccLog::Error("[ccFacet::createInternalRepresentation] Failed to compute the convex hull of the input points!");
}
unsigned hullPtsCount = static_cast<unsigned>(hullPoints.size());
//create vertices
m_contourVertices = new ccPointCloud();
{
if (!m_contourVertices->reserve(hullPtsCount))
{
delete m_contourVertices;
m_contourVertices = nullptr;
ccLog::Error("[ccFacet::createInternalRepresentation] Not enough memory!");
return false;
}
//projection on the LS plane (in 3D)
for (std::list<CCLib::PointProjectionTools::IndexedCCVector2*>::const_iterator it = hullPoints.begin(); it != hullPoints.end(); ++it)
{
m_contourVertices->addPoint(m_center + X*(*it)->x + Y*(*it)->y);
}
m_contourVertices->setName(DEFAULT_CONTOUR_POINTS_NAME);
m_contourVertices->setLocked(true);
m_contourVertices->setEnabled(false);
addChild(m_contourVertices);
}
//we create the corresponding (3D) polyline
{
m_contourPolyline = new ccPolyline(m_contourVertices);
if (m_contourPolyline->reserve(hullPtsCount))
{
m_contourPolyline->addPointIndex(0, hullPtsCount);
m_contourPolyline->setClosed(true);
m_contourPolyline->setVisible(true);
m_contourPolyline->setLocked(true);
m_contourPolyline->setName(DEFAULT_CONTOUR_NAME);
m_contourVertices->addChild(m_contourPolyline);
m_contourVertices->setEnabled(true);
m_contourVertices->setVisible(false);
}
else
{
delete m_contourPolyline;
m_contourPolyline = nullptr;
ccLog::Warning("[ccFacet::createInternalRepresentation] Not enough memory to create the contour polyline!");
}
}
//.........这里部分代码省略.........
示例7: FromFbxMesh
//converts a FBX mesh to a CC mesh
static ccMesh* FromFbxMesh(FbxMesh* fbxMesh, FileIOFilter::LoadParameters& parameters)
{
if (!fbxMesh)
return 0;
int polyCount = fbxMesh->GetPolygonCount();
//fbxMesh->GetLayer(
unsigned triCount = 0;
unsigned polyVertCount = 0; //different from vertCount (vertices can be counted multiple times here!)
//as we can't load all polygons (yet ;) we already look if we can load any!
{
unsigned skipped = 0;
for (int i=0; i<polyCount; ++i)
{
int pSize = fbxMesh->GetPolygonSize(i);
if (pSize == 3)
{
++triCount;
polyVertCount += 3;
}
else if (pSize == 4)
{
triCount += 2;
polyVertCount += 4;
}
else
{
++skipped;
}
}
if (triCount == 0)
{
ccLog::Warning(QString("[FBX] No triangle or quad found in mesh '%1'! (polygons with more than 4 vertices are not supported for the moment)").arg(fbxMesh->GetName()));
return 0;
}
else if (skipped != 0)
{
ccLog::Warning(QString("[FBX] Some polygons in mesh '%1' were ignored (%2): polygons with more than 4 vertices are not supported for the moment)").arg(fbxMesh->GetName()).arg(skipped));
return 0;
}
}
int vertCount = fbxMesh->GetControlPointsCount();
if (vertCount <= 0)
{
ccLog::Warning(QString("[FBX] Mesh '%1' has no vetex or no polygon?!").arg(fbxMesh->GetName()));
return 0;
}
ccPointCloud* vertices = new ccPointCloud("vertices");
ccMesh* mesh = new ccMesh(vertices);
mesh->setName(fbxMesh->GetName());
mesh->addChild(vertices);
vertices->setEnabled(false);
if (!mesh->reserve(static_cast<unsigned>(triCount)) || !vertices->reserve(vertCount))
{
ccLog::Warning(QString("[FBX] Not enough memory to load mesh '%1'!").arg(fbxMesh->GetName()));
delete mesh;
return 0;
}
//colors
{
for (int l=0; l<fbxMesh->GetElementVertexColorCount(); l++)
{
FbxGeometryElementVertexColor* vertColor = fbxMesh->GetElementVertexColor(l);
//CC can only handle per-vertex colors
if (vertColor->GetMappingMode() == FbxGeometryElement::eByControlPoint)
{
if (vertColor->GetReferenceMode() == FbxGeometryElement::eDirect
|| vertColor->GetReferenceMode() == FbxGeometryElement::eIndexToDirect)
{
if (vertices->reserveTheRGBTable())
{
switch (vertColor->GetReferenceMode())
{
case FbxGeometryElement::eDirect:
{
for (int i=0; i<vertCount; ++i)
{
FbxColor c = vertColor->GetDirectArray().GetAt(i);
vertices->addRGBColor( static_cast<colorType>(c.mRed * ccColor::MAX),
static_cast<colorType>(c.mGreen * ccColor::MAX),
static_cast<colorType>(c.mBlue * ccColor::MAX) );
}
}
break;
case FbxGeometryElement::eIndexToDirect:
{
for (int i=0; i<vertCount; ++i)
{
int id = vertColor->GetIndexArray().GetAt(i);
FbxColor c = vertColor->GetDirectArray().GetAt(id);
vertices->addRGBColor( static_cast<colorType>(c.mRed * ccColor::MAX),
static_cast<colorType>(c.mGreen * ccColor::MAX),
static_cast<colorType>(c.mBlue * ccColor::MAX) );
//.........这里部分代码省略.........
示例8: if
virtual void add3dFace(const DL_3dFaceData& face)
{
//TODO: understand what this really is?!
CCVector3 P[4];
for (unsigned i=0; i<4; ++i)
{
P[i] = CCVector3( static_cast<PointCoordinateType>(face.x[i]),
static_cast<PointCoordinateType>(face.y[i]),
static_cast<PointCoordinateType>(face.z[i]) );
}
//create the 'faces' mesh if necessary
if (!m_faces)
{
ccPointCloud* vertices = new ccPointCloud("vertices");
m_faces = new ccMesh(vertices);
m_faces->setName("Faces");
m_faces->addChild(vertices);
m_faces->setVisible(true);
vertices->setEnabled(false);
vertices->setLocked(true);
m_root->addChild(m_faces);
}
ccPointCloud* vertices = dynamic_cast<ccPointCloud*>(m_faces->getAssociatedCloud());
if (!vertices)
{
assert(false);
return;
}
int vertIndexes[4] = {-1, -1, -1, -1};
unsigned addedVertCount = 4;
//check if the two last vertices are the same
if (P[2].x == P[3].x && P[2].y == P[3].y && P[2].z == P[3].z)
addedVertCount = 3;
//current face color
colorType col[3];
colorType* faceCol = 0;
if (getCurrentColour(col))
faceCol = col;
//look for already defined vertices
unsigned vertCount = vertices->size();
if (vertCount)
{
//DGM TODO: could we be smarter?
for (unsigned i=0; i<addedVertCount; ++i)
{
for (unsigned j=0; j<vertCount; ++j)
{
const CCVector3* Pj = vertices->getPoint(j);
if (P[i].x == Pj->x && P[i].y == Pj->y && P[i].z == Pj->z)
{
bool useCurrentVertex = true;
//We must also check that the color is the same (if any)
if (faceCol || vertices->hasColors())
{
const colorType* _faceCol = faceCol ? faceCol : ccColor::white;
const colorType* _vertCol = vertices->hasColors() ? vertices->getPointColor(j) : ccColor::white;
useCurrentVertex = (_faceCol[0] == _vertCol[0] && _faceCol[1] == _vertCol[1] && _faceCol[2] == _vertCol[2]);
}
if (useCurrentVertex)
{
vertIndexes[i] = static_cast<int>(j);
break;
}
}
}
}
}
//now create new vertices
unsigned createdVertCount = 0;
{
for (unsigned i=0; i<addedVertCount; ++i)
if (vertIndexes[i] < 0)
++createdVertCount;
}
if (createdVertCount != 0)
{
//reserve memory for the new vertices
if (!vertices->reserve(vertCount+createdVertCount))
{
ccLog::Error("[DxfImporter] Not enough memory!");
return;
}
for (unsigned i=0; i<addedVertCount; ++i)
{
if (vertIndexes[i] < 0)
{
vertIndexes[i] = static_cast<int>(vertCount++);
vertices->addPoint(P[i]);
//.........这里部分代码省略.........