Personal tools
You are here: Home Forum Use sorting in the TUI

sorting in the TUI

Up to Use

sorting in the TUI

Posted by Chaz at May 22. 2012

I am unable to find documentation on how sorting works when using python TUI.

The phrase "sorted by center of mass" is used in some of the documentation.

p, li { white-space: pre-wrap; }

geompy.ExtractShapes for example appears to sort the shapes returned first by the x position of the center of mass. If more than one object have the same x position of the center of mass, then it looks like it sorts them by the y position of the center of mass, lowest value first. I would assume, then that in the case of matching x and y, the sort looks at z. Is this documented anywhere?

 

p, li { white-space: pre-wrap; }

My bigger challenge is RotationSweepObject2D. The resulting groups that are reported do not appear to be sorted in any logical way, and are certainly not sorted as ExtractShapes as noted above. In order to program a mesh using python, I need to know the order of the groups reported so that they can be properly labeled for export. What is the sorting used, or how can they be identified after the use of RotationSweepObject2D?

Thank you

 

Re: sorting in the TUI

Posted by Saint Michael at May 22. 2012

Hi

What is the sorting used, or how can they be identified after the use of RotationSweepObject2D?

You can identify groups by their names. A name of new group = a name of original group + "_rotated" postfix.

St.Michael

Re: sorting in the TUI

Posted by Ivo Plamenac at June 13. 2012

Hi. St.  Michael,

I am currently working on this problem with Chaz. We have made some progress although we seem to hit a bit of a snag when renaming components. Please find attached our script; it is ready to run in Salome.

We have confirmed that the program does assign names to the components based on the x-component of the center of mass, and then by the y-component for pieces with the same x-component value. Thus with the three pieces in our sample script there is a 0-, 1-, and 2-component. You were correct; the component names are then appended to read 0_rotated, 1_rotated, and 2_rotated. We wrote a script then to sort our parts by this convention so that we could rename the components with more appropriate names. When the program executes (despite the convention it used to assign numbers) the order has been rearranged.

In our sample script, if you comment out the last few lines were we reassign names, you will see the order of the components in our "meshVolumeGroups" list is [0_rotated, 2_rotated, 1_rotated], thus when we try to reassign names using SetName, the components appear with the incorrect names. The order of ascending x-component center of mass however has been confirmed to be 0_rotated -> 1_rotated -> 2_rotated.

After running/reading through the script you will see that two of our component names get switched around.

Any help or insight you can provide on our problem would be much appreciated. Thank you.

Attachments

Re: sorting in the TUI

Posted by Saint Michael at June 13. 2012

Hi

I have adjusted your nice script. My fix has a limitation, it is valid for 1-digit group names, i.e. it's OK for group name like "1_rotated" but KO for "11_rotated".

St.Michael

Attachments

Re: sorting in the TUI

Posted by Ivo Plamenac at June 13. 2012

Works perfectly. Thank you!

Previously Saint Michael wrote:

Hi

I have adjusted your nice script. My fix has a limitation, it is valid for 1-digit group names, i.e. it's OK for group name like "1_rotated" but KO for "11_rotated".

St.Michael

 

Re: sorting in the TUI

Posted by Chaz at July 19. 2012

Hello,

We have been using the method that Saint Michael recommended, and have extended it to more than 9 groups by removing the '_rotated' from the name.

Now that we are building some larger models, Salome is now not behaving in a predictable manner when it returns exploded subshapes, for example from geompy.ExtractShapes(fuse, geompy.ShapeType["FACE"], True).

Generally, the order has been based on the x position of the center of mass, then sorted by the y position of the center of mass.  This allows the order to be predicted, and allows mesh groups then to be named for export as unv.  Salome is not behaving in a predicable manner for larger models, making it imposible(?) to use when assignment of groups via TUI is needed.

The attached image is from a model that has 38 groups, but only 6 are shown. All groups are symmetric. The order that the objects were returned should be by x position of center of mass: Blueleft, Redleft, greenleft, greenright, redright, blueright.  However, as shown in the image, the order is not consistent left to right, and is not following.  The order reported is Redleft, blueleft, greenleft, greenright, redright, blueright.

There should not be this type of randomness in the order.  Is there a way to predict the order that items are returned?

In cfdrc ace, there is a function to select objects by a given x,y,z position, then they could be renamed or otherwise operated on.  This looks to be sorely needed, and would be a quick and easy solution to this issue.  There would be no need to struggle to predict the order that a Salome command may return objects.

Any advice?

Attachments

Re: sorting in the TUI

Posted by Saint Michael at July 19. 2012

Hello

In geompy there is a set of functions to find a face, seeming suitable for your task:

 def GetFaceNearPoint(self, theShape, thePoint):
 def GetFaceByPoints(self,theShape, thePoint1, thePoint2, thePoint3, thePoint4):
 def GetFaceByEdges(self,theShape, theEdge1, theEdge2):
 def GetShapesNearPoint(self, theShape, thePoint, theShapeType, theTolerance = 1e-07):
St.Michael

Re: sorting in the TUI

Posted by Chaz at July 19. 2012

Thank you, We will look into those functions to see if they can help.

 

Re: sorting in the TUI

Posted by Ivo Plamenac at July 20. 2012

Hi Saint Michael,

I would like to use GetFaceByPoints but I do not quite understand the inputs.

As in the picture posted above, we have a collection of 38 faces. I would like to grab a face by its 4 corner points and then assign a name to it.

For example, the code I have now is:

for i in range(38):

    face = geompy.GetFaceByPoints( theShape, point1[i], point2[i], point3[i], point4[i])

    face.SetName(someListofNames[i])

I am not certain what I should input for "theShape" if I want to grab a particular face from the 38 we have constructed.

Any help would be appreciated, thank you.

Re: sorting in the TUI

Posted by Ivo Plamenac at July 20. 2012

Also it seems that all the functions you recommended may only work to find faces from 3 dimensional objects (is this what blocks or compound blocks refers to?)?

Is there anyway to identify a face by certain points among only 2 dimension objects (i.e. 38 defined faces no 3D objects)?

Thanks.

Re: sorting in the TUI

Posted by Saint Michael at July 20. 2012

Hello Ivo,

theShape in those functions is a shape including a face one need to find. For example in sortingproblem.py faces of interest are included in 'fuse':

faceList = geompy.ExtractShapes(fuse, geompy.ShapeType["FACE"], True)

Then you are to call:

  face = geompy.GetFaceByPoints( fuse, point1[i], point2[i], point3[i], point4[i])

 

Previously Ivo Plamenac wrote:

Hi Saint Michael,

I would like to use GetFaceByPoints but I do not quite understand the inputs.

As in the picture posted above, we have a collection of 38 faces. I would like to grab a face by its 4 corner points and then assign a name to it.

For example, the code I have now is:

for i in range(38):

    face = geompy.GetFaceByPoints( theShape, point1[i], point2[i], point3[i], point4[i])

    face.SetName(someListofNames[i])

I am not certain what I should input for "theShape" if I want to grab a particular face from the 38 we have constructed.

Any help would be appreciated, thank you.

 

Re: sorting in the TUI

Posted by Saint Michael at July 20. 2012

Previously Ivo Plamenac wrote:

Also it seems that all the functions you recommended may only work to find faces from 3 dimensional objects (is this what blocks or compound blocks refers to?)?

Is there anyway to identify a face by certain points among only 2 dimension objects (i.e. 38 defined faces no 3D objects)?

Thanks.

 

Yes, theShape in those functions can be of any kind, e.g. a compound or group of faces.

St. Michael

Powered by Ploneboard
Document Actions