Salome HOME
Updated copyright comment
[modules/gui.git] / src / GLViewer / GLViewer_Tools.h
1 // Copyright (C) 2007-2024  CEA, EDF, 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, or (at your option) any later version.
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
23 //  Author : OPEN CASCADE
24 // File:      GLViewer_Tools.h
25 // Created:   April, 2005
26 //
27 #ifndef GLVIEWER_TOOLS_H
28 #define GLVIEWER_TOOLS_H
29
30 #ifdef WIN32
31 #include "windows.h"
32 #endif
33
34 #include "GLViewer.h"
35
36 /*!
37   \class GLViewer_Tools 
38   Tools for Viewer
39 */
40 class GLVIEWER_API GLViewer_Tools
41 {
42 public:
43         //GLViewer_Tools();
44         //virtual ~GLViewer_Tools();
45   //static 
46
47 };
48
49 //! Dimension of line
50 enum FieldDim
51 {
52   FD_X = 0, /*along x axis*/
53   FD_Y      /*along y axis*/
54 };
55
56 /*!
57   \class GLViewer_LineList 
58   Tools for distinct line
59   This class implmented interface for segment operations:
60   add, cut, remove and etc.
61   Memory does not changed and allocated only one time
62 */
63 class GLViewer_LineList  
64 {
65 public:
66   GLViewer_LineList( int  );
67   virtual ~GLViewer_LineList();
68
69   //! Returns number of segments
70   int         count() const { return mySegmentNumber; }
71   //! Returns real size
72   int         size() const { return myRealSize; }
73   
74   bool        addSegment( double coord1, double coord2 );
75   bool        removeSegment( int index );
76   bool        removeSegment( double coord1, double coord2 );
77
78   bool        readSegment( int index, double& coord1, double& coord2 );
79
80   //! Returns index of segment, else -1
81   int         contains( double thePoint ) const;
82
83   //! Sets level of segments
84   void        setMainCoord( double theVal ) { myMainCoord = theVal; }
85   double      mainCoord() const { return myMainCoord; }
86
87   void        clear();
88   void        print();
89
90   void        show( FieldDim );
91   
92   GLViewer_LineList& operator = ( GLViewer_LineList );
93
94 private:
95   double*     myArray;
96   int         myRealSize;
97   int         mySegmentNumber;
98
99   double      myMainCoord;
100 };
101
102 /*! struct GraphNode describe node in algorithm on rare grid*/
103 struct GraphNode
104 {
105   int       myCount;
106   FieldDim  myDim;
107   int       myLineIndex;
108   int       mySegmentindex;
109   int       prevNodeIndex; //feedback for searching for solution
110 };
111
112 /*! struct SearchPoint describe node for solving algorithm*/
113 struct SearchPoint
114 {
115   int       myXLineIndex;
116   int       myXSegmentIndex;
117   int       myYLineIndex;
118   int       myYSegmentIndex;
119   int       mySolveIndex;
120 };
121
122 /*! 
123   \class  GLViewer_LineField 
124   Tools for solving algorithm of finding shortest path on rare grid with minimum of 
125   line turns number
126 */
127 class GLViewer_LineField
128 {
129 public:
130   //!Searched point
131   enum  FieldPoint
132   {
133     FP_Start = 0,
134     FP_End = 1
135   };
136
137   //! Status of interation
138   enum IterationStatus
139   {
140     IS_ERROR = 0,
141     IS_LOOP,
142     IS_NOT_SOLVED,
143     IS_SOLVED
144   };
145
146   //! Final status of solving
147   enum EndStatus
148   {
149     ES_ERROR = 0,
150     ES_LOOP,
151     ES_SOLVED
152   };
153
154   GLViewer_LineField();
155   GLViewer_LineField( const int theMAXSize, const int xn, const int yn );
156   virtual ~GLViewer_LineField();
157
158   //! Adds new line
159   /*!best way, if line is already sorted*/
160   void                addLine( FieldDim, GLViewer_LineList* );
161   //! Calls previous
162   void                addLine( FieldDim theDim, double theMC, double theBegin, double theEnd );
163   
164   //! Adds new line and sorted field
165   /*! Returns position*/
166   int                 insertLine( FieldDim theDim, GLViewer_LineList*, int thePosition );
167   //! Calls previous
168   int                 insertLine( FieldDim theDim, double theMC, double theBegin, double theEnd, int thePosition );
169
170   //! Returns other dimension
171   static FieldDim     invertDim( FieldDim );
172
173   //! Returns line by index and dimension
174   GLViewer_LineList*  getLine( int index, FieldDim );
175
176   //! Nullifys field and sets same continued segments
177   void                setBorders( double X1, double X2, double Y1, double Y2 );
178   //! Cut rectangle in grid
179   void                addRectangle( double top, double right, double bottom, double left );
180
181   //! returns arrey of intersects indexes with \param theLL
182   int*                intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL , int& theSize );
183
184   void                print();
185
186   void                show();  
187
188   int                 getDimSize( FieldDim );
189   //! Returns number of segment
190   int                 segmentNumber();
191
192   //! Sets start/end search point
193   bool                setPoint( FieldPoint, double x, double y );
194
195   //! Optimize field
196   /*! Removes all multiple segments*/
197   void                optimize();
198   //! Some prepare actions
199   /*! Needs call setPoint before*/
200   void                initialize();
201   //! Main method
202   EndStatus           startAlgorithm();
203
204   //! Returns solution and size of solution
205   double*             solution( int& size );
206
207 protected:
208   //! One iteration of algorithm
209   void                iteration();
210   //! Checks for complete status
211   IterationStatus     checkComplete();  
212
213   //! Finds LineList by counts and returns indexes
214   int*                findByCount( int& theParam );
215   //! Finds LineList by segment and dimension
216   int                 findBySegment( FieldDim, int coord1, int coord2, bool inCurArray = true );
217
218   //! Returns current solution array
219   GraphNode*          getCurArray();
220   //! Returns 
221   GraphNode*          getSecArray();
222
223   //! Returns maximum segment number
224   int                 maxSegmentNum();
225
226   //! Returns list of LileList by dimension
227   GLViewer_LineList** getLLArray( FieldDim );
228
229 private:
230   GLViewer_LineList**    myXLineArray,
231                    **    myYLineArray;
232
233   int           myXSize,
234                 myYSize;
235
236   GraphNode*    myGraphArray1,
237            *    myGraphArray2;
238   int           myCurArrayIndex;
239
240   SearchPoint   myStartPoint,
241                 myEndPoint;
242   int           myCurCount;
243 };
244
245 #endif //GLVIEWER_TOOLS_H