vtkPolyData points Data type inconsistency?

Hi Everyone,

I was wondering if someone could help with this. I am reading a DXF file and trying to build a vtkPolyData from it. The DXF file has coordinates that constitutes points that form a triangle. one of the points coordinate has a value of 9999999999999999999999999999999999999999 which when inspected in the debugger is eventually stored as 1.0E+40 which is fine with me as I would like my values to be finite. I’m storing the points as follows

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
for (int idx = 0; idx < numberOfPoints; idx++)
	{
		double x = m_struct.points[idx].x;
		double y = m_struct.points[idx].y;
		double z = m_struct.points[idx].z;
		points->InsertNextPoint(x, y, z);
	}

vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
polyData->SetPoints(points);

where ‘inMeshStruct.points’ is where I stored the data read from the DXF file all above works thus far

However, when I read the same poly data for the points as follows

vtkSmartPointer<vtkPoints> points = inPolyData->GetPoints();
if (points)
{
	vtkSmartPointer<vtkDataArray> pointsDataArray = points->GetData();
	
        // this returns as FLOAT - even though I never specified it to be (perhaps it defaults to that).
        //pointsDataArray->GetDataType() == VTK_FLOAT

       for (vtkIdType idx = 0; idx < sizePoints; idx++)
	{
		double x = pointsDataArray->GetComponent(idx, 0);
		double y = pointsDataArray->GetComponent(idx, 1);
		double z = pointsDataArray->GetComponent(idx, 2);
		printf("z = %.10f\n", z);  //---> issue reported here 
	}
}

the previous value of 9999999999999999999999999999999999999999 which was stored as 1.0E+40 is now being reported as Inf which isn’t what I expect nor want. Also it’s worth nothing that

pointsDataArray->GetDataType() returns as VTK_FLOAT, now could it be that it reports Inf for the z-coordinate because I’m storing the value read in a double?

Could someone shed some light on this, thanks.

Hi Seun,

Yep, vtkPoints defaults to float. You can create a vtkPoints with double representation with the code

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New(VTK_DOUBLE);

Or you can set the type after creating it

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->SetDataTypeToDouble();

Give that a try and see if it handles 1.0E+40 better (it should).

1 Like

Hi Cory,

It was quite straightforward, indeed the points were defaulting to float as you mentioned.
I tried your suggestion & it worked, now it handles 1.0E+40 better. Thanks a lot.

1 Like