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

David Gobbi david.gobbi at gmail.com
Tue Jan 13 09:35:48 EST 2015


Hi Richard,

The "IJK" coordinates are not just data coordinates rounded to int.  Pixel
spacing must also be taken into account.  To properly display images with
VTK, you should become familiar with how VTK images utilize the Spacing and
Origin information that is stored with the images.

With regards to the your code, if the sphere and the image each has its own
renderer, then that is the source of your problems.  They should be in the
same renderer, and getting them to coincide is going to require that you
learn, in a fair bit of detail, (1) how VTK deals with coordinate systems,
and (2) how DICOM deals with coordinate systems.

 - David

On Tue, Jan 13, 2015 at 6:24 AM, Richard Brown <richard.j.brown at live.co.uk>
wrote:

> 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/21e8b8ba/attachment.html>


More information about the vtkusers mailing list