File: ccCompass.h

package info (click to toggle)
cloudcompare 2.10.1-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 55,916 kB
  • sloc: cpp: 219,837; ansic: 29,944; makefile: 67; sh: 45
file content (229 lines) | stat: -rw-r--r-- 9,453 bytes parent folder | download | duplicates (2)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//##########################################################################
//#                                                                        #
//#                    CLOUDCOMPARE PLUGIN: ccCompass                      #
//#                                                                        #
//#  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: Sam Thiele  2017                        #
//#                                                                        #
//##########################################################################

#ifndef CC_COMPASS_HEADER
#define CC_COMPASS_HEADER

#include <QObject>
#include <QXmlStreamWriter>
#include <cmath>
#include <random>

//qCC
#include "ccStdPluginInterface.h"
#include <ccPickingListener.h>
#include <qbuffer.h>

class ccCompassDlg;
class ccFitPlaneTool;
class ccGeoObject;
class ccLineationTool;
class ccMapDlg;
class ccNoteTool;
class ccPinchNodeTool;
class ccThicknessTool;
class ccTool;
class ccTopologyTool;
class ccTraceTool;
class ccSNECloud;

class ccCompass : public QObject, public ccStdPluginInterface, public ccPickingListener
{
	Q_OBJECT
		Q_INTERFACES(ccStdPluginInterface)
		Q_PLUGIN_METADATA(IID "cccorp.cloudcompare.plugin.ccCompass" FILE "info.json")

public:
	//! Default constructor
	explicit ccCompass(QObject* parent = nullptr);

	//deconstructor
	virtual ~ccCompass();

	//inherited from ccPluginInterface
	virtual void stop() override { stopMeasuring(true); m_dlg = nullptr; ccStdPluginInterface::stop(); } //called when the plugin is being stopped

	//inherited from ccStdPluginInterface
	void onNewSelection(const ccHObject::Container& selectedEntities) override;
	virtual QList<QAction *> getActions() override;

protected slots:

	//initialise the plugin
	void doAction();

	//start picking mode
	bool startMeasuring();

	//stop picking mode
	bool stopMeasuring(bool finalStop = false);
	
	//inherited from ccPickingListener
	virtual void onItemPicked(const ccPickingListener::PickedItem& pi) override;

	//picked point callback (called by the above function)
	void pointPicked(ccHObject* entity, unsigned itemIdx, int x, int y, const CCVector3& P);

	//**************
	//GUI actions:
	//**************
	//general
	void onClose();
	void onAccept();
	void onSave();
	void onUndo();

	//modes
	void enableMapMode(); //turns on/off map mode
	void enableMeasureMode(); //turns on/off map mode

	//tools
	void setPick(); //activates the picking tool
	void setLineation(); //activates the lineation tool
	void setPlane(); //activates the plane tool
	void setTrace(); //activates the trace tool

	//extra tools
	void addPinchNode(); //activates the pinch node tool
	void setThickness(); //activates the thickness tool
	void setThickness2(); //activates the thickness tool in two-point mode
	void setYoungerThan(); //activates topology tool in "younger-than" mode
	void setFollows(); //activates topology tool in "follows" mode
	void setEquivalent(); //activates topology mode in "equivalent" mode
	void setNote(); //activates the note tool
	void recalculateSelectedTraces(); //recalculate any selected traces (for updating with a different cost function)
	void mergeGeoObjects(); //merges the selected GeoObjects
	void fitPlaneToGeoObject(); //calculates best-fit plane for the upper and lower surfaces of the selected GeoObject
	void recalculateFitPlanes(); //recalcs fit planes for traces and GeoObjects
	void estimateStructureNormals(); //Estimate the normal vector to the structure this trace represents at each point in this trace.
	void estimateP21(); //Calculate the intensity of selected structures 
	void estimateStrain(); //Estimate strain from Mode-I dykes and veins
	void convertToPointCloud(); //converts selected traces or geoObjects to point clouds
	void distributeSelection(); //distributes selected objects into GeoObjects with the same name
	void importFoliations(); //import foliation data
	void importLineations(); //import lineation data
	void exportToSVG(); //exports current view to SVG

	//map mode dialog
	void writeToInterior(); //new digitization will be added to the GeoObjects interior
	void writeToUpper(); //new digitization will be added to the GeoObjects upper boundary
	void writeToLower(); //new digitiziation will be added to the GeoObjects lower boundary
	void addGeoObject(bool singleSurface=false); //creates a new GeoObject
	void addGeoObjectSS(); //creates a new single surface GeoObject

	//drawing options
	void hideAllPointClouds(ccHObject* o); //hides all point clouds and adds them to the m_hiddenObjects list
	void toggleStipple(bool checked);
	void recurseStipple(ccHObject* object, bool checked);
	void toggleLabels(bool checked);
	void recurseLabels(ccHObject* object, bool checked);
	void toggleNormals(bool checked);
	void recurseNormals(ccHObject* object, bool checked);

	//display the help dialog
	void showHelp();

protected:

	//event to get mouse-move updates & trigger repaint of overlay circle
	virtual bool eventFilter(QObject* obj, QEvent* event) override;
	
	//used to get the place/object that new measurements or interpretation should be stored
	ccHObject* getInsertPoint();

	//cleans up pointers etc before changing tools
	void cleanupBeforeToolChange(bool autoRestartPicking = true);

	//registers this plugin with the picking hub
	bool startPicking();

	//removes this plugin from the picking hub
	void stopPicking();

	//checks if the passed object, or any of it's children, represent unloaded ccCompass objects (e.g. traces, fitplanes etc).
	void tryLoading();
	void tryLoading(ccHObject* obj, std::vector<int>* originals, std::vector<ccHObject*>* replacements);

	//Action to start ccCompass
	QAction* m_action = nullptr;

	//link to application windows
	QMainWindow* m_main_window = nullptr;

	//picking or not?
	bool m_picking = false;
	bool m_active = false;

	//ccCompass toolbar gui
	ccCompassDlg* m_dlg = nullptr;
	ccMapDlg* m_mapDlg = nullptr;

	//tools
	ccTool* m_activeTool = nullptr;
	ccFitPlaneTool* m_fitPlaneTool;
	ccTraceTool* m_traceTool;
	ccLineationTool* m_lineationTool;
	ccThicknessTool* m_thicknessTool;
	ccTopologyTool* m_topologyTool;
	ccNoteTool* m_noteTool;
	ccPinchNodeTool* m_pinchNodeTool;

	//currently selected/active geoObject
	ccGeoObject* m_geoObject = nullptr; //the GeoObject currently being written to
	int m_geoObject_id = -1; //used to check if m_geoObject has been deleted
	std::vector<int> m_hiddenObjects; //used to hide objects (for picking)

	//used to 'guess' the name of new GeoObjects
	QString m_lastGeoObjectName = "GeoObject"; 

	//used while exporting data
	int writePlanes(ccHObject* object, QTextStream* out, const QString &parentName = QString());
	int writeTraces(ccHObject* object, QTextStream* out, const QString &parentName = QString());
	int writeLineations(ccHObject* object, QTextStream* out, const QString &parentName = QString(), bool thickness=false); //if thickness is true this will write "thickness lineations" rather than orientation lineations
	
	int writeTracesSVG(ccHObject* object, QTextStream* out, int height, float zoom);

	int writeToXML(const QString &filename); //exports Compass interpretation tree to xml
	int writeObjectXML(ccHObject* object, QXmlStreamWriter* out); //writes the provided object (recursive)

	//checks if an object was made by this app (i.e. returns true if we are responsible for a given layer)
	bool madeByMe(ccHObject* object);

	//used by the SNE algorithms
	//static double prior(double phi, double theta, double nx, double ny, double nz); //prior distribution for orientations (depends on outcrop orientation)
	//static double logWishSF(double X[3][3], int nobserved); //calculate log scale-factor for wishart dist. This only needs to be done once per X, so is pulled out of the wish function for performance
	//static double logWishart(double X[3][3], int nobserved, double phi, double theta, double alpha, double e1, double e2, double e3, double lsf); //calculate log wishart probability density for an observed covariance and proposed eigen system
	//static double wishartExp1D(double X[3][3], int nobserved, double phi, double theta, double e1, double e2, double e3, double lsf, unsigned steps=500); //integrate over alpha
	//static double** sampleMCMC(double icov[3][3], int nobserved, CCVector3* normal, int nsamples = 1000, double proposalWidth = 0.075); //sample posterior with MCMC

//static flags used to define simple behaviours
public:
	//drawing properties
	static bool drawName;
	static bool drawStippled;
	static bool drawNormals;

	//calculation properties
	static bool fitPlanes;
	static int costMode;

	//digitization mode
	static bool mapMode; //true if map mode, false if measure mode
	static int mapTo; //see flags in ccGeoObject.h for definition of different mapping locations
};

#endif