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

Jochen K. jochen.kling at email.de
Wed Jun 6 13:23:45 EDT 2012


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: 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 at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120606/387a766c/attachment.htm>


More information about the vtkusers mailing list