Edit Curve XSec Functions

Functions for modifying XSecs of type XS_EDIT_CURVE are defined here.

EditXSecInitShape(xsec_id)

Initialize the EditCurveXSec to the current value of m_ShapeType (i.e. EDIT_XSEC_ELLIPSE).

EditXSecConvertTo(xsec_id, newtype)

Convert the EditCurveXSec curve type to the specified new type.

GetEditXSecUVec(xsec_id)

Get the U parameter vector for an EditCurveXSec.

GetEditXSecCtrlVec(xsec_id[, non_dimensional])

Get the control point vector for an EditCurveXSec.

SetEditXSecPnts(xsec_id, u_vec, control_pts, ...)

Set the U parameter vector and the control point vector for an EditCurveXSec.

EditXSecDelPnt(xsec_id, indx)

Delete an EditCurveXSec control point.

EditXSecSplit01(xsec_id, u)

Split the EditCurveXSec at the specified U value

MoveEditXSecPnt(xsec_id, indx, new_pnt)

Move an EditCurveXSec control point.

ConvertXSecToEdit(geom_id[, indx])

Convert any XSec type into an EditCurveXSec.

GetEditXSecFixedUVec(xsec_id)

Get the vector of fixed U flags for each control point in an EditCurveXSec.

SetEditXSecFixedUVec(xsec_id, fixed_u_vec)

Set the vector of fixed U flags for each control point in an EditCurveXSec.

ReparameterizeEditXSec(xsec_id)

Perform an equal arc length repareterization on an EditCurveXSec.

Details

openvsp.EditXSecInitShape(xsec_id)[source]

Initialize the EditCurveXSec to the current value of m_ShapeType (i.e. EDIT_XSEC_ELLIPSE)

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 2, XS_EDIT_CURVE )

# Identify XSec 2
xsec_2 = GetXSec( xsec_surf, 2 )

# Set XSec 2 to linear
EditXSecConvertTo( xsec_2, LINEAR )

linear_pts = GetEditXSecCtrlVec( xsec_2, True )

EditXSecInitShape( xsec_2 ) # Change back to default ellipse

Update()

# The default ellipse is a four point Bezier, so it carries more control
# points than the linear square it replaced.
ellipse_pts = GetEditXSecCtrlVec( xsec_2, True )

assert len( ellipse_pts ) >= 4 and ( len( ellipse_pts ) - 1 ) % 3 == 0, "EditXSecInitShape did not restore a cubic Bezier"
assert len( ellipse_pts ) > len( linear_pts ), "EditXSecInitShape did not rebuild the control points"

# The ellipse is symmetric about both axes, so it stays inside the unit box
# the control points are normalized to.
for p in ellipse_pts:
    assert abs( p.x() ) <= 0.5 + 1e-9, "the rebuilt shape is not normalized"
    assert abs( p.y() ) <= 0.5 + 1e-9, "the rebuilt shape is not normalized"

See also: INIT_EDIT_XSEC_TYPE :param [in]: xsec_id string XSec ID

openvsp.EditXSecConvertTo(xsec_id, newtype)[source]

Convert the EditCurveXSec curve type to the specified new type. Note, EditCurveXSec uses the same enumerations for PCurve to identify curve type, but APPROX_CEDIT is not supported at this time.

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 1, XS_EDIT_CURVE )

# Identify XSec 1
xsec_1 = GetXSec( xsec_surf, 1 )

# The default shape is a Bezier ellipse, stored in groups of three plus a
# closing point.
bezier_pts = GetEditXSecCtrlVec( xsec_1, True )

assert len( bezier_pts ) >= 4 and ( len( bezier_pts ) - 1 ) % 3 == 0, "the edit curve did not start out as a cubic Bezier"

# Set XSec 1 to Linear
EditXSecConvertTo( xsec_1, LINEAR )

Update()

# A linear curve needs no interior control points, so the conversion drops
# them: the ellipse keeps only the points that were on the curve.
linear_pts = GetEditXSecCtrlVec( xsec_1, True )

assert len( linear_pts ) == ( len( bezier_pts ) - 1 ) // 3 + 1, "EditXSecConvertTo did not drop the interior control points"

# Converting back has to put them back.
EditXSecConvertTo( xsec_1, CEDIT )

Update()

assert len( GetEditXSecCtrlVec( xsec_1, True ) ) == len( bezier_pts ), "EditXSecConvertTo would not convert back"

See also: PCURV_TYPE :param [in]: xsec_id string XSec ID :param [in]: newtype int New curve type enum (i.e. CEDIT)

openvsp.GetEditXSecUVec(xsec_id)[source]

Get the U parameter vector for an EditCurveXSec. The vector will be in increasing order with a range of 0 - 1.

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 2, XS_EDIT_CURVE )

# Identify XSec 2
xsec_2 = GetXSec( xsec_surf, 2 )

# Set XSec 2 to linear
EditXSecConvertTo( xsec_2, LINEAR )

u_vec = GetEditXSecUVec( xsec_2 )

if  u_vec[1] - 0.25 > 1e-6 :
    print( "Error: GetEditXSecUVec" )
    assert False, "Error: GetEditXSecUVec"
Parameters:

[in] – xsec_id string XSec ID

Return type:

std::vector< double,std::allocator< double > >

Returns:

vector <double> Array of U parameter values

openvsp.GetEditXSecCtrlVec(xsec_id, non_dimensional=True)[source]

Get the control point vector for an EditCurveXSec. Note, the returned array of vec3d values will be represented in 2D with Z set to 0.

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 1, XS_EDIT_CURVE )

# Identify XSec 1
xsec_1 = GetXSec( xsec_surf, 1 )

# Get the control points for the default shape
xsec1_pts = GetEditXSecCtrlVec( xsec_1, True ) # The returned control points will not be scaled by width and height
assert len( xsec1_pts ) > 0, "GetEditXSecCtrlVec returned nothing"

print( f"Normalized Bottom Point of XSecCurve: {xsec1_pts[3].x()}, {xsec1_pts[3].y()}, {xsec1_pts[3].z()}" )
Parameters:
  • [in] – xsec_id string XSec ID

  • [in] – non_dimensional bool True to get the points non-dimensionalized, False to get them scaled by m_Width and m_Height

Return type:

std::vector< vec3d,std::allocator< vec3d > >

Returns:

vector <vec3d> Array of control points

openvsp.SetEditXSecPnts(xsec_id, u_vec, control_pts, r_vec)[source]

Set the U parameter vector and the control point vector for an EditCurveXSec. The arrays must be of equal length, with the values for U defined in increasing order and range 0 - 1. The input control points to SetEditXSecPnts must be nondimensionalized in the approximate range of [-0.5, 0.5].

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 2, XS_EDIT_CURVE )

# Identify XSec 2
xsec_2 = GetXSec( xsec_surf, 2 )

# Set XSec 2 to linear
EditXSecConvertTo( xsec_2, LINEAR )

# Turn off R/L symmetry
SetParmVal( GetXSecParm( xsec_2, "SymType"), SYM_NONE )

# Define a square
xsec2_pts = [vec3d(0.5, 0.5, 0.0),
         vec3d(0.5, -0.5, 0.0),
         vec3d(-0.5, -0.5, 0.0),
         vec3d(-0.5, 0.5, 0.0),
         vec3d(0.5, 0.5, 0.0)]

# u vec must start at 0.0 and end at 1.0
u_vec = [0.0, 0.25, 0.5, 0.75, 1.0]

r_vec = [0.0, 0.0, 0.0, 0.0, 0.0]

SetEditXSecPnts( xsec_2, u_vec, xsec2_pts, r_vec ) # Note: points are unscaled by the width and height parms

new_pnts = GetEditXSecCtrlVec( xsec_2, True ) # The returned control points will not be scaled by width and height

if  dist( new_pnts[3], xsec2_pts[3] ) > 1e-6 :
    print( "Error: SetEditXSecPnts")
    assert False, "Error: SetEditXSecPnts"
Parameters:
  • [in] – xsec_id string XSec ID

  • [in] – u_vec vector <double> Array of U parameter values

  • [in] – r_vec vector <double> Array of R parameter values

  • [in] – control_pts vector <vec3d> Nondimensionalized array of control points

openvsp.EditXSecDelPnt(xsec_id, indx)[source]

Delete an EditCurveXSec control point. Note, cubic Bezier intermediate control points (those not on the curve) cannot be deleted. The previous and next Bezier control point will be deleted along with the point on the curve. Regardless of curve type, the first and last points may not be deleted.

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 2, XS_EDIT_CURVE )

# Identify XSec 2
xsec_2 = GetXSec( xsec_surf, 2 )

# Turn off R/L symmetry
SetParmVal( GetXSecParm( xsec_2, "SymType"), SYM_NONE )

old_pnts = GetEditXSecCtrlVec( xsec_2, True ) # The returned control points will not be scaled by width and height

EditXSecDelPnt( xsec_2, 3 ) # Remove control point at bottom of circle

new_pnts = GetEditXSecCtrlVec( xsec_2, True ) # The returned control points will not be scaled by width and height

if  len(old_pnts) - len(new_pnts) != 3  :
    print( "Error: EditXSecDelPnt")
    assert False, "Error: EditXSecDelPnt"
Parameters:
  • [in] – xsec_id string XSec ID

  • [in] – indx int Control point index

openvsp.EditXSecSplit01(xsec_id, u)[source]

Split the EditCurveXSec at the specified U value

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 2, XS_EDIT_CURVE )

# Identify XSec 2
xsec_2 = GetXSec( xsec_surf, 2 )

# Turn off R/L symmetry
SetParmVal( GetXSecParm( xsec_2, "SymType"), SYM_NONE )

old_pnts = GetEditXSecCtrlVec( xsec_2, True ) # The returned control points will not be scaled by width and height

new_pnt_ind = EditXSecSplit01( xsec_2, 0.375 )

new_pnts = GetEditXSecCtrlVec( xsec_2, True ) # The returned control points will not be scaled by width and height

if  len(new_pnts) - len(old_pnts) != 3  :
    print( "Error: EditXSecSplit01")
    assert False, "Error: EditXSecSplit01"
Parameters:
  • [in] – xsec_id string XSec ID

  • [in] – u double U value to split the curve at (0 - 1)

Return type:

int

Returns:

int Index of the point added from the split

openvsp.MoveEditXSecPnt(xsec_id, indx, new_pnt)[source]

Move an EditCurveXSec control point. The XSec points are nondimensionalized by m_Width and m_Height and defined in 2D, so the Z value of the new coordinate point will be ignored.

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 1, XS_EDIT_CURVE )

# Identify XSec 1
xsec_1 = GetXSec( xsec_surf, 1 )

# Turn off R/L symmetry
SetParmVal( GetXSecParm( xsec_1, "SymType"), SYM_NONE )

# Get the control points for the default shape
xsec1_pts = GetEditXSecCtrlVec( xsec_1, True ) # The returned control points will not be scaled by width and height

# Identify a control point that lies on the curve and shift it in Y
move_pnt_ind = 3

new_pnt = vec3d( xsec1_pts[move_pnt_ind].x(), 2 * xsec1_pts[move_pnt_ind].y(), 0.0 )

# Move the control point
MoveEditXSecPnt( xsec_1, move_pnt_ind, new_pnt )

new_pnts = GetEditXSecCtrlVec( xsec_1, True ) # The returned control points will not be scaled by width and height

if  dist( new_pnt, new_pnts[move_pnt_ind] ) > 1e-6 :
    print( "Error: MoveEditXSecPnt" )
    assert False, "Error: MoveEditXSecPnt"
Parameters:
  • [in] – xsec_id string XSec ID

  • [in] – indx int Control point index

  • [in] – new_pnt vec3d Coordinate of the new point

openvsp.ConvertXSecToEdit(geom_id, indx=0)[source]

Convert any XSec type into an EditCurveXSec. This function will work for BOR Geoms, in which case the input XSec index is ignored.

# Add Stack
sid = AddGeom( "STACK", "" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( sid, 0 )

ChangeXSecShape( xsec_surf, 1, XS_ROUNDED_RECTANGLE )

# Convert Rounded Rectangle to Edit Curve type XSec
ConvertXSecToEdit( sid, 1 )

# Identify XSec 1
xsec_1 = GetXSec( xsec_surf, 1 )

# Get the control points for the default shape
xsec1_pts = GetEditXSecCtrlVec( xsec_1, True ) # The returned control points will not be scaled by width and height

# The section is an edit curve carrying a closed cubic Bezier, normalized to
# the unit box.
assert GetXSecShape( xsec_1 ) == XS_EDIT_CURVE, "the section is not an edit curve"
assert len( xsec1_pts ) >= 4, "the edit curve carries too few control points"
assert dist( xsec1_pts[0], xsec1_pts[-1] ) < 1e-9, "the edit curve does not close"
Parameters:
  • [in] – geom_id string Geom ID

  • [in] – indx int XSec index

openvsp.GetEditXSecFixedUVec(xsec_id)[source]

Get the vector of fixed U flags for each control point in an EditCurveXSec. The fixed U flag is used to hold the U parameter of the control point constant when performing an equal arc length reparameterization of the curve.

# Add Wing
wid = AddGeom( "WING" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( wid, 0 )

ChangeXSecShape( xsec_surf, 1, XS_EDIT_CURVE )

# Identify XSec 1
xsec_1 = GetXSec( xsec_surf, 1 )

fixed_u_vec = list(GetEditXSecFixedUVec( xsec_1 ))

fixed_u_vec[3] = True # change a flag

SetEditXSecFixedUVec( xsec_1, fixed_u_vec )

before_pts = GetEditXSecCtrlVec( xsec_1, True )

ReparameterizeEditXSec( xsec_1 )

Update()

# Reparameterizing redistributes U without changing the shape, so the same
# control points are still there.
after_pts = GetEditXSecCtrlVec( xsec_1, True )

assert len( after_pts ) == len( before_pts ), "ReparameterizeEditXSec changed the number of control points"

# The U values stay in order over the unit interval.
u_vec = GetEditXSecUVec( xsec_1 )

assert len( u_vec ) == len( after_pts ), "the U vector does not match the control points"
assert abs( u_vec[0] ) < 1e-9 and abs( u_vec[-1] - 1.0 ) < 1e-9, "the U vector does not span the curve"

for i in range( 1, len( u_vec ) ):
    assert u_vec[i] >= u_vec[i - 1], "the U vector is not increasing at " + str( i )

See also: SetEditXSecFixedUVec, ReparameterizeEditXSec :param [in]: xsec_id string XSec ID :rtype: std::vector< bool,std::allocator< bool > > :return: vector <bool> Array of bool values for each control point

openvsp.SetEditXSecFixedUVec(xsec_id, fixed_u_vec)[source]

Set the vector of fixed U flags for each control point in an EditCurveXSec. The fixed U flag is used to hold the U parameter of the control point constant when performing an equal arc length reparameterization of the curve.

# Add Wing
wid = AddGeom( "WING" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( wid, 0 )

ChangeXSecShape( xsec_surf, 1, XS_EDIT_CURVE )

# Identify XSec 1
xsec_1 = GetXSec( xsec_surf, 1 )

fixed_u_vec = list(GetEditXSecFixedUVec( xsec_1 ))

fixed_u_vec[3] = True # change a flag

SetEditXSecFixedUVec( xsec_1, fixed_u_vec )

assert len( GetEditXSecFixedUVec( xsec_1 ) ) == len( fixed_u_vec ), "SetEditXSecFixedUVec length"

before_pts = GetEditXSecCtrlVec( xsec_1, True )

ReparameterizeEditXSec( xsec_1 )

Update()

# Reparameterizing redistributes U without changing the shape, so the same
# control points are still there.
after_pts = GetEditXSecCtrlVec( xsec_1, True )

assert len( after_pts ) == len( before_pts ), "ReparameterizeEditXSec changed the number of control points"

# The U values stay in order over the unit interval.
u_vec = GetEditXSecUVec( xsec_1 )

assert len( u_vec ) == len( after_pts ), "the U vector does not match the control points"
assert abs( u_vec[0] ) < 1e-9 and abs( u_vec[-1] - 1.0 ) < 1e-9, "the U vector does not span the curve"

for i in range( 1, len( u_vec ) ):
    assert u_vec[i] >= u_vec[i - 1], "the U vector is not increasing at " + str( i )

See also: GetEditXSecFixedUVec, ReparameterizeEditXSec :param [in]: xsec_id string XSec ID :param [in]: fixed_u_vec vector <bool> Array of fixed U flags

openvsp.ReparameterizeEditXSec(xsec_id)[source]

Perform an equal arc length repareterization on an EditCurveXSec. The reparameterization is performed between specific U values if the Fixed U flag is true. This allows corners, such as at 0.25, 0.5, and 0.75 U, to be held constant while everything between them is reparameterized.

# Add Wing
wid = AddGeom( "WING" )

# Get First (and Only) XSec Surf
xsec_surf = GetXSecSurf( wid, 0 )

ChangeXSecShape( xsec_surf, 1, XS_EDIT_CURVE )

# Identify XSec 1
xsec_1 = GetXSec( xsec_surf, 1 )

fixed_u_vec = list(GetEditXSecFixedUVec( xsec_1 ))

fixed_u_vec[3] = True # change a flag

SetEditXSecFixedUVec( xsec_1, fixed_u_vec )

before_pts = GetEditXSecCtrlVec( xsec_1, True )

ReparameterizeEditXSec( xsec_1 )

Update()

# Reparameterizing redistributes U without changing the shape, so the same
# control points are still there.
after_pts = GetEditXSecCtrlVec( xsec_1, True )

assert len( after_pts ) == len( before_pts ), "ReparameterizeEditXSec changed the number of control points"

# The U values stay in order over the unit interval.
u_vec = GetEditXSecUVec( xsec_1 )

assert len( u_vec ) == len( after_pts ), "the U vector does not match the control points"
assert abs( u_vec[0] ) < 1e-9 and abs( u_vec[-1] - 1.0 ) < 1e-9, "the U vector does not span the curve"

for i in range( 1, len( u_vec ) ):
    assert u_vec[i] >= u_vec[i - 1], "the U vector is not increasing at " + str( i )

See also: SetEditXSecFixedUVec, GetEditXSecFixedUVec :param [in]: xsec_id string XSec ID