|
15 | 15 | vtkWorldPointPicker, |
16 | 16 | vtkCellPicker, |
17 | 17 | vtkPropPicker, |
18 | | - vtkCompositePolyDataMapper, |
19 | 18 | vtkDataSetMapper, |
20 | 19 | vtkActor, |
21 | 20 | ) |
@@ -262,52 +261,26 @@ def pickedIds(self, rpc_params: RpcParams) -> dict[str, list[str] | int | None]: |
262 | 261 | rpc_params, self.viewer_schemas_dict["picked_ids"], self.viewer_prefix |
263 | 262 | ) |
264 | 263 | params = schemas.PickedIDS.from_dict(rpc_params) |
265 | | - renderer = self.getView("-1").GetRenderers().GetFirstRenderer() |
266 | | - |
267 | | - pipelines_to_restore = [ |
268 | | - pipeline |
269 | | - for pipeline_id in params.ids |
270 | | - if (pipeline := self.get_vtk_pipeline(pipeline_id)).pick_mapper is not None |
271 | | - ] |
272 | | - for pipeline in pipelines_to_restore: |
273 | | - pick_mapper = pipeline.pick_mapper |
274 | | - if pick_mapper is not None: |
275 | | - pipeline.actor.SetMapper(pick_mapper) |
276 | | - |
277 | | - actors = [] |
278 | 264 | picker = vtkCellPicker(tolerance=0.005) |
279 | | - picker.Pick(params.x, params.y, 0, renderer) |
280 | | - actor = picker.GetActor() |
281 | | - viewer_id = picker.GetFlatBlockIndex() |
282 | | - |
283 | | - while actor: |
284 | | - actors.append(actor) |
285 | | - actor.SetPickable(False) |
286 | | - picker.Pick(params.x, params.y, 0, renderer) |
287 | | - actor = picker.GetActor() |
288 | | - |
289 | | - for actor in actors: |
290 | | - actor.SetPickable(True) |
291 | | - for pipeline in pipelines_to_restore: |
292 | | - pipeline.actor.SetMapper(pipeline.mapper) |
293 | | - |
| 265 | + # Retrieve all actors under the clicked coordinates |
| 266 | + actors, flat_index = self.pick_actors_under_coordinate( |
| 267 | + params.ids, params.x, params.y, picker |
| 268 | + ) |
| 269 | + # Filter pipeline IDs whose actors are in the picked list |
294 | 270 | array_ids = [ |
295 | | - id for id in params.ids if self.get_vtk_pipeline(id).actor in actors |
| 271 | + data_id |
| 272 | + for data_id in params.ids |
| 273 | + if self.get_vtk_pipeline(data_id).actor in actors |
296 | 274 | ] |
297 | 275 | if not array_ids: |
298 | 276 | return {"array_ids": [], "viewer_id": None} |
299 | | - if array_ids and viewer_id != -1: |
| 277 | + viewer_id = flat_index if flat_index != -1 else None |
| 278 | + if viewer_id is not None: |
300 | 279 | pipeline = self.get_vtk_pipeline(array_ids[0]) |
301 | | - mapper = pipeline.mapper |
302 | | - if isinstance(mapper, vtkCompositePolyDataMapper): |
303 | | - attr = mapper.GetCompositeDataDisplayAttributes() |
304 | | - if attr and not attr.GetBlockVisibility( |
305 | | - pipeline.blockDataSets[viewer_id] |
306 | | - ): |
307 | | - array_ids, viewer_id = [], -1 |
| 280 | + dataset, geode_id = self.get_composite_block_info(pipeline, picker) |
308 | 281 | return { |
309 | 282 | "array_ids": array_ids, |
310 | | - "viewer_id": viewer_id if viewer_id != -1 else None, |
| 283 | + "viewer_id": viewer_id, |
311 | 284 | } |
312 | 285 |
|
313 | 286 | @exportRpc(viewer_prefix + viewer_schemas_dict["grid_scale"]["rpc"]) |
@@ -362,89 +335,27 @@ def setHighlight( |
362 | 335 | rpc_params, self.viewer_schemas_dict["highlight"], self.viewer_prefix |
363 | 336 | ) |
364 | 337 | params = schemas.Highlight.from_dict(rpc_params) |
365 | | - picker = vtkCellPicker(tolerance=0.005) |
366 | | - |
367 | | - pipelines_to_restore = [ |
368 | | - pipeline |
369 | | - for pipeline_id in params.ids |
370 | | - if (pipeline := self.get_vtk_pipeline(pipeline_id)).pick_mapper is not None |
371 | | - ] |
372 | | - for pipeline in pipelines_to_restore: |
373 | | - pick_mapper = pipeline.pick_mapper |
374 | | - if pick_mapper is not None: |
375 | | - pipeline.actor.SetMapper(pick_mapper) |
376 | | - try: |
377 | | - picker.Pick(params.x, params.y, 0, self.get_renderer()) |
378 | | - finally: |
379 | | - for pipeline in pipelines_to_restore: |
380 | | - pipeline.actor.SetMapper(pipeline.mapper) |
381 | | - |
| 338 | + # Clear previous highlights |
382 | 339 | self.clear_highlights(params.ids) |
383 | | - actor = picker.GetActor() |
384 | | - pipeline_id = next( |
385 | | - (id for id in params.ids if self.get_vtk_pipeline(id).actor == actor), None |
386 | | - ) |
387 | | - id_to_select = ( |
388 | | - picker.GetCellId() |
389 | | - if params.field_type == schemas.FieldType.CELL |
390 | | - else picker.GetPointId() |
| 340 | + picker = vtkCellPicker(tolerance=0.005) |
| 341 | + # Perform pick operation to identify clicked pipeline and primitive ID |
| 342 | + data_id, id_to_select = self.pick_cell_or_point( |
| 343 | + params.ids, params.x, params.y, params.field_type.value, picker |
391 | 344 | ) |
392 | | - |
393 | | - if not pipeline_id or id_to_select == -1: |
| 345 | + if not data_id or id_to_select == -1: |
394 | 346 | self.render(-1) |
395 | 347 | return {} |
396 | | - |
397 | | - pipeline = self.get_vtk_pipeline(pipeline_id) |
398 | | - dataset = None |
399 | | - geode_id = None |
400 | | - if isinstance(pipeline.mapper, vtkCompositePolyDataMapper): |
401 | | - flat_index = picker.GetFlatBlockIndex() |
402 | | - dataset = ( |
403 | | - pipeline.blockDataSets[flat_index] |
404 | | - if 0 <= flat_index < len(pipeline.blockDataSets) |
405 | | - else None |
406 | | - ) |
407 | | - if dataset: |
408 | | - attr = pipeline.mapper.GetCompositeDataDisplayAttributes() |
409 | | - if attr and not attr.GetBlockVisibility(dataset): |
410 | | - self.render(-1) |
411 | | - return {} |
412 | | - geode_id = ( |
413 | | - pipeline.blockGeodeIds[flat_index] |
414 | | - if 0 <= flat_index < len(pipeline.blockGeodeIds) |
415 | | - else None |
416 | | - ) |
417 | | - |
| 348 | + # Retrieve picked composite block information |
| 349 | + pipeline = self.get_vtk_pipeline(data_id) |
| 350 | + dataset, geode_id = self.get_composite_block_info(pipeline, picker) |
| 351 | + # Update highlight visibility and extract attributes from the picked element |
418 | 352 | self.update_highlight(pipeline, id_to_select, params.field_type.value, dataset) |
419 | 353 | self.render(-1) |
420 | | - |
421 | | - data_obj = dataset or pipeline.reader.GetOutputDataObject(0) |
422 | | - data_attributes = {} |
423 | | - if isinstance(data_obj, vtkDataSet): |
424 | | - field_data = ( |
425 | | - data_obj.GetCellData() |
426 | | - if params.field_type == schemas.FieldType.CELL |
427 | | - else data_obj.GetPointData() |
428 | | - ) |
429 | | - for array_index in range(field_data.GetNumberOfArrays()): |
430 | | - array = field_data.GetArray(array_index) |
431 | | - if array and array.GetName(): |
432 | | - num_comps = array.GetNumberOfComponents() |
433 | | - component_values = [ |
434 | | - array.GetComponent(id_to_select, component_index) |
435 | | - for component_index in range(num_comps) |
436 | | - ] |
437 | | - data_attributes[array.GetName()] = ( |
438 | | - component_values[0] if num_comps == 1 else component_values |
439 | | - ) |
440 | | - |
441 | | - if params.field_type == schemas.FieldType.POINT: |
442 | | - point_coordinates = data_obj.GetPoint(id_to_select) |
443 | | - if point_coordinates: |
444 | | - data_attributes["coordinates"] = list(point_coordinates) |
445 | | - |
| 354 | + data_attributes = self.extract_picked_attributes( |
| 355 | + pipeline, id_to_select, params.field_type.value, dataset |
| 356 | + ) |
446 | 357 | return { |
447 | | - "id": pipeline_id, |
| 358 | + "id": data_id, |
448 | 359 | "picked_id": id_to_select, |
449 | 360 | "field_type": params.field_type.value, |
450 | 361 | "geode_id": geode_id, |
|
0 commit comments