localFrame.h 4.06 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __ALGO_GEOMETRY_LOCALFRAME_H__
#define __ALGO_GEOMETRY_LOCALFRAME_H__

#include "Geometry/basic.h"
#include "Geometry/matrix.h"
#include "Algo/Geometry/basic.h"
#include "Algo/Geometry/normal.h"

namespace CGoGN
{

namespace Algo
{

namespace Geometry
{

// compute a local frame on the vertex of dart d

template <typename PFP>
45
void vertexLocalFrame(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position, typename PFP::VEC3& X, typename PFP::VEC3& Y, typename PFP::VEC3& Z)
Pierre Kraemer's avatar
Pierre Kraemer committed
46
{
47 48
	Z = Algo::Surface::Geometry::vertexNormal<PFP>(map, d, position) ;
	X = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, d, position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51 52 53 54 55
	Y = Z ^ X ;
	Y.normalize() ;
	X = Y ^ Z ;
	X.normalize() ;
}

template <typename PFP>
56
typename PFP::MATRIX33 vertexLocalFrame(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position)
Pierre Kraemer's avatar
Pierre Kraemer committed
57 58
{
	typename PFP::VEC3 X, Y, Z ;
59
	vertexLocalFrame<PFP>(map, d, position, X, Y, Z) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
60 61 62 63 64 65 66 67 68 69
	typename PFP::MATRIX33 frame ;
	frame(0,0) = X[0] ;	frame(0,1) = X[1] ;	frame(0,2) = X[2] ;
	frame(1,0) = Y[0] ;	frame(1,1) = Y[1] ;	frame(1,2) = Y[2] ;
	frame(2,0) = Z[0] ;	frame(2,1) = Z[1] ;	frame(2,2) = Z[2] ;
	return frame ;
}

// compute a local frame on the vertex of dart d with a prescribed normal vector

template <typename PFP>
70
void vertexLocalFrame(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position, typename PFP::VEC3& normal, typename PFP::VEC3& X, typename PFP::VEC3& Y, typename PFP::VEC3& Z)
Pierre Kraemer's avatar
Pierre Kraemer committed
71 72
{
	Z = normal ;
73
	X = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, d, position) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
74 75 76 77 78 79 80
	Y = Z ^ X ;
	Y.normalize() ;
	X = Y ^ Z ;
	X.normalize() ;
}

template <typename PFP>
81
typename PFP::MATRIX33 vertexLocalFrame(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position, typename PFP::VEC3& normal)
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83
{
	typename PFP::VEC3 X, Y, Z ;
84
	vertexLocalFrame<PFP>(map, d, position, normal, X, Y, Z) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98
	typename PFP::MATRIX33 frame ;
	frame(0,0) = X[0] ;	frame(0,1) = X[1] ;	frame(0,2) = X[2] ;
	frame(1,0) = Y[0] ;	frame(1,1) = Y[1] ;	frame(1,2) = Y[2] ;
	frame(2,0) = Z[0] ;	frame(2,1) = Z[1] ;	frame(2,2) = Z[2] ;
	return frame ;
}

} // namespace Geometry

} // namespace Algo

} // namespace CGoGN

#endif