Add Dockerfile and modify generator script to change shapes and take a unique file id.
This commit is contained in:
parent
29ffa13092
commit
c9c98f91dc
18 changed files with 166867 additions and 57 deletions
3
Dockerfile
Normal file
3
Dockerfile
Normal file
|
@ -0,0 +1,3 @@
|
|||
FROM ubuntu:latest
|
||||
RUN apt-get update
|
||||
RUN apt-get install --no-install-recommends --no-install-suggests -y freecad python-vtk6 python-numpy
|
19
README.md
19
README.md
|
@ -1 +1,18 @@
|
|||
# gen-backend
|
||||
# gen-backend
|
||||
|
||||
Requirements:
|
||||
|
||||
```bash
|
||||
docker pull jmsgrogan/python-generator
|
||||
```
|
||||
|
||||
Launch:
|
||||
|
||||
```bash
|
||||
python generate_image.py -height 120.0 -radius 150.0 -r 100.0 -g 0.0 -b 0.0 -o 1 -s 0
|
||||
```
|
||||
|
||||
`-o` is a unique output identifier added to file names.
|
||||
`-s` is the generation stage. Stage 0 generates shapes. Stage 1 generates textures.
|
||||
|
||||
The output is a file `lamp_$o.png` in the launch directory, where `$o` is the unique output identifier. Three temporary files with suffix `_$o.stl` are also created.
|
|
@ -8,41 +8,6 @@ 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),
|
||||
|
|
Binary file not shown.
|
@ -30,6 +30,10 @@ def render_lamp(shade_file_path,
|
|||
shade_actor = vtk.vtkActor()
|
||||
shade_actor.SetMapper(shade_mapper)
|
||||
shade_actor.GetProperty().SetColor(np.array(color)/255.0)
|
||||
shade_actor.GetProperty().SetAmbient(0.3)
|
||||
shade_actor.GetProperty().SetDiffuse(0.75)
|
||||
shade_actor.GetProperty().SetSpecular(0.5)
|
||||
shade_actor.GetProperty().SetOpacity(0.4)
|
||||
|
||||
# base
|
||||
base_reader = vtk.vtkSTLReader()
|
||||
|
@ -56,6 +60,7 @@ def render_lamp(shade_file_path,
|
|||
# Add a light
|
||||
light = vtk.vtkLight()
|
||||
light.SetPositional(True)
|
||||
light.SetLightTypeToSceneLight()
|
||||
light.SetFocalPoint(0.0,-100.0, 0.0)
|
||||
light.SetIntensity(1.0)
|
||||
lightActor = vtk.vtkLightActor()
|
||||
|
@ -63,12 +68,29 @@ def render_lamp(shade_file_path,
|
|||
|
||||
light.SetColor(0.0,0.0,0.0)
|
||||
light.SetSwitch(1)
|
||||
light.SetConeAngle(60)
|
||||
ren.AddViewProp(lightActor)
|
||||
|
||||
cone = vtk.vtkConeSource()
|
||||
cone.SetResolution(60)
|
||||
cone.SetCenter(0.0,-150.0,0)
|
||||
cone.SetHeight(20.0)
|
||||
cone.SetRadius(20.0)
|
||||
|
||||
cone_mapper = vtk.vtkPolyDataMapper()
|
||||
cone_mapper.SetInputConnection(cone.GetOutputPort())
|
||||
cone_mapper.SetScalarVisibility(0)
|
||||
|
||||
cone_actor = vtk.vtkActor()
|
||||
cone_actor.SetMapper(cone_mapper)
|
||||
cone_actor.SetVisibility(1)
|
||||
cone_actor.GetProperty().SetColor(1.0, 1.0, 1.0)
|
||||
|
||||
# assign actor to the renderer
|
||||
ren.AddActor(shade_actor)
|
||||
ren.AddActor(base_actor)
|
||||
ren.AddActor(chord_actor)
|
||||
#ren.AddActor(cone_actor)
|
||||
|
||||
# Do render and output
|
||||
#iren.Initialize()
|
||||
|
|
Binary file not shown.
33819
src/utility/base_1.stl
Normal file
33819
src/utility/base_1.stl
Normal file
File diff suppressed because it is too large
Load diff
33819
src/utility/base_2.stl
Normal file
33819
src/utility/base_2.stl
Normal file
File diff suppressed because it is too large
Load diff
15171
src/utility/chord_1.stl
Normal file
15171
src/utility/chord_1.stl
Normal file
File diff suppressed because it is too large
Load diff
15171
src/utility/chord_2.stl
Normal file
15171
src/utility/chord_2.stl
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,37 +4,48 @@ import product_gen.render_lamp
|
|||
|
||||
from argparse import ArgumentParser
|
||||
|
||||
def run(color):
|
||||
height = 150.0
|
||||
radius = 100.0
|
||||
def run(height, radius, color, output_id):
|
||||
thickness = 3.0
|
||||
shade = product_gen.generate_lamp.generate_shade(height, radius, thickness)
|
||||
work_dir = os.getcwd()
|
||||
shade.exportStl(work_dir + "/shade.stl")
|
||||
shade.exportStl(work_dir + "/shade_" + output_id + ".stl")
|
||||
|
||||
height = 20.0
|
||||
radius = 15.0
|
||||
base_height = 20.0
|
||||
base_radius = 15.0
|
||||
thickness = 3.0
|
||||
base = product_gen.generate_lamp.generate_base(height, radius, thickness)
|
||||
base.exportStl(work_dir + "/base.stl")
|
||||
base = product_gen.generate_lamp.generate_base(base_height,
|
||||
base_radius,
|
||||
thickness)
|
||||
base.exportStl(work_dir + "/base_" + output_id + ".stl")
|
||||
|
||||
height = 150.0
|
||||
radius = 2.0
|
||||
chord_height = 150.0
|
||||
chord_radius = 2.0
|
||||
thickness = 1.0
|
||||
chord = product_gen.generate_lamp.generate_chord(height, radius, thickness)
|
||||
chord.exportStl(work_dir + "/chord.stl")
|
||||
chord = product_gen.generate_lamp.generate_chord(chord_height,
|
||||
chord_radius,
|
||||
thickness)
|
||||
chord.exportStl(work_dir + "/chord_" + output_id + ".stl")
|
||||
|
||||
product_gen.render_lamp.render_lamp(work_dir + "/shade.stl",
|
||||
work_dir + "/base.stl",
|
||||
work_dir + "/chord.stl",
|
||||
work_dir + "/lamp.png",
|
||||
product_gen.render_lamp.render_lamp(work_dir + "/shade_" + output_id + ".stl",
|
||||
work_dir + "/base_" + output_id + ".stl",
|
||||
work_dir + "/chord_" + output_id + ".stl",
|
||||
work_dir + "/lamp_" + output_id + ".png",
|
||||
color = color)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('-height', type=float, help='Height.')
|
||||
parser.add_argument('-radius', type=float, help='Radius.')
|
||||
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.')
|
||||
parser.add_argument('-g', type=float, help='Green intensity.')
|
||||
parser.add_argument('-b', type=float, help='Blue intensity.')
|
||||
parser.add_argument('-o', type=str, help='Output identifier.')
|
||||
parser.add_argument('-s', type=int, help='Stage identifier.')
|
||||
|
||||
args = parser.parse_args()
|
||||
run([args.r, args.g, args.b])
|
||||
color = [args.r, args.g, args.b]
|
||||
if args.s == 0:
|
||||
color = [18.0, 18.0, 18.0]
|
||||
|
||||
run(args.height, args.radius, color, args.o)
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
BIN
src/utility/lamp_1.png
Normal file
BIN
src/utility/lamp_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.4 KiB |
BIN
src/utility/lamp_2.png
Normal file
BIN
src/utility/lamp_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
34407
src/utility/shade_1.stl
Normal file
34407
src/utility/shade_1.stl
Normal file
File diff suppressed because it is too large
Load diff
34407
src/utility/shade_2.stl
Normal file
34407
src/utility/shade_2.stl
Normal file
File diff suppressed because it is too large
Load diff
BIN
test/lamp.png
BIN
test/lamp.png
Binary file not shown.
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 26 KiB |
|
@ -13,14 +13,12 @@ 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",
|
||||
|
|
Loading…
Reference in a new issue