Skip to content

Commit

Permalink
Calculate color scale by file instead of assuming it's the same
Browse files Browse the repository at this point in the history
  • Loading branch information
autra committed Mar 25, 2022
1 parent 4c46614 commit 1fc37bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion py3dtiles/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def add_tasks_to_process(state, name, task, point_count):

zmq_send_to_process(zmq_idle_clients, zmq_skt, [pickle.dumps({
'filename': file,
'offset_scale': (-avg_min, root_scale, rotation_matrix[:3, :3].T if rotation_matrix is not None else None, infos['color_scale']),
'offset_scale': (-avg_min, root_scale, rotation_matrix[:3, :3].T if rotation_matrix is not None else None, infos['color_scale'].get(file)),
'portion': portion,
'id': _id
})])
Expand Down
19 changes: 11 additions & 8 deletions py3dtiles/points/task/las_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def init(files, color_scale=None, srs_in=None, srs_out=None, fraction=100):
total_point_count = 0
pointcloud_file_portions = []
avg_min = np.array([0., 0., 0.])
color_scale_by_file = {}

for filename in files:
try:
Expand All @@ -32,13 +33,15 @@ def init(files, color_scale=None, srs_in=None, srs_out=None, fraction=100):
total_point_count += count

# read the first points red channel
if color_scale is None:
if 'red' in f.header.point_format.dimension_names:
points = next(f.chunk_iterator(10000))['red']
if np.max(points) > 255:
color_scale = 1.0 / 255
else:
color_scale = 1.0 / 255
if color_scale is not None:
color_scale_by_file[filename] = color_scale
elif 'red' in f.header.point_format.dimension_names:
points = next(f.chunk_iterator(10000))['red']
if np.max(points) > 255:
color_scale_by_file[filename] = 1.0 / 255
else:
# the intensity is then used as color
color_scale_by_file[filename] = 1.0 / 255

_1M = min(count, 1000000)
steps = math.ceil(count / _1M)
Expand All @@ -61,7 +64,7 @@ def init(files, color_scale=None, srs_in=None, srs_out=None, fraction=100):
return {
'portions': pointcloud_file_portions,
'aabb': aabb,
'color_scale': color_scale,
'color_scale': color_scale_by_file,
'srs_in': srs_in,
'point_count': total_point_count,
'avg_min': avg_min
Expand Down

0 comments on commit 1fc37bb

Please sign in to comment.