Scanning triangulated area data with a grid

I’m trying to scan values of area data into a grid.

Example Input Data:

Visualization of Grid:

The brute force method would be to check for every cell of the input data whether it’s (partially) within a cell of the grid but I’m trying to find a better solution.

I found vtkClipPolyData which sounded promising but when I defined a square 2D vtkBox the result looked more like a floppy disk:

I don’t really understand how this is happening. It does actually cut through the cells around the edges but the corners are missing.

Does anyone have an idea what is going on here or maybe a better approach on how to solve this?

Edit: This is the code I’m using to clip the data:

vtkSmartPointer<vtkClipPolyData> clipper = vtkSmartPointer<vtkClipPolyData>::New();
clipper->SetInputData(areaPolyData);
vtkSmartPointer<vtkBox> box = vtkSmartPointer<vtkBox>::New();
double boxbounds[6] = {0.0, 0.5, 0.0, 0.5, 0.0, 0.0};
box->SetBounds(boxbounds);
clipper->SetClipFunction(box);;
clipper->SetInsideOut(1);
clipper->Update();
return clipper->GetOutput();

Hello,

Could you try vtkClipClosedSurface filter with vtkPlaneCollection? Does it produce a better result?

There is an example here:
https://lorensen.github.io/VTKExamples/site/Cxx/Meshes/ClipClosedSurface/

Not sure to follow what you are trying to achieve here. Can you be more precise.

Are you looking for RessampleWithDataSet filter ?

I tried it with the example code (adding clipper->Update() and clipper->GetOutputDataObject(0)) and then played around with it a bit (e.g. using less planes) but all I got was an empty object.

I turned debug on but that didn’t tell me anything:
vtkClipClosedSurface.txt (5.7 KB)

This samples on points from another DataSet. Maybe it could work but it’s not what I had in mind.

I want to use a grid (like in the second picture of my post) and then calculate the average area value of that cell.
Each of the polygons/triangles stores one value (the area of the original polygons seen in the first picture). In the grid cell, I want to calculate the median value stored in the polygons/triangles below relative to its area within the cell.
The goal is to “smooth” or reduce big steps between the values within the polygons.

Does this make any more sense?

Hello,
Could you share your data?

I have now realized that resampling with points is almost as precise (depending on the number of points) and is enough for my purpose. This means ResampleWithDataSet is perfect. Thanks for trying to help!