介绍
CloudCompare是一款开源的点云处理软件,其功能包括:
- 点云滤波
- 采样
- 三角化
- 基元拟合
- 点云分割
- 法线计算
等等。
除了包含以上已有的功能外,CloudCompare(下文简称CC)还提供了插件接口,供用户任意添加自己的功能接口。本篇文章主要介绍CC的插件使用。
源码编译
编译环境
- VS2015企业版
- CloudCompare 2.10.2
- CMake 3.12.0
编译过程
1.打开CMake,根据下图所示设置对应目录;
2.点击Configure按钮,配置cmake工程
3.根据下图所示选择Visual Studio 14 2015 Win64编译器
4.勾选INSTALL_EXAMPLE_PLUGIN,该选项是用来开启插件模板编译的
5.修改安装目录
6.再次点击Configure,直至没有红色区域
7.点击Generate按钮,生成VS工程
8.在编译目录中打开VS项目CloudCompareProjects.sln
9.将工程ExamplePlugin中的ExamplePlugin.cpp替换为如下代码:
//##########################################################################
//# #
//# CLOUDCOMPARE PLUGIN: ExamplePlugin #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: XXX #
//# #
//##########################################################################
// First:
// Replace all occurrences of 'ExamplePlugin' by your own plugin class name in this file.
// This includes the resource path to info.json in the constructor.
// Second:
// Open ExamplePlugin.qrc, change the "prefix" and the icon filename for your plugin.
// Change the name of the file to <yourPluginName>.qrc
// Third:
// Open the info.json file and fill in the information about the plugin.
// "type" should be one of: "Standard", "GL", or "I/O" (required)
// "name" is the name of the plugin (required)
// "icon" is the Qt resource path to the plugin's icon (from the .qrc file)
// "description" is used as a tootip if the plugin has actions and is displayed in the plugin dialog
// "authors", "maintainers", and "references" show up in the plugin dialog as well
#include <QtGui>
#include<ccPointCloud.h>
#include "ExamplePlugin.h"
// Default constructor:
// - pass the Qt resource path to the info.json file (from <yourPluginName>.qrc file)
// - constructor should mainly be used to initialize actions and other members
ExamplePlugin::ExamplePlugin( QObject *parent )
: QObject( parent )
, ccStdPluginInterface( ":/CC/plugin/ExamplePlugin/info.json" )
, m_action( nullptr )
{
}
// This method should enable or disable your plugin actions
// depending on the currently selected entities ('selectedEntities').
void ExamplePlugin::onNewSelection( const ccHObject::Container &selectedEntities )
{
if ( m_action == nullptr )
{
return;
}
// If you need to check for a specific type of object, you can use the methods
// in ccHObjectCaster.h or loop and check the objects' classIDs like this:
//
// for ( ccHObject *object : selectedEntities )
// {
// if ( object->getClassID() == CC_TYPES::VIEWPORT_2D_OBJECT )
// {
// // ... do something with the viewports
// }
// }
// For example - only enable our action if something is selected.
m_action->setEnabled( !selectedEntities.empty() );
}
// This method returns all the 'actions' your plugin can perform.
// getActions() will be called only once, when plugin is loaded.
QList<QAction *> ExamplePlugin::getActions()
{
// default action (if it has not been already created, this is the moment to do it)
if ( !m_action )
{
// Here we use the default plugin name, description, and icon,
// but each action should have its own.
m_action = new QAction( getName(), this );
m_action->setToolTip( getDescription() );
m_action->setIcon( getIcon() );
// Connect appropriate signal
connect( m_action, &QAction::triggered, this, &ExamplePlugin::doAction );
}
return { m_action };
}
// 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 'm_app' variable (see the ccMainAppInterface
// class in ccMainAppInterface.h).
void ExamplePlugin::doAction()
{
if ( m_app == nullptr )
{
// m_app should have already been initialized by CC when plugin is loaded
Q_ASSERT( false );
return;
}
/*** HERE STARTS THE ACTION ***/
/*********************************插入代码*****************************************/
// 在这里插入需要的操作
const ccHObject::Container& selected_objs = m_app->getSelectedEntities();// 获取选择的点云
if (selected_objs.size() != 1)
{
m_app->dispToConsole("Please select one cloud!", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
ccHObject* ent = selected_objs[0];
assert(ent);
if (!ent || !ent->isA(CC_TYPES::POINT_CLOUD))//判断所选的对象是否为点云
{
m_app->dispToConsole("Please select one cloud!", ccMainAppInterface::ERR_CONSOLE_MESSAGE);
return;
}
// 插件功能:把选择的点云的x坐标增加100
ccPointCloud* pc = static_cast<ccPointCloud*>(ent);
ccPointCloud* pc_new = new ccPointCloud("new cc");
for (int i = 0; i < pc->size(); ++i)
{
pc_new->addPoint(CCVector3(pc->getPoint(i)->x+100,pc->getPoint(i)->y,pc->getPoint(i)->z));
}
ccHObject* cc_containers = new ccHObject("new-cc");
cc_containers->addChild(pc_new);
m_app->addToDB(cc_containers, true, true);
m_app->refreshAll();
/*********************************插入代码*****************************************/
// This is how you can output messages
// Display a standard message in the console
m_app->dispToConsole( "[ExamplePlugin] plugin run successfully!", ccMainAppInterface::STD_CONSOLE_MESSAGE );
Display a warning message in the console
//m_app->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
//m_app->dispToConsole( "Example plugin shouldn't be used - it doesn't do anything!", ccMainAppInterface::ERR_CONSOLE_MESSAGE );
/*** HERE ENDS THE ACTION ***/
}
效果如下:
10.编译ALL_BUILD工程;
11.编译INSTALL工程
12.在安装目录中打开CloudCompare.exe
13.效果
