attributeMultiVector.h 8.41 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-2012, 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.unistra.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 42 43 44 45 46 47 48 49 50 51
enum CGoGNCodeType
	{CGoGNUNKNOWNTYPE=0,
	 CGoGNINT,CGoGNUINT,
	 CGoGNSHORT,CGoGNUSHORT,
	 CGoGNCHAR,CGoGNUCHAR,
	 CGoGNFLOAT,CGoGNDOUBLE,
	 CGoGNVEC2F,CGoGNVEC2D,
	 CGoGNVEC3F,CGoGNVEC3D,
	 CGoGNVEC4F,CGoGNVEC4D
	};

52
class AttributeMultiVectorGen
Pierre Kraemer's avatar
Pierre Kraemer committed
53 54
{
protected:
55 56 57 58
	/**
	 * Name of the attribute
	 */
	std::string m_attrName;
Pierre Kraemer's avatar
Pierre Kraemer committed
59

60 61 62
	/**
	 * Name of the type of the attribute
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64
	std::string m_typeName;

65 66 67 68 69
	/**
	 * Code of type
	 */
	CGoGNCodeType m_typeCode;

70 71 72 73 74 75 76 77 78 79
	/**
	 * orbit of the attribute
	 */
	unsigned int m_orbit;

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

Pierre Kraemer's avatar
Pierre Kraemer committed
80
public:
81
	AttributeMultiVectorGen(const std::string& strName, const std::string& strType);
Pierre Kraemer's avatar
Pierre Kraemer committed
82

83
	AttributeMultiVectorGen();
Pierre Kraemer's avatar
Pierre Kraemer committed
84

85
 	virtual ~AttributeMultiVectorGen();
Pierre Kraemer's avatar
Pierre Kraemer committed
86

87
 	virtual AttributeMultiVectorGen* new_obj() = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
88

89 90 91
	/**************************************
	 *             ACCESSORS              *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
92

93 94 95 96
	/**
	* get / set orbit of the attribute
	*/
 	unsigned int getOrbit() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97

98
 	void setOrbit(unsigned int id) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99

100 101 102 103
	/**
	* get / set index of the attribute
	*/
 	unsigned int getIndex() const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
104

105
 	void setIndex(unsigned int id) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107

	/**
108
	* get / set name of the attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
109
	*/
110
	const std::string& getName() const;
111 112

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

	/**
115
	* get / set name of the type of the attribute
Pierre Kraemer's avatar
Pierre Kraemer committed
116
	*/
117
	const std::string& getTypeName() const;
118 119

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

121 122
	CGoGNCodeType getTypeCode() const;

Pierre Kraemer's avatar
Pierre Kraemer committed
123
	/**
124 125
	 * get block size
	 */
126
	unsigned int getBlockSize() const;
127 128 129 130 131 132 133

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

	/**
	* add a block of data in the multi vector
Pierre Kraemer's avatar
Pierre Kraemer committed
134
	*/
135
	virtual void addBlock() = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137

	/**
138
	* set the number of blocks
Pierre Kraemer's avatar
Pierre Kraemer committed
139
	*/
140 141
	virtual void setNbBlocks(unsigned int nbb) = 0;

142 143
	virtual unsigned int getNbBlocks() const = 0;

Sylvain Thery's avatar
Sylvain Thery committed
144
//	virtual void addBlocksBefore(unsigned int nbb) = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
145

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

148 149 150
	virtual bool swap(AttributeMultiVectorGen* atmvg) = 0;

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

	/**
153
	* free the used memory
Pierre Kraemer's avatar
Pierre Kraemer committed
154
	*/
155
	virtual void clear() = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
156

157 158 159 160 161
	/**
	 * get size of type
	 */
	virtual int getSizeOfType() const = 0;

162 163 164
	/**************************************
	 *             DATA ACCESS            *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
165

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

168 169 170
	/**************************************
	 *          LINES MANAGEMENT          *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
171

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
176 177
	virtual void swapElt(unsigned int id1, unsigned int id2) = 0;

178
	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
179 180


181 182 183 184 185 186 187 188 189 190 191
	/**************************************
	 *            SAVE & LOAD             *
	 **************************************/

	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);
192 193 194 195 196 197

	/**
	 * lecture binaire
	 * @param fs filestream
	 */
	virtual void dump(unsigned int i) const = 0;
Pierre Kraemer's avatar
Pierre Kraemer committed
198 199
};

200 201 202 203 204

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


Pierre Kraemer's avatar
Pierre Kraemer committed
205
template <typename T>
206
class AttributeMultiVector : public AttributeMultiVectorGen
Pierre Kraemer's avatar
Pierre Kraemer committed
207 208
{
	/**
209
	* table of blocks of data pointers: vectors!
Pierre Kraemer's avatar
Pierre Kraemer committed
210
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
211
	std::vector<T*> m_tableData;
Pierre Kraemer's avatar
Pierre Kraemer committed
212

213 214
	inline void setTypeCode();

Pierre Kraemer's avatar
Pierre Kraemer committed
215
public:
216
	AttributeMultiVector(const std::string& strName, const std::string& strType);
Pierre Kraemer's avatar
Pierre Kraemer committed
217

218
	AttributeMultiVector();
Pierre Kraemer's avatar
Pierre Kraemer committed
219

220
	~AttributeMultiVector();
Pierre Kraemer's avatar
Pierre Kraemer committed
221

222 223 224 225 226 227 228 229 230 231
	AttributeMultiVectorGen* new_obj();

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

	void addBlock();

	void setNbBlocks(unsigned int nbb);

232 233
	unsigned int getNbBlocks() const;

234 235
	void addBlocksBefore(unsigned int nbb);

236
	bool copy(const AttributeMultiVectorGen* atmvg);
Pierre Kraemer's avatar
Pierre Kraemer committed
237

238
	bool swap(AttributeMultiVectorGen* atmvg);
Pierre Kraemer's avatar
Pierre Kraemer committed
239

240
	bool merge(const AttributeMultiVectorGen& att);
Pierre Kraemer's avatar
Pierre Kraemer committed
241

242 243
	void clear();

244 245
	int getSizeOfType() const;

246 247 248 249
	/**************************************
	 *             DATA ACCESS            *
	 **************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
250
	/**
251 252 253
	 * get a reference on a elt
	 * @param i index of element
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
254 255 256
	T& operator[](unsigned int i);

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

	/**
263
	 * Get the addresses of each block of data
Pierre Kraemer's avatar
Pierre Kraemer committed
264
	 */
265
	unsigned int getBlocksPointers(std::vector<void*>& addr, unsigned int& byteBlockSize) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
266

267 268 269
	/**************************************
	 *          LINES MANAGEMENT          *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
270 271 272 273 274

	void initElt(unsigned int id);

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

Pierre Kraemer's avatar
Pierre Kraemer committed
275 276
	void swapElt(unsigned int id1, unsigned int id2);

Pierre Kraemer's avatar
Pierre Kraemer committed
277
	/**
278
	* swap two elements in container (useful for compact function)
Pierre Kraemer's avatar
Pierre Kraemer committed
279 280 281 282 283 284 285
	* @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);

286 287 288 289
	/**************************************
	 *       ARITHMETIC OPERATIONS        *
	 **************************************/

290
//	void affect(unsigned int i, unsigned int j);
291

292
//	void add(unsigned int i, unsigned int j);
293

294
//	void sub(unsigned int i, unsigned int j);
295

296
//	void mult(unsigned int i, double alpha);
297

298
//	void div(unsigned int i, double alpha);
299

300
//	void lerp(unsigned res, unsigned int i, unsigned int j, double alpha);
301 302 303 304 305

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

Pierre Kraemer's avatar
Pierre Kraemer committed
306 307 308 309 310 311 312 313 314 315 316 317
	/**
	 * 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);
318 319 320 321 322 323 324

	/**
	 * lecture binaire
	 * @param fs filestream
	 */
	virtual void dump(unsigned int i) const;

Pierre Kraemer's avatar
Pierre Kraemer committed
325 326
};

Pierre Kraemer's avatar
Pierre Kraemer committed
327
} // namespace CGoGN
Pierre Kraemer's avatar
Pierre Kraemer committed
328

Sylvain Thery's avatar
Sylvain Thery committed
329
#include "attributeMultiVectorBool.hpp"
330
#include "attributeMultiVector.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
331 332

#endif