tuto3.cpp 7.34 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include <iostream>

27
#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
28 29 30 31 32
#include "Topology/map/map2.h"
#include "Topology/generic/cellmarker.h"

#include "Geometry/vector_gen.h"
#include "Algo/Geometry/boundingbox.h"
33
#include "Algo/Render/GL2/mapRender.h"
34 35 36
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderColorPerVertex.h"

37 38

#include "tuto3.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
39

40 41
MyQT* sqt1_ptr;
MyQT* sqt2_ptr;
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43 44

using namespace CGoGN ;

45 46
struct PFP: public PFP_STANDARD
{
Pierre Kraemer's avatar
Pierre Kraemer committed
47 48 49 50
	// definition de la carte
	typedef Map2 MAP;
};

51
void MyQT::cb_initGL()
Pierre Kraemer's avatar
Pierre Kraemer committed
52
{
53 54
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);
Pierre Kraemer's avatar
Pierre Kraemer committed
55

56 57
	// create the render
	m_render = new Algo::Render::GL2::MapRender();
Pierre Kraemer's avatar
Pierre Kraemer committed
58

59 60 61
	// create VBO for position
	m_positionVBO = new Utils::VBO();
	m_colorVBO = new Utils::VBO();
Pierre Kraemer's avatar
Pierre Kraemer committed
62

63 64 65 66 67 68 69 70 71
	// using simple shader with color
	m_shader = new Utils::ShaderSimpleColor();
	m_shader->setAttributePosition(m_positionVBO);


	m_shader2 = new Utils::ShaderColorPerVertex();
	m_shader2->setAttributePosition(m_positionVBO);
	m_shader2->setAttributeColor(m_colorVBO);

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
72 73
	registerShader(m_shader);
	registerShader(m_shader2);
74
}
Pierre Kraemer's avatar
Pierre Kraemer committed
75

76
void MyQT::cb_redraw()
Pierre Kraemer's avatar
Pierre Kraemer committed
77
{
78
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
Pierre Kraemer's avatar
Pierre Kraemer committed
79

80 81 82
	glLineWidth(2.0f);
	m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.));
	m_render->draw(m_shader, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
83

84 85 86 87 88
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1.0f, 1.0f);
	m_render->draw(m_shader2, Algo::Render::GL2::TRIANGLES);
	glDisable(GL_POLYGON_OFFSET_FILL);
}
Pierre Kraemer's avatar
Pierre Kraemer committed
89

90 91 92 93 94 95 96 97 98 99 100
void MyQT::cb_keyPress(int code)
{
	switch(code)
	{
	case 's':
		if (this == sqt2_ptr)
			sqt1_ptr->synchronize(sqt2_ptr);
		if (this == sqt1_ptr)
			sqt2_ptr->synchronize(sqt1_ptr);
		break;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
101 102 103 104
}

int main(int argc, char **argv)
{
105 106 107 108 109 110
	PFP::MAP myMap;
	SelectorTrue allDarts;

	PFP::TVEC3 position ;
	PFP::TVEC3 normal ;
	AttributeHandler<Geom::Vec3f> color ;
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112 113 114 115

	Dart d2 = myMap.newOrientedFace(3);
	Dart d3 = myMap.newOrientedFace(4);
	myMap.sewFaces(d2,d3);

116 117
	position = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");
	color = myMap.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "couleur");
Pierre Kraemer's avatar
Pierre Kraemer committed
118 119

	position[d2] = PFP::VEC3(0.0f, 0.0f, 0.0f);
120
	color[d2] = PFP::VEC3(1.0f, 0.0f, 0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
121 122
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(2.0f, 0.0f, 0.0f);
123
	color[d2] = PFP::VEC3(0.0f, 1.0f, 0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
124 125
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(1.0f, 3.0f, 0.0f);
126
	color[d2] = PFP::VEC3(0.0f, 0.0f, 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
127 128 129
	d2 = myMap.phi1(d2);
	d3 = myMap.phi<11>(d3);
	position[d3] = PFP::VEC3(0.0f, -2.0f, 0.0f);
130
	color[d3] = PFP::VEC3(1.0f, 0.0f, 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
131 132
	d3 = myMap.phi1(d3);
	position[d3] = PFP::VEC3(2.0f, -2.0f, 0.0f);
133
	color[d3] = PFP::VEC3(0.0f, 1.0f, 1.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
	d3 = myMap.phi1(d3);

	//MARK !!!

	// on reserve des marqueur de brins
	DartMarkerStore mf(myMap);
	DartMarkerStore me(myMap);

	// avec lesquels on peut marquer des orbits
	mf.markOrbit(FACE_ORBIT, d2);
	me.markOrbit(EDGE_ORBIT, d2);

	// les sommet sont plonges, on peut utiliser un marqueur de cellule sommet
	CellMarker cm(myMap, VERTEX_ORBIT);
	cm.mark(d3);

	for (Dart d = myMap.begin(); d!= myMap.end(); myMap.next(d))
	{
		if (me.isMarked(d))
153
			CGoGNout << "Dart "<< d.label() << " marque par me"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
154
		if (mf.isMarked(d))
155
			CGoGNout << "Dart "<< d.label() << " marque par mf"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
156
		if (cm.isMarked(d))
157
			CGoGNout << "Sommet de dart "<< d.label() << " marque par mcv"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
158 159 160 161 162
	}

	//nettoyage
	cm.unmarkAll();

Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
163
	// interface:
164 165 166
	QApplication app(argc, argv);

	MyQT sqt;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
167
	sqt1_ptr = &sqt;
168 169

	MyQT sqt2;
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
170
	sqt2_ptr = &sqt2;
171 172 173 174 175 176 177

	// message d'aide
	sqt.setHelpMsg("Tuto3:\n"
			"marker tuto\n"
			"using two VBO & two shader");

    //  bounding box
Pierre Kraemer's avatar
Pierre Kraemer committed
178
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
179 180 181 182
    float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
    Geom::Vec3f lPosObj = (bb.min() +  bb.max()) / PFP::REAL(2);

    // envoit info BB a l'interface
Pierre Kraemer's avatar
merge..  
Pierre Kraemer committed
183
	sqt.setParamObject(lWidthObj, lPosObj.data());
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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

	// show 1 pour GL context
	sqt.show();

	// update du VBO position (context GL necessaire)
	sqt.m_positionVBO->updateData(position);
	// update du VBO color
	sqt.m_colorVBO->updateData(color);

	// update des primitives du renderer
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES);
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES);

	// show final pour premier redraw
	sqt.show();

	// et pour le fun une deuxieme carte et une deuxieme interface:

	PFP::MAP myMap2;
	PFP::TVEC3 position2 ;
	AttributeHandler<Geom::Vec3f> color2 ;

	Dart dx = myMap2.newOrientedFace(4);

	position2 = myMap2.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "position");
	color2 = myMap2.addAttribute<PFP::VEC3>(VERTEX_ORBIT, "couleur");

	position2[dx] = PFP::VEC3(0.0f, 0.0f, 0.0f);
	color2[dx] = PFP::VEC3(1.0f, 1.0f, 0.0f);
	dx = myMap.phi1(dx);
	position2[dx] = PFP::VEC3(2.0f, 0.0f, 0.0f);
	color2[dx] = PFP::VEC3(0.0f, 1.0f, 0.0f);
	dx = myMap.phi1(dx);
	position2[dx] = PFP::VEC3(2.0f, 2.0f, 0.0f);
	color2[dx] = PFP::VEC3(1.0f, 0.0f, 1.0f);
	dx = myMap.phi1(dx);
	position2[dx] = PFP::VEC3(0.0f, 2.0f, 0.0f);
	color2[dx] = PFP::VEC3(0.0f, 1.0f, 1.0f);

	sqt2.setHelpMsg("Fenetre 2!!");

	sqt2.setParamObject(lWidthObj,lPosObj.data());

	// show 1 pour GL context
	sqt2.show();

	// update du VBO position (context GL necessaire)
	sqt2.m_positionVBO->updateData(position2);
	// update du VBO color
	sqt2.m_colorVBO->updateData(color2);
Pierre Kraemer's avatar
Pierre Kraemer committed
234

235 236 237
	// update des primitives du renderer
	sqt2.m_render->initPrimitives<PFP>(myMap2, allDarts, Algo::Render::GL2::TRIANGLES);
	sqt2.m_render->initPrimitives<PFP>(myMap2, allDarts, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
238

239 240
	// et on attend la fin.
	return app.exec();
Pierre Kraemer's avatar
Pierre Kraemer committed
241
}