Viewer.cpp 17.8 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
24

Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27 28 29 30
#include <iostream>
#include "Utils/os_spec.h"

#include "Utils/GLSLShader.h"
#include "Utils/glutwin.h"

31
#include "Topology/generic/parameters.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#include "Topology/map/map2.h"
#include "Topology/generic/embeddedMap2.h"

#include "Geometry/vector_gen.h"

#include "Algo/Import/import.h"

#include "Algo/Render/map_glRender.h"
#include "Algo/Render/vbo_MapRender.h"

#include "Algo/Geometry/normal.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/area.h"
#include "Algo/Geometry/intersection.h"

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

#include "Algo/MC/marchingcubeGen.h"

#include "Topology/generic/ecell.h"

#include "Algo/Export/export.h"

using namespace CGoGN;

59
struct PFP: public PFP_STANDARD
Pierre Kraemer's avatar
Pierre Kraemer committed
60
{
Pierre Kraemer's avatar
Pierre Kraemer committed
61
	// definition of the map
Pierre Kraemer's avatar
Pierre Kraemer committed
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
	typedef EmbeddedMap2<Map2> MAP;
};


PFP::MAP myMap;
SelectorTrue allDarts;
PFP::TVEC3 position;
PFP::TVEC3 normal;


class myGlutWin: public Utils::SimpleGlutWin
{
public:
        Geom::Vec4f colDif;

        Geom::Vec4f colSpec;

        Geom::Vec4f colClear;

        Geom::Vec4f colNormal;

        float shininess;

        /**
         * position of object
         */
        Geom::Vec3f gPosObj;

        /**
         * width of object
         */
        float gWidthObj;

        /**
         * factor to apply to normal drawing
         */
        float normalScaleFactor;

        /**
         * redraw CB
         */
        void myRedraw();

        /**
         * keyboard CB
         */
        void myKeyboard(unsigned char keycode, int x, int y);

		 /**
		 * inverse the normal when computing normal
		 */
        bool invertedNormals;

        /**
         * inverse object for culling
         */
        bool invertedObject;

        /**
         * rendering normals ?
         */
        bool renderNormal;

        /**
         * rendering lines ?
         */
        bool renderLines;

        /**
        * aide affichee
        */
        bool aff_help;

        /**
         * style of rendering
         */
        int renderStyle;

Sylvain Thery's avatar
Sylvain Thery committed
140
        Algo::Render::GL2::MapRender_VBO* m_render;
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142 143 144 145 146 147 148 149 150 151 152 153 154

        /**
         * render mode enum
         */
        enum { CLEAR=1, LINE, FLAT, GOURAUD, PHONG, NORMAL,NONE };

	myGlutWin(	int* argc, char **argv, int winX, int winY) :
				SimpleGlutWin(argc,argv,winX,winY),
				renderNormal(false),
				renderLines(false),
				aff_help(true)
        {
			if (this->shaderOk) shaders[0].loadShaders("phong_vs.txt","phong_ps.txt");

Sylvain Thery's avatar
Sylvain Thery committed
155 156
//			m_cb = new Algo::Render::GL2::GL2_CB_PositionNormal<PFP>(myMap);
//			m_render = new Algo::Render::GL2::MapRender_VBO(myMap, allDarts, m_cb);
Pierre Kraemer's avatar
Pierre Kraemer committed
157 158
//
//			m_render->initBuffers();
Sylvain Thery's avatar
Sylvain Thery committed
159 160 161 162
//			m_render->updateData(Algo::Render::GL2::POSITIONS, position );
//			m_render->updateData(Algo::Render::GL2::NORMALS, normal );
//			m_render->initPrimitives<PFP>(myMap, good, Algo::Render::GL2::TRIANGLES);
//			m_render->initPrimitives<PFP>(myMap, good, Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
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

		}
};


void myGlutWin::myRedraw(void)
{

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glPushMatrix();

        float sc = 50./gWidthObj;
        glScalef(sc,sc,sc);
        glTranslatef(-gPosObj[0],-gPosObj[1],-gPosObj[2]);

        glEnable(GL_LIGHTING);
    	glEnable(GL_COLOR_MATERIAL);
    	glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
    	glColor3f(0.7f,0.8f,1.0f);

    	glMaterialfv(GL_FRONT,GL_SPECULAR,colSpec.data());
    	glMaterialf( GL_FRONT, GL_SHININESS, shininess );

    	Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;

    	glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
Sylvain Thery's avatar
Sylvain Thery committed
189
//        m_render->draw(Algo::Render::GL2::TRIANGLES);
Pierre Kraemer's avatar
Pierre Kraemer committed
190 191 192 193
       	Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::FLAT, 0.9 , position, normal, normal);

        glDisable(GL_LIGHTING);
        glColor3f(0.0f,0.0f,0.0f);
Sylvain Thery's avatar
Sylvain Thery committed
194
//        m_render->draw(Algo::Render::GL2::LINES);
Pierre Kraemer's avatar
Pierre Kraemer committed
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
        glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
      	Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::LINE, 1.0, position, normal);
//      	glPointSize(5.0f);
//      	glColor3f(1.0f,.0f,.0f);
//        glPolygonMode(GL_FRONT_AND_BACK,GL_POINT);
//      	Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::LINE, 0.9, position, normal);


//    	Algo::Render::Direct::renderTriQuadPoly<PFP>(myMap, Algo::Render::Direct::FLAT, 0.9, position, normal);
//		TESTED OK


        glPopMatrix();

        // a faire en dernier pour que ca dessine au dessus
        if (aff_help) {
                glColor3f(1.0f,1.0f,1.0f);
                printString2D(10,20,"Keys:\n----\nf : flat (DL)\ng: gouraud (DL) \np: phong ( strip DL)\na: dual\nu: simplification (nbfaces/2)\nC : catmullclark\nR : square3\nL: Loop\nO: inverse objet\nn: affiche normales\nZ/z: shininess\nD/d: focale\nv: calcul fps\nh: affiche l'aide");
        }

}

void myGlutWin::myKeyboard(unsigned char keycode, int, int)
{

	switch (keycode)
	{
	case 'a':
		{
			unsigned int end = position.end();
			for(unsigned int it = position.begin(); it !=  end; position.next(it))
			{
				position[it] += normal[it] * 0.1;
			}

Sylvain Thery's avatar
Sylvain Thery committed
230
			m_render->updateData(Algo::Render::GL2::POSITIONS, position );
Pierre Kraemer's avatar
Pierre Kraemer committed
231 232 233 234 235 236 237 238 239 240 241
		}
		break;

	case 'z':
		{
			unsigned int end = normal.end();
			for(unsigned int it = normal.begin(); it !=  end; normal.next(it))
			{
				normal[it] *= -1.0f;
			}

Sylvain Thery's avatar
Sylvain Thery committed
242
			m_render->updateData(Algo::Render::GL2::NORMALS, normal );
Pierre Kraemer's avatar
Pierre Kraemer committed
243 244 245 246 247 248
		}
		break;

	case 's':
		{
			GLint t1 = glutGet(GLUT_ELAPSED_TIME);
249
			Algo::Modelisation::CatmullClarkSubdivision<PFP>(myMap, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
250 251
			GLint t2 = glutGet(GLUT_ELAPSED_TIME);
			GLfloat seconds = (t2 - t1) / 1000.0f;
252
			CGoGNout << "catmull-clark: "<< seconds << "sec" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
253 254 255 256 257 258 259 260 261

			Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal) ;

			break;
		}

	case 'l':
		{
			GLint t1 = glutGet(GLUT_ELAPSED_TIME);
262 263 264 265 266
			Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
			Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
			Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
			Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
			Algo::Modelisation::LoopSubdivision<PFP>(myMap, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
267 268
			GLint t2 = glutGet(GLUT_ELAPSED_TIME);
			GLfloat seconds = (t2 - t1) / 1000.0f;
269
			CGoGNout << "loop: "<< seconds << "sec" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
270 271 272 273 274 275 276 277 278

			Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal, allDarts) ;

			break;
		}

	case 'd':
		{
			GLint t1 = glutGet(GLUT_ELAPSED_TIME);
279
			Algo::Modelisation::Sqrt3Subdivision<PFP>(myMap, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
280 281
			GLint t2 = glutGet(GLUT_ELAPSED_TIME);
			GLfloat seconds = (t2 - t1) / 1000.0f;
282
			CGoGNout << "dual: "<< seconds << "sec" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334

			Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal, allDarts) ;

			break;
		}
	}

	glutPostRedisplay();
}



class Scal3D
{
protected:
	int m_size;
	int m_mid;
public:
	Scal3D(int size) : m_size(size), m_mid(size/2) {}
	float getVoxSizeX() {return 1.0f;}
	float getVoxSizeY() {return 1.0f;}
	float getVoxSizeZ() {return 1.0f;}

	long getWidthX() { return m_size;}
	long getWidthY() { return m_size;}
	long getWidthZ() { return m_size;}

	float getVoxel(long x, long y, long z)
	{
		float  rad = sqrt(float((x-m_mid)*(x-m_mid) + (y-m_mid)*(y-m_mid) + (z-m_mid)*(z-m_mid)));
		float  radx = sqrt(float((y-m_mid)*(y-m_mid) + (z-m_mid)*(z-m_mid)));
		float  rady = sqrt(float((x-m_mid)*(x-m_mid) + (z-m_mid)*(z-m_mid)));
		float  radz = sqrt(float((x-m_mid)*(x-m_mid) + (y-m_mid)*(y-m_mid)));

		float val = 1.0f - rad/m_mid;

		if ((val <0.0f) || (radz < m_size/10)||(rady < m_size/8)||(radx < m_size/6))
			return 0.0f;
		return val;
	}
};




int main(int argc, char **argv)
{

//    GLint t1 = glutGet(GLUT_ELAPSED_TIME);

	if (argc == 1)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
335 336
		position = myMap.addAttribute<Geom::Vec3f>(VERTEX_ORBIT, "position");

337
		CGoGNout <<"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
338 339 340 341
//		typedef uint8 DATATYPE;
//		Algo::MC::Image<DATATYPE> myImg;
//		myImg.loadPNG3D("liver.png");
//
342 343
//		CGoGNout << "Image chargee"<<CGoGNendl;
//		CGoGNout << myImg.getWidthX() <<"x"<< myImg.getWidthY() <<"x"<< myImg.getWidthZ() << "voxels"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
344 345 346
//
//		// ajouté pour vérifier que ça marche sur les images non bool
//// 		myImg.Blur3();
347
//// 		CGoGNout << "Image lissee"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
348 349 350 351 352 353 354 355
//
//		// fonction de fenetrage de type superieur à ...
//		Algo::MC::WindowingGreater<DATATYPE> myWindFunc;
//
//		// valeur utilisee 0 (donc objet = tout ce qui est diff de 0)
//		myWindFunc.setIsoValue(DATATYPE(127));
//
//		// instanciation du mc
356
//		CGoGNout << "mc init"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
357 358 359 360 361
//		Algo::MC::MarchingCube<DATATYPE,Algo::MC::WindowingGreater,PFP> mc(&myImg, &myMap, position, myWindFunc, false);
//	//	MarchingCube<DATATYPE,WindowingDiff> mc(&myImg, &myMap, myWindFunc, false);
//
//		// realisation du maillage
//		mc.simpleMeshing();
362
//		CGoGNout << "mc ok"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
363 364 365 366 367 368 369 370 371 372 373

//		typedef float DATATYPE;
//
//		// fonction de fenetrage de type superieur à ...
//		Algo::MC::WindowingGreater<DATATYPE> myWindFunc;
//
//		// valeur utilisee 0 (donc objet = tout ce qui est diff de 0)
//		myWindFunc.setIsoValue(DATATYPE(0.32f));
//
//		Scal3D myImg(256);
//
374
//		CGoGNout << "mc init"<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
//		Algo::MC::MarchingCubeGen<DATATYPE, Scal3D, Algo::MC::WindowingGreater,PFP> mc(&myImg, &myMap, position, myWindFunc, false);
//
//		//realisation du maillage
//		mc.simpleMeshing();

		std::vector<Geom::Vec3f> objV;
		objV.push_back(Geom::Vec3f(-1,-1,37));
		objV.push_back(Geom::Vec3f(-1,-2,37));
		objV.push_back(Geom::Vec3f(+1,-2,37));
		objV.push_back(Geom::Vec3f(+1,-1,37));
		objV.push_back(Geom::Vec3f(+2,-1,37));
		objV.push_back(Geom::Vec3f(+2,+1,37));
		objV.push_back(Geom::Vec3f(+1,+1,37));
		objV.push_back(Geom::Vec3f(+1,+2,37));
		objV.push_back(Geom::Vec3f(-1,+2,37));
		objV.push_back(Geom::Vec3f(-1,+1,37));
		objV.push_back(Geom::Vec3f(-2,+1,37));
		objV.push_back(Geom::Vec3f(-2,-1,37));

		std::vector<Geom::Vec3f> pathV;
		std::vector<float> pathRadius;
		pathV.push_back(Geom::Vec3f(0,0,0));		pathRadius.push_back(1.);
		pathV.push_back(Geom::Vec3f(0,0,10));		pathRadius.push_back(1.5);
		pathV.push_back(Geom::Vec3f(10,0,10));		pathRadius.push_back(1.9);
		pathV.push_back(Geom::Vec3f(10,10,10));		pathRadius.push_back(2.5);
		pathV.push_back(Geom::Vec3f(10,10,20));		pathRadius.push_back(3.0);
		pathV.push_back(Geom::Vec3f(10,11,25));		pathRadius.push_back(1.0);
		pathV.push_back(Geom::Vec3f(11,13,30));		pathRadius.push_back(1.5);
		pathV.push_back(Geom::Vec3f(0,0,40));		pathRadius.push_back(.5);
		pathV.push_back(Geom::Vec3f(-20,-10,0.0));	pathRadius.push_back(1.9);
		pathV.push_back(Geom::Vec3f(-10,0 ,-20));	pathRadius.push_back(1.3);
		pathV.push_back(Geom::Vec3f(5,0 ,-10));		pathRadius.push_back(1.);
	//	Algo::Modelisation::extrusion<PFP>(myMap, objV, Geom::Vec3f(0.0,0.0,37.0), Geom::Vec3f(0.0,0.0,1.0),false, pathV, false);
		Algo::Modelisation::extrusion_scale_prim<PFP>(myMap, position, objV, Geom::Vec3f(0.0,0.0,37.0), Geom::Vec3f(0.0,0.0,1.0),false, pathV, false, pathRadius);
	}

//	{
//		Algo::Modelisation::Primitive<PFP> prim(myMap,position);
//
//		prim.grid_topo(2,2);
//
//		prim.embedGrid(8.0f,8.0f);
//
//		Algo::Modelisation::Primitive<PFP> prim2(myMap,position);
//
//		prim2.tore_topo(7,4);
//		prim2.embedTore(25.0f,5.0f);
//
//		GLint t1 = glutGet(GLUT_ELAPSED_TIME);
//
//		myMap.getAttributeContainer(VERTEX_ORBIT).toggleProcess(position);
////		myMap.getAttributeContainer(VERTEX_ORBIT).toggleProcess(idPipo);
//
//		PFP::MAP::EVertex::setContainer(myMap.getAttributeContainer(VERTEX_ORBIT));
//		PFP::MAP::EVertex::setMap(myMap);
//		PFP::MAP::EVertex ec(0);
//
//		GLint t2 = glutGet(GLUT_ELAPSED_TIME);
//			GLfloat seconds = (t2 - t1) / 1000.0f;
434
//			CGoGNout << "triangulation: "<< seconds << "sec" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
435 436 437 438 439 440 441
//
//		Marker m = myMap.getNewMarker(VERTEX_ORBIT);
//		myMap.markEmbVertex(myMap.begin(),m);
//
//		Dart xd = myMap.alpha1(myMap.begin());
//		if (myMap.isMarkedEmbVertex(xd,m))
//		{
442
//			CGoGNout << "Marke"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
443 444 445 446
//		}
//		xd = myMap.phi2(xd);
//		if (myMap.isMarkedEmbVertex(xd,m))
//		{
447
//			CGoGNout << "Marke aussi"<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
448 449 450 451 452 453 454 455 456 457 458
//		}
//
//		myMap.clearEmbMarkers(m,VERTEX_ORBIT);
//		myMap.releaseEmbMarker(m,VERTEX_ORBIT);
//
//	}
	else
	{
		SelectorTrue allDarts;
//		GLint t1 = glutGet(GLUT_ELAPSED_TIME);

Pierre Kraemer's avatar
Pierre Kraemer committed
459 460
		std::vector<std::string> attrNames ;
    	if(!Algo::Import::importMesh<PFP>(myMap, std::string(argv[1]), attrNames))
Pierre Kraemer's avatar
Pierre Kraemer committed
461
    	{
462
    		CGoGNerr << "could not import " << std::string(argv[1]) << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
463 464
    		exit(1);
    	}
Pierre Kraemer's avatar
Pierre Kraemer committed
465 466
		position = myMap.getAttribute<PFP::VEC3>(VERTEX_ORBIT, attrNames[0]) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
		GLint t1 = glutGet(GLUT_ELAPSED_TIME);

//		Algo::Export::exportCTM<PFP>(myMap, position, std::string("pipo.ctm"));

//        Algo::Modelisation::LoopSubdivision<PFP, PFP::TVEC3, PFP::VEC3>(myMap,position);
//        Algo::Modelisation::LoopSubdivision<PFP, PFP::TVEC3, PFP::VEC3>(myMap,position);
//        Algo::Modelisation::CatmullClark<PFP, PFP::TVEC3, PFP::VEC3>(myMap,position);
//        Algo::Modelisation::CatmullClark<PFP, PFP::TVEC3, PFP::VEC3>(myMap,position);


//		PFP::MAP::EVertex::setContainer(myMap.getAttributeContainer(VERTEX_ORBIT));
//		PFP::MAP::EVertex::setMap(myMap);
//		PFP::MAP::EVertex ec(0);
//		myMap.getAttributeContainer(VERTEX_ORBIT).toggleProcess(position);
//
//		Algo::Modelisation::LoopSubdivision<PFP, PFP::EVERTEX, PFP::EVERTEX>(myMap,ec);
//		Algo::Modelisation::LoopSubdivision<PFP, PFP::EVERTEX, PFP::EVERTEX>(myMap,ec);
//	    Algo::Modelisation::CatmullClark<PFP, PFP::EVERTEX, PFP::EVERTEX>(myMap,ec);
//	    Algo::Modelisation::CatmullClark<PFP, PFP::EVERTEX, PFP::EVERTEX>(myMap,ec);


		GLint t2 = glutGet(GLUT_ELAPSED_TIME);
		GLfloat seconds = (t2 - t1) / 1000.0f;
490
		CGoGNout << "subdiv: "<< seconds << "sec" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
491 492 493 494 495 496 497 498 499 500


//        myMap.getAttributeContainer(VERTEX_ORBIT).toggleProcess(position);
//		PFP::MAP::EVertex::setContainer(myMap.getAttributeContainer(VERTEX_ORBIT));
//		PFP::MAP::EVertex::setMap(myMap);
//		PFP::MAP::EVertex ec(0);
//        Algo::Modelisation::triangleSubdivide<PFP, PFP::EVERTEX, PFP::EVERTEX>(myMap,ec);
//        Algo::Modelisation::triangleSubdivide<PFP, PFP::EVERTEX, PFP::EVERTEX>(myMap,ec);
//        Algo::Modelisation::triangleSubdivide<PFP, PFP::EVERTEX, PFP::EVERTEX>(myMap,ec);

501 502 503
        CGoGNout << "Nombre de sommets plonges  "<< myMap.getNbCells(VERTEX_ORBIT)<<CGoGNendl;
        CGoGNout << "Nombre de sommets topo: "<< myMap.getNbOrbits(0)<<CGoGNendl;
        CGoGNout << "Nombre de faces topo: "<< myMap.getNbOrbits(2)<<CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
504 505 506 507


//		GLint t2 = glutGet(GLUT_ELAPSED_TIME);
//		GLfloat seconds = (t2 - t1) / 1000.0f;
508
//		CGoGNout << "import: "<< seconds << "sec" << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
509 510 511 512

	}

		float area = Algo::Geometry::totalArea<PFP>(myMap, position) ;
513
		CGoGNout << "total area = " << area << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
514 515

		bool inter = Algo::Geometry::areTrianglesInIntersection<PFP>(myMap,0,10,position) ;
516
		CGoGNout << "intersection = " << inter << CGoGNendl ;
Pierre Kraemer's avatar
Pierre Kraemer committed
517 518 519 520 521 522 523 524 525 526 527 528

		normal = myMap.addAttribute<Geom::Vec3f>(VERTEX_ORBIT, "normals");
//		PFP::NORMAL normal(normal,myMap);



//		Algo::Geometry::computeNormalVertices<PFP>(myMap, position, normal, allDarts) ;

//		AttributeHandler<Mark> tm(0,myMap);
//		for (Dart dd=myMap.begin(); dd!= myMap.end(); myMap.next(dd))
//		{
//			unsigned int a = myMap.getEmbedding(dd, 0);
529 530 531 532
//			CGoGNout << "dart:"<<dd.index<< " / ";
//			CGoGNout << "emb:"<<a<< " / ";
//			CGoGNout<<position[a]<< " / ";
//			CGoGNout << tm[a]<< CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
533 534 535 536 537 538
//		}



        Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap,position);

539
        CGoGNout << "BB: "<< bb.min() << " / "<< bb.max() << CGoGNendl;
Pierre Kraemer's avatar
Pierre Kraemer committed
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

       // compute width and position of object for centering

        myGlutWin mgw(&argc,argv,800,800);
        mgw.gPosObj = bb.center();

        float tailleX = bb.size(0);
        float tailleY = bb.size(1);
        float tailleZ = bb.size(2);

        mgw.gWidthObj = std::max<float>( std::max<float>(tailleX,tailleY),tailleZ);
        mgw.normalScaleFactor = std::min<float>( std::min<float>(tailleX,tailleY),tailleZ) / 50.0f;


        mgw.colClear = Geom::Vec4f(0.2f,0.2f,0.2f,0.1);
        mgw.colDif = Geom::Vec4f(0.8f,0.9f,0.7f,1.0f);
        mgw.colSpec = Geom::Vec4f(0.9f,0.9f,0.9f,1.0f);
        mgw.colNormal = Geom::Vec4f(1.0f,0.0f,0.0f,1.0f);
        mgw.shininess=80.0f;


        mgw.mainLoop();

        return 0;
}