diff --git a/Apps/Examples/texturesExample.cpp b/Apps/Examples/texturesExample.cpp index 7f2d87aaf4d315b8643294b67cb96293b8d14394..d33e8c2918fa5ad13155d041a3fbef0d5e912234 100644 --- a/Apps/Examples/texturesExample.cpp +++ b/Apps/Examples/texturesExample.cpp @@ -58,22 +58,15 @@ void TexView::cb_initGL() m_texture = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE); - m_textureWP = new Utils::Texture<2,Geom::Vec3uc>(GL_UNSIGNED_BYTE); - if (m_texture->load(m_fileNameTex)) m_texture->update(); else computeImage(); // CGoGNerr << "Problem loading image"<< CGoGNendl; - computeImage(); m_texture->setWrapping(GL_CLAMP_TO_EDGE); m_texture->update(); - computeImage(); - m_textureWP->setWrapping(GL_CLAMP_TO_EDGE); - m_textureWP->update(); - m_shader = new Utils::ShaderSimpleTexture(); m_shader->setAttributePosition(m_positionVBO); m_shader->setAttributeTexCoord(m_texcoordVBO); @@ -92,12 +85,6 @@ void TexView::cb_initGL() m_shader2->setSpecular(Geom::Vec4f(0.5)); registerShader(m_shader2); - m_shaderWP = new Utils::ShaderWallPaper(); - m_shaderWP->setTextureUnit(GL_TEXTURE2); - m_shaderWP->setTexture(m_textureWP); - registerShader(m_shaderWP); - - glEnable(GL_TEXTURE_2D); if (!m_obj.hasNormals()) @@ -117,8 +104,6 @@ void TexView::cb_redraw() { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - m_shaderWP->draw(); - if (m_phong) { m_shader2->activeTexture(); @@ -202,27 +187,16 @@ void TexView::computeImage() colorTable.push_back(Geom::Vec3uc(0,255,255)); colorTable.push_back(Geom::Vec3uc(255,255,255)); -// m_texture->create(Geom::Vec2ui(512,512)); - - m_textureWP->create(Geom::Vec2ui(512,512)); + m_texture->create(Geom::Vec2ui(512,512)); #define WIDTHCHECKER 20 -// for (unsigned int ki = 0; ki < m_texture->size()[0]; ++ki) -// { -// for (unsigned int kj = 0; kj < m_texture->size()[1]; ++kj) -// { -// unsigned int kc = ((kj/WIDTHCHECKER)*m_texture->size()[0] + (ki/WIDTHCHECKER))%7; -// (*m_texture)(ki,kj) =colorTable[kc]; -// } -// } - - for (unsigned int ki = 0; ki < m_textureWP->size()[0]; ++ki) + for (unsigned int ki = 0; ki < m_texture->size()[0]; ++ki) { - for (unsigned int kj = 0; kj < m_textureWP->size()[1]; ++kj) + for (unsigned int kj = 0; kj < m_texture->size()[1]; ++kj) { - unsigned int kc = ((kj/WIDTHCHECKER)*m_textureWP->size()[0] + (ki/WIDTHCHECKER))%7; - (*m_textureWP)(ki,kj) =colorTable[kc]; + unsigned int kc = ((kj/WIDTHCHECKER)*m_texture->size()[0] + (ki/WIDTHCHECKER))%7; + (*m_texture)(ki,kj) =colorTable[kc]; } } #undef WIDTHCHECKER diff --git a/Apps/Examples/texturesExample.h b/Apps/Examples/texturesExample.h index f68ec411b587167ab0e1087ea05032b6d4072a8f..80209dcfd3543d423dc0dcfa7b435b3602c07fc9 100644 --- a/Apps/Examples/texturesExample.h +++ b/Apps/Examples/texturesExample.h @@ -36,8 +36,6 @@ #include "Algo/Render/GL2/mapRender.h" #include "Algo/Import/importObjTex.h" -#include "Utils/Shaders/shaderWallPaper.h" - // forward definitions (minimize includes) namespace CGoGN { namespace Algo { namespace Render { namespace GL2 { class MapRender; }}}} @@ -76,13 +74,10 @@ public: unsigned int m_nbIndices; Utils::Texture<2,Geom::Vec3uc>* m_texture; - Utils::Texture<2,Geom::Vec3uc>* m_textureWP; - // shader simple texture Utils::ShaderSimpleTexture* m_shader; Utils::ShaderPhongTexture* m_shader2; - Utils::ShaderWallPaper* m_shaderWP; bool m_phong; diff --git a/Apps/SandBox/CMakeLists.txt b/Apps/SandBox/CMakeLists.txt index 712a265944730eb7a4ca1d6b7d06c78206eb6091..9bd6162c9dc3765ebfc1ebe155f433a41b2c1b5c 100644 --- a/Apps/SandBox/CMakeLists.txt +++ b/Apps/SandBox/CMakeLists.txt @@ -39,11 +39,12 @@ IF (WITH_QT) QT4_WRAP_CPP(testPlaneCutting_moc testPlaneCutting.h) add_executable(testPlaneCutting testPlaneCutting.cpp ${testPlaneCutting_ui} ${testPlaneCutting_moc}) target_link_libraries(testPlaneCutting ${CGoGN_LIBS} ${CGoGN_EXT_LIBS}) -ENDIF() -QT4_WRAP_CPP(wallPaper_moc wallPaper.h) -add_executable(wallPaper wallPaper.cpp ${wallPaper_moc}) -target_link_libraries(wallPaper ${CGoGN_LIBS_D} ${CGoGN_EXT_LIBS}) + QT4_WRAP_CPP(wallPaper_moc wallPaper.h) + add_executable(wallPaper wallPaper.cpp ${wallPaper_moc}) + target_link_libraries(wallPaper ${CGoGN_LIBS} ${CGoGN_EXT_LIBS}) + +ENDIF() # Example with Qt # diff --git a/include/Algo/Geometry/normal.hpp b/include/Algo/Geometry/normal.hpp index 085a0270057b289093672155c1e3293930b99e83..3111b8824a9674c919175b02ffd8f69d9ac2e237 100644 --- a/include/Algo/Geometry/normal.hpp +++ b/include/Algo/Geometry/normal.hpp @@ -28,8 +28,6 @@ #include "Topology/generic/traversor/traversorCell.h" #include "Topology/generic/traversor/traversor2.h" -#include "Algo/Parallel/parallel_foreach.h" - #include namespace CGoGN @@ -47,6 +45,8 @@ namespace Geometry template typename V_ATT::DATA_TYPE triangleNormal(typename PFP::MAP& map, Face f, const V_ATT& position) { + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + typename V_ATT::DATA_TYPE N = Geom::triangleNormal( position[f.dart], position[map.phi1(f)], @@ -59,6 +59,8 @@ typename V_ATT::DATA_TYPE triangleNormal(typename PFP::MAP& map, Face f, const V template typename V_ATT::DATA_TYPE newellNormal(typename PFP::MAP& map, Face f, const V_ATT& position) { + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + typedef typename V_ATT::DATA_TYPE VEC3; VEC3 N(0); @@ -78,6 +80,8 @@ typename V_ATT::DATA_TYPE newellNormal(typename PFP::MAP& map, Face f, const V_A template typename V_ATT::DATA_TYPE faceNormal(typename PFP::MAP& map, Face f, const V_ATT& position) { + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + if(map.faceDegree(f) == 3) return triangleNormal(map, f, position) ; else @@ -87,6 +91,8 @@ typename V_ATT::DATA_TYPE faceNormal(typename PFP::MAP& map, Face f, const V_ATT template typename V_ATT::DATA_TYPE vertexNormal(typename PFP::MAP& map, Vertex v, const V_ATT& position) { + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + typedef typename V_ATT::DATA_TYPE VEC3 ; VEC3 N(0) ; @@ -98,8 +104,12 @@ typename V_ATT::DATA_TYPE vertexNormal(typename PFP::MAP& map, Vertex v, const V { VEC3 v1 = vectorOutOfDart(map, f.dart, position) ; VEC3 v2 = vectorOutOfDart(map, map.phi_1(f), position) ; - n *= convexFaceArea(map, f, position) / (v1.norm2() * v2.norm2()) ; - N += n ; + typename VEC3::DATA_TYPE l = (v1.norm2() * v2.norm2()); + if (l > (typename VEC3::DATA_TYPE(0.0)) ) + { + n *= convexFaceArea(map, f, position) / l ; + N += n ; + } } }); @@ -110,6 +120,7 @@ typename V_ATT::DATA_TYPE vertexNormal(typename PFP::MAP& map, Vertex v, const V template typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Vertex v, const V_ATT& position) { + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); assert(map.dimension() == 3); typedef typename V_ATT::DATA_TYPE VEC3 ; @@ -145,39 +156,43 @@ typename V_ATT::DATA_TYPE vertexBorderNormal(typename PFP::MAP& map, Vertex v, c template void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_normal, unsigned int thread) { - if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread==0)) + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + CHECK_ATTRIBUTEHANDLER_ORBIT(F_ATT, FACE); + + if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0)) { - Parallel::computeNormalFaces(map,position,face_normal); + Parallel::computeNormalFaces(map, position, face_normal); return; } foreach_cell(map, [&] (Face f) { face_normal[f] = faceNormal(map, f, position) ; - }, - AUTO, thread); + }, AUTO, thread); } template void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal, unsigned int thread) { - if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread==0)) + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + + if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0)) { - Parallel::computeNormalVertices(map,position,normal); + Parallel::computeNormalVertices(map, position, normal); return; } foreach_cell(map, [&] (Vertex v) { normal[v] = vertexNormal(map, v, position) ; - }, - FORCE_CELL_MARKING, thread); + }, FORCE_CELL_MARKING, thread); } - template typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Edge e, const V_ATT& position) { + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + typedef typename V_ATT::DATA_TYPE VEC3 ; if(map.isBoundaryEdge(e)) @@ -211,50 +226,58 @@ typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Edge template void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles, unsigned int thread) { - if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread==0)) + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + CHECK_ATTRIBUTEHANDLER_ORBIT(E_ATT, EDGE); + + if ((CGoGN::Parallel::NumberOfThreads > 1) && (thread == 0)) { - Parallel::computeAnglesBetweenNormalsOnEdges(map,position,angles); + Parallel::computeAnglesBetweenNormalsOnEdges(map, position, angles); return; } foreach_cell(map, [&] (Edge e) { angles[e] = computeAngleBetweenNormalsOnEdge(map, e, position) ; - }, - AUTO, thread); + }, AUTO, thread); } - namespace Parallel { template void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal) { - CGoGN::Parallel::foreach_cell(map,[&](Vertex v, unsigned int /*thr*/) + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + + CGoGN::Parallel::foreach_cell(map, [&] (Vertex v, unsigned int /*thr*/) { normal[v] = vertexNormal(map, v, position) ; - },true,FORCE_CELL_MARKING); + }, FORCE_CELL_MARKING); } template void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& normal) { - CGoGN::Parallel::foreach_cell(map,[&](Face f, unsigned int thr) + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + CHECK_ATTRIBUTEHANDLER_ORBIT(F_ATT, FACE); + + CGoGN::Parallel::foreach_cell(map, [&] (Face f, unsigned int /*thr*/) { normal[f] = faceNormal(map, f, position) ; - },true,AUTO); + }); } - template void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles) { - CGoGN::Parallel::foreach_cell(map,[&](Edge e, unsigned int thr) + CHECK_ATTRIBUTEHANDLER_ORBIT(V_ATT, VERTEX); + CHECK_ATTRIBUTEHANDLER_ORBIT(E_ATT, EDGE); + + CGoGN::Parallel::foreach_cell(map,[&](Edge e, unsigned int /*thr*/) { angles[e] = computeAngleBetweenNormalsOnEdge(map, e, position) ; - },true,AUTO); + }); } } // namespace Parallel