Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

map_glRender.hpp 6.71 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <vector>
#include <limits>

#include <list>

Sylvain Thery's avatar
Sylvain Thery committed
30
#include "Algo/Render/GL1/renderFunctor.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
31
32
33
34
35
36
37
38
39
40

namespace CGoGN
{

namespace Algo
{

namespace Render
{

Sylvain Thery's avatar
Sylvain Thery committed
41
namespace GL1
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
44
{

template <typename PFP>
45
void renderTriQuadPoly(typename PFP::MAP& the_map, RenderType rt, float explode, const VertexAttribute<typename PFP::VEC3>& position, const VertexAttribute<typename PFP::VEC3>& normal, const FunctorSelect& good)
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48
49
50
51
52
53
54
{
	// RenderType => lighted & smooth ??
	bool lighted = (rt != NO_LIGHT) && (rt!= LINE);
	bool smooth = (rt==SMOOTH);

	// first pass render the triangles
	FunctorGLFace<PFP> fgl_tri(the_map, lighted, smooth, 3, explode, true, position, normal, good);

	glBegin(GL_TRIANGLES);
55
	the_map.template foreach_orbit<FACE>(fgl_tri, good);
Pierre Kraemer's avatar
Pierre Kraemer committed
56
57
58
59
	glEnd();

	// get untreated quads & polygons
	std::vector<Dart>& polygons = fgl_tri.getPolyDarts();
60
	//CGoGNout<< "Reste a rendre: "<< polygons.size()<<CGoGNendl;
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

	if (rt==LINE)
	{
		FunctorGLFace<PFP> fgl_quads(the_map, lighted, smooth, POLYGONS, explode, true, position, normal, good);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			glBegin(GL_POLYGON);
			fgl_quads(*d);
			glEnd();
		}
		polygons = fgl_quads.getPolyDarts();
	}
	else
	{
		FunctorGLFace<PFP> fgl_quads(the_map, lighted, smooth, 4, explode, true, position, normal, good);
		glBegin(GL_TRIANGLES);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			fgl_quads(*d);
		}
		glEnd();
		polygons = fgl_quads.getPolyDarts();
	}

	if (rt==LINE)
	{
		FunctorGLFace<PFP> fgl_polygStar(the_map, lighted, smooth, POLYGONS, explode, true, position, normal, good);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			glBegin(GL_POLYGON);
			fgl_polygStar(*d);
			glEnd();
		}
	}
	else
	{
		FunctorGLFace<PFP> fgl_polygStar(the_map, lighted, smooth, TRIFAN, explode, true, position, normal, good);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			glBegin(GL_TRIANGLE_FAN);
			fgl_polygStar(*d);
			glEnd();
		}
	}
}



template <typename PFP>
110
void renderTriQuadPoly(typename PFP::MAP& the_map, RenderType rt, float explode, const VertexAttribute<typename PFP::VEC3>& position, const VertexAttribute<typename PFP::VEC3>& normal, const VertexAttribute<typename PFP::VEC3>& color, const FunctorSelect& good)
Pierre Kraemer's avatar
Pierre Kraemer committed
111
112
113
114
115
116
117
118
119
120
{
	// RenderType => lighted & smooth ??
	bool lighted = (rt != NO_LIGHT) && (rt!= LINE);
	bool smooth = (rt==SMOOTH);

	// first pass render the triangles
	FunctorGLFaceColor<PFP> fgl_tri(the_map, lighted, smooth, 3, explode, true, position, normal, color, good);


	glBegin(GL_TRIANGLES);
Basile Sauvage's avatar
Basile Sauvage committed
121
	the_map.template foreach_orbit<FACE>(fgl_tri, good);
Pierre Kraemer's avatar
Pierre Kraemer committed
122
123
124
125
	glEnd();

	// get untreated quads & polygons
	std::vector<Dart>& polygons = fgl_tri.getPolyDarts();
126
	//CGoGNout<< "Reste a rendre: "<< polygons.size()<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
127
128
129
130
131
132
133
134
135
136
137
138
139
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
169
170
171
172
173
174

	if (rt==LINE)
	{
		FunctorGLFaceColor<PFP> fgl_quads(the_map, lighted, smooth, POLYGONS, explode, true, position, normal, color, good);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			glBegin(GL_POLYGON);
			fgl_quads(*d);
			glEnd();
		}
		polygons = fgl_quads.getPolyDarts();
	}
	else
	{
		FunctorGLFaceColor<PFP> fgl_quads(the_map, lighted, smooth, 4, explode, true, position, normal, color, good);
		glBegin(GL_TRIANGLES);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			fgl_quads(*d);
		}
		glEnd();
		polygons = fgl_quads.getPolyDarts();
	}

	if (rt==LINE)
	{
		FunctorGLFaceColor<PFP> fgl_polygStar(the_map, lighted, smooth, POLYGONS, explode, true, position, normal, color, good);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			glBegin(GL_POLYGON);
			fgl_polygStar(*d);
			glEnd();
		}
	}
	else
	{
		FunctorGLFaceColor<PFP> fgl_polygStar(the_map, lighted, smooth, TRIFAN, explode, true, position, normal, color, good);
		for(typename std::vector<Dart>::iterator d = polygons.begin(); d != polygons.end(); ++d)
		{
			glBegin(GL_TRIANGLE_FAN);
			fgl_polygStar(*d);
			glEnd();
		}
	}
}


template <typename PFP>
175
void renderNormalVertices(typename PFP::MAP& the_map, const VertexAttribute<typename PFP::VEC3>& position, const VertexAttribute<typename PFP::VEC3>& normal, float scale, const FunctorSelect& good)
Pierre Kraemer's avatar
Pierre Kraemer committed
176
177
178
179
{
	FunctorGLNormal<PFP> fgl_norm(the_map, good, position, normal, scale);

	glBegin(GL_LINES);
Basile Sauvage's avatar
Basile Sauvage committed
180
	the_map.template foreach_orbit<VERTEX>(fgl_norm, good);
Pierre Kraemer's avatar
Pierre Kraemer committed
181
182
183
	glEnd();
}

184
template <typename PFP>
185
void renderFrameVertices(typename PFP::MAP& the_map, const VertexAttribute<typename PFP::VEC3>& position, const VertexAttribute<typename PFP::VEC3> frame[3], float scale, const FunctorSelect& good)
186
187
188
189
{
	FunctorGLFrame<PFP> fgl_frame(the_map, good, position, frame, scale) ;

	glBegin(GL_LINES) ;
Basile Sauvage's avatar
Basile Sauvage committed
190
	the_map.template foreach_orbit<VERTEX>(fgl_frame, good) ;
191
192
193
	glEnd();
}

Sylvain Thery's avatar
Sylvain Thery committed
194
} // namespace GL1
Pierre Kraemer's avatar
Pierre Kraemer committed
195
196
197
198
199
200

} // namespace Render

} // namespace Algo

} // namespace CGoGN