Personal tools
You are here: Home Forum How to use Salome? cut a STL surface

cut a STL surface

Up to How to use Salome?

cut a STL surface

Posted by Martin at December 11. 2012

Dear all:

 

I need to cut a STL surface previously loaded within Salome. By "cut", I mean removing all triangles that are on one side of a plane, but making sure that the intersection of the surface and the plane is a line. Does it make sense? Is it possible to do that in Salome? If not, any advice on the tool I could use? Thanks!

 

Martin

Re: cut a STL surface

Posted by Saint Michael at December 11. 2012

Hi Martin

In SALOME you can at least remove triangles laying fully or partially on one side of a plane.

For this you are to
- create a large box, whose one side represents your plane of interest,
- create a mesh group on filter with "Belong to geom" or "Lying on geom" criteria. "Belong to geom" is to find triangles being fully inside the box and "Lying on geom", partially.
- remove the created group with its contents.

As about "making sure that the intersection of the surface and the plane is a line" I don't quite understand what you mean.

St.Michael

Re: cut a STL surface

Posted by Martin at December 11. 2012

Thanks St.Michael.

 

Sorry for not being clear enough. What I meant is that if I simply remove a bunch of triangles, the newly created surface border, i.e. the limit between the triangles that were removed and those that remain, will be quite rough. Is there a way to create new triangles so that the new border lies exactly on the plane? Does it make more sense?

 

Martin

Re: cut a STL surface

Posted by Saint Michael at December 12. 2012

Now it's clear! It's possible to do but not very simple. Algorithm is following.

- Create two groups on filters using the both above mentioned criteria, and cut these groups. The cut group contains triangles intersected by the plane.

- Create geometrical triangles equal to the intersected triangles (in a python script).

- In GEOM module, cut the geometrical triangles by the box used to create the groups on filters. Export them in an STL file.

- Import the new STL file in MESH module, make a compound mesh of the initial mesh and the new STL mesh.

St.Michael

Re: cut a STL surface

Posted by Saint Michael at December 12. 2012

Previously Saint Michael wrote:

Now it's clear! It's possible to do but not very simple. Algorithm is following.

- Create two groups on filters using the both above mentioned criteria, and cut these groups. The cut group contains triangles intersected by the plane.

- Create geometrical triangles equal to the intersected triangles (in a python script).

- In GEOM module,         cut      the geometrical triangles by the box used to create the groups on filters.

 

Actually not "cut" but "common".

Re: cut a STL surface

Posted by Martin at December 18. 2012

Thanks St.Michael. However, I can't seem to create the groups correctly. Here is an image. Any clue what I might do wrong? Thanks again! Martin

Attachments

Re: cut a STL surface

Posted by Martin at December 18. 2012

PS: Here is the original surface!

Attachments

Re: cut a STL surface

Posted by Saint Michael at December 18. 2012

Hi Martin

It's difficult to understand what is wrong by an image. Thus, I wrote a script (attached) that solves exactly this task. While writing it I found a problem that the group based on "Lying on geom" filter misses some triangles, as a workaround I used a bit larger box in this filter. Now it work OK.

St.Michael

Attachments

Re: cut a STL surface

Posted by Martin at December 22. 2012

Works like a charm…thanks St.Michael! :)

 

Any idea why the LyingOnGeom filter doesn't seem to work properly?

 

Also, is there no function to directly create a Geometrical triangle from a Mesh triangle? And no function to load a mesh directly, instead of writing/reading a temporary file?

 

Anyway, thanks again for the brilliant solution!

 

Martin

Re: cut a STL surface

Posted by Martin at December 23. 2012

Hi St.Michael,

Let me ask a couple additional questions.

1) What's the best way to run/debug a script? Creating a new document and loading the script ``by hand'' each time is quite annoying. And running ``runSalomeScript test.py'' directly from a terminal doesn't really work either.

2) How to load a .hdf file in a python script, and use the objects stored inside? I've been using something like

salome.myStudy = salome.myStudyManager.Open("test.hdf")

myMesh = salome.myStudy.FindObject("Mesh")

myGroup  = myMesh.MakeGroup("group_name" , etc…)

But it doesn't seem to be the right way to do so.

3) Is there a place in the documentation where I could have found an answer to these questions?

Thanks again!

Martin

Re: cut a STL surface

Posted by Saint Michael at December 24. 2012

Hi Martin

Any idea why the LyingOnGeom filter doesn't seem to work properly?

I think it's just a bug :)

Also, is there no function to directly create a Geometrical triangle from a Mesh triangle?

There is no such a function :(

And no function to load a mesh directly, instead of writing/reading a temporary file?

In my script, I used a temporary file just to show how to read an STL file in the Python script. The script can cut any triangular mesh, or even any 2D mesh with a little fix of the script.

1) What's the best way to run/debug a script? Creating a new document and loading the script ``by hand'' each time is quite annoying. And running ``runSalomeScript test.py'' directly from a terminal doesn't really work either.

I re-run the same >>> execfile(...) command in the same Python Console until it becomes hard to deal with many objects in the Object Browser. I.e. I check script execution result, then modify the script, Mouse-click in Python Console, Arrow-up --> ">>> execfile()" appears in the command line, Enter --> script runs again and so on.

2) How to load a .hdf file in a python script, and use the objects stored inside?

In addition to study opening some steps are necessary (but maybe not all, I'm not sure):
salome.myStudy     = salome.myStudyManager.Open( file_name )
salome.myStudyId   = salome.myStudy._get_StudyId()
salome.myStudyName = salome.myStudy._get_Name()
# module activation
meshCompSO         = salome.myStudy.FindComponent("SMESH")
b                  = salome.myStudy.NewBuilder()
b.LoadWith( meshCompSO, smesh.smesh )

3) Is there a place in the documentation where I could have found an answer to these questions?

I have not found a direct answer to question 2) :( , though all needed functions are described (separately) in the doc.

St.Michael

Re: cut a STL surface

Posted by Martin at December 26. 2012

Thanks St.Michael!

 

Any idea why the LyingOnGeom filter doesn't seem to work properly?

I think it's just a bug 

OK. Is there a Bug Tracking System where I should I report that somewhere? Any advice on how to fix the bug?

 

Also, is there no function to directly create a Geometrical triangle from a Mesh triangle?

There is no such a function 

OK. Should I create such function? If yes, where should I put it?


And no function to load a mesh directly, instead of writing/reading a temporary file?

In my script, I used a temporary file just to show how to read an STL file in the Python script. The script can cut any triangular mesh, or even any 2D mesh with a little fix of the script.

I see. But when you create a geom object with sphere_geom = geompy.MakeSphere(etc), is there a way to create a mesh object using e.g. sphere_mesh = smesh.CreateMeshesFromGEOM(sphere_geom)?

 

How to load a .hdf file in a python script, and use the objects stored inside?

In addition to study opening some steps are necessary (but maybe not all, I'm not sure):

salome.myStudy = salome.myStudyManager.Open( file_name )

salome.myStudyId = salome.myStudy._get_StudyId()

salome.myStudyName = salome.myStudy._get_Name()

meshCompSO = salome.myStudy.FindComponent("SMESH")

b = salome.myStudy.NewBuilder()

b.LoadWith( meshCompSO, smesh.smesh )

I see. However, I'm still having issues here. After doing box = salome.myStudy.FindObject("Geom_box"), if I do geompy.MakeCDG(box) I get some weird error message. What do I have to do exactly to get geom/mesh objects from an hdf file and manipulate them?

 

One more question: In the KERNEL documentation, I find a lot of "See exampleXX for an example of this method usage in batchmode of SALOME application.", where can I find these exampleXX?!

 

Thanks again so much for your continuing help, even in such busy times. Hopefully soon I'll be fluent in Salome, and I'll be able to contribute!

 

Martin

Re: cut a STL surface

Posted by Saint Michael at December 28. 2012

Hi Martin

Previously Martin wrote:

I think it's just a bug 

OK. Is there a Bug Tracking System where I should I report that somewhere? Any advice on how to fix the bug?

There is no public BTS. It seems that SALOME team notices bugs reported on this Forum.

There is no such a function 

OK. Should I create such function? If yes, where should I put it?

If you will manage to add a function to GEOM module, I think you can exchange your contribution via this Forum as well.

I see. But when you create a geom object with sphere_geom = geompy.MakeSphere(etc), is there a way to create a mesh object using e.g. sphere_mesh = smesh.CreateMeshesFromGEOM(sphere_geom)?

The main purpose of the whole MESH module is creation of meshes from geom objects.

I see. However, I'm still having issues here. After doing box = salome.myStudy.FindObject("Geom_box"), if I do geompy.MakeCDG(box) I get some weird error message. What do I have to do exactly to get geom/mesh objects from an hdf file and manipulate them?

You can find an answer by reading this my post  http://www.salome-platform.org/forum/forum_10/638257047#206420738

One more question: In the KERNEL documentation, I find a lot of "See exampleXX for an example of this method usage in batchmode of SALOME application.", where can I find these exampleXX?!

At the top of documentation page there is "Examples" button. 

Thanks again so much for your continuing help, even in such busy times. Hopefully soon I'll be fluent in Salome, and I'll be able to contribute!

I hope for your help in answering questions on this Forum! 

St.Michael

 

 

Re: cut a STL surface

Posted by Martin at January 06. 2013

I see. However, I'm still having issues here. After doing box = salome.myStudy.FindObject("Geom_box"), if I do geompy.MakeCDG(box) I get some weird error message. What do I have to do exactly to get geom/mesh objects from an hdf file and manipulate them?

You can find an answer by reading this my post  http://www.salome-platform.org/forum/forum_10/638257047#206420738

Thanks a lot, St.Michael! Actually, using this post, I was able to correctly load the geometrical object:
 
import salome
import geompy, GEOM
import smesh, SMESH
 
salome.salome_init()
 
salome.myStudy     = salome.myStudyManager.Open("study.hdf")
salome.myStudyId   = salome.myStudy._get_StudyId()
salome.myStudyName = salome.myStudy._get_Name()
 
myGeomComp      = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM")._narrow(GEOM.GEOM_Gen)
myStudyGeomComp = salome.myStudy.FindComponent('GEOM')
myStudyBuilder  = salome.myStudy.NewBuilder()
myStudyBuilder.LoadWith(myStudyGeomComp, myGeomComp)
 
myStudyBox = salome.myStudy.FindObject("box")
myGeomBox  = myStudyBox.GetObject()._narrow(geompy.GEOM.GEOM_Object)
 
Not straightforward, but it seems to work. However, when I try the same for a mesh object, e.g.:
 
myStudySurface = salome.myStudy.FindObject("surface")
myMeshSurface  = myStudySurface.GetObject()
 
I get a None object. What's the right way to do so?
 
Thanks again!
 
Martin
 

Re: cut a STL surface

Posted by SMESH expert at January 09. 2013
Hello Martin
myStudySurface = salome.myStudy.FindObject("surface")
myMeshSurface  = myStudySurface.GetObject()
 
I get a None object. What's the right way to do so?
It seems you have not loaded Mesh module data. I mean you have not called the following commands

meshCompSO = salome.myStudy.FindComponent("SMESH")
b = salome.myStudy.NewBuilder()
b.LoadWith( meshCompSO, smesh.smesh )

Best regards

Edward

Re: cut a STL surface

Posted by Martin at January 11. 2013

Indeed! Thanks so much, Edward! :) Martin

Powered by Ploneboard
Document Actions