View Issue Details

IDProjectCategoryView StatusLast Update
0033802CommunityOCCT:Modeling Algorithmspublic2024-09-25 13:20
Reporterdpasukhi Assigned Todpasukhi  
PrioritynormalSeverityjust a question 
Status closedResolutionno change required 
Product Version7.8.1 
Summary0033802: Modeling Algorithms - Unexpected Behavior in BRep_Tool.Curve Extraction Function
Description**Function**: `TestBRepToolCurve`

**Issue**: The `TestBRepToolCurve` function is designed to validate the extraction of a `Geom_Curve` from a `TopoDS_Edge` using the `BRep_Tool.Curve` method. The function encounters an issue where the extracted curve does not match the expected curve type (a line) despite correct input data. The following details summarize the function's behavior and the observed issue.

**Function Description**:

1. **Initialization**:
   - A `Geom_Line` object is created from two points, `p1` and `p2`. The line is constructed using these points, where `p1` serves as the origin, and the direction is calculated from the vector connecting `p1` to `p2`.
   - The `Geom_Line` is then passed to the `BRepBuilderAPI_MakeEdge` constructor to create a `TopoDS_Edge`.
2. **Curve Extraction**:
   - The curve is extracted from the edge using `BRep_Tool.Curve`.
   - The extracted curve is validated by checking its type against the expected `Geom_Line`.
3. **Issue Observed**:
   - Despite being constructed from a `Geom_Line`, the extracted curve is not recognized as a line. The printed values of the start and end points show unexpected, extremely large or small numbers, indicating a possible corruption of the curve data during extraction or the input being misinterpreted.

**Steps to Reproduce**:

1. Create a `Geom_Line` object using valid `gp_Pnt` coordinates.
2. Convert the line into a `TopoDS_Edge` using `BRepBuilderAPI_MakeEdge`.
3. Extract the curve using `BRep_Tool.Curve`.
4. Compare the extracted curve’s type against the original `Geom_Line`.

**Expected Behavior**:

- The extracted curve should match the original line type (`Geom_Line`), and the start/end points should correspond to the original points used in the creation of the line.

**Actual Behavior**:

- The extracted curve does not match the expected type. The start and end points display extremely large or small values, suggesting a data issue during the extraction process.

**Additional Notes**:

- The bug may stem from improper handling of floating-point values during curve extraction or a deeper issue within the `BRep_Tool.Curve` method itself.
- Further investigation is required to determine if this issue is isolated to specific inputs or if it is a more systemic problem within the function.

**Suggested Next Steps**:

- Review and test the `BRep_Tool.Curve` function for different types of curves and edge inputs to identify the root cause.
- Investigate potential fixes within the `BRep_Tool` module, especially regarding how it handles and returns curve data.

using OCC.BRepBuilderAPI;
using OCC.TopoDS;
using OCC.gp;
using OCC.BRep;
using OCC.Geom;
using OCC.GeomAbs;
using UnityEngine;

public static class BRepToolCurveTester
{
    public static void TestBRepToolCurve()
    {
        // Step 1: Create a basic line edge
        gp_Pnt p1 = new gp_Pnt(0, 0, 0);
        gp_Pnt p2 = new gp_Pnt(10, 0, 0);

        // Create a Geom_Line object
        Geom_Line geomLine = new Geom_Line(p1, new gp_Dir(p2.XYZ().Subtracted(p1.XYZ())));

        // Print the values from Geom_Line
        gp_Lin lineGeometry = geomLine.Lin();
        gp_Pnt origin = lineGeometry.Location();
        gp_Dir direction = lineGeometry.Direction();
        Debug.Log($"Geom_Line Origin: ({origin.X():F2}, {origin.Y():F2}, {origin.Z():F2})");
        Debug.Log($"Geom_Line Direction: ({direction.X():F2}, {direction.Y():F2}, {direction.Z():F2})");

        // Use BRepBuilderAPI_MakeEdge to create a TopoDS_Edge
        BRepBuilderAPI_MakeEdge edgeBuilder = new BRepBuilderAPI_MakeEdge(geomLine);
        TopoDS_Edge lineEdge = edgeBuilder.Edge();

        // Step 2: Extract the curve from the edge using BRep_Tool.Curve
        double first = 0, last = 0;
        Geom_Curve extractedCurve = BRep_Tool.Curve(lineEdge, ref first, ref last);

        // Step 3: Validate the extracted curve
        if (extractedCurve == null)
        {
            Debug.LogError("BRep_Tool.Curve failed to extract the curve from the edge.");
            return;
        }

        // Step 4: Print out the curve details for verification
        gp_Pnt startPoint = extractedCurve.Value(first);
        gp_Pnt endPoint = extractedCurve.Value(last);

        Debug.Log($"Start Point: ({startPoint.X():F2}, {startPoint.Y():F2}, {startPoint.Z():F2})");
        Debug.Log($"End Point: ({endPoint.X():F2}, {endPoint.Y():F2}, {endPoint.Z():F2})");

        // Check if the extracted curve is indeed a line
        if (extractedCurve is Geom_Line)
        {
            Debug.Log("The extracted curve is a line.");
        }
        else
        {
            Debug.Log($"The extracted curve is of type: {extractedCurve.GetType().Name}");
        }
    }
}

TagsNo tags attached.
Test case number

Activities

dpasukhi

2024-08-19 13:19

administrator   ~0116512

'gp_Lin' is a line. Without begin and end.
Standard_Real Geom_Line::FirstParameter () const 
{ return -Precision::Infinite(); }
Standard_Real Geom_Line::LastParameter () const 
{ return Precision::Infinite(); }

In you code you initialize direction and create an endless line
To create a bounded edge, you need to use another method for edge creating, see below.
BRepBuilderAPI_MakeEdge edgeBuilder = new BRepBuilderAPI_MakeEdge(geomLine, p1, p2 );

Issue History

Date Modified Username Field Change
2024-08-19 12:59 dpasukhi New Issue
2024-08-19 12:59 dpasukhi Assigned To => akaftasev
2024-08-19 13:02 dpasukhi Assigned To akaftasev =>
2024-08-19 13:02 dpasukhi Severity minor => major
2024-08-19 13:02 dpasukhi Product Version => 7.8.1
2024-08-19 13:02 dpasukhi Target Version 7.9.0 =>
2024-08-19 13:19 dpasukhi Severity major => just a question
2024-08-19 13:19 dpasukhi Note Added: 0116512
2024-08-19 13:39 dpasukhi Assigned To => dpasukhi
2024-08-19 13:39 dpasukhi Status new => feedback
2024-09-25 13:20 dpasukhi Status feedback => closed
2024-09-25 13:20 dpasukhi Resolution open => no change required