Geometric Modeler

Free Form Operators

Converting Curves into NURBS

How to use the CATCrvFittingToNurbsCrv operator

Use Case

Abstract

You can convert curves into NURBS by using the CATCrvFittingToNurbsCrv operator. This operator allows you to specify the characteristics of the resulting NURBS as well as a maximum deviation you would like to obtain with respect to the initial curve. This maximum deviation may not be achieved.


What You Will Learn With This Use Case

This use case is intended to help you use the free form operators. It particularly illustrates how to convert a curve into a NURBS.

[Top]

The CATCrvFittingToNurbsCrv Operator

The CATCrvFittingToNurbsCrv operator is to be used according to the general scheme of operators:

  1. Creation of an operator instance from a global function. Two modes BASIC or ADVANCED are proposed.
  2. If the ADVANCED mode is choosen, tuning of the parameters by using the Setxxx methods then run of the operator
  3. Retrieve the created NURBS by using the GetPNurbs method.

Note: In ADVANCED mode, you cannot use the same operator to convert several curves. You must replay the sequence below:

  1. operator creation
  2. set of parameters
  3. Run
  4. GetPNurbs
  5. operator deletion.

as many times as you need.

[Top]

The CAACrvFittingToNurbsCrv Use Case

CAACrvFittingToNurbsCrv is a use case of the CAAFreeFormOperators.edu framework that illustrates the FreeFormOperators framework capabilities.

[Top]

What Does CAACrvFittingToNurbsCrv Do

This use case

  1. Creates a PSpline to be converted into a Nurbs.
  2. Creates a CAACrvFittingToNurbsCrv operator to be used to convert the initial curve into a rational curve. A constraint is set on the minimum length of an arc.
  3. Retrieves the created Nurbs.

[Top]

How to Launch CAACrvFittingToNurbsCrv

To launch CAACrvFittingToNurbsCrv, you will need to set up the build time environment, then compile CAACrvFittingToNurbsCrv.m along with its prerequisites, set up the run time environment, and then execute the use case [4].

If you simply type CAACrvFittingToNurbsCrv with no argument, the use case executes, but doesn't save the result in an NCGM file. If you want to save this result, provide the full pathname of the NCGM file to create. For example:

With Windows CAACrvFittingToNurbsCrv e:\NurbsSur.NCGM

With UNIX CAACrvFittingToNurbsCrv /u/NurbsSur.NCGM

This NCGM file can be displayed using the CAAGemBrowser use case.

[Top]

Where to Find the CAACrvFittingToNurbsCrv Code

The CAACrvFittingToNurbsCrv use case is made of a main named CAACrvFittingToNurbsCrv .cpp located in the CAACrvFittingToNurbsCrv.m module of the CAAFreeFormOperators.edu framework:

Windows InstallRootDirectory\CAAFreeFormOperators.edu\CAACrvFittingToNurbsCrv.m\
Unix InstallRootDirectory/CAAFreeFormOperators.edu/CAACrvFittingToNurbsCrv.m/

where InstallRootDirectory is the directory where the CAA CD-ROM is installed.

[Top]

Step-by-Step

CAACrvFittingToNurbsCrv .cpp is divided into four logical steps:

  1. Creating the Geometry Factory
  2. Creating the Curve to Be Converted into a NURBS
  3. Converting the Created Curve into a NURBS and Specifying a Constraint on the Minimum Length of an Arc
  4. Writing the Model and Closing the Container

[Top]

Creating the Geometry Factory

The geometry factory (CATGeoFactory) creates and manages all the CATICGMObject (and the curves and surfaces in particular) [1]. This creation is done by the global function ::CATCreateCGMContainer. Notice that the factory can be defined by reading a NCGM file that was previously stored. In that case, the global function ::CATLoadCGMContainer must be used.

CATGeoFactory* piGeomFactory = ::CATCreateCGMContainer() ;
if (NULL==piGeomFactory) return (1);

[Top]

Creating the Curve to Be Converted into a NURBS

The curve to be converted is a PSpline. Its underlying geometry is a sphere. All the geometric objects are created from the geometry factory.

[Top]

Converting the Created Curve into a NURBS and Specifying a Constraint on the Minimum Length of an Arc

This first operator is intended to create an operator instance with the following parameters:

  1. a 0.001 maximum deviation. It is important to note that this value is the CATIA resolution and it would not be meaningful to specify a maximum deviation less than this resolution.
  2. the rational factor is 1 - meaning that resulting curve is to be rational.
CATCrvFittingToNurbsCrv * pCrvFitting1 = ::CATCreateCrvFittingToNurbsCrv(piGeomFactory,
		piCurve,
		crvLimits,
		maxdeviation,
		1,
		ADVANCED) ;

At this stage, you have just created an instance of operator. Prior to running the operator, the minimum length of an arc is set to 14.

//  (d) --- Specifies the minimal length of an arc on the output curve
//          Should be properly specified with respect to the input curve
//          length - otherwise the execution results in an abend
//
pCrvFitting1->SetInternalMinLength(14);

If you want to get the converted NURBS, you must Run the operator and retrieve the resulting NURBS by using the GetPNurbs method. To convert a CATPCurve into a CATNurbsCurve, you can use the Set3DCurveCreation method (before applying the Run method), then use the GetNurbsCurve method instead of GetPNurbs.

pCrvFitting1->Run();
CATPNurbs * piPNurbs1 = pCrvFitting1->GetPNurbs();

The transformation of the curve into NURBS is not exact. To check this, you can use the IsExactTransformation method or retrieve the maximum deviation (0.899 is returned in the present use case).

cout << "Maximum deviation is " << pCrvFitting1->GetMaxDeviation() << endl;

[Top]

Writing the Model and Closing the Factory

To save the model in a file, the ::CATSaveCGMContainer global function is used. Notice that in the use case, the save is conditioned by an input parameter representing the file inside which the model must be saved.

The use case ends with the closure of the geometry factory, done by the ::CATCloseCGMContainer global function.

 if(1==toStore)
 {
#ifdef _WINDOWS_SOURCE
   ofstream filetowrite(pfileName, ios::binary ) ;
#else
   ofstream filetowrite(pfileName,ios::out,filebuf::openprot) ;
#endif

   ::CATSaveCGMContainer(piGeomFactory,filetowrite);
   filetowrite.close();
 }	

 //
 // Closes the container
 //	
 ::CATCloseCGMContainer(piGeomFactory);

[Top]


In Short

The CATCreateCrvFittingToNurbsCrv operator allows you to convert a curve into a NURBS. Apart from the usual parameters, this operator requires you specify the maximum deviation you would like to obtain from the initial curve as well as the rationality. Constraints on the resulting curve can be specified by using Setxxx methods.

[Top]


References

[1] The NURBS Curves
[2] The CGM Objects
[3] The CGM Curves
[4] Building and Launching a CAA V5 Use Case
[5] Converting Surfaces into NURBS
[Top]

History

Version: 1 [Feb 2000] Document created
[Top]

Copyright © 2000, Dassault Systèmes. All rights reserved.