diff --git a/Examples/NonPlanarWobbleSlicer/Categorize.py b/Examples/NonPlanarWobbleSlicer/Categorize.py index 6f3ff78..8f1bca7 100644 --- a/Examples/NonPlanarWobbleSlicer/Categorize.py +++ b/Examples/NonPlanarWobbleSlicer/Categorize.py @@ -22,17 +22,17 @@ 'Start' : voxelizeMin, 'End' : voxelizeMax }); -if (IO): - print(' Remesh Model') - triangulateVolume({ - 'VoxelName': 'Main', - 'ModelName': 'Remeshed', - 'Resolution' : VoxelResolution, - 'Start' : voxelizeMin, - 'End' : voxelizeMax - }); - print(' Save Model') - saveModel({"Name":"Remeshed","Filename":"dbg/remeshed.stl"}); +#if (IO): + #print(' Remesh Model') + #triangulateVolume({ + # 'VoxelName': 'Main', + # 'ModelName': 'Remeshed', + # 'Resolution' : VoxelResolution, + # 'Start' : voxelizeMin, + # 'End' : voxelizeMax + #}); + #print(' Save Model') + #saveModel({"Name":"Remeshed","Filename":"dbg/remeshed.stl"}); print('Distance Map') @@ -70,7 +70,7 @@ 'Start' : voxelizeMin, 'End' : voxelizeMax }); - repairModel({'Name':name}) + #repairModel({'Name':name}) if (IO): saveModel({"Name":name,"Filename":"dbg/" + name + ".stl"}); if (Detail < 1): diff --git a/Examples/NonPlanarWobbleSlicer/SliceZ.py b/Examples/NonPlanarWobbleSlicer/SliceZ.py index 7d80e32..e7c7ae4 100644 --- a/Examples/NonPlanarWobbleSlicer/SliceZ.py +++ b/Examples/NonPlanarWobbleSlicer/SliceZ.py @@ -18,7 +18,7 @@ Z = 0.2 counter = 0; -#Z = 9 +Z = 9 setData({'Name':'ZCounter', 'Data' : 0}); diff --git a/Examples/NonPlanarWobbleSlicer/createSlice.py b/Examples/NonPlanarWobbleSlicer/createSlice.py index 86a747b..209065c 100644 --- a/Examples/NonPlanarWobbleSlicer/createSlice.py +++ b/Examples/NonPlanarWobbleSlicer/createSlice.py @@ -37,7 +37,7 @@ }); else: triangulateDouble({"DoubleName":"Slice","ModelName":"Slice","Resolution":SliceResolution,"Start":voxelizeMin,"End":voxelizeMax,"Isovalue":isovalue}) - repairModel({'Name':'Slice'}) + #repairModel({'Name':'Slice'}) if (IO): saveModel({"Name":"Slice","Filename":"dbg/slice/ZSlice" + "{:.2f}".format(Z) + ".stl"}); diff --git a/Source/Geometry/Model.cpp b/Source/Geometry/Model.cpp index 3bd600f..239ae33 100644 --- a/Source/Geometry/Model.cpp +++ b/Source/Geometry/Model.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "CGALDefs.h" #include "Mesh2D.h" @@ -88,40 +89,26 @@ Model::Model(const std::vector& vertecies, const std::vector } Model::Model(const std::vector& input) { - std::map, size_t> indexMap; - std::vector vertecies; - std::vector indices; - for (glm::dvec3 x : input) { - size_t index = 0; - std::tuple key = std::make_tuple(x.x, x.y, x.z); - if (indexMap.count(key) != 0) { - index = indexMap[key]; - } - else { - vertecies.push_back(x); - index = vertecies.size() - 1; - indexMap[key] = index; - } - indices.push_back(index); - } - p = std::make_unique(); - Surface_mesh mesh; - //https://doc.cgal.org/latest/Surface_mesh/Surface_mesh_2sm_iterators_8cpp-example.html - std::map vertexMap; - size_t counter = 0; - for (auto& x : vertecies) { - vertex_descriptor desc = mesh.add_vertex(Point(x.x, x.y, x.z)); - vertexMap[counter] = desc; - counter++; - } - for (size_t i = 0; i < indices.size(); i += 3) { - vertex_descriptor a = vertexMap[indices[i + 0]]; - vertex_descriptor b = vertexMap[indices[i + 1]]; - vertex_descriptor c = vertexMap[indices[i + 2]]; - mesh.add_face(a, b, c); + std::vector> dumbIndices; + std::vector dumbVertices; + dumbVertices.reserve(input.size()); + dumbIndices.reserve(input.size()); + for (size_t i = 0; i < input.size(); i+=3) { + dumbIndices.push_back({ i,i + 1,i + 2 }); } + for(auto& x : input) + dumbVertices.push_back(Point(x.x, x.y, x.z)); + std::ostringstream buffer; + CGAL::IO::write_STL(buffer, dumbVertices, dumbIndices); + std::stringstream asd; + asd << buffer.str(); + Surface_mesh mesh; + std::vector> goodIndices; + std::vector goodVertices; + CGAL::IO::read_STL(asd,goodVertices,goodIndices); + CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(goodVertices, goodIndices, mesh); p->mesh = mesh; init(); }