Commit bcfce3f5 authored by luroth's avatar luroth
Browse files

stable multithreathing

parent 6032fddd
......@@ -17,6 +17,8 @@ import matplotlib.pyplot as plt
import shapefile
from scipy.interpolate import griddata
from osgeo import gdalnumeric
import time
def rotation_matrix(axis, theta):
axis = np.asarray(axis)
......@@ -104,11 +106,13 @@ def ray_trace(line_vector, line_point, plane_point, plane_normal):
return Psi
def intersect_line_with_planes(plane_normales, plane_points, line_vector, line_point, corners):
t_start = time.time()
# create corner polygons
corners_poly1_normale = get_polygon_normale([corners[0], corners[1], corners[2]])
point_poly1 = corners[0]
corners_poly2_normale = get_polygon_normale([corners[2], corners[3], corners[0]])
point_poly2 = corners[2]
t_init_normales = time.time()
# estimate location with corner polygons
intersect_point1 = ray_trace(line_vector, line_point, point_poly1, corners_poly1_normale)
......@@ -117,12 +121,13 @@ def intersect_line_with_planes(plane_normales, plane_points, line_vector, line_p
hit_2 = point_in_poly(intersect_point2[0], intersect_point2[1], [(corners[2][0],corners[0][1]), (corners[3][0],corners[1][1]), (corners[0][0],corners[2][1])])
approximation_point = (intersect_point1 if hit_1 else intersect_point2)
# print("x", end="", flush=True)
t_approximation = time.time()
# create index with closes points first
plane_delta_pos = plane_points[:, [0,1]] - approximation_point[[0,1]]
plane_delta_dist = np.sqrt(plane_delta_pos[:,0]**2 + plane_delta_pos[:,1]**2)
index_list = np.argsort(plane_delta_dist)
t_sort = time.time()
# for all planes
for plane_index in index_list:
......@@ -139,13 +144,13 @@ def intersect_line_with_planes(plane_normales, plane_points, line_vector, line_p
p1_x, p1_y, p2_x, p2_y, p3_x, p3_y = plane_points[plane_index, [0,1,3,4,6,7]].tolist()
hit = point_in_poly(intersect_point[0], intersect_point[1], [(p1_x, p1_y), (p2_x, p2_y), (p3_x, p3_y)] )
if hit:
print('.', flush=True)
t_found= time.time()
print("Pixel calculated. Tries: {0}, Times: Init normal: {1}, Approximation: {2}, Sort: {3}, Intersect: {4}".format(t_init_normales-t_start, t_approximation-t_start, t_sort-t_start, t_found-t_start), flush=True)
return intersect_point.tolist()
else:
print("_", end="")
pass
print("?", end="\n" ,flush=True)
print("Pixel not found.", flush=True)
return [np.nan, np.nan, np.nan]
def main(argv):
......@@ -326,27 +331,27 @@ def main(argv):
plt.figure(figsize=(10,7))
plt.subplot(231)
plt.imshow(ground_pixel_coords_x_interpol.T)
plt.imshow(np.fliplr(ground_pixel_coords_x_interpol.T))
plt.title('X coord')
plt.colorbar(orientation='horizontal')
plt.subplot(232)
plt.imshow(ground_pixel_coords_y_interpol.T)
plt.imshow(np.fliplr(ground_pixel_coords_y_interpol.T))
plt.title('Y coord')
plt.colorbar(orientation='horizontal')
plt.subplot(233)
plt.imshow(ground_pixel_coords_z_interpol.T)
plt.imshow(np.fliplr(ground_pixel_coords_z_interpol.T))
plt.title('Z coord')
plt.colorbar(orientation='horizontal')
plt.subplot(234)
plt.imshow(ground_pixel_angle_xy_interpol.T)
plt.imshow(np.fliplr(ground_pixel_angle_xy_interpol.T))
plt.title('xy view angle')
plt.colorbar(orientation='horizontal')
plt.subplot(235)
plt.imshow(ground_pixel_angle_z_interpol.T)
plt.imshow(np.fliplr(ground_pixel_angle_z_interpol.T))
plt.title('z view angle')
plt.colorbar(orientation='horizontal')
......@@ -355,11 +360,11 @@ def main(argv):
print("\nwrite pixel matrix to TIFF")
gdalnumeric.SaveArray(ground_pixel_coords_x_interpol.T, os.path.join(output_directory, PhotoID + '_metadata_coord_x.tif'), format='GTiff' )
gdalnumeric.SaveArray(ground_pixel_coords_y_interpol.T, os.path.join(output_directory, PhotoID + '_metadata_coord_y.tif'), format='GTiff' )
gdalnumeric.SaveArray(ground_pixel_coords_z_interpol.T, os.path.join(output_directory, PhotoID + '_metadata_coord_z.tif'), format='GTiff' )
gdalnumeric.SaveArray(ground_pixel_angle_xy_interpol.T, os.path.join(output_directory, PhotoID + '_metadata_angle_xy.tif'), format='GTiff' )
gdalnumeric.SaveArray(ground_pixel_angle_z_interpol.T, os.path.join(output_directory, PhotoID + '_metadata_angle_z.tif'), format='GTiff' )
gdalnumeric.SaveArray(np.fliplr(ground_pixel_coords_x_interpol.T), os.path.join(output_directory, PhotoID + '_metadata_coord_x.tif'), format='GTiff' )
gdalnumeric.SaveArray(np.fliplr(ground_pixel_coords_y_interpol.T), os.path.join(output_directory, PhotoID + '_metadata_coord_y.tif'), format='GTiff' )
gdalnumeric.SaveArray(np.fliplr(ground_pixel_coords_z_interpol.T), os.path.join(output_directory, PhotoID + '_metadata_coord_z.tif'), format='GTiff' )
gdalnumeric.SaveArray(np.fliplr(ground_pixel_angle_xy_interpol.T), os.path.join(output_directory, PhotoID + '_metadata_angle_xy.tif'), format='GTiff' )
gdalnumeric.SaveArray(np.fliplr(ground_pixel_angle_z_interpol.T), os.path.join(output_directory, PhotoID + '_metadata_angle_z.tif'), format='GTiff' )
print("\nDONE\n")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment