Skip to content

Commit

Permalink
useless tries to fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Liech committed Nov 18, 2023
1 parent 363c28f commit 1750338
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ Examples/NonPlanarWobbleSlicer/3DBenchy.gcode
Examples/NonPlanarWobbleSlicer/Main.stl
Examples/NonPlanarWobbleSlicer/w3DBenchy.gcode
/Examples/NonPlanarWobbleSlicer/dbg
Examples/NonPlanarWobbleSlicer/slice2model.stl
Examples/NonPlanarWobbleSlicer/slice2tool.stl
39 changes: 28 additions & 11 deletions Examples/NonPlanarWobbleSlicer/BuildZSliceField.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@

config = getData({'Name':'config'});
SliceResolution = config['SliceResolution'];
WobbleAmplitude = config['WobbleAmplitude'];
WobbleFrequency = config['WobbleFrequency'];
WobbleFrom = config['WobbleFrom'];
WobbleTo = config['WobbleTo'];
rampTime = config['rampTime'];

Z = getData({'Name':'Z'});

boundary = modelBoundary({'Name':'Main'})
voxelizeMin=boundary['Min']
voxelizeMin[0] = voxelizeMin[0] - boundary['Size'][0]/10.0;
voxelizeMin[1] = voxelizeMin[1] - boundary['Size'][1]/10.0;
voxelizeMin[0] = voxelizeMin[0] - boundary['UniformSize'][0];
voxelizeMin[1] = voxelizeMin[1] - boundary['UniformSize'][1];

voxelizeMax=boundary['UniformMax']
voxelizeMax[0] = voxelizeMax[0] + boundary['UniformSize'][0]/10.0;
voxelizeMax[1] = voxelizeMax[1] + boundary['UniformSize'][1]/10.0;
voxelizeMax[0] = voxelizeMax[0] + boundary['UniformSize'][0];
voxelizeMax[1] = voxelizeMax[1] + boundary['UniformSize'][1];

print(" Generate Double Field...");
minZ = voxelizeMin[2]
Expand All @@ -24,21 +29,33 @@
data["minZ"] = minZ;
data["maxZ"] = maxZ;
data["SliceResolution"] = SliceResolution;
data["WobbleAmplitude"] = WobbleAmplitude;
data["WobbleFrequency"] = WobbleFrequency;
data["WobbleFrom"] = WobbleFrom;
data["WobbleTo"] = WobbleTo ;
data["rampTime"] = rampTime ;

print("minZ "+str(minZ))
def density(input):
import math
coord = input["Pos"]
data = input["Data"]
xWobble = 1.5
zWobble = 0.5
distortion = (math.sin(coord[1]/xWobble)*zWobble + math.cos(coord[0]/xWobble)*zWobble);
xWobble = data["WobbleFrequency"]
zWobble = data["WobbleAmplitude"]
distortion = (math.sin(coord[1]*(xWobble/data["SliceResolution"][0]))*zWobble + math.cos(coord[0]*(xWobble/data["SliceResolution"][0]))*zWobble);
perc = (coord[2] / data["SliceResolution"][2])
distance = abs(perc-0.1)
distortionInfluence = 0
R = 0.1
if (distance < R):
distortionInfluence = ((R-distance)/R)
fromPercentage = data["WobbleFrom"]
toPercentage = data["WobbleTo"]
rampTime = data["rampTime"]
distanceFrom = abs(perc-fromPercentage)
distanceTo = abs(perc-toPercentage)
if (perc > fromPercentage and perc < toPercentage):
distortionInfluence = 1
elif(distanceFrom < rampTime):
distortionInfluence = ((rampTime-distanceFrom)/rampTime)
elif(distanceTo < rampTime):
distortionInfluence = ((rampTime-distanceTo)/rampTime)
return (data["maxZ"]-data["minZ"])*perc + distortion * distortionInfluence

print(" createDensityField...");
Expand Down
1 change: 1 addition & 0 deletions Examples/NonPlanarWobbleSlicer/Categorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
'Start' : voxelizeMin,
'End' : voxelizeMax
});
repairModel({'Name':name})
if (IO):
saveModel({"Name":name,"Filename":"dbg/" + name + ".stl"});
if (Detail < 1):
Expand Down
2 changes: 1 addition & 1 deletion Examples/NonPlanarWobbleSlicer/SliceZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

Z = 0.2
counter = 0;

#Z = 9

setData({'Name':'ZCounter', 'Data' : 0});

Expand Down
2 changes: 1 addition & 1 deletion Examples/NonPlanarWobbleSlicer/WriteGCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
for i in range(0,zCounter):
gcode += linearPrint({
'Line': 'Result' + str(i),
'Feedrate': 0.025
'Feedrate': 0.028
})

gcode += shutdown({});
Expand Down
9 changes: 5 additions & 4 deletions Examples/NonPlanarWobbleSlicer/createSlice.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

boundary = modelBoundary({'Name':'Main'})
voxelizeMin=boundary['Min']
voxelizeMin[0] = voxelizeMin[0] - boundary['Size'][0]/10.0;
voxelizeMin[1] = voxelizeMin[1] - boundary['Size'][1]/10.0;
voxelizeMin[0] = voxelizeMin[0] - boundary['UniformSize'][0];
voxelizeMin[1] = voxelizeMin[1] - boundary['UniformSize'][1];
voxelizeMin[2] = voxelizeMin[2];

voxelizeMax=boundary['UniformMax']
voxelizeMax[0] = voxelizeMax[0] + boundary['UniformSize'][0]/10.0;
voxelizeMax[1] = voxelizeMax[1] + boundary['UniformSize'][1]/10.0;
voxelizeMax[0] = voxelizeMax[0] + boundary['UniformSize'][0];
voxelizeMax[1] = voxelizeMax[1] + boundary['UniformSize'][1];
voxelizeMax[2] = voxelizeMax[2];

print(" Generate Double Field...");
Expand All @@ -37,6 +37,7 @@
});
else:
triangulateDouble({"DoubleName":"Slice","ModelName":"Slice","Resolution":SliceResolution,"Start":voxelizeMin,"End":voxelizeMax,"Isovalue":isovalue})
repairModel({'Name':'Slice'})

if (IO):
saveModel({"Name":"Slice","Filename":"dbg/slice/ZSlice" + "{:.2f}".format(Z) + ".stl"});
Expand Down
31 changes: 18 additions & 13 deletions Examples/NonPlanarWobbleSlicer/main.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
from PolyglotModule import *
print("Prepare Config");
config = {
'Filename':"3DBenchy.stl",
'ResultFilename' : '3DBenchy.gcode',
'BuildplateCenter' : [100,100,0],
'LayerHeight' : 0.2,
'WallAmount' : 2,
'NozzleDiameter' : 0.43,
'VoxelResolution':[512,512,512],
'SliceResolution':[32,32,32],
'WallThickness' : 0.4,
'PlanarSlicing' : True,
'LayerLimit' : -1, # -1 for unlimited
'Detail' : 0.3, #0.0-1.0
'IntermediateFiles' : False
'Filename' :"3DBenchy.stl",
'ResultFilename' : '3DBenchy.gcode',
'BuildplateCenter' : [100,100,0],
'LayerHeight' : 0.2,
'WallAmount' : 2,
'NozzleDiameter' : 0.42,
'VoxelResolution' :[512,512,512],
'SliceResolution' :[32,32,32],
'WallThickness' : 0.4,
'PlanarSlicing' : False,
'LayerLimit' : -1, # -1 for unlimited
'Detail' : 0.3, #0.0-1.0
'IntermediateFiles' : True,
'WobbleAmplitude' : 1.0, # z height
'WobbleFrequency' : 4.14*10, #amount of waves in full volume
'WobbleFrom' : 0.11, # percentage where wobble is full
'WobbleTo' : 0.31, #percentage where wobble stops being full
'rampTime' : 0.06 #percentage before and after full wobble where it fades out
};

#createPlane({
Expand Down
Binary file added Examples/NonPlanarWobbleSlicer/meshCopy.stl
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions Source/Geometry/Mesh2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_2<K> Vb;
typedef CGAL::Delaunay_mesh_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds> CDT;
typedef CGAL::Constrained_Delaunay_triangulation_2<K, Tds, CGAL::Exact_intersections_tag> CDT;
typedef CGAL::Delaunay_mesh_size_criteria_2<CDT> Criteria;
typedef CDT::Vertex_handle Vertex_handle;
typedef CDT::Point Point;
Expand Down Expand Up @@ -183,7 +183,7 @@ std::vector<Polygon_with_holes_2> Mesh2DPIMPL::loopSoup2Polys(const std::vector<
Polygon_2 poly = Polygon_2();
for (auto& x : loop)
poly.push_back(x);
poly = PS::simplify(poly, cost, Stop(0.5));
//poly = PS::simplify(poly, cost, Stop(0.5));


outer.push_back(poly);
Expand Down Expand Up @@ -214,7 +214,7 @@ std::vector<Polygon_with_holes_2> Mesh2DPIMPL::loopSoup2Polys(const std::vector<
Polygon_2 h = Polygon_2();
for (auto& x : hole)
h.push_back(x);
h = PS::simplify(h, cost, Stop(0.5));
//h = PS::simplify(h, cost, Stop(0.5));

assignedHoles[bestPoly].push_back(h);
}
Expand Down
6 changes: 5 additions & 1 deletion Source/Geometry/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Edge_length_stop_predicate.h>
#include <CGAL/Surface_mesh_simplification/Policies/Edge_collapse/Midpoint_placement.h>
#include <boost/variant/get.hpp>
#include <CGAL/Polygon_mesh_processing/repair_degeneracies.h>



typedef CGAL::AABB_face_graph_triangle_primitive<Surface_mesh> AABB_face_graph_primitive;
Expand Down Expand Up @@ -287,14 +289,16 @@ void Model::getBoundingSphere(glm::dvec3& center, double& radius) const {
}

radius /= 2;
}
}

void Model::repair() {

std::cout << "Repairing..." << std::endl;
assert(CGAL::is_valid_polygon_mesh(p->mesh));
CGAL::Polygon_mesh_processing::remove_isolated_vertices(p->mesh);
CGAL::Polygon_mesh_processing::duplicate_non_manifold_vertices(p->mesh);
CGAL::Polygon_mesh_processing::remove_degenerate_faces(p->mesh);

if (CGAL::Polygon_mesh_processing::does_self_intersect(p->mesh)) {
std::cout << "Remove Self Intersection..." << std::endl;
if (!CGAL::Polygon_mesh_processing::experimental::remove_self_intersections(p->mesh, CGAL::parameters::preserve_genus(false))) {
Expand Down
1 change: 1 addition & 0 deletions Test/TorusSlice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TEST_CASE("TorusSlice", "[TorusSlice]") {
{"ToolName" , "Tool" },
{"Mode" , "Line" },
{"LineName" , "Result"},
{"ResultName" , "BenchySliceModel"}
});
api->getFunction("sliceModel").call(sliceModelParams);

Expand Down

0 comments on commit 1750338

Please sign in to comment.