[vtkusers] Why doesn't the intersection of the lines of a vtkCursor2D not set at the focal point?
David Doria
daviddoria+vtk at gmail.com
Fri Apr 9 08:42:09 EDT 2010
On Thu, Apr 8, 2010 at 9:52 PM, Xiaofeng Z <xf10036 at hotmail.com> wrote:
> Hi vtkUsers,
>
> The following is a program that place a vtkSphere and a vtkCursor2D in a
> rendering window. My question is why the cursor 2d does not pass the center
> of the sphere, see attached image.
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> // create sphere geometry
> vtkSphereSource *sphere = vtkSphereSource::New();
> sphere->SetCenter(0.0, 0.0, 0.0);
> sphere->SetRadius(1.0);
> sphere->SetThetaResolution(18);
> sphere->SetPhiResolution(18);
>
> // map to graphics library
> vtkPolyDataMapper *map = vtkPolyDataMapper::New();
> map->SetInput(sphere->GetOutput());
>
> // actor coordinates geometry, properties, transformation
> vtkActor *actor = vtkActor::New();
> actor->SetMapper(map);
> actor->GetProperty()->SetColor(0,0,1); // sphere color blue
>
> // renderers and render window
> vtkRenderer *renA = vtkRenderer::New();
> renA->SetViewport(0.0, 0.0, 1.0, 1.0);
> vtkRenderWindow* win = vtkRenderWindow::New();
> win->SetSize(300,300);
> win->AddRenderer(renA);
>
> // an interactor
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(win);
>
> renA->SetBackground(1,1,1); // Background color white
>
> renA->AddActor(actor);
>
> // add a 2D cursor to each Renderer
> vtkCursor2D* cursor = vtkCursor2D::New();
> cursor->SetTranslationMode(1);
> cursor->SetWrap(1);
> cursor->SetModelBounds(-0.5, 0.5, -0.5, 0.5, 0.0, 0.0);
> cursor->SetFocalPoint(0.0, 0.0, 0.0);
> cursor->AllOff();
> cursor->AxesOn();
>
> vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
> mapper->SetInput(cursor->GetOutput());
> actor = vtkActor::New();
> actor->SetMapper(mapper);
> actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
>
> renA->AddActor(actor);
>
> // render an image (lights and cameras are created automatically)
> win->Render();
>
> iren->Start();
>
> return 0;
> }
>
>
> Xiaofeng Z
Hi Xiaofeng,
You need to create a new actor for the cursor:
i.e. replace this:
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInput(cursor->GetOutput());
actor = vtkActor::New();
actor->SetMapper(mapper);
with this:
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInput(cursor->GetOutput());
vtkActor* cursorActor = vtkActor::New();
cursorActor->SetMapper(mapper);
and then it works.
Here is the working code:
http://www.vtk.org/Wiki/VTK/Examples/Widgets/Cursor2D
Thanks,
David
More information about the vtkusers
mailing list