ansys-pyensight-core 0.10.8__py3-none-any.whl → 0.10.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ansys-pyensight-core might be problematic. Click here for more details.

@@ -94,8 +94,7 @@ class _Simba:
94
94
  self.views.set_view_direction(
95
95
  1, 1, 1, perspective=self.ensight.objs.core.vports[0].PERSPECTIVE
96
96
  )
97
- self.auto_scale()
98
- return self.get_camera()
97
+ return self.auto_scale()
99
98
 
100
99
  def get_camera(self):
101
100
  """Get EnSight camera settings in VTK format."""
@@ -208,8 +207,49 @@ class _Simba:
208
207
  parallel_scale = 1 / data[9]
209
208
  return camera_position, focal_point, self.views._normalize_vector(view_up), parallel_scale
210
209
 
210
+ def get_camera_axes(self):
211
+ """
212
+ Returns the camera's local axes: right, up, and forward vectors.
213
+ These are useful for applying transformations in view space.
214
+
215
+ Parameters:
216
+ camera (dict): A dictionary with keys 'position', 'focal_point', and 'view_up'.
217
+
218
+ Returns:
219
+ right (np.ndarray): Right vector (X axis in view space).
220
+ up (np.ndarray): Up vector (Y axis in view space).
221
+ forw ard (np.ndarray): Forward vector (Z axis in view space, pointing from position to focal point).
222
+ """
223
+ camera = self.get_camera()
224
+ position = np.array(camera["position"])
225
+ focal_point = np.array(camera["focal_point"])
226
+ view_up = np.array(camera["view_up"])
227
+
228
+ # Forward vector: from camera position to focal point
229
+ forward = focal_point - position
230
+ forward /= np.linalg.norm(forward)
231
+
232
+ # Right vector: cross product of forward and view_up
233
+ right = np.cross(forward, view_up)
234
+ right /= np.linalg.norm(right)
235
+
236
+ # Recompute up vector to ensure orthogonality
237
+ up = np.cross(right, forward)
238
+ up /= np.linalg.norm(up)
239
+
240
+ return right, up, forward
241
+
211
242
  def set_camera(
212
- self, orthographic, view_up=None, position=None, focal_point=None, view_angle=None
243
+ self,
244
+ orthographic,
245
+ view_up=None,
246
+ position=None,
247
+ focal_point=None,
248
+ view_angle=None,
249
+ pan=None,
250
+ mousex=None,
251
+ mousey=None,
252
+ invert_y=False,
213
253
  ):
214
254
  """Set the EnSight camera settings from the VTK input."""
215
255
  self.ensight.view_transf.function("global")
@@ -219,17 +259,29 @@ class _Simba:
219
259
  vport = self.ensight.objs.core.VPORTS[0]
220
260
  if view_angle:
221
261
  vport.PERSPECTIVEANGLE = view_angle / 2
222
-
223
262
  if view_up and position and focal_point:
224
- q_current = self.normalize(np.array(vport.ROTATION.copy()))
225
- q_target = self.normalize(
226
- self.compute_model_rotation_quaternion(position, focal_point, view_up)
227
- )
228
- q_relative = self.quaternion_multiply(
229
- q_target, np.array([-q_current[0], -q_current[1], -q_current[2], q_current[3]])
230
- )
231
- angles = self.quaternion_to_euler(q_relative)
232
- self.ensight.view_transf.rotate(*angles)
263
+ if not pan:
264
+ q_current = self.normalize(np.array(vport.ROTATION.copy()))
265
+ q_target = self.normalize(
266
+ self.compute_model_rotation_quaternion(position, focal_point, view_up)
267
+ )
268
+ q_relative = self.quaternion_multiply(
269
+ q_target, np.array([-q_current[0], -q_current[1], -q_current[2], q_current[3]])
270
+ )
271
+ angles = self.quaternion_to_euler(q_relative)
272
+ self.ensight.view_transf.rotate(*angles)
273
+ else:
274
+ if mousex and mousey:
275
+ self.screen_to_world(
276
+ mousex=mousex, mousey=mousey, invert_y=invert_y, set_center=True
277
+ )
278
+ current_camera = self.get_camera()
279
+ right, up, _ = self.get_camera_axes()
280
+ translation_vector = np.array(position) - np.array(current_camera["position"])
281
+ dx = np.dot(translation_vector, right)
282
+ dy = np.dot(translation_vector, up)
283
+ self.ensight.view_transf.translate(-dx, -dy, 0)
284
+
233
285
  self.render()
234
286
 
235
287
  def set_perspective(self, value):
@@ -257,9 +309,85 @@ class _Simba:
257
309
  return {"model_point": model_point, "camera": self.get_camera()}
258
310
 
259
311
  def render(self):
312
+ """Force render update in EnSight."""
313
+ self.ensight.view_transf.zoom(1)
260
314
  self.ensight.render()
261
315
  self.ensight.refresh(1)
262
316
 
317
+ def _probe_setup(self, part_obj, get_probe_data=False):
318
+ self.ensight.query_interact.number_displayed(100)
319
+ self.ensight.query_interact.query("surface")
320
+ self.ensight.query_interact.display_id("OFF")
321
+ self.ensight.query_interact.label_always_on_top("ON")
322
+ self.ensight.query_interact.marker_size_normalized(2)
323
+ if get_probe_data:
324
+ variable_string = """Coordinates 'X' 'Y' 'Z'"""
325
+ variable_list = [variable_string]
326
+ variable_name = part_obj.COLORBYPALETTE
327
+ if variable_name:
328
+ if isinstance(variable_name, str):
329
+ variable_list.append(variable_name)
330
+ else:
331
+ if isinstance(variable_name, list):
332
+ if variable_name[0]:
333
+ variable_name = variable_name[0].DESCRIPTION
334
+ variable_list.append(variable_name)
335
+ else:
336
+ variable_name = None
337
+ if isinstance(self.ensight, ModuleType):
338
+ self.ensight.query_interact.select_varname_begin(*variable_list)
339
+ else:
340
+ command = "ensight.query_interact.select_varname_begin("
341
+ for var in variable_list:
342
+ command += var + ","
343
+ command = command[:-1] + ")"
344
+ self.ensight._session.cmd(command)
345
+ self.render()
346
+
347
+ def drag_allowed(self, mousex, mousey, invert_y=False, probe=False, get_probe_data=False):
348
+ """Return True if the picked object is allowed dragging in the interactor."""
349
+ mousex = int(mousex)
350
+ mousey = int(mousey)
351
+ if isinstance(self.ensight, ModuleType):
352
+ part_id, tool_id = self.ensight.objs.core.VPORTS[0].simba_what_is_picked(
353
+ mousex, mousey, invert_y
354
+ )
355
+ else:
356
+ part_id, tool_id = self.ensight._session.cmd(
357
+ f"ensight.objs.core.VPORTS[0].simba_what_is_picked({mousex}, {mousey}, {invert_y})"
358
+ )
359
+ coords = [None, None, None]
360
+ if probe:
361
+ screen_to_world = self.screen_to_world(
362
+ mousex=mousex, mousey=mousey, invert_y=invert_y, set_center=False
363
+ )
364
+ coords = screen_to_world["model_point"]
365
+ if tool_id > -1:
366
+ return True, coords[0], coords[1], coords[2], False
367
+ part_types_allowed = [
368
+ self.ensight.objs.enums.PART_CLIP_PLANE,
369
+ self.ensight.objs.enums.PART_ISO_SURFACE,
370
+ self.ensight.objs.enums.PART_CONTOUR,
371
+ ]
372
+ if part_id > -1:
373
+ part_obj = self.ensight.objs.core.PARTS.find(part_id, "PARTNUMBER")[0]
374
+ if probe:
375
+ width, height = tuple(self.ensight.objs.core.WINDOWSIZE)
376
+ if invert_y:
377
+ mousey = height - mousey
378
+ self.ensight.query_interact.number_displayed(100)
379
+ self.ensight.query_interact.query("surface")
380
+ self.ensight.query_interact.display_id("OFF")
381
+ self.ensight.query_interact.create(mousex / width, mousey / height)
382
+ self._probe_setup(part_obj, get_probe_data=get_probe_data)
383
+ return part_obj.PARTTYPE in part_types_allowed, coords[0], coords[1], coords[2], True
384
+ if (
385
+ get_probe_data and self.ensight.objs.core.PROBES[0].PROBE_DATA
386
+ ): # In case we have picked a probe point
387
+ for part in self.ensight.objs.core.PARTS:
388
+ self._probe_setup(part, get_probe_data=get_probe_data)
389
+ return False, coords[0], coords[1], coords[2], False
390
+
263
391
 
264
392
  class Views:
265
393
  """Controls the view in the current EnSight ``Session`` instance."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ansys-pyensight-core
3
- Version: 0.10.8
3
+ Version: 0.10.10
4
4
  Summary: A python wrapper for Ansys EnSight
5
5
  Author-email: "ANSYS, Inc." <pyansys.core@ansys.com>
6
6
  Maintainer-email: "ANSYS, Inc." <pyansys.core@ansys.com>
@@ -29,9 +29,9 @@ ansys/pyensight/core/utils/query.py,sha256=OXKDbf1sOTX0sUvtKcp64LhVl-BcrEsE43w8u
29
29
  ansys/pyensight/core/utils/readers.py,sha256=_IluAWz8mmoe5SM3hAewHIqlhtKMfEqrUJoQOlJ4U4I,12138
30
30
  ansys/pyensight/core/utils/support.py,sha256=QI3z9ex7zJxjFbkCPba9DWqWgPFIThORqr0nvRfVjuc,4089
31
31
  ansys/pyensight/core/utils/variables.py,sha256=ZUiJdDIeRcowrnLXaJQqGwA0RbrfXhc1s4o4v9A4PiY,95133
32
- ansys/pyensight/core/utils/views.py,sha256=FDBZsk_sXV5mRkOcrMsGfYgH3EhsYizByasEm_yHDbs,21597
32
+ ansys/pyensight/core/utils/views.py,sha256=16HhsxhrwjH_vRtyN96S5rItCfb8ACdVIQkBuEGgPh8,27273
33
33
  ansys/pyensight/core/utils/resources/Materials/000_sky.exr,sha256=xAR1gFd2uxPZDnvgfegdhEhRaqKtZldQDiR_-1rHKO0,8819933
34
- ansys_pyensight_core-0.10.8.dist-info/licenses/LICENSE,sha256=K6LiJHOa9IbWFelXmXNRzFr3zG45SOGZIN7vdLdURGU,1097
35
- ansys_pyensight_core-0.10.8.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
36
- ansys_pyensight_core-0.10.8.dist-info/METADATA,sha256=De1e_99-YQMsdWK_MJqoHjvr3yveUiG4lzUWPR5YIK8,12228
37
- ansys_pyensight_core-0.10.8.dist-info/RECORD,,
34
+ ansys_pyensight_core-0.10.10.dist-info/licenses/LICENSE,sha256=K6LiJHOa9IbWFelXmXNRzFr3zG45SOGZIN7vdLdURGU,1097
35
+ ansys_pyensight_core-0.10.10.dist-info/WHEEL,sha256=G2gURzTEtmeR8nrdXUJfNiB3VYVxigPQ-bEQujpNiNs,82
36
+ ansys_pyensight_core-0.10.10.dist-info/METADATA,sha256=j2qVkHFkgjFLJbBjOz82BXIEuaVmP-lB_UQC8T5bhxQ,12229
37
+ ansys_pyensight_core-0.10.10.dist-info/RECORD,,