/* g++ ./apps/embree/embree_sample.cpp -o ./apps/embree/prova.o -I ./vcg -I ./ -I ./eigenlib -I /usr/local/include/embree4/ -I ./vcglib/ -I ./vcglib/eigenlib/ -I ./vcglib/wrap/ply/ -L /usr/local/lib/ -lembree4 -std=c++17 -fopenmp -O3 ./apps/embree/prova.o ./apps/meshes/cube.off 64 or with cmake from embree folder mkdir build cd build cmake .. make ./embree_sample ../../meshes/bunny.off 64 */ #include #include #include //import export #include #include #include #include #include #include #include #include #include //vcgLibForEmbree #include class MyVertex; class MyEdge; class MyFace; struct MyUsedTypes : public vcg::UsedTypes ::AsVertexType, vcg::Use ::AsEdgeType, vcg::Use ::AsFaceType> {}; class MyVertex : public vcg::Vertex< MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags, vcg::vertex::VFAdj, vcg::vertex::Qualityf, vcg::vertex::Color4b> {}; class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VFAdj, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::BitFlags, vcg::face::Color4b, vcg::face::Qualityf> {}; class MyEdge : public vcg::Edge {}; class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector, std::vector > {}; using namespace vcg; using namespace std; int main( int argc, char **argv ) { cout << "start" << endl; MyMesh m; int ret = tri::io::ImporterOFF::Open(m, argv[1]); if(ret!=tri::io::ImporterOFF::NoError) { cout<<"Error reading file \n"< 2) { nOfRays = std::stoi(argv[2]); } MyMesh m2,m3,m4,m5,m6,m7; vcg::tri::Append::MeshCopy(m2,m); vcg::tri::Append::MeshCopy(m3,m); vcg::tri::Append::MeshCopy(m4, m); vcg::tri::Append::MeshCopy(m5, m); vcg::tri::Append::MeshCopy(m6,m); vcg::tri::Append::MeshCopy(m7,m); EmbreeAdaptor adaptor = EmbreeAdaptor(m); adaptor.computeAmbientOcclusion(m,nOfRays); tri::UpdateQuality::VertexFromFace(m); tri::UpdateColor::PerVertexQualityGray(m); tri::UpdateNormal::NormalizePerVertex(m); tri::io::ExporterOFF::Save(m,"testAO.off",tri::io::Mask::IOM_VERTCOLOR); cout << "Done AO" << endl; std::vector unifDirVec; std::vector ndir; GenNormal::Fibonacci(nOfRays,unifDirVec); Point3f dir(0, 1, 0); for (int g = 0; g < nOfRays; g++) { if (unifDirVec.at(g) >= dir) { ndir.push_back(unifDirVec.at(g)); } } adaptor = EmbreeAdaptor(m2); adaptor.computeAmbientOcclusion(m2,ndir); tri::UpdateQuality::VertexFromFace(m2); tri::UpdateColor::PerVertexQualityGray(m2); tri::io::ExporterOFF::Save(m2,"testAODir.off",tri::io::Mask::IOM_VERTCOLOR); cout << "Done AO Directioned" << endl; EmbreeAdaptor adaptor2 = EmbreeAdaptor(m4); adaptor2.computeSDF(m4,nOfRays,90); tri::UpdateQuality::VertexFromFace(m4); tri::UpdateColor::PerVertexQualityRamp(m4); tri::io::ExporterOFF::Save(m4,"testSDF.off",tri::io::Mask::IOM_VERTCOLOR); cout << "Done SDF" << endl; adaptor = EmbreeAdaptor(m5); adaptor.computeNormalAnalysis(m5, nOfRays, true); tri::io::ExporterOFF::Save(m5, "testNormal.off", tri::io::Mask::IOM_FACENORMAL); //vector BentNormal = adaptor.AOBentNormal(m5,nOfRays); cout << "Done NormalAnlysis" << endl; adaptor = EmbreeAdaptor(m6); Point3f p(1, 0, 0); adaptor.selectVisibleFaces(m6, p, true); tri::io::ExporterOFF::Save(m6, "testSelectS.off", tri::io::Mask::IOM_FACECOLOR); cout << "done face selection" << endl; std::vector origine; origine.push_back(Point3f(.0f,10.0f,.0f)); origine.push_back(Point3f(.0f,10.0f,.0f)); origine.push_back(Point3f(.0f,10.0f,.0f)); origine.push_back(Point3f(.0f,10.0f,.0f)); std::vector direction; direction.push_back(Point3f(.0f,1.0f,.0f)); direction.push_back(Point3f(.0f,1.0f,3.0f)); direction.push_back(Point3f(.0f,1.0f,6.0f)); direction.push_back(Point3f(.0f,1.0f,9.0f)); /* If you want to test the visualize_ray_shoot add the ply to makefile MyMesh m8; adaptor.visualize_ray_shoot(m8, origine[0], direction, true); int mask = vcg::tri::io::Mask::IOM_VERTCOORD; mask |= vcg::tri::io::Mask::IOM_EDGEINDEX; tri::io::ExporterPLY::Save(m8, "EdgeTest.ply", mask); */ cout << "Done All" << endl; return 0; }