Back to index

salome-gui  6.5.0
GLViewer_Tools.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  Author : OPEN CASCADE
00024 // File:      GLViewer_Tools.h
00025 // Created:   April, 2005
00026 //
00027 #ifndef GLVIEWER_TOOLS_H
00028 #define GLVIEWER_TOOLS_H
00029 
00030 #ifdef WIN32
00031 #include "windows.h"
00032 #endif
00033 
00034 #include "GLViewer.h"
00035 
00040 class GLVIEWER_API GLViewer_Tools
00041 {
00042 public:
00043         //GLViewer_Tools();
00044         //virtual ~GLViewer_Tools();
00045   //static 
00046 
00047 };
00048 
00050 enum FieldDim
00051 {
00052   FD_X = 0, /*along x axis*/
00053   FD_Y      /*along y axis*/
00054 };
00055 
00063 class GLViewer_LineList  
00064 {
00065 public:
00066   GLViewer_LineList( int  );
00067   virtual ~GLViewer_LineList();
00068 
00070   int         count() const { return mySegmentNumber; }
00072   int         size() const { return myRealSize; }
00073   
00074   bool        addSegment( double coord1, double coord2 );
00075   bool        removeSegment( int index );
00076   bool        removeSegment( double coord1, double coord2 );
00077 
00078   bool        readSegment( int index, double& coord1, double& coord2 );
00079 
00081   int         contains( double thePoint ) const;
00082 
00084   void        setMainCoord( double theVal ) { myMainCoord = theVal; }
00085   double      mainCoord() const { return myMainCoord; }
00086 
00087   void        clear();
00088   void        print();
00089 
00090   void        show( FieldDim );
00091   
00092   GLViewer_LineList& operator = ( GLViewer_LineList );
00093 
00094 private:
00095   double*     myArray;
00096   int         myRealSize;
00097   int         mySegmentNumber;
00098 
00099   double      myMainCoord;
00100 };
00101 
00103 struct GraphNode
00104 {
00105   int       myCount;
00106   FieldDim  myDim;
00107   int       myLineIndex;
00108   int       mySegmentindex;
00109   int       prevNodeIndex; //feedback for searching for solution
00110 };
00111 
00113 struct SearchPoint
00114 {
00115   int       myXLineIndex;
00116   int       myXSegmentIndex;
00117   int       myYLineIndex;
00118   int       myYSegmentIndex;
00119   int       mySolveIndex;
00120 };
00121 
00127 class GLViewer_LineField
00128 {
00129 public:
00131   enum  FieldPoint
00132   {
00133     FP_Start = 0,
00134     FP_End = 1
00135   };
00136 
00138   enum IterationStatus
00139   {
00140     IS_ERROR = 0,
00141     IS_LOOP,
00142     IS_NOT_SOLVED,
00143     IS_SOLVED
00144   };
00145 
00147   enum EndStatus
00148   {
00149     ES_ERROR = 0,
00150     ES_LOOP,
00151     ES_SOLVED
00152   };
00153 
00154   GLViewer_LineField();
00155   GLViewer_LineField( const int theMAXSize, const int xn, const int yn );
00156   virtual ~GLViewer_LineField();
00157 
00159 
00160   void                addLine( FieldDim, GLViewer_LineList* );
00162   void                addLine( FieldDim theDim, double theMC, double theBegin, double theEnd );
00163   
00165 
00166   int                 insertLine( FieldDim theDim, GLViewer_LineList*, int thePosition );
00168   int                 insertLine( FieldDim theDim, double theMC, double theBegin, double theEnd, int thePosition );
00169 
00171   static FieldDim     invertDim( FieldDim );
00172 
00174   GLViewer_LineList*  getLine( int index, FieldDim );
00175 
00177   void                setBorders( double X1, double X2, double Y1, double Y2 );
00179   void                addRectangle( double top, double right, double bottom, double left );
00180 
00182   int*                intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL , int& theSize );
00183 
00184   void                print();
00185 
00186   void                show();  
00187 
00188   int                 getDimSize( FieldDim );
00190   int                 segmentNumber();
00191 
00193   bool                setPoint( FieldPoint, double x, double y );
00194 
00196 
00197   void                optimize();
00199 
00200   void                initialize();
00202   EndStatus           startAlgorithm();
00203 
00205   double*             solution( int& size );
00206 
00207 protected:
00209   void                iteration();
00211   IterationStatus     checkComplete();  
00212 
00214   int*                findByCount( int& theParam );
00216   int                 findBySegment( FieldDim, int coord1, int coord2, bool inCurArray = true );
00217 
00219   GraphNode*          getCurArray();
00221   GraphNode*          getSecArray();
00222 
00224   int                 maxSegmentNum();
00225 
00227   GLViewer_LineList** getLLArray( FieldDim );
00228 
00229 private:
00230   GLViewer_LineList**    myXLineArray,
00231                    **    myYLineArray;
00232 
00233   int           myXSize,
00234                 myYSize;
00235 
00236   GraphNode*    myGraphArray1,
00237            *    myGraphArray2;
00238   int           myCurArrayIndex;
00239 
00240   SearchPoint   myStartPoint,
00241                 myEndPoint;
00242   int           myCurCount;
00243 };
00244 
00245 #endif //GLVIEWER_TOOLS_H