viewer.cpp 21.2 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
/*******************************************************************************
pitiot's avatar
init  
pitiot committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, 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: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
24 25

#include "viewer.h"
pitiot's avatar
stats  
pitiot committed
26

pitiot's avatar
pitiot committed
27 28 29 30 31
void Volusion::dart_onoff(bool x)
{
    draw_dart = x;
    updateGL();
}
Pierre Kraemer's avatar
Pierre Kraemer committed
32

pitiot's avatar
pitiot committed
33 34 35 36 37
void Volusion::slot_slide(int i)
    {
        dartSlider = i;
        updateGL();
    }
Pierre Kraemer's avatar
Pierre Kraemer committed
38

pitiot's avatar
init  
pitiot committed
39
void Volusion::volumes_onoff(bool x)
Pierre Kraemer's avatar
Pierre Kraemer committed
40
{
pitiot's avatar
init  
pitiot committed
41 42
	render_volumes = x;
	updateGL();
Pierre Kraemer's avatar
Pierre Kraemer committed
43
}
Pierre Kraemer's avatar
Pierre Kraemer committed
44

pitiot's avatar
init  
pitiot committed
45
void Volusion::edges_onoff(bool x)
Pierre Kraemer's avatar
Pierre Kraemer committed
46
{
pitiot's avatar
init  
pitiot committed
47 48
	render_edges = x;
	updateGL();
Thomas Jund's avatar
Thomas Jund committed
49 50
}

pitiot's avatar
pitiot committed
51
void Volusion::MovingObject_onoff(bool x)
pitiot's avatar
pitiot committed
52
{
pitiot's avatar
pitiot committed
53
    render_MovingObject = x;
pitiot's avatar
pitiot committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    updateGL();
}

void Volusion::belonging_onoff(bool x)
{
    render_belonging = x;
    updateGL();
}
void Volusion::neighbors_onoff(bool x)
{
    render_neighbors= x;
    updateGL();
}
void Volusion::comboEdge(int x)
{
    val_comboEdge = x;
    if(x!=0)  CGoGNout<< "affichage uniquement pour l'arete"<<val_comboEdge<<CGoGNendl;
    updateGL();
}

pitiot's avatar
init  
pitiot committed
74
void Volusion::topo_onoff(bool x)
Thomas Jund's avatar
Thomas Jund committed
75
{
pitiot's avatar
init  
pitiot committed
76 77
	render_topo = x;
	if (render_topo)
Thomas Jund's avatar
Thomas Jund committed
78
	{
pitiot's avatar
pitiot committed
79
//		SelectorDartNoBoundary<MAP> nb(simul.envMap_.map);
pitiot's avatar
init  
pitiot committed
80
		//TODO MapBrowser
pitiot's avatar
pitiot committed
81
        m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position, 0.8f, m_explode_factorf-0.05f, m_explode_factor);
Thomas Jund's avatar
Thomas Jund committed
82 83
	}

pitiot's avatar
init  
pitiot committed
84 85
	updateGL();
}
Thomas Jund's avatar
Thomas Jund committed
86

pitiot's avatar
init  
pitiot committed
87 88 89
void Volusion::clipping_onoff(bool x)
{
	clip_volume = x;
90

pitiot's avatar
init  
pitiot committed
91
	if (clip_volume)
Thomas Jund's avatar
Thomas Jund committed
92
	{
pitiot's avatar
init  
pitiot committed
93 94 95 96 97 98 99
		Geom::Vec3f pos = m_PlanePick->getPosition();
		float pipo;
		Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal
		float d = -(pos*normal);
		m_explode_render->setClippingPlane(Geom::Vec4f(normal[0],normal[1],normal[2],d));
		m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos);
		m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos);
Thomas Jund's avatar
Thomas Jund committed
100 101 102
	}
	else
	{
pitiot's avatar
init  
pitiot committed
103 104 105 106 107
		m_explode_render->setNoClippingPlane();
		m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f));
		m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), Geom::Vec3f(0,0,999999.9f));
		m_sh1->setClipColorAttenuationFactorRelative(0.0f,0.0f);
		m_sh2->setClipColorAttenuationFactorRelative(0.0f,0.0f);
Thomas Jund's avatar
Thomas Jund committed
108
	}
pitiot's avatar
init  
pitiot committed
109
	updateGL();
Thomas Jund's avatar
Thomas Jund committed
110 111
}

pitiot's avatar
init  
pitiot committed
112
void Volusion::hide_onoff(bool x)
Thomas Jund's avatar
Thomas Jund committed
113
{
pitiot's avatar
init  
pitiot committed
114 115
	hide_clipping = x;
	updateGL();
Thomas Jund's avatar
Thomas Jund committed
116 117
}

pitiot's avatar
init  
pitiot committed
118
void Volusion::slider_explode(int x)
Thomas Jund's avatar
Thomas Jund committed
119
{
pitiot's avatar
init  
pitiot committed
120 121 122
	m_explode_factor = 0.01f*(x+1)-0.0001f;
	m_explode_render->setExplodeVolumes(m_explode_factor);
	updateGL();
Thomas Jund's avatar
Thomas Jund committed
123 124
}

pitiot's avatar
init  
pitiot committed
125
void Volusion::slider_explodeF(int x)
Thomas Jund's avatar
Thomas Jund committed
126
{
pitiot's avatar
init  
pitiot committed
127 128 129
	m_explode_factorf = 0.01f*(x+1);
	m_explode_render->setExplodeFaces(m_explode_factorf);
	updateGL();
Thomas Jund's avatar
Thomas Jund committed
130 131
}

pitiot's avatar
init  
pitiot committed
132
void Volusion::slider_pressed()
Thomas Jund's avatar
Thomas Jund committed
133
{
pitiot's avatar
init  
pitiot committed
134 135 136 137
	render_topoTemp = render_topo;
	render_topo = false;
	updateGL();
}
pitiot's avatar
merge  
pitiot committed
138

pitiot's avatar
init  
pitiot committed
139 140 141 142
void Volusion::slider_released()
{
	render_topo = render_topoTemp;
	if (render_topo)
Thomas Jund's avatar
Thomas Jund committed
143
	{
pitiot's avatar
init  
pitiot committed
144 145
//		SelectorDartNoBoundary<MAP> nb(simul.envMap.map);
		//TODO MapBrowser
pitiot's avatar
pitiot committed
146
        m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position, 0.8f, m_explode_factorf-0.05f, m_explode_factor );
Thomas Jund's avatar
Thomas Jund committed
147
	}
pitiot's avatar
init  
pitiot committed
148
	updateGL();
Pierre Kraemer's avatar
Pierre Kraemer committed
149
}
Pierre Kraemer's avatar
Pierre Kraemer committed
150

pitiot's avatar
init  
pitiot committed
151
void Volusion::cb_Open()
Thomas Jund's avatar
Thomas Jund committed
152
{
pitiot's avatar
init  
pitiot committed
153 154 155 156
	std::string filters("all (*.*)") ;
	std::string filename = selectFile("Open Mesh", "", filters) ;
	if (filename.empty())
		return ;
pitiot's avatar
pitiot committed
157
    else simul.envMap_.open_file(filename);
Thomas Jund's avatar
Thomas Jund committed
158 159


pitiot's avatar
pitiot committed
160 161 162
//	SelectorDartNoBoundary<MAP> nb(simul.envMap_.map);
    m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position,  0.8f, 0.8f, 0.8f);
    m_explode_render->updateData<PFP>(simul.envMap_.map, simul.envMap_.position, simul.envMap_.color);
Thomas Jund's avatar
Thomas Jund committed
163

pitiot's avatar
init  
pitiot committed
164
	updateGL() ;
Thomas Jund's avatar
Thomas Jund committed
165 166
}

pitiot's avatar
pitiot committed
167

pitiot's avatar
pitiot committed
168

pitiot's avatar
init  
pitiot committed
169 170
void Volusion::cb_initGL()
{
pitiot's avatar
pitiot committed
171 172


pitiot's avatar
init  
pitiot committed
173 174
	// choose to use GL version 2
	Utils::GLSLShader::setCurrentOGLVersion(2);
pitiot's avatar
pitiot committed
175
    m_ds = new Utils::Drawer();
pitiot's avatar
init  
pitiot committed
176 177 178
	// create the renders
	m_topo_render = new Algo::Render::GL2::Topo3RenderMap<PFP>();
    m_explode_render = new Algo::Render::GL2::ExplodeVolumeRender(true,true,true);
pitiot's avatar
pitiot committed
179

pitiot's avatar
pitiot committed
180 181 182
//	SelectorDartNoBoundary<MAP> nb(simul.envMap_.map);
    m_topo_render->updateData(simul.envMap_.map, simul.envMap_.position,  0.8f, 0.8f, 0.8f);
    m_explode_render->updateData<PFP>(simul.envMap_.map, simul.envMap_.position, simul.envMap_.color);
pitiot's avatar
init  
pitiot committed
183 184 185 186 187
	m_explode_render->setExplodeVolumes(1.0f);
	m_explode_render->setExplodeFaces(1.0f);
	m_explode_render->setAmbiant(Geom::Vec4f(0.2f,0.2f,0.2f,1.0f));
	m_explode_render->setBackColor(Geom::Vec4f(0.9f,0.9f,0.9f,1.0f));
	m_explode_render->setColorLine(Geom::Vec4f(0.8f,0.2f,0.2f,1.0f));
pitiot's avatar
pitiot committed
188

pitiot's avatar
init  
pitiot committed
189 190
	m_sh1 = static_cast<Utils::ClippingShader*>(m_topo_render->shader1());
	m_sh2 = static_cast<Utils::ClippingShader*>(m_topo_render->shader2());
Thomas Jund's avatar
Thomas Jund committed
191

pitiot's avatar
init  
pitiot committed
192 193
	registerShader(m_explode_render->shaderFaces());
	registerShader(m_explode_render->shaderLines());
pitiot's avatar
pitiot committed
194

pitiot's avatar
init  
pitiot committed
195 196 197
    m_PlanePick = new Utils::Pickable(Utils::Pickable::GRID,1);
	m_frame = new Utils::FrameManipulator();
	m_frame->setSize(m_WidthObj/2.0f);
Thomas Jund's avatar
Thomas Jund committed
198

199

pitiot's avatar
init  
pitiot committed
200 201
	m_sh1->insertClippingCode();
	m_sh2->insertClippingCode();
pitiot's avatar
merging  
pitiot committed
202

pitiot's avatar
init  
pitiot committed
203 204
	clip_id1 = m_sh1->addClipPlane();
	clip_id2 = m_sh2->addClipPlane();
pitiot's avatar
pitiot committed
205

pitiot's avatar
init  
pitiot committed
206 207 208
	m_sh1->setClipPlaneParamsAll(clip_id1, Geom::Vec3f(0,0,1), m_PosObj);
	m_sh2->setClipPlaneParamsAll(clip_id2, Geom::Vec3f(0,0,1), m_PosObj);
	m_explode_render->setClippingPlane(Geom::Vec4f(0,0,1,m_PosObj*Geom::Vec3f(0,0,-1)));
pitiot's avatar
pitiot committed
209

pitiot's avatar
pitiot committed
210 211 212
    m_MovingObjectVBO = new Utils::VBO();
    m_MovingObjectVBO->setDataSize(3);
    m_MovingObjectVBO->allocate(simul.aiguille->nbVertices);
pitiot's avatar
pitiot committed
213 214 215

    //initialisation aiguille

pitiot's avatar
pitiot committed
216
    PFP::VEC3* data = static_cast<PFP::VEC3*>(m_MovingObjectVBO->lockPtr());
pitiot's avatar
pitiot committed
217 218 219 220 221
    for (unsigned int i=0; i< simul.aiguille->nbVertices; ++i)
    {
        VEC3 p = simul.aiguille->parts_[i]->getPosition();
        data[i] = p;
    }
pitiot's avatar
pitiot committed
222
    m_MovingObjectVBO->releasePtr();
pitiot's avatar
pitiot committed
223 224

    m_sprite = new Utils::PointSprite();
pitiot's avatar
pitiot committed
225
    m_sprite->setAttributePosition(m_MovingObjectVBO);
pitiot's avatar
pitiot committed
226 227 228
    m_sprite->setSize(simul.aiguille->width);

    registerShader(m_sprite);
pitiot's avatar
pitiot committed
229 230
    m_frame_MovingObject = new Utils::FrameManipulator();
    m_frame_MovingObject->setSize(5.0f);
pitiot's avatar
pitiot committed
231 232 233 234
//    VEC3 pos1 = simul.aiguille->parts_[0]->getPosition();
//    VEC3 pos2 = simul.aiguille->parts_[1]->getPosition();


pitiot's avatar
pitiot committed
235 236 237 238 239 240
//    m_frame_MovingObject->storeProjection(0);
//    CGoGNout<<m_frame_MovingObject->getPosition()<<CGoGNendl;
//    m_frame_MovingObject->translate(0,pos1[0]);
//    CGoGNout<<m_frame_MovingObject->getPosition()<<CGoGNendl;
//  m_frame_MovingObject->translate(1,pos1[1]);
//  m_frame_MovingObject->translate(2,pos1[2]);
pitiot's avatar
pitiot committed
241 242 243 244 245 246
    //tentative cylindre
//    cylinder->translate((pos1-cylinder->getPosition())/2);
//    cylinder = new Utils::Pickable(Utils::Pickable::CYLINDER,2);

//    cylinder->scale((pos2-pos1)/2);

pitiot's avatar
init  
pitiot committed
247
}
pitiot's avatar
pitiot committed
248 249


pitiot's avatar
merging  
pitiot committed
250

pitiot's avatar
init  
pitiot committed
251 252
void Volusion::cb_redraw()
{
pitiot's avatar
pitiot committed
253 254


pitiot's avatar
pitiot committed
255 256


pitiot's avatar
init  
pitiot committed
257 258
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_LIGHTING);
Arash HABIBI's avatar
Arash HABIBI committed
259

pitiot's avatar
init  
pitiot committed
260 261
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1.0f, 1.0f);
pitiot's avatar
maj  
pitiot committed
262

pitiot's avatar
pitiot committed
263
    if(render_MovingObject)
pitiot's avatar
pitiot committed
264 265 266 267
    {

        m_ds->newList(GL_COMPILE_AND_EXECUTE);
        m_ds->begin(GL_LINE_STRIP);
pitiot's avatar
pitiot committed
268

pitiot's avatar
pitiot committed
269 270
        m_ds->lineWidth(10.0f);

pitiot's avatar
pitiot committed
271
        for(Segment * s : simul.aiguille->Segments_)
pitiot's avatar
pitiot committed
272
        {
pitiot's avatar
pitiot committed
273 274
            m_ds->color3f(s->r,s->g,s->b);
            VEC3 p = s->p2;
pitiot's avatar
pitiot committed
275 276
            m_ds->vertex(p);
        }
pitiot's avatar
pitiot committed
277 278 279
        m_ds->color3f(0,0.5f,1.0f);
        m_ds->vertex(simul.aiguille->parts_[1]->getPosition());
        m_ds->vertex(simul.aiguille->parts_[0]->getPosition());
pitiot's avatar
pitiot committed
280 281 282 283 284 285 286

        m_ds->end();
        m_ds->endList();
//        VEC3 pos1 = simul.aiguille->parts_[0]->getPosition();
//        VEC3 pos2 = simul.aiguille->parts_[1]->getPosition();
//        float f;
//        VEC3 cylinder_axis =cylinder->getAxisScale(2,f);
pitiot's avatar
pitiot committed
287 288 289 290 291 292 293 294 295 296 297 298
        PFP::VEC3* data = static_cast<PFP::VEC3*>(m_MovingObjectVBO->lockPtr());
        int n= simul.aiguille->nbVertices;
        for(int i = 0; i< n; i ++)
        {
            VEC3 p = simul.aiguille->parts_[i]->getPosition();

            data[i] = p;
        }


        m_MovingObjectVBO->releasePtr();
//        m_frame_MovingObject->draw();
pitiot's avatar
pitiot committed
299 300 301 302 303 304 305 306 307 308 309 310 311
//        CGoGNout<<Geom::angle(pos2-pos1,cylinder_axis)<<CGoGNendl;
//        cylinder->rotate(Geom::angle(pos2-pos1,cylinder_axis),cylinder_axis^(pos2-pos1));

//        cylinder->translate((((pos1+pos2)/2)-cylinder->getPosition())/2);
//        cylinder->draw();


        m_sprite->enableVertexAttribs();
        glDrawArrays(GL_POINTS, 0, simul.aiguille->nbVertices);
        m_sprite->disableVertexAttribs();


    }
pitiot's avatar
up  
pitiot committed
312 313 314
    if(false) //affichage des normales
    {
        Dart volume=simul.envMap_.map.indexDart(1500);
pitiot's avatar
pitiot committed
315
        for (Face d : facesIncidentToVolume3(simul.envMap_.map,volume))
pitiot's avatar
up  
pitiot committed
316
        {
pitiot's avatar
pitiot committed
317

pitiot's avatar
up  
pitiot committed
318 319 320 321 322 323 324 325 326
            m_ds->newList(GL_COMPILE_AND_EXECUTE);
            m_ds->begin(GL_LINE_STRIP);
            m_ds->color3f(0,1.0f,0);
            m_ds->lineWidth(10.0f);
            m_ds->vertex(simul.envMap_.facecenter[d]);
            m_ds->vertex(simul.envMap_.facecenter[d]+simul.envMap_.normaleFromVolume(volume,d));
            m_ds->end();
            m_ds->endList();
        }
pitiot's avatar
pitiot committed
327

pitiot's avatar
up  
pitiot committed
328 329
    }

pitiot's avatar
pitiot committed
330
    if (draw_dart && dartSlider < (simul.envMap_.map.end().index))
pitiot's avatar
up  
pitiot committed
331
    {
pitiot's avatar
pitiot committed
332 333
        m_topo_render->overdrawDart(simul.envMap_.map.indexDart(dartSlider),15.0f,1.0f,0.0f,1.0f);

pitiot's avatar
up  
pitiot committed
334 335
    }

pitiot's avatar
pitiot committed
336 337
    if(render_belonging)
    {
pitiot's avatar
pitiot committed
338 339 340 341 342 343 344 345 346 347 348 349 350 351
        if (dock.comboBoxEdge->count()<simul.aiguille->nbEdges)
        {
            dock.comboBoxEdge->clear();
            dock.comboBoxEdge->addItem("Aiguille entiere",2);
            for(unsigned int i = 0; i< simul.aiguille->nbEdges;i++)
            {
                std::ostringstream oss ;
                oss<<"arete "<<i;
                const QString& s=oss.str().c_str();
                dock.comboBoxEdge->addItem(s,2);
            }
        }


pitiot's avatar
pitiot committed
352 353 354 355 356
        if(val_comboEdge==0)
        {

            for(unsigned int i =0;i<simul.aiguille->nbEdges;i++)
            {
pitiot's avatar
pitiot committed
357
//                 m_topo_render->overdrawDart(simul.aiguille->parts_[i]->d,10.0f,1.0f,0,0);
pitiot's avatar
pitiot committed
358 359
                for(auto it = simul.aiguille->belonging_cells[i].begin(); it !=simul.aiguille->belonging_cells[i].end();++it)
                {
pitiot's avatar
pitiot committed
360
                    for (Edge d : edgesIncidentToVolume3(simul.envMap_.map,(*it)))
pitiot's avatar
pitiot committed
361 362 363 364
                    {

                        m_topo_render->overdrawDart(d,5.0f,0,1.0f,0);
                    }
pitiot's avatar
pitiot committed
365

pitiot's avatar
pitiot committed
366 367 368

                }
            }
pitiot's avatar
pitiot committed
369
//             m_topo_render->overdrawDart(simul.aiguille->parts_[simul.aiguille->nbEdges]->d,10.0f,1.0f,0,0);
pitiot's avatar
pitiot committed
370 371 372 373
        }
        else
        {

pitiot's avatar
pitiot committed
374 375
//            m_topo_render->overdrawDart(simul.aiguille->parts_[val_comboEdge-1]->d,10.0f,1.0f,0,0);
//            m_topo_render->overdrawDart(simul.aiguille->parts_[val_comboEdge]->d,10.0f,1.0f,0,0);
pitiot's avatar
pitiot committed
376 377 378 379
            int i = val_comboEdge-1;
            for(auto it = simul.aiguille->belonging_cells[i].begin(); it !=simul.aiguille->belonging_cells[i].end();++it)
            {

pitiot's avatar
pitiot committed
380
                for (Edge d : edgesIncidentToVolume3(simul.envMap_.map,(*it)))
pitiot's avatar
pitiot committed
381 382 383 384
                {

                    m_topo_render->overdrawDart(d,5.0f,0,1.0f,0);
                }
pitiot's avatar
pitiot committed
385

pitiot's avatar
pitiot committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400

            }
        }

    }

    if(render_neighbors)
    {
        if(val_comboEdge==0)
        {
            for(unsigned int i =0;i<simul.aiguille->nbEdges;i++)
            {

                for(auto it = simul.aiguille->neighbor_cells[i].begin(); it !=simul.aiguille->neighbor_cells[i].end();++it)
                {
pitiot's avatar
pitiot committed
401
                    for (Edge d : edgesIncidentToVolume3(simul.envMap_.map,(*it)))
pitiot's avatar
pitiot committed
402 403 404 405
                    {

                        m_topo_render->overdrawDart(d,5.0f,1.0f,0.0f,0.8f);
                    }
pitiot's avatar
pitiot committed
406

pitiot's avatar
pitiot committed
407 408 409 410 411 412 413 414 415 416

                }

            }
        }
        else
        {
            int i = val_comboEdge-1;
            for(auto it = simul.aiguille->neighbor_cells[i].begin(); it !=simul.aiguille->neighbor_cells[i].end();++it)
            {
pitiot's avatar
pitiot committed
417
                for (Edge d : edgesIncidentToVolume3(simul.envMap_.map,(*it)))
pitiot's avatar
pitiot committed
418 419 420
                {
                    m_topo_render->overdrawDart(d,5.0f,1.0f,0.0f,0.8f);
                }
pitiot's avatar
pitiot committed
421

pitiot's avatar
pitiot committed
422 423 424 425 426 427 428

            }

        }
    }


pitiot's avatar
init  
pitiot committed
429
	if (render_topo)
pitiot's avatar
pitiot committed
430 431 432 433
    {
            m_topo_render->drawTopo();

    }
pitiot's avatar
maj  
pitiot committed
434

pitiot's avatar
init  
pitiot committed
435
	if (render_edges)
David Cazier's avatar
David Cazier committed
436
	{
pitiot's avatar
init  
pitiot committed
437 438
		glLineWidth(2.0f);
		m_explode_render->drawEdges();
pitiot's avatar
pitiot committed
439

Pierre Kraemer's avatar
Pierre Kraemer committed
440
	}
pitiot's avatar
pitiot committed
441

pitiot's avatar
init  
pitiot committed
442
	glDisable(GL_POLYGON_OFFSET_FILL);
Thomas Jund's avatar
Thomas Jund committed
443

pitiot's avatar
init  
pitiot committed
444
	if (render_volumes)
David Cazier's avatar
David Cazier committed
445
	{
pitiot's avatar
init  
pitiot committed
446
		m_explode_render->drawFaces();
Pierre Kraemer's avatar
Pierre Kraemer committed
447
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
448

pitiot's avatar
init  
pitiot committed
449
	if (clip_volume && !hide_clipping)
pitiot's avatar
pitiot committed
450
	{
pitiot's avatar
init  
pitiot committed
451 452
		m_frame->draw();
		m_PlanePick->draw();
Pierre Kraemer's avatar
Pierre Kraemer committed
453 454 455
	}
}

pitiot's avatar
pitiot committed
456

pitiot's avatar
init  
pitiot committed
457
void  Volusion::cb_mousePress(int /*button*/, int x, int y)
Pierre Kraemer's avatar
Pierre Kraemer committed
458
{
pitiot's avatar
pitiot committed
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
    if (Shift())
    {

        if (hide_clipping || !clip_volume)
            return;

        m_begX = x;
        m_begY = y;

        // get ray of selection
        Geom::Vec3f rayA,rayB;
        float dist = getOrthoScreenRay(x,y,rayA,rayB);
        Geom::Vec3f AB = rayB-rayA;

        unsigned int fr_picked =0;
        // picking the frame -> axis
        fr_picked = m_frame->pick(rayA,AB,dist);

        if (fr_picked != 0)
        {
            m_pickedAxis=fr_picked;
            m_frame->highlight(m_pickedAxis);
            m_frame->storeProjection(m_pickedAxis);
            updateGL();
        }
    }
    else if (Control())
    {
        startX=x;
        startY=y;
pitiot's avatar
pitiot committed
489 490
        m_frame_MovingObject->storeProjection(0);
        oldPosSprite=m_frame_MovingObject->getPosition();
pitiot's avatar
pitiot committed
491 492
        updateGL();
    }
Pierre Kraemer's avatar
Pierre Kraemer committed
493
}
494

pitiot's avatar
init  
pitiot committed
495
void  Volusion::cb_mouseRelease(int /*button*/, int /*x*/, int /*y*/)
Thomas's avatar
Thomas committed
496 497
{

pitiot's avatar
pitiot committed
498 499
    if (!hide_clipping && clip_volume)
    {
500

pitiot's avatar
pitiot committed
501 502 503 504
        m_pickedAxis=0;
        m_frame->highlight(m_pickedAxis);
        updateGL();
    }
pitiot's avatar
pitiot committed
505
    if (render_MovingObject)
pitiot's avatar
pitiot committed
506
        updateGL();
507

Thomas's avatar
Thomas committed
508 509
}

pitiot's avatar
init  
pitiot committed
510
void  Volusion::cb_mouseMove(int buttons, int x, int y)
Pierre Kraemer's avatar
Pierre Kraemer committed
511
{
pitiot's avatar
pitiot committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
    if (Shift())
    {


        if (hide_clipping || !clip_volume)
            return;

        // rotation selected ?
        if (Utils::FrameManipulator::rotationAxis(m_pickedAxis))
        {
            if (buttons&1)
            {
                float angle = m_frame->angleFromMouse(x,y,x-m_begX, y-m_begY);
                m_frame->rotate(m_pickedAxis, angle);
            }
            else if (buttons&2)
                m_frame->rotateInScreen(x-m_begX, y-m_begY);

            m_PlanePick->transfo() = m_frame->transfo();
        }
        // translation selected
        else if (Utils::FrameManipulator::translationAxis(m_pickedAxis))
        {
            if (buttons&1)
            {
                float dist =  m_frame->distanceFromMouse(x-m_begX, y-m_begY);
                m_frame->translate(m_pickedAxis, dist);
            }
            else if (buttons&2)
                m_frame->translateInScreen(x-m_begX, y-m_begY);

            m_PlanePick->transfo() = m_frame->transfo();
        }
        // scale selected
        else if (Utils::FrameManipulator::scaleAxis(m_pickedAxis) )
        {
            float scale = m_frame->scaleFromMouse(x-m_begX, y-m_begY);
            m_frame->scale(m_pickedAxis, scale );
            m_PlanePick->transfo() = m_frame->transfo();
        }

        Geom::Vec3f pos = m_PlanePick->getPosition();
        float pipo;
        Geom::Vec3f normal = m_PlanePick->getAxisScale(2, pipo); // 2 = Z axis = plane normal
        float d = -(pos*normal);
        m_explode_render->setClippingPlane(Geom::Vec4f(normal[0],normal[1],normal[2],d));

        m_sh1->setClipPlaneParamsAll(clip_id1, normal, pos);
        m_sh2->setClipPlaneParamsAll(clip_id2, normal, pos);

        m_begX = x;
        m_begY = y;
        updateGL();
        return;
    }
    else if(Control())
    {
pitiot's avatar
pitiot committed
569
        m_frame_MovingObject->translateInScreen(x-startX, y-startY);
pitiot's avatar
pitiot committed
570

pitiot's avatar
pitiot committed
571 572 573
//        cylinder->transfo() = m_frame_MovingObject->transfo();
//        simul.aiguille->transfo(m_frame_MovingObject->transfo());
        VEC3 diff = m_frame_MovingObject->getPosition()-oldPosSprite;
pitiot's avatar
pitiot committed
574 575
//        CGoGNout<<"deplacement de : "<<diff<<CGoGNendl;

pitiot's avatar
pitiot committed
576

pitiot's avatar
pitiot committed
577
        simul.aiguille->move(diff);
pitiot's avatar
pitiot committed
578

pitiot's avatar
pitiot committed
579 580
        startX=x;
        startY=y;
pitiot's avatar
pitiot committed
581
        oldPosSprite=m_frame_MovingObject->getPosition();
pitiot's avatar
pitiot committed
582 583
        updateGL();
    }
584

pitiot's avatar
init  
pitiot committed
585
}
586

Pierre Kraemer's avatar
Pierre Kraemer committed
587

588 589


pitiot's avatar
init  
pitiot committed
590
int main(int argc, char **argv)
Pierre Kraemer's avatar
Pierre Kraemer committed
591
{
pitiot's avatar
merging  
pitiot committed
592 593


Thomas Jund's avatar
Thomas Jund committed
594

pitiot's avatar
init  
pitiot committed
595 596 597 598
    // un peu d'interface
	QApplication app(argc, argv);
	Volusion sqt;
	sqt.simul.init(argc,argv);
Thomas Jund's avatar
Thomas Jund committed
599

pitiot's avatar
init  
pitiot committed
600
	// interface de tuto5.ui
pitiot's avatar
pitiot committed
601 602

    sqt.setDock(&(sqt.dock));
603

pitiot's avatar
init  
pitiot committed
604
	//  bounding box
pitiot's avatar
pitiot committed
605
    Geom::BoundingBox<VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(sqt.simul.envMap_.map, sqt.simul.envMap_.position);
pitiot's avatar
init  
pitiot committed
606 607
	sqt.m_WidthObj = std::max<REAL>(std::max<REAL>(bb.size(0), bb.size(1)), bb.size(2));
	sqt.m_PosObj = (bb.min() +  bb.max()) / REAL(2);
pitiot's avatar
merging  
pitiot committed
608

pitiot's avatar
init  
pitiot committed
609 610
    // envoit info BB a l'interface
	sqt.setParamObject(sqt.m_WidthObj, sqt.m_PosObj.data());
Pierre Kraemer's avatar
Pierre Kraemer committed
611

pitiot's avatar
pitiot committed
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
    sqt.setCallBack( sqt.dock.checkBox_volumes, SIGNAL(toggled(bool)), SLOT(volumes_onoff(bool)) );
    sqt.setCallBack( sqt.dock.checkBox_edges, SIGNAL(toggled(bool)), SLOT(edges_onoff(bool)) );
    sqt.setCallBack( sqt.dock.checkBox_topo, SIGNAL(toggled(bool)), SLOT(topo_onoff(bool)) );
    sqt.setCallBack( sqt.dock.checkBox_MovingObject, SIGNAL(toggled(bool)), SLOT(MovingObject_onoff(bool)) );
    sqt.setCallBack( sqt.dock.checkBox_belonging, SIGNAL(toggled(bool)), SLOT(belonging_onoff(bool)) );
    sqt.setCallBack( sqt.dock.checkBox_neighbors, SIGNAL(toggled(bool)), SLOT(neighbors_onoff(bool)) );
    sqt.setCallBack( sqt.dock.checkBox_hide, SIGNAL(toggled(bool)), SLOT(hide_onoff(bool)) );
    sqt.setCallBack( sqt.dock.checkBox_plane, SIGNAL(toggled(bool)), SLOT(clipping_onoff(bool)) );
    sqt.setCallBack( sqt.dock.slider_explode, SIGNAL(valueChanged(int)), SLOT(slider_explode(int)) );
     sqt.setCallBack( sqt.dock.comboBoxEdge, SIGNAL(	activated(int)), SLOT(comboEdge(int)) );
    sqt.setCallBack( sqt.dock.slider_explode, SIGNAL(sliderPressed()), SLOT(slider_pressed()) );
    sqt.setCallBack( sqt.dock.slider_explode, SIGNAL(sliderReleased()), SLOT(slider_released()) );
    sqt.setCallBack(sqt.dock.spinBox_dart, SIGNAL(valueChanged(int)), SLOT(slot_slide(int))) ;
    sqt.setCallBack(sqt.dock.checkBox_drawDart, SIGNAL(toggled(bool)), SLOT(dart_onoff(bool))) ;
    sqt.setCallBack( sqt.dock.slider_explode_face, SIGNAL(valueChanged(int)), SLOT(slider_explodeF(int)) );

    sqt.setCallBack( sqt.dock.slider_explode_face, SIGNAL(sliderPressed()), SLOT(slider_pressed()) );
    sqt.setCallBack( sqt.dock.slider_explode_face, SIGNAL(sliderReleased()), SLOT(slider_released()) );
630

pitiot's avatar
init  
pitiot committed
631
	sqt.show();
pitiot's avatar
pitiot committed
632 633
    sqt.dock.slider_explode->setValue(100);
    sqt.dock.slider_explode_face->setValue(100);
pitiot's avatar
init  
pitiot committed
634 635 636
	sqt.clipping_onoff(false);
	sqt.topo_onoff(false);
	sqt.edges_onoff(true);
pitiot's avatar
pitiot committed
637 638 639 640 641 642 643 644 645 646
    sqt.dock.checkBox_MovingObject->setChecked(true);
    sqt.dock.checkBox_topo->setChecked(false);
    sqt.dock.checkBox_belonging->setChecked(false);
    sqt.dock.checkBox_neighbors->setChecked(false);
    sqt.dock.checkBox_plane->setChecked(false);
    sqt.dock.checkBox_hide->setChecked(true);

    sqt.dock.spinBox_dart->setRange(0, sqt.simul.envMap_.map.end().index) ;

    sqt.dock.comboBoxEdge->addItem("Aiguille entiere",2);
pitiot's avatar
pitiot committed
647 648 649 650 651
    for(unsigned int i = 0; i< sqt.simul.aiguille->nbEdges;i++)
    {
        std::ostringstream oss ;
        oss<<"arete "<<i;
        const QString& s=oss.str().c_str();
pitiot's avatar
pitiot committed
652
        sqt.dock.comboBoxEdge->addItem(s,2);
pitiot's avatar
pitiot committed
653
    }
David Cazier's avatar
David Cazier committed
654

pitiot's avatar
init  
pitiot committed
655 656
	// et on attend la fin.
	return app.exec();
pitiot's avatar
merging  
pitiot committed
657

pitiot's avatar
merging  
pitiot committed
658

Arash HABIBI's avatar
Arash HABIBI committed
659 660


pitiot's avatar
merging  
pitiot committed
661

pitiot's avatar
init  
pitiot committed
662
	// exemple utilisation chrono
Pierre Kraemer's avatar
Pierre Kraemer committed
663

pitiot's avatar
merging  
pitiot committed
664

pitiot's avatar
init  
pitiot committed
665
//	Utils::Chrono ch;
pitiot's avatar
pitiot committed
666
//
pitiot's avatar
pitiot committed
667 668
//	Vertex v(simul.envMap_.map.begin());
////	VEC3 p = Algo::Volume::Geometry::vertexNeighborhoodCentroid<PFP>(simul.envMap_.map,v,simul.envMap_.position);
pitiot's avatar
pitiot committed
669
//
pitiot's avatar
pitiot committed
670 671
//	Vol w(simul.envMap_.map.begin());
//	VEC3 q = Algo::Surface::Geometry::volumeCentroid<PFP>(simul.envMap_.map,w,simul.envMap_.position);
pitiot's avatar
init  
pitiot committed
672 673

//	ch.start();
pitiot's avatar
pitiot committed
674 675 676 677
//	float vol = Algo::Geometry::Parallel::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
//	vol += Algo::Geometry::Parallel::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
//	vol += Algo::Geometry::Parallel::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
//	vol += Algo::Geometry::Parallel::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
pitiot's avatar
init  
pitiot committed
678 679 680 681
//	std::cout << ch.elapsed()<< " ms //  val="<<vol<< std::endl;
//
//	std::cout << "Compute Volume ->"<< std::endl;
//	ch.start();
pitiot's avatar
pitiot committed
682
//	vol = Algo::Geometry::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
pitiot's avatar
init  
pitiot committed
683 684
//	std::cout << ch.elapsed()<< " ms  val="<<vol<< std::endl;
//	ch.start();
pitiot's avatar
pitiot committed
685
//	vol += Algo::Geometry::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
pitiot's avatar
init  
pitiot committed
686 687
//	std::cout << ch.elapsed()<< " ms  val="<<vol<< std::endl;
//	ch.start();
pitiot's avatar
pitiot committed
688
//	vol += Algo::Geometry::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
pitiot's avatar
init  
pitiot committed
689 690
//	std::cout << ch.elapsed()<< " ms  val="<<vol<< std::endl;
//	ch.start();
pitiot's avatar
pitiot committed
691
//	vol += Algo::Geometry::totalVolume<PFP>(simul.envMap_.map, simul.envMap_.position);
pitiot's avatar
init  
pitiot committed
692 693
//	std::cout << ch.elapsed()<< " ms  val="<<vol<< std::endl;

pitiot's avatar
merging  
pitiot committed
694

Pierre Kraemer's avatar
Pierre Kraemer committed
695
}