# Initializing Contourwidget with line interpolator

**URL:** https://discourse.vtk.org/t/initializing-contourwidget-with-line-interpolator/4989
**Category:** Support
**Created:** [January 12, 2021, 12:20pm UTC](https://discourse.vtk.org/t/initializing-contourwidget-with-line-interpolator/4989 "2021-01-12T12:20:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![arnaud](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/a/e8c25b/32.png) [@arnaud](https://discourse.vtk.org/u/arnaud)
#### Post date: [January 12, 2021, 12:20pm UTC](https://discourse.vtk.org/t/initializing-contourwidget-with-line-interpolator/4989/1 "2021-01-12T12:20:44Z")

</div>

Hello,  
I’m using vtkContourWidget to select cells on a surface/polydata and I would like to initialize the contour.  
I have no issues if I use only vtkcontourwidget and vtkPolygonalSurfacePointPlacer. I have created a polydata containing points that fit on my initial surafce, and initialize the contourwidget with it (contourWidget-\>Initialize(polydata)).

But when adding vtkPolygonalSurfaceContourLineInterpolator I got a bug. The message indicates an nullptr error on nodeBegin and nodeEnd (into the vtkPolygonalSurfaceContourLineInterpolator class).

/////////////////////////////////////  
int numPts = 4;  
vtkSmartPointer points = vtkSmartPointer::New();  
points-\>InsertPoint(static\_cast(0), -36.604606, 3.172031, -15.775561);  
points-\>InsertPoint(static\_cast(1), 29.504172, 2.542050, -21.521465);  
points-\>InsertPoint(static\_cast(2), 13.557625, 5.584614, 17.892294);  
points-\>InsertPoint(static\_cast(3), -17.859298, 8.136532, 17.122012);

```
vtkIdType* vertexIndices = new vtkIdType[numPts + 1];
for (int i = 0; i < numPts; i++) { vertexIndices[i] = static_cast<vtkIdType>(i); }
vertexIndices[numPts] = 0;
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
lines->InsertNextCell(numPts + 1, vertexIndices);

vtkSmartPointer<vtkPolyData> polydataPickedPoints = vtkSmartPointer<vtkPolyData>::New();
polydataPickedPoints->SetPoints(points);
polydataPickedPoints->SetLines(lines);
polydataPickedPoints->Modified();

///////////////////////////////////////////////////////////////////////////////////////////////////
vtkSmartPointer<vtkContourWidget> contourWidget = vtkSmartPointer<vtkContourWidget>::New();
contourWidget->SetInteractor(interactor);
contourWidget->On();

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);

contourWidget->Initialize(polydataPickedPoints);

```

Could you help me understand how to initialize the contourwidget in case of using it with vtkPolygonalSurfaceContourLineInterpolator ? Or how to add nodes on the contour (similar issues than [Contour filter - add nodes programatically](https://discourse.vtk.org/t/contour-filter-add-nodes-programatically/1127) ) ?

Thanks by advance for helping me  
arnaud
