Hey Alexey,
I think that the code would still deselect tpts that have 2 or more projections in one selected group only and not different groups maybe following code could serve as basis for some better solution:
doc = Metashape.app.document
chunk = doc.chunk
point_cloud = chunk.point_cloud
points = point_cloud.points
projections = point_cloud.projections
npoints = len(points)
selected_groups = dict()
for camera in chunk.cameras:
if not camera.group:
continue
if camera.group.selected:
if chunk.camera_groups.index(camera.group) in selected_groups.keys():
selected_groups[chunk.camera_groups.index(camera.group)].append(camera)
else:
selected_groups[chunk.camera_groups.index(camera.group)] = [camera]
nselgrps = len(selected_groups.keys())
selected_points = dict()
for i, igroup in enumerate(selected_groups.keys()):
for camera in selected_groups[igroup]:
point_index = 0
for proj in projections[camera]:
track_id = proj.track_id
while point_index < npoints and points[point_index].track_id < track_id:
point_index += 1
if point_index < npoints and points[point_index].track_id == track_id:
if not points[point_index].valid:
continue
else:
if points[point_index].selected :
if points[point_index].track_id in selected_points.keys() :
if selected_points[points[point_index].track_id][i+2] == 0:
selected_points[points[point_index].track_id][1] += 1
selected_points[points[point_index].track_id][i+2] = 1
else:
selected_points[points[point_index].track_id][i+2] += 1
else:
selected_points[points[point_index].track_id] = [points[point_index], 1] + nselgrps*[0]
selected_points[points[point_index].track_id][i+2] = 1
ndsel = 0
for point in selected_points.keys():
if selected_points[point][1] > 1:
selected_points[point][0].selected = False
ndsel += 1
print("Number pts unselected: ",ndsel,"Number remaining: ",len(selected_points.keys())-ndsel)
print("done")
I added n flags (where n is number of selected camera groups or folders) to selected_points dict so as to test if a projection in one group has not been already detected for a given selected tiept..I am sure it can be improved as I am not a Python expert.
Result would be something like this in case of 4 selected groups:
selected_points
Out[18]: 2020-12-11 10:52:36
2020-12-11 10:52:36 {27906: [<Metashape.PointCloud.Point at 0x1c861a65e50>, 2, 1, 0, 1, 0],
2020-12-11 10:52:36 114398: [<Metashape.PointCloud.Point at 0x1c861a65e10>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 114498: [<Metashape.PointCloud.Point at 0x1c8011ef410>, 1, 3, 0, 0, 0],
2020-12-11 10:52:36 114499: [<Metashape.PointCloud.Point at 0x1c861a65910>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 114500: [<Metashape.PointCloud.Point at 0x1c8011ef510>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 114503: [<Metashape.PointCloud.Point at 0x1c8011ef770>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 114505: [<Metashape.PointCloud.Point at 0x1c8011ef7b0>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 115029: [<Metashape.PointCloud.Point at 0x1c8011ef790>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 115030: [<Metashape.PointCloud.Point at 0x1c8011ef610>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 115129: [<Metashape.PointCloud.Point at 0x1c8011ef210>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 115138: [<Metashape.PointCloud.Point at 0x1c8011ef630>, 1, 2, 0, 0, 0],
2020-12-11 10:52:36 33357: [<Metashape.PointCloud.Point at 0x1c8011ef890>, 2, 2, 3, 0, 0],
2020-12-11 10:52:36 36919: [<Metashape.PointCloud.Point at 0x1c8011ef6d0>, 2, 2, 2, 0, 0],
2020-12-11 10:52:36 37316: [<Metashape.PointCloud.Point at 0x1c8011ef7d0>, 2, 2, 2, 0, 0],
2020-12-11 10:52:36 37874: [<Metashape.PointCloud.Point at 0x1c8011ef650>, 3, 2, 2, 1, 0],
....
where when 2 or more flags are not 0 then there exists one or more projections from 2 or more different groups...so first integer after each PointCloud. Point in dict represents the number of groups or folders having projections.
Hope this can helpful,