attributeMultiVector.h 8.17 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
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
	const std::string& getName() const;
100 101

	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
	const std::string& getTypeName() const;
107 108

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

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

	/**************************************
	 *       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
	virtual void setNbBlocks(unsigned int nbb) = 0;

129 130
	virtual unsigned int getNbBlocks() const = 0;

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

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

135 136 137
	virtual bool swap(AttributeMultiVectorGen* atmvg) = 0;

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

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

144 145 146 147 148
	/**
	 * get size of type
	 */
	virtual int getSizeOfType() const = 0;

149 150 151
	/**************************************
	 *             DATA ACCESS            *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
152

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

155 156 157
	/**************************************
	 *          LINES MANAGEMENT          *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
158

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

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

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

165
	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
166 167


168 169 170 171 172 173 174 175 176 177 178
	/**************************************
	 *            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);
179 180 181 182 183 184

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

187 188 189 190 191

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


Pierre Kraemer's avatar
Pierre Kraemer committed
192
template <typename T>
193
class AttributeMultiVector : public AttributeMultiVectorGen
Pierre Kraemer's avatar
Pierre Kraemer committed
194 195
{
	/**
196
	* table of blocks of data pointers: vectors!
Pierre Kraemer's avatar
Pierre Kraemer committed
197
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
198
	std::vector<T*> m_tableData;
Pierre Kraemer's avatar
Pierre Kraemer committed
199 200

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

203
	AttributeMultiVector();
Pierre Kraemer's avatar
Pierre Kraemer committed
204

205
	~AttributeMultiVector();
Pierre Kraemer's avatar
Pierre Kraemer committed
206

207 208 209 210 211 212 213 214 215 216
	AttributeMultiVectorGen* new_obj();

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

	void addBlock();

	void setNbBlocks(unsigned int nbb);

217 218
	unsigned int getNbBlocks() const;

219 220
	void addBlocksBefore(unsigned int nbb);

221
	bool copy(const AttributeMultiVectorGen* atmvg);
Pierre Kraemer's avatar
Pierre Kraemer committed
222

223
	bool swap(AttributeMultiVectorGen* atmvg);
Pierre Kraemer's avatar
Pierre Kraemer committed
224

225
	bool merge(const AttributeMultiVectorGen& att);
Pierre Kraemer's avatar
Pierre Kraemer committed
226

227 228
	void clear();

229 230
	int getSizeOfType() const;

231 232 233 234
	/**************************************
	 *             DATA ACCESS            *
	 **************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
235
	/**
236 237 238
	 * get a reference on a elt
	 * @param i index of element
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
239 240 241
	T& operator[](unsigned int i);

	/**
242 243
	 * get a const reference on a elt
	 * @param i index of element
Pierre Kraemer's avatar
Pierre Kraemer committed
244
	 */
245
	const T& operator[](unsigned int i) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
246 247

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

252 253 254
	/**************************************
	 *          LINES MANAGEMENT          *
	 **************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
255 256 257 258 259

	void initElt(unsigned int id);

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
262
	/**
263
	* swap two elements in container (useful for compact function)
Pierre Kraemer's avatar
Pierre Kraemer committed
264 265 266 267 268 269 270
	* @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);

271 272 273 274
	/**************************************
	 *       ARITHMETIC OPERATIONS        *
	 **************************************/

275
//	void affect(unsigned int i, unsigned int j);
276

277
//	void add(unsigned int i, unsigned int j);
278

279
//	void sub(unsigned int i, unsigned int j);
280

281
//	void mult(unsigned int i, double alpha);
282

283
//	void div(unsigned int i, double alpha);
284

285
//	void lerp(unsigned res, unsigned int i, unsigned int j, double alpha);
286 287 288 289 290

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

Pierre Kraemer's avatar
Pierre Kraemer committed
291 292 293 294 295 296 297 298 299 300 301 302
	/**
	 * 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);
303 304 305 306 307 308 309

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

Pierre Kraemer's avatar
Pierre Kraemer committed
310 311
};

Pierre Kraemer's avatar
Pierre Kraemer committed
312
} // namespace CGoGN
Pierre Kraemer's avatar
Pierre Kraemer committed
313

Sylvain Thery's avatar
Sylvain Thery committed
314
#include "attributeMultiVectorBool.hpp"
315
#include "attributeMultiVector.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
316 317

#endif