Author Topic: Applying ConstructSurfaceModifier to multiple selected clusters.  (Read 45 times)

shanis

  • Newbie
  • *
  • Posts: 8
Dear ovito users,

If I have 10 clusters, out of which I want to select only 5 of them and apply the ConstructSurfaceModifier to each of them to obtain volume of each cluster, how could I achieve this ? Currently I can only select one cluster and apply the modifier. I can't use python variable to change the SelectExpressionModifier so I am thinking of an alternative way. Following is a code snippet that I am using to construct the surface.

Code: [Select]
# select cluster
clusterselect_modifier = SelectExpressionModifier(expression = 'Cluster == 1')
pipeline.modifiers.append(clusterselect_modifier)
data = pipeline.compute()

# apply surface mesh on selected cluster
pipeline.modifiers.append(ConstructSurfaceModifier(only_selected = True))
data = pipeline.compute()

volume = pipeline.output.attributes['ConstructSurfaceMesh.solid_volume']

Thanks a lot !





« Last Edit: May 06, 2019, 11:16:55 AM by Constanze Kalcher »

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 259
Re: Applying ConstructSurfaceModifier to multiple selected clusters.
« Reply #1 on: May 06, 2019, 11:16:24 AM »
Dear shanis,

in order to help you, I need to know what makes the five clusters you're trying to select different from the others? For example, if you wanted to get the 5 biggest clusters out of those 10 you could activate the option "Sort clusters by size"
https://www.ovito.org/manual_testing/particles.modifiers.cluster_analysis.html
and then create a selection based on their cluster ID's
Code: [Select]
clusterselect_modifier = SelectExpressionModifier(expression = 'Cluster <= 5')]Just let me know a little bit more about your system.

-Constanze

shanis

  • Newbie
  • *
  • Posts: 8
Re: Applying ConstructSurfaceModifier to multiple selected clusters.
« Reply #2 on: May 08, 2019, 05:42:12 PM »
Thanks Constanze,

Yes, I am sorting the clusters based on size, and I can see that using the relational operator <= , as you suggested computes the surface mesh on all selected clusters. However, I also want to output the surface volume values as a global attribute for all of the selected clusters, but currently I only get one value for surface mesh using the above code. Alternatively, I can repeat the code for each cluster separately and get the volumes for each clusters that way, but this is not very efficient when there are many clusters. Let me know if you have other suggestions.

Best,

Constanze Kalcher

  • Administrator
  • Sr. Member
  • *****
  • Posts: 259
Re: Applying ConstructSurfaceModifier to multiple selected clusters.
« Reply #3 on: May 10, 2019, 11:48:25 AM »
Dear shanis,

ah okay, sorry I somehow missed that you would like to get the individual cluster volumes instead. You're right, at the moment this is not possible yet by only applying the Surface mesh modifier once, but it is very likely a feature of the next release. So for now, you will have to use a little workaround, like you already suggested in your previous post, e.g. by looping over the Cluster-ID's and then applying the Surface mesh modifier to each individual cluster, e.g. :

Code: [Select]
   
...
clusterselect_modifier = SelectExpressionModifier()
pipeline.modifiers.append(clusterselect_modifier)
pipeline.modifiers.append(ConstructSurfaceModifier(only_selected = True))
for clusterID in range(1,6):
    my_expression = "Cluster == {}".format(clusterID)
    clusterselect_modifier.expression = my_expression
    data = pipeline.compute()
    print(pipeline.output.attributes['ConstructSurfaceMesh.solid_volume'])

-Constanze