[vtkusers] vtkContourWidget

Nicolas Sarrasin nsarrasin at phenix-systems.com
Mon May 17 12:00:41 EDT 2010


Thanks a lot for your reply, it solves my problem.

I associate your solution with 
/vtkPolygonalSurfaceContourLineInterpolator/ which permits me to have a 
contour which stays on the surface and whose spans lie on the surface.

Le 17/05/2010 17:25, Karthik Krishnan a écrit :
> Nicolas:
>
> Replace vtkPolyDataPointPlacer vtkPolygonalSurfacePointPlacer and now 
> I can no longer move the points ouside teh silhoutte.
>
> Thanks
> --
> karthik
>
> On Fri, May 14, 2010 at 2:25 PM, Nicolas Sarrasin 
> <nsarrasin at phenix-systems.com <mailto:nsarrasin at phenix-systems.com>> 
> wrote:
>
>     Here is a compiling example, I post a picture too to be clearer.
>
>     picture : http://img138.imageshack.us/img138/1695/123qny.png
>
>     /*        code begins        */
>
>     #include <vtkRenderer.h>
>     #include <vtkRendererCollection.h>
>     #include <vtkRenderWindow.h>
>     #include <vtkRenderWindowInteractor.h>
>     #include <vtkProperty.h>
>     #include <vtkLODActor.h>
>     #include <vtkPolyDataMapper.h>
>     #include <vtkPolyData.h>
>     #include <vtkCellArray.h>
>     #include <vtkSphereSource.h>
>     #include <vtkContourWidget.h>
>     #include <vtkOrientedGlyphContourRepresentation.h>
>     #include <vtkLinearContourLineInterpolator.h>
>     #include <vtkGlyph3D.h>
>     #include <vtkCellPicker.h>
>     #include <vtkCallbackCommand.h>
>     #include <vtkCamera.h>
>     #include <vtkInteractorStyleTrackballCamera.h>
>     #include <vtkSmartPointer.h>
>     #include <vtkPolyDataPointPlacer.h>
>
>     int main(int argc, char*argv[])
>     {
>         //définition de la sphere
>         vtkSphereSource* theSphere = vtkSphereSource::New();
>         theSphere->SetCenter( 0, 0, 5);
>         theSphere->SetRadius(1.0);
>
>
>         vtkPolyDataMapper * sphereMapper = vtkPolyDataMapper::New();
>         sphereMapper->SetInput(theSphere->GetOutput());
>
>         vtkLODActor* sphereActor = vtkLODActor::New();
>         sphereActor->SetMapper( sphereMapper);
>
>         // définition Renderer + renderWindow
>         vtkRenderer *renderer1 = vtkRenderer::New();
>         renderer1->SetBackground(0.3, 0.45, 0.6);
>
>         renderer1->AddActor(sphereActor);
>
>         vtkRenderWindow *renWin = vtkRenderWindow::New();
>         renWin->AddRenderer(renderer1);
>         renWin->SetSize(600, 600);
>         renWin->SetPosition(450,150);
>
>         //définition du WindowIteractor
>
>         vtkRenderWindowInteractor *rendIter =
>     vtkRenderWindowInteractor::New();
>         rendIter->SetRenderWindow(renWin);
>
>         // Here comes the image actor constrained handle widget stuff.....
>         vtkContourWidget *widget = vtkContourWidget::New();
>         widget->SetInteractor(rendIter);
>
>         vtkSmartPointer<vtkLinearContourLineInterpolator> contourStyle
>     = vtkSmartPointer<vtkLinearContourLineInterpolator>::New();
>
>         vtkOrientedGlyphContourRepresentation *rep
>     =vtkOrientedGlyphContourRepresentation::SafeDownCast(
>     widget->GetRepresentation() );
>         rep->GetLinesProperty()->SetColor(1, 1, 0);
>         rep->GetLinesProperty()->SetLineWidth(3.0);
>         rep->SetLineInterpolator(contourStyle);
>
>         //on définit un Placer pour forcer le contour a etre sur la
>     sphere
>
>         vtkPolyDataPointPlacer * spherePlacer =
>     vtkPolyDataPointPlacer::New();
>         spherePlacer->AddProp(sphereActor);
>         rep->SetPointPlacer(spherePlacer);
>
>         renWin->Render();
>         rendIter->Initialize();
>         widget->EnabledOn();
>         rendIter->Start();
>
>         //clean
>         rendIter->Delete();
>         renWin->Delete();
>         renderer1->Delete();
>
>         sphereMapper->Delete();
>         sphereActor->Delete();
>         theSphere->Delete();
>
>         return 0;
>     }
>
>     /*        code ends           */
>
>     Thanks
>
>
>     Le 14/05/2010 10:13, Karthik Krishnan a écrit :
>>     On Fri, May 14, 2010 at 1:15 PM, Nicolas Sarrasin
>>     <nsarrasin at phenix-systems.com
>>     <mailto:nsarrasin at phenix-systems.com>> wrote:
>>
>>         Ok thanks for your reply.
>>
>>
>>     Please keep mails on the list, so others may chime in.
>>
>>
>>         I'm gonna use /vtkPolygonalSurfaceContourLineInterpolator/,
>>         it satisfied me, for the moment.
>>
>>
>>     Great.
>>
>>
>>>         The interpolator internally traces the shortest path between
>>>         the two nodes along vertices of the mesh, so its not as good
>>>         as a projection that cuts through the cells, but if your
>>>         mesh is dense enough the traced path might be good enough.
>>
>>         What do you suggest me if my mesh isn't dense enough ? How
>>         can i project the contour on my sphere ?
>>
>>
>>     The path is an approximation of a projection onto the mesh, such
>>     that the projected path lies wholly along the vertices of the mesh.
>>
>>
>>         Now I encounter a new "problem" in using contour widget.
>>         After closing a contour, everytime I try to modify it by
>>         dragging a node, the node can be move outside the surface
>>         (it's still inside the silhouette of the sphere but it's not
>>         lying on any more and approach the screen).
>>
>>
>>     This should not happen if you are using a
>>     vtkPolygonalSurfacePointPlacer to constrain the nodes and the
>>     vtkPolygonalSurfaceContourLineInterpolator to constrain the path.
>>
>>     Please post a minimal, (compiling) example. Also take a look a
>>     look at TestDijkstraImageGeodesicPath. The contour and the
>>     interpolated path are confined to the surface of the mesh, while
>>     you manipulate interactively.
>>
>>     --
>>     karthik
>>
>>
>>         How can I manage this problem and constrain the position of
>>         the node of the contour during all its lifetime in the
>>         visualisation?
>>
>>         Thanks by advance,
>>
>>         Nicolas
>>
>>         Le 12/05/2010 18:43, Karthik Krishnan a écrit :
>>>         Yes Nicolas:
>>>
>>>         The contour widget uses two sets of classes, which (are
>>>         generally independent of each other).
>>>
>>>         A subclass of vtkPointPlacer dictates the constraints
>>>         imposed on the nodes.
>>>         A subclass of vtkContourLIneInterpolator dictates the
>>>         constraints imposed on the path in between the nodes.
>>>
>>>         In your case, you might want to look at the following
>>>         combination :
>>>
>>>           vtkPolygonalSurfacePointPlacer ->
>>>         vtkPolygonalSurfaceContourLineInterpolator
>>>
>>>         The interpolator internally traces the shortest path between
>>>         the two nodes along vertices of the mesh, so its not as good
>>>         as a projection that cuts through the cells, but if your
>>>         mesh is dense enough the traced path might be good enough.
>>>
>>>
>>>         Something like :
>>>
>>>
>>>            vtkContourWidget *contourWidget = vtkContourWidget::New();
>>>           contourWidget->SetInteractor(iren);
>>>
>>>           vtkOrientedGlyphContourRepresentation *rep =
>>>               vtkOrientedGlyphContourRepresentation::SafeDownCast(
>>>                                 contourWidget->GetRepresentation());
>>>
>>>           vtkPolygonalSurfacePointPlacer * pointPlacer
>>>                 = vtkPolygonalSurfacePointPlacer::New();
>>>           pointPlacer->AddProp( sphereActor );
>>>           rep->SetPointPlacer(pointPlacer);
>>>
>>>           vtkPolygonalSurfaceContourLineInterpolator * lineInterpolator
>>>                 = vtkPolygonalSurfaceContourLineInterpolator::New();
>>>           rep->SetLineInterpolator(lineInterpolator);
>>>
>>>           iren->Initialize();
>>>           contourWidget->EnabledOn();
>>>
>>>
>>>         Hope this helps.. Here is a minimal example..
>>>
>>>         --
>>>         karthik
>>>
>>>
>>>         On Wed, May 12, 2010 at 7:21 PM, Nicolas Sarrasin
>>>         <nsarrasin at phenix-systems.com
>>>         <mailto:nsarrasin at phenix-systems.com>> wrote:
>>>
>>>             Hi all,
>>>
>>>             I'm quite new in developping with vtk and I have some
>>>             questions concerning vtkContourWidget.
>>>
>>>             I built a quick project which uses vtkContourWidget and
>>>             vtkPolyDataPointPlacer to display a contour on a sphere.
>>>
>>>             When I click on this sphere, there's no problem : the
>>>             points of the contour are well positionned on the
>>>             sphere. But it's not the case for the spans which are
>>>             outside or inside the sphere (but not on).
>>>
>>>             Is there a way to force the borders of the contour to
>>>             follow the surface ?
>>>
>>>             A solution would be to project the contour on the sphere
>>>             but I can find any documentation about that.
>>>
>>>             For more clarity, I post a sample of my code.
>>>
>>>             Thanks by advance.
>>>
>>>             Nicolas
>>>
>>>             code:
>>>
>>>                  //sphere definition
>>>
>>>                   vtkSphereSource* theSphere = vtkSphereSource::New();
>>>
>>>                   vtkPolyDataMapper * sphereMapper = vtkPolyDataMapper::New();
>>>                   sphereMapper->SetInput(theSphere->GetOutput());
>>>
>>>                   vtkLODActor* sphereActor = vtkLODActor::New();
>>>                   sphereActor->SetMapper( sphereMapper);
>>>
>>>                   vtkRenderer *renderer1 = vtkRenderer::New();
>>>                   renderer1->AddActor(sphereActor);
>>>
>>>                   vtkRenderWindow *renWin = vtkRenderWindow::New();
>>>                   renWin->AddRenderer(renderer1);
>>>
>>>                   vtkRenderWindowInteractor *rendIter = vtkRenderWindowInteractor::New();
>>>                   rendIter->SetRenderWindow(renWin);
>>>
>>>                   // Here comes the image actor constrained handle widget stuff.....
>>>                   vtkContourWidget *widget = vtkContourWidget::New();
>>>                   widget->SetInteractor(rendIter);
>>>
>>>                   vtkSmartPointer<vtkLinearContourLineInterpolator>  contourStyle =
>>>             vtkSmartPointer<vtkLinearContourLineInterpolator>::New();
>>>
>>>                   vtkOrientedGlyphContourRepresentation *rep
>>>             =vtkOrientedGlyphContourRepresentation::SafeDownCast(
>>>             widget->GetRepresentation() );
>>>                   rep->SetLineInterpolator(contourStyle);
>>>
>>>                  // we define a Placer to force the contour to be on the sphere
>>>                   vtkPolyDataPointPlacer * spherePlacer = vtkPolyDataPointPlacer::New();
>>>                   spherePlacer->AddProp(sphereActor);
>>>                   rep->SetPointPlacer(spherePlacer);
>>>
>>>                   renWin->Render();
>>>                   rendIter->Initialize();
>>>                   widget->EnabledOn();
>>>                   rendIter->Start();/
>>>                  
>>>
>>>
>>>             -- 
>>>
>>>
>>>             _______________________________________________
>>>             Powered by www.kitware.com <http://www.kitware.com>
>>>
>>>             Visit other Kitware open-source projects at
>>>             http://www.kitware.com/opensource/opensource.html
>>>
>>>             Please keep messages on-topic and check the VTK FAQ at:
>>>             http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>>             Follow this link to subscribe/unsubscribe:
>>>             http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>>
>>>
>>>
>>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100517/1a46bc61/attachment.htm>


More information about the vtkusers mailing list