/******************************************************************************* * 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 * * * *******************************************************************************/ #ifndef __MULTI3ATTRIBS_H_ #define __MULTI3ATTRIBS_H_ #include "Topology/generic/cells.h" namespace CGoGN { //forward template struct RefCompo3Type; template struct Compo3Type { T1 m_v1; T2 m_v2; T3 m_v3; Compo3Type(){} Compo3Type(double z ): m_v1(z), m_v2(z), m_v3(z) {} Compo3Type(const RefCompo3Type& v); Compo3Type& operator =(const Compo3Type& comp); Compo3Type operator+(const Compo3Type& v) const; Compo3Type operator-(const Compo3Type& v) const; Compo3Type operator/(double d) const; Compo3Type operator*(double d) const; Compo3Type& operator+=(const Compo3Type& v); Compo3Type& operator-=(const Compo3Type& v); Compo3Type& operator*=(double d); Compo3Type& operator/=(double d); }; template struct RefCompo3Type { T1& m_v1; T2& m_v2; T3& m_v3; RefCompo3Type(T1& v1, T2& v2, T3& v3): m_v1(v1), m_v2(v2), m_v3(v3) {} RefCompo3Type (Compo3Type& comp); RefCompo3Type& operator=(const RefCompo3Type& v); RefCompo3Type& operator=(Compo3Type v); Compo3Type operator+(const RefCompo3Type& v) const; Compo3Type operator-(const RefCompo3Type& v) const; Compo3Type operator/(double d) const; Compo3Type operator*(double d) const; RefCompo3Type& operator+=(const RefCompo3Type& v); RefCompo3Type& operator-=(const RefCompo3Type& v); RefCompo3Type& operator*=(double d); RefCompo3Type& operator/=(double d); }; template class Cell3Attributes: public AttributeHandlerOrbit { AttributeHandler& m_h1; AttributeHandler& m_h2; AttributeHandler& m_h3; public: typedef Compo3Type DATA_TYPE; typedef RefCompo3Type REF_DATA_TYPE; Cell3Attributes(AttributeHandler& h1, AttributeHandler& h2, AttributeHandler& h3): AttributeHandlerOrbit(true), m_h1(h1), m_h2(h2), m_h3(h3) {} static const unsigned int ORBIT = ORB; virtual int getSizeOfType() const {return m_h1.getSizeOfType()+m_h2.getSizeOfType()+m_h3.getSizeOfType(); } virtual unsigned int getOrbit() const {return ORB;} virtual const std::string& name() const { return m_h1.name(); } virtual const std::string& typeName() const { return m_h1.typeName();} virtual AttributeMultiVectorGen* getDataVectorGen() const { return NULL;} RefCompo3Type operator[](unsigned int a) { return RefCompo3Type(m_h1[a],m_h2[a],m_h3[a]); } RefCompo3Type operator[](Cell c) { return RefCompo3Type(m_h1[c],m_h2[c],m_h3[c]); } const RefCompo3Type operator[](unsigned int a) const { return RefCompo3Type(m_h1[a],m_h2[a],m_h3[a]); } const RefCompo3Type operator[](Cell c) const { return RefCompo3Type(m_h1[c],m_h2[c],m_h3[c]); } }; template using Vertex3Attributes = Cell3Attributes; template using Edge3Attributes = Cell3Attributes; template using Face3Attributes = Cell3Attributes; template using Volume3Attributes = Cell3Attributes; /// implementation template < typename T1, typename T2, typename T3> Compo3Type& Compo3Type::operator =(const Compo3Type& comp) { m_v1 = comp.m_v1; m_v2 = comp.m_v2; m_v3 = comp.m_v3; return *this; } template < typename T1, typename T2, typename T3> Compo3Type::Compo3Type(const RefCompo3Type &v) { m_v1 = v.m_v1; m_v2 = v.m_v2; m_v3 = v.m_v3; } template < typename T1, typename T2, typename T3> Compo3Type Compo3Type::operator+(const Compo3Type& v) const { Compo3Type res ; res.m_v1 = this->m_v1 + v.m_v1; res.m_v2 = this->m_v2 + v.m_v2; res.m_v3 = this->m_v3 + v.m_v3; return res ; } template < typename T1, typename T2, typename T3> Compo3Type Compo3Type::operator-(const Compo3Type& v) const { Compo3Type res ; res.m_v1 = this->m_v1 - v.m_v1; res.m_v2 = this->m_v2 - v.m_v2; res.m_v3 = this->m_v3 - v.m_v3; return res ; } template < typename T1, typename T2, typename T3> Compo3Type Compo3Type::operator/(double d) const { Compo3Type res ; res.m_v1 = this->m_v1 / d; res.m_v2 = this->m_v2 / d; res.m_v3 = this->m_v3 / d; return res ; } template < typename T1, typename T2, typename T3> Compo3Type Compo3Type::operator*(double d) const { Compo3Type res ; res.m_v1 = this->m_v1 * d; res.m_v2 = this->m_v2 * d; res.m_v3 = this->m_v3 * d; return res ; } template < typename T1, typename T2, typename T3> Compo3Type& Compo3Type::operator+=(const Compo3Type& v) { m_v1 += v.m_v1; m_v2 += v.m_v2; m_v3 += v.m_v3; return *this; } template < typename T1, typename T2, typename T3> Compo3Type& Compo3Type::operator-=(const Compo3Type& v) { m_v1 += v.m_v1; m_v2 -= v.m_v2; m_v3 -= v.m_v3; return *this; } template < typename T1, typename T2, typename T3> Compo3Type& Compo3Type::operator*=(double d) { m_v1 *= d; m_v2 *= d; m_v3 *= d; return *this; } template < typename T1, typename T2, typename T3> Compo3Type& Compo3Type::operator/=(double d) { m_v1 /= d; m_v2 /= d; m_v3 /= d; return *this; } /// Ref version template < typename T1, typename T2, typename T3> RefCompo3Type::RefCompo3Type (Compo3Type& comp): m_v1(comp.m_v1), m_v2(comp.m_v2), m_v3(comp.m_v3) { } template < typename T1, typename T2, typename T3> RefCompo3Type& RefCompo3Type::operator=(const RefCompo3Type& v) { m_v1 = v.m_v1; m_v2 = v.m_v2; m_v3 = v.m_v3; return *this; } template < typename T1, typename T2, typename T3> RefCompo3Type& RefCompo3Type::operator=(Compo3Type v) { m_v1 = v.m_v1; m_v2 = v.m_v2; m_v3 = v.m_v3; return *this; } template < typename T1, typename T2, typename T3> Compo3Type RefCompo3Type::operator+(const RefCompo3Type& v) const { Compo3Type res ; res.m_v1 = this->m_v1 + v.m_v1; res.m_v2 = this->m_v2 + v.m_v2; res.m_v3 = this->m_v3 + v.m_v3; return res ; } template < typename T1, typename T2, typename T3> Compo3Type RefCompo3Type::operator-(const RefCompo3Type& v) const { Compo3Type res ; res.m_v1 = this->m_v1 - v.m_v1; res.m_v2 = this->m_v2 - v.m_v2; res.m_v3 = this->m_v3 - v.m_v3; return res ; } template < typename T1, typename T2, typename T3> Compo3Type RefCompo3Type::operator/(double d) const { Compo3Type res ; res.m_v1 = this->m_v1 / d; res.m_v2 = this->m_v2 / d; res.m_v3 = this->m_v3 / d; return res ; } template < typename T1, typename T2, typename T3> Compo3Type RefCompo3Type::operator*(double d) const { Compo3Type res ; res.m_v1 = this->m_v1 * d; res.m_v2 = this->m_v2 * d; res.m_v3 = this->m_v3 * d; return res ; } template < typename T1, typename T2, typename T3> RefCompo3Type& RefCompo3Type::operator+=(const RefCompo3Type& v) { m_v1 += v.m_v1; m_v2 += v.m_v2; m_v3 += v.m_v3; return *this; } template < typename T1, typename T2, typename T3> RefCompo3Type& RefCompo3Type::operator-=(const RefCompo3Type& v) { m_v1 -= v.m_v1; m_v2 -= v.m_v2; m_v3 -= v.m_v3; return *this; } template < typename T1, typename T2, typename T3> RefCompo3Type& RefCompo3Type::operator*=(double d) { m_v1 *= d; m_v2 *= d; m_v3 *= d; return *this; } template < typename T1, typename T2, typename T3> RefCompo3Type& RefCompo3Type::operator/=(double d) { m_v1 /= d; m_v2 /= d; m_v3 /= d; return *this; } } // namespace CGoGN #endif /* MULTIATTRIBS_H_ */