/******************************************************************************* * 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 * * * *******************************************************************************/ #include "tilings.h" #include "Geometry/vector_gen.h" #include "Algo/Import/import.h" #include "Algo/Geometry/boundingbox.h" #include "Utils/GLSLShader.h" //#include "Algo/Geometry/area.h" #include "Algo/Geometry/normal.h" #include "Utils/cgognStream.h" #include "Utils/chrono.h" using namespace CGoGN ; /** * Struct that contains some informations about the types of the manipulated objects * Mainly here to be used by the algorithms that are parameterized by it */ struct PFP: public PFP_STANDARD { // definition of the map typedef EmbeddedMap2 MAP; }; PFP::MAP myMap; VertexAttribute position; VertexAttribute position2; VertexAttribute normal; void MyQT::cb_initGL() { Utils::GLSLShader::setCurrentOGLVersion(2); // create the render m_render = new Algo::Render::GL2::MapRender(); // create VBO for position m_positionVBO = new Utils::VBO(); m_positionVBO->updateData(position); m_normalVBO = new Utils::VBO(); m_shader = new Utils::ShaderSimpleColor(); m_shader->setAttributePosition(m_positionVBO); m_shader->setColor(Geom::Vec4f(1.,1.,0.,0.)); m_lines = new Utils::ShaderVectorPerVertex(); m_lines->setAttributePosition(m_positionVBO); m_lines->setAttributeVector(m_normalVBO); m_lines->setScale(0.2f); m_lines->setColor(Geom::Vec4f(0.0f, 1.0f, 0.2f, 0.0f)); Algo::Surface::Geometry::computeNormalVertices(myMap, position, normal) ; m_render->initPrimitives(myMap, Algo::Render::GL2::LINES); m_render->initPrimitives(myMap, Algo::Render::GL2::POINTS); registerShader(m_shader); registerShader(m_lines); m_normalVBO->updateData(normal); } void MyQT::cb_redraw() { m_render->draw(m_shader, Algo::Render::GL2::LINES); m_render->draw(m_lines, Algo::Render::GL2::POINTS); } // mouse picking void MyQT::tiling(int code) { //myMap.clear(false); switch(code) { case 1: { std::cout << "square grid tiling" << std::endl; Algo::Surface::Tilings::Square::Grid g(myMap,10,10,true); g.embedIntoGrid(position,50,50); break; } case 2: { std::cout << "square grid twisted strip tiling" << std::endl; Algo::Surface::Tilings::Square::Grid g(myMap,10,10,true); g.embedIntoTwistedStrip(position, 0.3, 0.8, 5); break; } case 3: { std::cout << "square grid helocoid tiling" << std::endl; Algo::Surface::Tilings::Square::Grid g(myMap,20,20,true); g.embedIntoHelicoid(position, 0.3, 0.8, 5.0, 2.0); break; } case 4: { std::cout << "square cylinder tiling" << std::endl; Algo::Surface::Tilings::Square::Cylinder c(myMap,20,20); c.embedIntoCylinder(position,0.5,0.7,5.0); break; } case 5: { std::cout << "square cylinder tiling" << std::endl; Algo::Surface::Tilings::Square::Cylinder c(myMap,20,20); c.triangleBottom(); c.triangleTop(); c.embedIntoCylinder(position,0.5,0.7,5.0); break; } case 6: { std::cout << "square cylinder sphere tiling" << std::endl; Algo::Surface::Tilings::Square::Cylinder c(myMap,20,20); c.triangleTop(); c.triangleBottom(); c.embedIntoSphere(position,0.5); break; } case 7: { std::cout << "square cylinder cone tiling" << std::endl; Algo::Surface::Tilings::Square::Cylinder c(myMap,20,20); c.triangleTop(); c.triangleBottom(); c.embedIntoCone(position,0.5, 5.0); break; } case 8: { std::cout << "square cylinder cone tiling" << std::endl; Algo::Surface::Tilings::Square::Cube c(myMap,20,20,20); c.embedIntoCube(position,5.0,5.0, 5.0); break; } case 9: { std::cout << "square cylinder cone tiling" << std::endl; Algo::Surface::Tilings::Square::Tore c(myMap,20,10); c.embedIntoTore(position,5.0,2.0); break; } default: { break; } } // m_positionVBO->updateData(position); // m_lines->setAttributePosition(m_positionVBO); // updateGL(); } int main(int argc, char **argv) { // interface: QApplication app(argc, argv); MyQT sqt; sqt.statusMsg("Neww to create a sphere or Load for a mesh file"); CGoGNStream::allToConsole(&sqt); if (!position.isValid()) position = myMap.addAttribute("position"); if (!normal.isValid()) normal = myMap.addAttribute("normal"); if(argc == 2) { sqt.tiling(atoi(argv[1])); } // bounding box Geom::BoundingBox bb = Algo::Geometry::computeBoundingBox(myMap, position); float lWidthObj = std::max(std::max(bb.size(0), bb.size(1)), bb.size(2)); Geom::Vec3f lPosObj = (bb.min() + bb.max()) / PFP::REAL(2); CGoGNout << "lPosObj=" << lPosObj << CGoGNendl; CGoGNout << "lWidthObj=" << lWidthObj << CGoGNendl; sqt.setParamObject(lWidthObj,lPosObj.data()); // myMap.enableQuickTraversal() ; // myMap.enableQuickTraversal() ; sqt.show(); return app.exec(); }