File: mesh_document.h

package info (click to toggle)
meshlab 2022.02%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 47,348 kB
  • sloc: cpp: 536,635; ansic: 27,783; sh: 539; makefile: 36
file content (237 lines) | stat: -rw-r--r-- 7,596 bytes parent folder | download
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
230
231
232
233
234
235
236
237
/****************************************************************************
* MeshLab                                                           o o     *
* Visual and Computer Graphics Library                            o     o   *
*                                                                _   O  _   *
* Copyright(C) 2004-2021                                           \/)\/    *
* Visual Computing Lab                                            /\/|      *
* ISTI - Italian National Research Council                           |      *
*                                                                    \      *
* All rights reserved.                                                      *
*                                                                           *
* 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; either version 2 of the License, or         *
* (at your option) any later version.                                       *
*                                                                           *
* 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 (http://www.gnu.org/licenses/gpl.txt)          *
* for more details.                                                         *
*                                                                           *
****************************************************************************/

#ifndef MESH_DOCUMENT_H
#define MESH_DOCUMENT_H

#include "mesh_model.h"
#include "raster_model.h"

#include "helpers/mesh_document_state_data.h"

class MeshDocument : public QObject
{
	Q_OBJECT

public:

	// Iterators
	typedef std::list<MeshModel>::iterator MeshIterator;
	typedef std::list<MeshModel>::const_iterator ConstMeshIterator;
	typedef std::list<RasterModel>::iterator RasterIterator;
	typedef std::list<RasterModel>::const_iterator ConstRasterIterator;

	class MeshRangeIterator
	{
		friend class MeshDocument;
	public:
		MeshIterator begin() {return md.meshBegin();}
		MeshIterator end() {return md.meshEnd();}
	private:
		MeshRangeIterator(MeshDocument& md) : md(md){}
		MeshDocument& md;
	};

	class ConstMeshRangeIterator
	{
		friend class MeshDocument;
	public:
		ConstMeshIterator begin() {return md.meshBegin();}
		ConstMeshIterator end()   {return md.meshEnd();}
	private:
		ConstMeshRangeIterator(const MeshDocument& md) : md(md){}
		const MeshDocument& md;
	};

	class RasterRangeIterator
	{
		friend class MeshDocument;
	public:
		RasterIterator begin() {return md.rasterBegin();}
		RasterIterator end()   {return md.rasterEnd();}
	private:
		RasterRangeIterator(MeshDocument& md) : md(md){}
		MeshDocument& md;
	};

	class ConstRasterRangeIterator
	{
		friend class MeshDocument;
	public:
		ConstRasterIterator begin() {return md.rasterBegin();}
		ConstRasterIterator end()   {return md.rasterEnd();}
	private:
		ConstRasterRangeIterator(const MeshDocument& md) : md(md){}
		const MeshDocument& md;
	};

	MeshDocument();

	//deletes each meshModel
	~MeshDocument();

	void clear();

	///returns the mesh with the given unique id
	const MeshModel* getMesh(unsigned int id) const;
	MeshModel* getMesh(unsigned int id);

	//set the current mesh to be the one with the given ID
	void setCurrentMesh( int new_curr_id );
	
	void setVisible(int meshId, bool val);

	/// returns the raster with the given unique id
	RasterModel *getRaster(unsigned int i);

	//set the current raster to be the one with the given ID
	void setCurrentRaster( int new_curr_id );
	void setCurrent(MeshModel   *newCur);
	void setCurrent(RasterModel *newCur);

	/// methods to access the set of Meshes in a ordered fashion.
	MeshModel   *nextVisibleMesh(MeshModel *_m = nullptr);

	MeshModel   *nextMesh(MeshModel *_m = nullptr);
	/// methods to access the set of Meshes in a ordered fashion.
	RasterModel   *nextRaster(RasterModel *_rm = nullptr);

	MeshModel* mm();

	const MeshModel* mm() const;

	//Could return 0 if no raster has been selected
	RasterModel *rm();
	const RasterModel* rm() const;

	void requestUpdatingPerMeshDecorators(int mesh_id);

	MeshDocumentStateData& meshDocStateData();
	void setDocLabel(const QString& docLb);
	QString docLabel() const;
	QString pathName() const;
	void setFileName(const QString& newFileName);

	unsigned int meshNumber() const;
	unsigned int rasterNumber() const;

	bool isBusy();  // used in processing. To disable access to the mesh by the rendering thread
	void setBusy(bool _busy);

	///add a new mesh with the given name
	MeshModel* addNewMesh(const CMeshO& mesh, const QString& Label, bool setAsCurrent=true);
	MeshModel *addNewMesh(QString fullPath, const QString& Label, bool setAsCurrent=true);
	MeshModel *addOrGetMesh(const QString& fullPath, const QString& Label, bool setAsCurrent=true);
	std::list<MeshModel*> getMeshesLoadedFromSameFile(MeshModel& mm);

	///remove the mesh from the list and delete it from memory
	bool delMesh(unsigned int id);
	MeshIterator eraseMesh(MeshIterator it);

	///add a new raster model
	RasterModel *addNewRaster(/*QString rasterName*/);

	///remove the raster from the list and delete it from memory
	bool delRaster(unsigned int id);
	RasterIterator eraseRaster(RasterIterator it);

	int vn() const; /// Sum of all the vertices of all the meshes

	int fn() const;

	Box3m bbox() const;

	bool hasBeenModified() const;

	//iterator member functions
	MeshIterator meshBegin();
	MeshIterator meshEnd();
	RasterIterator rasterBegin();
	RasterIterator rasterEnd();
	ConstMeshIterator meshBegin() const;
	ConstMeshIterator meshEnd() const;
	ConstRasterIterator rasterBegin() const;
	ConstRasterIterator rasterEnd() const;

	MeshRangeIterator meshIterator();
	ConstMeshRangeIterator meshIterator() const;
	RasterRangeIterator rasterIterator();
	ConstRasterRangeIterator rasterIterator() const;

	GLLogStream Log;
	FilterScript filterHistory;

private:
	/// The very important member:
	/// The list of MeshModels.
	std::list<MeshModel> meshList;
	/// The list of the raster models of the project
	std::list<RasterModel> rasterList;

	int meshIdCounter;
	int rasterIdCounter;

	/**
	All the files referred in a document are relative to the folder containing the project file.
	this is the full path to the document.
	*/
	QString fullPathFilename;

	//it is the label of the document. it should only be something like Project_n (a temporary name for a new empty document) or the fullPathFilename.
	QString documentLabel;

	MeshDocumentStateData mdstate;

	bool busy;

	MeshModel* currentMesh;
	//the current raster model
	RasterModel* currentRaster;

	unsigned int newMeshId();
	unsigned int newRasterId();

signals:
	///whenever the current mesh is changed (e.g. the user click on a different mesh)
	// this signal will send out with the index of the newest mesh
	void currentMeshChanged(int index);

	/// whenever the document (or even a single mesh) is modified by a filter
	void meshDocumentModified();

	///whenever the meshList is changed
	void meshSetChanged();

	void meshAdded(int index);
	void meshRemoved(int index);

	///whenever the rasterList is changed
	void rasterSetChanged();

	//this signal is emitted when a filter request to update the mesh in the renderingState
	void documentUpdated();
	void updateDecorators(int mesh_id);
};// end class MeshDocument


#endif // MESH_DOCUMENT_H