<div class="gmail_quote"><div>Hi Jochen,</div><div> Why don't you add this to the wikiexamples (<a href="http://www.vtk.org/Wiki/VTK/Examples">http://www.vtk.org/Wiki/VTK/Examples</a>)?</div><div>One small suggestion I would make is to use vtkSmartPointer throughout your code.</div>
<div>e,g vtkSmartPointer<<span style="font-family:Consolas">vtkSphereSource</span>> <span style="font-family:Consolas">sphere</span><span style="font-family:Consolas"> </span>vtkSmartPointer<<span style="font-family:Consolas">vtkSphereSource</span>>::New();</div>
<div>but not for </div><div> vtkSphereSource *src = vtkSphereSource::SafeDownCast(algo);</div><div><br></div><div>In this way clean-up is automatically performed when the objects go out of scope, so ->Delete();; is not needed.</div>
<div><br></div><div>I could then make a Python equivalent for the wikiexamples.</div><div><br></div><div>Regards</div><div> ANdrew</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---------- Forwarded message ----------<br>From: "Jochen K." <<a href="mailto:jochen.kling@email.de" target="_blank">jochen.kling@email.de</a>><br>To: <a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a><br>
Cc: <br>Date: Wed, 6 Jun 2012 10:23:45 -0700 (PDT)<br>
Subject: Re: [vtkusers] what's the difference between actor 's position and sphere 's center ?<br>Hi Yeonchool,<br><br>
here is a complete example of how ro retrieve the source object from vtkActor reversely (relevant code lines are in bold):<br>
<font face="Consolas" color="#008000">
<p>//<br>
// This example demonstates how to access the source object reversely from the
actor.<br>
//<br>
// all the standard vtk headers<br>
</p></font><font face="Consolas" color="#0000ff">#include</font><font face="Consolas">
</font><font face="Consolas" color="#a31515"><vtkSphereSource.h><br>
</font><font face="Consolas" color="#0000ff">#include</font><font face="Consolas">
</font><font face="Consolas" color="#a31515"><vtkPolyDataMapper.h><br>
</font><font face="Consolas" color="#0000ff">#include</font><font face="Consolas">
</font><font face="Consolas" color="#a31515"><vtkRenderWindow.h><br>
</font><font face="Consolas" color="#0000ff">#include</font><font face="Consolas">
</font><font face="Consolas" color="#a31515"><vtkCamera.h><br>
</font><font face="Consolas" color="#0000ff">#include</font><font face="Consolas">
</font><font face="Consolas" color="#a31515"><vtkActor.h><br>
</font><font face="Consolas" color="#0000ff">#include</font><font face="Consolas">
</font><font face="Consolas" color="#a31515"><vtkRenderer.h>
</font><font face="Consolas"></font>
<font face="Consolas" color="#008000">
<p>// additional needed vtk header for this example<br>
</p></font><font face="Consolas" color="#0000ff">#include</font><font face="Consolas">
</font><font face="Consolas" color="#a31515"><vtkAlgorithmOutput.h>
</font><font face="Consolas"></font>
<font face="Consolas" color="#0000ff">
<p>#define</p></font><font face="Consolas"> PI 3.14159265
</font><font face="Consolas" color="#0000ff">
<p>int</p></font><font face="Consolas"> main() {<br>
</font><font face="Consolas" color="#008000"> // source<br>
</font><font face="Consolas"> vtkSphereSource *sphere =
vtkSphereSource::New();<br>
sphere->SetRadius( 1.0 );<br>
</font><font face="Consolas" color="#008000"> // mapper<br>
</font><font face="Consolas">vtkPolyDataMapper *sphereMapper =
vtkPolyDataMapper::New();<br>
sphereMapper->SetInputConnection( sphere->GetOutputPort() );<br>
</font><font face="Consolas" color="#008000">// actor<br>
</font><font face="Consolas">vtkActor *sphereActor =
vtkActor::New();<br>
sphereActor->SetMapper( sphereMapper );<br>
</font><font face="Consolas" color="#008000">//renderer<br>
</font><font face="Consolas">vtkRenderer *ren1 =
vtkRenderer::New();<br>
ren1->SetBackground( 0.1, 0.2, 0.4 );<br>
vtkRenderWindow *renWin = vtkRenderWindow::New();<br>
renWin->AddRenderer( ren1 );<br>
renWin->SetSize( 300, 300 );<br>
</font><font face="Consolas" color="#008000">// add actor to the
renderer<br>
</font><font face="Consolas">ren1->AddActor( sphereActor );<br>
</font><font face="Consolas" color="#008000">//<br>
// Now we retrieve the source object from vtkActor reversely, loop over
360 degrees, <br>
// changes the radius of the spheresource and render the sphere each
time.<br>
//<br>
</font><b><font face="Consolas">vtkAlgorithm *algo =
sphereActor->GetMapper()->GetInputConnection(0, 0)->GetProducer();<br>
vtkSphereSource *src = vtkSphereSource::SafeDownCast(algo);</font></b><br><br>
<font face="Consolas" color="#0000ff"> float</font><font face="Consolas">
origRadius = src->GetRadius();<br>
</font><font face="Consolas" color="#0000ff"> int</font><font face="Consolas">
i;<br>
</font><font face="Consolas" color="#0000ff"> for</font><font face="Consolas">
(i = 0; i < 360; ++i) {<br>
src->SetRadius(origRadius * (1 + sin((</font><font face="Consolas" color="#0000ff">float</font><font face="Consolas">)i/180.0
* PI)));<br>
renWin->Render();'<br>
}<br>
</font><font face="Consolas" color="#008000">//<br>
// Free up any objects we created. All instances in VTK are deleted by<br>
// using the Delete() method.<br>
//<br>
</font><font face="Consolas">sphere->Delete();<br>
sphereMapper->Delete();<br>
sphereActor->Delete();<br>
ren1->Delete();<br>
renWin->Delete();<br>
</font><font face="Consolas" color="#008000"> // dont't do that,
cause src is just a reference<br>
// src->Delete();<br>
</font><font face="Consolas" color="#0000ff"> return</font><font face="Consolas">
0;<br>
}
</font>
<br><br>
with best regards<br>
Jochen
        
<br><hr align="left" width="300">
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/what-s-the-difference-between-actor-s-position-and-sphere-s-center-tp5713553p5713622.html" target="_blank">Re: what's the difference between actor 's position and sphere 's center ?</a><br>
Sent from the <a href="http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html" target="_blank">VTK - Users mailing list archive</a> at Nabble.com.<br><br><br></blockquote></div><div><br></div>-- <br>___________________________________________<br>
Andrew J. P. Maclean<br><br>___________________________________________<br>