BaryPatch.h

00001 #ifndef BARYPATCH_H
00002 #define BARYPATCH_H
00003 /*
00004  ____                   _____      _       _     
00005 |  _ \                 |  __ \    | |     | |    
00006 | |_) | __ _ _ __ _   _| |__) |_ _| |_ ___| |__  
00007 |  _ < / _` | '__| | | |  ___/ _` | __/ __| '_ \ 
00008 | |_) | (_| | |  | |_| | |  | (_| | || (__| | | |
00009 |____/ \__,_|_|   \__, |_|   \__,_|\__\___|_| |_|
00010                    __/ |                         
00011                   |___/  
00012 */
00013 #include "SelectableThing.h"
00014 #include "matrices.h"
00015 #include "TDPoint.h"
00016 
00017 using namespace std;
00018 using namespace qglviewer;
00020 class BaryPatch : public SelectableThing
00021 {
00027 public :
00029         int _DimU;
00031         int _DimV;
00033         int _DimW;
00035         int _UCnx1;
00037         int _UCnx2;
00039         int _VCnx1;
00041         int _VCnx2;
00043         int _WCnx1;
00045         int _WCnx2;
00046 
00054         SSMatrix* _TransfoMatrice;
00056         int*** _RefPointsIndiceTable;
00058         Vec *** _MatrixPoints;
00060         TDPoint** _LevelPointsTable;
00062         bool IsAPoint(){return false;};
00064         bool IsAPatch(){return true;};
00066         TDPoint* GetPoint(){return NULL;};
00068         BaryPatch* GetPatch(){return this;};
00070         BaryPatch(int ThingName, SelectableThing** Workspace, int DimU, int DimV, int DimW, int UCnx1,int UCnx2, int VCnx1,int VCnx2, int WCnx1,int WCnx2, SSMatrix* TransfoMatrice,  int*** RefPointsI, TDPoint** LevelPointsTable): SelectableThing(ThingName,Workspace)
00071         {
00072                 _DimU=DimU;
00073                 _DimV=DimV;
00074                 _DimW=DimW;
00075                 _UCnx1=UCnx1;
00076                 _UCnx2=UCnx2;
00077                 _VCnx1=VCnx1;
00078                 _VCnx2=VCnx2;
00079                 _WCnx1=WCnx1;
00080                 _WCnx2=WCnx2;
00081                 _TransfoMatrice=TransfoMatrice;
00082                 _RefPointsIndiceTable=RefPointsI;
00083                 _LevelPointsTable=LevelPointsTable;
00084                 _MatrixPoints = new Vec** [_DimU];
00085                 for(int u=0;u<_DimU;u++)
00086                 {
00087                         _MatrixPoints[u] = new Vec*[_DimV];
00088                         for(int v=0;v<_DimV;v++)
00089                         {
00090                                 _MatrixPoints[u][v] = new Vec[_DimW];
00091                                 for(int w=0;w<_DimW;w++)
00092                                 {
00093                                         _MatrixPoints[u][v][w]=_LevelPointsTable[_RefPointsIndiceTable[u][v][w]]->_ThingGlobalFrame.position();
00094                                 }
00095                         }
00096                 }
00097         };
00099         ~BaryPatch()
00100         {
00101                 _RefPointsIndiceTable;
00102                 for(int u=0;u<_DimU;u++)
00103                 {
00104                         for(int v=0;v<_DimV;v++)
00105                         {
00106                                 delete[] _RefPointsIndiceTable[u][v];
00107                                 delete[] _MatrixPoints[u][v];
00108                         }
00109                         delete[] _RefPointsIndiceTable[u];
00110                         delete[] _MatrixPoints[u];
00111                 }
00112                 delete[] _RefPointsIndiceTable;
00113                 delete[] _MatrixPoints;
00114                 _DimU=0;
00115                 _DimV=0;
00116                 _DimW=0;
00117                 _UCnx1=0;
00118                 _UCnx2=0;
00119                 _VCnx1=0;
00120                 _VCnx2=0;
00121                 _WCnx1=0;
00122                 _WCnx2=0;
00123                 delete _TransfoMatrice;
00124 
00125         }
00127         void draw(ManipulatedFrame* MF)
00128         {
00129                 int u,v,w;
00130                 
00131                 if(_IsSelected)
00132                 {
00133                         glColor3f(_Color[0], _Color[1], _Color[2]);
00134                 }
00135                 else 
00136                 {
00137                         glColor3f(_Color[0]/2., _Color[1]/2., _Color[2]/2.);
00138                 }
00139                 bool uuUnsilentDim= ((_UCnx2-_UCnx1)>=1);
00140                 bool vvUnsilentDim= ((_VCnx2-_VCnx1)>=1);
00141                 bool wwUnsilentDim= ((_WCnx2-_WCnx1)>=1);
00142                 int NbUnSilentDims = (uuUnsilentDim)?((vvUnsilentDim)?((wwUnsilentDim)?(3):(2)):((wwUnsilentDim)?(2):(1))):((vvUnsilentDim)?((wwUnsilentDim)?(2):(1)):((wwUnsilentDim)?(1):(0)));
00143 
00144                 glPushName(_ThingName+TABLESIZE);
00145 
00146                 switch(NbUnSilentDims)
00147                 {
00148                 case 3: // UVW Cubes
00149                         for(u=_UCnx1;u<_UCnx2;u++)
00150                         {
00151                                 for(v=_VCnx1;v<_VCnx2;v++)
00152                                 {
00153                                         for(w=_WCnx1;w<_WCnx2;w++)
00154                                         {
00155                                                 drawQuad(_MatrixPoints[u][v][w],_MatrixPoints[u][v][w+1],_MatrixPoints[u][v+1][w+1],_MatrixPoints[u][v+1][w]);
00156                                                 drawQuad(_MatrixPoints[u][v][w+1],_MatrixPoints[u+1][v][w+1],_MatrixPoints[u+1][v+1][w+1],_MatrixPoints[u][v+1][w+1]);
00157                                                 drawQuad(_MatrixPoints[u+1][v][w+1],_MatrixPoints[u+1][v][w],_MatrixPoints[u+1][v+1][w],_MatrixPoints[u+1][v+1][w+1]);
00158                                                 drawQuad(_MatrixPoints[u+1][v][w],_MatrixPoints[u][v][w],_MatrixPoints[u][v+1][w],_MatrixPoints[u+1][v+1][w]);
00159                                                 drawQuad(_MatrixPoints[u][v+1][w],_MatrixPoints[u][v+1][w+1],_MatrixPoints[u+1][v+1][w+1],_MatrixPoints[u+1][v+1][w]);
00160                                                 drawQuad(_MatrixPoints[u+1][v][w],_MatrixPoints[u+1][v][w+1],_MatrixPoints[u][v][w+1],_MatrixPoints[u][v][w]);
00161                                         }
00162                                 }
00163                         }
00164                         break;
00165                 case 2:
00166                         if (!uuUnsilentDim) // VW surface
00167                         {
00168                                 u=_UCnx1;
00169                                 for(v=_VCnx1;v<_VCnx2;v++)
00170                                 {
00171                                         for(w=_WCnx1;w<_WCnx2;w++)
00172                                         {
00173                                                 drawQuad(_MatrixPoints[u][v][w],_MatrixPoints[u][v+1][w],_MatrixPoints[u][v+1][w+1],_MatrixPoints[u][v][w+1]);
00174                                         }
00175                                 }
00176                         }
00177                         else if (!vvUnsilentDim) // UW surface
00178                         {
00179                                 v=_VCnx1;
00180                                 for(u=_UCnx1;u<_UCnx2;u++)
00181                                 {
00182                                         for(w=_WCnx1;w<_WCnx2;w++)
00183                                         {
00184                                                 drawQuad(_MatrixPoints[u][v][w],_MatrixPoints[u+1][v][w],_MatrixPoints[u+1][v][w+1],_MatrixPoints[u][v][w+1]);
00185                                         }
00186                                 }
00187                         }
00188                         else if (!wwUnsilentDim) // UV surface
00189                         {
00190                                 w=_WCnx1;
00191                                 for(u=_UCnx1;u<_UCnx2;u++)
00192                                 {
00193                                         for(v=_VCnx1;v<_VCnx2;v++)
00194                                         {
00195                                                 drawQuad(_MatrixPoints[u][v][w],_MatrixPoints[u+1][v][w],_MatrixPoints[u+1][v+1][w],_MatrixPoints[u][v+1][w]);
00196                                         }
00197                                 }
00198                         }
00199                                 
00200                 case 1:
00201                         glDisable(GL_LIGHTING);
00202                         if (uuUnsilentDim)
00203                         {
00204                                 v=_VCnx1;
00205                                 w=_WCnx1;
00206                                 for(u=_UCnx1;u<_UCnx2;u++)
00207                                 {
00208                                         glBegin(GL_LINES);
00209                                         glVertex3f(_MatrixPoints[u][v][w].x,_MatrixPoints[u][v][w].y,_MatrixPoints[u][v][w].z);
00210                                         glVertex3f(_MatrixPoints[u+1][v][w].x,_MatrixPoints[u+1][v][w].y,_MatrixPoints[u+1][v][w].z);
00211                                         glEnd();
00212                                 }
00213                         }
00214                         else if (vvUnsilentDim)
00215                         {
00216                                 u=_UCnx1;
00217                                 w=_WCnx1;
00218                                 for(v=_VCnx1;v<_VCnx2;v++)
00219                                 {
00220                                         glBegin(GL_LINE);
00221                                         glVertex3f(_MatrixPoints[u][v][w].x,_MatrixPoints[u][v][w].y,_MatrixPoints[u][v][w].z);
00222                                         glVertex3f(_MatrixPoints[u][v+1][w].x,_MatrixPoints[u][v+1][w].y,_MatrixPoints[u][v+1][w].z);
00223                                         glEnd();
00224                                 }
00225                         }
00226                         else if (wwUnsilentDim)
00227                         {
00228                                 u=_UCnx1;
00229                                 v=_VCnx1;
00230                                 for(w=_WCnx1;w<_WCnx2;w++)
00231                                 {
00232                                         glBegin(GL_LINE);
00233                                         glVertex3f(_MatrixPoints[u][v][w].x,_MatrixPoints[u][v][w].y,_MatrixPoints[u][v][w].z);
00234                                         glVertex3f(_MatrixPoints[u][v][w+1].x,_MatrixPoints[u][v][w+1].y,_MatrixPoints[u][v][w+1].z);
00235                                         glEnd();
00236                                 }
00237                         }
00238                         glEnable(GL_LIGHTING);
00239                         break;
00240                 }
00241                 glPopName();
00242         };
00244         int UUnSilentDim()
00245         {
00246                 if((_UCnx2-_UCnx1)<1)
00247                         return 0;
00248                 else return 1;
00249         }
00251         int VUnSilentDim()
00252         {
00253                 if((_VCnx2-_VCnx1)<1)
00254                         return 0;
00255                 else return 1;
00256         }
00258         int WUnSilentDim()
00259         {
00260                 if((_WCnx2-_WCnx1)<1)
00261                         return 0;
00262                 else return 1;
00263         }
00265         int WhatsMyNumber()
00266         {
00267                 int CountWorkspacePoints = 0;
00268                 for(int i=0;i<_ThingName;i++)
00269                 {
00270                         if ((_Workspace[i])&&(_Workspace[i]->IsAPatch()))
00271                                 CountWorkspacePoints++;
00272                 }
00273                 return CountWorkspacePoints;
00274         };
00276         void UpdateNameTag()
00277         {
00278                 _NameTag = "Patch " + QString::number(WhatsMyNumber());
00279         };
00281         void drawQuad(Vec P1, Vec P2, Vec P3, Vec P4)
00282         {
00283                 Vec V12=P2-P1;
00284                 Vec V23=P3-P2;
00285                 Vec V34=P4-P3;
00286                 Vec V41=P1-P4;
00287                 Vec N1=cross(-V12,V41);
00288                 N1.normalize();
00289                 Vec N2=cross(-V23,V12);
00290                 N2.normalize();
00291                 Vec N3=cross(-V34,V23);
00292                 N3.normalize();
00293                 Vec N4=cross(-V41,V34);
00294                 N4.normalize();
00295                 glBegin(GL_QUADS);
00296                 glNormal3f(N1[0],N1[1],N1[2]);
00297                 glVertex3f(P1[0],P1[1],P1[2]);
00298                 glNormal3f(N2[0],N2[1],N2[2]);
00299                 glVertex3f(P2[0],P2[1],P2[2]);
00300                 glNormal3f(N3[0],N3[1],N3[2]);
00301                 glVertex3f(P3[0],P3[1],P3[2]);
00302                 glNormal3f(N4[0],N4[1],N4[2]);
00303                 glVertex3f(P4[0],P4[1],P4[2]);
00304                 glEnd();
00305         };
00307         void SelectAll()
00308         {
00309                 for(int u=0;u<_DimU;u++)
00310                 {
00311                         for(int v=0;v<_DimV;v++)
00312                         {
00313                                 for(int w=0;w<_DimW;w++)
00314                                 {
00315                                         _LevelPointsTable[_RefPointsIndiceTable[u][v][w]]->_IsSelected=true;
00316                                 }
00317                         }
00318                 }
00319         }
00320 
00326         void UpdateMatrixPoints()
00327         {
00328                 int C,L;
00329                 for(int u=0;u<_DimU;u++)
00330                 {
00331                         for(int v=0;v<_DimV;v++)
00332                         {
00333                                 for(int w=0;w<_DimW;w++)
00334                                 {
00335                                         _MatrixPoints[u][v][w]=Vec(0.,0.,0.);
00336                                         // this point is related to the matrix column U+V*DimU+W*DimU*DimV
00337                                         C=u+v*_DimU+w*_DimU*_DimV;
00338                                         for(int uu=0;uu<_DimU;uu++)
00339                                         {
00340                                                 for(int vv=0;vv<_DimV;vv++)
00341                                                 {
00342                                                         for(int ww=0;ww<_DimW;ww++)
00343                                                         {
00344                                                                 L=uu+vv*_DimU+ww*_DimU*_DimV;
00345                                                                 _MatrixPoints[u][v][w]+=(_TransfoMatrice->_Values[L][C]*_LevelPointsTable[_RefPointsIndiceTable[uu][vv][ww]]->_ThingGlobalFrame.position());
00346                                                         }
00347                                                 }
00348                                         }                       
00349                                 }
00350                         }
00351                 }
00352         }
00353         
00354 };
00355 #endif

Generated on Thu Sep 28 09:43:42 2006 by  doxygen 1.4.7