一、cmake 构建 cloudcompare工程
- 打开cmake GUI 设置源代码和输出文件路径
点击configure后,设置相应配置: - 设置QT安装路径
- 选择所需插件
再次点击Configure 无误后,再点击Generate即可
但是由于部分插件需要一些依赖库需自行下载,如
在配置时同样需设置好相应的文件路径
打开工程即完成即可进行编译
二、添加自己的插件
我们希望在右边工具栏加入自己的插件
- 在源代码路径\CloudCompare-master\plugins\core\Standard\下新建一个文件夹 TestPlugin
- 在TestPlugin文件夹下新建五个空文件
- TestPlugin.h里内容如下
#ifndef TestPlugin_PLUGIN_HEADER
#define TestPlugin_PLUGIN_HEADER
#include "ccStdPluginInterface.h"
class TestPlugin : public QObject, public ccStdPluginInterface
{
Q_OBJECT
Q_INTERFACES(ccStdPluginInterface)
Q_PLUGIN_METADATA(IID "cccorp.cloudcompare.plugin.TestPlugin" FILE "info.json")
public:
//! Default constructor
explicit TestPlugin(QObject* parent = nullptr);
virtual ~TestPlugin() = default;
//inherited from ccStdPluginInterface
virtual void onNewSelection(const ccHObject::Container& selectedEntities) override;
virtual QList<QAction *> getActions() override;
protected slots:
//! Slot called when associated ation is triggered
void doAction();
protected:
//! Associated action
QAction* m_action;
};
#endif //TestPlugin_PLUGIN_HEADER
TestPlugin.cpp里内容如下
#include "TestPlugin.h"
//qCC_db
#include <ccPointCloud.h>
//Qt
#include <QMainWindow>
#include <QProgressDialog>
//system
#include <assert.h>
TestPlugin::TestPlugin(QObject* parent)
: QObject(parent)
, ccStdPluginInterface( ":/CC/plugin/TestPlugin/info.json" )
, m_action( nullptr )
{
}
void TestPlugin::onNewSelection(const ccHObject::Container& selectedEntities)
{
//此处设置是否需要有点云时激活插件
if (m_action)
{
for (ccHObject* entity : selectedEntities)
{
//if we have found at least one cloud
if (entity && entity->isA(CC_TYPES::POINT_CLOUD))
{
m_action->setEnabled(true);
return;
}
}
//no cloud?
m_action->setEnabled(true);// 为True则不需要点云也可以激活插件,为false则需要点云才可以激活插件
}
}
QList<QAction *> TestPlugin::getActions()
{
//default action
if (!m_action)
{
m_action = new QAction(getName(),this);
m_action->setToolTip(getDescription());
m_action->setIcon(getIcon());
//connect signal
connect(m_action, &QAction::triggered, this, &TestPlugin::doAction);
}
return QList<QAction *>{ m_action };
}
//persistent settings during a single session
// CoamingMeasurmentDialog::Parameters s_params;
void TestPlugin::doAction()
{
ccLog::LogMessage("hello",1);//这里设置TestPlugin点击一下,日志栏输出hello字样
//currently selected entities parameters may have changed!
m_app->updateUI();
//currently selected entities appearance may have changed!
m_app->refreshAll();
}
- TestPlugin.qrc里内容如下,这是QT资源文件添加了两个资源(images/TestPlugin.png)和(info.json),因此需把这两个资源补齐
<RCC>
<qresource prefix="/CC/plugin/TestPlugin" >
<file>images/TestPlugin.png</file>
<file>info.json</file>
</qresource>
</RCC>
- 在TestPlugin目录下在新建一个目录images,并在目录下放置一个TestPlugin.PNG文件,这个图片就是插件的图标
- info.json内容如下,这是插件的信息描述,在对应模板处填写相应信息即可
{
"type" : "Standard",
"core" : true,
"name" : "TestPlugin",
"icon" : ":/CC/plugin/TestPlugin/images/TestPlugin.png",
"description": "",
"authors" : [
{
"name" : "",
"email" : ""
}
],
"maintainers" : [
{
"name" : "",
"email" : ""
}
],
"references" : [
{
"text": "\" \"<br/>
Talk by Alexandre Boulch & Renaud Marlet at the Symposium of Geometry Processing, 2016",
"url" : ""
},
{
"text": "TestPlugin library",
"url": ""
},
{
"text": "Documentation",
"url": ""
}
]
}
- CMakeLists.txt内容如下
cmake_minimum_required(VERSION 3.0)
option( PLUGIN_STANDARD_TestPlugin "Check to install TestPlugin plugin" ON )
if (PLUGIN_STANDARD_TestPlugin)
project( TestPlugin )
include( ../../../CMakePluginTpl.cmake )
target_link_libraries( ${PROJECT_NAME} )
target_link_libraries( ${PROJECT_NAME} ${OPENGL_LIBRARIES} )
endif()
- 返回上一级目录,修改此处CmakeLists.txt
在行尾追加 add_subdirectory(TestPlugin)
- 最后重复步骤一,重新构建工程文件,打开在解决方案中即出现TestPlugin工程
编译,插件已在工具栏中,点击运行出现hello输出字样