mcCrackenJoy.h 10.2 KB
Newer Older
untereiner's avatar
untereiner committed
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
/*******************************************************************************
* 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 __3MR_MCCRACKENJOY_MASK__
#define __3MR_MCCRACKENJOY_MASK__

#include <cmath>
#include "Algo/Geometry/centroid.h"

namespace CGoGN
{

namespace Algo
{

37 38 39
namespace Volume
{

untereiner's avatar
untereiner committed
40 41 42 43 44 45 46 47 48
namespace MR
{

namespace Primal
{

namespace Masks
{

49

50 51 52

/* MJ96 basic functions : polyhedral meshes
 *********************************************************************************/
untereiner's avatar
untereiner committed
53
template <typename PFP, typename EMBV>
untereiner's avatar
untereiner committed
54 55 56
class MJ96VertexVertexFunctor : public FunctorType
{
protected:
untereiner's avatar
untereiner committed
57
    typedef typename EMBV::DATA_TYPE EMB;
untereiner's avatar
untereiner committed
58
	typename PFP::MAP& m_map ;
59 60
	EMBV& m_attribut;
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
61
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
untereiner's avatar
untereiner committed
62 63

public:
64
	//MJ96VertexVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
65 66
	//MJ96VertexVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
	MJ96VertexVertexFunctor(typename PFP::MAP& m, EMBV& p) : m_map(m), m_attribut(p)
untereiner's avatar
untereiner committed
67 68 69 70 71 72
	{}

	bool operator() (Dart d)
	{
		if(m_map.isBoundaryVertex(d))
		{
73 74
			Dart db = m_map.findBoundaryFaceOfVertex(d);

75 76
			m_map.decCurrentLevel() ;

77 78
			EMB np1(0.0) ;
			EMB np2(0.0) ;
untereiner's avatar
untereiner committed
79 80 81 82 83 84 85
			unsigned int degree1 = 0 ;
			unsigned int degree2 = 0 ;
			Dart it = db ;
			do
			{
				++degree1 ;
				Dart dd = m_map.phi1(it) ;
86
				np1 += m_attribut[dd] ;
untereiner's avatar
untereiner committed
87 88 89 90 91
				Dart end = m_map.phi_1(it) ;
				dd = m_map.phi1(dd) ;
				do
				{
					++degree2 ;
92
					np2 += m_attribut[dd] ;
untereiner's avatar
untereiner committed
93 94 95 96 97 98 99 100 101 102
					dd = m_map.phi1(dd) ;
				} while(dd != end) ;
				it = m_map.phi2(m_map.phi_1(it)) ;
			} while(it != db) ;

			float beta = 3.0 / (2.0 * degree1) ;
			float gamma = 1.0 / (4.0 * degree2) ;
			np1 *= beta / degree1 ;
			np2 *= gamma / degree2 ;

103
			EMB vp = m_attribut[db] ;
untereiner's avatar
untereiner committed
104 105 106 107
			vp *= 1.0 - beta - gamma ;

			m_map.incCurrentLevel() ;

108
			m_attribut[d] = np1 + np2 + vp ;
untereiner's avatar
untereiner committed
109 110 111
		}
		else
		{
112 113
			m_map.decCurrentLevel() ;

114
			EMB P = m_attribut[d];
untereiner's avatar
untereiner committed
115 116

			//vertex points
117
			EMB Cavg = EMB(0);
118 119 120 121
			unsigned int degree = 0;
			Traversor3VW<typename PFP::MAP> travVW(m_map, d);
			for(Dart dit = travVW.begin() ; dit != travVW.end() ; dit = travVW.next())
			{
untereiner's avatar
untereiner committed
122
                Cavg += Algo::Surface::Geometry::volumeCentroid<PFP, EMBV>(m_map, dit, m_attribut);
123 124
				++degree;
			}
untereiner's avatar
untereiner committed
125 126
			Cavg /= degree;

127
			EMB Aavg(0.0);
128 129 130 131
			degree = 0;
			Traversor3VF<typename PFP::MAP> travVF(m_map, d);
			for(Dart dit = travVF.begin() ; dit != travVF.end() ; dit = travVF.next())
			{
untereiner's avatar
untereiner committed
132
                Aavg += Algo::Surface::Geometry::faceCentroid<PFP, EMBV>(m_map, dit, m_attribut);
133 134
				++degree;
			}
untereiner's avatar
untereiner committed
135 136
			Aavg /= degree;

137
			EMB Mavg(0.0);
138 139 140 141 142
			degree = 0;
			Traversor3VE<typename PFP::MAP> travVE(m_map, d);
			for(Dart dit = travVE.begin() ; dit != travVE.end() ; dit = travVE.next())
			{
				Dart d2 = m_map.phi2(dit);
143
				Mavg += (m_attribut[dit] + m_attribut[d2]) * typename PFP::REAL(0.5);
144 145
				++degree;
			}
146
			Mavg /= degree;
untereiner's avatar
untereiner committed
147

148
			EMB vp = Cavg + Aavg * 3 + Mavg * 3 + P;
untereiner's avatar
untereiner committed
149 150 151 152
			vp /= 8;

			m_map.incCurrentLevel() ;

153
			m_attribut[d] = vp;
untereiner's avatar
untereiner committed
154 155 156 157 158 159
		}

		return false;
	}
};

untereiner's avatar
untereiner committed
160
template <typename PFP, typename EMBV>
untereiner's avatar
untereiner committed
161 162 163
class MJ96EdgeVertexFunctor : public FunctorType
{
protected:
untereiner's avatar
untereiner committed
164
    typedef typename EMBV::DATA_TYPE EMB;
untereiner's avatar
untereiner committed
165
	typename PFP::MAP& m_map ;
166 167
	EMBV& m_attribut;
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
168
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
untereiner's avatar
untereiner committed
169 170

public:
171
	//MJ96EdgeVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
172 173
	//MJ96EdgeVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
	MJ96EdgeVertexFunctor(typename PFP::MAP& m, EMBV& p) : m_map(m), m_attribut(p)
untereiner's avatar
untereiner committed
174 175 176 177 178 179 180 181 182 183
	{}

	bool operator() (Dart d)
	{
		if(m_map.isBoundaryEdge(d))
		{
			Dart db = m_map.findBoundaryFaceOfEdge(d);

			Dart d1 = m_map.phi2(db) ;

184
			m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
185 186 187 188 189 190 191

			Dart d2 = m_map.phi2(d1) ;
			Dart d3 = m_map.phi_1(d1) ;
			Dart d4 = m_map.phi_1(d2) ;
			Dart d5 = m_map.phi1(m_map.phi1(d1)) ;
			Dart d6 = m_map.phi1(m_map.phi1(d2)) ;

192 193 194 195 196 197
			EMB p1 = m_attribut[d1] ;
			EMB p2 = m_attribut[d2] ;
			EMB p3 = m_attribut[d3] ;
			EMB p4 = m_attribut[d4] ;
			EMB p5 = m_attribut[d5] ;
			EMB p6 = m_attribut[d6] ;
untereiner's avatar
untereiner committed
198 199 200 201 202 203 204 205

			p1 *= 3.0 / 8.0 ;
			p2 *= 3.0 / 8.0 ;
			p3 *= 1.0 / 16.0 ;
			p4 *= 1.0 / 16.0 ;
			p5 *= 1.0 / 16.0 ;
			p6 *= 1.0 / 16.0 ;

206
			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
207

208
			m_attribut[d] = p1 + p2 + p3 + p4 + p5 + p6 ;
untereiner's avatar
untereiner committed
209 210 211 212 213
		}
		else
		{
			Dart d2 = m_map.phi2(d);

214 215
			m_map.decCurrentLevel() ;

untereiner's avatar
untereiner committed
216
			//edge points
217
			EMB Cavg(0.0);
untereiner's avatar
untereiner committed
218 219 220 221
			unsigned int degree = 0;
			Traversor3EW<typename PFP::MAP> travEW(m_map, d2);
			for(Dart dit = travEW.begin() ; dit != travEW.end() ; dit = travEW.next())
			{
untereiner's avatar
untereiner committed
222
                Cavg += Algo::Surface::Geometry::volumeCentroid<PFP, EMBV>(m_map, dit, m_attribut);
untereiner's avatar
untereiner committed
223 224 225 226
				++degree;
			}
			Cavg /= degree;

227
			EMB Aavg(0.0);
untereiner's avatar
untereiner committed
228 229 230 231
			degree = 0;
			Traversor3EF<typename PFP::MAP> travEF(m_map, d2);
			for(Dart dit = travEF.begin() ; dit != travEF.end() ; dit = travEF.next())
			{
untereiner's avatar
untereiner committed
232
                Aavg += Algo::Surface::Geometry::faceCentroid<PFP, EMBV>(m_map, dit, m_attribut);
untereiner's avatar
untereiner committed
233 234 235 236 237
				++degree;
			}
			Aavg /= degree;

			Dart d22 = m_map.phi2(d2);
238
			EMB M = (m_attribut[d2] + m_attribut[d22]) * typename PFP::REAL(0.5);
untereiner's avatar
untereiner committed
239

240
			EMB ep = Cavg + Aavg * 2 + M * (degree - 3);
untereiner's avatar
untereiner committed
241 242
			ep /= degree;

243
			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
244

245
			m_attribut[d] = ep;
untereiner's avatar
untereiner committed
246 247 248 249 250 251
		}

		return false;
	}
};

untereiner's avatar
untereiner committed
252
template <typename PFP, typename EMBV>
untereiner's avatar
untereiner committed
253 254 255
class MJ96FaceVertexFunctor : public FunctorType
{
protected:
untereiner's avatar
untereiner committed
256
    typedef typename EMBV::DATA_TYPE EMB;
untereiner's avatar
untereiner committed
257
	typename PFP::MAP& m_map ;
258 259
	EMBV& m_attribut;
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
260
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
untereiner's avatar
untereiner committed
261 262

public:
263
	//MJ96FaceVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
264 265
	//MJ96FaceVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
	MJ96FaceVertexFunctor(typename PFP::MAP& m, EMBV& p) : m_map(m), m_attribut(p)
untereiner's avatar
untereiner committed
266 267 268 269
	{}

	bool operator() (Dart d)
	{
270
		if(m_map.isBoundaryFace(d))
untereiner's avatar
untereiner committed
271
		{
272
			Dart db = m_map.phi_1(m_map.phi3(d));
untereiner's avatar
untereiner committed
273

274
			m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
275

276
			EMB p(0.0) ;
untereiner's avatar
untereiner committed
277
			unsigned int degree = 0 ;
278
			Traversor2FV<typename PFP::MAP> trav(m_map, db) ;
untereiner's avatar
untereiner committed
279 280 281
			for(Dart it = trav.begin(); it != trav.end(); it = trav.next())
			{
				++degree ;
282
				p += m_attribut[it] ;
untereiner's avatar
untereiner committed
283 284 285
			}
			p /= degree ;

286
			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
287

288
			m_attribut[d] = p ;
untereiner's avatar
untereiner committed
289 290 291
		}
		else
		{
292
			Dart df = m_map.phi1(m_map.phi1(d)) ;
293 294

			m_map.decCurrentLevel() ;
untereiner's avatar
untereiner committed
295

296
			//face points
untereiner's avatar
untereiner committed
297 298
            EMB C0 = Algo::Surface::Geometry::volumeCentroid<PFP, EMBV>(m_map, df, m_attribut);
            EMB C1 = Algo::Surface::Geometry::volumeCentroid<PFP, EMBV>(m_map, m_map.phi3(df), m_attribut);
299

untereiner's avatar
untereiner committed
300
            EMB A = Algo::Surface::Geometry::faceCentroid<PFP, EMBV>(m_map, df, m_attribut);
301

302
			EMB fp = C0 + A * 2 + C1;
303 304
			fp /= 4;

305
			m_map.incCurrentLevel() ;
untereiner's avatar
untereiner committed
306

307
			m_attribut[d] = fp;
untereiner's avatar
untereiner committed
308 309 310 311 312 313 314
		}

		return false;
	}

};

untereiner's avatar
untereiner committed
315
template <typename PFP, typename EMBV>
untereiner's avatar
untereiner committed
316 317 318
class MJ96VolumeVertexFunctor : public FunctorType
{
protected:
untereiner's avatar
untereiner committed
319
    typedef typename EMBV::DATA_TYPE EMB;
untereiner's avatar
untereiner committed
320
	typename PFP::MAP& m_map ;
321 322
	EMBV& m_attribut;
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
323
	//Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& m_position ;
untereiner's avatar
untereiner committed
324 325

public:
326
	//MJ96VolumeVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
327 328
	//MJ96VolumeVertexFunctor(typename PFP::MAP& m, Algo::Volume::IHM::AttributeHandler_IHM<typename PFP::VEC3, VERTEX>& p) : m_map(m), m_position(p)
	MJ96VolumeVertexFunctor(typename PFP::MAP& m, EMBV& p) : m_map(m), m_attribut(p)
untereiner's avatar
untereiner committed
329 330 331 332 333 334 335
	{}

	bool operator() (Dart d)
	{
		Dart df = m_map.phi_1(m_map.phi2(m_map.phi1(d))) ;

		m_map.decCurrentLevel() ;
336

untereiner's avatar
untereiner committed
337 338
		//cell points : these points are the average of the
		//vertices of the lattice that bound the cell
untereiner's avatar
untereiner committed
339
        EMB p = Algo::Surface::Geometry::volumeCentroid<PFP, EMBV>(m_map,df,m_attribut);
340

untereiner's avatar
untereiner committed
341 342
		m_map.incCurrentLevel() ;

343
		m_attribut[d] = p;
untereiner's avatar
untereiner committed
344 345 346 347 348

		return false;
	}
};

349 350 351



untereiner's avatar
untereiner committed
352 353 354 355 356 357
} // namespace Masks

} // namespace Primal

} // namespace MR

358 359
} // namespace Volume

untereiner's avatar
untereiner committed
360 361 362 363 364 365
} // namespace Algo

} // namespace CGoGN


#endif /* __3MR_FUNCTORS_PRIMAL__ */