Пример #1
0
void MyQT::createMap()
{
//	Dart d1 = Algo::Modelisation::createTetrahedron<PFP>(myMap);

//	Dart d2 = d1;

	position = myMap.addAttribute<PFP::VEC3, VERTEX>("position");

	Algo::Modelisation::Polyhedron<PFP> prim1(myMap, position);
	prim1.cylinder_topo(256, 256, true, true); // topo of sphere is a closed cylinder
	prim1.embedSphere(2.0f);

//	Dart d2 = d1;
//	position[d2] = PFP::VEC3(1, 0, 0);
//	d2 = PHI1(d2);
//	position[d2] = PFP::VEC3(-1, 0, 0);
//	d2 = PHI1(d2);
//	position[d2] = PFP::VEC3(0, 2, 0);
//	d2 = PHI<211>(d2);
//	position[d2] = PFP::VEC3(0, 1, 2);

	Algo::Modelisation::Polyhedron<PFP> prim2(myMap, position);
	prim2.cylinder_topo(256, 256, true, true); // topo of sphere is a closed cylinder
	prim2.embedSphere(2.0f);

	Geom::Matrix44f trf;
	trf.identity();
	Geom::translate<float>(5.0f, 0.0, 0.0, trf);
	prim2.transform(trf);

	xd1 = prim2.getDart();

//	xd1 = Algo::Modelisation::Polyhedron<PFP>::createTetra(myMap);
//	Dart xd2 = xd1;
//
//	position[xd2] = PFP::VEC3(5, 0, 0);
//	xd2 = PHI1(xd2);
//	position[xd2] = PFP::VEC3(3, 0, 0);
//	xd2 = PHI1(xd2);
//	position[xd2] = PFP::VEC3(4, 2, 0);
//	xd2 = PHI<211>(xd2);
//	position[xd2] = PFP::VEC3(4, 1, 2);

    //  bounding box of scene
    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);

    // send BB info to interface for centering on GL screen
	setParamObject(lWidthObj, lPosObj.data());

	// first show for be sure that GL context is binded
	show();

	// render the topo of the map without boundary darts
	SelectorDartNoBoundary<PFP::MAP> nb(myMap);
	m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f,nb);
}
Пример #2
0
void SimpleGMap2::cb_initGL()
{
	Utils::GLSLShader::setCurrentOGLVersion(1) ;

	Geom::BoundingBox<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());
}
Пример #3
0
void SimpleGMap3::cb_initGL()
{
    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());

	m_render_topo = new Algo::Render::GL2::Topo3RenderGMap<PFP>();
    m_render_topo->setDartWidth(2.0f);
    m_render_topo->setInitialDartsColor(1.0f,1.0f,1.0f);
	m_render_topo->updateData(myMap, position, 0.9f,0.9f,0.8f);
}
Пример #4
0
void MyQT::createMap()
{
	// creation of a new attribute on vertices of type 3D vector for position.
	// a handler to this attribute is returned
	position = myMap.addAttribute<VEC3, VERTEX, MAP>("position");

	// creation of 2 new faces: 1 triangle and 1 square
	Dart d1 = myMap.newFace(3);
	Dart d2 = myMap.newFace(4);

	// sew these faces along one of their edge
	myMap.sewFaces(d1, d2);

	// affect position by moving in the map
	position[d1] = VEC3(0, 0, 0);
	position[PHI1(d1)] = VEC3(2, 0, 0);
	position[PHI_1(d1)] = VEC3(1, 2, 0);
	position[PHI<11>(d2)] = VEC3(0, -2, 0);
	position[PHI_1(d2)] = VEC3(2, -2, 0);

    //  bounding box of scene
    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);

	show();
    // send BB info to interface for centering on GL screen
	setParamObject(lWidthObj, lPosObj.data());

	// first show for be sure that GL context is binded
	show();

	// render the topo of the map without boundary darts
	m_render_topo->setInitialBoundaryDartsColor(0,1,0);
	m_render_topo->updateDataGMap<PFP>(myMap, position, 0.9f, 0.9f,true);
}
Пример #5
0
void SimpleVisu::cb_redraw(Scene* scene){
	while(!l_waitingAssoc.isEmpty()){
		QPair<Scene*,MapHandler*> p= l_waitingAssoc.takeFirst();
		Scene* s= p.first;
		if(h_info.find(s)==h_info.end()){
			MapHandler* vh= p.second;

			VBOHandler* vboPosition, *vboNormal;
			if(!(vboPosition=vh->findVBO("positionVBO"))){
				vboPosition= vh->addNewVBO("positionVBO");
			}
			if(!(vboNormal=vh->findVBO("normalVBO"))){
				vboNormal= vh->addNewVBO("normalVBO");
			}

			PFP::MAP* map= (PFP::MAP*)vh->map();

			VertexAttribute<VEC3> position= map->getAttribute<PFP::VEC3, VERTEX>("position");
			VertexAttribute<VEC3> normal= map->getAttribute<PFP::VEC3, VERTEX>("normal") ;
			if(!normal.isValid()){
				normal= map->addAttribute<PFP::VEC3, VERTEX>("normal");

				if(position.isValid()){
					Algo::Geometry::computeNormalVertices<PFP>(*map, position, normal) ;
				}
			}

			Algo::Render::GL2::MapRender* render= NULL;
			bool valid= position.isValid() && normal.isValid();
			if(valid){
				vboPosition->updateData(position);
				vboNormal->updateData(normal) ;

				render= new Algo::Render::GL2::MapRender();

				render->initPrimitives<PFP>(*map, allDarts, Algo::Render::GL2::POINTS) ;
				render->initPrimitives<PFP>(*map, allDarts, Algo::Render::GL2::LINES) ;
				render->initPrimitives<PFP>(*map, allDarts, Algo::Render::GL2::TRIANGLES) ;

				Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(*map, position) ;
				s->firstViewFitSphere(bb.center()[0], bb.center()[1], bb.center()[2], bb.maxSize());
			}

			MyContainer mc(map,vboPosition,vboNormal,position,normal,render);
			mc.valid=valid;

			h_info.insert(s,mc);
		}
	}

	QHash<Scene*, MyContainer>::iterator it;
	if(scene && (it=h_info.find(scene))!=h_info.end() && it->valid){
		VBOHandler* vboPosition= it->vbos.first;
		VBOHandler* vboNormal= it->vbos.second;
		Algo::Render::GL2::MapRender* render= it->render;

		m_phongShader->setAttributePosition(vboPosition) ;
		m_phongShader->setAttributeNormal(vboNormal) ;
		m_flatShader->setAttributePosition(vboPosition) ;
		m_vectorShader->setAttributePosition(vboPosition) ;
		m_vectorShader->setAttributeVector(vboNormal) ;
		m_simpleColorShader->setAttributePosition(vboPosition) ;
		m_pointSprite->setAttributePosition(vboPosition) ;


		if(m_drawVertices)
		{
			float size = vertexScaleFactor ;
			m_pointSprite->setSize(size) ;
			m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ;
			render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
			m_pointSprite->postdraw() ;
		}

		if(m_drawEdges)
		{
			glLineWidth(1.0f) ;
			render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ;
		}

		if(m_drawFaces)
		{
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
			glEnable(GL_LIGHTING) ;
			glEnable(GL_POLYGON_OFFSET_FILL) ;
			glPolygonOffset(1.0f, 1.0f) ;
			switch(m_renderStyle)
			{
				case FLAT :
					m_flatShader->setExplode(faceShrinkage) ;
					render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES) ;
					break ;
				case PHONG :
						render->draw(m_phongShader, Algo::Render::GL2::TRIANGLES) ;
					break ;
			}
			glDisable(GL_POLYGON_OFFSET_FILL) ;
		}


		if(m_drawNormals)
		{
			float size = normalBaseSize * normalScaleFactor ;
			m_vectorShader->setScale(size) ;
			glLineWidth(1.0f) ;
			render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
		}

	}

//	if(scene){
//		for(int i=0; i<l_map.size(); ++i){
//			if(!initOK){
//				initVBOs(scene);
//			}
//
//			PFP::MAP* myMap= (PFP::MAP*)l_map[i];
//			if(!fited){
//
//				Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>((*myMap), m_position) ;
//				scene->firstViewFitSphere(bb.center()[0], bb.center()[1], bb.center()[2], bb.maxSize());
//
//				fited= true;
//			}
//
//			if(m_drawVertices /*&& position_ok*/)
//			{
//				float size = vertexScaleFactor ;
//				m_pointSprite->setSize(size) ;
//				m_pointSprite->predraw(Geom::Vec3f(0.0f, 0.0f, 1.0f)) ;
//				m_render->draw(m_pointSprite, Algo::Render::GL2::POINTS) ;
//				m_pointSprite->postdraw() ;
//			}
//
//			if(m_drawEdges /*&& position_ok*/)
//			{
//				glLineWidth(1.0f) ;
//				m_render->draw(m_simpleColorShader, Algo::Render::GL2::LINES) ;
//			}
//
//			if(m_drawFaces /*&& position_ok*/)
//			{
//				glPolygonMode(GL_FRONT_AND_BACK, GL_FILL) ;
//				glEnable(GL_LIGHTING) ;
//				glEnable(GL_POLYGON_OFFSET_FILL) ;
//				glPolygonOffset(1.0f, 1.0f) ;
//				switch(m_renderStyle)
//				{
//					case FLAT :
//						m_flatShader->setExplode(faceShrinkage) ;
//						m_render->draw(m_flatShader, Algo::Render::GL2::TRIANGLES) ;
//						break ;
//					case PHONG :
////						if(normal_ok){
//							m_render->draw(m_phongShader, Algo::Render::GL2::TRIANGLES) ;
////						}
//						break ;
//				}
//				glDisable(GL_POLYGON_OFFSET_FILL) ;
//			}
//
//
//			if(m_drawNormals /*&& normal_ok && position_ok*/)
//			{
//				float size = normalBaseSize * normalScaleFactor ;
//				m_vectorShader->setScale(size) ;
//				glLineWidth(1.0f) ;
//				m_render->draw(m_vectorShader, Algo::Render::GL2::POINTS) ;
//			}
//		}
//	}
}
Пример #6
0
void SimpleVisu::cb_initGL(Scene* scene){
	if(scene && h_info.find(scene)==h_info.end()){
		int t;
		if(((t=l_recievedScene.size())>0) && t<=l_map.size()){
			MapHandler* vh= l_map[l_recievedScene.size()-1];

			VBOHandler* vboPosition, *vboNormal;
			if(!(vboPosition=vh->findVBO("positionVBO"))){
				vboPosition= vh->addNewVBO("positionVBO");
			}
			if(!(vboNormal=vh->findVBO("normalVBO"))){
				vboNormal= vh->addNewVBO("normalVBO");
			}

			PFP::MAP* map= (PFP::MAP*)vh->map();

			VertexAttribute<VEC3> position= map->getAttribute<PFP::VEC3, VERTEX>("position");
			VertexAttribute<VEC3> normal= map->getAttribute<PFP::VEC3, VERTEX>("normal") ;
			if(!normal.isValid()){
				normal= map->addAttribute<PFP::VEC3, VERTEX>("normal");

				if(position.isValid()){
					Algo::Geometry::computeNormalVertices<PFP>(*map, position, normal) ;
				}
			}

			Algo::Render::GL2::MapRender* render= NULL;
			bool valid= position.isValid() && normal.isValid();
			if(valid){
				vboPosition->updateData(position);
				vboNormal->updateData(normal) ;

				render= new Algo::Render::GL2::MapRender();

				render->initPrimitives<PFP>(*map, allDarts, Algo::Render::GL2::POINTS) ;
				render->initPrimitives<PFP>(*map, allDarts, Algo::Render::GL2::LINES) ;
				render->initPrimitives<PFP>(*map, allDarts, Algo::Render::GL2::TRIANGLES) ;

				Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(*map, position) ;
				scene->firstViewFitSphere(bb.center()[0], bb.center()[1], bb.center()[2], bb.maxSize());
			}

			MyContainer mc(map,vboPosition,vboNormal,position,normal,render);
			mc.valid=valid;

			h_info.insert(scene,mc);
		}
	}
	if(!init && scene){
//		m_render = new Algo::Render::GL2::MapRender() ;


		m_phongShader = new Utils::ShaderPhong() ;
//		m_phongShader->setAttributePosition(m_positionVBO) ;
//		m_phongShader->setAttributeNormal(m_normalVBO) ;
		m_phongShader->setAmbiant(colClear) ;
		m_phongShader->setDiffuse(colDif) ;
		m_phongShader->setSpecular(colSpec) ;
		m_phongShader->setShininess(shininess) ;

		m_flatShader = new Utils::ShaderFlat() ;
//		m_flatShader->setAttributePosition(m_positionVBO) ;
		m_flatShader->setAmbiant(colClear) ;
		m_flatShader->setDiffuse(colDif) ;
		m_flatShader->setExplode(faceShrinkage) ;

		m_vectorShader = new Utils::ShaderVectorPerVertex() ;
//		m_vectorShader->setAttributePosition(m_positionVBO) ;
//		m_vectorShader->setAttributeVector(m_normalVBO) ;
		m_vectorShader->setColor(colNormal) ;

		m_simpleColorShader = new Utils::ShaderSimpleColor() ;
//		m_simpleColorShader->setAttributePosition(m_positionVBO) ;
		Geom::Vec4f c(0.1f, 0.1f, 0.1f, 1.0f) ;
		m_simpleColorShader->setColor(c) ;

		m_pointSprite = new Utils::PointSprite() ;
//		m_pointSprite->setAttributePosition(m_positionVBO) ;

		GLSLShader::registerShader(NULL,m_phongShader) ;
		GLSLShader::registerShader(NULL,m_flatShader) ;
		GLSLShader::registerShader(NULL,m_vectorShader) ;
		GLSLShader::registerShader(NULL,m_simpleColorShader) ;
		GLSLShader::registerShader(NULL,m_pointSprite) ;

		init=true;
	}
}
Пример #7
0
int main(int argc, char **argv)
{
	position = myMap.addAttribute<VEC3, VERTEX>("position");

	Dart d0 = myMap.newFace(12);
	position[d0] = PFP::VEC3(0, 20, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(10, 20, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(10, 30, 0);
	Dart dx = myMap.phi1(d0);
	d0 = myMap.phi<11>(dx);
	position[d0] = PFP::VEC3(8, 27, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(8, 22, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(2, 22, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(2, 27, 0);
	d0 = myMap.phi1(d0);
	myMap.sewFaces(d0,dx);
	position[d0] = PFP::VEC3(5, 27, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(5, 30, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(0, 30, 0);

	d0 = myMap.newFace(4);
	position[d0] = PFP::VEC3(-5, 14, -5);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(0, 18, -5);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(5, 14, -5);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(0, 20, -5);
	d0 = myMap.phi1(d0);

	Dart d1 = myMap.newFace(10);

	position[d1] = PFP::VEC3(0, 0, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(2, 4, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(4, 0, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(10, 0, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(4, 2, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(14, 6, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(6, 16, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(8, 8, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(4, 4, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(0, 8, 0);

	Dart d2 = myMap.newFace(12);

	position[d2] = PFP::VEC3(0, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(4, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(8, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -16, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -12, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(8, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(4, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(0, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(0, -12, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(0, -16, 0);
	d2 = myMap.phi1(d2);

#define NB 32

	//SPIRAL

	Dart d3 = myMap.newFace(NB*2);

	for (int i = 0; i<NB; ++i)
	{
		float z = 3.0f*float(rand()-RAND_MAX/2)/float(RAND_MAX);
		float alpha = (4.0f*6.283f / NB)*i;
		float radius = 1.2f*(NB-i);
		position[d3] = PFP::VEC3(radius*cos(alpha) -  2*NB+8, radius*sin(alpha), z);
		d3 = myMap.phi1(d3);
	}

	for (int i = NB-1; i>=0; --i)
	{
		float z = 3.0f*float(rand()-RAND_MAX/2)/float(RAND_MAX);
		float alpha = (4.0f*6.283f / NB)*i;
		float radius = (NB-i);
		position[d3] = PFP::VEC3(radius*cos(alpha) -  2*NB+8, radius*sin(alpha), z);
		d3 = myMap.phi1(d3);
	}

	//CIRCLE

	Dart d6 = myMap.newFace(NB);
	for (int i = 0; i<NB; ++i)
	{
		float z = 3.0f*float(rand()-RAND_MAX/2)/float(RAND_MAX);
		float alpha = (6.283f / NB)*i;
		float radius = NB;
		position[d6] = PFP::VEC3(radius*cos(alpha) + 2*NB+8, radius*sin(alpha), z);
		d6 = myMap.phi1(d6);
	}

// pour comparer les 2 versions (oreille et basique)
//#define NBB 100
//	for (int j = 0; j<10000; ++j)
//	{
//		Dart d6 = myMap.newFace(NBB);
//		for (int i = 0; i<NBB; ++i)
//		{
//			float alpha = (6.283f / NB)*i;
//			float radius = NB;
//			position[d6] = PFP::VEC3(radius*cos(alpha) + 2*NB+8, radius*sin(alpha), 0.1f*j);
//			d6 = myMap.phi1(d6);
//		}
//	}

	Geom::Vec3f V1(3,3,3);
	V1.normalize();
	Geom::Vec3f V2 = V1 ^ Geom::Vec3f(0,0,-1);
	Geom::Vec3f V3 = V1 ^ V2;

	V1 *= 50.0f;
	V2 *= 50.0f;

	Dart d5 = myMap.newFace(74);
	for (int i=0; i<74;++i)
	{
		float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f;
		position[d5] = PFP::VEC3(0.0,60.0,0.0f) + Ifont[2*i] * V1 + Ifont[2*i+1]*V2 + a*V3;
		d5 = myMap.phi1(d5);
	}
	Dart d9 = myMap.newFace(174);
	for (int i=0; i<174;++i)
	{
		float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f;
		position[d9] = PFP::VEC3(60.0,60.0,0.0f) + Gfont[2*i] * V1 + Gfont[2*i+1]*V2 + a*V3;
		d9 = myMap.phi1(d9);
	}

	// interface:
	QApplication app(argc, argv);
	MyQT sqt;


	// message d'aide
	sqt.setHelpMsg("Concave face rendering (ears method):\n"
			"a show all trianglesfaces\n"
			"a show none trianglesfaces\n"
			"+ / - show trinagles order rendering (ears creation)");

    //  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());

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

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

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

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

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