renderFunctor.h 6.47 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-2011, 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.u-strasbg.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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __RENDER_FUNCTOR_GL_H
#define __RENDER_FUNCTOR_GL_H

#include <vector>

namespace CGoGN
{

namespace Algo
{

namespace Render
{

Sylvain Thery's avatar
Sylvain Thery committed
39
namespace GL1
Pierre Kraemer's avatar
Pierre Kraemer committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 115 116 117 118 119 120 121 122 123 124 125 126 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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
{


template<typename PFP>
class FunctorGLFace: public FunctorMap<typename PFP::MAP>
{
	typedef typename PFP::MAP MAP;
	
protected:
	/**
	* functor used in GL smooth rendering ? (normal per vertex or per face)
	*/
	bool m_smooth;

	/**
	* functor used in lighted rendering ? (use normal or not)
	*/
	bool m_lighted;

	/**
	* Nb edges of primitive (3 for triangle and 4 for quad, -1 for polygon)
	*/
	unsigned m_nbEdges;

	/**
	* coefficient for exploding faces
	*/
	float m_explode;

	/**
	* storing faces that have not been rendered
	*/
	bool m_storing;

	/**
	 * positions of vertices
	 */
	const typename PFP::TVEC3& m_positions;

	/**
	 * normals of vertices
	 */
	const typename PFP::TVEC3& m_normals;

	/**
	* vector of darts (one for each polygon)
	*/
	std::vector<Dart> m_poly;

	/**
	* Dart selector to restrict the rendering
	*/
	const FunctorSelect& m_selector;


public:
	/**
	* @param lighted use normal (face or vertex)
	* @param smooth use per vertex normal
	* @param nbe number of vertex per primitive (3 for triangles, 4 for quads, -1 for polygons)
	* @param expl exploding coefficient
	* @param stor shall we store faces that are not of the good primitive type
	* @param vn the vertex normal vector (indiced by dart label)
	* @param good dart selector
	*/
	FunctorGLFace(MAP& map, bool lighted, bool smooth, int nbe, float expl, bool stor,
		const typename PFP::TVEC3& posi, const typename PFP::TVEC3& normals , const FunctorSelect& good);

	/**
	* get back the vector of darts of faces that have not been treated
	*/
	std::vector<Dart>& getPolyDarts();

	/**
	* operator applied on each face:
	* if the face has the right number of edges
	* it is rendered (glVertex). Other are stored
	* if needed.
	*/
	bool operator() (Dart d);

	/**
	* Render a face without exploding
	*/
	void renderFace(Dart d);

	/**
	* Render a face with exploding
	*/
	void renderFaceExplode(Dart d);
};


/**
 * Fonctor for color rendering
 */

template<typename PFP>
class FunctorGLFaceColor: public FunctorMap<typename PFP::MAP>
{
	typedef typename PFP::MAP MAP;

protected:
	/**
	* functor used in GL smooth rendering ? (normal per vertex or per face)
	*/
	bool m_smooth;

	/**
	* functor used in lighted rendering ? (use normal or not)
	*/
	bool m_lighted;

	/**
	* Nb edges of primitive (3 for triangle and 4 for quad, -1 for polygon)
	*/
	unsigned m_nbEdges;

	/**
	* coefficient for exploding faces
	*/
	float m_explode;

	/**
	* storing faces that have not been rendered
	*/
	bool m_storing;

	/**
	 * positions of vertices
	 */
	const typename PFP::TVEC3& m_positions;

	/**
	 * normals of vertices
	 */
	const typename PFP::TVEC3& m_normals;

	/**
	 * colors of vertices
	 */
	const typename PFP::TVEC3& m_colors;

	/**
	* vector of darts (one for each polygon)
	*/
	std::vector<Dart> m_poly;

	/**
	* Dart selector to restrict the rendering
	*/
	const FunctorSelect& m_selector;


public:

	FunctorGLFaceColor(MAP& map, bool lighted, bool smooth, int nbe, float expl, bool stor,
		const typename PFP::TVEC3& posi, const typename PFP::TVEC3& normals , const typename PFP::TVEC3& colors ,const FunctorSelect& good);

	std::vector<Dart>& getPolyDarts();

	bool operator() (Dart d);

	void renderFace(Dart d);

	void renderFaceExplode(Dart d);
};

template<typename PFP>
class FunctorGLNormal : public  CGoGN::FunctorMap<typename PFP::MAP>
{
	typedef typename PFP::MAP MAP;
212 213


Pierre Kraemer's avatar
Pierre Kraemer committed
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
protected:
	/**
	 * positions of vertices
	 */
	const typename PFP::TVEC3& m_positions;

	/**
	 * normals of vertices
	 */
	const typename PFP::TVEC3& m_normals;

	/**
	* Dart selector to restrict the rendering
	*/
	const FunctorSelect& m_selector;

	float m_scale;

public:
	/**

	* @param good dart selector
	*/
	FunctorGLNormal(MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& posi, const typename PFP::TVEC3& normals, float scale);

	bool operator() (Dart d);
};

242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
template<typename PFP>
class FunctorGLFrame : public  CGoGN::FunctorMap<typename PFP::MAP>
{
	typedef typename PFP::MAP MAP;


protected:
	/**
	 * positions of vertices
	 */
	const typename PFP::TVEC3& m_positions;

	/**
	 * frame of vertices
	 */
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
257
	const typename PFP::TVEC3 *m_frames;
258 259 260 261 262 263 264 265 266 267 268 269 270

	/**
	* Dart selector to restrict the rendering
	*/
	const FunctorSelect& m_selector;

	float m_scale;

public:
	/**

	* @param good dart selector
	*/
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
271
	FunctorGLFrame (MAP& map, const FunctorSelect& good, const typename PFP::TVEC3& posi, const typename PFP::TVEC3 frames[3], float scale);
272 273 274 275

	bool operator() (Dart d);
};

Sylvain Thery's avatar
Sylvain Thery committed
276
} // namespace GL1
Pierre Kraemer's avatar
Pierre Kraemer committed
277 278 279 280 281 282 283

} // namespace Render

} // namespace Algo

} // namespace CGoGN

Sylvain Thery's avatar
Sylvain Thery committed
284
#include "Algo/Render/GL1/renderFunctor.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
285 286

#endif