multiAttribs.h 8.37 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 30 31 32 33 34 35 36 37 38 39 40 41 42 43

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) {}
44
	Compo2Type(const RefCompo2Type<T1,T2>& v);
45

46
	Compo2Type<T1,T2>& operator =(const Compo2Type<T1,T2>& comp);
47

48
	Compo2Type<T1,T2> operator+(const Compo2Type<T1,T2>& v) const;
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
	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) {}
66
	RefCompo2Type (Compo2Type<T1,T2>& comp);
67

68
	RefCompo2Type<T1,T2>& operator=(const RefCompo2Type<T1,T2>& v);
69

70 71 72 73 74 75 76 77 78
	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);
};
79 80 81



82 83 84 85 86 87 88 89 90 91 92 93 94
template <typename T1, typename T2>
class Vertex2Attributes
{
	VertexAttribute<T1>& m_h1;
	VertexAttribute<T2>& m_h2;
public:
	typedef Compo2Type<T1,T2> VALUE;
	typedef RefCompo2Type<T1,T2> REF;

	Vertex2Attributes(VertexAttribute<T1>& h1, VertexAttribute<T2>& h2):
		m_h1(h1), m_h2(h2) {}

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

99
	RefCompo2Type<T1,T2> operator[](Dart d)
100
	{
101
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
102
	}
103 104
};

105

106 107 108 109 110 111 112 113 114 115 116 117 118
template <typename T1, typename T2>
class Face2Attributes
{
	FaceAttribute<T1>& m_h1;
	FaceAttribute<T2>& m_h2;
public:
	typedef Compo2Type<T1,T2> VALUE;
	typedef RefCompo2Type<T1,T2> REF;

	Face2Attributes(FaceAttribute<T1>& h1, FaceAttribute<T2>& h2):
		m_h1(h1), m_h2(h2) {}

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

123
	RefCompo2Type<T1,T2> operator[](Dart d)
124
	{
125
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
126
	}
127 128 129 130 131 132 133 134 135 136 137 138 139
};

template <typename T1, typename T2>
class Volume2Attributes
{
	VolumeAttribute<T1>& m_h1;
	VolumeAttribute<T2>& m_h2;
public:
	typedef Compo2Type<T1,T2> VALUE;
	typedef RefCompo2Type<T1,T2> REF;

	 Volume2Attributes(VolumeAttribute<T1>& h1, VolumeAttribute<T2>& h2):
		m_h1(h1), m_h2(h2) {}
140

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

146
	RefCompo2Type<T1,T2> operator[](Dart d)
147
	{
148
		return RefCompo2Type<T1,T2>(m_h1[d],m_h2[d]);
149 150 151 152
	}
};


153 154
/// implementation

155 156

template < typename T1, typename T2>
157 158
Compo2Type<T1,T2>::Compo2Type(const RefCompo2Type<T1,T2>& v)

159
{
160 161 162 163 164 165 166 167 168 169 170
	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;
171
}
172 173


174
template < typename T1, typename T2>
175
Compo2Type<T1,T2> Compo2Type<T1,T2>::operator+(const Compo2Type<T1,T2>& v) const
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
{
	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)
{
222 223
	m_v1 -= v.m_v1;
	m_v2 -= v.m_v2;
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
	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;
}


245
/// Ref version
246

247 248 249 250
template < typename T1, typename T2>
RefCompo2Type<T1,T2>::RefCompo2Type (Compo2Type<T1,T2>& comp):
	m_v1(comp.m_v1),
	m_v2(comp.m_v2)
251
{
252
}
253 254


255 256 257 258 259 260 261
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;
}
262

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
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 ;
}
280 281


282 283
template < typename T1, typename T2>
Compo2Type<T1,T2> RefCompo2Type<T1,T2>::operator/(double d) const
284
{
285 286 287 288 289
	Compo2Type<T1,T2> res ;
	res.m_v1 = this->m_v1 / d;
	res.m_v2 = this->m_v2 / d;
	return res ;
}
290

291 292 293 294 295 296 297 298
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 ;
}
299

300 301 302 303 304 305 306
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;
}
307 308


309 310
template < typename T1, typename T2>
RefCompo2Type<T1,T2>& RefCompo2Type<T1,T2>::operator-=(const RefCompo2Type<T1,T2>& v)
311
{
312 313 314 315
	m_v1 -= v.m_v1;
	m_v2 -= v.m_v2;
	return *this;
}
316 317


318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
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;
}

334 335 336 337 338


} // namespace CGoGN

#endif /* MULTIATTRIBS_H_ */