前面博客介绍了CloudCompare的配置,它提供了现成的功能强大的UI界面,且也有各种点云算法,所以对于软件工程开发人员,点云算法处理人员来说,这都是值得去参考和复用的。所以这篇博客简单的介绍下,如何使用插件机制来做二次开发,如何结合其它的一些点云库联合开发。CloudCompare的配置见博主之前的博客
CloudCompare配置介绍_cloudcompare二次开发_竹叶青lvye的博客-CSDN博客
一.自带例子参考
可参考ExamplePlugin工程,如下是将该dll的输出路径修改为CloudCompare编译生成的目录下的plugins文件夹里,方便进行调试。
修改Action.cpp文件,如下画线处语句是自己添加的
再运行CloudCompare软件后,点击plugins里的Examples选项,可以看到输出了刚才的新加的output信息。
若打断点的话,可以看到,先进入如下
后面才会进入
二.在ExamplePlugin例子基础上改写
实现小功能:只保留到重心距离满足一定范围内的点云,其它点云被去除掉了。只需要修改ActionA.cpp中的代码,里面也稍微加了些注释,如下:
// Example of a plugin action
#include "ccMainAppInterface.h"
#include
#include "qinputdialog.h"
#include
#include "ExamplePlugin.h"
namespace Example
{
// This is an example of an action's method called when the corresponding action
// is triggered (i.e. the corresponding icon or menu entry is clicked in CC's
// main interface). You can access most of CC's components (database,
// 3D views, console, etc.) via the 'appInterface' variable.
void performActionA( ccMainAppInterface *appInterface )
{
if ( appInterface == nullptr )
{
// The application interface should have already been initialized when the plugin is loaded
Q_ASSERT( false );
return;
}
/*** HERE STARTS THE ACTION ***/
// 1.获取所选点云
ccPointCloud* cloud;
const ccHObject::Container& selectedEntities = appInterface->getSelectedEntities();
if (selectedEntities.size() != 1)
{
appInterface->dispToConsole("[ExamplePlugin] selectedEntities.size() != 1", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
ccHObject* entity = selectedEntities[0];
if (entity->isA(CC_TYPES::POINT_CLOUD))
{
cloud = static_cast(entity);
}
else
{
appInterface->dispToConsole("[ExamplePlugin] is not a CC_TYPES::POINT_CLOUD", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
QElapsedTimer eTimer; // 统计时间
eTimer.start();
//CCVector3 bbmin, bbmax;
//cloud->getBoundingBox(bbmin, bbmax); // 获取边界框
//float th = (bbmin[2] + bbmax[2]) / 2; // 设定阈值
//获取点云的重心
CCVector3 center = cloud->computeGravityCenter();
bool isOK;
float range = QInputDialog::getDouble(nullptr, "set param", "limit_distance: ", 1, -10000, 10000, 2, &isOK);
if (!isOK)
{
ccLog::Print("has cancled!");;
return;
}
// 2.遍历点云坐标
CCCoreLib::ReferenceCloud sampledIndex(cloud);
for (size_t i = 0; i < cloud->size(); ++i)
{
double Lx = cloud->getPoint(i)->x - center.x;
double Ly = cloud->getPoint(i)->y - center.y;
double Lz = cloud->getPoint(i)->z - center.z;
double distance = sqrt(Lx * Lx + Ly * Ly + Lz * Lz);
if (distance < range)
{
sampledIndex.addPointIndex(i); // 取范围内的值
}
}
ccLog::Print("[ElevationPointsPlugin] Timing: %3.3f s.", eTimer.elapsed() / 1000.0);
// 3.根据索引提取生成新的点云
int warnings = 0;
ccPointCloud* newPointCloud = cloud->partialClone(&sampledIndex, &warnings);
if (warnings)
{
ccLog::Warning("[ElevationPointsPlugin] Not enough memory: colors, normals or scalar fields may be missing!");
}
if (newPointCloud)
{
newPointCloud->setName(cloud->getName() + QString(".ElevationPointsPlugin"));
newPointCloud->setGlobalShift(cloud->getGlobalShift());
newPointCloud->setGlobalScale(cloud->getGlobalScale());
newPointCloud->setDisplay(cloud->getDisplay());
newPointCloud->setColor(ccColor::blue);
newPointCloud->showColors(true);
newPointCloud->setPointSize(3);
newPointCloud->prepareDisplayForRefresh();
if (cloud->getParent())
cloud->getParent()->addChild(newPointCloud);
//cloud->setEnabled(false);
appInterface->addToDB(newPointCloud);
newPointCloud->prepareDisplayForRefresh();
}
cloud->setColor(ccColor::green);
cloud->showColors(true);
cloud->prepareDisplayForRefresh();
// 4.结尾 Hello world!
// Put your code here
// --> you may want to start by asking for parameters (with a custom dialog, etc.)
// This is how you can output messages
// Display a standard message in the console
appInterface->dispToConsole( "[ExamplePlugin] Hello world!", ccMainAppInterface::STD_CONSOLE_MESSAGE );
appInterface->dispToConsole("[ExamplePlugin] my first info!", ccMainAppInterface::STD_CONSOLE_MESSAGE);
// Display a warning message in the console
appInterface->dispToConsole( "[ExamplePlugin] Warning: example plugin shouldn't be used as is", ccMainAppInterface::WRN_CONSOLE_MESSAGE );
// Display an error message in the console AND pop-up an error box
appInterface->dispToConsole( "Example plugin shouldn't be used - it doesn't do anything!", ccMainAppInterface::ERR_CONSOLE_MESSAGE );
/*** HERE ENDS THE ACTION ***/
}
}
运行CloudCompare工程
在出来的程序中,选择自定义的插件
参数设置5,效果如下:
图中蓝色的点云即为满足要球的点云。
三. 调试简单说明
比如我想调试如下功能中点选2点的功能
那就打开mainWindows.ui
找到对应的槽函数,开始调试
可看见这边会去创建一个ccPointPropertiesDlg类
这个类的设计界面如下
这样就可以一步一步调试下去。注意后面会用到cc2DLabel类,这个类是在QCC_DB_LIB,为了调试,需要更改它的工程路径,修改为CloudCompare编译生成的目录。博主的路径如下:
其它就是花时间和精力慢慢去啃源代码了,不在赘叙了。
四. 结合PCL库做插件开发
可以借鉴QPCL_PLUGIN例子,好东西就是会提供一些sample例子,供参考自由发挥,确实很好。
这边继续在ExamplePlugin例子基础上做改写,把PCL的包含目录加上
添加pcl的lib库路径
添加PCL的lib库名
D:\CloudCompare\CloudCompare-2.12.3\build\plugins\core\Standard\qPCL\PclUtils\Debug\QPCL_PLUGIN_UTILS_LIBd.lib
..\..\..\libs\CCPluginAPI\Debug\CCPluginAPId.lib
..\..\..\libs\CCPluginStub\Debug\CCPluginStubd.lib
..\..\..\libs\qCC_glWindow\Debug\QCC_GL_LIBd.lib
..\..\..\libs\qCC_io\Debug\QCC_IO_LIBd.lib
..\..\..\libs\qCC_io\extern\dxflib\Debug\dxflibd.lib
..\..\..\libs\qCC_io\extern\shapelib\Debug\shapelibd.lib
..\..\..\libs\qCC_db\Debug\QCC_DB_LIBd.lib
..\..\..\libs\qCC_db\extern\CCCoreLib\Debug\CCCoreLibd.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Concurrentd.lib
..\..\..\libs\CCFbo\Debug\CC_FBO_LIBd.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5OpenGLd.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Widgetsd.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5OpenGLExtensionsd.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Guid.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\Qt5Cored.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\\Qt5Guid.lib
C:\Qt\Qt5.14.2\5.14.2\msvc2017_64\lib\\Qt5Cored.lib
C:\Program Files\PCL 1.9.0\lib\pcl_surface_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_keypoints_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_tracking_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_recognition_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_registration_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_stereo_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_outofcore_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_people_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_segmentation_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_features_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_filters_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_sample_consensus_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_ml_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_visualization_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_search_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_kdtree_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_io_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_octree_debug.lib
C:\Program Files\PCL 1.9.0\lib\pcl_common_debug.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_system-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_filesystem-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_thread-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_date_time-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_iostreams-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_serialization-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_chrono-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_atomic-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Boost\lib\libboost_regex-vc141-mt-gd-x64-1_68.lib
C:\Program Files\PCL 1.9.0\3rdParty\Qhull\lib\qhullstatic_d.lib
C:\Program Files\PCL 1.9.0\3rdParty\Lib\OpenNI2.lib
C:\Program Files\PCL 1.9.0\3rdParty\FLANN\lib\flann_cpp_s-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkDomainsChemistry-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersFlowPaths-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersGeneric-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersHyperTree-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersParallelImaging-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersPoints-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersProgrammable-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersSMP-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersSelection-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersTexture-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersTopology-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersVerdict-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkverdict-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkGeovisCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkproj4-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOAMR-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersAMR-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOEnSight-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOExodus-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOExportOpenGL-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOExport-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingGL2PS-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingContextOpenGL-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkgl2ps-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtklibharu-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOImport-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOInfovis-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtklibxml2-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOLSDyna-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOMINC-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOMovie-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkoggtheora-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOPLY-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOParallel-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersParallel-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkexoIIc-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOGeometry-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIONetCDF-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtknetcdfcpp-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkNetCDF-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkhdf5_hl-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkhdf5-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkjsoncpp-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOParallelXML-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkParallelCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOSQL-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtksqlite-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOTecplotTable-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOVideo-8.1-gd.lib
vfw32.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingMath-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingMorphological-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingStatistics-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingStencil-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkInteractionImage-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingImage-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingLIC-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOLegacy-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingLOD-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingVolumeOpenGL-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingOpenGL-8.1-gd.lib
opengl32.lib
glu32.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkViewsContext2D-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkViewsInfovis-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkChartsCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingContext2D-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersImaging-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkInfovisLayout-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkInfovisCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkViewsCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkInteractionWidgets-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersHybrid-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingGeneral-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingSources-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersModeling-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingHybrid-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOImage-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkDICOMParser-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkmetaio-8.1-gd.lib
comctl32.lib
wsock32.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkpng-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtktiff-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkjpeg-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkInteractionStyle-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersExtraction-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersStatistics-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingFourier-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkalglib-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingAnnotation-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingColor-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingVolume-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkImagingCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOXML-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOXMLParser-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkIOCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtklz4-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkexpat-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingLabel-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingFreeType-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkRenderingCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonColor-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersGeometry-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersSources-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersGeneral-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonComputationalGeometry-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkFiltersCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonExecutionModel-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonDataModel-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonMisc-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonSystem-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonTransforms-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonMath-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkCommonCore-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtksys-8.1-gd.lib
ws2_32.lib
Psapi.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkfreetype-8.1-gd.lib
C:\Program Files\PCL 1.9.0\3rdParty\VTK\lib\vtkzlib-8.1-gd.lib
kernel32.lib
user32.lib
gdi32.lib
winspool.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
comdlg32.lib
advapi32.lib
Action.cpp中的代码如下(先将cc点云转换为pcl表示,然后对pcl点云进行抽样,再将获得的点云数据转换到cc点云):
// Example of a plugin action
#include "ccMainAppInterface.h"
#include
#include "qinputdialog.h"
#include
#include "ExamplePlugin.h"
//PCL
#include
#include "../../../core/Standard/qPCL/PclUtils/utils/PCLConv.h"
#include "../../../core/Standard/qPCL/PclUtils/utils/cc2sm.h"
#include "../../../core/Standard/qPCL/PclUtils/utils/sm2cc.h"
#include // 均匀采样
using namespace pcl;
namespace Example
{
// This is an example of an action's method called when the corresponding action
// is triggered (i.e. the corresponding icon or menu entry is clicked in CC's
// main interface). You can access most of CC's components (database,
// 3D views, console, etc.) via the 'appInterface' variable.
void performActionA( ccMainAppInterface *appInterface )
{
if ( appInterface == nullptr )
{
// The application interface should have already been initialized when the plugin is loaded
Q_ASSERT( false );
return;
}
/*** HERE STARTS THE ACTION ***/
// 1.获取所选点云
ccPointCloud* cloud;
const ccHObject::Container& selectedEntities = appInterface->getSelectedEntities();
if (selectedEntities.size() != 1)
{
appInterface->dispToConsole("[ExamplePlugin] selectedEntities.size() != 1", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
ccHObject* entity = selectedEntities[0];
if (entity->isA(CC_TYPES::POINT_CLOUD))
{
cloud = static_cast(entity);
}
else
{
appInterface->dispToConsole("[ExamplePlugin] is not a CC_TYPES::POINT_CLOUD", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
QElapsedTimer eTimer; // 统计时间
eTimer.start();
//CCVector3 bbmin, bbmax;
//cloud->getBoundingBox(bbmin, bbmax); // 获取边界框
//float th = (bbmin[2] + bbmax[2]) / 2; // 设定阈值
//get xyz as a PCL cloud
pcl::PointCloud::Ptr pclCloud = cc2smReader(cloud).getRawXYZ();
if (!pclCloud)
{
ccLog::Error("cc to pcl fail");
}
bool isOK;
float radius = QInputDialog::getDouble(nullptr, "set param", "radius: ", 0.5, 0, 100, 2, &isOK);
if (!isOK)
{
ccLog::Print("has cancled!");;
return;
}
pcl::PointCloud::Ptr filtered(new pcl::PointCloud);
pcl::UniformSampling us;
us.setInputCloud(pclCloud);
us.setRadiusSearch(radius);
us.filter(*filtered);
if (!filtered->empty())
{
//不为空
ccPointCloud* newccCloud = new ccPointCloud("UniformSample");
PCLCloud::Ptr PCLcloud(new PCLCloud);
TO_PCL_CLOUD(*filtered, *PCLcloud);
pcl2cc::CopyXYZ(*PCLcloud, *newccCloud, PCLPointField::FLOAT32);
newccCloud->setGlobalShift(cloud->getGlobalShift());
newccCloud->setGlobalScale(cloud->getGlobalScale());
newccCloud->setDisplay(cloud->getDisplay());
newccCloud->setColor(ccColor::blue);
newccCloud->showColors(true);
newccCloud->setPointSize(3);
newccCloud->prepareDisplayForRefresh();
if (cloud->getParent())
cloud->getParent()->addChild(newccCloud);
cloud->setEnabled(false);
appInterface->addToDB(newccCloud);
newccCloud->prepareDisplayForRefresh();
}
else
{
//为空
ccLog::Print("after filter, the cloud is has no point");
}
//cloud->setColor(ccColor::green);
//cloud->showColors(true);
//cloud->prepareDisplayForRefresh();
// 4.结尾 Hello world!
// Put your code here
// --> you may want to start by asking for parameters (with a custom dialog, etc.)
// This is how you can output messages
// Display a standard message in the console
appInterface->dispToConsole( "[ExamplePlugin] Hello world!", ccMainAppInterface::STD_CONSOLE_MESSAGE );
appInterface->dispToConsole("[ExamplePlugin] my first info!", ccMainAppInterface::STD_CONSOLE_MESSAGE);
// Display a warning message in the console
appInterface->dispToConsole( "[ExamplePlugin] Warning: example plugin shouldn't be used as is", ccMainAppInterface::WRN_CONSOLE_MESSAGE );
// Display an error message in the console AND pop-up an error box
appInterface->dispToConsole( "Example plugin shouldn't be used - it doesn't do anything!", ccMainAppInterface::ERR_CONSOLE_MESSAGE );
/*** HERE ENDS THE ACTION ***/
}
}
注意下pcl和cc点云互转的代码,这里部分其实借用了工程QPCL_PLUGIN中的代码
再次执行CloudCompare工程,效果如下:
精力有限,接下来博主打算做一些基于点云的深度学习方面的小实验。