Translate the volume to origin #6016
-
First check
Commit to Help
Sample Code What is the problem, question, or error?Write a short description telling me what you are doing, what you expect to happen, and what is currently happening. import numpy as np
import pyvista as pv
from pyvista import examples
# Download a volumetric dataset
vol = examples.download_knee_full()
print(vol.center)
print(vol.origin)
vol = vol.translate(-np.array(vol.center).astype(np.float64))
cpos = [(-381.74, -46.02, 216.54), (74.8305, 89.2905, 100.0), (0.23, 0.072, 0.97)]
pl = pv.Plotter()
pl.add_volume(vol, cmap="bone", opacity="sigmoid")
pl.add_point_labels(vol.center, ['Center'], point_color='blue', point_size=20, text_color='black', font_size=20,)
pl.add_point_labels(vol.origin, ['Origin'], point_color='red', point_size=20, text_color='black', font_size=20,)
pl.camera_position = cpos
pl.show() DescriptionI want to translate the volume that moves the center to the origin using the code, but when I visualize the volume, it is still in the same position. I also tried to assign the return value of System Information--------------------------------------------------------------------------------
Date: Thu May 02 12:04:26 2024 SE Asia Standard Time
OS : Windows
CPU(s) : 12
Machine : AMD64
Architecture : 64bit
Environment : IPython
GPU Vendor : ATI Technologies Inc.
GPU Renderer : AMD Radeon(TM) Graphics
GPU Version : 4.5.14802 Core Profile Context 21.40.52 30.0.14052.5
MathText Support : False
Python 3.9.18 (main, Sep 11 2023, 14:09:26) [MSC v.1916 64 bit (AMD64)]
pyvista : 0.43.6
vtk : 9.3.0
numpy : 1.26.4
matplotlib : 3.8.2
scooby : 0.9.2
pooch : 1.8.1
pillow : 9.4.0
imageio : 2.34.1
IPython : 8.18.1
scipy : 1.11.4
nest_asyncio : 1.5.8
-------------------------------------------------------------------------------- ScreenshotsNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Sorry for the inconvenience, the translate method does not seem to work well with the ImageData class. We recommend updating the origin property as follows instead. vol.origin = vol.origin - np.array(vol.center) You can expect to get the results you request by executing the following code. import numpy as np
import pyvista as pv
from pyvista import examples
# Download a volumetric dataset
vol = examples.download_knee_full()
center = vol.center
origin = vol.origin
print(center)
print(origin)
# vol = vol.translate(-np.array(vol.center).astype(np.float64))
vol.origin = vol.origin - np.array(vol.center)
cpos = [(-381.74, -46.02, 216.54), (74.8305, 89.2905, 100.0), (0.23, 0.072, 0.97)]
pl = pv.Plotter()
pl.add_volume(vol, cmap="bone", opacity="sigmoid")
pl.add_point_labels(center, ['Center'], point_color='blue', point_size=20, text_color='black', font_size=20,)
pl.add_point_labels(origin, ['Origin'], point_color='red', point_size=20, text_color='black', font_size=20,)
pl.camera_position = cpos
pl.show() |
Beta Was this translation helpful? Give feedback.
Sorry for the inconvenience, the translate method does not seem to work well with the ImageData class. We recommend updating the origin property as follows instead.
You can expect to get the results you request by executing the following code.