本文整理汇总了C++中cclib::ScalarField类的典型用法代码示例。如果您正苦于以下问题:C++ ScalarField类的具体用法?C++ ScalarField怎么用?C++ ScalarField使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ScalarField类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
std::vector<float> getComboItemAsStdFloatVector(ComboItemDescriptor desc, const ccPointCloud* cloud)
{
int n = cloud->size();
std::vector<float> v;
v.resize(n);
v.reserve(n);
if (desc.type == ComboItemDescriptor::COORDINATE)
{
CCVector3 point;
for (int i = 0; i < n; i++)
{
cloud->getPoint(i, point);
v[i] = point[desc.index_in_cloud];
}
}
else if (desc.type == ComboItemDescriptor::SCALAR)
{
CCLib::ScalarField * field = cloud->getScalarField(desc.index_in_cloud);
for (int i = 0; i < n; i++)
v[i] = field->getValue(i);
}
return v;
}
示例2: copyScalarFields
void copyScalarFields(const ccPointCloud *inCloud, ccPointCloud *outCloud, pcl::PointIndicesPtr &in2outMapping, bool overwrite = true)
{
int n_in = inCloud->size();
int n_out = outCloud->size();
assert(in2outMapping->indices.size() == outCloud->size());
int n_scalars = inCloud->getNumberOfScalarFields();
for (int i = 0; i < n_scalars; ++i)
{
CCLib::ScalarField * field = inCloud->getScalarField(i);
const char * name = field->getName();
//we need to verify no scalar field with the same name exists in the output cloud
int id = outCloud->getScalarFieldIndexByName(name);
ccScalarField * new_field = new ccScalarField;
//resize the scalar field to the outcloud size
new_field->reserve(outCloud->size());
new_field->setName(name);
if (id >= 0) //a scalar field with the same name exists
{
if (overwrite)
outCloud->deleteScalarField(id);
else
break;
}
//now perform point to point copy
for (unsigned int j = 0; j < outCloud->size(); ++j)
{
new_field->setValue(j, field->getValue(in2outMapping->indices.at(j)));
}
//recompute stats
new_field->computeMinAndMax();
ccScalarField * casted_field = static_cast<ccScalarField *> (new_field);
casted_field->computeMinAndMax();
//now put back the scalar field to the outCloud
if (id < 0)
outCloud->addScalarField(casted_field);
}
}
示例3: scalar_cb
static int scalar_cb(p_ply_argument argument)
{
CCLib::ScalarField* sf = 0;
ply_get_argument_user_data(argument, (void**)(&sf), NULL);
p_ply_element element;
long instance_index;
ply_get_argument_element(argument, &element, &instance_index);
ScalarType scal = static_cast<ScalarType>(ply_get_argument_value(argument));
sf->setValue(instance_index,scal);
if ((++s_totalScalarCount % PROCESS_EVENTS_FREQ) == 0)
QCoreApplication::processEvents();
return 1;
}
示例4: nProgress
bool cc2Point5DimEditor::RasterGrid::fillWith( ccGenericPointCloud* cloud,
unsigned char projectionDimension,
cc2Point5DimEditor::ProjectionType projectionType,
bool interpolateEmptyCells,
cc2Point5DimEditor::ProjectionType sfInterpolation/*=INVALID_PROJECTION_TYPE*/,
ccProgressDialog* progressDialog/*=0*/)
{
if (!cloud)
{
assert(false);
return false;
}
//current parameters
unsigned gridTotalSize = width * height;
//vertical dimension
const unsigned char Z = projectionDimension;
assert(Z >= 0 && Z <= 2);
const unsigned char X = Z == 2 ? 0 : Z +1;
const unsigned char Y = X == 2 ? 0 : X +1;
//do we need to interpolate scalar fields?
ccPointCloud* pc = cloud->isA(CC_TYPES::POINT_CLOUD) ? static_cast<ccPointCloud*>(cloud) : 0;
bool interpolateSF = (sfInterpolation != INVALID_PROJECTION_TYPE);
interpolateSF &= (pc && pc->hasScalarFields());
if (interpolateSF)
{
unsigned sfCount = pc->getNumberOfScalarFields();
bool memoryError = false;
size_t previousCount = scalarFields.size();
if (sfCount > previousCount)
{
try
{
scalarFields.resize(sfCount,0);
}
catch (const std::bad_alloc&)
{
//not enough memory
memoryError = true;
}
}
for (size_t i=previousCount; i<sfCount; ++i)
{
assert(scalarFields[i] == 0);
scalarFields[i] = new double[gridTotalSize];
if (!scalarFields[i])
{
//not enough memory
memoryError = true;
break;
}
}
if (memoryError)
{
ccLog::Warning(QString("[Rasterize] Failed to allocate memory for scalar fields!"));
}
}
//filling the grid
unsigned pointCount = cloud->size();
double gridMaxX = gridStep * width;
double gridMaxY = gridStep * height;
if (progressDialog)
{
progressDialog->setMethodTitle("Grid generation");
progressDialog->setInfo(qPrintable(QString("Points: %1\nCells: %2 x %3").arg(pointCount).arg(width).arg(height)));
progressDialog->start();
progressDialog->show();
QCoreApplication::processEvents();
}
CCLib::NormalizedProgress nProgress(progressDialog,pointCount);
for (unsigned n=0; n<pointCount; ++n)
{
const CCVector3* P = cloud->getPoint(n);
CCVector3d relativePos = CCVector3d::fromArray(P->u) - minCorner;
int i = static_cast<int>(relativePos.u[X]/gridStep);
int j = static_cast<int>(relativePos.u[Y]/gridStep);
//specific case: if we fall exactly on the max corner of the grid box
if (i == static_cast<int>(width) && relativePos.u[X] == gridMaxX)
--i;
if (j == static_cast<int>(height) && relativePos.u[Y] == gridMaxY)
--j;
//we skip points outside the box!
if ( i < 0 || i >= static_cast<int>(width)
|| j < 0 || j >= static_cast<int>(height) )
continue;
assert(i >= 0 && j >= 0);
//.........这里部分代码省略.........
示例5: saveToFile
CC_FILE_ERROR LASFilter::saveToFile(ccHObject* entity, const char* filename)
{
if (!entity || !filename)
return CC_FERR_BAD_ARGUMENT;
ccHObject::Container clouds;
if (entity->isKindOf(CC_POINT_CLOUD))
clouds.push_back(entity);
else
entity->filterChildren(clouds, true, CC_POINT_CLOUD);
if (clouds.empty())
{
ccConsole::Error("No point cloud in input selection!");
return CC_FERR_BAD_ENTITY_TYPE;
}
else if (clouds.size()>1)
{
ccConsole::Error("Can't save more than one cloud per LAS file!");
return CC_FERR_BAD_ENTITY_TYPE;
}
//the cloud to save
ccGenericPointCloud* theCloud = static_cast<ccGenericPointCloud*>(clouds[0]);
unsigned numberOfPoints = theCloud->size();
if (numberOfPoints==0)
{
ccConsole::Error("Cloud is empty!");
return CC_FERR_BAD_ENTITY_TYPE;
}
//colors
bool hasColor = theCloud->hasColors();
//additional fields (as scalar fields)
CCLib::ScalarField* classifSF = 0;
CCLib::ScalarField* intensitySF = 0;
CCLib::ScalarField* timeSF = 0;
CCLib::ScalarField* returnNumberSF = 0;
if (theCloud->isA(CC_POINT_CLOUD))
{
ccPointCloud* pc = static_cast<ccPointCloud*>(theCloud);
//Classification
{
int sfIdx = pc->getScalarFieldIndexByName(CC_LAS_CLASSIFICATION_FIELD_NAME);
if (sfIdx>=0)
{
classifSF = pc->getScalarField(sfIdx);
assert(classifSF);
if ((int)classifSF->getMin()<0 || (int)classifSF->getMax()>255) //outbounds unsigned char?
{
ccConsole::Warning("[LASFilter] Found a 'Classification' scalar field, but its values outbound LAS specifications (0-255)...");
classifSF = 0;
}
}
}
//Classification end
//intensity (as a scalar field)
{
int sfIdx = pc->getScalarFieldIndexByName(CC_SCAN_INTENSITY_FIELD_NAME);
if (sfIdx>=0)
{
intensitySF = pc->getScalarField(sfIdx);
assert(intensitySF);
if ((int)intensitySF->getMin()<0 || (int)intensitySF->getMax()>65535) //outbounds unsigned short?
{
ccConsole::Warning("[LASFilter] Found a 'Intensity' scalar field, but its values outbound LAS specifications (0-65535)...");
intensitySF = 0;
}
}
}
//Intensity end
//Time (as a scalar field)
{
int sfIdx = pc->getScalarFieldIndexByName(CC_SCAN_TIME_FIELD_NAME);
if (sfIdx>=0)
{
timeSF = pc->getScalarField(sfIdx);
assert(timeSF);
}
}
//Time end
//Return number (as a scalar field)
{
int sfIdx = pc->getScalarFieldIndexByName(CC_SCAN_RETURN_INDEX_FIELD_NAME);
if (sfIdx>=0)
{
returnNumberSF = pc->getScalarField(sfIdx);
assert(returnNumberSF);
if ((int)returnNumberSF->getMin()<0 || (int)returnNumberSF->getMax()>7) //outbounds 3 bits?
{
ccConsole::Warning("[LASFilter] Found a 'Return number' scalar field, but its values outbound LAS specifications (0-7)...");
returnNumberSF = 0;
}
//.........这里部分代码省略.........
示例6: 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;
}
}
//.........这里部分代码省略.........
示例7: loadFile
//.........这里部分代码省略.........
{
if (numberOfPoints != numberOfColors)
{
ccConsole::Warning("The number of colors doesn't match the number of points!");
delete cloud;
ply_close(ply);
return CC_FERR_BAD_ENTITY_TYPE;
}
if (!cloud->reserveTheRGBTable())
{
delete cloud;
ply_close(ply);
return CC_FERR_NOT_ENOUGH_MEMORY;
}
cloud->showColors(true);
}
/* SCALAR FIELD (SF) */
unsigned numberOfScalars=0;
if (sfIndex>0)
{
plyProperty& pp = stdProperties[sfIndex-1];
numberOfScalars = pointElements[pp.elemIndex].elementInstances;
//does the number of scalars matches the number of points?
if (numberOfPoints != numberOfScalars)
{
ccConsole::Error("The number of scalars doesn't match the number of points (they will be ignored)!");
ccConsole::Warning("[PLY] Scalar field ignored!");
numberOfScalars = 0;
}
else if (!cloud->enableScalarField())
{
ccConsole::Error("Not enough memory to load scalar field (they will be ignored)!");
ccConsole::Warning("[PLY] Scalar field ignored!");
numberOfScalars = 0;
}
else
{
CCLib::ScalarField* sf = cloud->getCurrentInScalarField();
if (sf)
{
QString qPropName(pp.propName);
if (qPropName.startsWith("scalar_") && qPropName.length()>7)
{
//remove the 'scalar_' prefix added when saving SF with CC!
qPropName = qPropName.mid(7).replace('_',' ');
sf->setName(qPrintable(qPropName));
}
else
{
sf->setName(pp.propName);
}
}
ply_set_read_cb(ply, pointElements[pp.elemIndex].elementName, pp.propName, scalar_cb, cloud, 1);
}
cloud->showSF(true);
}
/* MESH FACETS (TRI) */
ccMesh* mesh = 0;
unsigned numberOfFacets=0;
示例8: saveToFile
//.........这里部分代码省略.........
outFile << "ASCII" << endl;
outFile << "DATASET " << (mesh ? "POLYDATA" : "UNSTRUCTURED_GRID") << endl;
//data type
QString floatType = (sizeof(PointCoordinateType) == 4 ? "float" : "double");
/*** what shall we save now? ***/
// write the points
{
outFile << "POINTS " << ptsCount << " " << floatType << endl;
for (unsigned i=0; i<ptsCount; ++i)
{
const CCVector3* P = vertices->getPoint(i);
CCVector3d Pglobal = vertices->toGlobal3d<PointCoordinateType>(*P);
outFile << Pglobal.x << " "
<< Pglobal.y << " "
<< Pglobal.z << endl;
}
}
// write triangles
if (mesh)
{
outFile << "POLYGONS " << triCount << " " << 4*triCount << endl;
mesh->placeIteratorAtBegining();
for (unsigned i=0; i<triCount; ++i)
{
const CCLib::VerticesIndexes* tsi = mesh->getNextTriangleVertIndexes(); //DGM: getNextTriangleVertIndexes is faster for mesh groups!
outFile << "3 " << tsi->i1 << " " << tsi->i2 << " " << tsi->i3 << endl;
}
}
else
{
// write cell data
outFile << "CELLS " << ptsCount << " " << 2*ptsCount << endl;
for (unsigned i=0; i<ptsCount; ++i)
outFile << "1 " << i << endl;
outFile << "CELL_TYPES " << ptsCount << endl;
for (unsigned i=0; i<ptsCount; ++i)
outFile << "1 " << endl;
}
outFile << "POINT_DATA " << ptsCount << endl;
// write normals
if (vertices->hasNormals())
{
outFile << "NORMALS Normals "<< floatType << endl;
for (unsigned i=0; i<ptsCount; ++i)
{
const CCVector3& N = vertices->getPointNormal(i);
outFile << N.x << " " << N.y << " " << N.z << endl;
}
}
// write colors
if (vertices->hasColors())
{
outFile << "COLOR_SCALARS RGB 3" << endl;
for (unsigned i=0; i<ptsCount; ++i)
{
const colorType* C = vertices->getPointColor(i);
outFile << static_cast<float>(C[0])/ccColor::MAX << " " << static_cast<float>(C[1])/ccColor::MAX << " " << static_cast<float>(C[2])/ccColor::MAX << endl;
}
}
// write scalar field(s)?
if (vertices->isA(CC_TYPES::POINT_CLOUD))
{
ccPointCloud* pointCloud = static_cast<ccPointCloud*>(vertices);
unsigned sfCount = pointCloud->getNumberOfScalarFields();
for (unsigned i=0;i<sfCount;++i)
{
CCLib::ScalarField* sf = pointCloud->getScalarField(i);
outFile << "SCALARS " << QString(sf->getName()).replace(" ","_") << (sizeof(ScalarType)==4 ? " float" : " double") << " 1" << endl;
outFile << "LOOKUP_TABLE default" << endl;
for (unsigned j=0;j<ptsCount; ++j)
outFile << sf->getValue(j) << endl;
}
}
else //virtual point cloud, we only have access to its currently displayed scalar field
{
if (vertices->hasScalarFields())
{
outFile << "SCALARS ScalarField" << (sizeof(ScalarType)==4 ? " float" : " double") << " 1" << endl;
outFile << "LOOKUP_TABLE default" << endl;
for (unsigned j=0;j<ptsCount; ++j)
outFile << vertices->getPointDisplayedDistance(j) << endl;
}
}
file.close();
return CC_FERR_NO_ERROR;
}
示例9: saveToFile
//.........这里部分代码省略.........
outFile << "ASCII" << endl;
outFile << "DATASET " << (mesh ? "POLYDATA" : "UNSTRUCTURED_GRID") << endl;
//data type
QString floatType = (sizeof(PointCoordinateType) == 4 ? "float" : "double");
/*** what shall we save now? ***/
// write the points
{
outFile << "POINTS " << ptsCount << " " << floatType << endl;
for (unsigned i=0; i<ptsCount; ++i)
{
const CCVector3* P = vertices->getPoint(i);
CCVector3d Pglobal = vertices->toGlobal3d<PointCoordinateType>(*P);
outFile << Pglobal.x << " "
<< Pglobal.y << " "
<< Pglobal.z << endl;
}
}
// write triangles
if (mesh)
{
outFile << "POLYGONS " << triCount << " " << 4*triCount << endl;
mesh->placeIteratorAtBegining();
for (unsigned i=0; i<triCount; ++i)
{
const CCLib::TriangleSummitsIndexes* tsi = mesh->getNextTriangleIndexes(); //DGM: getNextTriangleIndexes is faster for mesh groups!
outFile << "3 " << tsi->i1 << " " << tsi->i2 << " " << tsi->i3 << endl;
}
}
else
{
// write cell data
outFile << "CELLS " << ptsCount << " " << 2*ptsCount << endl;
for (unsigned i=0; i<ptsCount; ++i)
outFile << "1 " << i << endl;
outFile << "CELL_TYPES " << ptsCount << endl;
for (unsigned i=0; i<ptsCount; ++i)
outFile << "1 " << endl;
}
outFile << "POINT_DATA " << ptsCount << endl;
// write normals
if (vertices->hasNormals())
{
outFile << "NORMALS Normals "<< floatType << endl;
for (unsigned i=0; i<ptsCount; ++i)
{
const CCVector3& N = vertices->getPointNormal(i);
outFile << N.x << " " << N.y << " " << N.z << endl;
}
}
// write colors
if (vertices->hasColors())
{
outFile << "COLOR_SCALARS RGB 3" << endl;
for (unsigned i=0; i<ptsCount; ++i)
{
const colorType* C = vertices->getPointColor(i);
outFile << (float)C[0]/(float)MAX_COLOR_COMP << " " << (float)C[1]/(float)MAX_COLOR_COMP << " " << (float)C[2]/(float)MAX_COLOR_COMP << endl;
}
}
// write scalar field(s)?
if (vertices->isA(CC_TYPES::POINT_CLOUD))
{
ccPointCloud* pointCloud = static_cast<ccPointCloud*>(vertices);
unsigned sfCount = pointCloud->getNumberOfScalarFields();
for (unsigned i=0;i<sfCount;++i)
{
CCLib::ScalarField* sf = pointCloud->getScalarField(i);
outFile << "SCALARS " << QString(sf->getName()).replace(" ","_") << (sizeof(ScalarType)==4 ? " float" : " double") << " 1" << endl;
outFile << "LOOKUP_TABLE default" << endl;
for (unsigned j=0;j<ptsCount; ++j)
outFile << sf->getValue(j) << endl;
}
}
else //virtual point cloud, we only have access to its currently displayed scalar field
{
if (vertices->hasScalarFields())
{
outFile << "SCALARS ScalarField" << (sizeof(ScalarType)==4 ? " float" : " double") << " 1" << endl;
outFile << "LOOKUP_TABLE default" << endl;
for (unsigned j=0;j<ptsCount; ++j)
outFile << vertices->getPointDisplayedDistance(j) << endl;
}
}
file.close();
return CC_FERR_NO_ERROR;
}
示例10: saveToFile
CC_FILE_ERROR PVFilter::saveToFile(ccHObject* entity, const char* filename)
{
if (!entity || !filename)
return CC_FERR_BAD_ARGUMENT;
ccHObject::Container clouds;
if (entity->isKindOf(CC_POINT_CLOUD))
clouds.push_back(entity);
else
entity->filterChildren(clouds, true, CC_POINT_CLOUD);
if (clouds.empty())
{
ccConsole::Error("No point cloud in input selection!");
return CC_FERR_BAD_ENTITY_TYPE;
}
else if (clouds.size()>1)
{
ccConsole::Error("Can't save more than one cloud per PV file!");
return CC_FERR_BAD_ENTITY_TYPE;
}
//the cloud to save
ccGenericPointCloud* theCloud = static_cast<ccGenericPointCloud*>(clouds[0]);
//and its scalar field
CCLib::ScalarField* sf = 0;
if (theCloud->isA(CC_POINT_CLOUD))
sf = static_cast<ccPointCloud*>(theCloud)->getCurrentDisplayedScalarField();
if (!sf)
ccConsole::Warning("No displayed scalar field! Values will all be 0!\n");
unsigned numberOfPoints = theCloud->size();
if (numberOfPoints==0)
{
ccConsole::Error("Cloud is empty!");
return CC_FERR_BAD_ENTITY_TYPE;
}
//open binary file for writing
FILE* theFile = fopen(filename , "wb");
if (!theFile)
return CC_FERR_WRITING;
//Has the cloud been recentered?
const double* shift = theCloud->getOriginalShift();
if (fabs(shift[0])+fabs(shift[0])+fabs(shift[0])>0.0)
ccConsole::Warning(QString("[PVFilter::save] Can't recenter cloud %1 on PV file save!").arg(theCloud->getName()));
//progress dialog
ccProgressDialog pdlg(true); //cancel available
CCLib::NormalizedProgress nprogress(&pdlg,numberOfPoints);
pdlg.setMethodTitle("Save PV file");
char buffer[256];
sprintf(buffer,"Points: %i",numberOfPoints);
pdlg.setInfo(buffer);
pdlg.start();
float wBuff[3];
float val=0.0;
for (unsigned i=0;i<numberOfPoints;i++)
{
//conversion to float
const CCVector3* P = theCloud->getPoint(i);
wBuff[0]=float(P->x);
wBuff[1]=float(P->y);
wBuff[2]=float(P->z);
if (fwrite(wBuff,sizeof(float),3,theFile) < 0)
{fclose(theFile);return CC_FERR_WRITING;}
if (sf)
val = (float)sf->getValue(i);
if (fwrite(&val,sizeof(float),1,theFile) < 0)
{fclose(theFile);return CC_FERR_WRITING;}
if (!nprogress.oneStep())
break;
}
fclose(theFile);
return CC_FERR_NO_ERROR;
}
示例11: loadFile
//.........这里部分代码省略.........
{
return CC_FERR_NO_LOAD;
}
//load shapes
CC_FILE_ERROR error = CC_FERR_NO_ERROR;
ccPointCloud* singlePoints = 0;
qint64 pos = file.pos();
while (fileLength >= 12)
{
file.seek(pos);
assert(pos + fileLength == file.size());
//load shape record in main SHP file
{
file.read(header,8);
//Byte 0: Record Number
int32_t recordNumber = qFromBigEndian<int32_t>(*reinterpret_cast<const int32_t*>(header)); //Record numbers begin at 1
//Byte 4: Content Length
int32_t recordSize = qFromBigEndian<int32_t>(*reinterpret_cast<const int32_t*>(header+4)); //Record numbers begin at 1
recordSize *= 2; //recordSize is measured in 16-bit words
fileLength -= 8;
pos += 8;
if (fileLength < recordSize)
{
assert(false);
error = CC_FERR_MALFORMED_FILE;
break;
}
fileLength -= recordSize;
pos += recordSize;
//Record start (byte 0): Shape Type
if (recordSize < 4)
{
assert(false);
error = CC_FERR_MALFORMED_FILE;
break;
}
file.read(header,4);
recordSize -= 4;
int32_t shapeTypeInt = qToLittleEndian<int32_t>(*reinterpret_cast<const int32_t*>(header));
ccLog::Print(QString("[SHP] Record #%1 - type: %2 (%3 bytes)").arg(recordNumber).arg(ToString(static_cast<ESRI_SHAPE_TYPE>(shapeTypeInt))).arg(recordSize));
switch (shapeTypeInt)
{
case SHP_POLYLINE:
case SHP_POLYLINE_Z:
case SHP_POLYGON:
case SHP_POLYGON_Z:
error = LoadPolyline(file,container,recordNumber,static_cast<ESRI_SHAPE_TYPE>(shapeTypeInt),Pshift);
break;
case SHP_MULTI_POINT:
case SHP_MULTI_POINT_Z:
case SHP_MULTI_POINT_M:
error = LoadCloud(file,container,recordNumber,static_cast<ESRI_SHAPE_TYPE>(shapeTypeInt),Pshift);
break;
case SHP_POINT:
case SHP_POINT_Z:
case SHP_POINT_M:
error = LoadSinglePoint(file,singlePoints,static_cast<ESRI_SHAPE_TYPE>(shapeTypeInt),Pshift);
break;
//case SHP_MULTI_PATCH:
// error = LoadMesh(file,recordSize);
// break;
case SHP_NULL_SHAPE:
//ignored
break;
default:
//unhandled entity
ccLog::Warning("[SHP] Unhandled type!");
break;
}
}
if (error != CC_FERR_NO_ERROR)
break;
}
if (singlePoints)
{
if (singlePoints->size() == 0)
{
delete singlePoints;
singlePoints = 0;
}
else
{
CCLib::ScalarField* sf = singlePoints->getScalarField(0);
if (sf)
{
sf->computeMinAndMax();
singlePoints->showSF(true);
}
container.addChild(singlePoints);
}
}
return error;
}
示例12: loadFile
CC_FILE_ERROR UltFilter::loadFile(const char* filename, ccHObject& container, bool alwaysDisplayLoadDialog/*=true*/, bool* coordinatesShiftEnabled/*=0*/, double* coordinatesShift/*=0*/)
{
//ccConsole::Print("[BinFilter::loadFile] Opening binary file '%s'...\n",filename);
assert(filename);
//file size
long size = QFileInfo(filename).size();
if ( size == 0 || ((size % sizeof(MarkersFrame)) != 0))
return CC_FERR_MALFORMED_FILE;
//number of transformations in file
long count = size / sizeof(MarkersFrame);
ccConsole::Print("[TransBuffer] Found %i trans. in file '%s'",count,filename);
if (count<1)
return CC_FERR_NO_LOAD;
ccPointCloud* cloud = new ccPointCloud();
if (!cloud->reserve(count) || !cloud->enableScalarField())
{
delete cloud;
return CC_FERR_NOT_ENOUGH_MEMORY;
}
ccProgressDialog pdlg(true);
pdlg.setMethodTitle("Open Ult File");
CCLib::NormalizedProgress nprogress(&pdlg,count);
pdlg.reset();
pdlg.setInfo(qPrintable(QString("Transformations: %1").arg(count)));
pdlg.start();
QApplication::processEvents();
FILE* fp = fopen(filename,"rb");
if (!fp)
{
delete cloud;
return CC_FERR_READING;
}
//which marker is the reference?
QMessageBox::StandardButton tibiaIsRef = QMessageBox::question(0, "Choose reference", "Tibia as reference (yes)? Or femur (no)? Or none (no to all)", QMessageBox::Yes | QMessageBox::No | QMessageBox::NoToAll, QMessageBox::Yes );
MARKER_ROLE referenceRole = MARKER_LOCALIZER;
if (tibiaIsRef == QMessageBox::Yes)
referenceRole = MARKER_TIBIA;
else if (tibiaIsRef == QMessageBox::No)
referenceRole = MARKER_FEMUR;
//To apply a predefined pointer tip
//CCVector3 tip(0,0,0);
CCVector3 tip(-90.07f, -17.68f, 18.29f);
MarkersFrame currentframe;
MarkerState& currentMarker = currentframe.states[MARKER_POINTER];
MarkerState* referenceMarker = 0;
if (referenceRole != MARKER_LOCALIZER)
referenceMarker = currentframe.states+referenceRole;
unsigned MarkersFrameSize = sizeof(MarkersFrame);
unsigned realCount=0;
for (long i=0;i<count;++i)
{
if (fread(¤tframe,MarkersFrameSize,1,fp)==0)
{
fclose(fp);
delete cloud;
return CC_FERR_READING;
}
if (currentMarker.visible && (!referenceMarker || referenceMarker->visible))
{
CCVector3 P(tip);
ccGLMatrix trans = currentMarker.pos;
if (referenceMarker)
trans = referenceMarker->pos.inverse() * trans;
trans.apply(P);
cloud->addPoint(P);
cloud->setPointScalarValue(realCount,currentMarker.pos.timestamp);
++realCount;
}
if (!nprogress.oneStep())
break;
}
fclose(fp);
if (realCount==0)
{
delete cloud;
return CC_FERR_NO_LOAD;
}
cloud->resize(realCount);
//we update scalar field
CCLib::ScalarField* sf = cloud->getCurrentInScalarField();
if (sf)
{
sf->setPositive(true);
//.........这里部分代码省略.........
示例13: generateRaster
void ccRasterizeTool::generateRaster() const
{
#ifdef CC_GDAL_SUPPORT
if (!m_cloud || !m_grid.isValid())
return;
GDALAllRegister();
ccLog::PrintDebug("(GDAL drivers: %i)", GetGDALDriverManager()->GetDriverCount());
const char *pszFormat = "GTiff";
GDALDriver *poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
if (!poDriver)
{
ccLog::Error("[GDAL] Driver %s is not supported", pszFormat);
return;
}
char** papszMetadata = poDriver->GetMetadata();
if( !CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
{
ccLog::Error("[GDAL] Driver %s doesn't support Create() method", pszFormat);
return;
}
//which (and how many) bands shall we create?
bool heightBand = true; //height by default
bool densityBand = false;
bool allSFBands = false;
int sfBandIndex = -1; //scalar field index
int totalBands = 0;
bool interpolateSF = (getTypeOfSFInterpolation() != INVALID_PROJECTION_TYPE);
ccPointCloud* pc = m_cloud->isA(CC_TYPES::POINT_CLOUD) ? static_cast<ccPointCloud*>(m_cloud) : 0;
bool hasSF = interpolateSF && pc && !m_grid.scalarFields.empty();
RasterExportOptionsDlg reoDlg;
reoDlg.dimensionsLabel->setText(QString("%1 x %2").arg(m_grid.width).arg(m_grid.height));
reoDlg.exportHeightsCheckBox->setChecked(heightBand);
reoDlg.exportDensityCheckBox->setChecked(densityBand);
reoDlg.exportDisplayedSFCheckBox->setEnabled(hasSF);
reoDlg.exportAllSFCheckBox->setEnabled(hasSF);
reoDlg.exportAllSFCheckBox->setChecked(allSFBands);
if (!reoDlg.exec())
return;
//we ask the output filename AFTER displaying the export parameters ;)
QString outputFilename;
{
QSettings settings;
settings.beginGroup(ccPS::HeightGridGeneration());
QString imageSavePath = settings.value("savePathImage",QApplication::applicationDirPath()).toString();
outputFilename = QFileDialog::getSaveFileName(0,"Save height grid raster",imageSavePath+QString("/raster.tif"),"geotiff (*.tif)");
if (outputFilename.isNull())
return;
//save current export path to persistent settings
settings.setValue("savePathImage",QFileInfo(outputFilename).absolutePath());
}
heightBand = reoDlg.exportHeightsCheckBox->isChecked();
densityBand = reoDlg.exportDensityCheckBox->isChecked();
if (hasSF)
{
assert(pc);
allSFBands = reoDlg.exportAllSFCheckBox->isChecked() && hasSF;
if (!allSFBands && reoDlg.exportDisplayedSFCheckBox->isChecked())
{
sfBandIndex = pc->getCurrentDisplayedScalarFieldIndex();
if (sfBandIndex < 0)
ccLog::Warning("[Rasterize] Cloud has no active (displayed) SF!");
}
}
totalBands = heightBand ? 1 : 0;
if (densityBand)
{
++totalBands;
}
if (allSFBands)
{
assert(hasSF);
for (size_t i=0; i<m_grid.scalarFields.size(); ++i)
if (m_grid.scalarFields[i])
++totalBands;
}
else if (sfBandIndex >= 0)
{
++totalBands;
}
if (totalBands == 0)
{
ccLog::Warning("[Rasterize] Warning, can't output a raster with no band! (check export parameters)");
return;
}
//.........这里部分代码省略.........
示例14: loadFile
//.........这里部分代码省略.........
{
delete cloud;
ply_close(ply);
return CC_FERR_NOT_ENOUGH_MEMORY;
}
cloud->showColors(true);
}
/* SCALAR FIELDS (SF) */
{
for (size_t i=0; i<sfPropIndexes.size(); ++i)
{
int sfIndex = sfPropIndexes[i];
plyProperty& pp = stdProperties[sfIndex-1];
unsigned numberOfScalars = pointElements[pp.elemIndex].elementInstances;
//does the number of scalars matches the number of points?
if (numberOfPoints != numberOfScalars)
{
ccLog::Error(QString("Scalar field #%1: the number of scalars doesn't match the number of points (they will be ignored)!").arg(i+1));
ccLog::Warning(QString("[PLY] Scalar field #%1 ignored!").arg(i+1));
numberOfScalars = 0;
}
else
{
QString qPropName(pp.propName);
if (qPropName.startsWith("scalar_") && qPropName.length() > 7)
{
//remove the 'scalar_' prefix added when saving SF with CC!
qPropName = qPropName.mid(7).replace('_',' ');
}
int sfIdx = cloud->addScalarField(qPrintable(qPropName));
if (sfIdx >= 0)
{
CCLib::ScalarField* sf = cloud->getScalarField(sfIdx);
assert(sf);
if (sf->reserve(numberOfScalars))
{
ply_set_read_cb(ply, pointElements[pp.elemIndex].elementName, pp.propName, scalar_cb, sf, 1);
}
else
{
cloud->deleteScalarField(sfIdx);
sfIdx = -1;
}
}
if (sfIdx < 0)
{
ccLog::Error(QString("Scalar field #%1: not enough memory to load scalar field (they will be ignored)!").arg(i+1));
ccLog::Warning(QString("[PLY] Scalar field #%1 ignored!").arg(i+1));
}
}
}
}
/* MESH FACETS (TRI) */
ccMesh* mesh = 0;
unsigned numberOfFacets = 0;
if (facesIndex > 0)
{
plyProperty& pp = listProperties[facesIndex-1];
示例15: refCloud
ccPointCloud* cc2Point5DimEditor::convertGridToCloud( const std::vector<ExportableFields>& exportedFields,
bool interpolateSF,
bool resampleInputCloud,
ccGenericPointCloud* inputCloud,
bool fillEmptyCells,
double emptyCellsHeight) const
{
if (!m_grid.isValid())
return 0;
unsigned pointsCount = (fillEmptyCells ? m_grid.width * m_grid.height : m_grid.validCellCount);
if (pointsCount == 0)
{
ccLog::Warning("[Rasterize] Empty grid!");
return 0;
}
ccPointCloud* cloudGrid = 0;
if (resampleInputCloud)
{
CCLib::ReferenceCloud refCloud(inputCloud);
if (refCloud.reserve(m_grid.nonEmptyCellCount))
{
for (unsigned j=0; j<m_grid.height; ++j)
{
for (unsigned i=0; i<m_grid.width; ++i)
{
const RasterCell& cell = m_grid.data[j][i];
if (cell.nbPoints) //non empty cell
{
refCloud.addPointIndex(cell.pointIndex);
}
}
}
assert(refCloud.size() != 0);
cloudGrid = inputCloud->isA(CC_TYPES::POINT_CLOUD) ? static_cast<ccPointCloud*>(inputCloud)->partialClone(&refCloud) : ccPointCloud::From(&refCloud,inputCloud);
cloudGrid->setPointSize(0); //to avoid display issues
//even if we have already resampled the original cloud we may have to create new points and/or scalar fields
//if (!interpolateSF && !fillEmptyCells)
// return cloudGrid;
}
else
{
ccLog::Warning("[Rasterize] Not enough memory!");
return 0;
}
}
else
{
cloudGrid = new ccPointCloud("grid");
}
assert(cloudGrid);
//shall we generate per-cell fields as well?
std::vector<CCLib::ScalarField*> exportedSFs;
if (!exportedFields.empty())
{
exportedSFs.resize(exportedFields.size(),0);
for (size_t i=0; i<exportedFields.size(); ++i)
{
int sfIndex = -1;
switch (exportedFields[i])
{
case PER_CELL_HEIGHT:
case PER_CELL_COUNT:
case PER_CELL_MIN_HEIGHT:
case PER_CELL_MAX_HEIGHT:
case PER_CELL_AVG_HEIGHT:
case PER_CELL_HEIGHT_STD_DEV:
case PER_CELL_HEIGHT_RANGE:
sfIndex = cloudGrid->addScalarField(qPrintable(GetDefaultFieldName(exportedFields[i])));
break;
default:
assert(false);
break;
}
if (sfIndex < 0)
{
ccLog::Warning("[Rasterize] Couldn't allocate scalar field(s)! Try to free some memory ...");
break;
}
exportedSFs[i] = cloudGrid->getScalarField(sfIndex);
assert(exportedSFs[i]);
}
}
//the resampled cloud already contains the points corresponding to 'filled' cells so we will only
//need to add the empty ones (if requested)
if ((!resampleInputCloud || fillEmptyCells) && !cloudGrid->reserve(pointsCount))
{
ccLog::Warning("[Rasterize] Not enough memory!");
delete cloudGrid;
return 0;
}
//vertical dimension
const unsigned char Z = getProjectionDimension();
//.........这里部分代码省略.........