From 6cb0dbc21e61c7954a384d4d87cdd7c8018414e3 Mon Sep 17 00:00:00 2001 From: papush! Date: Fri, 12 May 2017 03:04:43 +0200 Subject: [PATCH] partially fix MeshReconstruction --- external/MeshReconstruction/.DS_Store | Bin 6148 -> 0 bytes external/MeshReconstruction/lib/CMakeLists.txt | 2 -- external/MeshReconstruction/lib/Cube.cpp | 15 +++++++-------- external/MeshReconstruction/lib/DataStructs.h | 2 +- external/MeshReconstruction/lib/IO.cpp | 16 +++++----------- .../lib/MeshReconstruction.cpp | 4 +--- 6 files changed, 14 insertions(+), 25 deletions(-) delete mode 100644 external/MeshReconstruction/.DS_Store diff --git a/external/MeshReconstruction/.DS_Store b/external/MeshReconstruction/.DS_Store deleted file mode 100644 index 13642ff228d4d78575f93cc515454bda5d9f6637..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!A=4(5N!dq8)D>OBFA35aR4Q7GT9&=yqT=ggBsY)64?Z{1{R6pn*9y^Bfr4k zai%Rqf+n7fk(p%rrqh`=eY@$jj4|Gtgf+%Wj4=ULKMZexbgaG>Lq?M8Mpk= z752{jq#s!OT&cmr_JfP4H|>;mk5!!bQQRBpVuyph@NSiNQ@e_@#|=EoKHyI^%j}n8&Wn?F)tL)xj@yIODEC zYKZ}2V3~ou>6WnmpM3xRUrwSPF+dFbD+YL>?X_F5C0kopHixxVf_6bsFfKE=NC88a gVu;03Tn5zweu)O4YcVqj9uT?+Xd0*?27Z-+4+lw5nE(I) diff --git a/external/MeshReconstruction/lib/CMakeLists.txt b/external/MeshReconstruction/lib/CMakeLists.txt index bd2f0c8..c6eb84c 100644 --- a/external/MeshReconstruction/lib/CMakeLists.txt +++ b/external/MeshReconstruction/lib/CMakeLists.txt @@ -1,7 +1,5 @@ add_library(MeshReconstruction MeshReconstruction.h MeshReconstruction.cpp Cube.h Cube.cpp DataStructs.h IO.h IO.cpp Triangulation.h Triangulation.cpp) -target_link_libraries(MeshReconstruction m) - install(TARGETS MeshReconstruction RUNTIME DESTINATION bin LIBRARY DESTINATION lib diff --git a/external/MeshReconstruction/lib/Cube.cpp b/external/MeshReconstruction/lib/Cube.cpp index 2c4f990..458b2ff 100644 --- a/external/MeshReconstruction/lib/Cube.cpp +++ b/external/MeshReconstruction/lib/Cube.cpp @@ -1,5 +1,4 @@ #include "Cube.h" -#include using namespace MeshReconstruction; @@ -44,7 +43,7 @@ namespace struct Edge { - int edgeFlag : 12; // flag: 1, 2, 4, ... 2048 + unsigned edgeFlag : 12; // flag: 1, 2, 4, ... 2048 int vert0; // 0-7 int vert1; // 0-7 }; @@ -74,9 +73,9 @@ Vec3 Cube::LerpVertex(double isoLevel, int i1, int i2) const auto const& p1 = pos[i1]; auto const& p2 = pos[i2]; - if (abs(isoLevel - v1) < Eps) return p1; - if (abs(isoLevel - v2) < Eps) return p2; - if (abs(v1 - v2) < Eps) return p1; + if (std::abs(isoLevel - v1) < Eps) return p1; + if (std::abs(isoLevel - v2) < Eps) return p2; + if (std::abs(v1 - v2) < Eps) return p1; auto mu = (isoLevel - v1) / (v2 - v1); return p1 + (p2 - p1)*mu; @@ -117,7 +116,7 @@ int Cube::SignConfig(double isoLevel) const { if (sdf[i] < isoLevel) { - edgeIndex |= 1 << i; + edgeIndex |= (1 << i); } } @@ -133,10 +132,10 @@ IntersectInfo Cube::Intersect(double iso) const IntersectInfo intersect; intersect.signConfig = SignConfig(iso); - + auto intersectedEdges = signConfigToIntersectedEdges[intersect.signConfig]; for (auto e = 0; e<12; ++e) { - if (signConfigToIntersectedEdges[intersect.signConfig] & edges[e].edgeFlag) + if (intersectedEdges & edges[e].edgeFlag) { auto v0 = edges[e].vert0; auto v1 = edges[e].vert1; diff --git a/external/MeshReconstruction/lib/DataStructs.h b/external/MeshReconstruction/lib/DataStructs.h index 9a38a9f..c1d912f 100644 --- a/external/MeshReconstruction/lib/DataStructs.h +++ b/external/MeshReconstruction/lib/DataStructs.h @@ -54,4 +54,4 @@ namespace MeshReconstruction using Fun3s = std::function; using Fun3v = std::function; -} +} \ No newline at end of file diff --git a/external/MeshReconstruction/lib/IO.cpp b/external/MeshReconstruction/lib/IO.cpp index dd145cb..d928a31 100644 --- a/external/MeshReconstruction/lib/IO.cpp +++ b/external/MeshReconstruction/lib/IO.cpp @@ -6,13 +6,7 @@ void MeshReconstruction::WriteObjFile(Mesh const& mesh, string const& fileName) { // FILE faster than streams. - FILE* file; - //auto status = fopen_s(&file, fileName.c_str(), "w"); - //if (status != 0) - //{ - // throw runtime_error("Could not write obj file."); - //} - file = fopen(fileName.c_str(), "w"); + FILE* file = fopen(fileName.c_str(), "w"); if (file == NULL) { throw runtime_error("Could not write obj file."); @@ -24,7 +18,7 @@ void MeshReconstruction::WriteObjFile(Mesh const& mesh, string const& fileName) static_cast(mesh.triangles.size())); // vertices - for (auto vi = 0; vi < mesh.vertices.size(); ++vi) + for (size_t vi = 0; vi < mesh.vertices.size(); ++vi) { auto const& v = mesh.vertices.at(vi); fprintf(file, "v %f %f %f\n", v.x, v.y, v.z); @@ -32,7 +26,7 @@ void MeshReconstruction::WriteObjFile(Mesh const& mesh, string const& fileName) // vertex normals fprintf(file, "\n"); - for (auto ni = 0; ni < mesh.vertices.size(); ++ni) + for (size_t ni = 0; ni < mesh.vertices.size(); ++ni) { auto const& vn = mesh.vertexNormals.at(ni); fprintf(file, "vn %f %f %f\n", vn.x, vn.y, vn.z); @@ -40,7 +34,7 @@ void MeshReconstruction::WriteObjFile(Mesh const& mesh, string const& fileName) // triangles (1-based) fprintf(file, "\n"); - for (auto ti = 0; ti < mesh.triangles.size(); ++ti) + for (size_t ti = 0; ti < mesh.triangles.size(); ++ti) { auto const& t = mesh.triangles.at(ti); fprintf(file, "f %d//%d %d//%d %d//%d\n", @@ -50,4 +44,4 @@ void MeshReconstruction::WriteObjFile(Mesh const& mesh, string const& fileName) } fclose(file); -} +} \ No newline at end of file diff --git a/external/MeshReconstruction/lib/MeshReconstruction.cpp b/external/MeshReconstruction/lib/MeshReconstruction.cpp index 6640582..e7a0466 100644 --- a/external/MeshReconstruction/lib/MeshReconstruction.cpp +++ b/external/MeshReconstruction/lib/MeshReconstruction.cpp @@ -52,11 +52,9 @@ Mesh MeshReconstruction::MarchCube( for (auto ix = 0; ix < NumX; ++ix) { auto x = domain.min.x + ix * cubeSize.x; - for (auto iy = 0; iy < NumY; ++iy) { auto y = domain.min.y + iy * cubeSize.y; - for (auto iz = 0; iz < NumZ; ++iz) { auto z = domain.min.z + iz * cubeSize.z; @@ -64,7 +62,7 @@ Mesh MeshReconstruction::MarchCube( // Process only if cube lies within narrow band around surface. auto cubeCenter = min + HalfCubeSize; - auto dist = abs(sdf(cubeCenter) - isoLevel); + double dist = std::fabs(sdf(cubeCenter) - isoLevel); if (dist > HalfCubeDiag) continue; Cube cube({ min, cubeSize }, sdf);