|
|
@ -52,41 +52,70 @@ class AHB_Render: |
|
|
|
if b >= 256 - step: |
|
|
|
if b >= 256 - step: |
|
|
|
b = step |
|
|
|
b = step |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reset_display(self): |
|
|
|
|
|
|
|
doc = App.activeDocument() |
|
|
|
|
|
|
|
for obj in doc.Objects: |
|
|
|
|
|
|
|
if obj.TypeId == 'Part::Feature': |
|
|
|
|
|
|
|
if 'AssemblyHandbook_Stage' in obj.PropertiesList: |
|
|
|
|
|
|
|
obj.ViewObject.LineColor = (0.0, 0.0, 0.0, 0.0) |
|
|
|
|
|
|
|
obj.ViewObject.DisplayMode = 'Flat Lines' |
|
|
|
|
|
|
|
obj.ViewObject.ShapeMaterial.AmbientColor = (0.3, 0.3, 0.3, 0.0) |
|
|
|
|
|
|
|
obj.ViewObject.ShapeMaterial.DiffuseColor = (1.0, 1.0, 1.0, 0.0) |
|
|
|
|
|
|
|
obj.ViewObject.ShapeMaterial.SpecularColor = (0.5, 0.5, 0.5, 0.0) |
|
|
|
|
|
|
|
obj.ViewObject.ShapeMaterial.EmissiveColor = (0.0, 0.0, 0.0, 0.0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
workbench = Gui.getWorkbench("AssemblyHandbookWorkbench") |
|
|
|
|
|
|
|
workbench.context.onPartStageChanged(None) |
|
|
|
|
|
|
|
|
|
|
|
def Activated(self): |
|
|
|
def Activated(self): |
|
|
|
resolution = (2048, 2048) |
|
|
|
resolution = (2000, 2000) |
|
|
|
filename = "/home/youen/dev_linux/vhelio-render/vhelio.png" |
|
|
|
filename = "/home/youen/dev_linux/vhelio-render/vhelio.png" |
|
|
|
|
|
|
|
|
|
|
|
temp_lines_file_name = tempfile.gettempdir() + "/ahb_temp_lines.png" |
|
|
|
temp_lines_file_name = tempfile.gettempdir() + "/ahb_temp_lines.png" |
|
|
|
temp_shapes_file_name = tempfile.gettempdir() + "/ahb_temp_shapes.png" |
|
|
|
temp_shapes_file_name = tempfile.gettempdir() + "/ahb_temp_shapes.png" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.set_render_outlines() |
|
|
|
|
|
|
|
Gui.ActiveDocument.ActiveView.saveImage(temp_shapes_file_name, resolution[0] * 2, resolution[1] * 2, "#ffffff") |
|
|
|
|
|
|
|
|
|
|
|
self.set_render_lines() |
|
|
|
self.set_render_lines() |
|
|
|
Gui.ActiveDocument.ActiveView.saveImage(temp_lines_file_name, resolution[0], resolution[1], "#ffffff") |
|
|
|
Gui.ActiveDocument.ActiveView.saveImage(temp_lines_file_name, resolution[0], resolution[1], "#ffffff") |
|
|
|
|
|
|
|
|
|
|
|
self.set_render_outlines() |
|
|
|
self.reset_display() |
|
|
|
Gui.ActiveDocument.ActiveView.saveImage(temp_shapes_file_name, resolution[0]*2, resolution[1]*2, "#ffffff") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from PIL import Image, ImageFilter |
|
|
|
from PIL import Image, ImageFilter |
|
|
|
#import time |
|
|
|
import time |
|
|
|
lines = Image.open(temp_lines_file_name) |
|
|
|
lines = Image.open(temp_lines_file_name) |
|
|
|
lines = lines.convert("L") |
|
|
|
lines = lines.convert("L") |
|
|
|
shapes = Image.open(temp_shapes_file_name) |
|
|
|
shapes = Image.open(temp_shapes_file_name) |
|
|
|
|
|
|
|
|
|
|
|
#startTime = time.perf_counter() |
|
|
|
startTime = time.perf_counter() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
outlines = None |
|
|
|
|
|
|
|
for x in range(0, 3): |
|
|
|
|
|
|
|
for y in range(0, 3): |
|
|
|
|
|
|
|
if x == 1 and y == 1: continue |
|
|
|
|
|
|
|
kernel = [0, 0, 0, 0, 1, 0, 0, 0, 0] |
|
|
|
|
|
|
|
kernel[y*3 + x] = -1 |
|
|
|
|
|
|
|
partial_outlines = shapes.filter(ImageFilter.Kernel((3, 3), kernel, 1, 127)) |
|
|
|
|
|
|
|
partial_outlines = partial_outlines.point(lambda p: 255 if p == 127 else 0) |
|
|
|
|
|
|
|
partial_outlines = partial_outlines.convert("L") |
|
|
|
|
|
|
|
partial_outlines = partial_outlines.point(lambda p: 255 if p == 255 else 0) |
|
|
|
|
|
|
|
if outlines is None: |
|
|
|
|
|
|
|
outlines = partial_outlines |
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
outlines.paste(partial_outlines, None, partial_outlines.point(lambda p: 255 - p)) |
|
|
|
|
|
|
|
|
|
|
|
outlines = shapes.filter(ImageFilter.Kernel((3, 3), (-1, -1, -1, -1, 8, -1, -1, -1, -1), 1, 0)) |
|
|
|
|
|
|
|
outlines2 = shapes.filter(ImageFilter.Kernel((3, 3), (1, 1, 1, 1, -8, 1, 1, 1, 1), 1, 0)) |
|
|
|
|
|
|
|
outlines = outlines.convert("L") |
|
|
|
|
|
|
|
outlines2 = outlines2.convert("L") |
|
|
|
|
|
|
|
outlines = outlines.point(lambda p: 0 if p > 0 else 255) |
|
|
|
|
|
|
|
outlines2 = outlines2.point(lambda p: 0 if p > 0 else 255) |
|
|
|
|
|
|
|
outlines.paste(outlines2, None, outlines2.point(lambda p: 255 - p)) |
|
|
|
|
|
|
|
#outlines.save("/home/youen/dev_linux/vhelio-render/vhelio-outlines.png") |
|
|
|
#outlines.save("/home/youen/dev_linux/vhelio-render/vhelio-outlines.png") |
|
|
|
lines = lines.resize(outlines.size, Image.NEAREST) |
|
|
|
|
|
|
|
lines.paste(outlines, None, outlines.point(lambda p: 255 - p)) |
|
|
|
|
|
|
|
lines = lines.resize(lines.size, Image.BILINEAR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endTime = time.perf_counter() |
|
|
|
#outlines = outlines.resize(lines.size, Image.BILINEAR) |
|
|
|
#print("Outline detection: " + str(round((endTime - startTime)*1000)/1000) + "s") |
|
|
|
#lines.paste(outlines, None, outlines.point(lambda p: 255 - p)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lines_fullres = lines.resize(outlines.size, Image.NEAREST) |
|
|
|
|
|
|
|
lines_fullres.paste(outlines, None, outlines.point(lambda p: 255 - p)) |
|
|
|
|
|
|
|
lines = lines_fullres.resize(lines.size, Image.BILINEAR) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
endTime = time.perf_counter() |
|
|
|
|
|
|
|
print("Outline detection: " + str(round((endTime - startTime)*1000)/1000) + "s") |
|
|
|
lines.save(filename) |
|
|
|
lines.save(filename) |
|
|
|
|
|
|
|
|
|
|
|
from ahb_command import AHB_CommandWrapper |
|
|
|
from ahb_command import AHB_CommandWrapper |
|
|
|