[surface].segment(uo,u1,v0,v1) appears to have changed

Need help, or want to share a macro? Post here!
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

[surface].segment(uo,u1,v0,v1) appears to have changed

Postby emills2 » Sat Mar 07, 2020 2:40 am

in

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19591 (Git)
Build type: Release
Branch: master
Hash: 27771fc6ee93170b6ecb978ff4da438a5b9cfe97
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)

i get the old behavior: a segment of a surface has the same normal as source surface (seen here by it's blue color)
Silk_model_152_0.19.19591.png
Silk_model_152_0.19.19591.png (25.43 KiB) Viewed 221 times
the closest following version i have to test on is

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19697 (Git)
Build type: Release
Branch: master
Hash: 8832356802011bf5d70e9d6f0efa89c47bc70a91
Python version: 3.7.3
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)

and here, the surface segment has a flipped normal compared to the source surface (seen here by its black color)
Silk_model_152_0.19.19697.png
Silk_model_152_0.19.19697.png (25.45 KiB) Viewed 221 times
i already do a lot of orientation checking, so if this change is intended, i could adapt my code to fix it.

Code: Select all

	def execute(self, fp):
		'''Do something when doing a recomputation, this method is mandatory'''
		# get surface
		surface=fp.NL_Surface.Shape.Surface
		# get cutting points from curve
		curve=fp.NL_Curve.Shape.Curve
		p0 = curve.StartPoint
		p1 = curve.EndPoint
		# determine u or v segmentation and get parameter span from cutting points
		param0=surface.parameter(p0)
		print ('param0: ', param0)
		param1=surface.parameter(p1)
		print ('param1: ', param1)
		if ((param0[0]<0.001 and param1[0]<0.001) or (param0[0]>0.999 and param1[0]>0.999)): # if u is constant 0 or constant 1 along curve
			segdir = 'v'
			if param0[1] < param1[1]:
				t0=param0[1]
				t1=param1[1]
			if param0[1] > param1[1]:
				t0=param1[1]
				t1=param0[1]
		if ((param0[1]<0.001 and param1[1]<0.001) or (param0[1]>0.999 and param1[1]>0.999)): # if v is constant 0 or constant 1 along curve
			segdir = 'u'
			if param0[0] < param1[0]:
				t0=param0[0]
				t1=param1[0]
			if param0[0] > param1[0]:
				t0=param1[0]
				t1=param0[0]
		# filter out t0<0 and t1>1 that may occur when the xyz position is projected to uv
		if t0<0:
			t0=0
		if t1>1:
			t1=1

		# create surface segment. this works very nicely most of the time, but! 
		#sometimes .segment returns [[vector],[vector],[vector],[vector]] instead of a whole grid.

		print ('sgdir: ', segdir)
		print ('t0 ', t0)
		print ('t1 ', t1)
		if segdir=='u':
			surface.segment(t0,t1,0,1)
		if segdir=='v':
			surface.segment(0,1,t0,t1) # 
but i really hope the output of segment has not become random, that would be hard to deal with.

this is the same file. going back and forth between freeCAD versions shows consistent behavior: always flipped in one version, and always correct in the older version.

file attached. requires silk addon to recompute.

any help in clarifying the situation with segment() greatly appreciated. if this counts as a bug, i'm not sure where to report it.
Attachments
Silk_model_152.FCStd
(48.32 KiB) Downloaded 12 times
wmayer
Site Admin
Posts: 16649
Joined: Thu Feb 19, 2009 10:32 am

Re: [surface].segment(uo,u1,v0,v1) appears to have changed

Postby wmayer » Sat Mar 07, 2020 3:07 pm

emills2 wrote:
Sat Mar 07, 2020 2:40 am
any help in clarifying the situation with segment() greatly appreciated. if this counts as a bug, i'm not sure where to report it.
In FreeCAD nothing has changed with respect to orientation of a segment of a surface.

What has changed is that there is now an option to set One-side or Two-side rendering for Part objects in the user preferences. The previous default behaviour was Two -side rendering and has become One-side rendering for now. Would this explain the behaviour you have observed?
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

Re: [surface].segment(uo,u1,v0,v1) appears to have changed

Postby emills2 » Sat Mar 07, 2020 11:26 pm

wmayer wrote:
Sat Mar 07, 2020 3:07 pm
The previous default behaviour was Two -side rendering and has become One-side rendering for now. Would this explain the behaviour you have observed?
maybe. it's hard to say right now, because not at the same computer with the same versions to test with.

I have done a lot of work to track orientation, because when i join two surfaces at a common edge, the surface normals have to agree. otherwise some operations will 'twist' to produce a set of surfaces with continuous normal across the edges. i have seen this problem and dealt with it before, so i thought i understood the parameters of the situation.

i always go back and forth between one-sided and two-sided, in order to, respectively, ensure continuity, and visualize the flip side.

but once we achieve proper on-side rendering, whether forced or by default, the same confusing situation occurs:

i have a source surface, with its normal pointing one way.

i create a segment surface from the source surface, and it's normal is pointed opposite.

(in the pictures, the segment was moved -500 in y so we can see both surfaces without artifacts)

OS: Ubuntu 18.04.4 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19066 (Git) AppImage
Build type: Release
Branch: master
Hash: c766d757912ded11d41bc825f82c47a8428396ad
Python version: 3.7.6
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)
Screenshot from 2020-03-07 14-36-42.png
Screenshot from 2020-03-07 14-36-42.png (380.55 KiB) Viewed 169 times
Screenshot from 2020-03-07 14-29-15.png
Screenshot from 2020-03-07 14-29-15.png (349.3 KiB) Viewed 169 times
is it expected that a segment of a surface will have flipped normal orientation in relation to the surface it was segmented from?

i went back to an older model and checked its segments, they appear to have identical normals. in pics below:
-top blue surface is segment of transparent pink surface
-blue and pink render from top
-neither render from bottom
Screenshot from 2020-03-07 15-11-40.png
Screenshot from 2020-03-07 15-11-40.png (686.19 KiB) Viewed 169 times
Screenshot from 2020-03-07 15-12-38.png
Screenshot from 2020-03-07 15-12-38.png (475.92 KiB) Viewed 169 times
This is the old behavior. in this case, even after a forced recompute of the object that calls segment(), the normals stay aligned.

so in one case, segment returns a normal that agrees withthe source surface, in one case it does not.

the only difference between the two case is the FreeCAD version they were riginally created in, and the difference appears to persist even after recomputing in different FreeCAD versions.
emills2
Posts: 631
Joined: Tue Apr 28, 2015 11:23 pm

Re: [surface].segment(uo,u1,v0,v1) appears to have changed

Postby emills2 » Sat Mar 07, 2020 11:49 pm

emills2 wrote:
Sat Mar 07, 2020 11:26 pm
the only difference between the two case is the FreeCAD version they were riginally created in, and the difference appears to persist even after recomputing in different FreeCAD versions.
correction: not version dependent.

i redid the modeling operation to produce the segment in


OS: Ubuntu 18.04.4 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.19066 (Git) AppImage
Build type: Release
Branch: master
Hash: c766d757912ded11d41bc825f82c47a8428396ad
Python version: 3.7.6
Qt version: 5.12.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/United States (en_US)

and it also returned a flipped segment
Screenshot from 2020-03-07 15-44-59.png
Screenshot from 2020-03-07 15-44-59.png (457.92 KiB) Viewed 163 times
so it appears that it might be input dependent.

i will need to test much deeper, but the behavior of segment() appears unpredictable for output surface orientation.

[edit] OR, my code is screwing up something, very very possible. my goal here is simply to understand how to use segment() correctly, not to have others fix my mistakes.

unfortunately, i have to use my workbench to produce examples, since there is no simple segmentation tool available without it in basic FreeCAD. or is there?