本文整理汇总了C++中ccHObject::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ ccHObject::addChild方法的具体用法?C++ ccHObject::addChild怎么用?C++ ccHObject::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ccHObject
的用法示例。
在下文中一共展示了ccHObject::addChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transferChildren
void ccHObject::transferChildren(ccHObject& newParent, bool forceFatherDependent/*=false*/)
{
for (Container::iterator it = m_children.begin(); it != m_children.end(); ++it)
{
//remove link from old parent
bool fatherDependent = (*it)->getFlagState(CC_FATHER_DEPENDANT) || forceFatherDependent;
if (fatherDependent)
(*it)->setFlagState(CC_FATHER_DEPENDANT,false);
newParent.addChild(*it,fatherDependent);
}
m_children.clear();
}
示例2: loadFile
CC_FILE_ERROR ImageFileFilter::loadFile(QString filename, ccHObject& container, LoadParameters& parameters)
{
QImage qImage;
if (!qImage.load(filename))
{
ccLog::Warning(QString("[IMAGE] Failed to load image '%1").arg(filename));
return CC_FERR_CONSOLE_ERROR;
}
//create corresponding ccImage
ccImage* image = new ccImage(qImage,QFileInfo(filename).baseName());
container.addChild(image);
return CC_FERR_NO_ERROR;
}
示例3: transferChild
void ccHObject::transferChild(unsigned index, ccHObject& newParent)
{
ccHObject* child = getChild(index);
if (!child)
{
assert(false);
return;
}
//remove link from old parent
bool fatherDependent = child->getFlagState(CC_FATHER_DEPENDANT);
if (fatherDependent)
child->setFlagState(CC_FATHER_DEPENDANT,false);
removeChild(index);
newParent.addChild(child,fatherDependent);
}
示例4: transferChild
//=====================================transferChild===============================================================//
void ccHObject::transferChild(ccHObject* child, ccHObject& newParent)
{
assert(child);
//remove link from old parent //从原先的父亲物体中删除依赖关系
int childDependencyFlags = child->getDependencyFlagsWith(this); //获取子物体对父物体的依赖关系
int parentDependencyFlags = getDependencyFlagsWith(child); //获取父亲物体对子物体的依赖关系
//automatically removes any dependency with this object //只是删除与该物体的依赖关系//两两之间
detachChild(child);
//新的父物体添加孩子物体 //依赖关系也同时转移
newParent.addChild(child,parentDependencyFlags);
//子物体添加依赖关系
child->addDependency(&newParent,childDependencyFlags);
//after a successful transfer, either the parent is 'newParent' or a null pointer
assert(child->getParent() == &newParent || child->getParent() == 0);
}
示例5: loadFile
//.........这里部分代码省略.........
if (loadedLists)
{
ccGBLSensor* gls = new ccGBLSensor(rotationOrder);
//ne pas oublier la base du scanner (SOISIC)
gls->setSensorBase(base);
CCLib::SquareMatrix* m = 0;
while (fgets(line, MAX_ASCII_FILE_LINE_LENGTH, fp))
{
if (line[0]=='#')
break;
else if (line[0]=='C')
{
float C[3];
sscanf(line,"C %f %f %f\n",C,C+1,C+2);
gls->setSensorCenter(C);
}
else if ((line[0]=='X')||(line[0]=='Y')||(line[0]=='Z'))
{
float X[3];
sscanf(line+2,"%f %f %f\n",X,X+1,X+2);
if (!m)
{
m = new CCLib::SquareMatrix(3);
m->toIdentity();
}
uchar col = uchar(line[0])-88;
m->setValue(0,col,X[0]);
m->setValue(1,col,X[1]);
m->setValue(2,col,X[2]);
}
else if (line[0]=='A')
{
float dPhi,dTheta;
sscanf(line,"A %f %f\n",&dPhi,&dTheta);
gls->setDeltaPhi(dPhi);
gls->setDeltaTheta(dTheta);
}
}
if (m) gls->setAxisMatrix(m);
int errorCode;
ccHObject::Container clouds;
if (loadedLists->isKindOf(CC_POINT_CLOUD))
clouds.push_back(loadedLists);
else
loadedLists->filterChildren(clouds,true,CC_POINT_CLOUD);
for (unsigned i=0;i<clouds.size();++i)
{
ccGenericPointCloud* theCloud = static_cast<ccGenericPointCloud*>(clouds[i]);
CCLib::GenericIndexedCloud* projectedList = gls->project(theCloud,errorCode,true);
switch (errorCode)
{
case -1:
ccConsole::Print(QString("[PovFilter::loadFile] Error on cloud #%1 (%2): nothing to project?! Must be a bug, sorry ;)").arg(i).arg(theCloud->getName()));
break;
case -2:
ccConsole::Print(QString("[PovFilter::loadFile] Error on cloud #%1 (%2): the resulting depth map seems much too big! Check parameters, or reduce angular steps ...").arg(i).arg(theCloud->getName()));
break;
case -3:
ccConsole::Print(QString("[PovFilter::loadFile] Error on cloud #%1 (%2): the resulting depth map is void (too small)! Check parameters and input, or increase angular steps ...").arg(i).arg(theCloud->getName()));
break;
case -4:
ccConsole::Print(QString("[PovFilter::loadFile] Error on cloud #%1 (%2): not enough memory!").arg(i).arg(theCloud->getName()));
break;
}
if (projectedList)
{
delete projectedList;
projectedList=0;
theCloud->addChild(gls);
}
else
{
delete gls;
gls=0;
}
theCloud->setName(subFileName);
container.addChild(theCloud);
}
}
else
{
ccConsole::Print("[PovFilter::loadFile] File (%s) not found or empty!\n",subFileName);
}
}
}
fclose(fp);
return CC_FERR_NO_ERROR;
}
示例6: loadFile
CC_FILE_ERROR IcmFilter::loadFile(const char* filename, ccHObject& container, bool alwaysDisplayLoadDialog/*=true*/, bool* coordinatesShiftEnabled/*=0*/, double* coordinatesShift/*=0*/)
{
//ouverture du fichier
FILE *fp = fopen(filename, "rt");
if (!fp)
return CC_FERR_READING;
//buffer
char line[MAX_ASCII_FILE_LINE_LENGTH];
//lecture du header
if (!fgets(line, MAX_ASCII_FILE_LINE_LENGTH , fp))
{
fclose(fp);
return CC_FERR_READING;
}
if (strncmp(line,"#CC_ICM_FILE",12)!=0)
{
fclose(fp);
return CC_FERR_WRONG_FILE_TYPE;
}
//on extrait le chemin relatif
QString path = QFileInfo(filename).absolutePath();
char cloudFileName[MAX_ASCII_FILE_LINE_LENGTH];
if (!fgets(line, MAX_ASCII_FILE_LINE_LENGTH , fp))
{
fclose(fp);
return CC_FERR_READING;
}
if (strncmp(line,"FILE_NAME=",10)!=0)
{
fclose(fp);
return CC_FERR_WRONG_FILE_TYPE;
}
sscanf(line,"FILE_NAME=%s",cloudFileName);
char subFileType[12];
if (!fgets(line, MAX_ASCII_FILE_LINE_LENGTH , fp))
{
fclose(fp);
return CC_FERR_READING;
}
if (strncmp(line,"FILE_TYPE=",10)!=0)
{
fclose(fp);
return CC_FERR_WRONG_FILE_TYPE;
}
sscanf(line,"FILE_TYPE=%s",subFileType);
CC_FILE_TYPES fType = FileIOFilter::StringToFileFormat(subFileType);
//chargement du fichier (potentiellement plusieurs listes) correspondant
ccHObject* entities = FileIOFilter::LoadFromFile(qPrintable(QString("%0/%1").arg(path).arg(cloudFileName)),fType);
if (!entities)
{
fclose(fp);
return CC_FERR_READING;
}
container.addChild(entities);
//chargement des images
char imagesDescriptorFileName[MAX_ASCII_FILE_LINE_LENGTH];
if (!fgets(line, MAX_ASCII_FILE_LINE_LENGTH , fp))
{
ccConsole::Error("[IcmFilter::loadModelFromIcmFile] Read error (IMAGES_DESCRIPTOR)! No image loaded");
fclose(fp);
return CC_FERR_READING;
}
else
{
if (strncmp(line,"IMAGES_DESCRIPTOR=",18)!=0)
{
fclose(fp);
return CC_FERR_WRONG_FILE_TYPE;
}
sscanf(line,"IMAGES_DESCRIPTOR=%s",imagesDescriptorFileName);
int n = loadCalibratedImages(entities,path,imagesDescriptorFileName);
ccConsole::Print("[IcmFilter::loadModelFromIcmFile] %i image(s) loaded ...",n);
}
fclose(fp);
return CC_FERR_NO_ERROR;
}
示例7: loadCloudFromFormatedAsciiFile
//.........这里部分代码省略.........
}
approximateNumberOfLines = static_cast<unsigned>(ceil(newNbOfLinesApproximation));
ccLog::PrintDebug("[ASCII] New approximate nb of lines: %i",approximateNumberOfLines);
}
//we try to resize actual clouds
if (cloudChunkSize < maxCloudSize || approximateNumberOfLines-cloudChunkPos <= maxCloudSize)
{
ccLog::PrintDebug("[ASCII] We choose to enlarge existing clouds");
cloudChunkSize = std::min(maxCloudSize,approximateNumberOfLines-cloudChunkPos);
if (!cloudDesc.cloud->reserve(cloudChunkSize))
{
ccLog::Error("Not enough memory! Process stopped ...");
result = CC_FERR_NOT_ENOUGH_MEMORY;
break;
}
}
else //otherwise we have to create new clouds
{
ccLog::PrintDebug("[ASCII] We choose to instantiate new clouds");
//we store (and resize) actual cloud
if (!cloudDesc.cloud->resize(cloudChunkSize))
ccLog::Warning("Memory reallocation failed ... some memory may have been wasted ...");
if (!cloudDesc.scalarFields.empty())
{
for (unsigned k=0; k<cloudDesc.scalarFields.size(); ++k)
cloudDesc.scalarFields[k]->computeMinAndMax();
cloudDesc.cloud->setCurrentDisplayedScalarField(0);
cloudDesc.cloud->showSF(true);
}
//we add this cloud to the output container
container.addChild(cloudDesc.cloud);
cloudDesc.reset();
//and create new one
cloudChunkPos = pointsRead;
cloudChunkSize = std::min(maxCloudSize,approximateNumberOfLines-cloudChunkPos);
cloudDesc = prepareCloud(openSequence, cloudChunkSize, maxPartIndex, separator, ++chunkRank);
if (!cloudDesc.cloud)
{
ccLog::Error("Not enough memory! Process stopped ...");
break;
}
cloudDesc.cloud->setGlobalShift(Pshift);
}
//we update the progress info
nprogress.scale(approximateNumberOfLines,100,true);
pdlg.setInfo(qPrintable(QString("Approximate number of points: %1").arg(approximateNumberOfLines)));
nextLimit = cloudChunkPos+cloudChunkSize;
}
//we split current line
QStringList parts = currentLine.split(separator,QString::SkipEmptyParts);
int nParts = parts.size();
if (nParts > maxPartIndex)
{
//(X,Y,Z)
if (cloudDesc.xCoordIndex >= 0)
P.x = parts[cloudDesc.xCoordIndex].toDouble();
if (cloudDesc.yCoordIndex >= 0)
P.y = parts[cloudDesc.yCoordIndex].toDouble();
示例8: LoadCloud
//.........这里部分代码省略.........
//DGM: ignored
//double xMin = qFromLittleEndian<double>(*reinterpret_cast<double*>(header ));
//double xMax = qFromLittleEndian<double>(*reinterpret_cast<double*>(header+ 8));
//double yMin = qFromLittleEndian<double>(*reinterpret_cast<double*>(header+16));
//double yMax = qFromLittleEndian<double>(*reinterpret_cast<double*>(header+24));
}
//Byte 32: NumPoints (The total number of points)
int32_t numPoints = qFromLittleEndian<int32_t>(*reinterpret_cast<int32_t*>(header+32));
ccPointCloud* cloud = new ccPointCloud(QString("Cloud #%1").arg(index));
if (!cloud->reserve(numPoints))
{
delete cloud;
return CC_FERR_NOT_ENOUGH_MEMORY;
}
//Points (An array of length NumPoints)
{
for (int32_t i=0; i<numPoints; ++i)
{
file.read(header,16);
double x = qFromLittleEndian<double>(*reinterpret_cast<double*>(header ));
double y = qFromLittleEndian<double>(*reinterpret_cast<double*>(header+8));
CCVector3 P(static_cast<PointCoordinateType>(x + PShift.x),
static_cast<PointCoordinateType>(y + PShift.y),
0);
cloud->addPoint(P);
}
}
//3D clouds
if (shapeTypeInt == SHP_MULTI_POINT_Z)
{
//Z boundaries
{
file.read(header,16);
//DGM: ignored
//double zMin = qFromLittleEndian<double>(*reinterpret_cast<double*>(header ));
//double zMax = qFromLittleEndian<double>(*reinterpret_cast<double*>(header+8));
}
//Z coordinates (an array of length NumPoints)
{
for (int32_t i=0; i<numPoints; ++i)
{
file.read(header,8);
double z = qFromLittleEndian<double>(*reinterpret_cast<double*>(header));
const CCVector3* P = cloud->getPoint(i);
const_cast<CCVector3*>(P)->z = static_cast<PointCoordinateType>(z + PShift.z);
}
cloud->invalidateBoundingBox();
}
}
//3D clouds or 2D clouds + measurement
if ( shapeTypeInt == SHP_MULTI_POINT_Z
|| shapeTypeInt == SHP_MULTI_POINT_M )
{
//M boundaries
ccScalarField* sf = 0;
{
file.read(header,16);
double mMin = qFromLittleEndian<double>(*reinterpret_cast<double*>(header ));
double mMax = qFromLittleEndian<double>(*reinterpret_cast<double*>(header+8));
if (mMin != ESRI_NO_DATA && mMax != ESRI_NO_DATA)
{
sf = new ccScalarField("Measures");
if (!sf->reserve(numPoints))
{
ccLog::Warning("[SHP] Not enough memory to load scalar values!");
sf->release();
sf = 0;
}
}
}
//M values (an array of length NumPoints)
if (sf)
{
double scalar = qToLittleEndian<double>(ESRI_NO_DATA);
for (int32_t i=0; i<numPoints; ++i)
{
file.read(header,8);
double m = qFromLittleEndian<double>(*reinterpret_cast<double*>(header));
ScalarType s = m == ESRI_NO_DATA ? NAN_VALUE : static_cast<ScalarType>(m);
sf->addElement(s);
}
sf->computeMinAndMax();
int sfIdx = cloud->addScalarField(sf);
cloud->setCurrentDisplayedScalarField(sfIdx);
cloud->showSF(true);
}
}
container.addChild(cloud);
return CC_FERR_NO_ERROR;
}
示例9: loadFile
//.........这里部分代码省略.........
bool ok;
unsigned elements = parts[1].toUInt(&ok);
if (!ok)
{
error = CC_FERR_MALFORMED_FILE;
break;
}
if (nextline.startsWith("CELL_DATA"))
{
//read next line (in case we actually know how to read it!
if (!GetNextNonEmptyLine(inFile,nextline))
{
error = CC_FERR_MALFORMED_FILE;
break;
}
skipReadLine = true;
if ( nextline.startsWith("SCALARS")
|| nextline.startsWith("NORMALS")
|| nextline.startsWith("COLOR_SCALARS"))
{
lastDataSize = elements;
acceptLookupTables = false; //this property is for triangles!
continue;
}
}
//we'll try to blindly skip the elements...
for (unsigned i=0; i<elements; ++i)
{
inFile.readLine(); //ignore
}
//end unhandled property
}
if (error != CC_FERR_NO_ERROR)
break;
}
file.close();
if (vertices && vertices->size() == 0)
{
delete vertices;
vertices = 0;
if (error == CC_FERR_NO_ERROR)
error = CC_FERR_NO_LOAD;
}
if (mesh && (mesh->size() == 0 || vertices == 0))
{
delete mesh;
mesh = 0;
if (error == CC_FERR_NO_ERROR)
error = CC_FERR_NO_LOAD;
}
if (mesh)
{
container.addChild(mesh);
mesh->setVisible(true);
mesh->addChild(vertices);
vertices->setEnabled(false);
vertices->setName("Vertices");
vertices->setLocked(true); //DGM: no need to lock it as it is only used by one mesh!
//DGM: normals can be per-vertex or per-triangle so it's better to let the user do it himself later
//Moreover it's not always good idea if the user doesn't want normals (especially in ccViewer!)
if (!mesh->hasNormals())
{
// mesh->computeNormals();
ccLog::Warning("[VTK] Mesh has no normal! You can manually compute them (select it then call \"Edit > Normals > Compute\")");
}
mesh->showNormals(mesh->hasNormals());
if (vertices->hasScalarFields())
{
vertices->setCurrentDisplayedScalarField(0);
mesh->showSF(true);
}
if (vertices->hasColors())
mesh->showColors(true);
}
else if (vertices)
{
container.addChild(vertices);
vertices->setVisible(true);
if (vertices->hasNormals())
vertices->showNormals(true);
if (vertices->hasScalarFields())
{
vertices->setCurrentDisplayedScalarField(0);
vertices->showSF(true);
}
if (vertices->hasColors())
vertices->showColors(true);
}
return error;
}
示例10: loadFile
//.........这里部分代码省略.........
{
std::string numPoints (line,4,line.size()-4);
nbPointsTotal=strtol(numPoints.c_str(),&pEnd,0);
//ccConsole::Print("[SoiFilter::loadFile] Total number of points: %i\n",nbPointsTotal);
}
else if (strcmp(line.substr(0,4).c_str(),"#NS#")==0)
{
std::string numScans (line,4,line.size()-4);
nbScansTotal=strtol(numScans.c_str(),&pEnd,0);
//ccConsole::Print("[SoiFilter::loadFile] Total number of scans: %i\n",nbScansTotal);
}
eof = fgets ((char*)line.c_str(), MAX_ASCII_FILE_LINE_LENGTH , fp);
}
if ((nbScansTotal == 0)||(nbPointsTotal == 0))
{
ccConsole::Warning("[SoiFilter::loadFile] No points or scans defined in this file!");
fclose(fp);
return CC_FERR_NO_LOAD;
}
//Progress dialog
ccProgressDialog pdlg(false); //cancel is not supported
pdlg.setMethodTitle("Open SOI file");
char buffer[256];
sprintf(buffer,"%i scans / %i points\n",nbScansTotal,nbPointsTotal);
CCLib::NormalizedProgress nprogress(&pdlg,nbPointsTotal);
pdlg.setInfo(buffer);
pdlg.start();
//Scan by scan
for (unsigned k=0;k<nbScansTotal;k++)
{
char* eof = fgets ((char*)line.c_str(), MAX_ASCII_FILE_LINE_LENGTH , fp);
//we only look for points (we ignore the rest)
while ((strcmp(line.substr(0,4).c_str(),"#pt#")!=0)&&(eof != NULL))
eof = fgets ((char*)line.c_str(), MAX_ASCII_FILE_LINE_LENGTH , fp);
unsigned nbOfPoints = 0;
if (strcmp(line.substr(0,4).c_str(),"#pt#")==0)
{
std::string numPoints(line,4,line.size()-4);
nbOfPoints=strtol(numPoints.c_str(),&pEnd,0);
//ccConsole::Print("[SoiFilter::loadFile] Scan %i - points: %i\n",k+1,nbOfPoints);
}
else
{
ccConsole::Warning("[SoiFilter::loadFile] Can't find marker '#pt#'!\n");
fclose(fp);
return CC_FERR_WRONG_FILE_TYPE;
}
//Creation de la liste de points
char name[64];
sprintf(name,"unnamed - Scan #%i",k);
ccPointCloud* loadedCloud = new ccPointCloud(name);
if (!loadedCloud)
{
fclose(fp);
return CC_FERR_NOT_ENOUGH_MEMORY;
}
if (nbOfPoints>0)
{
loadedCloud->reserveThePointsTable(nbOfPoints);
loadedCloud->reserveTheRGBTable();
loadedCloud->showColors(true);
}
else
{
ccConsole::Warning("[SoiFilter::loadFile] Scan #%i is empty!\n",k);
continue;
}
CCVector3 P;
int c = 0;
//we can read points now
for (unsigned i=0;i<nbOfPoints;i++)
{
fscanf(fp,"%f %f %f %i",&P.x,&P.y,&P.z,&c);
loadedCloud->addPoint(P);
loadedCloud->addGreyColor(colorType(c<<3)); //<<2 ? <<3 ? we lack some info. here ...
nprogress.oneStep();
}
container.addChild(loadedCloud);
}
fclose(fp);
return CC_FERR_NO_ERROR;
}
示例11: if
//.........这里部分代码省略.........
if (!loadedCloud)
return CC_FERR_NOT_ENOUGH_MEMORY;
unsigned fileChunkPos = 0;
unsigned fileChunkSize = std::min(nbOfPoints,CC_MAX_NUMBER_OF_POINTS_PER_CLOUD);
loadedCloud->reserveThePointsTable(fileChunkSize);
if (header.colors)
{
loadedCloud->reserveTheRGBTable();
loadedCloud->showColors(true);
}
if (header.normals)
{
loadedCloud->reserveTheNormsTable();
loadedCloud->showNormals(true);
}
if (header.scalarField)
loadedCloud->enableScalarField();
unsigned lineRead = 0;
int parts = 0;
const ScalarType FORMER_HIDDEN_POINTS = (ScalarType)-1.0;
//lecture du fichier
for (unsigned i=0; i<nbOfPoints; ++i)
{
if (lineRead == fileChunkPos+fileChunkSize)
{
if (header.scalarField)
loadedCloud->getCurrentInScalarField()->computeMinAndMax();
container.addChild(loadedCloud);
fileChunkPos = lineRead;
fileChunkSize = std::min(nbOfPoints-lineRead,CC_MAX_NUMBER_OF_POINTS_PER_CLOUD);
char partName[64];
++parts;
sprintf(partName,"%s.part_%i",cloudName,parts);
loadedCloud = new ccPointCloud(partName);
loadedCloud->reserveThePointsTable(fileChunkSize);
if (header.colors)
{
loadedCloud->reserveTheRGBTable();
loadedCloud->showColors(true);
}
if (header.normals)
{
loadedCloud->reserveTheNormsTable();
loadedCloud->showNormals(true);
}
if (header.scalarField)
loadedCloud->enableScalarField();
}
float Pf[3];
if (in.read((char*)Pf,sizeof(float)*3) < 0)
{
//Console::print("[BinFilter::loadModelFromBinaryFile] Error reading the %ith entity point !\n",k);
return CC_FERR_READING;
}
loadedCloud->addPoint(CCVector3::fromArray(Pf));
if (header.colors)
{
示例12: loadFile
//.........这里部分代码省略.........
else
ccConsole::Error("Mesh is empty!");
delete mesh;
mesh=0;
}
//we save coordinates shift information
if (s_ShiftApplyAll && coordinatesShiftEnabled && coordinatesShift)
{
*coordinatesShiftEnabled = true;
coordinatesShift[0] = s_Pshift[0];
coordinatesShift[1] = s_Pshift[1];
coordinatesShift[2] = s_Pshift[2];
}
//we update scalar field
CCLib::ScalarField* sf = cloud->getCurrentInScalarField();
if (sf)
{
sf->setPositive(!s_negSF);
sf->computeMinAndMax();
int sfIdx = cloud->getCurrentInScalarFieldIndex();
cloud->setCurrentDisplayedScalarField(sfIdx);
cloud->showSF(sfIdx>=0);
}
if (mesh)
{
assert(s_triCount > 0);
//check number of loaded facets against 'theoretical' number
if (s_triCount<numberOfFacets)
{
mesh->resize(s_triCount);
ccConsole::Warning("[PLY] Missing vertex indexes!");
}
//check that vertex indices start at 0
unsigned minVertIndex=numberOfPoints,maxVertIndex=0;
for (unsigned i=0;i<s_triCount;++i)
{
const CCLib::TriangleSummitsIndexes* tri = mesh->getTriangleIndexes(i);
if (tri->i1 < minVertIndex)
minVertIndex = tri->i1;
else if (tri->i1 > maxVertIndex)
maxVertIndex = tri->i1;
if (tri->i2 < minVertIndex)
minVertIndex = tri->i2;
else if (tri->i2 > maxVertIndex)
maxVertIndex = tri->i2;
if (tri->i3 < minVertIndex)
minVertIndex = tri->i3;
else if (tri->i3 > maxVertIndex)
maxVertIndex = tri->i3;
}
if (maxVertIndex>=numberOfPoints)
{
if (maxVertIndex == numberOfPoints && minVertIndex > 0)
{
ccLog::Warning("[PLY] Vertex indices seem to be shifted (+1)! We will try to 'unshift' indices (otherwise file is corrupted...)");
for (unsigned i=0;i<s_triCount;++i)
{
CCLib::TriangleSummitsIndexes* tri = mesh->getTriangleIndexes(i);
--tri->i1;
--tri->i2;
--tri->i3;
}
}
else //file is definitely corrupted!
{
ccLog::Warning("[PLY] Invalid vertex indices!");
delete mesh;
delete cloud;
return CC_FERR_MALFORMED_FILE;
}
}
mesh->addChild(cloud);
cloud->setEnabled(false);
cloud->setName("Vertices");
//cloud->setLocked(true); //DGM: no need to lock it as it is only used by one mesh!
if (cloud->hasColors())
mesh->showColors(true);
if (cloud->hasDisplayedScalarField())
mesh->showSF(true);
if (cloud->hasNormals())
mesh->showNormals(true);
else
mesh->computeNormals();
container.addChild(mesh);
}
else
{
container.addChild(cloud);
}
return CC_FERR_NO_ERROR;
}
示例13: loadFile
CC_FILE_ERROR PVFilter::loadFile(QString filename, ccHObject& container, LoadParameters& parameters)
{
//opening file
QFile in(filename);
if (!in.open(QIODevice::ReadOnly))
return CC_FERR_READING;
//we deduce the points number from the file size
qint64 fileSize = in.size();
qint64 singlePointSize = 4*sizeof(float);
//check that size is ok
if (fileSize == 0)
return CC_FERR_NO_LOAD;
if ((fileSize % singlePointSize) != 0)
return CC_FERR_MALFORMED_FILE;
unsigned numberOfPoints = static_cast<unsigned>(fileSize / singlePointSize);
//progress dialog
ccProgressDialog pdlg(true); //cancel available
CCLib::NormalizedProgress nprogress(&pdlg,numberOfPoints);
pdlg.setMethodTitle("Open PV file");
pdlg.setInfo(qPrintable(QString("Points: %1").arg(numberOfPoints)));
pdlg.start();
ccPointCloud* loadedCloud = 0;
//if the file is too big, it will be chuncked in multiple parts
unsigned chunkIndex = 0;
unsigned fileChunkPos = 0;
unsigned fileChunkSize = 0;
//number of points read for the current cloud part
unsigned pointsRead = 0;
CC_FILE_ERROR result = CC_FERR_NO_ERROR;
for (unsigned i=0;i<numberOfPoints;i++)
{
//if we reach the max. cloud size limit, we cerate a new chunk
if (pointsRead == fileChunkPos+fileChunkSize)
{
if (loadedCloud)
{
int sfIdx = loadedCloud->getCurrentInScalarFieldIndex();
if (sfIdx>=0)
{
CCLib::ScalarField* sf = loadedCloud->getScalarField(sfIdx);
sf->computeMinAndMax();
loadedCloud->setCurrentDisplayedScalarField(sfIdx);
loadedCloud->showSF(true);
}
container.addChild(loadedCloud);
}
fileChunkPos = pointsRead;
fileChunkSize = std::min<unsigned>(numberOfPoints-pointsRead,CC_MAX_NUMBER_OF_POINTS_PER_CLOUD);
loadedCloud = new ccPointCloud(QString("unnamed - Cloud #%1").arg(++chunkIndex));
if (!loadedCloud || !loadedCloud->reserveThePointsTable(fileChunkSize) || !loadedCloud->enableScalarField())
{
result = CC_FERR_NOT_ENOUGH_MEMORY;
if (loadedCloud)
delete loadedCloud;
loadedCloud=0;
break;
}
}
//we read the 3 coordinates of the point
float rBuff[3];
if (in.read((char*)rBuff,3*sizeof(float))>=0)
{
//conversion to CCVector3
CCVector3 P((PointCoordinateType)rBuff[0],
(PointCoordinateType)rBuff[1],
(PointCoordinateType)rBuff[2]);
loadedCloud->addPoint(P);
}
else
{
result = CC_FERR_READING;
break;
}
//then the scalar value
if (in.read((char*)rBuff,sizeof(float))>=0)
{
loadedCloud->setPointScalarValue(pointsRead,(ScalarType)rBuff[0]);
}
else
{
//add fake scalar value for consistency then break
loadedCloud->setPointScalarValue(pointsRead,0);
result = CC_FERR_READING;
break;
}
++pointsRead;
if (!nprogress.oneStep())
{
result = CC_FERR_CANCELED_BY_USER;
break;
}
}
//.........这里部分代码省略.........
示例14: loadFile
CC_FILE_ERROR OFFFilter::loadFile(QString filename, ccHObject& container, LoadParameters& parameters)
{
//try to open file
QFile fp(filename);
if (!fp.open(QIODevice::ReadOnly | QIODevice::Text))
return CC_FERR_READING;
QTextStream stream(&fp);
QString currentLine = stream.readLine();
if (!currentLine.toUpper().startsWith("OFF"))
return CC_FERR_MALFORMED_FILE;
//check if the number of vertices/faces/etc. are on the first line (yes it happens :( )
QStringList tokens = currentLine.split(QRegExp("\\s+"),QString::SkipEmptyParts);
if (tokens.size() == 4)
{
tokens.removeAt(0);
}
else
{
currentLine = GetNextLine(stream);
//end of file already?!
if (currentLine.isNull())
return CC_FERR_MALFORMED_FILE;
//read the number of vertices/faces
tokens = currentLine.split(QRegExp("\\s+"),QString::SkipEmptyParts);
if (tokens.size() < 2/*3*/) //should be 3 but we only use the 2 firsts...
return CC_FERR_MALFORMED_FILE;
}
bool ok = false;
unsigned vertCount = tokens[0].toUInt(&ok);
if (!ok)
return CC_FERR_MALFORMED_FILE;
unsigned triCount = tokens[1].toUInt(&ok);
if (!ok)
return CC_FERR_MALFORMED_FILE;
//create cloud and reserve some memory
ccPointCloud* vertices = new ccPointCloud("vertices");
if (!vertices->reserve(vertCount))
{
delete vertices;
return CC_FERR_NOT_ENOUGH_MEMORY;
}
//read vertices
{
CCVector3d Pshift(0,0,0);
for (unsigned i=0; i<vertCount; ++i)
{
currentLine = GetNextLine(stream);
tokens = currentLine.split(QRegExp("\\s+"),QString::SkipEmptyParts);
if (tokens.size() < 3)
{
delete vertices;
return CC_FERR_MALFORMED_FILE;
}
//read vertex
CCVector3d Pd(0,0,0);
{
bool vertexIsOk = false;
Pd.x = tokens[0].toDouble(&vertexIsOk);
if (vertexIsOk)
{
Pd.y = tokens[1].toDouble(&vertexIsOk);
if (vertexIsOk)
Pd.z = tokens[2].toDouble(&vertexIsOk);
}
if (!vertexIsOk)
{
delete vertices;
return CC_FERR_MALFORMED_FILE;
}
}
//first point: check for 'big' coordinates
if (i == 0)
{
if (HandleGlobalShift(Pd,Pshift,parameters))
{
vertices->setGlobalShift(Pshift);
ccLog::Warning("[OFF] Cloud has been recentered! Translation: (%.2f,%.2f,%.2f)",Pshift.x,Pshift.y,Pshift.z);
}
}
CCVector3 P = CCVector3::fromArray((Pd + Pshift).u);
vertices->addPoint(P);
}
}
ccMesh* mesh = new ccMesh(vertices);
mesh->addChild(vertices);
if (!mesh->reserve(triCount))
{
delete mesh;
//.........这里部分代码省略.........
示例15: loadFile
//.........这里部分代码省略.........
char* eof = fgets ((char*)line.c_str(), MAX_ASCII_FILE_LINE_LENGTH , fp);
char* pEnd;
//header
while ((strcmp((char*)line.substr(0,4).c_str(),"#CC#") != 0)&&(eof != NULL))
{
if (strcmp(line.substr(0,4).c_str(),"#NP#")==0)
{
std::string numPoints (line,4,line.size()-4);
nbPointsTotal=strtol(numPoints.c_str(),&pEnd,0);
//ccLog::Print("[SoiFilter::loadFile] Total number of points: %i",nbPointsTotal);
}
else if (strcmp(line.substr(0,4).c_str(),"#NS#")==0)
{
std::string numScans (line,4,line.size()-4);
nbScansTotal=strtol(numScans.c_str(),&pEnd,0);
//ccLog::Print("[SoiFilter::loadFile] Total number of scans: %i",nbScansTotal);
}
eof = fgets ((char*)line.c_str(), MAX_ASCII_FILE_LINE_LENGTH , fp);
}
if ((nbScansTotal == 0)||(nbPointsTotal == 0))
{
ccLog::Warning("[SoiFilter::loadFile] No points or scans defined in this file!");
fclose(fp);
return CC_FERR_NO_LOAD;
}
//Progress dialog
ccProgressDialog pdlg(false); //cancel is not supported
pdlg.setMethodTitle("Open SOI file");
char buffer[256];
sprintf(buffer,"%u scans / %u points\n",nbScansTotal,nbPointsTotal);
CCLib::NormalizedProgress nprogress(&pdlg,nbPointsTotal);
pdlg.setInfo(buffer);
pdlg.start();
//Scan by scan
for (unsigned k=0; k<nbScansTotal; k++)
{
char* eof = fgets ((char*)line.c_str(), MAX_ASCII_FILE_LINE_LENGTH , fp);
//we only look for points (we ignore the rest)
while ((strcmp(line.substr(0,4).c_str(),"#pt#")!=0)&&(eof != NULL))
eof = fgets ((char*)line.c_str(), MAX_ASCII_FILE_LINE_LENGTH , fp);
unsigned nbOfPoints = 0;
if (strcmp(line.substr(0,4).c_str(),"#pt#")==0)
{
std::string numPoints(line,4,line.size()-4);
nbOfPoints = strtol(numPoints.c_str(),&pEnd,0);
//ccLog::Print("[SoiFilter::loadFile] Scan %i - points: %i",k+1,nbOfPoints);
}
else
{
ccLog::Warning("[SoiFilter::loadFile] Can't find marker '#pt#'!");
fclose(fp);
return CC_FERR_WRONG_FILE_TYPE;
}
if (nbOfPoints == 0)
{
ccLog::Warning("[SoiFilter::loadFile] Scan #%i is empty!",k);
continue;
}
//Creation de la liste de points
QString name = QString("unnamed - Scan #%1").arg(k);
ccPointCloud* loadedCloud = new ccPointCloud(name);
if ( !loadedCloud->reserveThePointsTable(nbOfPoints) || !loadedCloud->reserveTheRGBTable() )
{
fclose(fp);
delete loadedCloud;
return CC_FERR_NOT_ENOUGH_MEMORY;
}
loadedCloud->showColors(true);
//we can read points now
for (unsigned i=0; i<nbOfPoints; i++)
{
float P[3];
int c = 0;
fscanf(fp,"%f %f %f %i",P,P+1,P+2,&c);
loadedCloud->addPoint(CCVector3::fromArray(P));
loadedCloud->addGreyColor(static_cast<colorType>(c<<3)); //<<2 ? <<3 ? we lack some info. here ...
nprogress.oneStep();
}
container.addChild(loadedCloud);
}
fclose(fp);
return CC_FERR_NO_ERROR;
}