1 #include <nurbs.h>
2
3 // testing of interpolation and approximation
4
main()5 int main(){
6 int i ;
7 // Initialize a NURBS curve and generate a list of points from it
8 int deg = 3 ;
9 Vector_HPoint3Df P(10) ;
10
11 using namespace PLib ;
12
13 P[0] = HPoint3Df(30,30,0,1) ;
14 P[1] = HPoint3Df(40,60,0,1) ;
15 P[2] = HPoint3Df(80,60,0,1) ;
16 P[3] = HPoint3Df(60,160,0,1) ;
17 P[4] = HPoint3Df(100,80,0,1) ;
18 P[5] = HPoint3Df(120,50,0,1) ;
19 P[6] = HPoint3Df(120,50,0,1) ;
20 P[7] = HPoint3Df(120,50,0,1) ;
21 P[8] = HPoint3Df(160,90,0,1) ;
22 P[9] = HPoint3Df(200,200,0,1) ;
23
24 Vector_FLOAT U(10+deg+1) ;
25 for(i=0;i<deg+1;++i)
26 U[i] = 0 ;
27 for(i=deg+1;i<P.n();++i)
28 U[i] = float(i-deg)/float(P.n()-deg) ;
29 for(i=P.n();i<U.n();++i)
30 U[i] = 1.0 ;
31
32 PlNurbsCurvef testCurve(P,U,deg) ;
33
34 Vector_Point3Df Pts(100) ;
35
36 for(i=0;i<Pts.n();++i){
37 Pts[i] = testCurve.pointAt(float(i)/float(Pts.n()-1)) ;
38 }
39
40 #ifdef WITH_IMAGE_MAGICK
41 IM_ColorImage tstImage ;
42 tstImage.resize(256,256) ;
43
44 tstImage.reset(Color(255,255,255)) ;
45
46 for(i=0;i<Pts.n();++i){
47 tstImage(int(Pts[i].y()),int(Pts[i].x())) = Color(0,0,0) ;
48 }
49
50
51 tstImage.write("tnurbs.gif") ;
52 cout << "The result can be viewed in tnurbs.gif\n" ;
53 #endif
54
55 cout << "Testing the read/write interface \n" ;
56 testCurve.write("tnurbs.nc");
57 testCurve.read("tnurbs.nc");
58
59 testCurve.writeVRML("tnurbs.wrl",2,18,blueColor,6,30) ;
60 testCurve.writeVRML97("tnurbs97.wrl",2,18,blueColor,6,30) ;
61
62 cout << "Testing the derivative computation\n" ;
63 PlVector_HPoint3Df D ;
64
65 testCurve.deriveAtH(0.5,1,D) ;
66 cout << "First derivative at 0.5 = \n\t" << D[1] ;
67
68 HPoint3Df d1 ;
69 d1 = testCurve.firstD(0.5) ;
70
71 cout << "\n\t" << d1 << endl ;
72
73 cout << "or in 3D =\n\t" ;
74
75 PlVector_Point3Df D3 ;
76 testCurve.deriveAt(0.5,1,D3) ;
77 cout << D3[1] << endl ;
78 cout << "\t" << testCurve.firstDn(0.5) << endl ;
79
80 cout << "The result can be viewed in tnurbs.wrl (VRML 1.0)\n" ;
81 cout << "and tnurbs97.wrl (VRML 2.0).\n" ;
82 return 0 ;
83 }
84