Commit a04d4f76 authored by Sören Schwertfeger's avatar Sören Schwertfeger
Browse files

initial commit

parents
cmake_minimum_required(VERSION 3.0)
option( INSTALL_QTRANSFORMS_PLUGIN "Check to install qTransforms plugin" ON )
# CloudCompare 'Transforms' plugin
if (INSTALL_QTRANSFORMS_PLUGIN)
add_subdirectory (sttl)
project( QTRANSFORMS_PLUGIN )
include( ../CMakePluginTpl.cmake )
#set dependencies to necessary libraries (see qPCV for an example)
target_link_libraries( ${PROJECT_NAME} STTL )
#include_directories( ${STTL_INCLUDE_DIR} )
get_target_property(sttl_includes STTL INTERFACE_INCLUDE_DIRECTORIES)
INCLUDE_DIRECTORIES ( ${sttl_includes} )
MESSAGE("sttl_includes: ${sttl_includes} ")
endif()
icon.png

156 Bytes

//##########################################################################
//# #
//# CLOUDCOMPARE PLUGIN: qDummy #
//# #
//# 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: Sören Schwertfeg #
//# #
//##########################################################################
//First: replace all occurrences of 'qDummyPlugin' by your own plugin class name in this file!
#include "qTransformsPlugin.h"
//Qt
#include <QtGui>
#include "sttl.h"
//Default constructor: should mainly be used to initialize
//actions (pointers) and other members
qTransformsPlugin::qTransformsPlugin(QObject* parent/*=0*/)
: QObject(parent)
, m_action(0)
{
}
//This method should enable or disable each plugin action
//depending on the currently selected entities ('selectedEntities').
//For example: if none of the selected entities is a cloud, and your
//plugin deals only with clouds, call 'm_action->setEnabled(false)'
void qTransformsPlugin::onNewSelection(const ccHObject::Container& selectedEntities)
{
//if (m_action)
// m_action->setEnabled(!selectedEntities.empty());
}
//This method returns all 'actions' of your plugin.
//It will be called only once, when plugin is loaded.
void qTransformsPlugin::getActions(QActionGroup& group)
{
//default action (if it has not been already created, it's the moment to do it)
if (!m_action)
{
//here we use the default plugin name, description and icon,
//but each action can have its own!
m_action = new QAction(getName(),this);
m_action->setToolTip(getDescription());
m_action->setIcon(getIcon());
//connect appropriate signal
connect(m_action, SIGNAL(triggered()), this, SLOT(doAction()));
}
group.addAction(m_action);
}
void qTransformsPlugin::recTravTree(ccHObject * obj, QString spaces){
QString num("Name: %1 Children %2 PointCloud %3");
num = num.arg(obj->getName());
num = num.arg(obj->getChildrenNumber());
num = num.arg(obj->getClassID() == CC_TYPES::POINT_CLOUD);
m_app->dispToConsole(spaces+num,ccMainAppInterface::WRN_CONSOLE_MESSAGE); //an error message is displayed in the console AND an error box will pop-up!
const QVariantMap& meta = obj->metaData();
for(QVariantMap::const_iterator iter = meta.begin(); iter != meta.end(); ++iter) {
m_app->dispToConsole(spaces+iter.key()+" "+iter.value().toString(),ccMainAppInterface::STD_CONSOLE_MESSAGE); //an error message is displayed in the console AND an error box will pop-up!
}
const ccGLMatrix& transf = obj->getGLTransformationHistory();
m_app->dispToConsole(spaces+" "+transf.toString(),ccMainAppInterface::WRN_CONSOLE_MESSAGE); //an error message is displayed in the console AND an error box will pop-up!
spaces = spaces + QString(" ");
for(int i=0; i<obj->getChildrenNumber(); ++i){
recTravTree(obj->getChild(i), spaces);
}
}
void qTransformsPlugin::recTravTree(ccHObject * obj, sttl::Frame * parent){
sttl::Frame * current = parent;
if(obj->getClassID() == CC_TYPES::POINT_CLOUD){
// this is a point cloud - will be a new parent...
sttl::Frame frame;
frame.name = obj->getName().toStdString();
const ccGLMatrix& transf = obj->getGLTransformationHistory();
Eigen::Transform<double,3,Eigen::Affine> globalT;
for(int i = 0; i<16; ++i){
globalT.data()[i] = transf.data()[i];
}
// ToDo: properly compute the transform of this frame wrt the parent... - I think this is correct...
Eigen::Transform<double,3,Eigen::Affine> result = globalT * parent->transform.inverse();
frame.transform = result;
frame.referenceFrameName = parent->name;
frame.referenceFrame = parent;
m_frames.push_back(frame);
current = &m_frames.back();
}
// recursively call the children...
for(int i=0; i<obj->getChildrenNumber(); ++i){
recTravTree(obj->getChild(i), current);
}
}
//This is an example of an action's slot 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 to most of CC components (database,
//3D views, console, etc.) via the 'm_app' attribute (ccMainAppInterface
//object).
void qTransformsPlugin::doAction()
{
//m_app should have already been initialized by CC when plugin is loaded!
//(--> pure internal check)
assert(m_app);
if (!m_app)
return;
//This is how you can output messages
m_app->dispToConsole("[qTransformsPlugin] Hello world!",ccMainAppInterface::STD_CONSOLE_MESSAGE); //a standard message is displayed in the console
m_app->dispToConsole("[qTransformsPlugin] Warning: dummy plugin shouldn't be used as is!",ccMainAppInterface::WRN_CONSOLE_MESSAGE); //a warning message is displayed in the console
// m_app->dispToConsole("Transforms plugin shouldn't be used as is!",ccMainAppInterface::ERR_CONSOLE_MESSAGE); //an error message is displayed in the console AND an error box will pop-up!
ccHObject * root = getMainAppInterface()->dbRootObject();
recTravTree(root, QString(""));
m_frames.clear();
sttl::Frame rootFrame;
rootFrame.name = "root";
rootFrame.transform = Eigen::Transform<double,3,Eigen::Affine>::Identity();
rootFrame.referenceFrameName = "";
rootFrame.byUser = "Schwerti";
m_frames.push_back(rootFrame);
recTravTree(root, &m_frames.front());
sttl::saveList(m_frames);
}
//This method should return the plugin icon (it will be used mainly
//if your plugin as several actions in which case CC will create a
//dedicated sub-menu entry with this icon.
QIcon qTransformsPlugin::getIcon() const
{
//open qDummyPlugin.qrc (text file), update the "prefix" and the
//icon(s) filename(s). Then save it with the right name (yourPlugin.qrc).
//(eventually, remove the original qDummyPlugin.qrc file!)
return QIcon(":/CC/plugin/qTransforms/icon.png");
}
//##########################################################################
//# #
//# CLOUDCOMPARE PLUGIN: qDummy #
//# #
//# 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 #
//# #
//##########################################################################
#ifndef Q_TRANSFORMS_PLUGIN_HEADER
#define Q_TRANSFORMS_PLUGIN_HEADER
//qCC
#include "../ccStdPluginInterface.h"
#include "sttl.h"
#include <list>
//! Dummy qCC plugin
/** Replace the 'qDummyPlugin' string by your own plugin class name
and then check 'qDummyPlugin.cpp' for more directions (you
have to fill-in the blank methods. The most important one is the
'getActions' method. This method should return all actions
(QAction objects). CloudCompare will automatically add them to an
icon in the plugin toolbar and to an entry in the plugin menu
(if your plugin returns several actions, CC will create a dedicated
toolbar and sub-menu).
You are responsible to connect these actions to custom slots of your
plugin.
Look at the ccStdPluginInterface::m_app attribute to get access to
most of CC components (database, 3D views, console, etc.).
**/
class qTransformsPlugin : public QObject, public ccStdPluginInterface
{
Q_OBJECT
Q_INTERFACES(ccStdPluginInterface)
//replace qDummy by the plugin name (IID should be unique - let's hope your plugin name is unique ;)
Q_PLUGIN_METADATA(IID "cccorp.cloudcompare.plugin.qTransforms")
public:
//! Default constructor
explicit qTransformsPlugin(QObject* parent = 0);
//inherited from ccPluginInterface
virtual QString getName() const override { return "qTransformsPlugin"; }
virtual QString getDescription() const override { return "Transforms plugin (add description here)"; }
virtual QIcon getIcon() const override;
//inherited from ccStdPluginInterface
void onNewSelection(const ccHObject::Container& selectedEntities) override;
virtual void getActions(QActionGroup& group) override;
protected slots:
/*** ADD YOUR CUSTOM ACTIONS' SLOTS HERE ***/
void doAction();
protected:
//! Default action
/** You can add as many actions as you want in a plugin.
All actions will correspond to an icon in the dedicated
toolbar and an entry in the plugin menu.
**/
void recTravTree(ccHObject * obj, QString spaces);
void recTravTree(ccHObject * obj, sttl::Frame * parent);
std::list<sttl::Frame> m_frames;
QAction* m_action;
};
#endif
<RCC>
<qresource prefix="/CC/plugin/qTransforms" >
<file>icon.png</file>
</qresource>
</RCC>
cmake_minimum_required(VERSION 3.0)
# CloudCompare 'Transforms' plugin
project( STTL )
set( CMAKE_AUTOMOC OFF )
find_package( JsonCpp REQUIRED )
SET( EIGEN3_INCLUDE_DIR "$ENV{EIGEN3_INCLUDE_DIR}" )
IF( NOT EIGEN3_INCLUDE_DIR )
MESSAGE( FATAL_ERROR "Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.")
ENDIF()
INCLUDE_DIRECTORIES ( ${EIGEN3_INCLUDE_DIR} )
MESSAGE("EIGEN3_INCLUDE_DIR: ${EIGEN3_INCLUDE_DIR} ")
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
file( GLOB header_list *.h )
file( GLOB source_list *.cpp )
add_library( ${PROJECT_NAME} STATIC ${header_list} ${source_list} )
#target_link_libraries( ${PROJECT_NAME} CC_CORE_LIB )
get_target_property(JsonCpp_includes jsoncpp_lib_static INTERFACE_INCLUDE_DIRECTORIES)
INCLUDE_DIRECTORIES ( ${JsonCpp_includes} )
set_target_properties(${PROJECT_NAME} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR};${CMAKE_CURRENT_SOURCE_DIR}"
)
#set dependencies to necessary libraries (see qPCV for an example)
target_link_libraries( ${PROJECT_NAME} jsoncpp_lib_static )
#include_directories( ${LIB1_INCLUDE_DIR} )
#include "sttl.h"
#include <iostream>
#include <json/json.h>
#include <json/value.h>
using namespace std;
void testSTTL(){
cout<<"Hello STTL"<<endl;
}
Eigen::MatrixXd ReadJsonMatrix(Json::Value Array){
int rows = Array.size();
int cols = Array[0].size();
Eigen::MatrixXd Matrix(rows,cols) ;
for(int i = 0 ; i<rows ; i++){
for(int j=0 ; j<cols ; j++){
Matrix(i,j) = Array[i][j].asDouble() ;
}
}
return Matrix;
}
//// Read Json Array and return as Eigen Vector
Eigen::VectorXd ReadJsonVector(Json::Value Array){
int size = Array.size();
Eigen::VectorXd Vector(size);
for(int i = 0 ; i < size ; i++){
Vector(i) = Array[i].asDouble();
}
return Vector;
}
bool fillJson(const sttl::Frame & frame, Json::Value & node){
node["name"] = frame.name;
for(int i=0; i<4; ++i){
for(int j=0; j<4; ++j){
}
}
Json::Value trans(Json::arrayValue);
trans.resize(4);
for(int i=0; i<4; ++i){
trans[i]=Json::Value(Json::arrayValue);
trans[i].resize(4);
for(int k=0; k<4; ++k){
trans[i][k] = frame.transform(i, k);
}
}
node["transform"] = trans;
if(frame.hasCovariance){
Json::Value cov(Json::arrayValue);
cov.resize(7);
for(int i=0; i<7; ++i){
cov[i]=Json::Value(Json::arrayValue);
cov[i].resize(7);
for(int k=0; k<7; ++k){
cov[i][k] = frame.covariance(i, k);
}
}
node["covariance"] = cov;
}
node["referenceFrame"] = frame.referenceFrameName;
//std::cout<<node;
return true;
}
bool sttl::saveList(const std::list<sttl::Frame> & frames){
Json::Value root(Json::arrayValue);
for(std::list<sttl::Frame>::const_iterator itr = frames.begin(); itr != frames.end(); ++itr){
Json::Value frame;
fillJson(*itr, frame);
root.append(frame);
}
std::cout<<root;
return true;
}
#ifndef STTL
#define STTL
#include <Eigen/Geometry>
#include <string>
#include <list>
namespace sttl{
class Frame{
public:
std::string name;
Eigen::Transform<double,3,Eigen::Affine> transform;
Eigen::Matrix<double, 7, 7> covariance; //< the 7x7 covariance matrix of translation and rotation as quaternion
bool hasCovariance; //< only true ifthe covariance matrix has proper values
Frame * referenceFrame;
std::string referenceFrameName; //< in case the reference Frame cannot be found
Frame():hasCovariance(false), referenceFrame(0){}
std::string byUser;
std::string time;
std::list<std::string> files;
};
bool saveList(const std::list<sttl::Frame> & frames);
void testSTTL();
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment