[vtkusers] what's the difference between actor 's position and sphere 's center

Andrew Maclean andrew.amaclean at gmail.com
Wed Jun 6 18:52:51 EDT 2012


Hi Jochen,
  Why don't you add this to the wikiexamples (
http://www.vtk.org/Wiki/VTK/Examples)?
One small suggestion I would make is to use vtkSmartPointer throughout your
code.
e,g vtkSmartPointer<vtkSphereSource> sphere vtkSmartPointer<vtkSphereSource
>::New();
but not for
  vtkSphereSource *src = vtkSphereSource::SafeDownCast(algo);

In this way clean-up is automatically performed when the objects go out of
scope, so ->Delete();; is not needed.

I could then make a Python equivalent for the wikiexamples.

Regards
  ANdrew



> ---------- Forwarded message ----------
> From: "Jochen K." <jochen.kling at email.de>
> To: vtkusers at vtk.org
> Cc:
> Date: Wed, 6 Jun 2012 10:23:45 -0700 (PDT)
> Subject: Re: [vtkusers] what's the difference between actor 's position
> and sphere 's center ?
> Hi Yeonchool,
>
> here is a complete example of how ro retrieve the source object from
> vtkActor reversely (relevant code lines are in bold):
>
> //
> // This example demonstates how to access the source object reversely from
> the actor.
> //
> // all the standard vtk headers
> #include <vtkSphereSource.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkRenderWindow.h>
> #include <vtkCamera.h>
> #include <vtkActor.h>
> #include <vtkRenderer.h>
>
> // additional needed vtk header for this example
> #include <vtkAlgorithmOutput.h>
>
> #define
> PI 3.14159265
>
> int
> main() {
>   // source
>   vtkSphereSource *sphere = vtkSphereSource::New();
>   sphere->SetRadius( 1.0 );
>   // mapper
>   vtkPolyDataMapper *sphereMapper = vtkPolyDataMapper::New();
>   sphereMapper->SetInputConnection( sphere->GetOutputPort() );
>   // actor
>   vtkActor *sphereActor = vtkActor::New();
>   sphereActor->SetMapper( sphereMapper );
>   //renderer
>   vtkRenderer *ren1 = vtkRenderer::New();
>   ren1->SetBackground( 0.1, 0.2, 0.4 );
>   vtkRenderWindow *renWin = vtkRenderWindow::New();
>   renWin->AddRenderer( ren1 );
>   renWin->SetSize( 300, 300 );
>   // add actor to the renderer
>   ren1->AddActor( sphereActor );
>   //
>   // Now we retrieve the source object from vtkActor reversely, loop over
> 360 degrees,
>   // changes the radius of the spheresource and render the sphere each
> time.
>   //
>   *vtkAlgorithm *algo = sphereActor->GetMapper()->GetInputConnection(0,
> 0)->GetProducer();
>   vtkSphereSource *src = vtkSphereSource::SafeDownCast(algo);*
>
>   float origRadius = src->GetRadius();
>   int i;
>   for (i = 0; i < 360; ++i) {
>     src->SetRadius(origRadius * (1 + sin((float)i/180.0 * PI)));
>     renWin->Render();'
>   }
>   //
>   // Free up any objects we created. All instances in VTK are deleted by
>   // using the Delete() method.
>   //
>   sphere->Delete();
>   sphereMapper->Delete();
>   sphereActor->Delete();
>   ren1->Delete();
>   renWin->Delete();
>   // dont't do that, cause src is just a reference
>   // src->Delete();
>   return 0;
> }
>
> with best regards
> Jochen
> ------------------------------
> View this message in context: Re: what's the difference between actor 's
> position and sphere 's center ?<http://vtk.1045678.n5.nabble.com/what-s-the-difference-between-actor-s-position-and-sphere-s-center-tp5713553p5713622.html>
> Sent from the VTK - Users mailing list archive<http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html>at Nabble.com.
>
>
>
-- 
___________________________________________
Andrew J. P. Maclean

___________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120607/ba9cca5f/attachment.htm>


More information about the vtkusers mailing list