I need to use Paraview to calculate lengths of extracted isocontour curves (in 2D). I would eventually like to extend this to computing the surface area of isocontours on a 3D mesh, but for now, I am starting with the 2D case. Following the advice here (Surface area of isosurface - #5 by dutta-alankar), I use the Cell Size filter along with the Integrate Variables filter to sum the length of the cells in the isocontour. That works for a single isocontour, but I’d like to calculate the length of multiple isocontours at once. I attached the .pvsm file of my case for reference.
As a test, I am computing 10 isocontours on a square with a constant x-value. This means the 10 isocontours should have the same length=1, and the total length of all isocontours is 10. You can see that when I apply the Integrate Variables filter, Paraview sums up ALL the 1D cells on all the isocontours, but rather, I’d like the report of the lengths of each individual isocontours, summing only over the cells that are on the same isocontour.
Any advice with this would be appreciated! Is there a way to assign different IDs to the cells on different isocontours, and then apply the Integrate Variables filter to each chunk of cells?
Let me see if this can be achieved with a Programmable filter. If possible, will you be able to share the data so that I can try my hands on it and see if something can be done?
Since your data was Point data (so are the contours), I converted them to Cell Data to get the x position for every cell on which you are making the contours. After that, I applied the following programmable filter on Cell Size filter. Seems to work and create an ascii text file that contains the length for every contour value in two columns.
Here is the filter and the state file is also attached (change the loc variable to the directory where you want to save the text file).
import numpy as np
data_cell = inputs[0].CellData
data_point = inputs[0].PointData
x = np.array(data_cell.GetArray("x_val"))
length = np.array(data_cell.GetArray("Length"))
area = np.array(data_cell.GetArray("Area"))
volume = np.array(data_cell.GetArray("Volume"))
# set(x) will have all the unique values of isocontours
x_contours = list(set(x))
x_contours.sort()
sum_length = np.zeros((len(x_contours),2), dtype=np.float64)
sum_length[:,0] = x_contours
for i, position in enumerate(x_contours):
total = 0.
for j, x_val in enumerate(x):
if x_val==position:
total += length[j]
sum_length[i, 1] = total
print(sum_length)
loc = "/Users/alankard/Downloads"
np.savetxt(f"{loc}/contour-length.txt", sum_length)