Main Page   Class Hierarchy   Compound List   File List   Compound Members  

nurbsGL.h

00001 /*=============================================================================
00002         File: nurbsGL.H
00003      Purpose: Describes all OpenGL related classes.
00004     Revision: $Id: nurbsGL.h,v 1.3 2002/05/27 19:57:45 philosophil Exp $
00005   Created by: Philippe Lavoie          (28 September, 1997)
00006  Modified by: 
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-1998 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 //enum NurbsGLState { showCurve=0, showCPoints, showBbox } ;
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   extern const int NURBS_DISPLAY_SOLID ;
00078                  
00079 extern const int NURBSLIST_DELETE_AT_RESET ;
00080 extern const int NURBSLIST_KEEP_AT_RESET ;
00081 
00082 extern int NurbsDisplayMode ;
00083 extern float tessel_tolerance ;
00084 
00085 extern HPoint3Df dummyCPoint ;
00086 
00087 extern Point3Df XAxis_3D ;
00088 extern Point3Df YAxis_3D ;
00089 extern Point3Df ZAxis_3D ;
00090 
00091  struct NurbsSubSurfaceGL : public NurbsSubSurface<float> {
00092    NurbsSubSurfaceGL(const NurbsSurface<float,3>& s, const Color& c) : NurbsSubSurface<float>(s), color(c) {;}
00093    ~NurbsSubSurfaceGL() {;}
00094    void drawSubdivisionGL(float tolerance) ;
00095  protected:
00096    Color color ; 
00097  };
00098 
00099 
00111 inline void glColor(const Color& color){
00112   //glColor3f(GLfloat(color.r)/255.0,GLfloat(color.g)/255.0,GLfloat(color.b)/255.0) ;
00113 }
00114 
00128 inline void colorToMaterial(const Color& color, GLfloat* c, GLfloat alpha=1.0){
00129   c[0] = GLfloat(color.r)/255.0 ;
00130   c[1] = GLfloat(color.g)/255.0 ;
00131   c[2] = GLfloat(color.b)/255.0 ;
00132   c[3] = alpha ;
00133 }
00134 
00145 struct RGBAf {
00146   float r,g,b,a ;
00147 
00148   RGBAf(){ r=g=b=a=0;}
00149   RGBAf(const RGBAf& c) { r = c.r ; g =c.g ; b=c.b ; a=c.a; }
00150   RGBAf(const Color& c) { r = (float)c.r/255.0 ; g = (float)c.g/255.0 ; b = (float)c.b/255.0 ; a = 1 ; }
00151 
00152 };
00153 
00167 struct Material {
00168   Material() ; 
00169   // For OpenGL rendering
00170   RGBAf frontAmbient, backAmbient ;
00171   RGBAf frontDiffuse, backDiffuse ;
00172   RGBAf frontSpecular, backSpecular ;
00173   RGBAf frontEmission, backEmission ;
00174   float frontShininess, backShininess ;
00175   void glMaterial() ;
00176   
00177   // for POV-RAY rendering 
00178   // pigment options
00179   RGBAf pigment ;
00180   double pigment_transfer ;
00181   double pigment_transmit ;
00182   char *pigment_userdefined ;
00183   // normal options
00184   double bump,bump_scale ;
00185   char *normal_userdefined ;
00186   // finish options
00187   Color ambient ;
00188   double diffuse,brilliance,phong,specular,roughness,metallic ;
00189   Color reflection ;
00190   double refraction,ior,caustics,fade_distance,fade_power ;
00191   double irid_thick ;
00192   Vector< Point3Df > irid_turbulence ;
00193   double crand ;
00194 
00195   // for RIB rendering
00196   char* material ;
00197 };
00198 
00216 class ObjectGL {
00217 public:
00218   ObjectGL() ; 
00219   virtual ~ObjectGL() ;
00220 
00221   ObjectGL& operator=(const ObjectGL& a) ;
00222 
00223   Color objectColor ;
00224   Color selectColor ;
00225   Color currentColor ;
00226   GLfloat *materialColor ;
00227   
00228 
00229   void setObjectColor(const Color& c) { objectColor = c ; }
00230   void setSelectColor(const Color& c) { selectColor = c ; }
00231   void setCurrentColor(const Color& c) { currentColor = c ; }
00232 
00233   void glSelectColor() const { glColor(selectColor) ; colorToMaterial(selectColor,materialColor) ;}
00234   void glObjectColor() const { glColor(objectColor) ; colorToMaterial(objectColor,materialColor) ;}
00235   void glCurrentColor() const { glColor(currentColor) ; colorToMaterial(currentColor,materialColor) ;}
00236 
00237   void hideObject() { state = hideState ; }
00238   void selectObject() { state = selectedState ; }
00239   void viewObject() { state = objectState ; }
00240   void currentObject() { state = currentState ; }
00241 
00242   virtual void glColor() const 
00243     { if(isActive())
00244         glColor(currentColor) ;
00245         else{
00246           if(isSelected()) glColor(selectColor) ; 
00247           else glColor(objectColor) ; }
00248     }
00249                              
00250 
00251   void glColor(const Color& c) const {
00252     colorToMaterial(Color(0,0,0),materialColor) ;
00253     glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,materialColor) ;
00254     colorToMaterial(c,materialColor) ;
00255     glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,materialColor) ;
00256     //glColor3f(c) ;
00257   }
00258 
00259   virtual void glObject() const = 0 ;  
00260 
00261   enum ObjectCategory { badType, nurbsType, pointType, vectorType, listType };
00262   enum ObjectType {badObject,curveObject,surfaceObject,pointObject,cpointObject,cpointPolygonObject,bboxObject,vectorObject,listObject,hSurfObject,hcpointObject,pointListObject,spointObject} ;
00263   ObjectType type ;
00264   ObjectCategory category ;
00265 
00266 
00267   // object tranformation information
00268   GLfloat tx,ty,tz ;
00269   GLfloat rx,ry,rz ;
00270   GLfloat sx,sy,sz ;
00271 
00272   virtual void glTransform() const ;
00273 
00274   virtual void display() const { if(state) {glPushMatrix() ; glTransform() ; glObject(); glPopMatrix() ;} }
00275   virtual void displayList()  { if(state) {glPushMatrix() ; glTransform() ; glColor(); glCallList(callListId); glPopMatrix();} }
00276   virtual void displayName() { ; }
00277   
00278   virtual void glNewList() ; 
00279   int callListId ; // This is assigned by the user, NOT the class
00280 
00281   // Information for the link list node
00282   virtual ObjectGL*& previous() { return prev_ ;}
00283   virtual ObjectGL*& next() { return next_ ;}
00284   virtual ObjectGL* previous() const { return prev_ ;}
00285   virtual ObjectGL* next() const { return next_ ;}
00286 
00287   ObjectGLState getState() const { return state ; }
00288 
00289   virtual void select() { selected = 1 ; }
00290   virtual void deselect() { selected = 0 ; }
00291   int isSelected() const { return selected ; }
00292 
00293   virtual void activate() { active = 1 ; }
00294   virtual void deactivate() { active = 0 ; }
00295   int isActive() const { return active ; }
00296 
00297   virtual ObjectGL* copy() { return 0;} 
00298   virtual void applyTransform() { ;} 
00299 
00300   // I/O functions
00301   virtual int read(const char* filename) ;
00302   virtual int write(const char* filename) const ;
00303   virtual int writeRIB(const char* filename) const {return 1; }
00304   virtual int writePOVRAY(const char* filename) const {return 1; }
00305   virtual int read(ifstream &fin) ;
00306   virtual int write(ofstream &fout) const ;
00307   virtual int writeRIB(ofstream &fout) const { return 1; }
00308   virtual int writePOVRAY(ofstream &fout) const { return 1; }
00309 
00310   // Info functions
00311   void setName(const char* n) ;
00312   char* name() const { return name_ ; }
00313   char* typeName() const ;
00314 
00315 protected:
00316   int selected,active ;
00317   ObjectGLState state ;  
00318   ObjectGL *prev_,*next_ ;
00319   char* name_ ; 
00320 };
00321 
00322 
00331 class ObjectRefGL : public ObjectGL {
00332 public:
00333   ObjectRefGL(ObjectGL* p) : ptr(ptr_) { ptr_ = p ; }
00334 
00335   ObjectGL* &ptr ;
00336   void glObject() const { ptr->glObject(); }
00337 
00338 protected:
00339   ObjectGL* ptr_ ;
00340 };
00341 
00348 class ObjectListGL : public ObjectGL {
00349  public:
00350   ObjectListGL() ;
00351   virtual ~ObjectListGL() ;
00352   
00353   ObjectGL* first() const { return first_ ; }
00354   ObjectGL* last() const { return last_ ; }
00355   ObjectGL* current() const { return current_ ; }
00356   ObjectGL*& first() { return first_ ; }
00357   ObjectGL*& last() { return last_ ; }
00358   ObjectGL*& current() { return current_ ; }
00359 
00360   virtual void glObject() const ;
00361   virtual void display() const ;
00362   virtual void displayName() const ;
00363 
00364   void reset() ;
00365   void setResetMode(int m) { resetMode = m ; }
00366   void add(ObjectGL* obj) ;
00367   ObjectGL* remove(ObjectGL* obj) ;
00368   // void insertAfter(ObjectGL* obj) ;
00369   // void insertBefore(ObjectGL* obj) ;
00370 
00371   void activate() ;
00372   void deactivate() ;
00373 
00374   void select() ;
00375   void deselect() ;
00376 
00377   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) ;
00378   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) ;
00379 
00380   ObjectGL* goTo(int a) ;
00381   ObjectGL* goToActive(int a) ;
00382 
00383   ObjectGL* goToNext() ; 
00384   ObjectGL* goToPrevious() ; 
00385 
00386   ObjectGL* goToNextActive() ; 
00387   ObjectGL* goToPreviousActive() ; 
00388 
00389   ObjectGL* jumpToNext() ;
00390   ObjectGL* jumpToPrevious() ;
00391 
00392   void setJumpSize(int a) {if(a>0) jumpSize=a ; }
00393 
00394   int size() const { return  n; }
00395 
00396   virtual int read(const char* filename) ;
00397   virtual int write(const char* filename) const ;
00398   virtual int writeRIB(const char* filename) const ;
00399   virtual int writePOVRAY(const char* filename) const ;
00400 
00401   void viewAllObjects() ;
00402   void hideAllObjects() ;
00403 
00404 protected:
00405   ObjectGL *first_, *last_ ;
00406   ObjectGL *current_ ;
00407   int jumpSize ;
00408   int n ;
00409   int resetMode ;
00410 };
00411 
00418 class ObjectRefListGL : public ObjectListGL{
00419 public:
00420   ObjectRefListGL() : ObjectListGL() { resetMode = NURBSLIST_KEEP_AT_RESET ; }
00421   ~ObjectRefListGL() ;
00422 
00423   void add(ObjectGL* obj) { ObjectRefGL *t = new ObjectRefGL(obj) ; ObjectListGL::add(t) ; }
00424   ObjectGL* remove(ObjectGL* obj) ;
00425 
00426   void refList(const ObjectListGL* list, int addOnce=1) ;
00427 
00428 };
00429 
00430 
00437 class PointListGL : public ObjectGL {
00438 public:
00439   PointListGL() :  ObjectGL() { category = pointType ; type = pointListObject ; psize = pSizeDefault ; }
00440   PointListGL(const PointListGL &pl);
00441   PointListGL(const BasicList<Point3Df> &l) ;
00442   virtual void glObject() const ;
00443   void setPsize(int s) {psize = s ;}
00444 
00445   int read(const char*f) { return ObjectGL::read(f); }
00446   int write(const char* f) const { return ObjectGL::write(f); }
00447 
00448   int read(ifstream &fin) ;
00449   int write(ofstream &fout) const ; 
00450 
00451   void applyTransform() ;
00452 
00453 
00454   ObjectGL* copy() { PointListGL *t = new PointListGL(*this) ; return t ; }
00455 
00456   mutable BasicList<Point3Df> list ;
00457 protected:
00458   int psize ;
00459 };
00460 
00461 
00468 class CPointGL : public ObjectGL  {
00469 protected:
00470   CPointGL() : ObjectGL(), cpoint(dummyCPoint), symPoint(0) { type = cpointObject;  psize=pSizeDefault ; xCoord = yCoord = zCoord = wCoord = 1.0 ;}
00471 public:  
00472   CPointGL(HPoint3Df& cp, int i,int j=-1): ObjectGL(), cpoint(cp), symPoint(0) { type = cpointObject; psize=pSizeDefault ; i0= i ; j0=j ; } 
00473   ~CPointGL() {;}
00474 
00475   virtual void glObject() const;
00476 
00477   virtual void modify(const HPoint3Df& v) { cpoint += v ; }
00478   virtual void modifySym(const HPoint3Df &v) ;
00479 
00480   void setPsize(int s) {psize = s ; }
00481 
00482   HPoint3Df& point() const { return cpoint ; }
00483 
00484   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 ;}
00485 
00486   int row() const { return i0 ; }
00487   int col() const { return j0 ; }
00488 
00489 protected:
00490   HPoint3Df& cpoint ;
00491   int psize ;
00492   int i0,j0 ; 
00493   CPointGL *symPoint ;
00494   float xCoord,yCoord,zCoord,wCoord ;
00495 };
00496 
00497 class HNurbsSurfaceGL ;
00498 
00505 class HCPointGL : public CPointGL  {
00506 public:
00507   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 ;} 
00508   ~HCPointGL() { ; } 
00509 
00510   virtual void glObject() const;
00511 
00512   virtual void modify(const HPoint3Df& v) ;
00513 
00514 protected:
00515   HPoint3Df& offset ;
00516   HNurbsSurfaceGL *s ;
00517   int canModify ;
00518 };
00519 
00526 class SPointGL : public CPointGL {
00527 protected:
00528   SPointGL(HPoint3Df& cp, int i,int j,int fix) : CPointGL(cp,i,j),editFix(fix) { } ;
00529 
00530 
00531 public:
00532   virtual ~SPointGL() { ; }
00533 
00534   void setFixEdit(int f) { editFix = f ; }
00535   int fixEdit() const { return editFix ; }
00536 
00537 protected:
00538   int editFix ; 
00539 
00540 };
00541 
00548 class SPointCurveGL : public SPointGL  {
00549 public:
00550   SPointCurveGL(int i, NurbsCurveSPf *c, int fix);
00551   ~SPointCurveGL() { ; } 
00552 
00553   virtual void glObject() const;
00554 
00555   virtual void modify(const HPoint3Df& v) ; 
00556 
00557   void updateOthers() ; 
00558 
00559   void setStartEnd(SPointCurveGL* s, int r) { start = s; rows = r ;  }
00560 
00561 protected:
00562   HPoint3Df spoint ;
00563   NurbsCurveSPf *curve ;
00564   SPointCurveGL *start ; 
00565   int rows ;
00566 };
00567 
00574 class SPointSurfaceGL : public SPointGL  {
00575 public:
00576   SPointSurfaceGL(int i, int j, NurbsSurfaceSPf *s, ObjectListGL *sp, int fix);
00577   ~SPointSurfaceGL() { ; } 
00578 
00579   virtual void glObject() const;
00580 
00581   virtual void modify(const HPoint3Df& v) ; 
00582 
00583   void updateOthers() ; 
00584 
00585   void setStartEnd(SPointSurfaceGL* s, int r, int c=0) { start = s; rows = r ; cols = c ;  }
00586 
00587 protected:
00588   HPoint3Df spoint ;
00589   NurbsSurfaceSPf *surface ;
00590   SPointSurfaceGL *start ; 
00591   ObjectListGL *spoints ;
00592   int rows,cols ; 
00593 };
00594 
00601 class SPointHSurfaceGL : public SPointGL  {
00602 public:
00603   SPointHSurfaceGL(int i, int j, HNurbsSurfaceSPf *s, ObjectListGL *sp, int fix);
00604   ~SPointHSurfaceGL() { ; } 
00605 
00606   virtual void glObject() const;
00607 
00608   virtual void modify(const HPoint3Df& v) ; 
00609 
00610   void updateOthers() ; 
00611 
00612   void setStartEnd(SPointHSurfaceGL* s, int r, int c=0) { start = s; rows = r ; cols = c ;  }
00613 
00614 protected:
00615   HPoint3Df spoint ;
00616   HNurbsSurfaceSPf *surface ;
00617   SPointHSurfaceGL *start ; 
00618   ObjectListGL *spoints ;
00619   int rows,cols ; 
00620 };
00621 
00628 class PointGL : public ObjectGL  {
00629 public:  
00630   PointGL(const Point3Df& p3d): ObjectGL(), p(p3d) { type = pointObject ; psize=pSizeDefault ;}
00631 
00632   void glObject() const ;
00633 
00634   void modify(const Point3Df& v) { p += v ; }
00635   void set(const Point3Df& v) { p = v ; }
00636 
00637   void setPsize(int s) {psize = s ; }
00638 
00639   float x() const { return p.x() ; }
00640   float y() const { return p.y() ; }
00641   float z() const { return p.z() ; }
00642   const Point3Df& point() const { return p ; }
00643 
00644   ObjectGL* copy() { PointGL* t = new PointGL(p) ; return t ; }
00645 
00646 protected:
00647   Point3Df p ;
00648   int psize ;
00649 };
00650 
00657 class KnotGL : public ObjectGL  {
00658 public:  
00659   KnotGL(const Point3Df& p3d, int kU, int kV): ObjectGL(), p(p3d), ku(kU), kv(kV) { type = pointObject ; psize=pSizeDefault ;}
00660 
00661   void glObject() const ;
00662 
00663   void modify(const Point3Df& v) { p += v ; }
00664   void set(const Point3Df& v) { p = v ; }
00665 
00666   void setPsize(int s) {psize = s ; }
00667 
00668   float x() const { return p.x() ; }
00669   float y() const { return p.y() ; }
00670   float z() const { return p.z() ; }
00671   const Point3Df& point() const { return p ; }
00672 
00673   ObjectGL* copy() { PointGL* t = new PointGL(p) ; return t ; }
00674   
00675   int knotU() { return ku ; }
00676   int knotV() { return kv ; }
00677 
00678 protected:
00679   Point3Df p ;
00680   int ku,kv ;
00681   int psize ;
00682 };
00683 
00690 class NurbsCpolygonGL : public ObjectGL  {
00691 public:  
00692   NurbsCpolygonGL(NurbsCurvef& c): ObjectGL(),curve(c) { objectColor = cPolygonColorDefault;} ;
00693 
00694   void glObject() const;
00695 
00696 protected:
00697   NurbsCurvef& curve ;
00698 };
00699 
00706 class NurbsSpolygonGL : public ObjectGL  {
00707 public:  
00708   NurbsSpolygonGL(NurbsSurfacef& s): ObjectGL(),surface(s) {objectColor = cPolygonColorDefault;}
00709 
00710   void glObject() const;
00711 
00712 
00713 protected:
00714   NurbsSurfacef& surface ;
00715 };
00716 
00723 class BoundingBoxGL : public ObjectGL  {
00724 public:  
00725   BoundingBoxGL() ;
00726 
00727   void glObject() const;
00728 
00729   Point3Df minP, maxP ;
00730  
00731   void setColorXYZ(const Color& colX, const Color& colY, const Color& colZ){
00732     colorX = colX; colorY = colY; colorZ = colZ ; }
00733 
00734 protected:
00735   Color colorX, colorY, colorZ ;
00736 };
00737 
00744 class NurbsGL : public ObjectGL {
00745 public:
00746   NurbsGL();
00747 
00748   virtual ~NurbsGL() { if(polygon) delete polygon ; }
00749 
00750 
00751   virtual NurbsGL& operator=(const NurbsGL& a) ;
00752 
00753   virtual void gluNurbs() const = 0 ;
00754   
00755   void setNurbsRenderer(GLUnurbsObj *nobj) { nurbsRenderer = nobj ; }
00756 
00757   virtual void glObject() const;
00758 
00759   virtual void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const = 0 ;
00760 
00761   virtual void resetAll() { resetBoundingBox(); resetCPoints(); resetPolygon(); resetKnots(); }
00762   virtual void resetBoundingBox() {} ;
00763   virtual void resetCPoints() {} ;
00764   virtual void resetPolygon() {};
00765   virtual void resetKnots() {} ;
00766   
00767   friend NurbsGL* readNurbsObject(const char* filename) ;
00768 
00769   Color colorCP, colorCP0, colorPolygon, colorKnot ;
00770 
00771 
00772   void setObjectColor(const Color& a, const Color& b, const Color& c){ objectColor=a ; selectColor = b ; currentColor = c ; }
00773   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) ;}
00774   void setPolygonColor(const Color& a, const Color& b, const Color& c){ polygon->objectColor=a ; polygon->selectColor = b ; polygon->currentColor = c ; }
00775   void setCPointColor(const Color& a, const Color& b, const Color& c, const Color& d){ colorCP=a ; colorCP0=b ; cpoints.selectColor = c ; cpoints.currentColor = d ; }
00776   void setKnotsColor(const Color& a, const Color& b, const Color& c){ knots.objectColor = colorKnot =a ; knots.selectColor = b ; knots.currentColor = c ; }
00777 
00778   void viewBBox()    { bbox.viewObject();}
00779   void viewCPoints() { cpoints.viewAllObjects();}
00780   void viewCpolygon(){ if(polygon) polygon->viewObject() ; }
00781   void viewNurbs()   { nurbsState = objectState ; }
00782   void viewKnots()   { knots.viewObject();}
00783 
00784   void hideBBox()     { bbox.hideObject();}         
00785   void hideCPoints()  { cpoints.hideAllObjects();}      
00786   void hideCpolygon() { if(polygon) polygon->hideObject() ; }   
00787   void hideNurbs()    { nurbsState = hideState ; }
00788   void hideKnots()    { knots.hideObject() ; }
00789 
00790   void select() { selected = 1 ; bbox.select() ; }
00791   void deselect() { selected = 0 ; bbox.deselect() ; }
00792 
00793   void activate() { active = 1 ; bbox.activate() ; }
00794   void deactivate() { active = 0 ; bbox.deactivate() ; }
00795 
00796   virtual void setSym(int set, int uDir, float x, float y, float z, float w) = 0 ;
00797 
00798   ObjectListGL cpoints;
00799   ObjectListGL knots ;
00800   ObjectGL *polygon; 
00801   BoundingBoxGL bbox ;
00802 
00803   ObjectGLState nurbsState ;
00804 
00805   virtual void modifyPoint(float u, float v, float dx, float dy, float dz) = 0 ;
00806 
00807   int editSurfacePoints() const { return editSP ; }
00808   int editControlPoints() const { return !editSP; }
00809   int editSurfacePoints(int a) { editSP = a ; return editSP ; }
00810   int editControlPoints(int a) { editSP = !a ; return !editSP; }
00811   int editFixPoints() const { return editFix ; }
00812   int editFixPoints(int a) { editFix = a ; return editFix ; }
00813 
00814   void setULines(int u) { if(u<=1) u = 2 ; nUlines = u ; }
00815   void setVLines(int v) { if(v<=2) v = 2 ; nVlines = v ; }
00816   int ULines() const { return nUlines ; }
00817   int VLines() const { return nVlines ; }
00818 
00819 protected:
00820   int editSP, editFix ;
00821   GLUnurbsObj *nurbsRenderer;
00822   int nUlines,nVlines ; 
00823 };
00824 
00825 
00826 
00833 class NurbsCurveGL : public NurbsCurveSPf, public NurbsGL {
00834 public:
00835   NurbsCurveGL() : NurbsCurveSPf(),NurbsGL() { type = curveObject ;  polygon = new NurbsCpolygonGL(*this) ;}
00836   NurbsCurveGL(const NurbsCurvef& nurb): NurbsCurveSPf(nurb),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00837   NurbsCurveGL(const NurbsCurveGL& nurb): NurbsCurveSPf((NurbsCurvef)nurb),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00838   NurbsCurveGL(const Vector<HPoint3Df>& P1, const Vector<float> &U1, int degree=3):NurbsCurveSPf(P1,U1,degree),NurbsGL() { type = curveObject ; polygon = new NurbsCpolygonGL(*this) ;}
00839   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) ;}
00840 
00841   void gluNurbs() const;
00842   void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const ;
00843 
00844   NurbsCurveGL& operator=(const NurbsCurveGL& a) ;
00845   NurbsCurveGL& operator=(const NurbsCurvef& a) ;
00846 
00847   void resetBoundingBox() ;
00848   void resetCPoints() ;
00849   void resetPolygon() {}
00850   void resetKnots() ;
00851 
00852   ObjectGL* copy() { NurbsCurveGL *t = new NurbsCurveGL(*this); return t ; }
00853 
00854   int read(ifstream &fin) ;
00855   int write(ofstream &fout) const ;
00856 
00857   void applyTransform() ;
00858   void modifyPoint(float u, float v, float dx, float dy, float dz);
00859 
00860 
00861   void setSym(int set, int uDir, float x, float y, float z, float w) { }
00862 
00863 };
00864 
00871 class NurbsSurfaceGL : public NurbsSurfaceSPf, public NurbsGL  {
00872 public:  
00873   NurbsSurfaceGL():NurbsSurfaceSPf(),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; }
00874   NurbsSurfaceGL(const NurbsSurfacef& nS):NurbsSurfaceSPf(nS),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; }
00875   NurbsSurfaceGL(const NurbsSurfaceGL& nS):NurbsSurfaceSPf((NurbsSurfacef)nS),NurbsGL() { type = surfaceObject ; polygon = new NurbsSpolygonGL(*this) ; image = 0 ; }
00876   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 ; }
00877   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 ; } ;
00878   ~NurbsSurfaceGL() { if(image) delete []image ; }
00879 
00880   void gluNurbs() const;
00881   void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const ;
00882 
00883   virtual NurbsSurfaceGL& operator=(const NurbsSurfaceGL& a);
00884   virtual NurbsSurfaceGL& operator=(const NurbsSurfacef& a);
00885 
00886 
00887   void resetBoundingBox() ;
00888   void resetCPoints() ;
00889   void resetPolygon() {}
00890   void resetKnots() ;
00891 
00892   int read(ifstream &fin) ;
00893   int write(ofstream &fout) const ;
00894 
00895   int writeRIB(ofstream &fout) const { return NurbsSurfacef::writeRIB(fout); }
00896   //  int writePOVRAY(ofstream &fout) const { return NurbsSurface::writePOVRAY(0.1,fout); }
00897   int writePOVRAY(ofstream &fout) const {  return NurbsSurfacef::writePOVRAY(0.1,fout); }
00898 
00899   ObjectGL* copy() { NurbsSurfaceGL *t = new NurbsSurfaceGL(*this); return t ; }
00900 
00901   void applyTransform() ;
00902 
00903   void modifyPoint(float u, float v, float dx, float dy, float dz);
00904 
00905   void setImage(GLubyte *img,GLint w, GLint h) ;
00906 
00907   void setSym(int set, int uDir, float x, float y, float z, float w) ;
00908 
00909 
00910   std::list<NurbsCurve_2Df*> trimmedCurves ; 
00911 
00912 private:
00913   void displaySolid() const;
00914   void displayWireframe() const;
00915 
00916 protected:
00917   GLubyte *image ;
00918   GLint imgW, imgH ;
00919   //NurbsCurveArray<float> ca ; 
00920 
00921 };
00922 
00929 class HNurbsSurfaceGL : public HNurbsSurfaceSPf, public NurbsGL  {
00930 public:  
00931   HNurbsSurfaceGL() ;
00932   HNurbsSurfaceGL(const NurbsSurfacef& nS);
00933   HNurbsSurfaceGL(const HNurbsSurfaceGL& bS) ;
00934   HNurbsSurfaceGL(const HNurbsSurfaceGL* bS);
00935   virtual ~HNurbsSurfaceGL() { ; }
00936 
00937   void setLevelOfDetail(int l) { lod = l ; }
00938   int levelOfDetail() const { return lod; }
00939   void increaseLevelOfDetail() { ++lod ; if(lod>maxLevel()) lod=maxLevel() ;}
00940   void decreaseLevelOfDetail() ;
00941   void highestLevelOfDetail() { lod = maxLevel() ; }
00942   int maxLevelOfDetail() { return maxLevel() ; }
00943 
00944   void gluNurbs() const;
00945   void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const ;
00946 
00947   //virtual NurbsSurfaceGL& operator=(const NurbsSurfaceGL& a);
00948   //virtual NurbsSurfaceGL& operator=(const NurbsSurface& a);
00949 
00950   void resetBoundingBox() ;
00951   void resetCPoints() ;
00952   void resetPolygon() ;
00953   void resetKnots() { }
00954 
00955 
00956   int read(const char*f) { return ObjectGL::read(f); }
00957   int write(const char* f) const { return ObjectGL::write(f); }
00958 
00959   int read(ifstream &fin) ;
00960   int write(ofstream &fout) const ;
00961 
00962 
00963   int writeRIB(ofstream &fout) const { return NurbsSurfacef::writeRIB(fout); }
00964   //  int writePOVRAY(ofstream &fout) const { return NurbsSurface::writePOVRAY(0.1,fout); }
00965   int writePOVRAY(ofstream &fout) const { return NurbsSurfacef::writePOVRAY(0.1,fout); }
00966 
00967   //void applyTransform() ;
00968 
00969   void selectBasePatch() { activePatch = this ; }
00970   void selectNextPatch() ;
00971   void selectPrevPatch() ;
00972   void selectHigherLevel() ;
00973   void selectLowerLevel() ;
00974   void selectHighestLevel() ;
00975   int editLevel() { return activePatch->level() ; }
00976 
00977   void updateUpToLOD() { updateLevels(lod) ; }
00978 
00979   HNurbsSurfaceSPf* addLevel() ;
00980 
00981   void applyTransform() ;
00982   void modifyPoint(float u, float v, float dx, float dy, float dz);
00983   
00984 
00985   ObjectGL* copy() { HNurbsSurfaceGL *t = new HNurbsSurfaceGL(*this); return t ; }
00986 
00987   void setSym(int set, int uDir, float x, float y, float z, float w) ;
00988 
00989   void axis(int i, int j, Point3Df& xaxis, Point3Df& yaxis, Point3Df& zaxis) const { activePatch->HNurbsSurfacef::axis(i,j,xaxis,yaxis,zaxis) ; }
00990 
00991 protected:
00992   int lod ;
00993   HNurbsSurfaceGL *activePatch ;
00994 };
00995 
01002 class NurbsListGL : public ObjectListGL {
01003  public:
01004   //void add(NurbsGL* obj) { ObjectListGL::add(obj) ; }
01005   NurbsGL* remove(NurbsGL* obj) { return (NurbsGL*)ObjectListGL::remove(obj) ; }
01006 
01007   void glObject() const ; 
01008   void display() const ;
01009 
01010   void resetDisplayFlags(int o, int cp, int p, int b, int k, int behavior=NURBS_FLAGS_AFFECT_ALL) ;
01011 };
01012 
01013 
01014 void initColorsGL() ;
01015 
01026 class SimpleNurbsCurveGL : public NurbsGL, public NurbsCurvef {
01027 protected:
01028   SimpleNurbsCurveGL() : NurbsCurvef(),NurbsGL() { type = curveObject ;  polygon = 0 ;}
01029 
01030 public:
01031 
01032   void gluNurbs() const;
01033   void glObject() const { gluNurbs() ; }
01034 
01035   void point(float &u, float &v, int pSize, const Color& colorP, int cp_flag=0) const {}
01036   void resetBoundingBox() {}
01037   void resetCPoints() {}
01038   void resetPolygon() {}
01039   void resetKnots() {}
01040 
01041   void modifyPoint(float u, float v, float dx, float dy, float dz) { }
01042   void setSym(int set, int uDir, float x, float y, float z, float w) { }
01043 
01044   friend class NurbsCurveGL ; 
01045   friend class NurbsSurfaceGL ; 
01046   friend class HNurbsSurfaceGL ; 
01047 
01048 };
01049 
01050 } // end namespace
01051 
01052 typedef PLib::NurbsCurveGL PlNurbsCurveGL ; 
01053 typedef PLib::NurbsSurfaceGL PlNurbsSurfaceGL ; 
01054 typedef PLib::HNurbsSurfaceGL PlHNurbsSurfaceGL ; 
01055 typedef PLib::ObjectGL PlObjectGL ; 
01056 typedef PLib::NurbsListGL PlNurbsListGL ; 
01057 typedef PLib::ObjectRefGL PlObjectRefGL  ;
01058 typedef PLib::ObjectListGL PlObjectListGL  ;
01059 typedef PLib::ObjectRefListGL PlObjectRefListGL  ;
01060 typedef PLib::PointListGL PlPointListGL  ;
01061 typedef PLib::CPointGL PlCPointGL  ;
01062 typedef PLib::HCPointGL PlHCPointGL  ;
01063 typedef PLib::SPointGL PlSPointGL  ;
01064 typedef PLib::SPointCurveGL PlSPointCurveGL  ;
01065 typedef PLib::SPointSurfaceGL PlSPointSurfaceGL  ;
01066 typedef PLib::SPointHSurfaceGL PlSPointHSurfaceGL  ;
01067 typedef PLib::PointGL PlPointGL  ;
01068 typedef PLib::KnotGL PlKnotGL  ;
01069 typedef PLib::NurbsCpolygonGL PlNurbsCpolygonGL  ;
01070 typedef PLib::NurbsSpolygonGL PlNurbsSpolygonGL  ;
01071 typedef PLib::BoundingBoxGL PlBoundingBoxGL  ;
01072 typedef PLib::NurbsGL PlNurbsGL  ;
01073 typedef PLib::SimpleNurbsCurveGL PlSimpleNurbsCurveGL  ;
01074 
01075 #endif // WITH_OPENGL
01076 
01077 #endif

Generated on Tue Jun 24 13:26:57 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002