<div dir="ltr"><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large">Hello. </div><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large"><br></div><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large">I am trying to record a video of VTK 3D animation in Python. The <a href="http://www.itk.org/Wiki/VTK/Examples/Cxx/Video/FFMPEG">example I found </a> is a bit strange for me, because it does not create a render, so it is not clear how to attach actors to canvas. </div><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large"><br></div><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large">I write a simplified example:</div><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large"><pre style="font-family:Consolas,'DejaVu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:13px;letter-spacing:0.015em;line-height:15.6000003814697px;padding:0.5em;border:1px solid rgb(204,204,204);border-radius:2px;color:rgb(0,0,0);background:rgb(240,240,240)"><span class="" style="color:rgb(0,112,32)">import</span> <span class="" style="color:rgb(14,132,181);font-weight:bold">vtk</span>

<span class="" style="color:rgb(96,160,176);font-style:italic"># draw a plane</span>
<span class="">plane_source</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">vtk</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">vtkPlaneSource</span><span class="">()</span>
<span class="">plane_source</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">SetCenter</span><span class="">(</span><span class="" style="color:rgb(64,160,112)">0</span><span class="">,</span> <span class="" style="color:rgb(64,160,112)">0</span><span class="">,</span> <span class="" style="color:rgb(64,160,112)">0</span><span class="">)</span>
<span class="">plane_source</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">SetNormal</span><span class="">(</span><span class="" style="color:rgb(64,160,112)">0</span><span class="">,</span> <span class="" style="color:rgb(64,160,112)">0</span><span class="">,</span> <span class="" style="color:rgb(64,160,112)">1</span><span class="">)</span>
<span class="">plane_mapper</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">vtk</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">vtkPolyDataMapper</span><span class="">()</span>
<span class="">plane_mapper</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">SetInput</span><span class="">(</span><span class="">plane_source</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">GetOutput</span><span class="">())</span>
<span class="">plane_actor</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">vtk</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">vtkActor</span><span class="">()</span>
<span class="">plane_actor</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">SetMapper</span><span class="">(</span><span class="">plane_mapper</span><span class="">)</span>

<span class="" style="color:rgb(96,160,176);font-style:italic"># create render</span>
<span class="">render</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">vtk</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">vtkRenderer</span><span class="">()</span>
<span class="">renWin</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">vtk</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">vtkRenderWindow</span><span class="">()</span>
<span class="">renWin</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">AddRenderer</span><span class="">(</span><span class="">render</span><span class="">)</span>
<span class="">renWin</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">SetSize</span><span class="">(</span><span class="" style="color:rgb(64,160,112)">800</span><span class="">,</span> <span class="" style="color:rgb(64,160,112)">600</span><span class="">)</span>
<span class="">renInter</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">vtk</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">vtkRenderWindowInteractor</span><span class="">()</span>
<span class="">renInter</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">SetRenderWindow</span><span class="">(</span><span class="">renWin</span><span class="">)</span>
<span class="">render</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">AddActor</span><span class="">(</span><span class="">plane_actor</span><span class="">)</span>
<span class="">renWin</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">Render</span><span class="">()</span>
<span class="">renInter</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">Initialize</span><span class="">()</span>

<span class="" style="color:rgb(96,160,176);font-style:italic"># set callback</span>
<span class="" style="color:rgb(0,112,32);font-weight:bold">def</span> <span class="" style="color:rgb(6,40,126)">cb</span><span class="">(</span><span class="">interactor</span><span class="">,</span> <span class="">event</span><span class="">):</span>
    <span class="" style="color:rgb(0,112,32);font-weight:bold">global</span> <span class="">plane_actor</span>
    <span class="">plane_actor</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">RotateZ</span><span class="">(</span><span class="" style="color:rgb(64,160,112)">0.1</span><span class="">)</span>
    <span class="">interactor</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">GetRenderWindow</span><span class="">()</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">Render</span><span class="">()</span>

<span class="">renInter</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">AddObserver</span><span class="">(</span><span class="" style="color:rgb(64,112,160)">'TimerEvent'</span><span class="">,</span> <span class="">cb</span><span class="">)</span>
<span class="">timerId</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">renInter</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">CreateRepeatingTimer</span><span class="">(</span><span class="" style="color:rgb(64,160,112)">100</span><span class="">);</span>

<span class="" style="color:rgb(96,160,176);font-style:italic"># put something here?</span>
<span class="">writer</span> <span class="" style="color:rgb(102,102,102)">=</span> <span class="">vtk</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">vtkFFMPEGWriter</span><span class="">()</span>
<span class="" style="color:rgb(96,160,176);font-style:italic"># ??? writer.SetInputConnection(...)</span>
<span class="">writer</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">SetFileName</span><span class="">(</span><span class="" style="color:rgb(64,112,160)">"test.avi"</span><span class="">)</span>
<span class="">writer</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">Start</span><span class="">()</span>

<span class="" style="color:rgb(96,160,176);font-style:italic"># run</span>
<span class="">renInter</span><span class="" style="color:rgb(102,102,102)">.</span><span class="">Start</span><span class="">()</span></pre></div><div><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large">My question is <i>how to connect <b>vtkRenderer </b>to <b>vtkFFMPEGWriter</b></i>? <br></div></div><div class="gmail_default" style="font-family:'courier new',monospace;font-size:large"><br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><i>Best regards, </i><div><i>Maksim Surov</i></div></div></div>
</div>