Initial commit.

This commit is contained in:
jmsgrogan 2017-10-20 12:30:47 +01:00
parent 68d9a17dd1
commit 29ffa13092
17 changed files with 224546 additions and 0 deletions

View file

Binary file not shown.

View file

@ -0,0 +1,101 @@
import sys
from argparse import ArgumentParser
# freecad setup
FREECADPATH = "/usr/lib/freecad/lib/"
sys.path.append(FREECADPATH)
import numpy as np
import FreeCAD
import Part
# def generate_bulb(height, radius, thickness):
#
# light_angle = np.arcsin(0.25) + np.pi/2.0
# light_arc_length = radius*light_angle+np.pi/2.0
# num_divisions = 25
# segment_length = light_arc_length/float(num_divisions)
#
# edges = []
# for idx in range(1, num_divisions):
# angle0 = float(idx-1)/float(num_divisions)*light_angle
# angle1 = float(idx)/float(num_divisions)*light_angle
# x0 = -radius*np.sin(angle0)
# y0 = -radius*np.cos(angle0)
# x1 = -radius*np.sin(angle1)
# y1 = -radius*np.cos(angle1)
# edges.append(Part.makeLine((x0, y0, 0),
# (x1, y1, 0)))
#
# edge0 = Part.makeLine((0.0, height, 0),
# (-radius, 0.0, 0))
# edge1 = Part.makeLine((-radius, 0.0, 0),
# (-radius -thickness, 0.0, 0))
# edge2 = Part.makeLine((-radius -thickness, 0.0, 0),
# (-radius -thickness, height, 0))
# edge3 = Part.makeLine((-radius -thickness, height, 0),
# (0.0, height, 0))
# wire1 = Part.Wire([edge0, edge1, edge2, edge3])
# face = Part.Face([wire1,])
#
# pos = FreeCAD.Vector(0.0, 0.0, 0.0)
# vec = FreeCAD.Vector(0.0, 1.0, 0.0)
# angle = 360
# solid = face.revolve(pos, vec, angle)
# return solid
def generate_chord(height, radius, thickness):
edge0 = Part.makeLine((0.0, height, 0),
(-radius, 0.0, 0))
edge1 = Part.makeLine((-radius, 0.0, 0),
(-radius -thickness, 0.0, 0))
edge2 = Part.makeLine((-radius -thickness, 0.0, 0),
(-radius -thickness, height, 0))
edge3 = Part.makeLine((-radius -thickness, height, 0),
(0.0, height, 0))
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
face = Part.Face([wire1,])
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
angle = 360
solid = face.revolve(pos, vec, angle)
return solid
def generate_base(height, radius, thickness):
edge0 = Part.makeLine((0.0, 0.0, 0),
(-radius, -height, 0))
edge1 = Part.makeLine((-radius, -height, 0),
(-radius -thickness, -height, 0))
edge2 = Part.makeLine((-radius -thickness, -height, 0),
(-thickness, 0.0, 0))
edge3 = Part.makeLine((-thickness, 0.0, 0),
(0.0, 0.0, 0))
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
face = Part.Face([wire1,])
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
angle = 360
solid = face.revolve(pos, vec, angle)
return solid
def generate_shade(height, radius, thickness):
edge0 = Part.makeLine((0.0, 0.0, 0),
(-radius, -height, 0))
edge1 = Part.makeLine((-radius, -height, 0),
(-radius -thickness, -height, 0))
edge2 = Part.makeLine((-radius -thickness, -height, 0),
(-thickness, 0.0, 0))
edge3 = Part.makeLine((-thickness, 0.0, 0),
(0.0, 0.0, 0))
wire1 = Part.Wire([edge0, edge1, edge2, edge3])
face = Part.Face([wire1,])
pos = FreeCAD.Vector(0.0, 0.0, 0.0)
vec = FreeCAD.Vector(0.0, 1.0, 0.0)
angle = 360
solid = face.revolve(pos, vec, angle)
return solid

Binary file not shown.

View file

@ -0,0 +1,87 @@
import numpy as np
import vtk
def render_lamp(shade_file_path,
base_file_path,
chord_file_path,
image_file_path,
color):
# create a rendering window and renderer
ren = vtk.vtkRenderer()
ren.SetBackground(1.0, 1.0, 1.0)
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
WIDTH=640
HEIGHT=480
renWin.SetSize(WIDTH,HEIGHT)
# create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# shade
reader = vtk.vtkSTLReader()
reader.SetFileName(shade_file_path)
reader.Update()
shade = reader.GetOutput()
shade_mapper = vtk.vtkPolyDataMapper()
shade_mapper.SetInputData(shade)
shade_actor = vtk.vtkActor()
shade_actor.SetMapper(shade_mapper)
shade_actor.GetProperty().SetColor(np.array(color)/255.0)
# base
base_reader = vtk.vtkSTLReader()
base_reader.SetFileName(base_file_path)
base_reader.Update()
base = base_reader.GetOutput()
base_mapper = vtk.vtkPolyDataMapper()
base_mapper.SetInputData(base)
base_actor = vtk.vtkActor()
base_actor.SetMapper(base_mapper)
base_actor.GetProperty().SetColor(16.0/255.0, 17.0/255.0, 17.0/255.0)
#
# # chord
chord_reader = vtk.vtkSTLReader()
chord_reader.SetFileName(chord_file_path)
chord_reader.Update()
chord = chord_reader.GetOutput()
chord_mapper = vtk.vtkPolyDataMapper()
chord_mapper.SetInputData(chord)
chord_actor = vtk.vtkActor()
chord_actor.SetMapper(chord_mapper)
chord_actor.GetProperty().SetColor(16.0/255.0, 17.0/255.0, 17.0/255.0)
# Add a light
light = vtk.vtkLight()
light.SetPositional(True)
light.SetFocalPoint(0.0,-100.0, 0.0)
light.SetIntensity(1.0)
lightActor = vtk.vtkLightActor()
lightActor.SetLight(light)
light.SetColor(0.0,0.0,0.0)
light.SetSwitch(1)
ren.AddViewProp(lightActor)
# assign actor to the renderer
ren.AddActor(shade_actor)
ren.AddActor(base_actor)
ren.AddActor(chord_actor)
# Do render and output
#iren.Initialize()
renWin.Modified()
renWin.Render()
ren.AddLight(light)
window_to_image = vtk.vtkWindowToImageFilter()
window_to_image.SetInput(renWin)
window_to_image.Update()
png_writer = vtk.vtkPNGWriter()
png_writer.SetFileName(image_file_path)
png_writer.SetInputData(window_to_image.GetOutput())
png_writer.Write()
#iren.Start()

Binary file not shown.

33819
src/utility/base.stl Normal file

File diff suppressed because it is too large Load diff

15171
src/utility/chord.stl Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,40 @@
import os
import product_gen.generate_lamp
import product_gen.render_lamp
from argparse import ArgumentParser
def run(color):
height = 150.0
radius = 100.0
thickness = 3.0
shade = product_gen.generate_lamp.generate_shade(height, radius, thickness)
work_dir = os.getcwd()
shade.exportStl(work_dir + "/shade.stl")
height = 20.0
radius = 15.0
thickness = 3.0
base = product_gen.generate_lamp.generate_base(height, radius, thickness)
base.exportStl(work_dir + "/base.stl")
height = 150.0
radius = 2.0
thickness = 1.0
chord = product_gen.generate_lamp.generate_chord(height, radius, thickness)
chord.exportStl(work_dir + "/chord.stl")
product_gen.render_lamp.render_lamp(work_dir + "/shade.stl",
work_dir + "/base.stl",
work_dir + "/chord.stl",
work_dir + "/lamp.png",
color = color)
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument('-r', type=float, help='Red intensity.')
parser.add_argument('-g', type=float, help='Red intensity.')
parser.add_argument('-b', type=float, help='Red intensity.')
args = parser.parse_args()
run([args.r, args.g, args.b])

BIN
src/utility/lamp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

42107
src/utility/shade.stl Normal file

File diff suppressed because it is too large Load diff

33819
test/base.stl Normal file

File diff suppressed because it is too large Load diff

15171
test/chord.stl Normal file

File diff suppressed because it is too large Load diff

BIN
test/lamp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

42093
test/lamp.stl Normal file

File diff suppressed because it is too large Load diff

42107
test/shade.stl Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,31 @@
import os
import product_gen.generate_lamp
import product_gen.render_lamp
height = 150.0
radius = 100.0
thickness = 3.0
shade = product_gen.generate_lamp.generate_shade(height, radius, thickness)
work_dir = os.getcwd()
shade.exportStl(work_dir + "/shade.stl")
height = 20.0
radius = 15.0
thickness = 3.0
base = product_gen.generate_lamp.generate_base(height, radius, thickness)
work_dir = os.getcwd()
base.exportStl(work_dir + "/base.stl")
height = 150.0
radius = 2.0
thickness = 1.0
chord = product_gen.generate_lamp.generate_chord(height, radius, thickness)
work_dir = os.getcwd()
chord.exportStl(work_dir + "/chord.stl")
product_gen.render_lamp.render_lamp(work_dir + "/shade.stl",
work_dir + "/base.stl",
work_dir + "/chord.stl",
work_dir + "/lamp.png",
color = [25.0, 128.0, 132.0])