Skip to content

Solution to functions that tries modifying immutable arguments passed by reference #167

Open

Description

@GabrielJMS

Hello,

Have you found any solution for handling functions that return values via output parameters passed by reference, especially when those parameters are of immutable types?

This becomes a problem with important functions like BRep_Tool::CurveOnSurface. In such cases, the function modifies the arguments passed by reference (e.g., to return the first and last parameters of the Geom2d_Curve), but when these are immutable types in the binding language, we can’t retrieve the modified values.

This effectively blocks access to important return data.

Some relevant references:

pybind11 FAQ – Limitations involving reference arguments

pyOCCT developer notes – Reference arguments

Would appreciate any guidance or workarounds!

Thanks in advance.

Activity

  1. adam-urbanczyk commented on Apr 11, 2025

    @adam-urbanczyk
    Member

    The solution is to add workaround method in the binding manually or via rules. What is your use case (not CQ I presume) case and why is this function so important?

  2. GabrielJMS commented on Apr 17, 2025

    @GabrielJMS
    Author

    Hello @adam-urbanczyk , thank you for your quick response.

    In some data science workflows involving BRep geometry, we need to work directly in the parametric (UV) domain of surfaces to perform calculations on faces. For instance, we often need to construct 2D edges and wires that represent the boundaries of a face in this parametric space.

    To do this, it's essential to retrieve the associated pcurve and its parameter range. This also applies to vertices—sometimes we need to extract their (u, v) coordinates on a given surface to carry out specific operations.

    Since this information is already available within the BRep data structures, it would be ideal to access it directly using functions like BRep_Tool::CurveOnSurface, rather than having to recompute or approximate it manually.

    Thanks again for your support!

  3. GabrielJMS commented on Apr 22, 2025

    @GabrielJMS
    Author
  4. GabrielJMS commented on Aug 6, 2025

    @GabrielJMS
    Author

    Hello @adam-urbanczyk Do you think would be possible to expose the Standard_Real object, so we could use something like this to solve this issue:

    from OCP.Standard import Standard_Real
    from OCP import BRep_Tool
    from OCP.Geom2dAPI import Geom2dAPI_ExtremaCurveCurve
    
    first = Standard_Real()
    last = Standard_Real()
    curve = BRep_Tool.CurveOnSurface(edge, face, first, last)
    
    extrema_curve = Geom2dAPI_ExtremaCurveCurve(curve1, curve2)
    u1 = Standard_Real()
    u2 = Standard_Real()
    extrema_curve.LowerDistanceParameters(u1, u2)
    

    Thank you for your attention

  5. adam-urbanczyk commented on Aug 19, 2025

    @adam-urbanczyk
    Member

    I don't think that is going to fly, it would not mesh well with how CQ is using OCP. I assume you are working on some closed-source project, so I think your best bet for now is to write a custom extension to OCP that wraps the needed functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions