# Visualise 3D finite element data by slice

I have a program that solves for scalar fields on a 3D finite element mesh, and I I want to be able to view slices, e.g. 2D field at a given value of z. Further, I want to display this within a Qt application. I assume that if I can do it in a VTK program it can be done in Qt. Is there an example that does this?

I can see that from the intersection of a plane with the 3D tet mesh I can generate a set of 2D points with their associated values, and from the points, using vtkDelaunay2d I can create a 2D unstructured triangle mesh. Not sure what should come next.

I have something working, but it seems rather contrived and more complicated than it needs to be.
The first part, creating a set of points and values where the selected plane intersects the 3D mesh is straightforward (because the elements are all tetrahedrons.) Putting this aside, I wanted to find out how to make a 2D display of an unstructured grid with values at the nodes.
Using one of the examples as a guide, I do this:
Create a set of (x,y,z) points (the z value will be used to provide the value, i.e. the color.)
vtkPoints *points = vtkPoints::New();
for (int i = 0; i<npts; i++) {
points->InsertNextPoint(x[i], y[i], z[i]);
}
vtkPolyData *inputPolyData = vtkPolyData::New();
inputPolyData->SetPoints(points);
// Triangulate the grid points
vtkDelaunay2D *delaunay = vtkDelaunay2D::New();
delaunay->SetInput(inputPolyData);
delaunay->Update();
vtkPolyData *outputPolyData = delaunay->GetOutput();
colors->Initialize();
for(int i = 0; i < outputPolyData->GetNumberOfPoints(); i++) {
double *p = outputPolyData->GetPoint(i);
double dcolor;
colorLookupTable->GetColor(p,dcolor);
p = 0;
outputPolyData->GetPoints()->SetPoint(i,p); // flatten the surface
unsigned char *color = new unsigned char;
for(int j = 0; j < 3; j++) {
color[j] = (unsigned char)( 255 * dcolor[j] );
}
colors->InsertNextTuple3(color, color, color );
}
outputPolyData->GetPointData()->SetScalars(colors);

``````vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(outputPolyData->GetProducerPort());
``````

Then an actor is created, using mapper, and rendered in the usual way.
This works, but I can’t believe it’s the best way to do it. If I don’t flatten the surface by setting p = 0 the z value at a point is used to create a terrain image, which I don’t want, I just want the coloring.

I’d be grateful if somebody could tell me a better way to make a “heat map” picture of an unstructured 2D grid of points with values.

This is implemented in ParaView and 3D Slicer (see description and implementation). You can use/extend/customize these applications (I would recommend this) or copy-paste code from these applications into yours (may sound like a good idea at first but in the long term you spend a lot more time with keep copying code and maintaining it).