00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef _NURBS_SURFACE_SUBDIVISION_
00027 #define _NURBS_SURFACE_SUBDIVISION_
00028
00029 #include "nurbs.h"
00030 #include "nurbsS.h"
00031 #include <vector>
00032 #include <iostream>
00033
00036 namespace PLib {
00037
00053 template <class T>
00054 struct SurfSample {
00055 Point_nD<T,3> point ;
00056 Point_nD<T,3> normal ;
00057 T normLen ;
00058 T u,v ;
00059
00060 SurfSample<T>& operator=(const SurfSample<T>& s) ;
00061
00062 SurfSample() : normLen(-1),u(0),v(0) {;}
00063
00064 static T epsilon ;
00065 };
00066
00067
00068
00079 template <class T>
00080 class RenderMesh {
00081 public:
00082
00083 virtual void drawHeader() = 0;
00084 virtual void drawTriangle(const SurfSample<T>&, const SurfSample<T>&, const SurfSample<T>&) = 0;
00085 virtual void drawFooter() = 0;
00086 virtual void screenProject(const HPoint_nD<T,3> &worldPt, Point_nD<T,3> &screenPt ) = 0 ;
00087 };
00088
00089
00090 template <class T> class NurbSurface ;
00091
00109 template <class T>
00110 struct NurbsSubSurface {
00111 public:
00112 NurbsSubSurface(const NurbsSurface<T,3>& s) ;
00113 ~NurbsSubSurface() ;
00114
00115 void drawSubdivisionPS(ostream& os, T tolerance) ;
00116 void drawSubdivisionPS(const char* f, T tolerance) ;
00117
00118 void drawSubdivisionVRML(ostream& os, T tolerance, const Color& col=Color(0,0,255)) ;
00119 void drawSubdivisionVRML(const char* f, T tolerance, const Color& col=Color(0,0,255)) ;
00120
00121 void drawSubdivisionVRML97(ostream& os, T tolerance, const Color& col=Color(0,0,255)) ;
00122 void drawSubdivisionVRML97(const char* f, T tolerance, const Color& col=Color(0,0,255)) ;
00123
00124
00125 void drawSubdivisionPoints(BasicArray<Point_nD<T,3> > &pnts, T tolerance) ;
00126 void drawSubdivisionPoints(T tolerance) ;
00127
00128 protected:
00129
00130 void drawSubdivision(T tolerance) ;
00131 void initSurf() ;
00132 RenderMesh<T> *render;
00133 const NurbsSurface<T,3> &rsurf ;
00134 NurbSurface<T> *surf ;
00135 };
00136
00137
00145 template <class T>
00146 class RenderMeshPS : public RenderMesh<T> {
00147 public:
00148 RenderMeshPS(ostream& os): out(os) {;}
00149 virtual ~RenderMeshPS() {;}
00150 virtual void drawHeader() ;
00151 virtual void drawTriangle( const SurfSample<T> &v0, const SurfSample<T> &v1, const SurfSample<T> & v2 );
00152 void drawLine( const SurfSample<T> &v0, const SurfSample<T> &v1);
00153 virtual void drawFooter() ;
00154 virtual void screenProject(const HPoint_nD<T,3> &worldPt, Point_nD<T,3> &screenPt ) ;
00155 protected:
00156 ostream& out ;
00157 };
00158
00159
00160
00161
00169 template <class T>
00170 class RenderMeshVRML : public RenderMesh<T> {
00171 public:
00172 RenderMeshVRML(ostream& os,const Color& col): out(os), color(col) {;}
00173 virtual ~RenderMeshVRML() { ; }
00174 virtual void drawHeader() ;
00175 virtual void drawTriangle( const SurfSample<T> &v0, const SurfSample<T> &v1, const SurfSample<T> & v2 );
00176 virtual void drawFooter() ;
00177 virtual void screenProject(const HPoint_nD<T,3> &worldPt, Point_nD<T,3> &screenPt ) ;
00178 protected:
00179 int size ;
00180 ostream &out ;
00181 Color color ;
00182 };
00183
00191 template <class T>
00192 class RenderMeshVRML97 : public RenderMesh<T> {
00193 public:
00194 RenderMeshVRML97(ostream& os,const Color& col): out(os), color(col) { init = 1 ;}
00195 virtual ~RenderMeshVRML97() { ; }
00196 virtual void drawHeader() ;
00197 virtual void drawTriangle( const SurfSample<T> &v0, const SurfSample<T> &v1, const SurfSample<T> & v2 );
00198 virtual void drawFooter() ;
00199 virtual void screenProject(const HPoint_nD<T,3> &worldPt, Point_nD<T,3> &screenPt ) ;
00200 protected:
00201 int size ;
00202 ostream &out ;
00203 Color color ;
00204 Point_nD<T,3> p_min,p_max ;
00205 int init ;
00206 };
00207
00218 template <class T>
00219 class RenderMeshPoints : public RenderMesh<T> {
00220 public:
00221
00222 RenderMeshPoints(BasicArray<Point_nD<T,3> >& pts): points(pts) {;}
00223 virtual ~RenderMeshPoints() {; }
00224 virtual void drawHeader() ;
00225 virtual void drawTriangle( const SurfSample<T> &v0, const SurfSample<T> &v1, const SurfSample<T> & v2 );
00226 virtual void drawFooter() ;
00227 virtual void screenProject(const HPoint_nD<T,3> &worldPt, Point_nD<T,3> &screenPt ) ;
00228 protected:
00229
00230
00231 BasicArray<Point_nD<T,3> > &points;
00232 };
00233
00234
00235
00236
00237 }
00238
00239
00240 #endif