multiAttribs.h 10.8 KB
Newer Older
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-2012, 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: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25 26
#ifndef __MULTI2ATTRIBS_H_
#define __MULTI2ATTRIBS_H_
27

28 29
#include "Topology/generic/cells.h"

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
namespace CGoGN
{

//forward
template <typename T1, typename T2>
struct RefCompo2Type;


template <typename T1, typename T2>
struct Compo2Type
{
	T1 m_v1;
	T2 m_v2;

	Compo2Type(){}
	Compo2Type(double z ): m_v1(z), m_v2(z) {}
46 47 48

	Compo2Type(const Compo2Type<double,double>& ct ): m_v1(ct.m_v1), m_v2(ct.m_v1) {}

49
	Compo2Type(const RefCompo2Type<T1,T2>& v);
50

51
	Compo2Type<T1,T2>& operator =(const Compo2Type<T1,T2>& comp);
52

53
	Compo2Type<T1,T2> operator+(const Compo2Type<T1,T2>& v) const;
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
	Compo2Type<T1,T2> operator-(const Compo2Type<T1,T2>& v) const;
	Compo2Type<T1,T2> operator/(double d) const;
	Compo2Type<T1,T2> operator*(double d) const;
	Compo2Type<T1,T2>& operator+=(const Compo2Type<T1,T2>& v);
	Compo2Type<T1,T2>& operator-=(const Compo2Type<T1,T2>& v);
	Compo2Type<T1,T2>& operator*=(double d);
	Compo2Type<T1,T2>& operator/=(double d);
};


template <typename T1, typename T2>
struct RefCompo2Type
{
	T1& m_v1;
	T2& m_v2;

	RefCompo2Type(T1& v1, T2& v2): m_v1(v1), m_v2(v2) {}
71
	RefCompo2Type (Compo2Type<T1,T2>& comp);
72

73
	RefCompo2Type<T1,T2>& operator=(const RefCompo2Type<T1,T2>& v);
Sylvain Thery's avatar
Sylvain Thery committed
74
	RefCompo2Type<T1,T2>& operator=(Compo2Type<T1,T2> v);
75

76 77 78 79 80 81 82 83 84
	Compo2Type<T1,T2> operator+(const RefCompo2Type<T1,T2>& v) const;
	Compo2Type<T1,T2> operator-(const RefCompo2Type<T1,T2>& v) const;
	Compo2Type<T1,T2> operator/(double d) const;
	Compo2Type<T1,T2> operator*(double d) const;
	RefCompo2Type<T1,T2>& operator+=(const RefCompo2Type<T1,T2>& v);
	RefCompo2Type<T1,T2>& operator-=(const RefCompo2Type<T1,T2>& v);
	RefCompo2Type<T1,T2>& operator*=(double d);
	RefCompo2Type<T1,T2>& operator/=(double d);
};
85

86 87 88 89 90 91 92 93 94 95 96 97 98 99
template <typename T1, typename T2>
Compo2Type<double, double> length( const Compo2Type<T1,T2>& v)
{
	Compo2Type<double, double> l;
	l.m_v1 = sqrt(v.m_v1*v.m_v1);
	l.m_v2 = sqrt(v.m_v2*v.m_v2);
	return l;
}

template <typename T>
double length(const T& v)
{
	return v.norm();
}
100 101


Pierre Kraemer's avatar
Pierre Kraemer committed
102
template <typename T1, typename T2, typename MAP_IMPL>
103 104
class Vertex2Attributes
{
Pierre Kraemer's avatar
Pierre Kraemer committed
105 106
	VertexAttribute<T1, MAP_IMPL>& m_h1;
	VertexAttribute<T2, MAP_IMPL>& m_h2;
107
public:
Sylvain Thery's avatar
Sylvain Thery committed
108 109
	typedef Compo2Type<T1,T2> DATA_TYPE;
	typedef RefCompo2Type<T1,T2> REF_DATA_TYPE;
110

Pierre Kraemer's avatar
Pierre Kraemer committed
111
	Vertex2Attributes(VertexAttribute<T1, MAP_IMPL>& h1, VertexAttribute<T2, MAP_IMPL>& h2):
112 113 114
		m_h1(h1), m_h2(h2) {}

	RefCompo2Type<T1,T2> operator[](unsigned int a)
115
	{
116
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
117 118
	}

119
	RefCompo2Type<T1,T2> operator[](Vertex d)
120
	{
121
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
122
	}
Sylvain Thery's avatar
Sylvain Thery committed
123 124 125 126 127 128

	const RefCompo2Type<T1,T2> operator[](unsigned int a) const
	{
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
	}

129
	const RefCompo2Type<T1,T2> operator[](Vertex d) const
Sylvain Thery's avatar
Sylvain Thery committed
130 131 132
	{
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
	}
133 134 135 136

	static unsigned int getOrbit() { return VERTEX; }
};

Pierre Kraemer's avatar
Pierre Kraemer committed
137
template <typename T1, typename T2, typename MAP_IMPL>
138 139
class Edge2Attributes
{
Pierre Kraemer's avatar
Pierre Kraemer committed
140 141
	EdgeAttribute<T1, MAP_IMPL>& m_h1;
	EdgeAttribute<T2, MAP_IMPL>& m_h2;
142 143 144 145
public:
	typedef Compo2Type<T1,T2> DATA_TYPE;
	typedef RefCompo2Type<T1,T2> REF_DATA_TYPE;

Pierre Kraemer's avatar
Pierre Kraemer committed
146
	Edge2Attributes(EdgeAttribute<T1, MAP_IMPL>& h1, EdgeAttribute<T2, MAP_IMPL>& h2):
147 148 149 150 151 152 153
		m_h1(h1), m_h2(h2) {}

	RefCompo2Type<T1,T2> operator[](unsigned int a)
	{
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
	}

154
	RefCompo2Type<T1,T2> operator[](Edge d)
155 156 157 158 159 160 161 162 163
	{
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
	}

	const RefCompo2Type<T1,T2> operator[](unsigned int a) const
	{
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
	}

164
	const RefCompo2Type<T1,T2> operator[](Edge d) const
165 166 167 168 169
	{
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
	}

	static unsigned int getOrbit() { return EDGE; }
170 171
};

Pierre Kraemer's avatar
Pierre Kraemer committed
172
template <typename T1, typename T2, typename MAP_IMPL>
173 174
class Face2Attributes
{
Pierre Kraemer's avatar
Pierre Kraemer committed
175 176
	FaceAttribute<T1, MAP_IMPL>& m_h1;
	FaceAttribute<T2, MAP_IMPL>& m_h2;
177
public:
Sylvain Thery's avatar
Sylvain Thery committed
178 179
	typedef Compo2Type<T1,T2> DATA_TYPE;
	typedef RefCompo2Type<T1,T2> REF_DATA_TYPE;
180

Pierre Kraemer's avatar
Pierre Kraemer committed
181
	Face2Attributes(FaceAttribute<T1, MAP_IMPL>& h1, FaceAttribute<T2, MAP_IMPL>& h2):
182 183 184
		m_h1(h1), m_h2(h2) {}

	RefCompo2Type<T1,T2> operator[](unsigned int a)
185
	{
186
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
187 188
	}

189
	RefCompo2Type<T1,T2> operator[](Face d)
190
	{
191
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
192
	}
Sylvain Thery's avatar
Sylvain Thery committed
193 194 195 196 197 198

	const RefCompo2Type<T1,T2> operator[](unsigned int a) const
	{
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
	}

199
	const RefCompo2Type<T1,T2> operator[](Face d) const
Sylvain Thery's avatar
Sylvain Thery committed
200 201 202 203
	{
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
	}

204
	static unsigned int getOrbit() { return FACE; }
205 206
};

Pierre Kraemer's avatar
Pierre Kraemer committed
207
template <typename T1, typename T2, typename MAP_IMPL>
208 209
class Volume2Attributes
{
Pierre Kraemer's avatar
Pierre Kraemer committed
210 211
	VolumeAttribute<T1, MAP_IMPL>& m_h1;
	VolumeAttribute<T2, MAP_IMPL>& m_h2;
212
public:
Sylvain Thery's avatar
Sylvain Thery committed
213 214
	typedef Compo2Type<T1,T2> DATA_TYPE;
	typedef RefCompo2Type<T1,T2> REF_DATA_TYPE;
215

Pierre Kraemer's avatar
Pierre Kraemer committed
216
	 Volume2Attributes(VolumeAttribute<T1, MAP_IMPL>& h1, VolumeAttribute<T2, MAP_IMPL>& h2):
217
		m_h1(h1), m_h2(h2) {}
218

219
	RefCompo2Type<T1,T2> operator[](unsigned int a)
220
	{
221
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
222 223
	}

224
	RefCompo2Type<T1,T2> operator[](Vol d)
225
	{
226
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
227
	}
Sylvain Thery's avatar
Sylvain Thery committed
228 229 230 231 232 233

	const RefCompo2Type<T1,T2> operator[](unsigned int a) const
	{
		return RefCompo2Type<T1,T2>(m_h1[a],m_h2[a]);
	}

234
	const RefCompo2Type<T1,T2> operator[](Vol d) const
Sylvain Thery's avatar
Sylvain Thery committed
235 236 237
	{
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
	}
238 239 240

	static unsigned int getOrbit() { return VOLUME; }

241 242 243
};


244 245
/// implementation

246
template < typename T1, typename T2>
247
Compo2Type<T1,T2>::Compo2Type(const RefCompo2Type<T1,T2>& v)
248
{
249 250 251 252 253 254 255 256 257 258
	m_v1 = v.m_v1;
	m_v2 = v.m_v2;
}

template < typename T1, typename T2>
Compo2Type<T1,T2>& Compo2Type<T1,T2>::operator =(const Compo2Type<T1,T2>& comp)
{
	m_v1 = comp.m_v1;
	m_v2 = comp.m_v2;
	return *this;
259
}
260

261
template < typename T1, typename T2>
262
Compo2Type<T1,T2> Compo2Type<T1,T2>::operator+(const Compo2Type<T1,T2>& v) const
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
{
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 + v.m_v1;
	res.m_v2 = this->m_v2 + v.m_v2;
	return res ;
}

template < typename T1, typename T2>
Compo2Type<T1,T2> Compo2Type<T1,T2>::operator-(const Compo2Type<T1,T2>& v) const
{
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 - v.m_v1;
	res.m_v2 = this->m_v2 - v.m_v2;
	return res ;
}

template < typename T1, typename T2>
Compo2Type<T1,T2> Compo2Type<T1,T2>::operator/(double d) const
{
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 / d;
	res.m_v2 = this->m_v2 / d;
	return res ;
}

template < typename T1, typename T2>
Compo2Type<T1,T2> Compo2Type<T1,T2>::operator*(double d) const
{
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 * d;
	res.m_v2 = this->m_v2 * d;
	return res ;
}

template < typename T1, typename T2>
Compo2Type<T1,T2>& Compo2Type<T1,T2>::operator+=(const Compo2Type<T1,T2>& v)
{
	m_v1 += v.m_v1;
	m_v2 += v.m_v2;
	return *this;
}

template < typename T1, typename T2>
Compo2Type<T1,T2>& Compo2Type<T1,T2>::operator-=(const Compo2Type<T1,T2>& v)
{
308 309
	m_v1 -= v.m_v1;
	m_v2 -= v.m_v2;
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
	return *this;
}

template < typename T1, typename T2>
Compo2Type<T1,T2>& Compo2Type<T1,T2>::operator*=(double d)
{
	m_v1 *= d;
	m_v2 *= d;
	return *this;
}

template < typename T1, typename T2>
Compo2Type<T1,T2>& Compo2Type<T1,T2>::operator/=(double d)
{
	m_v1 /= d;
	m_v2 /= d;
	return *this;
}

329
/// Ref version
330

331 332 333 334
template < typename T1, typename T2>
RefCompo2Type<T1,T2>::RefCompo2Type (Compo2Type<T1,T2>& comp):
	m_v1(comp.m_v1),
	m_v2(comp.m_v2)
335
{
336
}
337

338 339 340 341 342 343 344
template < typename T1, typename T2>
RefCompo2Type<T1,T2>& RefCompo2Type<T1,T2>::operator=(const RefCompo2Type<T1,T2>& v)
{
	m_v1 = v.m_v1;
	m_v2 = v.m_v2;
	return *this;
}
345

Sylvain Thery's avatar
Sylvain Thery committed
346 347 348 349 350 351 352 353
template < typename T1, typename T2>
RefCompo2Type<T1,T2>& RefCompo2Type<T1,T2>::operator=(Compo2Type<T1,T2>  v)
{
	m_v1 = v.m_v1;
	m_v2 = v.m_v2;
	return *this;
}

354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
template < typename T1, typename T2>
Compo2Type<T1,T2> RefCompo2Type<T1,T2>::operator+(const RefCompo2Type<T1,T2>& v) const
{
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 + v.m_v1;
	res.m_v2 = this->m_v2 + v.m_v2;
	return res ;
}

template < typename T1, typename T2>
Compo2Type<T1,T2> RefCompo2Type<T1,T2>::operator-(const RefCompo2Type<T1,T2>& v) const
{
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 - v.m_v1;
	res.m_v2 = this->m_v2 - v.m_v2;
	return res ;
}
371

372 373
template < typename T1, typename T2>
Compo2Type<T1,T2> RefCompo2Type<T1,T2>::operator/(double d) const
374
{
375 376 377 378 379
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 / d;
	res.m_v2 = this->m_v2 / d;
	return res ;
}
380

381 382 383 384 385 386 387 388
template < typename T1, typename T2>
Compo2Type<T1,T2> RefCompo2Type<T1,T2>::operator*(double d) const
{
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 * d;
	res.m_v2 = this->m_v2 * d;
	return res ;
}
389

390 391 392 393 394 395 396
template < typename T1, typename T2>
RefCompo2Type<T1,T2>& RefCompo2Type<T1,T2>::operator+=(const RefCompo2Type<T1,T2>& v)
{
	m_v1 += v.m_v1;
	m_v2 += v.m_v2;
	return *this;
}
397

398 399
template < typename T1, typename T2>
RefCompo2Type<T1,T2>& RefCompo2Type<T1,T2>::operator-=(const RefCompo2Type<T1,T2>& v)
400
{
401 402 403 404
	m_v1 -= v.m_v1;
	m_v2 -= v.m_v2;
	return *this;
}
405

406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
template < typename T1, typename T2>
RefCompo2Type<T1,T2>& RefCompo2Type<T1,T2>::operator*=(double d)
{
	m_v1 *= d;
	m_v2 *= d;
	return *this;
}

template < typename T1, typename T2>
RefCompo2Type<T1,T2>& RefCompo2Type<T1,T2>::operator/=(double d)
{
	m_v1 /= d;
	m_v2 /= d;
	return *this;
}

422 423 424
} // namespace CGoGN

#endif /* MULTIATTRIBS_H_ */