Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,881 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
from raypier.tracer import RayTraceModel | ||
from raypier.faces import PlanarFace, ExtendedPolynomialFace, ConicFace | ||
from raypier.shapes import CircleShape | ||
from raypier.general_optic import GeneralLens | ||
from raypier.materials import OpticalMaterial | ||
from raypier.gausslet_sources import CollimatedGaussletSource | ||
from raypier.fields import EFieldPlane | ||
from raypier.probes import GaussletCapturePlane | ||
from raypier.intensity_image import IntensityImageView | ||
from raypier.intensity_surface import IntensitySurface | ||
|
||
import numpy | ||
|
||
coefs = numpy.array([[0.1, 0.1, 1], | ||
[0.1, 0.2, 0.0], | ||
[0.1, 0.0, 0.0]]) | ||
|
||
#coefs = numpy.zeros((3,3), 'd') | ||
|
||
|
||
shape = CircleShape(radius=10.0) | ||
f1 = ExtendedPolynomialFace(z_height=-2.0, curvature=-25.0, conic_const=0.0, norm_radius=5.0, coefs=coefs) | ||
#f1 = ConicFace(z_height=0.0, curvature=-25.0, conic_const=0.0) | ||
f2 = PlanarFace(z_height=5.0) | ||
|
||
mat = OpticalMaterial(glass_name="N-BK7") | ||
lens = GeneralLens(shape=shape, surfaces=[f1,f2], materials=[mat]) | ||
|
||
src = CollimatedGaussletSource(radius=8.0, resolution=6, | ||
origin=(0,0,-15), direction=(0,0,1), | ||
display="wires", opacity=0.2, show_normals=True) | ||
src.max_ray_len=50.0 | ||
|
||
|
||
cap = GaussletCapturePlane(centre = (0,0,50), | ||
direction= (0,0,1), | ||
width=20, | ||
height=20) | ||
|
||
field = EFieldPlane(detector=cap, | ||
align_detector=True, | ||
size=100, | ||
width=1, | ||
height=1) | ||
|
||
img = IntensityImageView(field_probe=field) | ||
surf = IntensitySurface(field_probe=field) | ||
|
||
|
||
model = RayTraceModel(optics=[lens], sources=[src], probes=[field,cap], | ||
results=[img,surf]) | ||
model.configure_traits() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
|
||
from raypier.tracer import RayTraceModel | ||
from raypier.meshes import STLFileMesh | ||
from raypier.sources import ParallelRaySource | ||
|
||
|
||
src = ParallelRaySource(origin=(0.,0.,-50.0) | ||
) | ||
|
||
m = STLFileMesh(file_name = "../experiments/monkey.stl", scale_factor=20.0) | ||
|
||
model = RayTraceModel(sources=[src], optics=[m]) | ||
model.configure_traits() | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
|
||
from tvtk.api import tvtk | ||
|
||
import numpy as np | ||
|
||
from raypier.core.obbtree import OBBTree | ||
|
||
|
||
def get_monkey_actor(): | ||
reader = tvtk.STLReader(file_name="monkey.stl") | ||
m = tvtk.PolyDataMapper(input_connection=reader.output_port) | ||
a = tvtk.Actor(mapper=m) | ||
return a | ||
|
||
|
||
def show_monkey(): | ||
a = get_monkey_actor() | ||
|
||
ren = tvtk.Renderer() | ||
ren.add_actor(a) | ||
|
||
renwin = tvtk.RenderWindow() | ||
renwin.add_renderer(ren) | ||
|
||
iren = tvtk.RenderWindowInteractor(render_window=renwin) | ||
iren.start() | ||
|
||
def get_monkey_mesh(): | ||
reader = tvtk.STLReader(file_name="monkey.stl") | ||
tris = tvtk.TriangleFilter(input_connection=reader.output_port) | ||
tris.update() | ||
pd = tris.output | ||
points = np.asarray(pd.points) | ||
cells = pd.polys.to_array().reshape(-1,4)[:,1:] | ||
cells = np.ascontiguousarray(cells, dtype=np.int32) | ||
return points.copy(), cells.copy() | ||
|
||
|
||
def get_monkey_obbtree(): | ||
points, cells = get_monkey_mesh() | ||
print(cells.dtype, cells.shape, points.shape) | ||
obbtree = OBBTree(points, cells) | ||
obbtree.max_level = 20 | ||
obbtree.number_of_cells_per_node = 8 | ||
obbtree.build_tree() | ||
return obbtree | ||
|
||
|
||
def append_obb_to_dataset(obb, point_list, line_list=None, poly_list=None): | ||
corner = obb.corner | ||
axes = obb.axes | ||
points = [corner, #0 | ||
corner + axes[0], #1 | ||
corner + axes[1], #2 | ||
corner + axes[2], #3 | ||
corner + axes[0] + axes[1], #4 | ||
corner + axes[0] + axes[2], #5 | ||
corner + axes[1] + axes[2], #6 | ||
corner + axes[0] + axes[1] + axes[2]] #7 | ||
if any(any(not np.isfinite(a) for a in pt) for pt in points): | ||
return | ||
start = len(point_list) | ||
point_list.extend(points) | ||
if line_list is not None: | ||
lines = [(0,1),(0,2),(0,3),(2,6),(3,6),(6,7),(1,4),(1,5),(4,7),(5,7),(2,4),(3,5)] | ||
for i, line in enumerate(lines): | ||
this = (start + line[0], start + line[1]) | ||
line_list.append(this) | ||
|
||
if poly_list is not None: | ||
tris = [ | ||
(0,1,2), (1,2,4), | ||
(0,1,3), (1,3,5), | ||
(0,2,3), (2,3,6), | ||
(7,3,5), (7,6,3), | ||
(7,5,1), (7,1,4), | ||
(7,6,2), (7,2,4) | ||
] | ||
for i, tri in enumerate(tris): | ||
this = tuple(start + vtx for vtx in tri) | ||
poly_list.append(this) | ||
|
||
|
||
def add_subtree(obb, points, lines, polys, level=-1): | ||
append_obb_to_dataset(obb, points, lines, polys) | ||
if level == 0: | ||
return | ||
level -= 1 | ||
if obb.child1 is not None: | ||
add_subtree(obb.child1, points, lines, polys, level=level) | ||
if obb.child2 is not None: | ||
add_subtree(obb.child2, points, lines, polys, level=level) | ||
|
||
|
||
def show_monkey_tree(): | ||
obbtree = get_monkey_obbtree() | ||
|
||
print(obbtree.intersect_with_line([0.,0.,0.], [10.,10.,10.])) | ||
|
||
print("Level", obbtree.level) | ||
|
||
points = [] | ||
lines = [] | ||
polys=[] | ||
|
||
add_subtree(obbtree.root, points, lines, polys, level=4) | ||
|
||
points = np.array(points) | ||
lines = np.array(lines) | ||
polys = np.array(polys) | ||
|
||
#print(points) | ||
#print(polys) | ||
|
||
pd = tvtk.PolyData(points=points, lines=lines, polys=polys) | ||
|
||
mapper = tvtk.PolyDataMapper(color_mode=2) | ||
mapper.set_input_data(pd) | ||
act = tvtk.Actor(mapper=mapper) | ||
act.property.opacity=0.1 | ||
ren = tvtk.Renderer() | ||
ren.add_actor(act) | ||
|
||
mk = get_monkey_actor() | ||
ren.add_actor(mk) | ||
|
||
renwin = tvtk.RenderWindow() | ||
renwin.add_renderer(ren) | ||
iren = tvtk.RenderWindowInteractor() | ||
iren._set_render_window(renwin) | ||
iren.start() | ||
|
||
|
||
if __name__=="__main__": | ||
show_monkey_tree() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.