<div dir="ltr">Hi Andreas,<div><br></div><div>My comments about vtkImageActor might not be the full solution, but I can guarantee that they are part of the solution.</div><div><br></div><div>If the objects cannot be displayed together, it is probably because they are either too far apart in world coordinates, or perhaps the image actor is simply obscuring (in front of) the spine actor. To help with debugging the coordinates, you can print the bounding box for the image data and for the poly data to make sure they are in roughly the same location. Use the data's GetBounds() method to do this. Note that the actors also have a GetBounds method, which returns the bounding box after the actor transformations have taken place.</div><div><br></div><div> David</div><div><br></div><div><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Nov 18, 2018 at 1:26 PM Andreas Pedroni <<a href="mailto:anpedroni@gmail.com">anpedroni@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Dear David </div><div><br></div><div>Thank you very much for your answer. I tried your suggestions but unfortunately I did not lead to a solution to my problem.</div><div>It seems that only the ren.AddActor(plane_actor) has an effect on the rendered image. The ren.AddActor(spine_actor) is not shown. But when I comment out ren.AddActor(plane_actor) the spine_actor is shown.</div><div>It is also only a problem if I use a <span>vtk.vtkImageActor(), which I have chosen as it is supposed to be more efficient(?) than doing it with a </span><span>vtk.vtkPlaneSource().</span></div><div><span><br></span></div><div>Thanks again for helping!</div><div>Cheers</div><div>Andreas</div><span><br></span><span><br></span><span></span><span><br></span><div><blockquote type="cite"><div>Am 18.11.2018 um 14:52 schrieb David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>>:</div><br class="m_-1009785283575188647Apple-interchange-newline"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Hi Andreas,<div><br></div><div>Thanks for sending the code along with your question. The method you want is AddViewProp(), but it's just a new name for AddActor() and it actually has the same behavior.</div><div><br></div><div>For the image actor, you probably want code like the following.</div><div><div> vtk_image = vtk.vtkImageData()</div><div> vtk_image.SetDimensions(720, 1280, 1)</div><div> vtk_image.SetSpacing(1.0, 1.0, 1.0)</div><div> vtk_image.SetOrigin(-(720 - 1)/2.0, -(1280 - 1)/2.0, 0.0)</div><div><br></div><div>The "Spacing" is the size of each pixel, and the "Origin" is the position of the first pixel in the image (in this case, I set it so that the center of the image will be at (0,0,0), I'm not sure if this is what you want but it is a good place to start).</div><div><br></div><div>After creating the image data, it is a good idea to add an assert to ensure the array is the correct size:</div><div> assert vtk_image.GetNumberOfPoints() == vtk_array.GetNumberOfTuples()</div><div><br></div><div>For the following code, I'm not sure what you are trying to do, but the effect will be to vertically squash the frame so that it is square:</div><div> plane_actor.SetScale(1, 0.5625, 1)<br></div><div><br></div><div>I hope this helps,</div><div> David</div><div><br></div><div class="gmail_quote"><div dir="ltr">On Sun, Nov 18, 2018 at 4:43 AM Andreas Pedroni <<a href="mailto:anpedroni@gmail.com" target="_blank">anpedroni@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Dear list<br>
<br>
I would like to display a 3D object in front of a vtkImageActor (using Python 3.6 and vtk on Mac OS, see code below). However, the vtkImageActor erases the 3D object. I read in the manual that one should use AddProp() with the renderer to add a vtkImageActor to a render scene. But there is no AddProp() method for the renderer class. I’d be very thankful for any suggestions. <br>
<br>
Best <br>
Andreas <br>
<br>
<br>
import vtk<br>
import cv2<br>
from vtk.util import numpy_support<br>
<br>
IMAGEPATH = ‚/models3d/'<br>
VIDEOPATH = "20180816-133303.mp4“<br>
<br>
def main():<br>
cap = cv2.VideoCapture(VIDEOPATH)<br>
success, frame = cap.read()<br>
<br>
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)<br>
vtk_array = numpy_support.numpy_to_vtk(frame.reshape((-1, 3), order='F'), deep=False)<br>
<br>
# Create a vtkImage Object. This is filled with the vtkArray data later<br>
vtk_image = vtk.vtkImageData()<br>
vtk_image.SetDimensions(720, 1280, 1)<br>
vtk_image.SetSpacing(720, 1280, 1)<br>
vtk_image.SetOrigin(720, 1280, 0)<br>
vtk_image.GetPointData().SetScalars(vtk_array)<br>
# create the Texture for a plane<br>
<br>
# The Screen where the movie is mapped onto<br>
plane = vtk.vtkPlaneSource()<br>
<br>
plane_mapper = vtk.vtkPolyDataMapper()<br>
plane_mapper.SetInputConnection(plane.GetOutputPort())<br>
<br>
plane_actor = vtk.vtkImageActor()<br>
plane_actor.SetInputData(vtk_image)<br>
plane_actor.SetScale(1, 0.5625, 1)<br>
plane_actor.SetOrientation(180, 180, 90)<br>
<br>
# add the spine object<br>
obj_importer = vtk.vtkOBJReader()<br>
obj_importer.SetFileName(IMAGEPATH + 'Spine.obj')<br>
obj_importer.Update()<br>
<br>
spine_mapper = vtk.vtkPolyDataMapper()<br>
spine_mapper.SetInputConnection(obj_importer.GetOutputPort())<br>
<br>
spine_actor = vtk.vtkActor()<br>
spine_actor.SetMapper(spine_mapper)<br>
spine_actor.SetOrientation(90, 10, 90)<br>
spine_actor.SetScale(0.3, 0.3, 0.3)<br>
<br>
# set up the renderer and the window<br>
ren = vtk.vtkRenderer()<br>
ren_win = vtk.vtkRenderWindow()<br>
ren_win.AddRenderer(ren)<br>
ren_win.SetSize(1500, 1500)<br>
<br>
ren.AddActor(spine_actor)<br>
ren.AddActor(plane_actor)<br>
<br>
ren.SetBackground(0, 0, 0.1)<br>
<br>
iren = vtk.vtkRenderWindowInteractor()<br>
iren.SetRenderWindow(ren_win)<br>
<br>
# Initialize must be called prior to creating timer events.<br>
iren.Initialize()<br>
<br>
# start the interaction and timer<br>
iren.Start()<br>
<br>
if __name__ == '__main__':<br>
main()<br>
</blockquote></div></div></div></div></div>
</div></blockquote></div><br></div></blockquote></div></div></div>