[Gul-users] Re: SNURBS example
Status: Beta
Brought to you by:
nurbert
From: Norbert I. <nor...@he...> - 2000-09-14 01:50:10
|
Ronan GOLHEN wrote: > > You're library looks very good and the image that interpolate scattered data > points looks like exactly what I'm looking for. > > As far as I've understood, the function to use for this is > NUNU_MBAapproximate(). > > I've not found any sample using the function NUNU_MBAapproximate(). It would > help if you can provide me with one sample. > If you do not have, should I refer to the book : "The NURBS Book" ? Any > other idea ? > Hello, The MBA algorithm is based on Lee, S., Wolberg, G., and Shin, S.Y. "Scattered Data Interpolation with Multilevel B-Splines" IEEE Transactions on Visualization and Computer Graphics, VOL. 3, NO. 3, July-September 1997 But I would recommend the "The NURBS Book", too, since i use in my library the type of nurbs functions described in the nurbs book (with clamped knot vectors), and use the same functions for calculating their values, derivatives, etc. Some remarks in advance: There are two versions of the library. The old one is called "snurbs", and the new one is called "gul". (you find the new one at http://gul.sourceforge.net ) The new library makes much use of C++ and templates. I don't use the old version anymore, since in the new version I can use the same templates for algorithms with "float" and "double" coordinates, and 1-,2-,3-, or 4-dimensional control points. The new version also uses a "smart" pointer class, which remembers the storage class of allocated memory, and automatically deallocates it correctly when the last pointer which references it gets deleted. So you don't have to write cleanup code, and don't have to worry about memory leaks. This is very convenient. But the disadvantage is, that the new version of the library doesn't compiles anymore with VisualC++ 5.0/6.0 on Windows, since this compiler is quite old, and doesn't fully supports the new Ansi C++ standard from 1998. So you have to use Mingw32 or the free BorlandC++ 5.5.1 command line tools (with service pack 2) to get the thing compiled on windows. If you want to compile the library with BorlandC++ or Mingw32 on windows, you have to checkout the CVS version (see the project page), since the Makefiles for BorlandC or Mingw32 are not included in the distribution. But for this you must have cvs + ssh installed on your windows box, ... Phew, is that complicated ! Perhaps it's the best you write again to me if you want to compile the thing on windows, then I make a standalone distribution of the library, including the makefiles for borlandx++ and mingw32. Best regards, Norbert PS: Here is a simple example i made which shows how to call the MBA function (i also attached it to this mail) I hope this helps you. #include <gul_types.h> #include <gunu_mba_approximate.h> #include <iostream.h> #include <gul_io.h> using gul::point; using gul::Ptr; using gunu::SurfaceOverXYPlane; // test case with 6 data points int nTestPoints = 6; point<float> TestPoints[] = { {1330.76, 1650.00, 220.00}, {2198.50, 2033.20, 20.00}, {2872.27, 1052.20, 30.00}, {487.25, 4149.87, 1590.00}, {4334.40, 5134.66, 170.00}, {4977.55, 5458.02, -120.00} }; // main program int main() { int pu,pv,nu,nv,i,j; // data points Ptr< point<float> > pts; // standard deviations, will not be used, but must be given as a // function parameter Ptr<float> devs; // arrays for knot vectors, will be reserved by the Mba function Ptr<float> U,V; // array for control points, will be reserved by the Mba function Ptr< Ptr< point<float> > > Pw; // the "pts" pointer simply uses the already existing "TestPoints" // array pts.use_pointer( TestPoints, nTestPoints ); // here the mba algorithm is called pu = 3; pv = 3; SurfaceOverXYPlane< float,point<float> >( nTestPoints, // number of data points pts, // data points false, // don't use standard deviations devs, // standard deviations for data points (not used in // this example) false, // minimize area of base rectangle in xy-plane 2, // number of iterations pu, pv, // degree for u and v direction of the calculated surface &nu, &U, &nv, &V, &Pw // knot vectors and control points of the calculated // data points (nu and nv will contain the number of // knots - 1 !!!) ); // dump the result surface cout << "U knot vector:\n"; for( i = 0; i < nu + pu + 2; i++ ) cout << U[i] << " "; cout << "\n"; cout << "V knot vector:\n"; for( i = 0; i < nv + pv + 2; i++ ) cout << V[i] << " "; cout << "\n"; cout << "Control point matrix:\n"; for( i = 0; i <= nv; i++ ) { for( j = 0; j <= nu; j++ ) cout << Pw[i][j] << " "; cout << "\n"; } // no cleanup code neccessary, everything gets deallocated automatically // when the destructors of the pointers are called :)) } |