Repository: cpederkoff/stl-to-voxel (language: python)

Issue:
perimeter.py - Error occurred at multiple points
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.

<img width="303" alt="Screenshot 2021-04-17 at 5 05 29 AM" src="https://user-images.githubusercontent.com/62240341/115100078-8ac4b980-9f3a-11eb-9d47-f0d0d0c8dfb1.png">

Would appreciate it a lot.

Thank you.
mesh triangle check edits to slice.py
With respect to this discussion - https://github.com/cpederkoff/stl-to-voxel/commit/81df3e656f7cfc7fec6c28aef030e661dedade05#commitcomment-50249160

1. In slice.py, check for correct mesh triangle points has been added from previous working commit
2. Edited doExport function in stltovoxel.py file in accordance to the first point

Hope it helps.

Thanks.


Discussion / hints:
If you upload the STL file where the issue can be reproduced, I will debug it.
> 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](https://file.io/FqsVtgs5MgHx) 

Once again, thanks a lot for attending my case.
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.
> I found the cause. There was a problem with the code I committed.
> [youngkiu@b948ef8](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.


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 :) 
@cpederkoff 
What if the commit: 0faf8394b2e5f93255863563a664f1a3cd367ff5 had been based on PR https://github.com/cpederkoff/stl-to-voxel/pull/18?



Fix patch:
diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml
new file mode 100644
index 0000000..df47cfe
--- /dev/null
+++ b/.github/workflows/python-package.yml
@@ -0,0 +1,40 @@
+# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
+# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
+
+name: Python package
+
+on:
+  push:
+    branches:
+      - '**'        # matches every branch
+  pull_request:
+    branches: [ master ]
+
+jobs:
+  build:
+
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version: [3.7, 3.8, 3.9]
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+    - name: Install dependencies
+      run: |
+        python -m pip install --upgrade pip
+        python -m pip install flake8 pytest
+        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
+    # - name: Lint with flake8
+    #   run: |
+    #     # stop the build if there are Python syntax errors or undefined names
+    #     flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
+    #     # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
+    #     flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
+    - name: Test with pytest
+      run: |
+        pytest
diff --git a/.gitignore b/.gitignore
index 5445306..7d7cf8a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -139,3 +139,7 @@ dmypy.json
 
 # Cython debug symbols
 cython_debug/
+
+# output files of test stl
+data/Stanford_Bunny*.png
+data/test*.png
diff --git a/README.md b/README.md
index 00a9243..9527752 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Turn STL files into voxels, images, and videos
 git clone https://github.com/cpederkoff/stl-to-voxel.git
 $ cd stl-to-voxel
 
-$ python3 stltovoxel.py Stanford_Bunny.stl Stanford_Bunny.png
+$ python3 stltovoxel.py data/Stanford_Bunny.stl data/Stanford_Bunny.png
 ```
 <!--- https://commons.wikimedia.org/wiki/File:Stanford_Bunny.stl --->
 
diff --git a/Stanford_Bunny.stl b/data/Stanford_Bunny.stl
similarity index 100%
rename from Stanford_Bunny.stl
rename to data/Stanford_Bunny.stl
diff --git a/stanford_bunny.gif b/data/stanford_bunny.gif
similarity index 100%
rename from stanford_bunny.gif
rename to data/stanford_bunny.gif
diff --git a/stanford_bunny.png b/data/stanford_bunny.png
similarity index 100%
rename from stanford_bunny.png
rename to data/stanford_bunny.png
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..1b3e49c
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,3 @@
+numpy
+Pillow
+matplotlib


Test patch:
diff --git a/data/test1.stl b/data/test1.stl
new file mode 100644
index 0000000..e8f8120
Binary files /dev/null and b/data/test1.stl differ
diff --git a/data/test2.stl b/data/test2.stl
new file mode 100644
index 0000000..39a404c
Binary files /dev/null and b/data/test2.stl differ
diff --git a/test/__init__.py b/test/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/test/test_export.py b/test/test_export.py
new file mode 100644
index 0000000..5f90b35
--- /dev/null
+++ b/test/test_export.py
@@ -0,0 +1,13 @@
+from stltovoxel import doExport
+
+
+def test_stanford_bunny():
+    # https://commons.wikimedia.org/wiki/File:Stanford_Bunny.stl
+    doExport('data/Stanford_Bunny.stl', 'data/Stanford_Bunny.png', 100)
+
+
+def test_issue_files():
+    # Provided by @silverscorpio in issue #16
+    doExport('data/test1.stl', 'data/test1.png', 99)
+    # Provided by @silverscorpio in PR #18
+    doExport('data/test2.stl', 'data/test2.png', 111)
diff --git a/test_perimeter.py b/test/test_perimeter.py
similarity index 100%
rename from test_perimeter.py
rename to test/test_perimeter.py
diff --git a/test_slice.py b/test/test_slice.py
similarity index 100%
rename from test_slice.py
rename to test/test_slice.py