sqrt3.h 4.47 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
/*******************************************************************************
* 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 __MR_SQRT3_MASK__
#define __MR_SQRT3_MASK__

#include <cmath>

namespace CGoGN
{

namespace Algo
{

namespace MR
{

namespace Primal
{

namespace Masks
{


template <typename PFP>
class Sqrt3VertexVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
51
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& m_position ;
52 53

public:
54
	Sqrt3VertexVertexFunctor(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& p) : m_map(m), m_position(p)
55 56 57 58
	{}

	bool operator() (Dart d)
	{
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
		if(m_map.isBoundaryVertex(d))
		{
			Dart df = m_map.findBoundaryEdgeOfVertex(d);

			if(m_map.getDartLevel(df) < m_map.getCurrentLevel())
			{
				if((m_map.getCurrentLevel()%2 == 0))
				{
					m_map.decCurrentLevel() ;

					typename PFP::VEC3 np(0) ;
					typename PFP::VEC3 nl(0) ;
					typename PFP::VEC3 nr(0) ;

					typename PFP::VEC3 pi = m_position[df];
					typename PFP::VEC3 pi_1 = m_position[m_map.phi_1(df)];
					typename PFP::VEC3 pi1 = m_position[m_map.phi1(df)];

					np += pi_1 * 4 + pi * 19 + pi1 * 4;
					np /= 27;

					nl +=  pi_1 * 10 + pi * 16 + pi1;
					nl /= 27;

					nr += pi_1 + pi * 16 + pi1 * 10;
					nr /= 27;

					m_map.incCurrentLevel() ;

					m_position[df] = np;
					m_position[m_map.phi_1(df)] = nl;
					m_position[m_map.phi1(df)] = nr;

					return false;
				}
			}
		}

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
		m_map.decCurrentLevel() ;

		typename PFP::VEC3 np(0) ;
		unsigned int degree = 0 ;
		Traversor2VVaE<typename PFP::MAP> trav(m_map, d) ;
		for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
		{
			++degree ;
			np += m_position[it] ;
		}
		float alpha = 1.0/9.0 * ( 4.0 - 2.0 * cos(2.0 * M_PI / degree));
		np *= alpha / degree ;

		typename PFP::VEC3 vp = m_position[d] ;
		vp *= 1.0 - alpha ;

		m_map.incCurrentLevel() ;

		m_position[d] = np + vp ;

		return false ;
	}
} ;

template <typename PFP>
class Sqrt3FaceVertexFunctor : public FunctorType
{
protected:
	typename PFP::MAP& m_map ;
126
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& m_position ;
127 128

public:
129
	Sqrt3FaceVertexFunctor(typename PFP::MAP& m, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& p) : m_map(m), m_position(p)
130 131 132 133 134 135 136 137
	{}

	bool operator() (Dart d)
	{
		Dart d0 = m_map.phi1(d) ;

		m_map.decCurrentLevel() ;

138 139
		Dart d1 = m_map.phi1(d0) ;
		Dart d2 = m_map.phi1(d1) ;
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

		typename PFP::VEC3 p0 = m_position[d0] ;
		typename PFP::VEC3 p1 = m_position[d1] ;
		typename PFP::VEC3 p2 = m_position[d2] ;

		p0 *= 1.0 / 3.0 ;
		p1 *= 1.0 / 3.0 ;
		p2 *= 1.0 / 3.0 ;

		m_map.incCurrentLevel() ;

		m_position[d] = p0 + p1 + p2;

		return false ;
	}
} ;

} // namespace Masks

} // namespace Primal

} // namespace MR

} // namespace Algo

} // namespace CGoGN

#endif