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.95 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
* 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

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
156
157
	virtual void swapElt(unsigned int id1, unsigned int id2) = 0;

158
	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
159

160
161
162
	/**************************************
	 *       ARITHMETIC OPERATIONS        *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
163

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

166
 	void toggleNoProcess();
Pierre Kraemer's avatar
Pierre Kraemer committed
167

168
 	bool toProcess();
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
172

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

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

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

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

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

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

200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
	/**************************************
	 *            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
215
216
};

217
218
219
220
221

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


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

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

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

235
	~AttributeMultiVector();
Pierre Kraemer's avatar
Pierre Kraemer committed
236

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

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

	void addBlock();

	void setNbBlocks(unsigned int nbb);

	void addBlocksBefore(unsigned int nbb);

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

251
	bool swap(AttributeMultiVectorGen* atmvg);
Pierre Kraemer's avatar
Pierre Kraemer committed
252

253
	bool merge(const AttributeMultiVectorGen& att);
Pierre Kraemer's avatar
Pierre Kraemer committed
254

255
256
257
258
259
260
	void clear();

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

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

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

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

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

	void initElt(unsigned int id);

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

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
286
287
	void swapElt(unsigned int id1, unsigned int id2);

Pierre Kraemer's avatar
Pierre Kraemer committed
288
	/**
289
	* swap two elements in container (useful for compact function)
Pierre Kraemer's avatar
Pierre Kraemer committed
290
291
292
293
294
295
296
	* @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);

297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
	/**************************************
	 *       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
317
	/**
318
319
320
321
	 *  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
322
323

	/**
324
325
326
	 *  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
327
	 */
328
	void input(unsigned int i,const std::string& st);
Pierre Kraemer's avatar
Pierre Kraemer committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343

	/**
	 * 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
344
} // namespace CGoGN
Pierre Kraemer's avatar
Pierre Kraemer committed
345

346
#include "attributeMultiVector.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
347
348

#endif