further curve confusion

Discussions concerning programming of SOFTIMAGE©
Post Reply
janrogowski
Posts: 6
Joined: 04 Jul 2013, 16:56

further curve confusion

Post by janrogowski » 05 Jul 2013, 16:00

This is really puzzling me. Code below allows the user to select an isopoint on a curve and places a null constrained to the curve in the correct location thanks to pulling a u value from the isopoint. All fine and well. Now I want to convert that to a percentage value along the curve in order that I can add a controlpoint to the curve in the correct spot. So, I convert the normalised u value to an actual u value with 'GetUFromNormalizedU' and I feed this in to 'getPercentageFromU' but it doesn't appear to return the correct percentage values. In fact it's wildly off. I think it's because the return from 'GetUFromNormalizedU' is wrong.

Code: Select all

//FIRST DRAW A CURVE!!!
var crv = dictionary.getobject("crvlist");
FreezeObj(crv, null, null);

SelectObj(crv);	
SetSelFilter("Isopoint");

//pick a point on the curve
var rtn = PickElement("isopoint");
var button = rtn.Value("ButtonPressed");
var iso = rtn.Value("PickedElement");

//get the percentage of the isopoint on the curve (0-1)
if (button!=0)
{
	var e = iso.SubElements2.toArray();		
	var normU = e[1];

	var U = crv.ActivePrimitive.Geometry.Curves(0).GetUFromNormalizedU(normU);
	var P = crv.ActivePrimitive.Geometry.Curves(0).getPercentageFromU(U);
}

//display percentage
LogMessage("ISOPOINT: "+iso);
LogMessage("normU: "+normU);
LogMessage("U: "+U);
LogMessage("P: "+P);


//put null on curve using normU got from isopoint selection
var nul = Application.ActiveProject.ActiveScene.Root.addnull();
ApplyCns("Curve", nul, crv, null);
SetValue(nul+".kine.crvcns.posu", normU, null);

In my attempts to debug this I found the following post which would seem to suggest that all is not what it seems with these functions: https://groups.google.com/forum/#!topic ... -yazJigXyE but try as I might I can't get the solution suggested here (divide by length of curve) to work.

I have also tried this code:

Code: Select all

set oRoot = Application.ActiveProject.ActiveScene.Root
set oArc = oRoot.AddGeometry( "Arc", "NurbsCurve" )
UValue = oArc.ActivePrimitive.Geometry.Curves(0).GetUFromNormalizedU( 0.7 )
LogMessage "The equivalent to the normalized U: 0.7 is U :" &  UValue

normUValue = oArc.ActivePrimitive.Geometry.Curves(0).GetNormalizedUFromU( UValue )
LogMessage "Normalized back it is:" & normUValue
The top half is taken directly from SI wiki examples. But when I try to run the inverse operation, normalising back doesn't get me to where I started. Confusing.


-

User avatar
rray
Moderator
Posts: 1775
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: further curve confusion

Post by rray » 05 Jul 2013, 16:55

I didn't get the wrong percentage values (but could try only with curves created with the draw tools)
To test the %ages I added this to the bottom of the first code

Code: Select all

var nul2 = Application.ActiveProject.ActiveScene.Root.addnull();
ApplyCns("Path", nul2, crv, null);
SetValue(nul2+".kine.pathcns.perc", P, null);
Does using reparameterize help anything?
softimage resources section updated Jan 5th 2024

janrogowski
Posts: 6
Joined: 04 Jul 2013, 16:56

Re: further curve confusion

Post by janrogowski » 05 Jul 2013, 17:19

That's odd. If I draw a curve like below:

Image

And run the following code:

Code: Select all

//FIRST DRAW A CURVE!!!
var oCrv = dictionary.getobject("crvlist");
var crv = oCrv.ActivePrimitive.Geometry.Curves(0);
FreezeObj(oCrv, null, null);

SelectObj(oCrv);	
SetSelFilter("Isopoint");

//pick a point on the curve
var rtn = PickElement("isopoint");
var button = rtn.Value("ButtonPressed");
var iso = rtn.Value("PickedElement");

//get the percentage of the isopoint on the curve (0-1)
if (button!=0)
{
	var e = iso.SubElements2.toArray();		
	var normU = e[1];

	var U = crv.GetUFromNormalizedU(normU);
	var P = crv.getPercentageFromU(U);
}

//display percentage
LogMessage("ISOPOINT: "+iso);
LogMessage("normU: "+normU);
LogMessage("U: "+U);
LogMessage("P: "+P);

//put null on curve using normU got from isopoint selection
var nul = Application.ActiveProject.ActiveScene.Root.addnull();
ApplyCns("Curve", nul, oCrv, null);
SetValue(nul+".kine.crvcns.posu", normU, null);

//put null on curve using perc got from isopoint selection
var nul2 = Application.ActiveProject.ActiveScene.Root.addnull();
ApplyCns("Path", nul2, oCrv, null);
SetValue(nul2+".kine.pathcns.perc", P, null);
I get the null positions you can see in the image. The percentage value is way off.

janrogowski
Posts: 6
Joined: 04 Jul 2013, 16:56

Re: further curve confusion

Post by janrogowski » 05 Jul 2013, 17:24

Reparametrizing shouldn't do anything as I would have thought the methods for interrogating U values and deriving percentage values should take that into account. I did try changing the curve's parameterization and couldn't see a solution there...

User avatar
rray
Moderator
Posts: 1775
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: further curve confusion

Post by rray » 05 Jul 2013, 17:33

Ok getting this too now in 2013 SP1, in 2014 SP1 it worked nicely. Appears to be a bug that was fixed,

edit. Aha: http://images.autodesk.com/adsk/files/s ... e-2014.htm

SOFT-1658 NurbsCurve.GetUFromNormalizedU is not returning the correct value.
softimage resources section updated Jan 5th 2024

janrogowski
Posts: 6
Joined: 04 Jul 2013, 16:56

Re: further curve confusion

Post by janrogowski » 05 Jul 2013, 17:40

That's a relief!

Just tested on 2014 and it worked fine. Thanks for the help!

Post Reply

Who is online

Users browsing this forum: No registered users and 48 guests