The following code uses the CATGeoFactory which inherits from the CATICGMContainer. This means that the geometry created is purely mathematical. It can only be viewed in CATIA by making it a Datum feature which allows it to be added to the procedural view. See [[Adding a Geometrical Object to a CATIA part]].
This code initializes the CATGeoFactory (a part must be open first):
CATDocument *pDoc = pEditor->GetDocument();
CATIContainerOfDocument_var spConODocs = pDoc;
CATIContainer* spCGMContainer;
HRESULT hr = spConODocs->GetResultContainer(spCGMContainer);
CATGeoFactory_var piGeomFactory = spCGMContainer;
This code creates the grid of points to be passed as the knot vector argument
int nbPoleU = 5;
int nbPoleV = 5;
CATMathGridOfPoints gridOfPoints(nbPoleU,nbPoleV);
// Row 0
gridOfPoints.SetPoint(CATMathPoint( 0., 0., 0.),0,0);
gridOfPoints.SetPoint(CATMathPoint(10., 0., 0.),0,1);
gridOfPoints.SetPoint(CATMathPoint(20., 0., 0.),0,2);
gridOfPoints.SetPoint(CATMathPoint(30., 0., 0.),0,3);
gridOfPoints.SetPoint(CATMathPoint(40., 0., 0.),0,4);
// Row 1
gridOfPoints.SetPoint(CATMathPoint( 0.,10., 0.),1,0);
gridOfPoints.SetPoint(CATMathPoint(10.,10.,-10.),1,1);
gridOfPoints.SetPoint(CATMathPoint(20.,10.,-10.),1,2);
gridOfPoints.SetPoint(CATMathPoint(30.,10.,-10.),1,3);
gridOfPoints.SetPoint(CATMathPoint(40.,10., 0.),1,4);
// Row 2
gridOfPoints.SetPoint(CATMathPoint( 0.,20., 0.),2,0);
gridOfPoints.SetPoint(CATMathPoint(10.,20.,-40.),2,1);
gridOfPoints.SetPoint(CATMathPoint(20.,20.,-40.),2,2);
gridOfPoints.SetPoint(CATMathPoint(30.,20., -40.),2,3);
gridOfPoints.SetPoint(CATMathPoint(40.,20., 0.),2,4);
// Row 4
gridOfPoints.SetPoint(CATMathPoint( 0.,30., 0.),3,0);
gridOfPoints.SetPoint(CATMathPoint(10.,30., -10.),3,1);
gridOfPoints.SetPoint(CATMathPoint(20.,30., -10.),3,2);
gridOfPoints.SetPoint(CATMathPoint(30.,30., -10.),3,3);
gridOfPoints.SetPoint(CATMathPoint(40.,30., 0.),3,4);
// Row 5
gridOfPoints.SetPoint(CATMathPoint( 0.,40., 0.),4,0);
gridOfPoints.SetPoint(CATMathPoint(10.,40., 0.),4,1);
gridOfPoints.SetPoint(CATMathPoint(20.,40., 0.),4,2);
gridOfPoints.SetPoint(CATMathPoint(30.,40., 0.),4,3);
gridOfPoints.SetPoint(CATMathPoint(40.,40., 0.),4,4);
This code creates the knot vectors:
CATLONG32 IsPeriodic= 0;
CATLONG32 Degree= 4;
CATLONG32 KnotsCount= 2;
double Knots[]= {0.,10.};
CATLONG32 Multiplicities[]= {5,5};
CATLONG32 IndexOffset= 1;
CATKnotVector NonUniformU(Degree,IsPeriodic,KnotsCount,Knots,
Multiplicities,IndexOffset);
CATKnotVector NonUniformV(Degree,IsPeriodic,KnotsCount,Knots,
Multiplicities,IndexOffset);
This code creates the NURBS surface:
CATLONG32 isRational=1;
double * aWeights=new double[nbPoleU*nbPoleV];
for (int i = 0; i {
aWeights[i] = 1.;
}
CATNurbsSurface * piSurf1 = piGeomFactory->
CATCreateNurbsSurface(NonUniformU, NonUniformV,isRational,gridOfPoints,aWeights);
delete [] aWeights;
aWeights = NULL;
