本文整理汇总了C++中cclib::ScalarField::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ ScalarField::getValue方法的具体用法?C++ ScalarField::getValue怎么用?C++ ScalarField::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cclib::ScalarField
的用法示例。
在下文中一共展示了ScalarField::getValue方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: if
//.........这里部分代码省略.........
++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)
{
unsigned char C[3];
if (in.read((char*)C,sizeof(ColorCompType)*3) < 0)
{
//Console::print("[BinFilter::loadModelFromBinaryFile] Error reading the %ith entity colors !\n",k);
return CC_FERR_READING;
}
loadedCloud->addRGBColor(C);
}
if (header.normals)
{
CCVector3 N;
if (in.read((char*)N.u,sizeof(float)*3) < 0)
{
//Console::print("[BinFilter::loadModelFromBinaryFile] Error reading the %ith entity norms !\n",k);
return CC_FERR_READING;
}
loadedCloud->addNorm(N);
}
if (header.scalarField)
{
double D;
if (in.read((char*)&D,sizeof(double)) < 0)
{
//Console::print("[BinFilter::loadModelFromBinaryFile] Error reading the %ith entity distance!\n",k);
return CC_FERR_READING;
}
ScalarType d = static_cast<ScalarType>(D);
loadedCloud->setPointScalarValue(i,d);
}
lineRead++;
if (parameters.alwaysDisplayLoadDialog && !nprogress.oneStep())
{
loadedCloud->resize(i+1-fileChunkPos);
k=nbScansTotal;
i=nbOfPoints;
}
}
if (parameters.alwaysDisplayLoadDialog)
{
pdlg.stop();
QApplication::processEvents();
}
if (header.scalarField)
{
CCLib::ScalarField* sf = loadedCloud->getCurrentInScalarField();
assert(sf);
sf->setName(sfName);
//replace HIDDEN_VALUES by NAN_VALUES
for (unsigned i=0; i<sf->currentSize(); ++i)
{
if (sf->getValue(i) == FORMER_HIDDEN_POINTS)
sf->setValue(i,NAN_VALUE);
}
sf->computeMinAndMax();
loadedCloud->setCurrentDisplayedScalarField(loadedCloud->getCurrentInScalarFieldIndex());
loadedCloud->showSF(true);
}
container.addChild(loadedCloud);
}
return CC_FERR_NO_ERROR;
}
示例4: nProgress
//.........这里部分代码省略.........
if (P->u[Z] < aCell->minHeight)
{
aCell->minHeight = P->u[Z];
if (projectionType == PROJ_MINIMUM_VALUE)
aCell->pointIndex = n;
}
else if (P->u[Z] > aCell->maxHeight)
{
aCell->maxHeight = P->u[Z];
if (projectionType == PROJ_MAXIMUM_VALUE)
aCell->pointIndex = n;
}
}
else
{
aCell->minHeight = aCell->maxHeight = P->u[Z];
aCell->pointIndex = n;
}
// Sum the points heights
aCell->avgHeight += P->u[Z];
aCell->stdDevHeight += static_cast<double>(P->u[Z])*P->u[Z];
//scalar fields
if (interpolateSF)
{
int pos = j*static_cast<int>(width)+i; //pos in 2D SF grid(s)
assert(pos < static_cast<int>(gridTotalSize));
for (size_t k=0; k<scalarFields.size(); ++k)
{
if (scalarFields[k])
{
CCLib::ScalarField* sf = pc->getScalarField(static_cast<unsigned>(k));
assert(sf);
ScalarType sfValue = sf->getValue(n);
ScalarType formerValue = static_cast<ScalarType>(scalarFields[k][pos]);
if (pointsInCell && ccScalarField::ValidValue(formerValue))
{
if (ccScalarField::ValidValue(sfValue))
{
switch (sfInterpolation)
{
case PROJ_MINIMUM_VALUE:
// keep the minimum value
scalarFields[k][pos] = std::min<double>(formerValue,sfValue);
break;
case PROJ_AVERAGE_VALUE:
//we sum all values (we will divide them later)
scalarFields[k][pos] += sfValue;
break;
case PROJ_MAXIMUM_VALUE:
// keep the maximum value
scalarFields[k][pos] = std::max<double>(formerValue,sfValue);
break;
default:
assert(false);
break;
}
}
}
else
{
//for the first (vaild) point, we simply have to store its SF value (in any case)
scalarFields[k][pos] = sfValue;
}
}
示例5: saveToFile
//.........这里部分代码省略.........
const double* shift = theCloud->getOriginalShift();
liblas::Writer* writer = 0;
try
{
liblas::Header header;
//LAZ support based on extension!
if (QFileInfo(filename).suffix().toUpper() == "LAZ")
{
header.SetCompressed(true);
}
//header.SetDataFormatId(liblas::ePointFormat3);
ccBBox bBox = theCloud->getBB();
if (bBox.isValid())
{
header.SetMin(-shift[0]+(double)bBox.minCorner().x,-shift[1]+(double)bBox.minCorner().y,-shift[2]+(double)bBox.minCorner().z);
header.SetMax(-shift[0]+(double)bBox.maxCorner().x,-shift[1]+(double)bBox.maxCorner().y,-shift[2]+(double)bBox.maxCorner().z);
CCVector3 diag = bBox.getDiagVec();
//Set offset & scale, as points will be stored as boost::int32_t values (between 0 and 4294967296)
//int_value = (double_value-offset)/scale
header.SetOffset(-shift[0]+(double)bBox.minCorner().x,-shift[1]+(double)bBox.minCorner().y,-shift[2]+(double)bBox.minCorner().z);
header.SetScale(1.0e-9*std::max<double>(diag.x,ZERO_TOLERANCE), //result must fit in 32bits?!
1.0e-9*std::max<double>(diag.y,ZERO_TOLERANCE),
1.0e-9*std::max<double>(diag.z,ZERO_TOLERANCE));
}
header.SetPointRecordsCount(numberOfPoints);
//header.SetDataFormatId(Header::ePointFormat1);
writer = new liblas::Writer(ofs, header);
}
catch (...)
{
return CC_FERR_WRITING;
}
//progress dialog
ccProgressDialog pdlg(true); //cancel available
CCLib::NormalizedProgress nprogress(&pdlg,numberOfPoints);
pdlg.setMethodTitle("Save LAS file");
char buffer[256];
sprintf(buffer,"Points: %i",numberOfPoints);
pdlg.setInfo(buffer);
pdlg.start();
//liblas::Point point(boost::shared_ptr<liblas::Header>(new liblas::Header(writer->GetHeader())));
liblas::Point point(&writer->GetHeader());
for (unsigned i=0; i<numberOfPoints; i++)
{
const CCVector3* P = theCloud->getPoint(i);
{
double x=-shift[0]+(double)P->x;
double y=-shift[1]+(double)P->y;
double z=-shift[2]+(double)P->z;
point.SetCoordinates(x, y, z);
}
if (hasColor)
{
const colorType* rgb = theCloud->getPointColor(i);
point.SetColor(liblas::Color(rgb[0]<<8,rgb[1]<<8,rgb[2]<<8)); //DGM: LAS colors are stored on 16 bits!
}
if (classifSF)
{
liblas::Classification classif;
classif.SetClass((boost::uint32_t)classifSF->getValue(i));
point.SetClassification(classif);
}
if (intensitySF)
{
point.SetIntensity((boost::uint16_t)intensitySF->getValue(i));
}
if (timeSF)
{
point.SetTime((double)timeSF->getValue(i));
}
if (returnNumberSF)
{
point.SetReturnNumber((boost::uint16_t)returnNumberSF->getValue(i));
point.SetNumberOfReturns((boost::uint16_t)returnNumberSF->getMax());
}
writer->WritePoint(point);
if (!nprogress.oneStep())
break;
}
delete writer;
//ofs.close();
return CC_FERR_NO_ERROR;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}