Description:
The current implementation of the curvature function in the DiffGeomCurve class from OCC.Utils.edge_py appears to provide inaccurate results when applied to B-spline curves. While the function successfully calculates curvature for circular edges, it consistently returns a value of 0 for B-spline curves, indicating inaccurate behavior.
Steps to Reproduce:
- Obtain the attached TXT file (
sin_curve.txt) containing a B-spline representation of a sine curve.
- Change the file extension from
.txt to .step.
- Load the STEP file using pythonocc.
- Obtain the curvature of the B-spline curve using the
curvature function from the DiffGeomCurve class.
Expected Behavior:
The curvature function should accurately compute the curvature of B-spline curves, providing meaningful non-zero values consistent with the curvature of the curve at various points.
Actual Behavior:
The curvature function consistently returns 0 when applied to B-spline curves, while it correctly computes curvature for circular edges. This discrepancy indicates inaccurate behavior specific to B-spline curves.
Code Snippet:
from OCC.Core.TopExp import TopExp_Explorer
from OCC.Core.TopAbs import TopAbs_EDGE
from OCC.Core.GCPnts import GCPnts_UniformAbscissa
from OCC.Core.BRepAdaptor import BRepAdaptor_Curve
from OCC.Core.TDocStd import TDocStd_Document
from OCC.Core.XCAFDoc import XCAFDoc_DocumentTool
from OCC.Core.STEPCAFControl import STEPCAFControl_Reader
from OCC.Core.IFSelect import IFSelect_RetDone
from OCC.Core.TDF import TDF_LabelSequence
from OCCUtils.edge import Edge
doc = TDocStd_Document("pythonocc-doc")
shape_tool = XCAFDoc_DocumentTool.ShapeTool(doc.Main())
step_reader = STEPCAFControl_Reader()
step_reader.SetNameMode(True)
status = step_reader.ReadFile("sin_curve.step")
if status != IFSelect_RetDone:
raise IOError("Failed to read STEP file")
step_reader.Transfer(doc)
labels = TDF_LabelSequence()
shape_tool.GetFreeShapes(labels)
shape = shape_tool.GetShape(labels.Value(1))
explorer = TopExp_Explorer(shape, TopAbs_EDGE)
while explorer.More():
edge = explorer.Current()
curve_adaptor = BRepAdaptor_Curve(edge)
curve_edge = Edge(edge)
curvatures = []
_lower_bound, _upper_bound = curve_adaptor.FirstParameter(), curve_adaptor.LastParameter()
num_eval_points = 100
npts = GCPnts_UniformAbscissa(curve_adaptor, num_eval_points, _lower_bound, _upper_bound)
if npts.IsDone():
for i in range(1, npts.NbPoints() + 1):
param = npts.Parameter(i)
curvature = curve_edge.DiffGeom.curvature(param)
curvatures.append(curvature)
# Print or store the curvature value at each evaluation point
print("Parameter:", param, "Curvature:", curvature)
# Print all curvature values calculated for the current edge
print("Curvatures for current edge:", curvatures)
explorer.Next()
Geometry File:
Changed the file ending to .txt as Github doesn't allow uploads of .step files.
Attached TXT file: sin_curve.txt
Any assistance from the community in diagnosing and resolving this issue would be greatly appreciated. Thank you in advance for your help!
Description:
The current implementation of the
curvaturefunction in theDiffGeomCurveclass fromOCC.Utils.edge_pyappears to provide inaccurate results when applied to B-spline curves. While the function successfully calculates curvature for circular edges, it consistently returns a value of 0 for B-spline curves, indicating inaccurate behavior.Steps to Reproduce:
sin_curve.txt) containing a B-spline representation of a sine curve..txtto.step.curvaturefunction from theDiffGeomCurveclass.Expected Behavior:
The
curvaturefunction should accurately compute the curvature of B-spline curves, providing meaningful non-zero values consistent with the curvature of the curve at various points.Actual Behavior:
The
curvaturefunction consistently returns 0 when applied to B-spline curves, while it correctly computes curvature for circular edges. This discrepancy indicates inaccurate behavior specific to B-spline curves.Code Snippet:
Geometry File:
Changed the file ending to
.txtas Github doesn't allow uploads of.stepfiles.Attached TXT file: sin_curve.txt
Any assistance from the community in diagnosing and resolving this issue would be greatly appreciated. Thank you in advance for your help!