[vtkusers] A points marker widget on a 2D image
Patrick D. Emond
patrickdemond at gmail.com
Wed Jul 2 20:09:07 EDT 2008
Hi Wagner,
I've recently implemented exactly what you've asked about. There are a
few ways you can accomplish this, but here's how I did it.
First, keep track of all points in a vtkPolyData object (using the
SetPoints() method). This object will hold all points (which I tend to
call "seeds") even if they are not currently visible. Let's call that
object SeedsPolyData:
vtkPolyData *SeedsPolyData = vtkPolyData::New();
Next, you'll want another vtkPolyData object that will contain all
_visible_ seed points. The points in this object will change every time
you change slices. Let's call that object VisibleSeedsPolyData:
vtkPolyData *VisibleSeedsPolyData = vtkPolyData::New();
Now we'll need some way to display our visible points. For that you'll
need a number of objects:
vtkCursor2D *SeedsCursor = vtkCursor2D::New();
SeedsCursor->AllOff();
SeedsCursor->AxesOn();
SeedsCursor->PointOn();
vtkGlyph3D *SeedsGlyph = vtkGlyph3D::New();
SeedsGlyph->SetVectorModeToVectorRotationOff();
SeedsGlyph->ScalingOn();
SeedsGlyph->SetScaleModeToDataScalingOff();
SeedsGlyph->SetScaleFactor( 0.2 );
SeedsGlyph->SetInput( VisibleSeedsPolyData );
SeedsGlyph->SetSource( SeedsCursor->GetOutput() );
vtkPolyDataMapper *SeedsMapper = vtkPolyDataMapper::New();
SeedsMapper->SetInput( SeedsGlyph->GetOutput() );
vtkActor *SeedsActor = vtkActor:New();
SeedsActor->SetMapper( SeedsMapper );
Also, you'll want to add the SeedsActor to your renderer.
Finally, you'll want to create a callback that is invoked whenever the
visible slice changes. That callback should then remove all points in
the VisibleSeedsPolyData object, run through the SeedsPolyData object to
find all points visible on the new slice and add them to the
VisibleSeedsPolyData object. Then call Render(), and only the
appropriate seed points will be visible.
You may also wish to incorporate a vtkSeedWidget for point placement.
It works quite well but requires a bit of work to get it to interact
with the above code properly. How you implement that really depends on
how you want your application to work, so I won't go into detail.
Hope that helps,
Patrick
Wagner Sales wrote:
> Dear all,
>
> I'm developing a 2D image viewer that's needs the following functionalities:
> 1) The user can click on a image and mark a point in this image.
> 2) Various points can be marked, and can be used, for example, for an
> image segmentation algorithm
> 3) When I change the slices, if this slice have marked points, needs to
> be showed properly
>
> Well, I started by taking a look in vtkImageTracerWidget. But not fits
> my needs because when I change the slice, the points and lines not
> change. I implemented this using a Qt image viewer, but now I need to
> change the entirely code to VTK. The problem are I don't know what's are
> the correct way to do this in VTK.
>
> Since I think I'm not the first that's needs this, may be someone here
> can helps.
>
> Any help will be must appreciate!
> Thanks in advance,
>
> Wagner Sales
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
More information about the vtkusers
mailing list