[CC]平面拟合

MainWindow中的平面拟合方法,调用了ccPlane的Fit方法。

  1 void MainWindow::doActionFitPlane()
  2 {
  3     doComputePlaneOrientation(false);
  4 }
  5
  6 void MainWindow::doActionFitFacet()
  7 {
  8     doComputePlaneOrientation(true);
  9 }
 10
 11 static double s_polygonMaxEdgeLength = 0;
 12 void MainWindow::doComputePlaneOrientation(bool fitFacet)
 13 {
 14     ccHObject::Container selectedEntities = m_selectedEntities;
 15     size_t selNum = selectedEntities.size();
 16     if (selNum < 1)
 17         return;
 18
 19     double maxEdgeLength = 0;
 20     if (fitFacet)
 21     {
 22         bool ok = true;
 23         maxEdgeLength = QInputDialog::getDouble(this,"Fit facet", "Max edge length (0 = no limit)", s_polygonMaxEdgeLength, 0, 1.0e9, 8, &ok);
 24         if (!ok)
 25             return;
 26         s_polygonMaxEdgeLength = maxEdgeLength;
 27     }
 28
 29     for (size_t i=0; i<selNum; ++i)
 30     {
 31         ccHObject* ent = selectedEntities[i];
 32         ccShiftedObject* shifted = 0;
 33         CCLib::GenericIndexedCloudPersist* cloud = 0;
 34
 35         if (ent->isKindOf(CC_TYPES::POLY_LINE))
 36         {
 37             ccPolyline* poly = ccHObjectCaster::ToPolyline(ent);
 38             cloud = static_cast<CCLib::GenericIndexedCloudPersist*>(poly);
 39             shifted = poly;
 40         }
 41         else
 42         {
 43             ccGenericPointCloud* gencloud = ccHObjectCaster::ToGenericPointCloud(ent);
 44             if (gencloud)
 45             {
 46                 cloud = static_cast<CCLib::GenericIndexedCloudPersist*>(gencloud);
 47                 shifted = gencloud;
 48             }
 49         }
 50
 51         if (cloud)
 52         {
 53             double rms = 0.0;
 54             CCVector3 C,N;
 55
 56             ccHObject* plane = 0;
 57             if (fitFacet)
 58             {
 59                 ccFacet* facet = ccFacet::Create(cloud, static_cast<PointCoordinateType>(maxEdgeLength));
 60                 if (facet)
 61                 {
 62                     plane = static_cast<ccHObject*>(facet);
 63                     N = facet->getNormal();
 64                     C = facet->getCenter();
 65                     rms = facet->getRMS();
 66
 67                     //manually copy shift & scale info!
 68                     if (shifted)
 69                     {
 70                         ccPolyline* contour = facet->getContour();
 71                         if (contour)
 72                         {
 73                             contour->setGlobalScale(shifted->getGlobalScale());
 74                             contour->setGlobalShift(shifted->getGlobalShift());
 75                         }
 76                     }
 77                 }
 78             }
 79             else
 80             {
 81                 ccPlane* pPlane = ccPlane::Fit(cloud, &rms);
 82                 if (pPlane)
 83                 {
 84                     plane = static_cast<ccHObject*>(pPlane);
 85                     N = pPlane->getNormal();
 86                     C = *CCLib::Neighbourhood(cloud).getGravityCenter();
 87                     pPlane->enableStippling(true);
 88                 }
 89             }
 90
 91             //as all information appears in Console...
 92             forceConsoleDisplay();
 93
 94             if (plane)
 95             {
 96                 ccConsole::Print(QString("[Orientation] Entity ‘%1‘").arg(ent->getName()));
 97                 ccConsole::Print("\t- plane fitting RMS: %f",rms);
 98
 99                 //We always consider the normal with a positive ‘Z‘ by default!
100                 if (N.z < 0.0)
101                     N *= -1.0;
102                 ccConsole::Print("\t- normal: (%f,%f,%f)",N.x,N.y,N.z);
103
104                 //we compute strike & dip by the way
105                 PointCoordinateType dip = 0, dipDir = 0;
106                 ccNormalVectors::ConvertNormalToDipAndDipDir(N,dip,dipDir);
107                 QString dipAndDipDirStr = ccNormalVectors::ConvertDipAndDipDirToString(dip,dipDir);
108                 ccConsole::Print(QString("\t- %1").arg(dipAndDipDirStr));
109
110                 //hack: output the transformation matrix that would make this normal points towards +Z
111                 ccGLMatrix makeZPosMatrix = ccGLMatrix::FromToRotation(N,CCVector3(0,0,PC_ONE));
112                 CCVector3 Gt = C;
113                 makeZPosMatrix.applyRotation(Gt);
114                 makeZPosMatrix.setTranslation(C-Gt);
115                 ccConsole::Print("[Orientation] A matrix that would make this plane horizontal (normal towards Z+) is:");
116                 ccConsole::Print(makeZPosMatrix.toString(12,‘ ‘)); //full precision
117                 ccConsole::Print("[Orientation] You can copy this matrix values (CTRL+C) and paste them in the ‘Apply transformation tool‘ dialog");
118
119                 plane->setName(dipAndDipDirStr);
120                 plane->applyGLTransformation_recursive(); //not yet in DB
121                 plane->setVisible(true);
122                 plane->setSelectionBehavior(ccHObject::SELECTION_FIT_BBOX);
123
124                 ent->addChild(plane);
125                 plane->setDisplay(ent->getDisplay());
126                 plane->prepareDisplayForRefresh_recursive();
127                 addToDB(plane);
128             }
129             else
130             {
131                 ccConsole::Warning(QString("Failed to fit a plane/facet on entity ‘%1‘").arg(ent->getName()));
132             }
133         }
134     }
135
136     refreshAll();
137     updateUI();
138 }
时间: 2024-07-29 05:07:56

[CC]平面拟合的相关文章

蛙蛙推荐: TensorFlow Hello World 之平面拟合

tensorflow 已经发布了 2.0 alpha 版本,所以是时候学一波 tf 了.官方教程有个平面拟合的类似Hello World的例子,但没什么解释,新手理解起来比较困难. 所以本文对这个案例进行详细解释,对关键的numpy, tf, matplotlib 函数加了注释,并且对原始数据和训练效果进行了可视化展示,希望对你理解这个案例有所帮助. 因为 2.0 成熟还需要一段时间,所以本文使用的是 tf 1.13.1 版本,Python 代码也从 Python 2 迁移到了 Python 3

使用matlab进行空间拟合

假设有这么一组数据, x=[4 5 6 7 8 4 8 10]'; y=[56 56 56 56 56 60 60 60]';z=[6 6 6 9 6 19 6 6]'; 要求出其平面方程z=C+Ax+By 可以使用MATLAB的regress来进行平面拟合: X = [ones(size(x,1),1) x y];b = regress(z,X); 解得:b=[-63.488372093023390;-1.406976744186046;1.402325581395351]; 分别对应上式的C

激光雷达联合标定

目录 一.联合标定的由来 二.标定方法 (A)联合标定发展史 (B)细说线性标定 三. 参考文献 好久没认真写博客了,动起手有点生疏,markdown都不会用了...哈哈...废话不说了,之后有时间专门写一篇从学生到工作的记录. 一.联合标定的由来 ? 本文介绍激光雷达和相机的联合标定,至于为什么要进行标定,简单的说就是:激光代表深度,图像代表细节.举个例子:假如对面行驶过来一辆车,单目相机只能判断那是一辆汽车,双目相机可以判断那是一辆汽车并且知道大概的位置信息.既然双目可以知道距离和三维重建,

简单的线性回归问题-TensorFlow+MATLAB&#183;

首先我们要试验的是 人体脂肪fat和年龄age以及体重weight之间的关系,我们的目标就是得到一个最优化的平面来表示三者之间的关系: TensorFlow的程序如下: import tensorflow as tf import numpy as np import matplotlib.pyplot as plt W = tf.Variable(tf.zeros([2, 1], name="weight_age")) b = tf.Variable(0.0, name="

梯度下降法与牛顿下降法速度的比较

"牛顿下降法和梯度下降法在机器学习和自适应滤波中都很重要,本质上是为了寻找极值点的位置.但是收敛的速度不同. 本文中就两种方法来探究一下,哪种收敛方法速度快" 牛顿下降法的递推公式: xn+1=xn?f′(xn)/f′′(xn) 梯度下降算法的递推公式: xn+1=xn?μ?f′(xn) 解释一 下图是两种方法的图示表示,红色为牛顿下降法,绿色为梯度下降法,从图中直观的感觉是,红色线短,下降速度快.因为牛顿下降法是用二次曲面去拟合当前的局部曲面,而梯度下降法是用平面去拟合当前的局部曲面

RANSAC算法笔记

最近在做平面拟合,待处理的数据中有部分噪点需要去除,很多论文中提到可以使用Ransac方法来去除噪点. 之前在做图像配准时,用到了Ransac算法,但是没有去仔细研究,现在好好研究一番. 参考: http://download.csdn.net/detail/tuoxie2046/6012333#comment http://grunt1223.iteye.com/blog/961063 http://www.cnblogs.com/tiandsp/archive/2013/06/03/3115

人人都可以做深度学习应用:入门篇

一.人工智能和新科技革命 2017年围棋界发生了一件比较重要事,Master(Alphago)以60连胜横扫天下,击败各路世界冠军,人工智能以气势如虹的姿态出现在我们人类的面前.围棋曾经一度被称为"人类智慧的堡垒",如今,这座堡垒也随之成为过去.从2016年三月份AlphaGo击败李世石开始,AI全面进入我们大众的视野,对于它的讨论变得更为火热起来,整个业界普遍认为,它很可能带来下一次科技革命,并且,在未来可预见的10多年里,深刻得改变我们的生活. 其实,AI除了可以做我们熟知的人脸.

人人都能够做深度学习应用:入门篇

一.人工智能和新科技革命 2017年围棋界发生了一件比較重要事,Master(Alphago)以60连胜横扫天下,击败各路世界冠军.人工智能以气势如虹的姿态出现在我们人类的面前.围棋以前一度被称为"人类智慧的堡垒",现在.这座堡垒也随之成为过去.从2016年三月份AlphaGo击败李世石開始,AI全面进入我们大众的视野,对于它的讨论变得更为火热起来.整个业界普遍觉得,它非常可能带来下一次科技革命,而且,在未来可预见的10多年里,深刻得改变我们的生活. 事实上.AI除了能够做我们熟知的人

Overfitting and Its Avoidance【总结】

主要内容: Overfitting(问题) 判断和防止overfitting 的方式 ------------------------------------ 过度拟合的模型往往不能进行一般化推广(generalization) 拟合问题需要在两个方面进行权衡 需要注意的是 如果用来训练的数据和测试的数据是同样的,那么这样的检验是没有意义的,就像  "Table Model" 一样 一般我们会将数据集分为training/testing(holdout) 两个部分  注: 在pytho