Manifold Geometry // Многообразная Геометрия

# Beware of exception in GeomLProp_CLProps

/ Просмотров: 863

There was an annoying problem in Analysis Situs for those who run it in debug mode. If you ever tried to draw a vector using the imperative plotter, you might have noticed that an exception was thrown. Here is a simple reproducer (a Tcl command for the Active Script):

int MISC_Test(const Handle(asiTcl_Interp)& interp,
int                          argc,
const char**                 argv)
{
if ( argc != 1 )
{
return interp->ErrorOnWrongArgs(argv[0]);
}
interp->GetPlotter().DRAW_VECTOR_AT(gp::Origin(), gp::DZ(), Color_Yellow, "DZ");
return TCL_OK;
}

The crash is caused by attempting to get a normal vector for a geometric primitive with zero or infinite curvature (zero in that case). OpenCascade is not exception-safe, so be ready to face crashes in the code like this:

GeomLProp_CLProps lProps( m_curve3d, m_curve3d->LastParameter(), 2, gp::Resolution() );

gp_Dir norm;
lProps.Normal(norm);

To fix the code, you should check the curvature first:

GeomLProp_CLProps lProps( m_curve3d, m_curve3d->LastParameter(), 2, gp::Resolution() );

gp_Dir norm;
if ( Abs( lProps.Curvature() ) > RealEpsilon() )
{
lProps.Normal(norm);
}
 Vectors rendered using the imperative plotter interface of Analysis Situs.

Analysis Situs uses this computation to draw an arrow tip for all curves (in fact, a vector can be seen as a straight curve for the unification of visualization code). Checking these tips, the user can easily see the geometric orientation of a curve. Such orientation is the fundamental property for many modeling operators.