Can we add a check to see if we have at least 2 nodes when vtkContourWidget is in Manipulate state?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Can we add a check to see if we have at least 2 nodes when vtkContourWidget is in Manipulate state?

Mengda Wu-3
Hi all,

   I would like to set the state of vtkContourWidget to Manipulate at initialize and add the nodes programmably instead of interactively. Everything is fine but I have to check the there are at least 2 nodes in the following, otherwise AddNodeOnContour will crash

So I hope you can change the following function to

void vtkContourWidget::SelectAction( vtkAbstractWidget *w )
{

................
................

  switch ( self->WidgetState )
    {
    case vtkContourWidget::Start:
    case vtkContourWidget::Define:
................
................
    case vtkContourWidget::Manipulate:
      {
      if ( rep->ActivateNode( X, Y ) )
        {
................
................
        }
      else if ( rep->GetNumberOfNodes()>1 && rep->AddNodeOnContour( X, Y ) )   //Ensure the number of nodes is at least 2
        {
................
................
        }
................
................
}



_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Can we add a check to see if we have at least 2 nodes when vtkContourWidget is in Manipulate state?

Yumin Yuan
Hi Mengda,

I will suggest to figure out why it is crashing first. Even with only one node, it should still work.

Also, assuming you are using this method vtkContourWidget::Initialize( vtkPolyData * poly, int state = 1, vtkIdList *idList = NULL ), your input poly doesn't have any points?

Yumin

On Fri, Jan 22, 2016 at 10:40 AM, Mengda Wu <[hidden email]> wrote:
Hi all,

   I would like to set the state of vtkContourWidget to Manipulate at initialize and add the nodes programmably instead of interactively. Everything is fine but I have to check the there are at least 2 nodes in the following, otherwise AddNodeOnContour will crash

So I hope you can change the following function to

void vtkContourWidget::SelectAction( vtkAbstractWidget *w )
{

................
................

  switch ( self->WidgetState )
    {
    case vtkContourWidget::Start:
    case vtkContourWidget::Define:
................
................
    case vtkContourWidget::Manipulate:
      {
      if ( rep->ActivateNode( X, Y ) )
        {
................
................
        }
      else if ( rep->GetNumberOfNodes()>1 && rep->AddNodeOnContour( X, Y ) )   //Ensure the number of nodes is at least 2
        {
................
................
        }
................
................
}



_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers



_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Can we add a check to see if we have at least 2 nodes when vtkContourWidget is in Manipulate state?

Mengda Wu-3
OK. I did not initialize it with a polydata but just used the method vtkContourWidget::Initialize(). I believe it means that there is no point in it.
Then I set the state to Manipulate immediately with SetWidgetState(vtkContourWidget::Manipulate);

After that, using some other code, I got the point from the pick point on vtkImagePlaneWidget and added it to vtkContourWidget with vtkContourWidget->GetContourRepresentation()->AddNodeAtWorldPosition(point);

The first point is fine but it crashes when I tried to add the second point. The crashes happened in vtkLine::Intersection with the call stack as follows:

vtkLine::Intersection(double * a1, double * a2, double * b1, double * b2, double & u, double & v) Line 117
vtkContourRepresentation::FindClosestPointOnContour(int X, int Y, double * closestWorldPos, int * idx) Line 808
vtkContourRepresentation::AddNodeOnContour(int X, int Y) Line 896

Mengda

On Fri, Jan 22, 2016 at 3:07 PM, Yumin Yuan <[hidden email]> wrote:
Hi Mengda,

I will suggest to figure out why it is crashing first. Even with only one node, it should still work.

Also, assuming you are using this method vtkContourWidget::Initialize( vtkPolyData * poly, int state = 1, vtkIdList *idList = NULL ), your input poly doesn't have any points?

Yumin

On Fri, Jan 22, 2016 at 10:40 AM, Mengda Wu <[hidden email]> wrote:
Hi all,

   I would like to set the state of vtkContourWidget to Manipulate at initialize and add the nodes programmably instead of interactively. Everything is fine but I have to check the there are at least 2 nodes in the following, otherwise AddNodeOnContour will crash

So I hope you can change the following function to

void vtkContourWidget::SelectAction( vtkAbstractWidget *w )
{

................
................

  switch ( self->WidgetState )
    {
    case vtkContourWidget::Start:
    case vtkContourWidget::Define:
................
................
    case vtkContourWidget::Manipulate:
      {
      if ( rep->ActivateNode( X, Y ) )
        {
................
................
        }
      else if ( rep->GetNumberOfNodes()>1 && rep->AddNodeOnContour( X, Y ) )   //Ensure the number of nodes is at least 2
        {
................
................
        }
................
................
}



_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers




_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Can we add a check to see if we have at least 2 nodes when vtkContourWidget is in Manipulate state?

Yumin Yuan
Hi Mengda,

Since you are using the vtkImagePlaneWidget to get the points and then inserting them programmatically into the vtkContourWidget, the vtkContourWidget should not be enabled while you are doing this. It seems like when you click in the render window, the vtkContourWidget::SelectAction is also invoked (from your first email), which is not what you want. Try to disable the vtkContourWidget while you are interacting with the plane widget and inserting points into contour widget. You can enable the contour widget after you have done inserting points.

HTH,
Yumin

On Fri, Jan 22, 2016 at 11:20 PM, Mengda Wu <[hidden email]> wrote:
OK. I did not initialize it with a polydata but just used the method vtkContourWidget::Initialize(). I believe it means that there is no point in it.
Then I set the state to Manipulate immediately with SetWidgetState(vtkContourWidget::Manipulate);

After that, using some other code, I got the point from the pick point on vtkImagePlaneWidget and added it to vtkContourWidget with vtkContourWidget->GetContourRepresentation()->AddNodeAtWorldPosition(point);

The first point is fine but it crashes when I tried to add the second point. The crashes happened in vtkLine::Intersection with the call stack as follows:

vtkLine::Intersection(double * a1, double * a2, double * b1, double * b2, double & u, double & v) Line 117
vtkContourRepresentation::FindClosestPointOnContour(int X, int Y, double * closestWorldPos, int * idx) Line 808
vtkContourRepresentation::AddNodeOnContour(int X, int Y) Line 896

Mengda

On Fri, Jan 22, 2016 at 3:07 PM, Yumin Yuan <[hidden email]> wrote:
Hi Mengda,

I will suggest to figure out why it is crashing first. Even with only one node, it should still work.

Also, assuming you are using this method vtkContourWidget::Initialize( vtkPolyData * poly, int state = 1, vtkIdList *idList = NULL ), your input poly doesn't have any points?

Yumin

On Fri, Jan 22, 2016 at 10:40 AM, Mengda Wu <[hidden email]> wrote:
Hi all,

   I would like to set the state of vtkContourWidget to Manipulate at initialize and add the nodes programmably instead of interactively. Everything is fine but I have to check the there are at least 2 nodes in the following, otherwise AddNodeOnContour will crash

So I hope you can change the following function to

void vtkContourWidget::SelectAction( vtkAbstractWidget *w )
{

................
................

  switch ( self->WidgetState )
    {
    case vtkContourWidget::Start:
    case vtkContourWidget::Define:
................
................
    case vtkContourWidget::Manipulate:
      {
      if ( rep->ActivateNode( X, Y ) )
        {
................
................
        }
      else if ( rep->GetNumberOfNodes()>1 && rep->AddNodeOnContour( X, Y ) )   //Ensure the number of nodes is at least 2
        {
................
................
        }
................
................
}



_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers





_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Can we add a check to see if we have at least 2 nodes when vtkContourWidget is in Manipulate state?

andyjk
I have the same problem. I can only add one point (the first) and even then,
the interactor crashes if I try to do more. Simple example below - basically
from
https://vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolygonalSurfaceContourLineInterpolator
with a few lines added. Any reason why I cannot add nodes programatically ?
Thanks !

#include <vtkVersion.h>
#include "vtkSmartPointer.h"

#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkCellArray.h"
#include "vtkImageDataGeometryFilter.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkPolyDataCollection.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSphereSource.h"
#include "vtkTriangleFilter.h"
#include "vtkXMLPolyDataReader.h"

#include "vtkContourWidget.h"
#include "vtkOrientedGlyphContourRepresentation.h"
#include "vtkPolygonalSurfacePointPlacer.h"
#include "vtkPolygonalSurfaceContourLineInterpolator.h"


int main(int argc, char *argv[])
{
  vtkSmartPointer<vtkPolyData> polyData;
  if (argc < 2)
    {
    vtkSmartPointer<vtkSphereSource> sphereSource =
      vtkSmartPointer<vtkSphereSource>::New();
    sphereSource->SetThetaResolution(40);
    sphereSource->SetPhiResolution(20);
    sphereSource->Update();

    polyData = sphereSource->GetOutput();
    }
  else
    {
    vtkSmartPointer<vtkXMLPolyDataReader> reader =
      vtkSmartPointer<vtkXMLPolyDataReader>::New();
    reader->SetFileName(argv[1]);
    reader->Update();
    polyData = reader->GetOutput();
    }
     
  // The Dijkistra interpolator will not accept cells that aren't triangles
  vtkSmartPointer<vtkTriangleFilter> triangleFilter =
    vtkSmartPointer<vtkTriangleFilter>::New();
#if VTK_MAJOR_VERSION <= 5
  triangleFilter->SetInput( polyData );
#else
  triangleFilter->SetInputData( polyData );
#endif
  triangleFilter->Update();
 
  vtkSmartPointer<vtkPolyData> pd = triangleFilter->GetOutput();
 
  //Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(triangleFilter->GetOutputPort());
 
  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);
  actor->GetProperty()->SetInterpolationToFlat();
 
  // Create the render window, renderer and interactor.
 
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> interactor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  interactor->SetRenderWindow(renderWindow);
 
  // Add the actors to the renderer, set the background and size
 
  renderer->AddActor(actor);
  renderer->SetBackground (.3, .4, .5);

  // Here comes the contour widget stuff...

  vtkSmartPointer<vtkContourWidget> contourWidget =
    vtkSmartPointer<vtkContourWidget>::New();
  contourWidget->SetInteractor(interactor);
  vtkSmartPointer<vtkOrientedGlyphContourRepresentation> rep =
    vtkOrientedGlyphContourRepresentation::SafeDownCast(
      contourWidget->GetRepresentation());
  rep->GetLinesProperty()->SetColor(1, 0.2, 0);
  rep->GetLinesProperty()->SetLineWidth(3.0);

  vtkSmartPointer<vtkPolygonalSurfacePointPlacer> pointPlacer =
    vtkSmartPointer<vtkPolygonalSurfacePointPlacer>::New();
  pointPlacer->AddProp(actor);
  pointPlacer->GetPolys()->AddItem( pd );
  rep->SetPointPlacer(pointPlacer);

  vtkSmartPointer<vtkPolygonalSurfaceContourLineInterpolator> interpolator =
    vtkSmartPointer<vtkPolygonalSurfaceContourLineInterpolator>::New();
  interpolator->GetPolys()->AddItem( pd );
  rep->SetLineInterpolator(interpolator);
 
  renderWindow->Render();
  interactor->Initialize();

  contourWidget->EnabledOn();
  contourWidget->Initialize();
  contourWidget->EnabledOff();

  double pt1[3]; pt1[0] = -0.107433; pt1[1] = 0.112549; pt1[2] = 0.474558;
  contourWidget->SetWidgetState(vtkContourWidget::Define);
  contourWidget->GetContourRepresentation()->AddNodeAtWorldPosition(pt1);

  //double pt2[3]; pt2[0] = 0.187556; pt2[1] = 0.187556; pt2[2] = 0.42192;
  //contourWidget->GetContourRepresentation()->AddNodeAtWorldPosition(pt2);
 
  contourWidget->EnabledOn();
  interactor->Start();

  return EXIT_SUCCESS;
}



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
Powered by 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

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers