本文整理汇总了C++中cclib::GenericIndexedCloudPersist类的典型用法代码示例。如果您正苦于以下问题:C++ GenericIndexedCloudPersist类的具体用法?C++ GenericIndexedCloudPersist怎么用?C++ GenericIndexedCloudPersist使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GenericIndexedCloudPersist类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ComputeFacetExtensions
//helper: computes a facet horizontal and vertical extensions
void ComputeFacetExtensions(CCVector3& N, ccPolyline* facetContour, double& horizExt, double& vertExt)
{
//horizontal and vertical extensions
horizExt = vertExt = 0;
CCLib::GenericIndexedCloudPersist* vertCloud = facetContour->getAssociatedCloud();
if (vertCloud)
{
//oriRotMat.applyRotation(N); //DGM: oriRotMat is only for display!
//we assume that at this point the "up" direction is always (0,0,1)
CCVector3 Xf(1,0,0), Yf(0,1,0);
//we get the horizontal vector on the plane
CCVector3 D = CCVector3(0,0,1).cross(N);
if (D.norm2() > ZERO_TOLERANCE) //otherwise the facet is horizontal!
{
Yf = D;
Yf.normalize();
Xf = N.cross(Yf);
}
const CCVector3* G = CCLib::Neighbourhood(vertCloud).getGravityCenter();
ccBBox box;
for (unsigned i=0; i<vertCloud->size(); ++i)
{
const CCVector3 P = *(vertCloud->getPoint(i)) - *G;
CCVector3 p( P.dot(Xf), P.dot(Yf), 0 );
box.add(p);
}
vertExt = box.getDiagVec().x;
horizExt = box.getDiagVec().y;
}
}
开发者ID:Sephrimoth,项目名称:trunk,代码行数:35,代码来源:qFacets.cpp
示例2: readPolygonFile
void TestShpFilter::readPolygonFile(const QString &filePath) const
{
const unsigned expectedNumPoints = 14; // File has 15 points but as its a polygon, CC will keep the 14 first pts
CCVector3d bbMin(-626146.0444521683, 5219675.646154184, 0);
CCVector3d shift = ccGlobalShiftManager::BestShift(bbMin);
bool shiftEnabled = true;
ccHObject container;
FileIOFilter::LoadParameters params;
params.alwaysDisplayLoadDialog = false;
params.shiftHandlingMode = ccGlobalShiftManager::Mode::NO_DIALOG;
params.coordinatesShiftEnabled = &shiftEnabled;
params.coordinatesShift = &shift;
params.preserveShiftOnSave = true;
ShpFilter filter;
CC_FILE_ERROR error = filter.loadFile(filePath, container, params);
QVERIFY(error == CC_FERR_NO_ERROR);
QVERIFY(container.getChildrenNumber() == 1);
ccHObject *item = container.getFirstChild();
QVERIFY(item->getClassID() == CC_TYPES::POLY_LINE);
auto *poly = static_cast<ccPolyline *>(item);
QVERIFY(poly->size() == expectedNumPoints);
QVERIFY(!poly->isScalarFieldEnabled());
QVERIFY(!poly->is2DMode());
QVERIFY(poly->isClosed());
CCLib::GenericIndexedCloudPersist *vertices = poly->getAssociatedCloud();
QVERIFY(vertices->size() == expectedNumPoints);
std::array<double, 14> expectedXs{-626146.0444521683, -187004.53123683017, -59884.61951660062, 169316.43343351,
180872.78904444003, 300288.4636907161, 914701.3703384919, 752912.3917854726,
880032.303505702, 749060.273248496, 473633.79785466543, 375404.77516176086,
-212043.3017271784, -187004.53123683017};
std::array<double, 14> expectedYs{6182705.280398346, 6409980.274079968, 6383015.444321131, 6488948.704087989,
6606438.319465778, 6650737.682641009, 6236634.939916019, 5878387.91597719,
5391094.921049644, 5271679.246403368, 5352573.735679878, 5219675.646154184,
5348721.617142901, 5789789.189626727};
for (unsigned i(0); i < expectedNumPoints; ++i)
{
const CCVector3 *p = vertices->getPoint(i);
QCOMPARE(p->x, static_cast<ScalarType >(expectedXs[i] + shift.x));
QCOMPARE(p->y, static_cast<ScalarType >(expectedYs[i] + shift.y));
QCOMPARE(p->z, 0.0);
}
}
开发者ID:asmaloney,项目名称:trunk,代码行数:49,代码来源:TestShpFilter.cpp
示例3: ICP
bool ccRegistrationTools::ICP( ccHObject* data,
ccHObject* model,
ccGLMatrix& transMat,
double &finalScale,
double& finalRMS,
unsigned& finalPointCount,
double minRMSDecrease,
unsigned maxIterationCount,
unsigned randomSamplingLimit,
bool removeFarthestPoints,
CCLib::ICPRegistrationTools::CONVERGENCE_TYPE method,
bool adjustScale,
double finalOverlapRatio/*=1.0*/,
bool useDataSFAsWeights/*=false*/,
bool useModelSFAsWeights/*=false*/,
int filters/*=CCLib::ICPRegistrationTools::SKIP_NONE*/,
int maxThreadCount/*=0*/,
QWidget* parent/*=0*/)
{
//progress bar
QScopedPointer<ccProgressDialog> progressDlg;
if (parent)
{
progressDlg.reset(new ccProgressDialog(false, parent));
}
Garbage<CCLib::GenericIndexedCloudPersist> cloudGarbage;
//if the 'model' entity is a mesh, we need to sample points on it
CCLib::GenericIndexedCloudPersist* modelCloud = nullptr;
ccGenericMesh* modelMesh = nullptr;
if (model->isKindOf(CC_TYPES::MESH))
{
modelMesh = ccHObjectCaster::ToGenericMesh(model);
modelCloud = modelMesh->getAssociatedCloud();
}
else
{
modelCloud = ccHObjectCaster::ToGenericPointCloud(model);
}
//if the 'data' entity is a mesh, we need to sample points on it
CCLib::GenericIndexedCloudPersist* dataCloud = nullptr;
if (data->isKindOf(CC_TYPES::MESH))
{
dataCloud = CCLib::MeshSamplingTools::samplePointsOnMesh(ccHObjectCaster::ToGenericMesh(data), s_defaultSampledPointsOnDataMesh, progressDlg.data());
if (!dataCloud)
{
ccLog::Error("[ICP] Failed to sample points on 'data' mesh!");
return false;
}
cloudGarbage.add(dataCloud);
}
else
{
dataCloud = ccHObjectCaster::ToGenericPointCloud(data);
}
//we activate a temporary scalar field for registration distances computation
CCLib::ScalarField* dataDisplayedSF = nullptr;
int oldDataSfIdx = -1, dataSfIdx = -1;
//if the 'data' entity is a real ccPointCloud, we can even create a proper temporary SF for registration distances
if (data->isA(CC_TYPES::POINT_CLOUD))
{
ccPointCloud* pc = static_cast<ccPointCloud*>(data);
dataDisplayedSF = pc->getCurrentDisplayedScalarField();
oldDataSfIdx = pc->getCurrentInScalarFieldIndex();
dataSfIdx = pc->getScalarFieldIndexByName(REGISTRATION_DISTS_SF);
if (dataSfIdx < 0)
dataSfIdx = pc->addScalarField(REGISTRATION_DISTS_SF);
if (dataSfIdx >= 0)
pc->setCurrentScalarField(dataSfIdx);
else
{
ccLog::Error("[ICP] Couldn't create temporary scalar field! Not enough memory?");
return false;
}
}
else
{
if (!dataCloud->enableScalarField())
{
ccLog::Error("[ICP] Couldn't create temporary scalar field! Not enough memory?");
return false;
}
}
//add a 'safety' margin to input ratio
static double s_overlapMarginRatio = 0.2;
finalOverlapRatio = std::max(finalOverlapRatio, 0.01); //1% minimum
//do we need to reduce the input point cloud (so as to be close
//to the theoretical number of overlapping points - but not too
//low so as we are not registered yet ;)
if (finalOverlapRatio < 1.0 - s_overlapMarginRatio)
{
//DGM we can now use 'approximate' distances as SAITO algorithm is exact (but with a coarse resolution)
//level = 7 if < 1.000.000
//level = 8 if < 10.000.000
//level = 9 if > 10.000.000
//.........这里部分代码省略.........
开发者ID:cloudcompare,项目名称:trunk,代码行数:101,代码来源:ccRegistrationTools.cpp
示例4: ComputeSurfacesAndVolumes
bool DistanceMapGenerationTool::ComputeSurfacesAndVolumes( const QSharedPointer<Map>& map,
ccPolyline* profile,
Measures& surface,
Measures& volume)
{
if (!map || !profile)
//invalid input!
return false;
CCLib::GenericIndexedCloudPersist* vertices = profile->getAssociatedCloud();
unsigned vertexCount = vertices ? vertices->size() : 0;
if (vertexCount < 2)
{
//invalid profile!
return false;
}
const ccPointCloud* pcVertices = dynamic_cast<ccPointCloud*>(profile->getAssociatedCloud());
if (!pcVertices)
return false;
//surface measures
surface = Measures();
//volume measures
volume = Measures();
//theoretical surface and volumes
{
double surfaceProd = 0.0;
double volumeProd = 0.0;
const double yMax = map->yMin + map->yStep * (double)map->ySteps;
for (unsigned i=1; i<pcVertices->size(); ++i)
{
const CCVector3* P0 = pcVertices->getPoint(i-1);
const CCVector3* P1 = pcVertices->getPoint(i);
//polyline: X = radius, Y = height
double r0 = P0->x;
double y0 = P0->y;
double r1 = P1->x;
double y1 = P1->y;
//without loss of generality ;)
if (y0 > y1)
{
std::swap(y0,y1);
std::swap(r0,r1);
}
//segment is totally outside the map?
if (y1 < map->yMin || y0 > yMax)
{
//we skip it
continue;
}
if (y0 < map->yMin)
{
//interpolate r0 @ map->yMin
double alpha = (map->yMin - y0)/(y1 - y0);
assert(alpha >= 0.0 && alpha <= 1.0);
r0 = r0 + alpha * (r1 - r0);
y0 = map->yMin;
}
else if (y1 > yMax)
{
//interpolate r1 @ map->yMax
double alpha = (yMax - y0)/(y1 - y0);
assert(alpha >= 0.0 && alpha <= 1.0);
r1 = r0 + alpha * (r1 - r0);
y1 = yMax;
}
//product for truncated cone surface (see http://en.wikipedia.org/wiki/Frustum)
double segmentLength = sqrt((r1-r0)*(r1-r0) + (y1-y0)*(y1-y0));
surfaceProd += (r0 + r1) * segmentLength;
//product for truncated cone volume (see http://en.wikipedia.org/wiki/Frustum)
volumeProd += (y1 - y0) * (r0*r0 + r1*r1 + r0*r1);
}
surface.theoretical = M_PI * surfaceProd;
volume.theoretical = M_PI / 3.0 * volumeProd;
}
int revolDim = GetPoylineRevolDim(profile);
if (revolDim < 0)
return false;
//constant factors
const double surfPart = map->xStep / 2.0; //perimeter of a portion of circle of angle alpha = alpha * r (* height to get the external surface)
const double volPart = map->yStep * map->xStep / 6.0; //area of a portion of circle of angle alpha = alpha/2 * r^2 (* height to get the volume)
const MapCell* cell = &map->at(0);
//for each row
for (unsigned j=0; j<map->ySteps; ++j)
{
//corresponding heights
double height1 = map->yMin + (double)j * map->yStep;
double height2 = height1 + map->yStep;
//.........这里部分代码省略.........
开发者ID:ORNis,项目名称:CloudCompare,代码行数:101,代码来源:distanceMapGenerationTool.cpp
示例5: ComputeRadialDist
bool DistanceMapGenerationTool::ComputeRadialDist( ccPointCloud* cloud,
ccPolyline* profile,
bool storeRadiiAsSF/*=false*/,
ccMainAppInterface* app/*=0*/)
{
//check input cloud and profile/polyline
if (!cloud || !profile)
{
if (app)
app->dispToConsole(QString("Internal error: invalid input parameters"),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return false;
}
assert(cloud && profile);
//number of vertices for the profile
CCLib::GenericIndexedCloudPersist* vertices = profile->getAssociatedCloud();
unsigned vertexCount = vertices->size();
if (vertexCount < 2)
{
if (app)
app->dispToConsole(QString("Invalid polyline (not enough vertices)"),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return false;
}
//profile meta-data
ProfileMetaData profileDesc;
if (!GetPoylineMetaData(profile, profileDesc))
{
if (app)
app->dispToConsole(QString("Invalid polyline (bad or missing meta-data)"),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return false;
}
//reserve a new scalar field (or take the old one if it already exists)
int sfIdx = cloud->getScalarFieldIndexByName(RADIAL_DIST_SF_NAME);
if (sfIdx < 0)
sfIdx = cloud->addScalarField(RADIAL_DIST_SF_NAME);
if (sfIdx < 0)
{
if (app)
app->dispToConsole(QString("Failed to allocate a new scalar field for computing distances! Try to free some memory ..."),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return false;
}
ccScalarField* sf = static_cast<ccScalarField*>(cloud->getScalarField(sfIdx));
unsigned pointCount = cloud->size();
sf->resize(pointCount); //should always be ok
assert(sf);
ccScalarField* radiiSf = 0;
if (storeRadiiAsSF)
{
int sfIdxRadii = cloud->getScalarFieldIndexByName(RADII_SF_NAME);
if (sfIdxRadii < 0)
sfIdxRadii = cloud->addScalarField(RADII_SF_NAME);
if (sfIdxRadii < 0)
{
if (app)
app->dispToConsole(QString("Failed to allocate a new scalar field for storing radii! You should try to free some memory ..."),ccMainAppInterface::WRN_CONSOLE_MESSAGE);
//return false;
}
else
{
radiiSf = static_cast<ccScalarField*>(cloud->getScalarField(sfIdxRadii));
radiiSf->resize(pointCount); //should always be ok
}
}
bool success = true;
//now compute the distance between the cloud and the (implicit) surface of revolution
{
ccGLMatrix cloudToSurface = profileDesc.computeProfileToSurfaceTrans();
//we deduce the horizontal dimensions from the revolution axis
const unsigned char dim1 = static_cast<unsigned char>(profileDesc.revolDim < 2 ? profileDesc.revolDim+1 : 0);
const unsigned char dim2 = (dim1 < 2 ? dim1+1 : 0);
ccProgressDialog dlg(true, app ? app->getMainWindow() : 0);
dlg.setMethodTitle("Cloud to profile radial distance");
dlg.setInfo(qPrintable(QString("Polyline: %1 vertices\nCloud: %2 points").arg(vertexCount).arg(pointCount)));
dlg.start();
CCLib::NormalizedProgress nProgress(static_cast<CCLib::GenericProgressCallback*>(&dlg),pointCount);
for (unsigned i=0; i<pointCount; ++i)
{
const CCVector3* P = cloud->getPoint(i);
//relative point position
CCVector3 Prel = cloudToSurface * (*P);
//deduce point height and radius (i.e. in profile 2D coordinate system)
double height = Prel.u[profileDesc.revolDim] - profileDesc.heightShift;
//TODO FIXME: we assume the surface of revolution is smooth!
double radius = sqrt(Prel.u[dim1]*Prel.u[dim1] + Prel.u[dim2]*Prel.u[dim2]);
if (radiiSf)
{
ScalarType radiusVal = static_cast<ScalarType>(radius);
radiiSf->setValue(i,radiusVal);
}
//.........这里部分代码省略.........
开发者ID:ORNis,项目名称:CloudCompare,代码行数:101,代码来源:distanceMapGenerationTool.cpp
示例6: ConvertMapToCloud
ccPointCloud* DistanceMapGenerationTool::ConvertMapToCloud( const QSharedPointer<Map>& map,
ccPolyline* profile,
double baseRadius/*=1.0*/,
bool keepNaNPoints/*=true*/)
{
if (!map || !profile)
return 0;
unsigned count = map->ySteps * map->xSteps;
ccPointCloud* cloud = new ccPointCloud("map");
ccScalarField* sf = new ccScalarField("values");
if (!cloud->reserve(count) || !sf->reserve(count))
{
//not enough memory
delete cloud;
sf->release();
return 0;
}
//number of vertices
CCLib::GenericIndexedCloudPersist* polyVertices = profile->getAssociatedCloud();
unsigned polyVertCount = polyVertices->size();
if (polyVertCount < 2)
return 0;
//profile meta-data (we only need the height shift)
PointCoordinateType heightShift = 0;
GetPolylineHeightShift(profile, heightShift);
const double xStep = baseRadius * (2.0*M_PI) / static_cast<double>(map->xSteps);
const MapCell* cell = &map->at(0);
for (unsigned j=0; j<map->ySteps; ++j)
{
CCVector3 P(0,static_cast<PointCoordinateType>(map->yMin + (static_cast<double>(j) + 0.5) * map->yStep),0);
//for each column
for (unsigned i=0; i<map->xSteps; ++i, ++cell)
{
if (keepNaNPoints || cell->count != 0)
{
P.x = static_cast<PointCoordinateType>(map->xMin + (static_cast<double>(i) + 0.5) * xStep);
//search nearest "segment" in polyline
for (unsigned k=1; k<polyVertCount; ++k)
{
const CCVector3* A = polyVertices->getPoint(k-1);
const CCVector3* B = polyVertices->getPoint(k);
double alpha = (P.y - heightShift - A->y)/(B->y - A->y);
if (alpha >= 0.0 && alpha <= 1.0)
{
//we deduce the right radius by linear interpolation
double radius_th = A->x + alpha * (B->x - A->x);
//TODO: we take the first radius (even if there are other segments at
//this particular height, because we can't guess which one is the 'right' one!
P.z = static_cast<PointCoordinateType>(radius_th);
break;
}
}
cloud->addPoint(P);
ScalarType val = cell->count ? static_cast<ScalarType>(cell->value) : NAN_VALUE;
sf->addElement(val);
}
}
}
sf->computeMinAndMax();
int sfIdx = cloud->addScalarField(sf);
cloud->setCurrentDisplayedScalarField(sfIdx);
cloud->showSF(true);
cloud->resize(cloud->size()); //if we have skipped NaN values!
return cloud;
}
开发者ID:ORNis,项目名称:CloudCompare,代码行数:78,代码来源:distanceMapGenerationTool.cpp
示例7: ConvertProfileToMesh
ccMesh* DistanceMapGenerationTool::ConvertProfileToMesh(ccPolyline* profile,
const ccGLMatrix& cloudToSurface,
bool counterclockwise,
unsigned angularSteps/*=36*/,
QImage mapTexture/*=QImage()*/)
{
if (!profile || angularSteps < 3)
{
return 0;
}
//profile vertices
CCLib::GenericIndexedCloudPersist* profileVertices = profile->getAssociatedCloud();
unsigned profVertCount = profileVertices->size();
if (profVertCount < 2)
{
return 0;
}
//profile meta-data
ProfileMetaData profileDesc;
if (!GetPoylineMetaData(profile, profileDesc))
{
assert(false);
return 0;
}
unsigned char Z = static_cast<unsigned char>(profileDesc.revolDim);
//we deduce the 2 other ('horizontal') dimensions
const unsigned char X = (Z < 2 ? Z+1 : 0);
const unsigned char Y = (X < 2 ? X+1 : 0);
unsigned meshVertCount = profVertCount * angularSteps;
unsigned meshFaceCount = (profVertCount-1) * angularSteps * 2;
ccPointCloud* cloud = new ccPointCloud("vertices");
ccMesh* mesh = new ccMesh(cloud);
if (!cloud->reserve(meshVertCount) || !mesh->reserve(meshFaceCount))
{
//not enough memory
delete cloud;
delete mesh;
return 0;
}
ccGLMatrix surfaceToCloud = cloudToSurface.inverse();
//create vertices
{
double cwSign = (counterclockwise ? -1.0 : 1.0);
for (unsigned j=0; j<angularSteps; ++j)
{
double angle_rad = static_cast<double>(j)/angularSteps * (2*M_PI);
CCVector3d N(sin(angle_rad) * cwSign,
cos(angle_rad),
0);
for (unsigned i=0; i<profVertCount; ++i)
{
const CCVector3* P = profileVertices->getPoint(i);
double radius = static_cast<double>(P->x);
CCVector3 Pxyz;
Pxyz.u[X] = static_cast<PointCoordinateType>(radius * N.x);
Pxyz.u[Y] = static_cast<PointCoordinateType>(radius * N.y);
Pxyz.u[Z] = P->y + profileDesc.heightShift;
surfaceToCloud.apply(Pxyz);
cloud->addPoint(Pxyz);
}
}
mesh->addChild(cloud);
}
PointCoordinateType h0 = profileVertices->getPoint(0)->y;
PointCoordinateType dH = profileVertices->getPoint(profVertCount-1)->y - h0;
bool invertedHeight = (dH < 0);
//create facets
{
for (unsigned j=0; j<angularSteps; ++j)
{
unsigned nextJ = ((j+1) % angularSteps);
for (unsigned i=0; i+1<profVertCount; ++i)
{
unsigned vertA = j*profVertCount+i;
unsigned vertB = nextJ*profVertCount+i;
unsigned vertC = vertB+1;
unsigned vertD = vertA+1;
if (invertedHeight)
{
mesh->addTriangle(vertB,vertC,vertD);
mesh->addTriangle(vertB,vertD,vertA);
}
else
{
mesh->addTriangle(vertB,vertD,vertC);
mesh->addTriangle(vertB,vertA,vertD);
//.........这里部分代码省略.........
开发者ID:ORNis,项目名称:CloudCompare,代码行数:101,代码来源:distanceMapGenerationTool.cpp
示例8: doExportSegmentationPolyline
void ccGraphicalSegmentationTool::doExportSegmentationPolyline()
{
MainWindow* mainWindow = MainWindow::TheInstance();
if (mainWindow && m_segmentationPoly)
{
QMessageBox messageBox(0);
messageBox.setWindowTitle("Choose export type");
messageBox.setText("Export polyline in:\n - 2D (with coordinates relative to the screen)\n - 3D (with coordinates relative to the segmented entities)");
QPushButton* button2D = new QPushButton("2D");
QPushButton* button3D = new QPushButton("3D");
messageBox.addButton(button2D,QMessageBox::AcceptRole);
messageBox.addButton(button3D,QMessageBox::AcceptRole);
messageBox.addButton(QMessageBox::Cancel);
messageBox.setDefaultButton(button3D);
messageBox.exec();
if (messageBox.clickedButton() == messageBox.button(QMessageBox::Cancel))
{
//process cancelled by user
return;
}
ccPolyline* poly = new ccPolyline(*m_segmentationPoly);
//if we export the polyline in 3D, we must project its vertices
bool mode2D = (messageBox.clickedButton() == button2D);
if (!mode2D)
{
//get current display parameters
const double* MM = m_associatedWin->getModelViewMatd(); //viewMat
const double* MP = m_associatedWin->getProjectionMatd(); //projMat
const GLdouble half_w = static_cast<GLdouble>(m_associatedWin->width())/2;
const GLdouble half_h = static_cast<GLdouble>(m_associatedWin->height())/2;
int VP[4];
m_associatedWin->getViewportArray(VP);
//project the 2D polyline in 3D
CCLib::GenericIndexedCloudPersist* vertices = poly->getAssociatedCloud();
ccPointCloud* verticesPC = dynamic_cast<ccPointCloud*>(vertices);
if (verticesPC)
{
for (unsigned i=0; i<vertices->size(); ++i)
{
CCVector3* Pscreen = const_cast<CCVector3*>(verticesPC->getPoint(i));
GLdouble xp,yp,zp;
gluUnProject(half_w+Pscreen->x,half_h+Pscreen->y,0/*Pscreen->z*/,MM,MP,VP,&xp,&yp,&zp);
Pscreen->x = static_cast<PointCoordinateType>(xp);
Pscreen->y = static_cast<PointCoordinateType>(yp);
Pscreen->z = static_cast<PointCoordinateType>(zp);
}
verticesPC->invalidateBoundingBox();
}
else
{
assert(false);
ccLog::Warning("[Segmentation] Failed to convert 2D polyline to 3D! (internal inconsistency)");
mode2D = false;
}
}
poly->setName(QString("Segmentation polyline #%1").arg(++s_polylineExportCount));
poly->setEnabled(false); //we don't want it to appear while the segmentation mode is enabled! (anyway it's 2D only...)
poly->set2DMode(mode2D);
poly->setColor(ccColor::yellow); //we use a different color so as to differentiate them from the active polyline!
mainWindow->addToDB(poly);
ccLog::Print(QString("[Segmentation] Polyline exported (%1 vertices)").arg(poly->size()));
}
}
开发者ID:norbertwenzel,项目名称:CloudCompare,代码行数:69,代码来源:ccGraphicalSegmentationTool.cpp
示例9: doActionUseExistingPolyline
void ccGraphicalSegmentationTool::doActionUseExistingPolyline()
{
MainWindow* mainWindow = MainWindow::TheInstance();
if (mainWindow)
{
ccHObject* root = mainWindow->dbRootObject();
ccHObject::Container polylines;
if (root)
{
root->filterChildren(polylines,true,CC_TYPES::POLY_LINE);
}
if (!polylines.empty())
{
ccEntityPickerDlg epDlg(polylines,0,this);
if (!epDlg.exec())
return;
int index = epDlg.getSelectedIndex();
assert(index >= 0 && index < static_cast<int>(polylines.size()));
assert(polylines[index]->isA(CC_TYPES::POLY_LINE));
ccPolyline* poly = static_cast<ccPolyline*>(polylines[index]);
CCLib::GenericIndexedCloudPersist* vertices = poly->getAssociatedCloud();
bool mode3D = !poly->is2DMode();
//viewing parameters (for conversion from 3D to 2D)
const double* MM = m_associatedWin->getModelViewMatd(); //viewMat
const double* MP = m_associatedWin->getProjectionMatd(); //projMat
const GLdouble half_w = static_cast<GLdouble>(m_associatedWin->width())/2;
const GLdouble half_h = static_cast<GLdouble>(m_associatedWin->height())/2;
int VP[4];
m_associatedWin->getViewportArray(VP);
//force polygonal selection mode
doSetPolylineSelection();
m_segmentationPoly->clear();
m_polyVertices->clear();
//duplicate polyline 'a minima' (only points and indexes + closed state)
if ( m_polyVertices->reserve(vertices->size())
&& m_segmentationPoly->reserve(poly->size()))
{
for (unsigned i=0; i<vertices->size(); ++i)
{
CCVector3 P = *vertices->getPoint(i);
if (mode3D)
{
GLdouble xp,yp,zp;
gluProject(P.x,P.y,P.z,MM,MP,VP,&xp,&yp,&zp);
P.x = static_cast<PointCoordinateType>(xp-half_w);
P.y = static_cast<PointCoordinateType>(yp-half_h);
P.z = 0;
}
m_polyVertices->addPoint(P);
}
for (unsigned j=0; j<poly->size(); ++j)
m_segmentationPoly->addPointIndex(poly->getPointGlobalIndex(j));
m_segmentationPoly->setClosed(poly->isClosed());
if (m_segmentationPoly->isClosed())
{
//stop
m_state &= (~RUNNING);
}
if (m_associatedWin)
m_associatedWin->updateGL();
}
else
{
ccLog::Error("Not enough memory!");
}
}
else
{
ccLog::Error("No polyline in DB!");
}
}
}
开发者ID:norbertwenzel,项目名称:CloudCompare,代码行数:80,代码来源:ccGraphicalSegmentationTool.cpp
示例10: exportFacets
//.........这里部分代码省略.........
}
//determine the 'global' orientation matrix
ccGLMatrix oriRotMat;
oriRotMat.toIdentity();
if (!useNativeOrientation)
{
oriRotMat.getColumn(0)[0] = static_cast<float>(X.x);
oriRotMat.getColumn(0)[1] = static_cast<float>(X.y);
oriRotMat.getColumn(0)[2] = static_cast<float>(X.z);
oriRotMat.getColumn(1)[0] = static_cast<float>(Y.x);
oriRotMat.getColumn(1)[1] = static_cast<float>(Y.y);
oriRotMat.getColumn(1)[2] = static_cast<float>(Y.z);
oriRotMat.getColumn(2)[0] = static_cast<float>(Z.x);
oriRotMat.getColumn(2)[1] = static_cast<float>(Z.y);
oriRotMat.getColumn(2)[2] = static_cast<float>(Z.z);
oriRotMat.invert();
ccGLMatrix transMat;
transMat.setTranslation(-C);
oriRotMat = oriRotMat * transMat;
oriRotMat.setTranslation(oriRotMat.getTranslationAsVec3D() + C);
}
//for each facet
for (FacetSet::iterator it=facets.begin(); it!=facets.end(); ++it)
{
ccFacet* facet = *it;
ccPolyline* poly = facet->getContour();
//if necessary, we create a (temporary) new facet
if (!useNativeOrientation)
{
CCLib::GenericIndexedCloudPersist* vertices = poly->getAssociatedCloud();
if (!vertices || vertices->size() < 3)
continue;
//create (temporary) new polyline
ccPolyline* newPoly = new ccPolyline(*poly);
ccPointCloud* pc = (newPoly ? dynamic_cast<ccPointCloud*>(newPoly->getAssociatedCloud()) : 0);
if (pc)
{
pc->applyGLTransformation_recursive(&oriRotMat);
}
else
{
m_app->dispToConsole(QString("Failed to change the orientation of polyline '%1'! (not enough memory)").arg(poly->getName()),ccMainAppInterface::WRN_CONSOLE_MESSAGE);
continue;
}
newPoly->set2DMode(true);
poly = newPoly;
}
toSave.addChild(poly, useNativeOrientation ? ccHObject::DP_NONE : ccHObject::DP_PARENT_OF_OTHER);
//save associated meta-data as 'shapefile' fields
{
//main parameters
FacetMetaData data;
GetFacetMetaData(facet, data);
//horizontal and vertical extensions
double horizExt = 0, vertExt = 0;
ComputeFacetExtensions(data.normal,poly,horizExt,vertExt);
开发者ID:Sephrimoth,项目名称:trunk,代码行数:66,代码来源:qFacets.cpp
示例11: SavePolyline
CC_FILE_ERROR SavePolyline(ccPolyline* poly, QFile& file, int32_t& bytesWritten, ESRI_SHAPE_TYPE outputShapeType)
{
bytesWritten = 0;
if (!poly)
{
assert(false);
return CC_FERR_BAD_ENTITY_TYPE;
}
CCLib::GenericIndexedCloudPersist* vertices = poly->getAssociatedCloud();
if (!vertices)
return CC_FERR_BAD_ENTITY_TYPE;
int32_t realNumPoints = poly->size();
if (realNumPoints < 3)
return CC_FERR_BAD_ENTITY_TYPE;
bool is2D = poly->is2DMode();
bool isClosed = poly->isClosed();
ccBBox box = poly->getBB();
assert(box.isValid());
//Shape Type
{
//Byte 0: Shape Type
int32_t shapeTypeInt = qToLittleEndian<int32_t>(outputShapeType);
file.write((const char*)&shapeTypeInt,4);
bytesWritten += 4;
}
//Byte 4: Box
{
double xMin = qToLittleEndian<double>(box.minCorner().x);
double xMax = qToLittleEndian<double>(box.maxCorner().x);
double yMin = qToLittleEndian<double>(box.minCorner().y);
double yMax = qToLittleEndian<double>(box.maxCorner().y);
//The Bounding Box for the PolyLine stored in the order Xmin, Ymin, Xmax, Ymax
/*Byte 4*/file.write((const char*)&xMin,8);
/*Byte 12*/file.write((const char*)&yMin,8);
/*Byte 20*/file.write((const char*)&xMax,8);
/*Byte 28*/file.write((const char*)&yMax,8);
bytesWritten += 32;
}
//Byte 36: NumParts (The number of parts in the PolyLine)
{
int32_t numParts = qToLittleEndian<int32_t>(1);
file.write((const char*)&numParts,4);
bytesWritten += 4;
}
//Byte 40: NumPoints (The total number of points for all parts)
int32_t numPoints = realNumPoints;
if (isClosed)
numPoints++;
{
int32_t numPointsLE = qToLittleEndian<int32_t>(numPoints);
file.write((const char*)&numPointsLE,4);
bytesWritten += 4;
}
//Byte 44: Parts (An array of length NumParts)
{
//for each part, the index of its first point in the points array
int32_t startIndex = qToLittleEndian<int32_t>(0);
file.write((const char*)&startIndex,4);
bytesWritten += 4;
}
//for polygons we must list the vertices in the right order:
//"The neighborhood to the right of an observer walking along
//the ring in vertex order is the inside of the polygon"
bool inverseOrder = false;
if (outputShapeType == SHP_POLYGON || outputShapeType == SHP_POLYGON_Z)
{
assert(isClosed);
assert(numPoints > 2);
//get bounding box
ccBBox box = poly->getBB();
assert(box.isValid());
//get the two largest (ordered) dimensions (dim1, dim2)
CCVector3 diag = box.getDiagVec();
unsigned char minDim = diag.y < diag.x ? 1 : 0;
if (diag.z < diag.u[minDim])
minDim = 2;
unsigned char dim1 = ((minDim+1) % 3);
unsigned char dim2 = ((minDim+2) % 3);
if (diag.u[dim1] > 0) //if the polyline is flat, no need to bother ;)
{
//look for the top-left-most point in this 'plane'
int32_t leftMostPointIndex = 0;
{
const CCVector3* leftMostPoint = vertices->getPoint(0);
for (int32_t i=1; i<realNumPoints; ++i)
{
const CCVector3* P = vertices->getPoint(i);
if (P->u[dim1] < leftMostPoint->u[dim1] || (P->u[dim1] == leftMostPoint->u[dim1] && P->u[dim2] < leftMostPoint->u[dim2]))
//.........这里部分代码省略.........
开发者ID:sniperx2,项目名称:trunk,代码行数:101,代码来源:ShpFilter.cpp
示例12: ICP
bool ccRegistrationTools::ICP( ccHObject* data,
ccHObject* model,
ccGLMatrix& transMat,
double &finalScale,
double& finalError,
double minErrorDecrease,
unsigned maxIterationCount,
unsigned randomSamplingLimit,
bool removeFarthestPoints,
ConvergenceMethod method,
bool adjustScale,
bool useDataSFAsWeights/*=false*/,
bool useModelSFAsWeights/*=false*/,
QWidget* parent/*=0*/)
{
//progress bar
ccProgressDialog pDlg(false,parent);
//if the 'model' entity is a mesh, we need to sample points on it
CCLib::GenericIndexedCloudPersist* modelCloud = 0;
if (model->isKindOf(CC_TYPES::MESH))
{
modelCloud = CCLib::MeshSamplingTools::samplePointsOnMesh(ccHObjectCaster::ToGenericMesh(model),s_defaultSampledPointsOnModelMesh,&pDlg);
if (!modelCloud)
{
ccLog::Error("[ICP] Failed to sample points on 'model' mesh!");
return false;
}
}
else
{
modelCloud = ccHObjectCaster::ToGenericPointCloud(model);
}
//if the 'data' entity is a mesh, we need to sample points on it
CCLib::GenericIndexedCloudPersist* dataCloud = 0;
if (data->isKindOf(CC_TYPES::MESH))
{
dataCloud = CCLib::MeshSamplingTools::samplePointsOnMesh(ccHObjectCaster::ToGenericMesh(data),s_defaultSampledPointsOnDataMesh,&pDlg);
if (!dataCloud)
{
ccLog::Error("[ICP] Failed to sample points on 'data' mesh!");
return false;
}
}
else
{
dataCloud = ccHObjectCaster::ToGenericPointCloud(data);
}
//we activate a temporary scalar field for registration distances computation
CCLib::ScalarField* dataDisplayedSF = 0;
int oldDataSfIdx=-1, dataSfIdx=-1;
//if the 'data' entity is a real ccPointCloud, we can even create a temporary SF for registration distances
if (data->isA(CC_TYPES::POINT_CLOUD))
{
ccPointCloud* pc = static_cast<ccPointCloud*>(data);
dataDisplayedSF = pc->getCurrentDisplayedScalarField();
oldDataSfIdx = pc->getCurrentInScalarFieldIndex();
dataSfIdx = pc->getScalarFieldIndexByName(REGISTRATION_DISTS_SF);
if (dataSfIdx < 0)
dataSfIdx = pc->addScalarField(REGISTRATION_DISTS_SF);
if (dataSfIdx >= 0)
pc->setCurrentScalarField(dataSfIdx);
else
ccLog::Warning("[ICP] Couldn't create temporary scalar field! Not enough memory?");
}
else
{
dataCloud->enableScalarField();
}
//parameters
CCLib::PointProjectionTools::Transformation transform;
CCLib::ScalarField* modelWeights = 0;
if (useModelSFAsWeights)
{
if (modelCloud == dynamic_cast<CCLib::GenericIndexedCloudPersist*>(model) && model->isA(CC_TYPES::POINT_CLOUD))
{
ccPointCloud* pc = static_cast<ccPointCloud*>(model);
modelWeights = pc->getCurrentDisplayedScalarField();
if (!modelWeights)
ccLog::Warning("[ICP] 'useDataSFAsWeights' is true but model has no displayed scalar field!");
}
else
{
ccLog::Warning("[ICP] 'useDataSFAsWeights' is true but only point clouds scalar fields can be used as weights!");
}
}
CCLib::ScalarField* dataWeights = 0;
if (useDataSFAsWeights)
{
if (!dataDisplayedSF)
{
if (dataCloud == (CCLib::GenericIndexedCloudPersist*)data && data->isA(CC_TYPES::POINT_CLOUD))
ccLog::Warning("[ICP] 'useDataSFAsWeights' is true but data has no displayed scalar field!");
else
//.........这里部分代码省略.........
开发者ID:eile,项目名称:trunk,代码行数:101,代码来源:ccRegistrationTools.cpp
示例13: doExportSegmentationPolyline
void ccGraphicalSegmentationTool::doExportSegmentationPolyline()
{
MainWindow* mainWindow = MainWindow::TheInstance();
if (mainWindow && m_segmentationPoly)
{
bool mode2D = false;
#ifdef ALLOW_2D_OR_3D_EXPORT
QMessageBox messageBox(0);
messageBox.setWindowTitle("Choose export type");
messageBox.setText("Export polyline in:\n - 2D (with coordinates relative to the screen)\n - 3D (with coordinates relative to the segmented entities)");
QPushButton* button2D = new QPushButton("2D");
QPushButton* button3D = new QPushButton("3D");
messageBox.addButton(button2D,QMessageBox::AcceptRole);
messageBox.addButton(button3D,QMessageBox::AcceptRole);
messageBox.addButton(QMessageBox::Cancel);
messageBox.setDefaultButton(button3D);
messageBox.exec();
if (messageBox.clickedButton() == messageBox.button(QMessageBox::Cancel))
{
//process cancelled by user
return;
}
mode2D = (messageBox.clickedButton() == button2D);
#endif
ccPolyline* poly = new ccPolyline(*m_segmentationPoly);
//if the polyline is 2D and we export the polyline in 3D, we must project its vertices
if (!mode2D)
{
//get current display parameters
ccGLCameraParameters camera;
m_associatedWin->getGLCameraParameters(camera);
const double half_w = camera.viewport[2] / 2.0;
const double half_h = camera.viewport[3] / 2.0;
//project the 2D polyline in 3D
CCLib::GenericIndexedCloudPersist* vertices = poly->getAssociatedCloud();
ccPointCloud* verticesPC = dynamic_cast<ccPointCloud*>(vertices);
if (verticesPC)
{
for (unsigned i=0; i<vertices->size(); ++i)
{
CCVector3* Pscreen = const_cast<CCVector3*>(verticesPC->getPoint(i));
CCVector3d Pd(half_w + Pscreen->x, half_h + Pscreen->y, 0/*Pscreen->z*/);
CCVector3d Q3D;
camera.unproject(Pd, Q3D);
*Pscreen = CCVector3::fromArray(Q3D.u);
}
verticesPC->invalidateBoundingBox();
}
else
{
assert(false);
ccLog::Warning("[Segmentation] Failed to convert 2D polyline to 3D! (internal inconsistency)");
mode2D = false;
}
}
QString polyName = QString("Segmentation polyline #%1").arg(++s_polylineExportCount);
poly->setName(polyName);
poly->setEnabled(false); //we don't want it to appear while the segmentation mode is enabled! (anyway it's 2D only...)
poly->set2DMode(mode2D);
poly->setColor(ccColor::yellow); //we use a different color so as to differentiate them from the active polyline!
//save associated viewport
cc2DViewportObject* viewportObject = new cc2DViewportObject(polyName + QString(" viewport"));
viewportObject->setParameters(m_associatedWin->getViewportParameters());
viewportObject->setDisplay(m_associatedWin);
poly->addChild(viewportObject);
mainWindow->addToDB(poly,false,false,false);
ccLog::Print(QString("[Segmentation] Polyline exported (%1 vertices)").arg(poly->size()));
}
}
开发者ID:FrankHXW,项目名称:trunk,代码行数:75,代码来源:ccGraphicalSegmentationTool.cpp
示例14: doActionUseExistingPolyline
void ccGraphicalSegmentationTool::doActionUseExistingPolyline()
{
MainWindow* mainWindow = MainWindow::TheInstance();
if (mainWindow)
{
ccHObject* root = mainWindow->dbRootObject();
ccHObject::Container polylines;
if (root)
{
root->filterChildren(polylines,true,CC_TYPES::POLY_LINE);
}
if (!polylines.empty())
{
ccEntityPickerDlg epDlg(polylines,false,0,this);
if (!epDlg.exec())
return;
int index = epDlg.getSelectedIndex();
assert(index >= 0 && index < static_cast<int>(polylines.size()));
assert(polylines[index]->isA(CC_TYPES::POLY_LINE));
ccPolyline* poly = static_cast<ccPolyline*>(polylines[index]);
//look for an asociated viewport
ccHObject::Container viewports;
if (poly->filterChildren(viewports,false,CC_TYPES::VIEWPORT_2D_OBJECT,true) == 1)
{
//shall we apply this viewport?
if (QMessageBox::question( m_associatedWin ? m_associatedWin->asWidget() : 0,
"Associated viewport",
"The selected polyline has an associated viewport: do you want to apply it?",
QMessageBox::Yes,
QMessageBox::No) == QMessageBox::Yes)
{
m_associatedWin->setViewportParameters(static_cast<cc2DViewportObject*>(viewports.front())->getParameters());
m_associatedWin->redraw(false);
}
}
CCLib::GenericIndexedCloudPersist* vertices = poly->getAssociatedCloud();
bool mode3D = !poly->is2DMode();
//viewing parameters (for conversion from 3D to 2D)
ccGLCameraParameters camera;
m_associatedWin->getGLCameraParameters(camera);
const double half_w = camera.viewport[2] / 2.0;
const double half_h = camera.viewport[3] / 2.0;
//force polygonal selection mode
doSetPolylineSelection();
m_segmentationPoly->clear();
m_polyVertices->clear();
allowPolylineExport(false);
//duplicate polyline 'a minima' (only points and indexes + closed state)
if ( m_polyVertices->reserve(vertices->size())
&& m_segmentationPoly->reserve(poly->size()))
{
for (unsigned i=0; i<vertices->size(); ++i)
{
CCVector3 P = *vertices->getPoint(i);
if (mode3D)
{
CCVector3d Q2D;
camera.project(P, Q2D);
P.x = static_cast<PointCoordinateType>(Q2D.x-half_w);
P.y = static_cast<PointCoordinateType>(Q2D.y-half_h);
P.z = 0;
}
m_polyVertices->addPoint(P);
}
for (unsigned j=0; j<poly->size(); ++j)
{
m_segmentationPoly->addPointIndex(poly->getPointGlobalIndex(j));
}
m_segmentationPoly->setClosed(poly->isClosed());
if (m_segmentationPoly->isClosed())
{
//stop
m_state &= (~RUNNING);
allowPolylineExport(m_segmentationPoly->size() > 1);
}
if (m_associatedWin)
m_associatedWin->redraw(true, false);
}
else
{
ccLog::Error("Not enough memory!");
}
}
else
{
ccLog::Error("No polyline in DB!");
}
}
}
开发者ID:FrankHXW,项目名称:trunk,代码行数:99,代码来源:ccGraphicalSegmentationTool.cpp
注:本文中的cclib::GenericIndexedCloudPersist类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论