# VTK 9 Help vtkPolyData GetScalarFieldCriticalIndex

**URL:** https://discourse.vtk.org/t/vtk-9-help-vtkpolydata-getscalarfieldcriticalindex/7453
**Category:** Support
**Created:** [December 21, 2021, 1:29pm UTC](https://discourse.vtk.org/t/vtk-9-help-vtkpolydata-getscalarfieldcriticalindex/7453 "2021-12-21T13:29:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AlexUtrobin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexutrobin/32/4432_2.png) [@AlexUtrobin](https://discourse.vtk.org/u/AlexUtrobin)
#### Post date: [December 21, 2021, 1:29pm UTC](https://discourse.vtk.org/t/vtk-9-help-vtkpolydata-getscalarfieldcriticalindex/7453/1 "2021-12-21T13:29:42Z")

</div>

Finding critical point in vtkPolyData. Found the GetScalarFieldCriticalIndex method, but the method always returns _ERR\_INCORRECT\_FIELD_ (-3), what am I doing wrong?

vtkDoubleArray\* da = dynamic\_cast\<vtkDoubleArray\*\>(pd-\>GetPointData()-\>GetArray(0));  
if (da != NULL) {  
for (int i = 0; i \< pd-\>GetNumberOfPoints(); i++) {  
auto p = points-\>GetPoint(i);  
pointsNew-\>InsertNextPoint(p[0], p[1], p[2] + da-\>GetValue(i));  
int type = pd-\>GetScalarFieldCriticalIndex(pd-\>FindPoint(p[0], p[1], p[2]), 0);  
if (type != -3) {

```
				printf("");
			}
		}
	}
```

---

<div class="post-metadata">

### Author: ![AlexUtrobin](https://discourse.vtk.org/user_avatar/discourse.vtk.org/alexutrobin/32/4432_2.png) [@AlexUtrobin](https://discourse.vtk.org/u/AlexUtrobin)
#### Post date: [December 22, 2021, 6:07am UTC](https://discourse.vtk.org/t/vtk-9-help-vtkpolydata-getscalarfieldcriticalindex/7453/2 "2021-12-22T06:07:50Z")

</div>

Java code:

```
    vtkPolyData pd = new vtkPolyData();

    vtkPoints points = new vtkPoints();
    points.InsertNextPoint(0, 0, 0);
    points.InsertNextPoint(5, 0, 0);
    points.InsertNextPoint(5, 5, 0);
    points.InsertNextPoint(0, 5, 0);
    points.InsertNextPoint(2.5, 2.5, 0);

    vtkDoubleArray da = new vtkDoubleArray();
    da.InsertNextValue(0);
    da.InsertNextValue(0);
    da.InsertNextValue(0);
    da.InsertNextValue(0);
    da.InsertNextValue(1);

    pd.SetPoints(points);
    pd.GetPointData().SetScalars(da);

    for (int i = 0; i < points.GetNumberOfPoints(); i++) {
        System.out.println(pd.GetScalarFieldCriticalIndex(i, 0));
    }

```

out:  
-3  
-3  
-3  
-3  
-3

What am I doing wrong?

---

<div class="post-metadata">

### Author: ![andreasbuykx](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andreasbuykx/32/8137_2.png) [@andreasbuykx](https://discourse.vtk.org/u/andreasbuykx)
#### Post date: [December 22, 2021, 7:30am UTC](https://discourse.vtk.org/t/vtk-9-help-vtkpolydata-getscalarfieldcriticalindex/7453/3 "2021-12-22T07:30:14Z")

</div>

> if (this-\>GetNumberOfPoints() != scalarField-\>GetSize())  
> {  
> return vtkPolyData::ERR\_INCORRECT\_FIELD;  
> }

so you could try and print the size of the array.

Apart from that, you also need to add triangle cells to form a valid manifold 2d mesh.
