]> SALOME platform Git repositories - modules/gui.git/blob - src/GLViewer/GLViewer_Tools.h
Salome HOME
222c27052640bc72b437746ee4c3b265b1401bc7
[modules/gui.git] / src / GLViewer / GLViewer_Tools.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  Author : OPEN CASCADE
23 // File:      GLViewer_Tools.h
24 // Created:   April, 2005
25 //
26 #ifndef GLVIEWER_TOOLS_H
27 #define GLVIEWER_TOOLS_H
28
29 #ifdef WIN32
30 #include "windows.h"
31 #endif
32
33 #include "GLViewer.h"
34
35 /*!
36   \class GLViewer_Tools 
37   Tools for Viewer
38 */
39 class GLVIEWER_API GLViewer_Tools
40 {
41 public:
42         //GLViewer_Tools();
43         //virtual ~GLViewer_Tools();
44   //static 
45
46 };
47
48 //! Dimension of line
49 enum FieldDim
50 {
51   FD_X = 0, /*along x axis*/
52   FD_Y      /*along y axis*/
53 };
54
55 /*!
56   \class GLViewer_LineList 
57   Tools for distinct line
58   This class implmented interface for segment operations:
59   add, cut, remove and etc.
60   Memory does not changed and allocated only one time
61 */
62 class GLViewer_LineList  
63 {
64 public:
65   GLViewer_LineList( int  );
66   virtual ~GLViewer_LineList();
67
68   //! Returns number of segments
69   int         count() const { return mySegmentNumber; }
70   //! Returns real size
71   int         size() const { return myRealSize; }
72   
73   bool        addSegment( double coord1, double coord2 );
74   bool        removeSegment( int index );
75   bool        removeSegment( double coord1, double coord2 );
76
77   bool        readSegment( int index, double& coord1, double& coord2 );
78
79   //! Returns index of segment, else -1
80   int         contains( double thePoint ) const;
81
82   //! Sets level of segments
83   void        setMainCoord( double theVal ) { myMainCoord = theVal; }
84   double      mainCoord() const { return myMainCoord; }
85
86   void        clear();
87   void        print();
88
89   void        show( FieldDim );
90   
91   GLViewer_LineList& operator = ( GLViewer_LineList );
92
93 private:
94   double*     myArray;
95   int         myRealSize;
96   int         mySegmentNumber;
97
98   double      myMainCoord;
99 };
100
101 /*! struct GraphNode describe node in algorithm on rare grid*/
102 struct GraphNode
103 {
104   int       myCount;
105   FieldDim  myDim;
106   int       myLineIndex;
107   int       mySegmentindex;
108   int       prevNodeIndex; //feedback for searching for solution
109 };
110
111 /*! struct SearchPoint describe node for solving algorithm*/
112 struct SearchPoint
113 {
114   int       myXLineIndex;
115   int       myXSegmentIndex;
116   int       myYLineIndex;
117   int       myYSegmentIndex;
118   int       mySolveIndex;
119 };
120
121 /*! 
122   \class  GLViewer_LineField 
123   Tools for solving algorithm of finding shortest path on rare grid with minimum of 
124   line turns number
125 */
126 class GLViewer_LineField
127 {
128 public:
129   //!Searched point
130   enum  FieldPoint
131   {
132     FP_Start = 0,
133     FP_End = 1
134   };
135
136   //! Status of interation
137   enum IterationStatus
138   {
139     IS_ERROR = 0,
140     IS_LOOP,
141     IS_NOT_SOLVED,
142     IS_SOLVED
143   };
144
145   //! Final status of solving
146   enum EndStatus
147   {
148     ES_ERROR = 0,
149     ES_LOOP,
150     ES_SOLVED
151   };
152
153   GLViewer_LineField();
154   GLViewer_LineField( const int theMAXSize, const int xn, const int yn );
155   virtual ~GLViewer_LineField();
156
157   //! Adds new line
158   /*!best way, if line is already sorted*/
159   void                addLine( FieldDim, GLViewer_LineList* );
160   //! Calls previous
161   void                addLine( FieldDim theDim, double theMC, double theBegin, double theEnd );
162   
163   //! Adds new line and sorted field
164   /*! Returns position*/
165   int                 insertLine( FieldDim theDim, GLViewer_LineList*, int thePosition );
166   //! Calls previous
167   int                 insertLine( FieldDim theDim, double theMC, double theBegin, double theEnd, int thePosition );
168
169   //! Returns other dimension
170   static FieldDim     invertDim( FieldDim );
171
172   //! Returns line by index and dimension
173   GLViewer_LineList*  getLine( int index, FieldDim );
174
175   //! Nullifys field and sets same continued segments
176   void                setBorders( double X1, double X2, double Y1, double Y2 );
177   //! Cut rectangle in grid
178   void                addRectangle( double top, double right, double bottom, double left );
179
180   //! returns arrey of intersects indexes with \param theLL
181   int*                intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL , int& theSize );
182
183   void                print();
184
185   void                show();  
186
187   int                 getDimSize( FieldDim );
188   //! Returns number of segment
189   int                 segmentNumber();
190
191   //! Sets start/end search point
192   bool                setPoint( FieldPoint, double x, double y );
193
194   //! Optimize field
195   /*! Removes all multiple segments*/
196   void                optimize();
197   //! Some prepare actions
198   /*! Needs call setPoint before*/
199   void                initialize();
200   //! Main method
201   EndStatus           startAlgorithm();
202
203   //! Returns solution and size of solution
204   double*             solution( int& size );
205
206 protected:
207   //! One iteration of algorithm
208   void                iteration();
209   //! Checks for complete status
210   IterationStatus     checkComplete();  
211
212   //! Finds LineList by counts and returns indexes
213   int*                findByCount( int& theParam );
214   //! Finds LineList by segment and dimension
215   int                 findBySegment( FieldDim, int coord1, int coord2, bool inCurArray = true );
216
217   //! Returns current solution array
218   GraphNode*          getCurArray();
219   //! Returns 
220   GraphNode*          getSecArray();
221
222   //! Returns maximum segment number
223   int                 maxSegmentNum();
224
225   //! Returns list of LileList by dimension
226   GLViewer_LineList** getLLArray( FieldDim );
227
228 private:
229   GLViewer_LineList**    myXLineArray,
230                    **    myYLineArray;
231
232   int           myXSize,
233                 myYSize;
234
235   GraphNode*    myGraphArray1,
236            *    myGraphArray2;
237   int           myCurArrayIndex;
238
239   SearchPoint   myStartPoint,
240                 myEndPoint;
241   int           myCurCount;
242 };
243
244 #endif //GLVIEWER_TOOLS_H