BaryPatch.h

00001 #ifndef BARYPATCH_H
00002 #define BARYPATCH_H
00003 #include "SelectableThing.h"
00004 #include "matrices.h"
00005 #include "Point.h"
00006 #include "SubdivScheme.h"
00007 #include <stack>
00008 
00009 /*
00010  ____                    _____                    _ 
00011 |  _ \                  / ____|                  | |
00012 | |_) | __ _ _ __ _   _| |     ___   ___  _ __ __| |
00013 |  _ < / _` | '__| | | | |    / _ \ / _ \| '__/ _` |
00014 | |_) | (_| | |  | |_| | |___| (_) | (_) | | | (_| |
00015 |____/ \__,_|_|   \__, |\_____\___/ \___/|_|  \__,_|
00016                    __/ |                            
00017                   |___/   
00018  ____                   _____      _       _     
00019 |  _ \                 |  __ \    | |     | |    
00020 | |_) | __ _ _ __ _   _| |__) |_ _| |_ ___| |__  
00021 |  _ < / _` | '__| | | |  ___/ _` | __/ __| '_ \ 
00022 | |_) | (_| | |  | |_| | |  | (_| | || (__| | | |
00023 |____/ \__,_|_|   \__, |_|   \__,_|\__\___|_| |_|
00024                    __/ |                         
00025                   |___/  
00026 */
00027 
00029 
00032 class BaryCoord 
00033 {
00034 public:
00036         int _Dim;
00038         float* _BaryCoordFloatTable;
00040         int* _LvlZeroPointsIndice;
00042         Point* _CreatedPoint;
00043 
00045         BaryCoord(int Dim,float * BaryCoordFloatTable,int * LvlZeroPointsIndices,Point* CreatedPoint)
00046         {
00047                 _Dim=Dim;
00048                 _BaryCoordFloatTable=BaryCoordFloatTable;
00049                 _LvlZeroPointsIndice=LvlZeroPointsIndices;
00050                 _CreatedPoint=CreatedPoint;
00051         };
00053         ~BaryCoord()
00054         {
00055                 _Dim = 0;
00056                 delete[] _BaryCoordFloatTable;
00057                 _CreatedPoint = NULL;
00058         };
00060         bool IsIdentical(BaryCoord &P2)
00061         {
00062                 // go through my non 0 coordinates
00063                 for (int i=0;i<_Dim;i++)
00064                 {
00065                         if(_BaryCoordFloatTable[i]!=0.0)
00066                         {
00067                                 // check for identical coordinate associated to same point in other point
00068                                 bool FoundSameCoord = false;
00069                                 for(int j=0;j<P2._Dim;j++)
00070                                 {
00071                                         if((P2._LvlZeroPointsIndice[j]==_LvlZeroPointsIndice[i])&&(P2._BaryCoordFloatTable[j]==_BaryCoordFloatTable[i]))
00072                                         {
00073                                                 FoundSameCoord=true;
00074                                                 break;
00075                                         }
00076                                 }
00077                                 if(!FoundSameCoord)
00078                                         return false;
00079                         }
00080                 }
00081                 // go through P2 non 0 coordinates
00082                 for (i=0;i<P2._Dim;i++)
00083                 {
00084                         if(P2._BaryCoordFloatTable[i]!=0.0)
00085                         {
00086                                 // check for identical coordinate associated to same point in other point
00087                                 bool FoundSameCoord = false;
00088                                 for(int j=0;j<_Dim;j++)
00089                                 {
00090                                         if((_LvlZeroPointsIndice[j]==P2._LvlZeroPointsIndice[i])&&(_BaryCoordFloatTable[j]==P2._BaryCoordFloatTable[i]))
00091                                         {
00092                                                 FoundSameCoord=true;
00093                                                 break;
00094                                         }
00095                                 }
00096                                 if(!FoundSameCoord)
00097                                         return false;
00098                         }
00099                 }
00100                 return true;
00101         };
00102 };
00104 class BaryPatch : public SelectableThing
00105 {
00110 public :
00113 
00117         int _DimU;
00119         int _DimV;
00121         int _DimW;
00123         int _UCnx1;
00125         int _UCnx2;
00127         int _VCnx1;
00129         int _VCnx2;
00131         int _WCnx1;
00133         int _WCnx2;
00134 
00142         SSMatrix _TransfoMatrix;
00144         int* _LvlZeroPointsIndices;
00146         Point** _LvlZeroPointsTable;
00147 
00152         int _Level;
00154         BaryPatch* _Parent;
00156         BaryPatch* _Root;
00158         int _NbChildren;
00160         BaryPatch** _Children;
00161 
00164         float _CoordPatch_U1;
00167         float _CoordPatch_U2;
00170         float _CoordPatch_V1;
00173         float _CoordPatch_V2;
00176         float _CoordPatch_W1;
00179         float _CoordPatch_W2;
00180         
00183         SSMatrix _ProjectedTransfoMatrix;
00184 
00189         Point** _Perturbations;
00190         
00193         SubdivScheme* _NextSubdiv;
00194         
00196         bool IsAPoint(){return false;};
00198         bool IsAPatch(){return true;};
00200         Point* GetPoint(){return NULL;};
00202         BaryPatch* GetPatch(){return this;};
00203 
00205         BaryPatch(int ThingName, int DimU,int DimV,int DimW,int UCnx1,int UCnx2,int VCnx1,int VCnx2,int WCnx1,int WCnx2,SSMatrix TransfoMat,int Level,int * LvlZeroPointsIndices, Point ** LvlZeroPointsTable,BaryPatch* Parent,BaryPatch* Root,SubdivScheme* NextSubdiv);
00207         BaryPatch(int ThingName, SSMatrix TransfoMat,BaryPatch* Parent);
00209         ~BaryPatch();
00211         void ClearChild(BaryPatch* Child);
00212 
00218         void UpdateProjectedTransfoMatrix();
00220         void ApplySchemeToLevelSelected(int Level,SubdivScheme* Scheme);
00222         void SubDivideLevel(int Level);
00224         void SubDivideLevelSelected(int Level);
00226         void RSubDivideLevel(int Level, int &NextName, bool IfSelected);
00228         void SubDivide(int &NextName);
00230         SSMatrix BuildCumulatedMatrix();
00234         void BuildPerturbations(int Level);
00236         void RBuildPerturbations(int Level, stack<BaryCoord*> &CreatedPoints);
00238         void DeletePerturbations(int Level);
00239 
00243         Point* FindPerturbation(int Level, int Name);
00245         int CountPerturbationOccurences(Point* Perturbation);
00247         void BuildLevelPerturbationTable(int Level, bool OnlyOnSelectedPatches, bool OnlySelectedPerturbations, int &NbPerturbFound, Point** &Table);
00249         void RBuildLevelPerturbationTable(int Level, bool OnlyOnSelectedPatches, bool OnlySelectedPerturbations,stack<Point*> &FoundStack);
00251         void BuildLevelPatchesTable(int Level, bool OnlyOnSelectedPatches, int &NbPatchesFound, BaryPatch** &Table);
00253         void RBuildLevelPatchesTable(int Level, bool OnlyOnSelectedPatches, stack<BaryPatch*> &FoundStack);
00255         void BuildLevelQuadTable(int Level, bool OnlyOnSelectedPatches, int &NbQuadsFound, Point*** &Table);
00257         void RBuildLevelQuadTable(int Level, bool OnlyOnSelectedPatches,stack<Point**> &FoundStack);
00259         bool DeletePerturbation(Point* Perturbation, bool& AlreadyDeleted);
00261         int GetSubTreeDepth();
00263         int GetLowestPatchName();
00265         int RGetLowestPatchName(int CurrentLowest);
00267         void FindNeighbour(stack<BaryPatch*> &Neighbours);
00269         void FindNeighbourFromPoints(Point** TabPnts,int NbPnts,int Level,int Name,stack<BaryPatch*> &Neighbours);
00271         void BuildEdges(stack<Point*> &EdgeTable);
00274         void BuildPerturbQuads(stack<Point**> &QuadTable);
00276         void SavePoints(int Level,stack<Point*> &SaveTable);
00278         void SavePatches(int Level,stack<BaryPatch*> &SaveTable);
00280         int WritePatch(FILE* file,int NbPntsLvlZero);
00282         int ReadPatch(FILE* file,int NbPntsLvlZero);
00283 
00285         BaryPatch* FindPatch(int Level,int Name);
00287         BaryPatch* FindPatchFromParameter(float CoordToFind_U,float CoordToFind_V,float CoordToFind_W);
00290         Vec* FindElementFromParameter(int& Dim,float CoordToFind_U,float CoordToFind_V,float CoordToFind_W,float& Limit_U1,float& Limit_U2,float& Limit_V1,float& Limit_V2,float& Limit_W1,float& Limit_W2);
00291         
00293         void SelectAll(int Level);
00295         void SelectAllSelected(int Level);
00297         void LevelUnSelectAllPerturbations(int Level);
00299         void LevelSelectAllPatches(int Level);
00301         void LevelUnSelectAllPatches(int Level);
00303         void LevelDeleteSelected(int Level);
00305         void LevelCutSubtreeSelected(int Level);
00307         Vec LevelSelectedCenterOfGravity(int Level);
00309         Vec RLevelSelectedCenterOfGravity(int Level, Vec &CurrentCenter, int &CurrentNbPoints, stack<Point*> &AlreadyCounted);
00311         void ChangedPerturbationSelection(int Level, ManipulatedFrame* MF);
00313         void RChangedPerturbationSelection(int Level, ManipulatedFrame* MF, stack<Point*> &AlreadyCounted);
00315         void ResetPerturbations();
00318         void ResetLevelPerturbations(int Level);
00320         void ResetSelectedPerturbations(int Level);
00322         void InversePatchSelection(int Level);
00323 
00325         void draw(int Level,ManipulatedFrame* MF);
00327         void draw(ManipulatedFrame* MF,bool Selectable=true);
00329         void draw(ManipulatedFrame* MF){draw(MF,false);};
00331         int drawToFile(int Level,FILE *file,int counting,int TypePrint);
00333         int drawFacesToFile(int Level,int counting);
00335 
00340         int inline UUnSilentDim(){return ((_UCnx2-_UCnx1)<1) ? 0 : 1;};
00342         int inline VUnSilentDim(){return ((_VCnx2-_VCnx1)<1) ? 0 : 1;};
00344         int inline WUnSilentDim(){return ((_WCnx2-_WCnx1)<1) ? 0 : 1;};
00346         int inline PointIndice(int u, int v, int w){return u+v*_DimU+w*_DimU*_DimV;};
00348         void inline UpdateNameTag(){_NameTag = "Patch " + QString::number(_ThingName);};
00349 
00351         void drawQuad(Vec P1, Vec P2, Vec P3, Vec P4);
00353         void fastDrawQuad(Vec P1, Vec P2, Vec P3, Vec P4);
00355 
00358 
00363         double _SavedMinPlanarity;
00365         double _SavedAvgPlanarity;
00367         double QuadPlanarity(Vec P1, Vec P2, Vec P3, Vec P4, bool DegMode);
00369         void SurfacePlanarityFactor(double& Worst, double& Average, bool DegMode);
00371         void UpdatePlanarities(int Level, bool DegMode);
00373         void UpdatePlanaritiesIfContains(int Level, int PerturbName,bool DegMode);
00374 
00377         void LevelWorstAndAveragePlanarity(int Level, bool OnlySelectedPatches, double& worst, double& average, double averageOffset, int& NbPatches, bool DegMode);
00380         void RLevelWorstAndAveragePlanarity(int Level, bool OnlySelectedPatches, double& worst, double& average, double averageOffset, int &NbPatches, bool DegMode);
00383         void SelectPatchesWorstPlanarityAbove(float bound, int Level, bool DegMode);
00386         float AveragePlanarityOfPatchesContainingPerturb(int Level, int PerturbName, int &NbPatchesFound, bool DegMode);
00389         void RAveragePlanarityOfPatchesContainingPerturb(int Level, int PerturbName, int &NbPatchesFound, float &AveragePlanarity, bool DegMode);
00392         void ViewAverageOrWorstPatchPlanarity(int Level, float Min, bool Average, bool DegMode);
00394         void ResetColor(int Level);
00396 };
00397 #endif

Generated on Thu Sep 28 09:38:08 2006 by  doxygen 1.4.7