[vtkusers] add circles & sphere to DICOM slices & 3D viewer

Richard Brown richard.j.brown at live.co.uk
Tue Jan 13 08:24:58 EST 2015


Thanks, vtkContourTriangulator worked well and I’ll continue to work my way through your first two points.

For the third point:

> I also haven't managed to see both the circle and the DICOM image at the
> same time, despite what feels like every combination of setOpacity,
> setAmbient, etc. When I set the background of the newly cut circle to green,
> everything goes green, so I think it might be that the background of the
> circle is masking the DICOM slice, can I set it to have a transparent
> background?
> 
> There is no way to set the background for a single actor, AFAIK the only way to
> set the background is in the vtkRenderer, in which case you are setting the background
> for everything, and the background will therefore be behind everything and cannot
> ever be in front of something.  Can you explain in more detail what you are doing?

Beneath I’ve copied the code that I’ve been trying. worldCoords is the point returned by the user’s click using GetIJK (by the way, the difference between GetIJK and GetPickPosition & GetMapperPosition is IJK is the rounded to int, the values are otherwise the same?). I try to add the newly cut circle to the QVTKWidget already containing the DICOM slice using GetRenderindow()->AddRenderer(renderer) at the end, and the output is a semi-transparent red circle (because opacity is 40%) on a bright green background. I can’t for the life of me figure out where I need to point the camera to see the DICOM slice again.

Cheers for the help,
Richard

P.S. I know the vtkCamera settings are nonsensical, I am just messing about with them at this stage.

    vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
    sphere->SetCenter(mmCoords);
    sphere->SetPhiResolution(30);
    sphere->SetThetaResolution(30);
    sphere->SetRadius(5);
    sphere->Update();

    vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
    plane->SetOrigin(worldCoords[0], worldCoords[1], worldCoords[2]);
    plane->SetNormal(0, 0, 1);

    vtkSmartPointer<vtkContourTriangulator> triangles = vtkSmartPointer<vtkContourTriangulator>::New();
    triangles->SetInputConnection(sphereCutter->GetOutputPort());

    // Visualize
    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(triangles->GetOutputPort());

    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
    actor->GetProperty()->EdgeVisibilityOff();
    actor->GetProperty()->SetAmbient(1.0);
    actor->GetProperty()->SetDiffuse(1.0);
    actor->GetProperty()->SetOpacity(0.4);


    vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
    camera->SetPosition(worldCoords[0], worldCoords[1], worldCoords[2]+50);
    camera->SetFocalPoint(worldCoords[0], worldCoords[1], worldCoords[2]);

    vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);
    renderer->SetBackground(0,1,0);
    renderer->SetActiveCamera(camera);

    ui->qvtk->GetRenderWindow()->AddRenderer(renderer);


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150113/1e5b580a/attachment.html>


More information about the vtkusers mailing list