FAQ: Why is the A3DCrvBase* for this A3DTopoEdge null?

Introduction

As a developer using HOOPS Exchange, you would like to evaluate the exact positions and directions along the edges of a B-Rep model. While attempting to do this, you encounter A3DTopoEdge objects that have a null curve pointer. Why is this, and how do I evaluate edge geometry defined in this way?

Background

HOOPS Exchange is capable of representing B-Rep data from many different source formats. Some formats define edge geometry using a parametric evaluation of the adjacent face(s) rather than a 3D curve defined by A3DTopoEdgeData::m_pCurve.

If this is the case, you will encounter a null 3D curve pointer, but each co-edge referencing the edge will contain a non-null A3DTopoCoEdgeData::m_pUVCurve. This is a 2D curve that you can use with the function A3DCrvEvaluate to evaluate over its valid interval. The evaluation will return a 2D vector (Z will be 0) which are parametric values to be used with the surface evaluator.

Solution

One way to solve this problem is to use the A3DTopoEdgeGetOrCompute3DCurve helper function provided by HOOPS Exchange. This function obtains the 3D curve from the edge if it exists and computes a new 3D curve if it does not. One consideration to make before using this function is that it requires a pointer to the A3DTopoBrepData that contains the edge.

bool evaluateEdgePosition( A3DTopoBrepData *brep_data, A3DTopoEdge *edge, double const t, A3DVector3dData &result ) {
    A3DCrvBase const *curve = nullptr;
    if( ! CheckResult( A3DTopoEdgeGetOrCompute3DCurve( brep_data, edge, &curve ) ) ) {
        return false;
    }
    
    return CheckResult( A3DCrvEvaluate( curve, t, 0, &result ) );
}

Summary

The HOOPS Exchange data model can represent edge geometry in different ways depending on the input file format. Using the method described above, you can determine and reliably obtain a 3D curve for parametric evaluation.