simpleGMap3.cpp 6.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*******************************************************************************
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                  *
21 22 23 24 25 26 27
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#include "simpleGMap3.h"
#include "Utils/GLSLShader.h"
#include "Algo/Geometry/boundingbox.h"
untereiner's avatar
untereiner committed
28
#include "Algo/Tiling/Volume/cubic.h"
untereiner's avatar
untereiner committed
29
#include "Algo/Modelisation/subdivision3.h"
30 31 32

SimpleGMap3::SimpleGMap3()
{
33 34
    position = myMap.addAttribute<VEC3, VERTEX>("position");
    volume = myMap.addAttribute<VEC3, VOLUME>("volume");
35

36
    //	CellMarker<EDGE> mE(myMap);
37

untereiner's avatar
untereiner committed
38 39
    Algo::Volume::Tilings::Cubic::Grid<PFP> cubic(myMap, 1, 1, 1);
    cubic.embedIntoGrid(position, 1.0f, 1.0f, 1.0f);
40
    myMap.check();
41

untereiner's avatar
untereiner committed
42
//    Dart dp = Algo::Surface::Modelisation::createQuadrangularPyramid<PFP>(myMap);
43

untereiner's avatar
untereiner committed
44 45 46 47 48
//    position[dp] = typename PFP::VEC3(0.5,0.5,-0.5);
//    position[myMap.phi1(dp)] = typename PFP::VEC3(0.5,0.5,0.5);
//    position[myMap.phi1(myMap.phi1(dp))] = typename PFP::VEC3(0.5,-0.5,0.5);
//    position[myMap.phi_1(dp)] = typename PFP::VEC3(0.5,-0.5,-0.5);
//    position[myMap.phi_1(myMap.phi2(dp))] = typename PFP::VEC3(1.5f, 0.0f, 0.0f);
49

untereiner's avatar
untereiner committed
50
//    Dart dtemp = myMap.beta1(myMap.beta0(myMap.beta1(myMap.beta2(myMap.beta1(myMap.beta0(myMap.beta1(myMap.beta2(d))))))));
51

untereiner's avatar
untereiner committed
52
//    myMap.sewVolumes(dtemp,dp);
Thomas's avatar
Thomas committed
53

54 55
    //	Geom::Plane3D<PFP::REAL> pl(VEC3(-1,-0.5,-0.5),VEC3(-1,-0.5,0.5),VEC3(1,0.5,0.5));
    //	Algo::Volume::Modelisation::sliceConvexVolume<PFP>(myMap, position, d, pl);
56

57
    //	myMap.check();
58

59 60
    //	for(unsigned int i = position.begin() ; i != position.end() ; position.next(i))
    //		position[i] += VEC3(2,0,0);
61

62 63 64
    //	Algo::Volume::Modelisation::Primitive3D<PFP> prim(myMap, position);
    //	d = prim.hexaGrid_topo(2,2,1);
    //	prim.embedHexaGrid(1,1,1);
65

66 67 68 69
    //	Dart d1 = myMap.phi1(myMap.phi1(myMap.phi2(myMap.phi1(myMap.phi1(d)))));
    //	VEC3 mid0 = (position[d1] + position[myMap.phi1(d1)]) / 2.0f;
    //	myMap.cutEdge(d1);
    //	position[myMap.phi1(d1)] = mid0;
70

71 72 73
    //	VEC3 mid1 = (position[d] + position[myMap.phi1(d)]) / 2.0f;
    //	myMap.cutEdge(d);
    //	position[myMap.phi1(d)] = mid1;
74

75 76 77 78
    //	d = myMap.phi1(myMap.phi1(myMap.phi2(myMap.phi1(myMap.phi1(d)))));
    //	VEC3 mid = (position[d] + position[myMap.phi1(d)]) / 2.0f;
    //	myMap.cutEdge(d);
    //	position[myMap.phi1(d)] = mid;
79

80
    //	myMap.splitFace(d,myMap.phi1(myMap.phi1(myMap.phi1(d))));
81

82 83 84 85 86 87 88 89 90 91 92 93 94
    //	myMap.check();

    //	for(unsigned int i = position.begin() ; i != position.end() ; position.next(i))
    //		position[i] += VEC3(0,2,0);

    //	Algo::Volume::Modelisation::Primitive3D<PFP> prim2(myMap,position);
    //	d = prim2.hexaGrid_topo(2,1,1);
    //	prim2.embedHexaGrid(1,1,1);

    //	d = myMap.phi2(myMap.phi1(myMap.phi1(myMap.phi2(d))));
    //	myMap.unsewVolumes(d);

    //	myMap.check();
95 96 97 98 99 100
}

void SimpleGMap3::initGUI()
{
}

101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
void SimpleGMap3::cb_keyPress(int code)
{
    switch(code)
    {
        case 'e':
        {
            time_t rawtime;
            struct tm * timeinfo;
            char buffer[80];

            time (&rawtime);
            timeinfo = localtime (&rawtime);

            strftime (buffer,80,".%F.%H:%M:%S",timeinfo);

            std::string filename = std::string("topo_screenshot") + std::string(buffer) + std::string(".svg");
            m_render_topo->svgout2D(filename, modelViewMatrix(), projectionMatrix());
            break;
        }
    }
}

123 124
void SimpleGMap3::cb_initGL()
{
125 126 127 128 129 130 131 132 133 134
    Utils::GLSLShader::setCurrentOGLVersion(2) ;

    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
    VEC3 gPosObj = bb.center() ;
    float tailleX = bb.size(0) ;
    float tailleY = bb.size(1) ;
    float tailleZ = bb.size(2) ;
    float gWidthObj = std::max<float>(std::max<float>(tailleX, tailleY), tailleZ) ;
    setParamObject(gWidthObj, gPosObj.data());

135
	m_render_topo = new Algo::Render::GL2::Topo3Render<PFP>();
136 137
    m_render_topo->setDartWidth(2.0f);
    m_render_topo->setInitialDartsColor(1.0f,1.0f,1.0f);
138
	m_render_topo->updateData(myMap, position, 0.9f,0.9f,0.8f);
139 140 141 142
}

void SimpleGMap3::cb_redraw()
{
143 144 145
    glDisable(GL_LIGHTING);
    glLineWidth(1.0f);
    m_render_topo->drawTopo();
146 147 148 149 150 151 152 153
}

/**********************************************************************************************
 *                                      MAIN FUNCTION                                         *
 **********************************************************************************************/

int main(int argc, char **argv)
{
154
    QApplication app(argc, argv) ;
155

156 157 158
    SimpleGMap3 sqt ;
    sqt.setGeometry(0, 0, 1000, 800) ;
    sqt.show() ;
159

160
    sqt.initGUI() ;
161

162
    return app.exec() ;
163
}