forked from youen/assembly_handbook
optimized outline detection (3x faster), added possibility to disable lines per object
This commit is contained in:
parent
7719650a85
commit
6c0301dc30
@ -18,10 +18,13 @@ class AHB_Render:
|
|||||||
for obj in doc.Objects:
|
for obj in doc.Objects:
|
||||||
if obj.TypeId == 'Part::Feature':
|
if obj.TypeId == 'Part::Feature':
|
||||||
if 'AssemblyHandbook_Stage' in obj.PropertiesList:
|
if 'AssemblyHandbook_Stage' in obj.PropertiesList:
|
||||||
|
if 'AssemblyHandbook_RenderLines' in obj.PropertiesList and not obj.AssemblyHandbook_RenderLines:
|
||||||
|
obj.ViewObject.LineColor = background_color
|
||||||
|
else:
|
||||||
|
obj.ViewObject.LineColor = line_color
|
||||||
obj.ViewObject.DisplayMode = 'Flat Lines'
|
obj.ViewObject.DisplayMode = 'Flat Lines'
|
||||||
obj.ViewObject.ShapeMaterial.AmbientColor = (0.0, 0.0, 0.0, 0.0)
|
obj.ViewObject.ShapeMaterial.AmbientColor = (0.0, 0.0, 0.0, 0.0)
|
||||||
obj.ViewObject.ShapeMaterial.EmissiveColor = background_color
|
obj.ViewObject.ShapeMaterial.EmissiveColor = background_color
|
||||||
obj.ViewObject.LineColor = line_color
|
|
||||||
|
|
||||||
def set_render_outlines(self):
|
def set_render_outlines(self):
|
||||||
doc = App.activeDocument()
|
doc = App.activeDocument()
|
||||||
@ -49,7 +52,7 @@ class AHB_Render:
|
|||||||
b = step
|
b = step
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
resolution = (512, 512)
|
resolution = (1024, 1024)
|
||||||
|
|
||||||
self.set_render_lines()
|
self.set_render_lines()
|
||||||
Gui.ActiveDocument.ActiveView.saveImage("/home/youen/dev_linux/vhelio-render/vhelio.png", resolution[0], resolution[1], "#ffffff")
|
Gui.ActiveDocument.ActiveView.saveImage("/home/youen/dev_linux/vhelio-render/vhelio.png", resolution[0], resolution[1], "#ffffff")
|
||||||
@ -62,25 +65,41 @@ class AHB_Render:
|
|||||||
lines = Image.open("/home/youen/dev_linux/vhelio-render/vhelio.png")
|
lines = Image.open("/home/youen/dev_linux/vhelio-render/vhelio.png")
|
||||||
lines = lines.convert("L")
|
lines = lines.convert("L")
|
||||||
shapes = Image.open("/home/youen/dev_linux/vhelio-render/vhelio-shapes.png")
|
shapes = Image.open("/home/youen/dev_linux/vhelio-render/vhelio-shapes.png")
|
||||||
|
|
||||||
|
cacheWidth = 8
|
||||||
|
cacheHalfWidth = int(cacheWidth/2)
|
||||||
|
cache = []
|
||||||
|
for y in range(0, 4):
|
||||||
|
cacheLine = []
|
||||||
|
for x in range(0, cacheWidth + 2):
|
||||||
|
cacheLine.append((0.0,0.0,0.0))
|
||||||
|
cache.append(cacheLine)
|
||||||
|
|
||||||
startTime = time.perf_counter()
|
startTime = time.perf_counter()
|
||||||
for xb in range(1, lines.size[0]-1):
|
for xb in range(1, lines.size[0]-cacheHalfWidth, cacheHalfWidth):
|
||||||
for yb in range(1, lines.size[1]-1):
|
for yb in range(1, lines.size[1]-1):
|
||||||
outline_color = 1.0
|
for y in range(0, 4):
|
||||||
for x in range(xb*2, xb*2+2):
|
cacheLine = cache[y]
|
||||||
for y in range(yb*2, yb*2+2):
|
for x in range(0, cacheWidth + 2):
|
||||||
c = shapes.getpixel((x, y))
|
cacheLine[x] = shapes.getpixel((xb*2+x-1, yb*2+y-1))
|
||||||
border = False
|
|
||||||
if c != shapes.getpixel((x - 1, y - 1)): border = True
|
for xa in range(0, cacheHalfWidth):
|
||||||
if c != shapes.getpixel((x, y - 1)): border = True
|
outline_color = 1.0
|
||||||
if c != shapes.getpixel((x + 1, y - 1)): border = True
|
for xaa in range(0, 2):
|
||||||
if c != shapes.getpixel((x - 1, y)): border = True
|
x = xa*2 + xaa
|
||||||
if c != shapes.getpixel((x, y)): border = True
|
for y in range(0, 2):
|
||||||
if c != shapes.getpixel((x + 1, y)): border = True
|
c = cache[y+1][x+1]
|
||||||
if c != shapes.getpixel((x - 1, y + 1)): border = True
|
border = False
|
||||||
if c != shapes.getpixel((x, y + 1)): border = True
|
if c != cache[y][x]: border = True
|
||||||
if c != shapes.getpixel((x + 1, y + 1)): border = True
|
if c != cache[y][x+1]: border = True
|
||||||
if border: outline_color = outline_color - 0.25
|
if c != cache[y][x+2]: border = True
|
||||||
lines.putpixel((xb, yb), min(lines.getpixel((xb, yb)), int(outline_color * 255.0)))
|
if c != cache[y+1][x]: border = True
|
||||||
|
if c != cache[y+1][x+2]: border = True
|
||||||
|
if c != cache[y+2][x]: border = True
|
||||||
|
if c != cache[y+2][x+1]: border = True
|
||||||
|
if c != cache[y+2][x+2]: border = True
|
||||||
|
if border: outline_color = outline_color - 0.25
|
||||||
|
lines.putpixel((xb+xa, yb), min(lines.getpixel((xb+xa, yb)), int(outline_color * 255.0)))
|
||||||
endTime = time.perf_counter()
|
endTime = time.perf_counter()
|
||||||
print("Outline detection: " + str(round((endTime - startTime)*1000)/1000) + "s")
|
print("Outline detection: " + str(round((endTime - startTime)*1000)/1000) + "s")
|
||||||
lines.save("/home/youen/dev_linux/vhelio-render/vhelio-final.png")
|
lines.save("/home/youen/dev_linux/vhelio-render/vhelio-final.png")
|
||||||
|
@ -25,6 +25,8 @@ class AHB_SetPartStage:
|
|||||||
if obj is not None and obj.TypeId == 'Part::Feature':
|
if obj is not None and obj.TypeId == 'Part::Feature':
|
||||||
if not "AssemblyHandbook_Stage" in obj.PropertiesList:
|
if not "AssemblyHandbook_Stage" in obj.PropertiesList:
|
||||||
obj.addProperty("App::PropertyInteger", "AssemblyHandbook_Stage", "AssemblyHandbook")
|
obj.addProperty("App::PropertyInteger", "AssemblyHandbook_Stage", "AssemblyHandbook")
|
||||||
|
if not "AssemblyHandbook_RenderLines" in obj.PropertiesList:
|
||||||
|
obj.addProperty("App::PropertyBool", "AssemblyHandbook_RenderLines", "AssemblyHandbook")
|
||||||
if obj.AssemblyHandbook_Stage != stageId:
|
if obj.AssemblyHandbook_Stage != stageId:
|
||||||
obj.AssemblyHandbook_Stage = stageId
|
obj.AssemblyHandbook_Stage = stageId
|
||||||
workbench.context.onPartStageChanged(obj)
|
workbench.context.onPartStageChanged(obj)
|
||||||
|
Loading…
Reference in New Issue
Block a user