drawerCells.hpp 6.86 KB
Newer Older
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           *
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/                                           *
21 22 23 24
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

25 26
#include "Geometry/vector_gen.h"

27 28
namespace CGoGN
{
Pierre Kraemer's avatar
Pierre Kraemer committed
29

30 31
namespace Algo
{
Pierre Kraemer's avatar
Pierre Kraemer committed
32

33 34 35 36
namespace Render
{

template<typename PFP>
37
void drawerAddEdge(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, float k)
38
{
39 40

	const Geom::Vec3f& P = PFP::toVec3f(positions[d]);
41
	Dart e = map.phi1(d);
42
	const Geom::Vec3f& Q = PFP::toVec3f(positions[e]);
43

44
	Geom::Vec3f C = (P+Q)/ typename PFP::REAL(2.0);
45 46 47 48 49 50

	dr.vertex(C*(1.0f-k) + k*P);
	dr.vertex(C*(1.0f-k) + k*Q);
}

template<typename PFP>
51
void drawerAddEdgeShrink(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, const typename PFP::VEC3& C, float k)
52
{
53
	const Geom::Vec3f& P = PFP::toVec3f(positions[d]);
54
	Dart e = map.phi1(d);
55
	const Geom::Vec3f& Q = PFP::toVec3f(positions[e]);
56 57 58 59 60 61

	dr.vertex(C*(1.0f-k) + k*P);
	dr.vertex(C*(1.0f-k) + k*Q);
}

template<typename PFP>
62
void drawerAddFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, float k)
63
{
64
	Geom::Vec3f C = PFP::toVec3f(Algo::Surface::Geometry::faceCentroid<PFP>(map,d,positions));
65 66 67 68 69 70 71 72 73

	Traversor2FE<typename PFP::MAP> trav(map,d);
	for (Dart e=trav.begin(); e!=trav.end(); e=trav.next())
	{
		drawerAddEdgeShrink<PFP>(dr,map,e,positions,C,k);
	}
}

template<typename PFP>
74
void drawerAddVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions,float k)
75
{
76
	Geom::Vec3f C = PFP::toVec3f(Algo::Surface::Geometry::volumeCentroid<PFP>(map,d,positions));
77 78 79 80 81 82 83

	Traversor3WE<typename PFP::MAP> trav(map,d);
	for (Dart e=trav.begin(); e!=trav.end(); e=trav.next())
		drawerAddEdgeShrink<PFP>(dr,map,e,positions,C,k);
}

template<typename PFP>
84
void drawerVertices(Utils::Drawer& dr, typename PFP::MAP& /*map*/, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions)
85 86 87 88 89 90 91 92
{
	dr.begin(GL_POINTS);
	for (std::vector<Dart>::iterator it = vd.begin(); it !=vd.end(); ++it)
		dr.vertex(positions[*it]);
	dr.end();
}

template<typename PFP>
93
void drawerEdges(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions,float k)
94 95 96 97 98 99 100 101
{
	dr.begin(GL_LINES);
	for (std::vector<Dart>::iterator it = vd.begin(); it !=vd.end(); ++it)
		drawerAddEdge<PFP>(dr,map,*it,positions,k);
	dr.end();
}

template<typename PFP>
102
void drawerFaces(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions,float k)
103 104 105 106 107 108 109
{
	dr.begin(GL_LINES);
	for (std::vector<Dart>::iterator it = vd.begin(); it !=vd.end(); ++it)
		drawerAddFace<PFP>(dr,map,*it,positions,k);
	dr.end();
}
template<typename PFP>
110
void drawerVolumes(Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions,float k)
111 112 113 114 115 116 117 118
{
	dr.begin(GL_LINES);
	for (std::vector<Dart>::iterator it = vd.begin(); it !=vd.end(); ++it)
		drawerAddVolume<PFP>(dr,map,*it,positions,k);
	dr.end();
}

template<typename PFP>
119
void drawerVertex(Utils::Drawer& dr, typename PFP::MAP& /*map*/, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions)
120 121 122 123 124 125 126
{
	dr.begin(GL_POINTS);
	dr.vertex(positions[d]);
	dr.end();
}

template<typename PFP>
127
void drawerEdge(Utils::Drawer& dr, typename PFP::MAP& map,  Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions,float k)
128 129 130 131 132 133 134
{
	dr.begin(GL_LINES);
	drawerAddEdge<PFP>(dr,map,d,positions,k);
	dr.end();
}

template<typename PFP>
135
void drawerFace(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions,float k)
136 137 138 139 140 141 142
{
	dr.begin(GL_LINES);
	drawerAddFace<PFP>(dr,map,d,positions,k);
	dr.end();
}

template<typename PFP>
143
void drawerVolume(Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions,float k)
144 145 146 147 148
{
	dr.begin(GL_LINES);
	drawerAddVolume<PFP>(dr,map,d,positions,k);
	dr.end();
}
Pierre Kraemer's avatar
Pierre Kraemer committed
149

Sylvain Thery's avatar
Sylvain Thery committed
150
template<typename PFP>
151
void drawerCells(unsigned int cell, Utils::Drawer& dr, typename PFP::MAP& map, std::vector<Dart>& vd, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, float k)
Sylvain Thery's avatar
Sylvain Thery committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
{
	switch(cell)
	{
	case VERTEX:
		drawerVertices<PFP>(dr, map, vd, positions);
		break;
	case EDGE:
		drawerEdges<PFP>(dr, map, vd, positions,k);
		break;
	case FACE:
		drawerFaces<PFP>(dr, map, vd, positions,k);
		break;
	case VOLUME:
		drawerVolumes<PFP>(dr, map, vd, positions,k);
		break;
	default:
		break;
	}
}

template<typename PFP>
173
void drawerCell(unsigned int cell, Utils::Drawer& dr, typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& positions, float k)
Sylvain Thery's avatar
Sylvain Thery committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
{
	switch(cell)
	{
	case VERTEX:
		drawerVertex<PFP>(dr, map, d, positions);
		break;
	case EDGE:
		drawerEdge<PFP>(dr, map, d, positions,k);
		break;
	case FACE:
		drawerFace<PFP>(dr, map, d, positions,k);
		break;
	case VOLUME:
		drawerVolume<PFP>(dr, map, d, positions,k);
		break;
	default:
		break;
	}
}

194
}
Pierre Kraemer's avatar
Pierre Kraemer committed
195

196
}
Pierre Kraemer's avatar
Pierre Kraemer committed
197

198
}