예제 #1
0
import tfrt.boundaries as boundaries
import tfrt.drawing as drawing
import pyvista as pv

plot = pv.Plotter()
plot.add_axes()
drawer = drawing.TriangleDrawer(plot,
                                color="cyan",
                                parameter_arrow_length=.2,
                                draw_parameter_arrows=True,
                                parameter_arrow_visibility=True,
                                norm_arrow_length=.2,
                                draw_norm_arrows=True,
                                norm_arrow_visibility=True)

#surface = boundaries.ManualTriangleBoundary(file_name="./stl/short_pyramid.stl")
#surface = boundaries.ManualTriangleBoundary(mesh=pv.Sphere())
vg = boundaries.FromAxisVG((0, 0, 0), direction=(0, 0, -1))
surface = boundaries.ParametricTriangleBoundary("./stl/short_pyramid.stl", vg)


def draw():
    drawer.surface = surface
    drawer.draw()


draw()

#print(f"surface vectors: {surface.vectors}")
plot.show()
예제 #2
0
# generate the accumulator
#zero_points = pv.read("./stl/processed_disk.stl")
zero_points = pv.read("./stl/short_pyramid.stl")

top_parent = graph.get_closest_point(zero_points, (0, 0, 0))
vertex_update_map, accumulator = graph.mesh_parametrization_tools(
    zero_points, top_parent)
print("accumulator: ")
print(accumulator)

# build the boundary
vg = boundaries.FromVectorVG((0, 0, 1))
lens = boundaries.ParametricTriangleBoundary(
    zero_points,
    vg,
    auto_update_mesh=True,
    vertex_update_map=vertex_update_map)

# build the plotter
plot = pv.BackgroundPlotter()
plot.add_axes()
drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)
drawer.surface = lens
drawer.draw()
plot.show()

# input loop
point_count = accumulator.shape[0]
grad_step = .1
print(f"type a number between 0 and {point_count - 1} to adjust surface.")
random_angles = distributions.RandomUniformSphere(PI / 8.0, ray_count)
random_source = sources.AngularSource(3, (-source_distance, 0, 0), (1, 0, 0),
                                      random_angles,
                                      random_base_points,
                                      [drawing.YELLOW] * ray_count,
                                      dense=False,
                                      rank_type="base_point")

# build the boundaries
zero_points = pv.read("./stl/processed_disk.stl")
zero_points.rotate_y(90)
vg = boundaries.FromVectorVG((1, 0, 0))
lens = boundaries.ParametricTriangleBoundary(zero_points,
                                             vg,
                                             flip_norm=False,
                                             auto_update_mesh=True,
                                             material_dict={
                                                 "mat_in": 1,
                                                 "mat_out": 0
                                             })
target = boundaries.ManualTriangleBoundary(
    mesh=pv.Plane(center=(target_distance, 0, 0),
                  direction=(1, 0, 0),
                  i_size=100,
                  j_size=100,
                  i_resolution=1,
                  j_resolution=1).triangulate())
target.frozen = True

# build the optical system
system = engine.OpticalSystem3D()
system.optical = [lens]
예제 #4
0
    print("smoother")
    print(smoother)
    print("------------")
row_sums = [np.sum(row) for row in smoother]
sum_to_1 = np.equal(row_sums, 1)
print(f"check rows sum to 1: {np.all(sum_to_1)}")

print(f"shape: {smoother.shape}")

# build the boundary
vg = boundaries.FromVectorVG((0, 0, 1))
point_count = zero_points.points.shape[0]
lens = boundaries.ParametricTriangleBoundary(
    zero_points,
    vg,
    auto_update_mesh=True,
    initial_parameters=tf.random.normal((point_count, ),
                                        stddev=.1,
                                        dtype=tf.float64))

# build the plotter
plot = pv.Plotter()
plot.add_axes()
drawer = drawing.TriangleDrawer(plot, color="cyan", show_edges=True)
drawer.surface = lens
drawer.draw()


def smooth(lens, smoother):
    params = tf.reshape(lens.parameters, (-1, 1))
    params = tf.matmul(smoother, params)
                          np.array([3, 0, 1, 2]))

# do the mesh tricks
top_parent = graph.get_closest_point(zero_points, (0, 0, 0))
vertex_update_map, accumulator = graph.mesh_parametrization_tools(
    zero_points, top_parent)

print(f"accumulator: {accumulator}")
print(f"vertex update map: {vertex_update_map}")

vg = boundaries.FromVectorVG((1, 0, 0))
lens = boundaries.ParametricTriangleBoundary(
    zero_points,
    vg,
    True,
    auto_update_mesh=True,
    material_dict={
        "mat_in": 1,
        "mat_out": 0
    },
    vertex_update_map=vertex_update_map)
target = boundaries.ManualTriangleBoundary(
    mesh=pv.Plane(center=(5, 0, 0),
                  direction=(1, 0, 0),
                  i_size=100,
                  j_size=100,
                  i_resolution=1,
                  j_resolution=1).triangulate())
target.frozen = True

# build the optical system
system = engine.OpticalSystem3D()
예제 #6
0
import tensorflow as tf
import numpy as np
import pyvista as pv

import tfrt.boundaries as boundaries

b = boundaries.ParametricTriangleBoundary("./stl/short_pyramid.stl", None)
#b.mesh.plot(color="cyan")