Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions __init___.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
def get_attribute(header, attr_name, default="N/A"):
if hasattr(header, attr_name):
return str(getattr(header, attr_name))
else:
return default
return default

class IMPORT_OT_las_data(Operator, ImportHelper):
bl_idname = "import_scene.las_data"
Expand All @@ -59,18 +58,16 @@ def execute(self, context):
# Get LAS points
num_points_to_read = infile.header.point_count
all_points = infile.read_points(n=num_points_to_read)
points = np.array([(point['X'] * infile.header.x_scale + infile.header.x_offset,
point['Y'] * infile.header.y_scale + infile.header.y_offset,
point['Z'] * infile.header.z_scale + infile.header.z_offset)
for point in all_points])

# Prepare LiDAR info
lidar_info = {
'filepath': self.filepath,
'point_format': infile.header.point_format,
'point_count': num_points_to_read,
'header': infile.header
}

# Prepare LiDAR info
lidar_info = {
'filepath': self.filepath,
'point_format': infile.header.point_format,
'point_count': num_points_to_read,
'header': infile.header
}
points = np.array(all_points.array)
points = points[['X', 'Y', 'Z']]

# Import LAS points as a mesh
self.import_points_as_mesh(context, points, lidar_info)
Expand Down Expand Up @@ -100,16 +97,7 @@ def import_points_as_mesh(self, context, points, lidar_info):

# Create mesh vertices from points
mesh.from_pydata(points, [], [])

# Set mesh object's origin to the center of its bounding box and location to (0, 0, 0)
min_coords = [min(points, key=lambda coord: coord[i])[i] for i in range(3)]
max_coords = [max(points, key=lambda coord: coord[i])[i] for i in range(3)]
center = Vector([(min_coords[i] + max_coords[i]) / 2 for i in range(3)])

for vertex in mesh.vertices:
vertex.co -= center

obj.location = Vector((0, 0, 0))
obj.scale = Vector(obj['lidar_scale'])

# Update mesh
mesh.update()
Expand Down