show_traversors.cpp 10.2 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
#include "show_traversors.h"
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <iostream>

#include "Algo/Modelisation/primitives3d.h"
#include "Algo/Modelisation/polyhedron.h"
#include "Algo/Modelisation/subdivision.h"

#include "Algo/Render/GL2/topo3Render.h"
#include "Algo/Render/SVG/mapSVGRender.h"

#include "Topology/generic/traversor3.h"
#include "Topology/generic/traversor2.h"

#include "Algo/Render/GL2/drawerCells.h"


Pierre Kraemer's avatar
Pierre Kraemer committed
41 42
MAP myMap;
AttributeHandler<VEC3, VERTEX> position ;
43 44 45 46 47 48 49 50 51 52
Dart dglobal;

void MyQT::cb_checkTopo(bool b)
{
	m_showTopo = b;
	updateGL();
}

void MyQT::cb_combo1(int x)
{
Sylvain Thery's avatar
Sylvain Thery committed
53 54
	m_first3 = x;
	if (m_first3!=m_second3)
55 56 57 58 59 60 61
		traverse3();
	else
		CGoGNerr <<"undefined traversor" << CGoGNendl;
}

void MyQT::cb_combo2(int x)
{
Sylvain Thery's avatar
Sylvain Thery committed
62 63
	m_ajd_or_inci3 = x;
	if (m_first3!=m_second3)
64 65 66 67 68 69 70
		traverse3();
	else
		CGoGNerr <<"undefined traversor" << CGoGNendl;
}

void MyQT::cb_combo3(int x)
{
Sylvain Thery's avatar
Sylvain Thery committed
71 72
	m_second3 = x;
	if (m_first3!=m_second3)
73 74 75 76 77 78 79
		traverse3();
	else
		CGoGNerr <<"undefined traversor" << CGoGNendl;
}

void MyQT::cb_combo4(int x)
{
Sylvain Thery's avatar
Sylvain Thery committed
80 81
	m_first2 = x;
	if (m_first2!=m_second2)
82 83 84 85 86 87 88
		traverse2();
	else
		CGoGNerr <<"undefined traversor" << CGoGNendl;
}

void MyQT::cb_combo5(int x)
{
Sylvain Thery's avatar
Sylvain Thery committed
89 90
	m_ajd_or_inci2 = x;
	if (m_first2!=m_second2)
91 92 93 94 95 96 97
		traverse2();
	else
		CGoGNerr <<"undefined traversor" << CGoGNendl;
}

void MyQT::cb_combo6(int x)
{
Sylvain Thery's avatar
Sylvain Thery committed
98 99
	m_second2 = x;
	if (m_first2!=m_second2)
100 101 102 103 104
		traverse2();
	else
		CGoGNerr <<"undefined traversor" << CGoGNendl;
}

Sylvain Thery's avatar
Sylvain Thery committed
105 106 107 108 109 110 111 112 113
void MyQT::cb_explode(int x)
{
	m_expl = float (x) /100.0f;
	if (m_last==2)
		traverse2();
	if (m_last==3)
		traverse3();
}

114 115 116 117 118 119 120 121 122 123

void MyQT::cb_initGL()
{
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);

    m_render_topo = new Algo::Render::GL2::Topo3Render();

	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
	m_render_topo->updateData<PFP>(myMap, position,  0.95f, 0.9f, 0.8f, nb);
Sylvain Thery's avatar
Sylvain Thery committed
124
	m_dm_topo = new DartMarker(myMap);
125 126 127 128 129 130 131 132 133
}

void MyQT::cb_redraw()
{
	if (m_showTopo)
	{
		m_render_topo->drawTopo();

		if (m_selected != NIL)
Sylvain Thery's avatar
Sylvain Thery committed
134 135
			m_render_topo->overdrawDart(m_selected, 7, 1.0f, 0.0f, 1.0f);

136 137 138 139 140 141 142 143 144 145 146 147 148 149
		for (std::vector<Dart>::iterator it=m_affDarts.begin(); it!=m_affDarts.end(); ++it)
		{
			m_render_topo->overdrawDart(*it, 6, 1.0f, 1.0f, 1.0f);
		}
	}

	m_drawer.callList();
}

void MyQT::cb_mousePress(int button, int x, int y)
{
	if (Shift())
	{
		SelectorDartNoBoundary<PFP::MAP> nb(myMap);	
Pierre Kraemer's avatar
Pierre Kraemer committed
150
		Dart d = m_render_topo->picking<PFP>(myMap, x, y, nb);
151 152
		if (d != Dart::nil())
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
153
			CGoGNout << "Dart " << d << " clicked" << CGoGNendl;
154 155 156 157 158 159
			m_selected = d;
		}
		updateGL();
	}
}

Sylvain Thery's avatar
Sylvain Thery committed
160 161
void  MyQT::cb_Save()
{
Sylvain Thery's avatar
Sylvain Thery committed
162 163 164 165 166
//	std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
//	Utils::SVG::SVGOut svg(filename,modelViewMatrix(),projectionMatrix());
//	m_drawer.toSVG(svg);
//	m_render_topo->toSVG(svg);

Pierre Kraemer's avatar
Pierre Kraemer committed
167
	Utils::SVG::SVGOut svg1(modelViewMatrix(), projectionMatrix());
Sylvain Thery's avatar
Sylvain Thery committed
168 169 170 171 172
	m_drawer.toSVG(svg1);
	svg1.addOpacityAnimation(1.0f);
	svg1.addOpacityAnimation(1.0f);
	svg1.addOpacityAnimation(0.0f);

Pierre Kraemer's avatar
Pierre Kraemer committed
173
	Utils::SVG::SVGOut svg2(modelViewMatrix(), projectionMatrix());
Sylvain Thery's avatar
Sylvain Thery committed
174 175 176 177 178 179 180 181 182 183
	m_render_topo->toSVG(svg2);
	svg2.addOpacityAnimation(1.0f);
	svg2.addOpacityAnimation(0.0f);
	svg2.addOpacityAnimation(1.0f);

	Utils::SVG::AnimatedSVGOut anim;

	anim.add(&svg1);
	anim.add(&svg2);

Sylvain Thery's avatar
Sylvain Thery committed
184
	std::string filename = selectFileSave("Export SVG file ",".","(*.svg)");
Sylvain Thery's avatar
Sylvain Thery committed
185 186

	anim.write(filename, 2.0f);
Sylvain Thery's avatar
Sylvain Thery committed
187 188
}

Pierre Kraemer's avatar
Pierre Kraemer committed
189 190
template <unsigned int ORBIT>
void MyQT::colorizeCell(Dart d, float r,float g, float b)
191
{
Pierre Kraemer's avatar
Pierre Kraemer committed
192 193 194
	TraversorDartsOfOrbit<PFP::MAP, ORBIT>doo (myMap, d);
	for (Dart e = doo.begin(); e != doo.end(); e = doo.next())
		m_render_topo->setDartColor(e, r, g, b);
195 196 197 198 199 200
}

void MyQT::traverse2()
{
	if (m_selected == NIL)
		return;
Sylvain Thery's avatar
Sylvain Thery committed
201
	m_last=2;
Sylvain Thery's avatar
Sylvain Thery committed
202
//	int code = (m_ajd_or_inci2)*100+m_first2*10+m_second2;
203 204 205
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);

	m_drawer.newList(GL_COMPILE);
Sylvain Thery's avatar
Sylvain Thery committed
206 207
	m_drawer.lineWidth(7.0f);
	m_drawer.pointSize(9.0f);
Sylvain Thery's avatar
Sylvain Thery committed
208
	m_drawer.color3f(0.0f,0.7f,0.0f);
209 210 211

	m_affDarts.clear();

Sylvain Thery's avatar
Sylvain Thery committed
212
	if (m_ajd_or_inci2 == 0) // incident
213
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
214
		Algo::Render::drawerCell<PFP>(VERTEX+m_second2, m_drawer, myMap, m_selected, position, m_expl);
215
		m_drawer.color3f(1.0f,0.0f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
216

Pierre Kraemer's avatar
Pierre Kraemer committed
217
		Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createIncident(myMap, m_selected, VERTEX+m_second2, VERTEX+m_first2);
Sylvain Thery's avatar
Sylvain Thery committed
218 219
		for (Dart d=tra->begin(); d != tra->end(); d= tra->next())
				m_affDarts.push_back(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
220
		Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl);
221
	}
Sylvain Thery's avatar
Sylvain Thery committed
222
	else	// adjacent
223
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
224
		Algo::Render::drawerCell<PFP>(VERTEX+m_first2, m_drawer, myMap, m_selected, position, m_expl);
225
		m_drawer.color3f(1.0f,0.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
226
		Traversor2<PFP::MAP>* tra = Traversor2<PFP::MAP>::createAdjacent(myMap, m_selected, VERTEX+m_first2, VERTEX+m_second2);
227

Pierre Kraemer's avatar
Pierre Kraemer committed
228 229 230
		for (Dart d = tra->begin(); d != tra->end(); d = tra->next())
			m_affDarts.push_back(d);
		Algo::Render::drawerCells<PFP>(VERTEX+m_first2, m_drawer, myMap, m_affDarts, position, m_expl);
231
	}
Sylvain Thery's avatar
Sylvain Thery committed
232

233
	m_drawer.endList();
Sylvain Thery's avatar
Sylvain Thery committed
234 235

	SelectorMarked sm(*m_dm_topo);
Pierre Kraemer's avatar
Pierre Kraemer committed
236
	m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f, sm);
Sylvain Thery's avatar
Sylvain Thery committed
237

238 239 240 241 242 243 244
	updateGL();
}

void MyQT::traverse3()
{
	if (m_selected == NIL)
		return;
Sylvain Thery's avatar
Sylvain Thery committed
245 246 247

	m_last=3;

248 249 250 251
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);

	m_affDarts.clear();
	m_drawer.newList(GL_COMPILE);
Sylvain Thery's avatar
Sylvain Thery committed
252 253
	m_drawer.lineWidth(7.0f);
	m_drawer.pointSize(9.0f);
Sylvain Thery's avatar
Sylvain Thery committed
254
	m_drawer.color3f(0.0f,0.7f,0.0f);
255

Sylvain Thery's avatar
Sylvain Thery committed
256 257 258
	m_dm_topo->unmarkAll();
	SelectorMarked sm(*m_dm_topo);

Sylvain Thery's avatar
Sylvain Thery committed
259
	if (m_ajd_or_inci3 == 0) // incident
260
	{
Sylvain Thery's avatar
Sylvain Thery committed
261
		Algo::Render::drawerCell<PFP>(VERTEX+m_second3, m_drawer,myMap,m_selected,position,m_expl);
Pierre Kraemer's avatar
Pierre Kraemer committed
262
		m_dm_topo->markOrbit<VERTEX+m_second3>(m_selected);
263
		m_drawer.color3f(1.0f,0.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
264 265
		Traversor3XY<PFP::MAP, VERTEX+m_second3, VERTEX+m_first3> tra(myMap, m_selected);
		for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
Sylvain Thery's avatar
Sylvain Thery committed
266 267
		{
			m_affDarts.push_back(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
268
			m_dm_topo->markOrbit<VERTEX+m_first3>(d);
Sylvain Thery's avatar
Sylvain Thery committed
269
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
270
		Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap, m_affDarts, position, m_expl);
Sylvain Thery's avatar
Sylvain Thery committed
271

Pierre Kraemer's avatar
Pierre Kraemer committed
272 273
		m_render_topo->updateData<PFP>(myMap, position, 0.95f, 0.9f, 0.8f, sm);
		for (std::vector<Dart>::iterator id = m_affDarts.begin(); id != m_affDarts.end(); ++id)
Sylvain Thery's avatar
Sylvain Thery committed
274 275
			m_render_topo->setDartColor(*id,0.7f,0.0f,0.0f);
		m_render_topo->setDartColor(m_selected,0.0f,0.7f,0.0f);
276
	}
Sylvain Thery's avatar
Sylvain Thery committed
277
	else	// adjacent
278
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
279 280
		Algo::Render::drawerCell<PFP>(VERTEX+m_first3, m_drawer, myMap, m_selected, position, m_expl);
		m_dm_topo->markOrbit<VERTEX+m_first3>(m_selected);
281
		m_drawer.color3f(1.0f,0.0f,0.0f);
Pierre Kraemer's avatar
Pierre Kraemer committed
282 283
		Traversor3XXaY<PFP::MAP, VERTEX+m_first3, VERTEX+m_second3> tra(myMap,m_selected);
		for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
Sylvain Thery's avatar
Sylvain Thery committed
284 285
		{
			m_affDarts.push_back(d);
Pierre Kraemer's avatar
Pierre Kraemer committed
286
			m_dm_topo->markOrbit<VERTEX+m_first3>(d);
Sylvain Thery's avatar
Sylvain Thery committed
287
		}
Sylvain Thery's avatar
Sylvain Thery committed
288
		Algo::Render::drawerCells<PFP>(VERTEX+m_first3, m_drawer, myMap,m_affDarts,position,m_expl);
Sylvain Thery's avatar
Sylvain Thery committed
289 290 291 292 293

		m_render_topo->updateData<PFP>(myMap, position,  0.95f, 0.9f, 0.8f, sm);
		for (std::vector<Dart>::iterator id=m_affDarts.begin(); id != m_affDarts.end(); ++id)
			m_render_topo->setDartColor(*id,0.7f,0.0f,0.0f);
		m_render_topo->setDartColor(m_selected,0.0f,0.7f,0.0f);
294 295 296
	}

	m_drawer.endList();
Sylvain Thery's avatar
Sylvain Thery committed
297

298 299 300 301 302
	updateGL();
}

int main(int argc, char **argv)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
303
	position = myMap.addAttribute<VEC3, VERTEX>( "position");
304 305 306 307 308 309 310 311 312 313 314 315 316 317

	Algo::Modelisation::Primitive3D<PFP> prim(myMap, position);
	dglobal = prim.hexaGrid_topo(4,4,4);
	prim.embedHexaGrid(1.0f,1.0f,1.0f);

    // un peu d'interface
	QApplication app(argc, argv);
	MyQT sqt;

	// interface de tuto5.ui
    Utils::QT::uiDockInterface dock;
    sqt.setDock(&dock);

 	// message d'aide
318
	sqt.setHelpMsg("shit click to select a dart\nand select a traversor\nif keyboard focus problem\nundock");
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334

	//  bounding box
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
    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
	sqt.setParamObject(lWidthObj, lPosObj.data());

	sqt.setCallBack( dock.combo1, SIGNAL(	activated(int)), SLOT(cb_combo1(int)) );
	sqt.setCallBack( dock.combo2, SIGNAL(	activated(int)), SLOT(cb_combo2(int)) );
	sqt.setCallBack( dock.combo3, SIGNAL(	activated(int)), SLOT(cb_combo3(int)) );

	sqt.setCallBack( dock.combo4, SIGNAL(	activated(int)), SLOT(cb_combo4(int)) );
	sqt.setCallBack( dock.combo5, SIGNAL(	activated(int)), SLOT(cb_combo5(int)) );
	sqt.setCallBack( dock.combo6, SIGNAL(	activated(int)), SLOT(cb_combo6(int)) );
Sylvain Thery's avatar
Sylvain Thery committed
335
	sqt.setCallBack( dock.explodeSlider, SIGNAL(valueChanged(int)), SLOT(cb_explode(int)) );
336 337 338 339 340 341 342 343 344 345

	sqt.setCallBack( dock.checkTopo, SIGNAL(	clicked(bool)), SLOT(cb_checkTopo(bool)) );

	sqt.m_selected = NIL;

	sqt.show();

	// et on attend la fin.
	return app.exec();
}