本文整理汇总了C++中cclib::GenericIndexedCloudPersist::size方法的典型用法代码示例。如果您正苦于以下问题:C++ GenericIndexedCloudPersist::size方法的具体用法?C++ GenericIndexedCloudPersist::size怎么用?C++ GenericIndexedCloudPersist::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cclib::GenericIndexedCloudPersist
的用法示例。
在下文中一共展示了GenericIndexedCloudPersist::size方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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);
}
}
示例3: ICP
//.........这里部分代码省略.........
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
int gridLevel = static_cast<int>(floor(log10(static_cast<double>(std::max(dataCloud->size(), modelCloud->size()))))) + 2;
gridLevel = std::min(std::max(gridLevel, 7), 9);
int result = -1;
if (modelMesh)
{
CCLib::DistanceComputationTools::Cloud2MeshDistanceComputationParams c2mParams;
c2mParams.octreeLevel = gridLevel;
c2mParams.maxSearchDist = 0;
c2mParams.useDistanceMap = true;
c2mParams.signedDistances = false;
c2mParams.flipNormals = false;
c2mParams.multiThread = false;
result = CCLib::DistanceComputationTools::computeCloud2MeshDistance(dataCloud, modelMesh, c2mParams, progressDlg.data());
}
else
{
result = CCLib::DistanceComputationTools::computeApproxCloud2CloudDistance( dataCloud,
modelCloud,
gridLevel,
-1,
progressDlg.data());
}
if (result < 0)
{
ccLog::Error("Failed to determine the max (overlap) distance (not enough memory?)");
return false;
}
//determine the max distance that (roughly) corresponds to the input overlap ratio
ScalarType maxSearchDist = 0;
{
unsigned count = dataCloud->size();
示例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;
//.........这里部分代码省略.........
示例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);
}
//.........这里部分代码省略.........
示例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;
}
示例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);
//.........这里部分代码省略.........
示例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()));
}
}
示例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!");
}
}
}
示例10: exportFacets
void qFacets::exportFacets()
{
assert(m_app);
if (!m_app)
return;
//disclaimer accepted?
if (!ShowDisclaimer(m_app))
return;
//Retrive selected facets
FacetSet facets;
getFacetsInCurrentSelection(facets);
if (facets.empty())
{
m_app->dispToConsole("Couldn't find any facet in the current selection!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
assert(!facets.empty());
FacetsExportDlg fDlg(FacetsExportDlg::SHAPE_FILE_IO,m_app->getMainWindow());
//persistent settings (default export path)
QSettings settings;
settings.beginGroup("qFacets");
QString facetsSavePath = settings.value("exportPath",QApplication::applicationDirPath()).toString();
fDlg.destinationPathLineEdit->setText(facetsSavePath + QString("/facets.shp"));
if (!fDlg.exec())
return;
QString filename = fDlg.destinationPathLineEdit->text();
//save current export path to persistent settings
settings.setValue("exportPath",QFileInfo(filename).absolutePath());
if (QFile(filename).exists())
{
//if the file already exists, ask for confirmation!
if (QMessageBox::warning(m_app->getMainWindow(),"File already exists!","File already exists! Are you sure you want to overwrite it?",QMessageBox::Yes,QMessageBox::No) == QMessageBox::No)
return;
}
//fields (shapefile) - WARNING names must not have more than 10 chars!
ShpFilter::IntegerField facetIndex("index");
ShpFilter::DoubleField facetSurface("surface");
ShpFilter::DoubleField facetRMS("rms");
ShpFilter::IntegerField facetDipDir("dip_dir");
ShpFilter::IntegerField facetDip("dip");
ShpFilter::IntegerField familyIndex("family_ind");
ShpFilter::IntegerField subfamilyIndex("subfam_ind");
ShpFilter::DoubleField3D facetNormal("normal");
ShpFilter::DoubleField3D facetBarycenter("center");
ShpFilter::DoubleField horizExtension("horiz_ext");
ShpFilter::DoubleField vertExtension("vert_ext");
ShpFilter::DoubleField surfaceExtension("surf_ext");
size_t facetCount = facets.size();
assert(facetCount != 0);
try
{
facetIndex.values.reserve(facetCount);
facetSurface.values.reserve(facetCount);
facetRMS.values.reserve(facetCount);
facetDipDir.values.reserve(facetCount);
facetDip.values.reserve(facetCount);
familyIndex.values.reserve(facetCount);
subfamilyIndex.values.reserve(facetCount);
facetNormal.values.reserve(facetCount);
facetBarycenter.values.reserve(facetCount);
horizExtension.values.reserve(facetCount);
vertExtension.values.reserve(facetCount);
surfaceExtension.values.reserve(facetCount);
}
catch (const std::bad_alloc&)
{
m_app->dispToConsole("Not enough memory!",ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
ccHObject toSave("facets");
//depending on the 'main orientation', the job is more or less easy ;)
bool useNativeOrientation = fDlg.nativeOriRadioButton->isChecked();
bool useGlobalOrientation = fDlg.verticalOriRadioButton->isChecked();
bool useCustomOrientation = fDlg.customOriRadioButton->isChecked();
//Default base
CCVector3 X(1,0,0), Y(0,1,0), Z(0,0,1);
//'vertical' orientation (potentially specified by the user)
if (!useNativeOrientation)
{
if (useCustomOrientation)
{
Z = CCVector3( static_cast<PointCoordinateType>(fDlg.nXLineEdit->text().toDouble()),
static_cast<PointCoordinateType>(fDlg.nYLineEdit->text().toDouble()),
static_cast<PointCoordinateType>(fDlg.nZLineEdit->text().toDouble()) );
Z.normalize();
//.........这里部分代码省略.........
示例11: 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()));
}
}
示例12: 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!");
}
}
}