cpederkoff / stl-to-voxel

Turn STL files into voxels, images, and videos
MIT License
138 stars 75 forks source link

perimeter.py - Error occurred at multiple points #16

Closed silverscorpio closed 3 years ago

silverscorpio commented 3 years ago

before your last commit 3-4 days back, I could convert voxelize STL files, however after the latest commits, none is being converted to png. I tried to look into the history and understand, but in vain.

The error seems to be with the perimeter.py file - with the isBlack being True - leading to the error for multiple points.

Could you once check into it, if it works for STL files other than the example one at your end.

if you would like, I could attach a sample STL file for your perusal.

Screenshot 2021-04-17 at 5 05 29 AM

Would appreciate it a lot.

Thank you.

youngkiu commented 3 years ago

If you upload the STL file where the issue can be reproduced, I will debug it.

silverscorpio commented 3 years ago

If you upload the STL file where the issue can be reproduced, I will debug it.

Hello, Thank you for getting back.

Please find the STL file (out of many STL files with the same error) here

Once again, thanks a lot for attending my case.

youngkiu commented 3 years ago

I found the cause. There was a problem with the code I committed. https://github.com/youngkiu/stl-to-voxel/commit/b948ef8e942f8f60729b693a259c860609fcaa9e

If you roll back the code like this, it will work without error.

Index: slice.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/slice.py b/slice.py
--- a/slice.py  (revision 2353bcc90ad9f626b7fd9babb3ece931fd3b7dae)
+++ b/slice.py  (date 1618644431245)
@@ -100,7 +100,7 @@
     xyscale = float(resolution - 1) / (max(maxs[0] - mins[0], maxs[1] - mins[1]))
     #TODO: Change this to return one scale. If not, verify svx exporting still works.
     scale = [xyscale, xyscale, xyscale]
-    bounding_box = [resolution, resolution, round((maxs[2] - mins[2]) * xyscale) + 1]
+    bounding_box = [resolution, resolution, math.ceil((maxs[2] - mins[2]) * xyscale)]
     return (scale, shift, bounding_box)

@@ -110,7 +110,7 @@
         for pt in tri:
             newpt = [0, 0, 0]
             for i in range(3):
-                newpt[i] = round((pt[i] + shift[i]) * scale[i])
+                newpt[i] = (pt[i] + shift[i]) * scale[i]
             newTri.append(tuple(newpt))
         if len(removeDupsFromPointList(newTri)) == 3:
             yield newTri

I will pull request the modified code. Sorry.

silverscorpio commented 3 years ago

I found the cause. There was a problem with the code I committed. youngkiu@b948ef8

If you roll back the code like this, it will work without error.

Index: slice.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/slice.py b/slice.py
--- a/slice.py    (revision 2353bcc90ad9f626b7fd9babb3ece931fd3b7dae)
+++ b/slice.py    (date 1618644431245)
@@ -100,7 +100,7 @@
     xyscale = float(resolution - 1) / (max(maxs[0] - mins[0], maxs[1] - mins[1]))
     #TODO: Change this to return one scale. If not, verify svx exporting still works.
     scale = [xyscale, xyscale, xyscale]
-    bounding_box = [resolution, resolution, round((maxs[2] - mins[2]) * xyscale) + 1]
+    bounding_box = [resolution, resolution, math.ceil((maxs[2] - mins[2]) * xyscale)]
     return (scale, shift, bounding_box)

@@ -110,7 +110,7 @@
         for pt in tri:
             newpt = [0, 0, 0]
             for i in range(3):
-                newpt[i] = round((pt[i] + shift[i]) * scale[i])
+                newpt[i] = (pt[i] + shift[i]) * scale[i]
             newTri.append(tuple(newpt))
         if len(removeDupsFromPointList(newTri)) == 3:
             yield newTri

I will pull request the modified code. Sorry.

That was quite fast! I rolled back and tried. It works now. And also, no worries about sorry! It happens :)

Thank you very much for the prompt debug help & the PR, would help others in the future :)