Fonctions isSame isEqual isPartner.

Forum destiné aux questions et discussions en français
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Post Reply
Siardéni
Posts: 6
Joined: Sat Jun 13, 2015 8:06 am

Fonctions isSame isEqual isPartner.

Post by Siardéni »

Bonjour,

Dans une Macro je compare des éléments entre eux pour reconnaître ceux qui sont identiques. Je m’en sors en comparants les coordonnées, les « boundbox », etc, mais je me demande si je ne pourrais pas utiliser les fonctions, « isEqual », « isPartner » ou « isPartner ». Mais je n'arrive pas à comprendre leur fonctionnement. Elles me renvoient toujours un « False» même sur des éléments identiques (cf. code ci-dessous). Peut-être même qu’elles ne servent pas à faire ce que je crois qu’elle pourrait faire !!

Est-ce que quelqu’un les a déjà utilisées ?

Sinon, je profite de ce post et suite à un précédent message où rockn évoque un outil pour reconnaître les poutres de bois, pour diffuser un lien vers mon dépôt github où j'ai commencé a créer une macro qui reconnaît également les poutres et les plaques mais qui est plus orientée chaudronnerie. Je serais curieux de comparer les deux méthodes de reconnaissance quand rockn diffusera son travail.

Macro « 01AnalyseSolides.FCMacro »dans le dossier Macros

https://github.com/Siardeni/FreeCADTools

Plus généralement, FreeCADTools est un atelier perso que j'ai créé au fil du temps depuis quelques années maintenant et que j'utilise presque au quotidien dans mon boulot de dessinateur. J'ai « volé » des idées à droite à gauche dans les ateliers et les macros existantes déjà diffusées, les ateliers de yorick bien sur et la macro Work Feature de rentlau_64 notamment, merci à eux.
Il est évident que tous ces outils peuvent être bugés et où un peu bancales je progresse petit à petit avec python et github…
Je laisse ceux qui le souhaitent découvrir les quelques outils pour beaucoup perfectibles et je reste bien sur ouverts aux conseils, commentaires et autres questions.

Salutations,

Code: Select all

>>> a=Part.makeBox(10,10,10)
>>> b=Part.makeBox(10,10,10)
>>> a.isEqual(b)
False
>>> b.isEqual(a)
False
>>> b.isEqual(b)
True
>>> b.isPartner(a)
False
>>> b.isPartner(b)
True
>>> b=a.copy()
>>> b.isPartner(a)
False
>>> b.isEqual(a)
False
>>> b.isSame(a)
False
>>> b.isSame(b)
True
>>> a=Part.makeLine((1.,2.,3.),(4.,5.,6.))
>>> b=Part.makeLine((1.,2.,3.),(4.,5.,6.))
>>> c=a.copy()
>>> a.isEqual(b)
False
>>> a.isEqual(c)
False
>>> b.isEqual(c)
False
>>> a.isSame(b)
False
>>> b.isSame(c)
False
>>> a.isSame(c)
False
>>> a
<Edge object at 0F146BB0>
>>> a.isSame(a)
True

Code: Select all

a=Part.makeBox(10,10,10)
b=Part.makeBox(10,10,10)
a.isEqual(b)
b.isEqual(a)
b.isEqual(b)
b.isPartner(a)
b.isPartner(b)
b=a.copy()
b.isPartner(a)
b.isEqual(a)
b.isSame(a)
b.isSame(b)
a=Part.makeLine((1.,2.,3.),(4.,5.,6.))
b=Part.makeLine((1.,2.,3.),(4.,5.,6.))
c=a.copy()
a.isEqual(b)
a.isEqual(c)
b.isEqual(c)
a.isSame(b)
b.isSame(c)
a.isSame(c)
a
a.isSame(a)



OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 32-bit
Version: 0.16.5354 (Git)
Build type: Release
Branch: master
Hash: 15d7369de823f0789e1abaa5e4d26fe80d2cd751
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Fonctions isSame isEqual isPartner.

Post by ickby »

Hello,

Je travaille avec le traducteur Google . Les fonctions que vous avez testés ne sont pas utilisés pour comparer la géométrie ! Ils sont utilisés pour calssify le partage de la topologie interne de forme . Une forme se compose d'un TShape (la topologie réelle ) , un lieu ( le placement ) et une orientation (pour exampl direction d'un bord ) . Formes multiples peuvent partager le même TShape pour réduire la mémoire foodprint . Cela arrive souvent pour les fonctions qui sont de construire sur un annother , par exemple un chanfreinées actions de forme très nombreuses formes secondaires avec la forme originale sans chanfrein . Les fonctions que vous avez testés sont maintenant utilisés pour trouver le type de partage :
  • isEqual : true si les deux formes partagent la même TShape , avoir le même endroit et ont la même orientation
  • isSame : true si les deux formes partagent la même TShape , avoir le même endroit, mais peut avoir une orientation différente
  • isPartner : true si les deux formes partager le même TShape , mais peuvent avoir un emplacement différent et peuvent avoir une orientation différente
I work with google translator. The functions you tested are not used to compare geometry! They are used to calssify the shape internal topology sharing. A shape consists of a TSHape (the actual topology), a location (the placement) and a orientation (for exampl direction of a edge). Multiple shapes can share the same TShape to reduce memory foodprint. This often happens for features which are build on one annother, for example a chamfered shape shares many many subshapes with the original unchamfered shape. The functions you tested are now used to find the kind of sharing:
  • isEqual: true if both shapes share the same TShape, have the same Location and have the same Orientation
  • isSame: true if both shapes share the same TShape, have the same Location but may have a different Orientation
  • isPartner: true if both shapes share the same TShape, but may have a different Location and may have a different Orientation
Siardéni
Posts: 6
Joined: Sat Jun 13, 2015 8:06 am

Re: Fonctions isSame isEqual isPartner.

Post by Siardéni »

Merci ickby, et merci d’avoir fait le détour par le forum français je vais également essayé de traduire ma réponse.

Effectivement je n'avais pas bien compris le fonctionnement de ces fonctions. Mais elles vont m’être très utile puisque je voulais analyser les arêtes communes entre faces dans un solide. Par contre il reste une subtilité que je n'explique pas.

Code: Select all

f=Part.makeBox(10,10,10)
g=f.makeChamfer(1.0,[f.Edges[0]])

Part.show(f)
Part.show(g)

for facef in f.Faces:
	for faceg in g.Faces:
		if facef.isEqual(faceg):
		Part.show(facef)

il y a deux faces partagées entre ces deux solides, les deux seules qui n'ont pas été modifiées par le chanfrein.
Ok pour ce cas par contre :

Code: Select all

f=Part.makeBox(10,10,10)
g=f.makeChamfer(1.0,[f.Edges[0]])

Part.show(f)
Part.show(g)

Part.show(g.Edges[0])

for face in g.Faces:
	for edge in face.Edges:
		if g.Edges[0].isEqual(edge):
			Part.show(face)
			print "1"
		elif g.Edges[0].isSame(edge):
			Part.show(face)
			print "2"
		elif g.Edges[0].isPartner(edge):
			Part.show(face)
			print "3"



Dans ce cas la face « 1 » contient l'arête « edges[0] » et la face « 2 » contient la même arête avec une orientation différente, pourtant c'est la même orientation ? Pourquoi il n’y a pas de retour avec isPartner ?

Il faudra que j'utilise encore ces fonctions plusieurs fois pour comprendre le fonctionnement.

Siardéni.




Ickby thank you, and thank you for making a visit in the French forum I also tried to translate my answer.

Actually I had not understood functioning of these functions. But they are very useful because I myself wanted to analyze the common edges between faces in a solid. By cons there is a subtlety that I can not explain.

Code: Select all

f=Part.makeBox(10,10,10)
g=f.makeChamfer(1.0,[f.Edges[0]])

Part.show(f)
Part.show(g)

for facef in f.Faces:
	for faceg in g.Faces:
		if facef.isEqual(faceg):
		Part.show(facef)



there are two faces shared between these two solids, the only two that have not been modified by the chamfer.
Ok for this case by against:

Code: Select all

f=Part.makeBox(10,10,10)
g=f.makeChamfer(1.0,[f.Edges[0]])

Part.show(f)
Part.show(g)

Part.show(g.Edges[0])

for face in g.Faces:
	for edge in face.Edges:
		if g.Edges[0].isEqual(edge):
			Part.show(face)
			print "1"
		elif g.Edges[0].isSame(edge):
			Part.show(face)
			print "2"
		elif g.Edges[0].isPartner(edge):
			Part.show(face)
			print "3"



In this case the face "1" contains the edge "edges [0]" and face "2" contains the same edge with a different orientation, yet it is the same orientation? Why there is no returns with isPartner?

I must still use these functions multiple times to understand the operation.

Siardéni
Attachments
Code 1
Code 1
04.png (27.8 KiB) Viewed 1982 times
Code 2
Code 2
06.png (31.33 KiB) Viewed 1982 times
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: Fonctions isSame isEqual isPartner.

Post by ickby »

Hello,

I recommend to read this blog entry and all the following with the same topic: http://opencascade.blogspot.de/2009/02/ ... scade.html
In this case the face "1" contains the edge "edges [0]" and face "2" contains the same edge with a different orientation, yet it is the same orientation?
Apparently they have not the same orientation. You cannot use the visual as indication, it is quite possible that one facees outer wire has a left-tourning orientation while he other has a right-tourning outer wire. They would both uise the shared edge, but the edge would than have a different orientation in the shape. That is actually why TShape, Orientation and Location are splitted and treated individual.
Why there is no returns with isPartner?
Because of your else-if statement. As the first face is treated by isEqual and the second by isSame the call to isPartner is never issued for the two sharing faces. But isPartner should return 'True' for both faces (as well as isSame)
Siardéni
Posts: 6
Joined: Sat Jun 13, 2015 8:06 am

Re: Fonctions isSame isEqual isPartner.

Post by Siardéni »

Hello,

Thank you for these explanations, I realized my mistake with elif. Below is the code more in line with what I was looking for.

Siardéni


------------------------------------------------


Bonjour,

Merci pour ces explications, j'ai compris mon erreur avec les elif, ci-dessous le code plus conforme à ce que je cherchais.

Siardéni



Code: Select all

f=Part.makeBox(10,10,10)
g=f.makeChamfer(1.0,[f.Edges[0]])

Part.show(f)
Part.show(g)

Part.show(g.Edges[0])

for face in g.Faces:
	for edge in face.Edges:
		print"---------"
		if g.Edges[0].isEqual(edge):
			Part.show(face)
			print "1"
		if g.Edges[0].isSame(edge):
			Part.show(face)
			print "2"
		if g.Edges[0].isPartner(edge):
			Part.show(face)
			print "3"
User avatar
rockn
Veteran
Posts: 1791
Joined: Wed Sep 28, 2011 10:39 am
Location: Toulouse, France
Contact:

Re: Fonctions isSame isEqual isPartner.

Post by rockn »

Ola !
Siardéni wrote:Je serais curieux de comparer les deux méthodes de reconnaissance quand rockn diffusera son travail.
C'est sortit du carton :D
viewtopic.php?f=12&t=12559
Formations - Assistance - Développement : https://freecad-france.com
Post Reply