Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

attributeMultiVector.h 8.84 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer 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
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library 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 Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25
26
#ifndef __ATTRIBUTE_MULTI_VECTOR__
#define __ATTRIBUTE_MULTI_VECTOR__
Pierre Kraemer's avatar
Pierre Kraemer committed
27
28
29
30
31
32
33
34
35

#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cstring>

#include <typeinfo>

36
#include "Container/sizeblock.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
37
38
39
40

namespace CGoGN
{

41
class AttributeMultiVectorGen
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
{
protected:
44
45
46
47
	/**
	 * Name of the attribute
	 */
	std::string m_attrName;
Pierre Kraemer's avatar
Pierre Kraemer committed
48

49
50
51
	/**
	 * Name of the type of the attribute
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
	std::string m_typeName;

54
55
56
57
58
59
60
61
62
63
64
65
66
	/**
	 * orbit of the attribute
	 */
	unsigned int m_orbit;

	/**
	 * index of the attribute in its container
	 */
	unsigned int m_index;

	/**
	 * Process or not the attribute in arithmetic operations
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
69
	bool m_toProcess;

public:
70
	AttributeMultiVectorGen(const std::string& strName, const std::string& strType);
Pierre Kraemer's avatar
Pierre Kraemer committed
71

72
	AttributeMultiVectorGen();
Pierre Kraemer's avatar
Pierre Kraemer committed
73

74
 	virtual ~AttributeMultiVectorGen();
Pierre Kraemer's avatar
Pierre Kraemer committed
75

76
 	virtual AttributeMultiVectorGen* new_obj() = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
77

78
79
80
	/**************************************
	 *             ACCESSORS              *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
81

82
83
84
85
	/**
	* get / set orbit of the attribute
	*/
 	unsigned int getOrbit() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
86

87
 	void setOrbit(unsigned int id) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
88

89
90
91
92
	/**
	* get / set index of the attribute
	*/
 	unsigned int getIndex() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
93

94
 	void setIndex(unsigned int id) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
95
96

	/**
97
	* get / set name of the attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
98
	*/
99
100
101
	const std::string& getName();

	void setName(const std::string& n);
Pierre Kraemer's avatar
Pierre Kraemer committed
102
103

	/**
104
	* get / set name of the type of the attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
105
	*/
106
107
108
	const std::string& getTypeName();

	void setTypeName(const std::string& n);
Pierre Kraemer's avatar
Pierre Kraemer committed
109
110

	/**
111
112
113
114
115
116
117
118
119
120
	 * get block size
	 */
 	unsigned int getBlockSize();

	/**************************************
	 *       MULTI VECTOR MANAGEMENT      *
	 **************************************/

	/**
	* add a block of data in the multi vector
Pierre Kraemer's avatar
Pierre Kraemer committed
121
	*/
122
	virtual void addBlock() = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
123
124

	/**
125
	* set the number of blocks
Pierre Kraemer's avatar
Pierre Kraemer committed
126
	*/
127
128
129
	virtual void setNbBlocks(unsigned int nbb) = 0;

	virtual void addBlocksBefore(unsigned int nbb) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
130

131
	virtual bool copy(const AttributeMultiVectorGen* atmvg) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
132

133
134
135
	virtual bool swap(AttributeMultiVectorGen* atmvg) = 0;

	virtual bool merge(const AttributeMultiVectorGen& att) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
136
137

	/**
138
	* free the used memory
Pierre Kraemer's avatar
Pierre Kraemer committed
139
	*/
140
	virtual void clear() = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
141

142
143
144
	/**************************************
	 *             DATA ACCESS            *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
145

146
	virtual unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
147

148
149
150
	/**************************************
	 *          LINES MANAGEMENT          *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
151

152
	virtual void initElt(unsigned int id) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
153

154
	virtual void copyElt(unsigned int dst, unsigned int src) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
155

156
	virtual void overwrite(unsigned int src_b, unsigned int src_id, unsigned int dst_b, unsigned int dst_id) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
157

158
159
160
	/**************************************
	 *       ARITHMETIC OPERATIONS        *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
161

162
 	void toggleProcess();
Pierre Kraemer's avatar
Pierre Kraemer committed
163

164
 	void toggleNoProcess();
Pierre Kraemer's avatar
Pierre Kraemer committed
165

166
 	bool toProcess();
Pierre Kraemer's avatar
Pierre Kraemer committed
167
168
169
170

	/**
	 * copy attribute j on i
	 */
171
	virtual void affect(unsigned int i, unsigned int j) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
172
173
174
175

	/**
	 * add attribute j to i
	 */
176
	virtual void add(unsigned int i, unsigned int j) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
177
178
179
180

	/**
	 * sub attribute j from i
	 */
181
	virtual void sub(unsigned int i, unsigned int j) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
182
183
184
185

	/**
	 * multiply attribute i by alpha
	 */
186
	virtual void mult(unsigned int i, double alpha) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
187
188
189
190

	/**
	 * divide attribute i by alpha
	 */
191
	virtual void div(unsigned int i, double alpha) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
192
193

	/**
194
	 * interpolate attribute i and j in res (with alpha coefficient)
Pierre Kraemer's avatar
Pierre Kraemer committed
195
	 */
196
	virtual void lerp(unsigned res, unsigned int i, unsigned int j, double alpha) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
197

198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
	/**************************************
	 *            SAVE & LOAD             *
	 **************************************/

	virtual std::string output(unsigned int i) = 0;

	virtual void input(unsigned int i,const std::string& st) = 0;

	virtual void saveBin(CGoGNostream& fs, unsigned int id) = 0;

	static unsigned int loadBinInfos(CGoGNistream& fs, std::string& name, std::string& type);

	virtual bool loadBin(CGoGNistream& fs) = 0;

	static bool skipLoadBin(CGoGNistream& fs);
Pierre Kraemer's avatar
Pierre Kraemer committed
213
214
};

215
216
217
218
219

/***************************************************************************************************/
/***************************************************************************************************/


Pierre Kraemer's avatar
Pierre Kraemer committed
220
template <typename T>
221
class AttributeMultiVector : public AttributeMultiVectorGen
Pierre Kraemer's avatar
Pierre Kraemer committed
222
223
{
	/**
224
	* table of blocks of data pointers: vectors!
Pierre Kraemer's avatar
Pierre Kraemer committed
225
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
226
	std::vector<T*> m_tableData;
Pierre Kraemer's avatar
Pierre Kraemer committed
227
228

public:
229
	AttributeMultiVector(const std::string& strName, const std::string& strType);
Pierre Kraemer's avatar
Pierre Kraemer committed
230

231
	AttributeMultiVector();
Pierre Kraemer's avatar
Pierre Kraemer committed
232

233
	~AttributeMultiVector();
Pierre Kraemer's avatar
Pierre Kraemer committed
234

235
236
237
238
239
240
241
242
243
244
245
246
	AttributeMultiVectorGen* new_obj();

	/**************************************
	 *       MULTI VECTOR MANAGEMENT      *
	 **************************************/

	void addBlock();

	void setNbBlocks(unsigned int nbb);

	void addBlocksBefore(unsigned int nbb);

247
	bool copy(const AttributeMultiVectorGen* atmvg);
Pierre Kraemer's avatar
Pierre Kraemer committed
248

249
	bool swap(AttributeMultiVectorGen* atmvg);
Pierre Kraemer's avatar
Pierre Kraemer committed
250

251
	bool merge(const AttributeMultiVectorGen& att);
Pierre Kraemer's avatar
Pierre Kraemer committed
252

253
254
255
256
257
258
	void clear();

	/**************************************
	 *             DATA ACCESS            *
	 **************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
259
	/**
260
261
262
	 * get a reference on a elt
	 * @param i index of element
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
263
264
265
	T& operator[](unsigned int i);

	/**
266
267
	 * get a const reference on a elt
	 * @param i index of element
Pierre Kraemer's avatar
Pierre Kraemer committed
268
	 */
269
	const T& operator[](unsigned int i) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
270
271

	/**
272
	 * Get the addresses of each block of data
Pierre Kraemer's avatar
Pierre Kraemer committed
273
	 */
274
	unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize);
Pierre Kraemer's avatar
Pierre Kraemer committed
275

276
277
278
	/**************************************
	 *          LINES MANAGEMENT          *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
279
280
281
282
283
284

	void initElt(unsigned int id);

	void copyElt(unsigned int dst, unsigned int src);

	/**
285
	* swap two elements in container (useful for compact function)
Pierre Kraemer's avatar
Pierre Kraemer committed
286
287
288
289
290
291
292
	* @param src_b  block index of source element
	* @param src_id index in block of source element
	* @param dst_b  block index of destination element
	* @param dst_id index in block of destination element
	*/
	void overwrite(unsigned int src_b, unsigned int src_id, unsigned int dst_b, unsigned int dst_id);

293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
	/**************************************
	 *       ARITHMETIC OPERATIONS        *
	 **************************************/

	void affect(unsigned int i, unsigned int j);

	void add(unsigned int i, unsigned int j);

	void sub(unsigned int i, unsigned int j);

	void mult(unsigned int i, double alpha);

	void div(unsigned int i, double alpha);

	void lerp(unsigned res, unsigned int i, unsigned int j, double alpha);

	/**************************************
	 *            SAVE & LOAD             *
	 **************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
313
	/**
314
315
316
317
	 *  export en string d'un element
	 *  @param i index de l'element a sortie
	 */
	std::string output(unsigned int i);
Pierre Kraemer's avatar
Pierre Kraemer committed
318
319

	/**
320
321
322
	 *  import d'un element depuis une string
	 *  @param i index de l'element a importer
	 *  @param st string contenant l'element a importer
Pierre Kraemer's avatar
Pierre Kraemer committed
323
	 */
324
	void input(unsigned int i,const std::string& st);
Pierre Kraemer's avatar
Pierre Kraemer committed
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339

	/**
	 * Sauvegarde binaire
	 * @param fs filestream
	 * @param id id of mv
	 */
	void saveBin(CGoGNostream& fs, unsigned int id);

	/**
	 * lecture binaire
	 * @param fs filestream
	 */
	bool loadBin(CGoGNistream& fs);
};

Pierre Kraemer's avatar
Pierre Kraemer committed
340
} // namespace CGoGN
Pierre Kraemer's avatar
Pierre Kraemer committed
341

342
#include "attributeMultiVector.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
343
344

#endif