qTransformsPlugin.cpp 6.49 KB
Newer Older
Sören Schwertfeger's avatar
Sören Schwertfeger committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//##########################################################################
//#                                                                        #
//#                       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");
}