<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">2012/11/13 David Lonie <span dir="ltr">&lt;<a href="mailto:david.lonie@kitware.com" target="_blank">david.lonie@kitware.com</a>&gt;</span><br>
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Sorry for the noise -- message got sent too early last time...<br>
<div><br>
Hi list,<br>
<br>
I&#39;m writing a test for some new functionality that will generate<br>
several vtkImageData instances and render them at different positions.<br>
<br>
I&#39;m setting up a vtkImageSlice like this:<br>
<br>
vtkNew&lt;vtkImageData&gt; image1;<br>
</div>// Generate image...<br>
<div>vtkNew&lt;vtkImageSliceMapper&gt; mapper1;<br>
mapper1-&gt;SetInputData(image1.GetPointer());<br>
vtkNew&lt;vtkImageSlice&gt; actor1;<br>
actor1-&gt;SetMapper(mapper1.GetPointer());<br>
actor1-&gt;SetPosition(10, 10, 10);<br>
<br>
</div>then adding the actor to the renderer as usual. The docs for vtkImageSlice say:<br>
<br>
&quot;Prop3D methods such as SetPosition() and RotateWXYZ() change the<br>
position and orientation of the data with respect to VTK world<br>
coordinates.&quot;<br>
<br>
Trouble is, no matter what I set the position of the actor to, the<br>
image appears in the center of the scene. Is this expected behavior?<br>
Is there a better class to use for this sort of thing?<br>
<br>
Thanks,<br>
<br>
Dave</blockquote></div></div></div></blockquote><div><br></div><div>If you want to do it with the &quot;change the position of the actor&quot; technique, here is one way to make the view not update to always make the object look centered. I get the camera before adding the actor, add the actor (which changes the current camera, but not the one I deep copied previously), then set the camera to the one that was saved.</div>
<div><br></div><div>(I just saw your reply - that is easier haha, but this might be good to know about too :) ).</div><div><br></div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkSphereSource.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkCamera.h&gt;</span></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkPolyData.h&gt;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkSmartPointer.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkPolyDataMapper.h&gt;</span></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkActor.h&gt;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkRenderWindow.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkRenderer.h&gt;</span></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(0,0,128)">#include</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,128,0)">&lt;vtkRenderWindowInteractor.h&gt;</span></pre><pre style="margin-top:0px;margin-bottom:0px"><br>
</pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(128,128,0)">int</span><span style="color:rgb(192,192,192)"> </span>main(<span style="color:rgb(128,128,0)">int</span>,<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,128,0)">char</span><span style="color:rgb(192,192,192)"> </span>*[])</pre>
<pre style="margin-top:0px;margin-bottom:0px">{</pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(0,128,0)">// Create a sphere</span></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkSphereSource</span>&gt;<span style="color:rgb(192,192,192)"> </span>sphereSource<span style="color:rgb(192,192,192)"> </span>=</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkSphereSource</span>&gt;::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>sphereSource-&gt;<span style="font-style:italic">SetCenter</span>(<span style="color:rgb(0,0,128)">0</span>,<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span>,<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(0,128,0)">//  sphereSource-&gt;SetCenter(0, -0.1, 0);</span></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>sphereSource-&gt;SetCenter(<span style="color:rgb(0,0,128)">0.1</span>,<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0.1</span>,<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">0</span>);</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>sphereSource-&gt;SetRadius(<span style="color:rgb(0,0,128)">0.1</span>);</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkPolyDataMapper</span>&gt;<span style="color:rgb(192,192,192)"> </span>mapper<span style="color:rgb(192,192,192)"> </span>=</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkPolyDataMapper</span>&gt;::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>mapper-&gt;SetInputConnection(sphereSource-&gt;GetOutputPort());</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkActor</span>&gt;<span style="color:rgb(192,192,192)"> </span>actor<span style="color:rgb(192,192,192)"> </span>=</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkActor</span>&gt;::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>actor-&gt;SetMapper(mapper);</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkRenderer</span>&gt;<span style="color:rgb(192,192,192)"> </span>renderer<span style="color:rgb(192,192,192)"> </span>=</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkRenderer</span>&gt;::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkRenderWindow</span>&gt;<span style="color:rgb(192,192,192)"> </span>renderWindow<span style="color:rgb(192,192,192)"> </span>=</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkRenderWindow</span>&gt;::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>renderWindow-&gt;AddRenderer(renderer);</pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkRenderWindowInteractor</span>&gt;<span style="color:rgb(192,192,192)"> </span>renderWindowInteractor<span style="color:rgb(192,192,192)"> </span>=</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">    </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkRenderWindowInteractor</span>&gt;::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>renderWindowInteractor-&gt;SetRenderWindow(renderWindow);</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkCamera</span>&gt;<span style="color:rgb(192,192,192)"> </span>camera<span style="color:rgb(192,192,192)"> </span>=<span style="color:rgb(192,192,192)"> </span><span style="color:rgb(128,0,128)">vtkSmartPointer</span>&lt;<span style="color:rgb(128,0,128)">vtkCamera</span>&gt;::New();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>camera-&gt;DeepCopy(renderer-&gt;GetActiveCamera());</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px">
<span style="color:rgb(192,192,192)">  </span>renderer-&gt;AddActor(actor);</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>renderer-&gt;SetActiveCamera(camera);</pre>
<pre style="margin-top:0px;margin-bottom:0px"><br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span>renderWindowInteractor-&gt;Start();</pre><pre style="margin-top:0px;margin-bottom:0px">
<br></pre><pre style="margin-top:0px;margin-bottom:0px"><span style="color:rgb(192,192,192)">  </span><span style="color:rgb(128,128,0)">return</span><span style="color:rgb(192,192,192)"> </span><span style="color:rgb(0,0,128)">EXIT_SUCCESS</span>;</pre>
<pre style="margin-top:0px;margin-bottom:0px">}</pre><pre style="margin-top:0px;margin-bottom:0px"><br></pre><br>David<br><div> </div></div>