Skip to content

Commit

Permalink
final tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bperseghetti committed Sep 10, 2022
1 parent bdf944e commit 8cb846e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 29 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ The automatically generated website can be viewed at https://iroboteducation.git
Install required dependencies:

```bash
pip3 install mkdocs
pip3 install mkdocs-material
pip3 -r requirements.txt
```

Optionally, if you desire to generate images of STL models dynamically install:

```bash
pip3 -r model_image_generation.txt
```


Build the documentation locally:

```bash
Expand Down
69 changes: 40 additions & 29 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,30 @@ class cl:
currentGitBranch = repo.active_branch.name
print('INFO\t - {:s}Using github organization in main.py:{:s} {:s}'.format(cl.GRN,cl.END,currentGitOrg))
print('INFO\t - {:s}Using git branch in main.py:{:s} {:s}'.format(cl.GRN,cl.END,currentGitBranch))

# End of optional block
flag_gen_image = True
try:
from stl.mesh import Mesh
except ImportError:
flag_gen_image = False
print('\n\n{:s}{:s}ERROR\t - Unable to import Python module "stl", check to see if numpy-stl is installed.{:s}\n\n'.format(cl.FAIL,cl.BOLD,cl.END))

try:
import vtkplotlib as vpl
except ImportError:
flag_gen_image = False
print('\n\n{:s}{:s}ERROR\t - Unable to import Python module "vtkplotlib", check to see if vtkplotlib is installed.{:s}\n\n'.format(cl.FAIL,cl.BOLD,cl.END))
flagImageMesh = False
flagImageMeshCleanup = False

try:
from PIL import Image
from stl.mesh import Mesh
except ImportError:
flag_gen_image = False
print('\n\n{:s}{:s}ERROR\t - Unable to import Python module "PIL", check to see if PIL is installed.{:s}\n\n'.format(cl.FAIL,cl.BOLD,cl.END))
print('\n\n{:s}{:s}WARN\t - Unable to import Python module "stl", check to see if numpy-stl is installed, disregard if not building STL images.{:s}\n\n'.format(cl.WARN,cl.BOLD,cl.END))
else:
try:
import vtkplotlib as vpl
except ImportError:
flag_gen_image = False
print('\n\n{:s}{:s}WARN\t - Unable to import Python module "vtkplotlib", check to see if vtkplotlib is installed, disregard if not building STL images.{:s}\n\n'.format(cl.WARN,cl.BOLD,cl.END))
else:
flagImageMesh = True
try:
from PIL import Image
except ImportError:
print('\n\n{:s}{:s}WARN\t - Unable to import Python module "PIL", check to see if PIL is installed, disregard if not building STL images.{:s}\n\n'.format(cl.WARN,cl.BOLD,cl.END))
else:
flagImageMeshCleanup = True



def define_env(env):
Expand Down Expand Up @@ -150,7 +154,7 @@ def check_generate(file_path):
name_file = './docs/'+file_path
image_name = name_file.replace(".stl",".png")
if not os.path.exists(image_name):
if flag_gen_image:
if flagImageMesh:
print('INFO\t - {:s}Attempting to generate:{:s} {:s} -> {:s}'.format(cl.GRN,cl.END,name_file,image_name))
try:
mesh = Mesh.from_file(name_file)
Expand All @@ -161,20 +165,27 @@ def check_generate(file_path):
return False
print('ERROR\t - {:s}Failed to generate:{:s} {:s} -> {:s}'.format(cl.FAIL,cl.END,name_file,image_name))
else:
try:
img = Image.open(image_name)
img = img.convert("RGBA")
pixdata = img.load()
width, height = img.size
for y in range(height):
for x in range(width):
if pixdata[x, y] == (216, 220, 214, 255):
pixdata[x, y] = (255, 255, 255, 0)

img.save(image_name, "PNG")
except:
print('WARN\t - {:s}Failed to remove background in:{:s} {:s}'.format(cl.WARN,cl.END,image_name))
if flagImageMeshCleanup:
try:
img = Image.open(image_name)
img = img.convert("RGBA")
pixdata = img.load()
width, height = img.size
for y in range(height):
for x in range(width):
if pixdata[x, y] == (216, 220, 214, 255):
pixdata[x, y] = (255, 255, 255, 0)

img.save(image_name, "PNG")
except:
print('WARN\t - {:s}Failed to remove background in:{:s} {:s}'.format(cl.WARN,cl.END,image_name))
return True
else:
return True
else:
return True
else:
print('WARN\t - {:s}Image does not exist and is not generated, not using in docs:{:s} {:s}'.format(cl.WARN,cl.END,image_name))
return False

return True
4 changes: 4 additions & 0 deletions model_image_generation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy-stl==2.17.1
Pillow==9.0.1
matplotlib==3.5.1
vtkplotlib==2.0.0

0 comments on commit 8cb846e

Please sign in to comment.