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 #ifndef _nurbs_nurbsGL_h_
00026 #define _nurbs_nurbsGL_h_
00027
00028 #include "nurbs_global.h"
00029 #include <list>
00030
00031 #ifdef WITH_OPENGL
00032
00033 #include "nurbs_sp.h"
00034 #include "nurbsS_sp.h"
00035 #include "hnurbsS_sp.h"
00036 #include "nurbsSub.h"
00037 #include <GL/gl.h>
00038 #include <GL/glu.h>
00039
00042 namespace PLib {
00043
00044 enum ObjectGLState {hideState=0, objectState, selectedState, currentState, selected_currentState };
00045
00046
00047 extern Color objectColorDefault ;
00048 extern Color selectColorDefault ;
00049 extern Color currentColorDefault ;
00050
00051 extern Color axisXColorDefault ;
00052 extern Color axisYColorDefault ;
00053 extern Color axisZColorDefault ;
00054
00055 extern Color cpointColorDefault ;
00056 extern Color cpoint0ColorDefault ;
00057 extern Color cPolygonColorDefault ;
00058 extern Color cpointActiveColorDefault ;
00059
00060 extern Color knotColorDefault ;
00061 extern Color knotActiveColorDefault ;
00062
00063 extern ObjectGLState objectStateDefault ;
00064
00065 extern int pSizeDefault ;
00066
00067 extern const int NURBS_FLAGS_AFFECT_ALL ;
00068 extern const int NURBS_FLAGS_AFFECT_ACTIVE_ONLY ;
00069 extern const int NURBS_FLAGS_AFFECT_SELECTED_ONLY ;
00070 extern const int NURBS_FLAGS_VIEW_BBOX ;
00071
00072 extern const int NURBS_DISPLAY_NORMAL ;
00073 extern const int NURBS_DISPLAY_ISOCURVES ;
00074 extern const int NURBS_DISPLAY_SHADED ;
00075 extern const int NURBS_DISPLAY_HIDDEN_LINES ;
00076 extern const int NURBS_DISPLAY_TESSELATION ;
00077
00078 extern const int NURBSLIST_DELETE_AT_RESET ;
00079 extern const int NURBSLIST_KEEP_AT_RESET ;
00080
00081 extern int NurbsDisplayMode ;
00082 extern float tessel_tolerance ;
00083
00084 extern HPoint3Df dummyCPoint ;
00085
00086 extern Point3Df XAxis_3D ;
00087 extern Point3Df YAxis_3D ;
00088 extern Point3Df ZAxis_3D ;
00089
00090 struct NurbsSubSurfaceGL : public NurbsSubSurface<float> {
00091 NurbsSubSurfaceGL(const NurbsSurface<float,3>& s, const Color& c) : NurbsSubSurface<float>(s), color(c) {;}
00092 ~NurbsSubSurfaceGL() {;}
00093 void drawSubdivisionGL(float tolerance) ;
00094 protected:
00095 Color color ;
00096 };
00097
00098
00110 inline void glColor(const Color& color){
00111 glColor3f(GLfloat(color.r)/255.0,GLfloat(color.g)/255.0,GLfloat(color.b)/255.0) ;
00112 }
00113
00127 inline void colorToMaterial(const Color& color, GLfloat* c, GLfloat alpha=1.0){
00128 c[0] = GLfloat(color.r)/255.0 ;
00129 c[1] = GLfloat(color.g)/255.0 ;
00130 c[2] = GLfloat(color.b)/255.0 ;
00131 c[3] = alpha ;
00132 }
00133
00144 struct RGBAf {
00145 float r,g,b,a ;
00146
00147 RGBAf(){ r=g=b=a=0;}
00148 RGBAf(const RGBAf& c) { r = c.r ; g =c.g ; b=c.b ; a=c.a; }
00149 RGBAf(const Color& c) { r = (float)c.r/255.0 ; g = (float)c.g/255.0 ; b = (float)c.b/255.0 ; a = 1 ; }
00150
00151 };
00152
00166 struct Material {
00167 Material() ;
00168
00169 RGBAf frontAmbient, backAmbient ;
00170 RGBAf frontDiffuse, backDiffuse ;
00171 RGBAf frontSpecular, backSpecular ;
00172 RGBAf frontEmission, backEmission ;
00173 float frontShininess, backShininess ;
00174 void glMaterial() ;
00175
00176
00177
00178 RGBAf pigment ;
00179 double pigment_transfer ;
00180 double pigment_transmit ;
00181 char *pigment_userdefined ;
00182
00183 double bump,bump_scale ;
00184 char *normal_userdefined ;
00185
00186 Color ambient ;
00187 double diffuse,brilliance,phong,specular,roughness,metallic ;
00188 Color reflection ;
00189 double refraction,ior,caustics,fade_distance,fade_power ;
00190 double irid_thick ;
00191 Vector< Point3Df > irid_turbulence ;
00192 double crand ;
00193
00194
00195 char* material ;
00196 };
00197
00215 class ObjectGL {
00216 public:
00217 ObjectGL() ;
00218 virtual ~ObjectGL() ;
00219
00220 ObjectGL& operator=(const ObjectGL& a) ;
00221
00222 Color objectColor ;
00223 Color selectColor ;
00224 Color currentColor ;
00225 GLfloat *materialColor ;
00226
00227
00228 void setObjectColor(const Color& c) { objectColor = c ; }
00229 void setSelectColor(const Color& c) { selectColor = c ; }
00230 void setCurrentColor(const Color& c) { currentColor = c ; }
00231
00232 void glSelectColor() const { glColor(selectColor) ; colorToMaterial(selectColor,materialColor) ;}
00233 void glObjectColor() const { glColor(objectColor) ; colorToMaterial(objectColor,materialColor) ;}
00234 void glCurrentColor() const { glColor(currentColor) ; colorToMaterial(currentColor,materialColor) ;}
00235
00236 void hideObject() { state = hideState ; }
00237 void selectObject() { state = selectedState ; }
00238 void viewObject() { state = objectState ; }
00239 void currentObject() { state = currentState ; }
00240
00241 virtual void glColor() const
00242 { if(isActive())
00243 glColor(currentColor) ;
00244 else{
00245 if(isSelected()) glColor(selectColor) ;
00246 else glColor(objectColor) ; }
00247 }
00248
00249
00250 void glColor(const Color& c) const {
00251 colorToMaterial(Color(0,0,0),materialColor) ;
00252 glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,materialColor) ;
00253 colorToMaterial(c,materialColor) ;
00254 glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,materialColor) ;
00255
00256 }
00257
00258 virtual void glObject() const = 0 ;
00259
00260 enum ObjectCategory { badType, nurbsType, pointType, vectorType, listType };
00261 enum ObjectType {badObject,curveObject,surfaceObject,pointObject,cpointObject,cpointPolygonObject,bboxObject,vectorObject,listObject,hSurfObject,hcpointObject,pointListObject,spointObject} ;
00262 ObjectType type ;
00263 ObjectCategory category ;
00264
00265
00266
00267 GLfloat tx,ty,tz ;
00268 GLfloat rx,ry,rz ;
00269 GLfloat sx,sy,sz ;
00270
00271 virtual void glTransform() const ;
00272
00273 virtual void display() const { if(state) {glPushMatrix() ; glTransform() ; glObject(); glPopMatrix() ;} }
00274 virtual void displayList() { if(state) {glPushMatrix() ; glTransform() ; glColor(); glCallList(callListId); glPopMatrix();} }
00275 virtual void displayName() { ; }
00276
00277 virtual void glNewList() ;
00278 int callListId ;
00279
00280
00281 virtual ObjectGL*& previous() { return prev_ ;}
00282 virtual ObjectGL*& next() { return next_ ;}
00283 virtual ObjectGL* previous() const { return prev_ ;}
00284 virtual ObjectGL* next() const { return next_ ;}
00285
00286 ObjectGLState getState() const { return state ; }
00287
00288 virtual void select() { selected = 1 ; }
00289 virtual void deselect() { selected = 0 ; }
00290 int isSelected() const { return selected ; }
00291
00292 virtual void activate() { active = 1 ; }
00293 virtual void deactivate() { active = 0 ; }
00294 int isActive() const { return active ; }
00295
00296 virtual ObjectGL* copy() { return 0;}
00297 virtual void applyTransform() { ;}
00298
00299
00300 virtual int read(const char* filename) ;
00301 virtual int write(const char* filename) const ;
00302 virtual int writeRIB(const char* filename) const {return 1; }
00303 virtual int writePOVRAY(const char* filename) const {return 1; }
00304 virtual int read(ifstream &fin) ;
00305 virtual int write(ofstream &fout) const ;
00306 virtual int writeRIB(ofstream &fout) const { return 1; }
00307 virtual int writePOVRAY(ofstream &fout) const { return 1; }
00308
00309
00310 void setName(const char* n) ;
00311 char* name() const { return name_ ; }
00312 char* typeName() const ;
00313
00314 protected:
00315 int selected,active ;
00316 ObjectGLState state ;
00317 ObjectGL *prev_,*next_ ;
00318 char* name_ ;
00319 };
00320
00321
00330 class ObjectRefGL : public ObjectGL {
00331 public:
00332 ObjectRefGL(ObjectGL* p) : ptr(ptr_) { ptr_ = p ; }
00333
00334 ObjectGL* &ptr ;
00335 void glObject() const { ptr->glObject(); }
00336
00337 protected:
00338 ObjectGL* ptr_ ;
00339 };
00340
00347 class ObjectListGL : public ObjectGL {
00348 public:
00349 ObjectListGL() ;
00350 virtual ~ObjectListGL() ;
00351
00352 ObjectGL* first() const { return first_ ; }
00353 ObjectGL* last() const { return last_ ; }
00354 ObjectGL* current() const { return current_ ; }
00355 ObjectGL*& first() { return first_ ; }
00356 ObjectGL*& last() { return last_ ; }
00357 ObjectGL*& current() { return current_ ; }
00358
00359 virtual void glObject() const ;
00360 virtual void display() const ;
00361 virtual void displayName() const ;
00362
00363 void reset() ;
00364 void setResetMode(int m) { resetMode = m ; }
00365 void add(ObjectGL* obj) ;
00366 ObjectGL* remove(ObjectGL* obj) ;
00367
00368
00369
00370 void activate() ;
00371 void deactivate() ;
00372
00373 void select() ;
00374 void deselect() ;
00375
00376 void transformTo(GLfloat x, GLfloat y, GLfloat z, GLfloat a, GLfloat b, GLfloat c, GLfloat sx, GLfloat sy, GLfloat sz, int behavior=NURBS_FLAGS_AFFECT_ALL) ;
00377 void transformBy(GLfloat x, GLfloat y, GLfloat z, GLfloat a, GLfloat b, GLfloat c, GLfloat sx, GLfloat sy, GLfloat sz, int behavior=NURBS_FLAGS_AFFECT_ALL) ;
00378
00379 ObjectGL* goTo(int a) ;
00380 ObjectGL* goToActive(int a) ;
00381
00382 ObjectGL* goToNext() ;
00383 ObjectGL* goToPrevious() ;
00384
00385 ObjectGL* goToNextActive() ;
00386 ObjectGL* goToPreviousActive() ;
00387
00388 ObjectGL* jumpToNext() ;
00389 ObjectGL* jumpToPrevious() ;
00390
00391 void setJumpSize(int a) {if(a>0) jumpSize=a ; }
00392
00393 int size() const { return n; }
00394
00395 virtual int read(const char* filename) ;
00396 virtual int write(const char* filename) const ;
00397 virtual int writeRIB(const char* filename) const ;
00398 virtual int writePOVRAY(const char* filename) const ;
00399
00400 void viewAllObjects() ;
00401 void hideAllObjects() ;
00402
00403 protected:
00404 ObjectGL *first_, *last_ ;
00405 ObjectGL *current_ ;
00406 int jumpSize ;
00407 int n ;
00408 int resetMode ;
00409 };
00410
00417 class ObjectRefListGL : public ObjectListGL{
00418 public:
00419 ObjectRefListGL() : ObjectListGL() { resetMode = NURBSLIST_KEEP_AT_RESET ; }
00420 ~ObjectRefListGL() ;
00421
00422 void add(ObjectGL* obj) { ObjectRefGL *t = new ObjectRefGL(obj) ; ObjectListGL::add(t) ; }
00423 ObjectGL* remove(ObjectGL* obj) ;
00424
00425 void refList(const ObjectListGL* list, int addOnce=1) ;
00426
00427 };
00428
00429
00436 class PointListGL : public ObjectGL {
00437 public:
00438 PointListGL() : ObjectGL() { category = pointType ; type = pointListObject ; psize = pSizeDefault ; }
00439 PointListGL(const PointListGL &pl);
00440 PointListGL(const BasicList<Point3Df> &l) ;
00441 virtual void glObject() const ;
00442 void setPsize(int s) {psize = s ;}
00443
00444 int read(const char*f) { return ObjectGL::read(f); }
00445 int write(const char* f) const { return ObjectGL::write(f); }
00446
00447 int read(ifstream &fin) ;
00448 int write(ofstream &fout) const ;
00449
00450 void applyTransform() ;
00451
00452
00453 ObjectGL* copy() { PointListGL *t = new PointListGL(*this) ; return t ; }
00454
00455 mutable BasicList<Point3Df> list ;
00456 protected:
00457 int psize ;
00458 };
00459
00460
00467 class CPointGL : public ObjectGL {
00468 protected:
00469 CPointGL() : ObjectGL(), cpoint(dummyCPoint), symPoint(0) { type = cpointObject; psize=pSizeDefault ; xCoord = yCoord = zCoord = wCoord = 1.0 ;}
00470 public:
00471 CPointGL(HPoint3Df& cp, int i,int j=-1): ObjectGL(), cpoint(cp), symPoint(0) { type = cpointObject; psize=pSizeDefault ; i0= i ; j0=j ; }
00472 ~CPointGL() {;}
00473
00474 virtual void glObject() const;
00475
00476 virtual void modify(const HPoint3Df& v) { cpoint += v ; }
00477 virtual void modifySym(const HPoint3Df &v) ;
00478
00479 void setPsize(int s) {psize = s ; }
00480
00481 HPoint3Df& point() const { return cpoint ; }
00482
00483 void setSym(CPointGL* sp, float x, float y, float z, float w) { symPoint = sp ; xCoord = x; yCoord = y ; zCoord = z; wCoord = w ; if(symPoint == this) symPoint = 0 ;}
00484
00485 int row() const { return i0 ; }
00486 int col() const { return j0 ; }
00487
00488 protected:
00489 HPoint3Df& cpoint ;
00490 int psize ;
00491 int i0,j0 ;
00492 CPointGL *symPoint ;
00493 float xCoord,yCoord,zCoord,wCoord ;
00494 };
00495
00496 class HNurbsSurfaceGL ;
00497
00504 class HCPointGL : public CPointGL {
00505 public:
00506 HCPointGL(HPoint3Df& off, int i, int j, HNurbsSurfaceGL* hs, int mod): CPointGL(), offset(off),s(hs) { type = hcpointObject; psize=pSizeDefault ; i0 = i ; j0 = j ; canModify = mod ;}
00507 ~HCPointGL() { ; }
00508
00509 virtual void glObject() const;
00510
00511 virtual void modify(const HPoint3Df& v) ;
00512
00513 protected:
00514 HPoint3Df& offset ;
00515 HNurbsSurfaceGL *s ;
00516 int canModify ;
00517 };
00518
00525 class SPointGL : public CPointGL {
00526 protected:
00527 SPointGL(HPoint3Df& cp, int i,int j,int fix) : CPointGL(cp,i,j),editFix(fix) { } ;
00528
00529
00530 public:
00531 virtual ~SPointGL() { ; }
00532
00533 void setFixEdit(int f) { editFix = f ; }
00534 int fixEdit() const { return editFix ; }
00535
00536 protected:
00537 int editFix ;
00538
00539 };
00540
00547 class SPointCurveGL : public SPointGL {
00548 public:
00549 SPointCurveGL(int i, NurbsCurveSPf *c, int fix);
00550 ~SPointCurveGL() { ; }
00551
00552 virtual void glObject() const;
00553
00554 virtual void modify(const HPoint3Df& v) ;
00555
00556 void updateOthers() ;
00557
00558 void setStartEnd(SPointCurveGL* s, int r) { start = s; rows = r ; }
00559
00560 protected:
00561 HPoint3Df spoint ;
00562 NurbsCurveSPf *curve ;
00563 SPointCurveGL *start ;
00564 int rows ;
00565 };
00566
00573 class SPointSurfaceGL : public SPointGL {
00574 public:
00575 SPointSurfaceGL(int i, int j, NurbsSurfaceSPf *s, ObjectListGL *sp, int fix);
00576 ~SPointSurfaceGL() { ; }
00577
00578 virtual void glObject() const;
00579
00580 virtual void modify(const HPoint3Df& v) ;
00581
00582 void updateOthers() ;
00583
00584 void setStartEnd(SPointSurfaceGL* s, int r, int c=0) { start = s; rows = r ; cols = c ; }
00585
00586 protected:
00587 HPoint3Df spoint ;
00588 NurbsSurfaceSPf *surface ;
00589 SPointSurfaceGL *start ;
00590 ObjectListGL *spoints ;
00591 int rows,cols ;
00592 };
00593
00600 class SPointHSurfaceGL : public SPointGL {
00601 public:
00602 SPointHSurfaceGL(int i, int j, HNurbsSurfaceSPf *s, ObjectListGL *sp, int fix);
00603 ~SPointHSurfaceGL() { ; }
00604
00605 virtual void glObject() const;
00606
00607 virtual void modify(const HPoint3Df& v) ;
00608
00609 void updateOthers() ;
00610
00611 void setStartEnd(SPointHSurfaceGL* s, int r, int c=0) { start = s; rows = r ; cols = c ; }
00612
00613 protected:
00614 HPoint3Df spoint ;
00615 HNurbsSurfaceSPf *surface ;
00616 SPointHSurfaceGL *start ;
00617 ObjectListGL *spoints ;
00618 int rows,cols ;
00619 };
00620
00627 class PointGL : public ObjectGL {
00628 public:
00629 PointGL(const Point3Df& p3d): ObjectGL(), p(p3d) { type = pointObject ; psize=pSizeDefault ;}
00630
00631 void glObject() const ;
00632
00633 void modify(const Point3Df& v) { p += v ; }
00634 void set(const Point3Df& v) { p = v ; }
00635
00636 void setPsize(int s) {psize = s ; }
00637
00638 float x() const { return p.x() ; }
00639 float y() const { return p.y() ; }
00640 float z() const { return p.z() ; }
00641 const Point3Df& point() const { return p ; }
00642
00643 ObjectGL* copy() { PointGL* t = new PointGL(p) ; return t ; }
00644
00645 protected:
00646 Point3Df p ;
00647 int psize ;
00648 };
00649
00656 class KnotGL : public ObjectGL {
00657 public:
00658 KnotGL(const Point3Df& p3d, int kU, int kV): ObjectGL(), p(p3d), ku(kU), kv(kV) { type = pointObject ; psize=pSizeDefault ;}
00659
00660 void glObject() const ;
00661
00662 void modify(const Point3Df& v) { p += v ; }
00663 void set(const Point3Df& v) { p = v ; }
00664
00665 void setPsize(int s) {psize = s ; }
00666
00667 float x() const { return p.x() ; }
00668 float y() const { return p.y() ; }
00669 float z() const { return p.z() ; }
00670 const Point3Df& point() const { return p ; }
00671
00672 ObjectGL* copy() { PointGL* t = new PointGL(p) ; return t ; }
00673
00674 int knotU() { return ku ; }
00675 int knotV() { return kv ; }
00676
00677 protected:
00678 Point3Df p ;
00679 int ku,kv ;
00680 int psize ;
00681 };
00682
00689 class NurbsCpolygonGL : public ObjectGL {
00690 public:
00691 NurbsCpolygonGL(NurbsCurvef& c): ObjectGL(),curve(c) { objectColor = cPolygonColorDefault;} ;
00692
00693 void glObject() const;
00694
00695 protected:
00696 NurbsCurvef& curve ;
00697 };
00698
00705 class NurbsSpolygonGL : public ObjectGL {
00706 public:
00707 NurbsSpolygonGL(NurbsSurfacef& s): ObjectGL(),surface(s) {objectColor = cPolygonColorDefault;}
00708
00709 void glObject() const;
00710
00711
00712 protected:
00713 NurbsSurfacef& surface ;
00714 };
00715
00722 class BoundingBoxGL : public ObjectGL {
00723 public:
00724 BoundingBoxGL() ;
00725
00726 void glObject() const;
00727
00728 Point3Df minP, maxP ;
00729
00730 void setColorXYZ(const Color& colX, const Color& colY, const Color& colZ){
00731 colorX = colX; colorY = colY; colorZ = colZ ; }
00732
00733 protected:
00734 Color colorX, colorY, colorZ ;
00735 };
00736
00743 class NurbsGL : public ObjectGL {
00744 public:
00745 NurbsGL();
00746
00747 virtual ~NurbsGL() { if(polygon) delete polygon ; }
00748
00749
00750 virtual NurbsGL& operator=(const NurbsGL& a) ;
00751
00752 virtual void gluNurbs() const = 0 ;
00753
00754 void setNurbsRenderer(GLUnurbsObj *nobj) { nurbsRenderer = nobj ; }
00755
00756 virtual void glObject() const;
00757
00758 virtual void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const = 0 ;
00759
00760 virtual void resetAll() { resetBoundingBox(); resetCPoints(); resetPolygon(); resetKnots(); }
00761 virtual void resetBoundingBox() {} ;
00762 virtual void resetCPoints() {} ;
00763 virtual void resetPolygon() {};
00764 virtual void resetKnots() {} ;
00765
00766 friend NurbsGL* readNurbsObject(const char* filename) ;
00767
00768 Color colorCP, colorCP0, colorPolygon, colorKnot ;
00769
00770
00771 void setObjectColor(const Color& a, const Color& b, const Color& c){ objectColor=a ; selectColor = b ; currentColor = c ; }
00772 void setBBoxColor(const Color& a, const Color& b, const Color& c,const Color& d, const Color& e, const Color& f){ bbox.objectColor=a ; bbox.selectColor = b ; bbox.currentColor = c ; bbox.setColorXYZ(d,e,f) ;}
00773 void setPolygonColor(const Color& a, const Color& b, const Color& c){ polygon->objectColor=a ; polygon->selectColor = b ; polygon->currentColor = c ; }
00774 void setCPointColor(const Color& a, const Color& b, const Color& c, const Color& d){ colorCP=a ; colorCP0=b ; cpoints.selectColor = c ; cpoints.currentColor = d ; }
00775 void setKnotsColor(const Color& a, const Color& b, const Color& c){ knots.objectColor = colorKnot =a ; knots.selectColor = b ; knots.currentColor = c ; }
00776
00777 void viewBBox() { bbox.viewObject();}
00778 void viewCPoints() { cpoints.viewAllObjects();}
00779 void viewCpolygon(){ if(polygon) polygon->viewObject() ; }
00780 void viewNurbs() { nurbsState = objectState ; }
00781 void viewKnots() { knots.viewObject();}
00782
00783 void hideBBox() { bbox.hideObject();}
00784 void hideCPoints() { cpoints.hideAllObjects();}
00785 void hideCpolygon() { if(polygon) polygon->hideObject() ; }
00786 void hideNurbs() { nurbsState = hideState ; }
00787 void hideKnots() { knots.hideObject() ; }
00788
00789 void select() { selected = 1 ; bbox.select() ; }
00790 void deselect() { selected = 0 ; bbox.deselect() ; }
00791
00792 void activate() { active = 1 ; bbox.activate() ; }
00793 void deactivate() { active = 0 ; bbox.deactivate() ; }
00794
00795 virtual void setSym(int set, int uDir, float x, float y, float z, float w) = 0 ;
00796
00797 ObjectListGL cpoints;
00798 ObjectListGL knots ;
00799 ObjectGL *polygon;
00800 BoundingBoxGL bbox ;
00801
00802 ObjectGLState nurbsState ;
00803
00804 virtual void modifyPoint(float u, float v, float dx, float dy, float dz) = 0 ;
00805
00806 int editSurfacePoints() const { return editSP ; }
00807 int editControlPoints() const { return !editSP; }
00808 int editSurfacePoints(int a) { editSP = a ; return editSP ; }
00809 int editControlPoints(int a) { editSP = !a ; return !editSP; }
00810 int editFixPoints() const { return editFix ; }
00811 int editFixPoints(int a) { editFix = a ; return editFix ; }
00812
00813 void setULines(int u) { if(u<=1) u = 2 ; nUlines = u ; }
00814 void setVLines(int v) { if(v<=2) v = 2 ; nVlines = v ; }
00815 int ULines() const { return nUlines ; }
00816 int VLines() const { return nVlines ; }
00817
00818 protected:
00819 int editSP, editFix ;
00820 GLUnurbsObj *nurbsRenderer;
00821 int nUlines,nVlines ;
00822 };
00823
00824
00825
00832 class NurbsCurveGL : public NurbsCurveSPf, public NurbsGL {
00833 public:
00834 NurbsCurveGL() : NurbsCurveSPf(),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00835 NurbsCurveGL(const NurbsCurvef& nurb): NurbsCurveSPf(nurb),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00836 NurbsCurveGL(const NurbsCurveGL& nurb): NurbsCurveSPf((NurbsCurvef)nurb),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00837 NurbsCurveGL(const Vector<HPoint3Df>& P1, const Vector<float> &U1, int degree=3):NurbsCurveSPf(P1,U1,degree),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00838 NurbsCurveGL(const Vector<Point3Df>& P1, const Vector<float> &W, const Vector<float> &U1, int degree=3):NurbsCurveSPf(P1,W,U1,degree),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00839
00840 void gluNurbs() const;
00841 void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const ;
00842
00843 NurbsCurveGL& operator=(const NurbsCurveGL& a) ;
00844 NurbsCurveGL& operator=(const NurbsCurvef& a) ;
00845
00846 void resetBoundingBox() ;
00847 void resetCPoints() ;
00848 void resetPolygon() {}
00849 void resetKnots() ;
00850
00851 ObjectGL* copy() { NurbsCurveGL *t = new NurbsCurveGL(*this); return t ; }
00852
00853 int read(ifstream &fin) ;
00854 int write(ofstream &fout) const ;
00855
00856 void applyTransform() ;
00857 void modifyPoint(float u, float v, float dx, float dy, float dz);
00858
00859
00860 void setSym(int set, int uDir, float x, float y, float z, float w) { }
00861
00862 };
00863
00870 class NurbsSurfaceGL : public NurbsSurfaceSPf, public NurbsGL {
00871 public:
00872 NurbsSurfaceGL():NurbsSurfaceSPf(),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; }
00873 NurbsSurfaceGL(const NurbsSurfacef& nS):NurbsSurfaceSPf(nS),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; }
00874 NurbsSurfaceGL(const NurbsSurfaceGL& nS):NurbsSurfaceSPf((NurbsSurfacef)nS),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; }
00875 NurbsSurfaceGL(int DegU, int DegV, const Vector<float>& Uk, const Vector<float>& Vk, const Matrix<HPoint3Df>& Cp):NurbsSurfaceSPf(DegU,DegV,Uk,Vk,Cp),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; }
00876 NurbsSurfaceGL(int DegU, int DegV, Vector<float>& Uk, Vector<float>& Vk, Matrix< Point3Df >& Cp, Matrix<float>& W):NurbsSurfaceSPf(DegU,DegV,Uk,Vk,Cp,W),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; } ;
00877 ~NurbsSurfaceGL() { if(image) delete []image ; }
00878
00879 void gluNurbs() const;
00880 void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const ;
00881
00882 virtual NurbsSurfaceGL& operator=(const NurbsSurfaceGL& a);
00883 virtual NurbsSurfaceGL& operator=(const NurbsSurfacef& a);
00884
00885
00886 void resetBoundingBox() ;
00887 void resetCPoints() ;
00888 void resetPolygon() {}
00889 void resetKnots() ;
00890
00891 int read(ifstream &fin) ;
00892 int write(ofstream &fout) const ;
00893
00894 int writeRIB(ofstream &fout) const { return NurbsSurfacef::writeRIB(fout); }
00895
00896 int writePOVRAY(ofstream &fout) const { return NurbsSurfacef::writePOVRAY(0.1,fout); }
00897
00898 ObjectGL* copy() { NurbsSurfaceGL *t = new NurbsSurfaceGL(*this); return t ; }
00899
00900 void applyTransform() ;
00901
00902 void modifyPoint(float u, float v, float dx, float dy, float dz);
00903
00904 void setImage(GLubyte *img,GLint w, GLint h) ;
00905
00906 void setSym(int set, int uDir, float x, float y, float z, float w) ;
00907
00908
00909 std::list<NurbsCurve_2Df*> trimmedCurves ;
00910
00911 protected:
00912 GLubyte *image ;
00913 GLint imgW, imgH ;
00914
00915 };
00916
00923 class HNurbsSurfaceGL : public HNurbsSurfaceSPf, public NurbsGL {
00924 public:
00925 HNurbsSurfaceGL() ;
00926 HNurbsSurfaceGL(const NurbsSurfacef& nS);
00927 HNurbsSurfaceGL(const HNurbsSurfaceGL& bS) ;
00928 HNurbsSurfaceGL(const HNurbsSurfaceGL* bS);
00929 virtual ~HNurbsSurfaceGL() { ; }
00930
00931 void setLevelOfDetail(int l) { lod = l ; }
00932 int levelOfDetail() const { return lod; }
00933 void increaseLevelOfDetail() { ++lod ; if(lod>maxLevel()) lod=maxLevel() ;}
00934 void decreaseLevelOfDetail() ;
00935 void highestLevelOfDetail() { lod = maxLevel() ; }
00936 int maxLevelOfDetail() { return maxLevel() ; }
00937
00938 void gluNurbs() const;
00939 void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const ;
00940
00941
00942
00943
00944 void resetBoundingBox() ;
00945 void resetCPoints() ;
00946 void resetPolygon() ;
00947 void resetKnots() { }
00948
00949
00950 int read(const char*f) { return ObjectGL::read(f); }
00951 int write(const char* f) const { return ObjectGL::write(f); }
00952
00953 int read(ifstream &fin) ;
00954 int write(ofstream &fout) const ;
00955
00956
00957 int writeRIB(ofstream &fout) const { return NurbsSurfacef::writeRIB(fout); }
00958
00959 int writePOVRAY(ofstream &fout) const { return NurbsSurfacef::writePOVRAY(0.1,fout); }
00960
00961
00962
00963 void selectBasePatch() { activePatch = this ; }
00964 void selectNextPatch() ;
00965 void selectPrevPatch() ;
00966 void selectHigherLevel() ;
00967 void selectLowerLevel() ;
00968 void selectHighestLevel() ;
00969 int editLevel() { return activePatch->level() ; }
00970
00971 void updateUpToLOD() { updateLevels(lod) ; }
00972
00973 HNurbsSurfaceSPf* addLevel() ;
00974
00975 void applyTransform() ;
00976 void modifyPoint(float u, float v, float dx, float dy, float dz);
00977
00978
00979 ObjectGL* copy() { HNurbsSurfaceGL *t = new HNurbsSurfaceGL(*this); return t ; }
00980
00981 void setSym(int set, int uDir, float x, float y, float z, float w) ;
00982
00983 void axis(int i, int j, Point3Df& xaxis, Point3Df& yaxis, Point3Df& zaxis) const { activePatch->HNurbsSurfacef::axis(i,j,xaxis,yaxis,zaxis) ; }
00984
00985 protected:
00986 int lod ;
00987 HNurbsSurfaceGL *activePatch ;
00988 };
00989
00996 class NurbsListGL : public ObjectListGL {
00997 public:
00998
00999 NurbsGL* remove(NurbsGL* obj) { return (NurbsGL*)ObjectListGL::remove(obj) ; }
01000
01001 void glObject() const ;
01002 void display() const ;
01003
01004 void resetDisplayFlags(int o, int cp, int p, int b, int k, int behavior=NURBS_FLAGS_AFFECT_ALL) ;
01005 };
01006
01007
01008 void initColorsGL() ;
01009
01020 class SimpleNurbsCurveGL : public NurbsGL, public NurbsCurvef {
01021 protected:
01022 SimpleNurbsCurveGL() : NurbsCurvef(),NurbsGL() { type = curveObject ; polygon = 0 ;}
01023
01024 public:
01025
01026 void gluNurbs() const;
01027 void glObject() const { gluNurbs() ; }
01028
01029 void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const {}
01030 void resetBoundingBox() {}
01031 void resetCPoints() {}
01032 void resetPolygon() {}
01033 void resetKnots() {}
01034
01035 void modifyPoint(float u, float v, float dx, float dy, float dz) { }
01036 void setSym(int set, int uDir, float x, float y, float z, float w) { }
01037
01038 friend class NurbsCurveGL ;
01039 friend class NurbsSurfaceGL ;
01040 friend class HNurbsSurfaceGL ;
01041
01042 };
01043
01044 }
01045
01046 typedef PLib::NurbsCurveGL PlNurbsCurveGL ;
01047 typedef PLib::NurbsSurfaceGL PlNurbsSurfaceGL ;
01048 typedef PLib::HNurbsSurfaceGL PlHNurbsSurfaceGL ;
01049 typedef PLib::ObjectGL PlObjectGL ;
01050 typedef PLib::NurbsListGL PlNurbsListGL ;
01051 typedef PLib::ObjectRefGL PlObjectRefGL ;
01052 typedef PLib::ObjectListGL PlObjectListGL ;
01053 typedef PLib::ObjectRefListGL PlObjectRefListGL ;
01054 typedef PLib::PointListGL PlPointListGL ;
01055 typedef PLib::CPointGL PlCPointGL ;
01056 typedef PLib::HCPointGL PlHCPointGL ;
01057 typedef PLib::SPointGL PlSPointGL ;
01058 typedef PLib::SPointCurveGL PlSPointCurveGL ;
01059 typedef PLib::SPointSurfaceGL PlSPointSurfaceGL ;
01060 typedef PLib::SPointHSurfaceGL PlSPointHSurfaceGL ;
01061 typedef PLib::PointGL PlPointGL ;
01062 typedef PLib::KnotGL PlKnotGL ;
01063 typedef PLib::NurbsCpolygonGL PlNurbsCpolygonGL ;
01064 typedef PLib::NurbsSpolygonGL PlNurbsSpolygonGL ;
01065 typedef PLib::BoundingBoxGL PlBoundingBoxGL ;
01066 typedef PLib::NurbsGL PlNurbsGL ;
01067 typedef PLib::SimpleNurbsCurveGL PlSimpleNurbsCurveGL ;
01068
01069 #endif // WITH_OPENGL
01070
01071 #endif