feature.hpp 4.35 KB
Newer Older
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
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.u-strasbg.fr/                                         *
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

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

namespace CGoGN
{

namespace Algo
{

namespace Geometry
{

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
38
void featureEdgeDetection(typename PFP::MAP& map, typename PFP::TVEC3& position, CellMarker& featureEdge)
39 40 41 42
{
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

Pierre Kraemer's avatar
Pierre Kraemer committed
43
	featureEdge.unmarkAll() ;
44

Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47
	AttributeHandler<VEC3> fNormal = map.template getAttribute<VEC3>(FACE, "normal") ;
	if(!fNormal.isValid())
		fNormal = map.template addAttribute<VEC3>(FACE, "normal") ;
48 49
	Algo::Geometry::computeNormalFaces<PFP>(map, position, fNormal) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
50
	CellMarker m(map, EDGE) ;
51 52 53 54
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(!m.isMarked(d))
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
55
			m.mark(d) ;
56
			if(Geom::angle(fNormal[d], fNormal[map.phi2(d)]) > M_PI / REAL(6))
Pierre Kraemer's avatar
Pierre Kraemer committed
57
				featureEdge.mark(d) ;
58 59 60
		}
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
//	map.template removeAttribute<VEC3>(fNormal) ;
}

template <typename PFP>
std::vector<typename PFP::VEC3> occludingContoursDetection(typename PFP::MAP& map, const typename PFP::VEC3& viewDir, const typename PFP::TVEC3& position, const typename PFP::TVEC3& normal)
{
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

	std::vector<VEC3> occludingContours ;

	CellMarker m(map, FACE) ;
	for(Dart d = map.begin(); d != map.end(); map.next(d))
	{
		if(!m.isMarked(d))
		{
			m.mark(d) ;
			REAL dp1 = viewDir * normal[d] ;
			REAL dp2 = viewDir * normal[map.phi1(d)] ;
			REAL dp3 = viewDir * normal[map.phi_1(d)] ;
			if(dp1 < 0 && dp2 > 0)
			{
				REAL alpha = -dp1 / (-dp1 + dp2) ;
				occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi1(d)]) ;
			}
			if(dp2 < 0 && dp1 > 0)
			{
				REAL alpha = dp1 / (dp1 - dp2) ;
				occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi1(d)]) ;
			}
			if(dp1 < 0 && dp3 > 0)
			{
				REAL alpha = -dp1 / (-dp1 + dp3) ;
				occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi_1(d)]) ;
			}
			if(dp3 < 0 && dp1 > 0)
			{
				REAL alpha = dp1 / (dp1 - dp3) ;
				occludingContours.push_back(alpha * position[d] + (1 - alpha) * position[map.phi_1(d)]) ;
			}
			if(dp2 < 0 && dp3 > 0)
			{
				REAL alpha = -dp2 / (-dp2 + dp3) ;
				occludingContours.push_back(alpha * position[map.phi1(d)] + (1 - alpha) * position[map.phi_1(d)]) ;
			}
			if(dp3 < 0 && dp2 > 0)
			{
				REAL alpha = dp2 / (dp2 - dp3) ;
				occludingContours.push_back(alpha * position[map.phi1(d)] + (1 - alpha) * position[map.phi_1(d)]) ;
			}
		}
	}

	return occludingContours ;
115 116 117 118 119 120 121
}

} // namespace Geometry

} // namespace Algo

} // namespace CGoGN