1 // Copyright (C) 2007-2023 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Author : OPEN CASCADE
24 // File: GLViewer_Tools.cxx
25 // Created: April, 2005
27 #include "GLViewer_Tools.h"
30 #include <OpenGL/gl.h>
40 \param size - size of internal array
42 GLViewer_LineList::GLViewer_LineList( int size )
48 myArray = new double[myRealSize];
52 std::cout << "Can't allocate memory: " << size << std::endl;
56 memset( myArray, 0, myRealSize*sizeof(double) );
62 GLViewer_LineList::~GLViewer_LineList()
68 Adds new line segment to list
69 \param coord1, coord2 - co-ordinates of points
71 bool GLViewer_LineList::addSegment( double coord1, double coord2 )
80 if( 2*mySegmentNumber == myRealSize || !myArray )
85 while( index < mySegmentNumber)
87 readSegment( index, c1, c2 );
88 if( coord1 < c1 && coord2 < c1 )
90 for( int i = mySegmentNumber; i > index - 1; i--)
92 myArray[2*i] = myArray[2*i-2]; //2*(i-1)
93 myArray[2*i+1] = myArray[2*i-1];//2*(i-1)+1
97 // mySegmentNumber; what is means ?
100 else if( coord1 < c1 && coord2 < c2 )
102 myArray[index*2] = coord1;
105 else if( c1 < coord1 && coord2 < c2 )
109 else if( coord1 < c2 && c2 < coord2 )
112 myArray[2*index] = coord1;
114 if( index != mySegmentNumber - 1 )
116 for( int i = index+1; i < mySegmentNumber; i++ )
118 if( coord2 < myArray[2*i] )
120 myArray[2*index+1] = coord2;
123 for( int j = 0; i+j < mySegmentNumber;j++ )
125 myArray[2*(index+1+j)] = myArray[2*(i+j)];
126 myArray[2*(index+1+j)+1] = myArray[2*(i+j)+1];
128 for( int k = 0; k < mySegmentNumber - i; k++ )
130 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
131 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
133 mySegmentNumber -= i - index-1;
137 else if( coord2 < myArray[2*i+1] )
139 myArray[2*index+1] = myArray[2*i+1];
141 for( int j = index+1; j < mySegmentNumber-1;j++ )
143 myArray[2*j] = myArray[2*(i+j-index)];
144 myArray[2*j+1] = myArray[2*(i+j-index)+1];
146 for( int k = 0; k < mySegmentNumber - i-1; k++ )
148 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
149 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
151 mySegmentNumber -= i - index;
158 myArray[2*index+1] = coord2;
165 myArray[mySegmentNumber*2] = coord1;
166 myArray[mySegmentNumber*2+1] = coord2;
173 Gets info about segment
174 \param theIndex - index of segment
175 \param coord1, coord2 - co-ordinates of points
177 bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord2 )
179 if( theIndex > mySegmentNumber || !myArray)
182 coord1 = myArray[theIndex*2];
183 coord2 = myArray[theIndex*2+1];
189 \return true if line list covers point
190 \param thePoint - point co-ordinate
192 int GLViewer_LineList::contains( double thePoint ) const
194 if( !myArray || mySegmentNumber == 0 )
197 for( int i = 0; i < mySegmentNumber; i++ )
198 if( myArray[2*i] <= thePoint && thePoint <= myArray[2*i+1] )
207 \param theIndex - segment index
209 bool GLViewer_LineList::removeSegment( int theIndex )
211 if( theIndex > mySegmentNumber || !myArray)
214 for( int i = theIndex; i < mySegmentNumber; i++ )
216 myArray[i*2] = myArray[(i+1)*2];
217 myArray[i*2+1] = myArray[(i+1)*2+1];
220 myArray[mySegmentNumber*2] = 0.0;
221 myArray[mySegmentNumber*2+1] = 0.0;
226 Removes segment from line list
227 \param coord1, coord2 - co-ordinates of points
229 bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
231 if( coord1 > coord2 )
233 double temp = coord1;
238 if( 2*mySegmentNumber == myRealSize || !myArray )
243 while( index < mySegmentNumber)
245 readSegment( index, c1, c2 );
246 if( coord1 < c1 && coord2 < c1 )
251 else if( coord1 < c1 && coord2 < c2 )
253 myArray[index*2] = coord2;
256 else if( c1 < coord1 && coord2 < c2 )
258 if( 2*mySegmentNumber == myRealSize )
260 for( int i = mySegmentNumber; i > index + 1; i-- )
262 myArray[2*i] = myArray[2*(i-1)];
263 myArray[2*i+1] = myArray[2*(i-1)+1];
265 myArray[2*(index+1)+1] = myArray[2*index+1];
266 myArray[2*(index+1)] = coord2;
267 myArray[2*index+1] = coord1;
271 else if( coord1 < c2 && c2 < coord2 )
275 myArray[2*index+1] = coord1;
278 if( index != mySegmentNumber - 1 )
280 for( int i = index+1; i < mySegmentNumber; i++ )
282 if( coord2 < myArray[2*i] )
286 for( int j = 1; i+j-1 < mySegmentNumber;j++ )
288 myArray[2*(index+j)] = myArray[2*(i+j-1)];
289 myArray[2*(index+j)+1] = myArray[2*(i+j-1)+1];
291 for( int k = 0; k < mySegmentNumber - i; k++ )
293 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
294 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
296 mySegmentNumber -= i - index -1;
302 for( int j = 0; index + j + 1 < mySegmentNumber;j++ )
304 myArray[2*(index+j)] = myArray[2*(index+j+1)];
305 myArray[2*(index+j)+1] = myArray[2*(index+j+1)+1];
308 myArray[2*(mySegmentNumber - 1)] = 0.0;
309 myArray[2*(mySegmentNumber - 1)+1] = 0.0;
319 else if( coord2 < myArray[2*i+1] )
326 myArray[2*index] = coord2;
327 myArray[2*index+1] = myArray[2*i+1];
329 for( int j = 1; i+j < mySegmentNumber;j++ )
331 myArray[2*(index+j)] = myArray[2*(i+j)];
332 myArray[2*(index+j)+1] = myArray[2*(i+j)+1];
334 for( int k = 0; k < mySegmentNumber - i - 1; k++ )
336 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
337 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
339 mySegmentNumber -= i - index;
345 myArray[2*(index+1)] = coord2;
350 myArray[2*(index)] = coord2;
351 myArray[2*(index)+1] = myArray[2*(index+1)+1];
352 for( int j = index+1; j < mySegmentNumber-1; j++ )
354 myArray[2*j] = myArray[2*(j+1)];
355 myArray[2*j+1] = myArray[2*(j+1)+1];
358 myArray[2*mySegmentNumber] = 0.0;
359 myArray[2*mySegmentNumber+1] = 0.0;
371 myArray[2*index] = 0.0;
372 myArray[2*index+1] = 0.0;
384 void GLViewer_LineList::clear()
387 memset( myArray, 0, myRealSize*sizeof(double) );
391 Prints debug info about line list
393 void GLViewer_LineList::print()
395 std::cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
396 for( int i = 0; i < mySegmentNumber; i++ )
397 std::cout << " " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
399 std::cout << std::endl;
403 Draws line list with help of OpenGL
404 \param theDim - dimension
406 void GLViewer_LineList::show( FieldDim theDim )
411 glColor3f( 1.0, 0.0, 1.0 );
415 for( int i = 0; i < mySegmentNumber; i++ )
417 glVertex2d( myArray[2*i], myMainCoord );
418 glVertex2d( myArray[2*i+1], myMainCoord );
422 else if( theDim == FD_Y )
425 for( int i = 0; i < mySegmentNumber; i++ )
427 glVertex2d( myMainCoord, myArray[2*i] );
428 glVertex2d( myMainCoord, myArray[2*i+1] );
438 GLViewer_LineField::GLViewer_LineField()
441 myGraphArray1 = NULL;
442 myGraphArray2 = NULL;
455 GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, const int theYN )
458 myGraphArray1 = NULL;
459 myGraphArray2 = NULL;
463 if( theXN <= 0 || theYN <= 0 )
472 myXLineArray = new GLViewer_LineList*[theXN];
473 myYLineArray = new GLViewer_LineList*[theYN];
475 for( int i = 0; i < theXN; i++ )
476 myXLineArray[i] = new GLViewer_LineList( theMAXSize );
478 for( int j = 0; j < theYN; j++ )
479 myYLineArray[j] = new GLViewer_LineList( theMAXSize );
489 GLViewer_LineField::~GLViewer_LineField()
493 for( int i = 0; i < myXSize; i++ )
494 delete myXLineArray[i];
501 for( int j = 0; j < myYSize; j++ )
502 delete myYLineArray[j];
508 delete myGraphArray1;
511 delete myGraphArray2;
517 void GLViewer_LineField::addLine( FieldDim, GLViewer_LineList* )
524 \param theDim - dimension
525 \param theMC - main co-ordinate
526 \param theBegin - start co-ordinate
527 \param theEnd - end co-ordinate
529 void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegin, double theEnd )
531 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
532 aLL->addSegment( theBegin, theEnd );
533 aLL->setMainCoord( theMC );
534 addLine( theDim, aLL );
539 \param theDim - dimension
540 \param theLL - main co-ordinate
541 \param thePosition - index in list
543 int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, int thePosition )
545 if( !myXLineArray || !myYLineArray )
548 GLViewer_LineList** anArray = getLLArray( theDim );
552 int size = getDimSize( theDim );
554 if( thePosition >= size )
556 else if( thePosition < 0 )
558 if( anArray[size-1]->count() != 0 ) // no more space
561 for( int i = 0; i < size; i++ )
563 if( anArray[i]->count() == 0 )
570 double cur_mc = anArray[i]->mainCoord();
571 if( theLL->mainCoord() < cur_mc )
573 for( int j = 0; j+i+1 < size; j++ )
575 delete anArray[size-j-1];
576 anArray[size-j-1] = anArray[size-j-2];
586 delete anArray[thePosition];
587 anArray[thePosition] = theLL;
596 \param theDim - dimension
597 \param theMainCoord - main co-ordinate
598 \param theBegin - start co-ordinate
599 \param theEnd - end co-ordinate
600 \param thePosition - index in list
602 int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double theBegin, double theEnd, int thePosition )
604 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
605 aLL->addSegment( theBegin, theEnd );
606 aLL->setMainCoord( theMainCoord );
607 return insertLine( theDim, aLL, thePosition );
611 \return other dimension
613 FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
623 \param theIndex - index in list
624 \param tehFD - dimension
626 GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
628 if( !myXLineArray || !myYLineArray )
633 if( theIndex > myXSize )
636 return myXLineArray[theIndex];
638 else if( theFD == FD_Y )
640 if( theIndex > myYSize )
643 return myYLineArray[theIndex];
650 Sets borders of field
651 \param X1, X2 - minimal and maximal abscisses
652 \param Y1, Y2 - minimal and maximal ordinates
654 void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2 )
656 if( !myXLineArray || !myYLineArray )
659 for( int i = 0; i < myXSize; i++ )
661 myXLineArray[i]->clear();
662 myXLineArray[i]->addSegment( X1, X2 );
663 myXLineArray[i]->setMainCoord( Y1 + (Y2-Y1)*(double(i)/(myXSize-1)) );
666 for( int j = 0; j < myYSize; j++ )
668 myYLineArray[j]->clear();
669 myYLineArray[j]->addSegment( Y1, Y2 );
670 myYLineArray[j]->setMainCoord( X1 + (X2-X1)*(double(j)/(myYSize-1)) );
676 \param top, right - a corner of rectangle
677 \param bottom, left - other corner of rectangle
679 void GLViewer_LineField::addRectangle( double top, double right, double bottom, double left )
681 if( !myXLineArray || !myYLineArray )
683 for( int i = 0; i < myXSize; i++ )
685 double mainCoord = myXLineArray[i]->mainCoord();
686 if( mainCoord < top && mainCoord > bottom )
687 myXLineArray[i]->removeSegment( left, right );
690 for( int j = 0; j < myYSize; j++ )
692 double mainCoord = myYLineArray[j]->mainCoord();
693 if( mainCoord < right && mainCoord > left )
694 myYLineArray[j]->removeSegment( bottom, top );
699 Prints debug info about line field
701 void GLViewer_LineField::print()
703 std::cout << "My X matrix Number: " << myXSize << std::endl;
704 for( int i = 0; i < myXSize; i++ )
705 myXLineArray[i]->print();
707 std::cout << "My Y matrix Number: " << myYSize << std::endl;
708 for( int j = 0; j < myYSize; j++ )
709 myYLineArray[j]->print();
713 Draws field with help of OpenGL
715 void GLViewer_LineField::show()
717 for( int i = 0; i < myXSize; i++ )
718 getLine( i, FD_X )->show( FD_X );
720 for( int j = 0; j < myYSize; j++ )
721 getLine( j, FD_Y )->show( FD_Y );
723 double* anArray = solution( count );
724 glColor3f( 1.0, 0.0, 0.0 );
726 for( int k = 0; k < count; k++ )
728 glVertex2d( anArray[4*k], anArray[4*k+1] );
729 glVertex2d( anArray[4*k+2], anArray[4*k+3] );
733 std::cout << "Show function" << std::endl;
738 \param theDim - dimension
740 int GLViewer_LineField::getDimSize( FieldDim theDim )
744 else if( theDim == FD_Y )
751 \return array of intersected indexes
752 \param theDim - dimension
753 \param theIndex - index
754 \param theLL - line with that intersection is checked
755 \param theSize - to return value of array size
757 int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL, int& theSize )
760 if( !myXLineArray || !myYLineArray )
763 int aDimSize = getDimSize( theDim );
764 int* anArray = new int[aDimSize*2 ];
766 for( int i = 0; i < aDimSize; i++ )
768 GLViewer_LineList* aLL = getLine( i, theDim );
769 int index = aLL->contains( theLL->mainCoord() );
770 if( index != -1 && theLL->contains( aLL->mainCoord() ) == theIndex )
772 anArray[theSize*2] = i;
773 anArray[theSize*2+1] = index;
782 Sets start/end search point
783 \param thePoint - type of point (start: FP_Start; end: FP_End )
784 \param theX, theY - point co-ordinates
786 bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY )
788 if( !myXLineArray || !myYLineArray )
792 int xSeg = -1, ySeg = -1;
793 for( i = 0; i < myXSize; i++ )
795 GLViewer_LineList* aLL = getLine( i, FD_X );
796 if( aLL->mainCoord() == theY )
798 xSeg = aLL->contains( theX );
803 for( j = 0; j < myYSize; j++ )
805 GLViewer_LineList* aLL = getLine( j, FD_Y );
806 if( aLL->mainCoord() == theX )
808 ySeg = aLL->contains( theY );
813 if( xSeg != -1 && ySeg != -1 )
815 if( thePoint == FP_Start )
817 myStartPoint.myXLineIndex = i;
818 myStartPoint.myXSegmentIndex = xSeg;
819 myStartPoint.myYLineIndex = j;
820 myStartPoint.myYSegmentIndex = ySeg;
821 myStartPoint.mySolveIndex = -1;
825 myEndPoint.myXLineIndex = i;
826 myEndPoint.myXSegmentIndex = xSeg;
827 myEndPoint.myYLineIndex = j;
828 myEndPoint.myYSegmentIndex = ySeg;
829 myEndPoint.mySolveIndex = -1;
838 \return number of segments
840 int GLViewer_LineField::segmentNumber()
842 if( !(myXLineArray || myYLineArray) )
846 for( int aDim = 0; aDim < 2; aDim++ )
847 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
848 aNumber += getLine( i, (FieldDim)aDim )->count();
854 Removes all multiple segments
856 void GLViewer_LineField::optimize()
858 if( !myXLineArray || !myYLineArray )
861 for( int aDim = 0; aDim < 2; aDim++ )
863 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
865 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
866 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
868 // int index = i; unused
870 aLL->readSegment( k, a1, a2 );
871 for( int l = i+1, m = getDimSize( (FieldDim)aDim ); l < m; l++ )
874 GLViewer_LineList* aCurLL = getLine( l, (FieldDim)aDim );
875 for( int j = 0, count = aCurLL->count(); j < count; j++ )
878 aCurLL->readSegment( j, c1, c2 );
879 if( a1 == c1 && a2 == c2 )
881 if( !(aDim == 0 && myStartPoint.myXLineIndex == l && myStartPoint.myXSegmentIndex == j) &&
882 !(aDim == 0 && myEndPoint.myXLineIndex == l && myEndPoint.myXSegmentIndex == j) &&
883 !(aDim == 1 && myStartPoint.myYLineIndex == l && myStartPoint.myYSegmentIndex == j) &&
884 !(aDim == 1 && myEndPoint.myYLineIndex == l && myEndPoint.myYSegmentIndex == j) )
885 aCurLL->removeSegment( j );
895 if( end == -1 || end == 1)
905 Needs call setPoint before
907 void GLViewer_LineField::initialize()
909 if( !myXLineArray || !myYLineArray )
912 int size = segmentNumber();
917 myGraphArray1 = new GraphNode[size];
918 myGraphArray2 = new GraphNode[size];
923 for( int aDim = 0; aDim < 2; aDim++ )
925 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
927 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
928 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
930 myGraphArray1[index].myCount = size;
931 myGraphArray1[index].myDim = (FieldDim)aDim;
932 myGraphArray1[index].myLineIndex = i;
933 myGraphArray1[index].mySegmentindex = k;
934 myGraphArray1[index].prevNodeIndex = -1;
936 myGraphArray2[index].myCount = size;
937 myGraphArray2[index].myDim = (FieldDim)aDim;
938 myGraphArray2[index].myLineIndex = i;
939 myGraphArray2[index].mySegmentindex = k;
940 myGraphArray2[index].prevNodeIndex = -1;
942 if( !isXSet && aDim == FD_X && myStartPoint.myXLineIndex == i && myStartPoint.myXSegmentIndex == k )
944 myGraphArray1[index].myCount = 0;
948 if( aDim == FD_Y && !isYSet && myStartPoint.myYLineIndex == i && myStartPoint.myYSegmentIndex == k )
950 myGraphArray1[index].myCount = 0;
961 One iteration of algorithm
963 void GLViewer_LineField::iteration()
965 int aParam = myCurCount;
968 int* aNodes = findByCount( aParam );
969 GraphNode* aCurArray = getCurArray();
971 for( int i = 0; i < aParam; i++ )
973 GraphNode aCurNode = aCurArray[aNodes[i]];
975 int* aInterNodes = intersectIndexes( invertDim( aCurNode.myDim ), aCurNode.mySegmentindex,
976 getLine( aCurNode.myLineIndex, aCurNode.myDim ), aSize );
977 for( int j = 0; j < aSize; j++ )
979 int index = findBySegment( invertDim( aCurNode.myDim ), aInterNodes[2*j], aInterNodes[2*j+1], false );
981 if( aCurArray[index].myCount > myCurCount )
983 aCurArray[index].myCount = myCurCount;
984 aCurArray[index].prevNodeIndex = aNodes[i];
988 delete[] aInterNodes;
995 Checks for complete status
997 GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
999 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1003 GraphNode* aCurArray = getCurArray(),
1004 * aSecArray = getSecArray();
1006 for( int i = 0, n = segmentNumber(); i < n; i++ )
1008 if( aCurArray[i].myCount != aSecArray[i].myCount )
1010 if( aCurArray[i].myDim == FD_X &&
1011 aCurArray[i].myLineIndex == myEndPoint.myXLineIndex &&
1012 aCurArray[i].mySegmentindex == myEndPoint.myXSegmentIndex )
1014 std::cout << "Algorithm complete X!!!!!!!" << std::endl;
1015 myEndPoint.mySolveIndex = i;
1018 else if( aCurArray[i].myDim == FD_Y &&
1019 aCurArray[i].myLineIndex == myEndPoint.myYLineIndex &&
1020 aCurArray[i].mySegmentindex == myEndPoint.myYSegmentIndex )
1022 std::cout << "Algorithm complete Y!!!!!!!" << std::endl;
1023 myEndPoint.mySolveIndex = i;
1029 aSecArray[i].myCount = aCurArray[i].myCount;
1030 aSecArray[i].prevNodeIndex = aCurArray[i].prevNodeIndex;
1035 if( myCurArrayIndex == 0)
1036 myCurArrayIndex = 1;
1038 myCurArrayIndex = 0;
1040 std::cout << "Number of ways: " << count << std::endl;
1044 return IS_NOT_SOLVED;
1048 Finds LineList by counts and returns indexes
1050 int* GLViewer_LineField::findByCount( int& theParam )
1052 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1055 int count = segmentNumber();
1056 int* anArray = new int[count];
1059 GraphNode* aCurArray = getCurArray();
1060 for( int i = 0; i < count; i++ )
1062 GraphNode aCurNode = aCurArray[i];
1063 if( aCurNode.myCount == theParam )
1075 Finds LineList by segment and dimension
1077 int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int theSegment, bool inCurArray )
1079 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 || getDimSize( theDim ) <= theLineIndex )
1082 GraphNode* aCurArray;
1084 aCurArray = getCurArray();
1086 aCurArray = getSecArray();
1088 for( int i = 0, n = segmentNumber(); i < n; i++ )
1090 GraphNode aCurNode = aCurArray[i];
1091 if( aCurNode.myDim == theDim && aCurNode.myLineIndex == theLineIndex && aCurNode.mySegmentindex == theSegment )
1099 Main method, performs algorithm execution
1101 GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
1103 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1108 std::cout << "-----------Iteration #" << myCurCount << "-------------" << std::endl;
1111 IterationStatus is = checkComplete();
1112 if( is == IS_ERROR )
1114 else if( is == IS_LOOP )
1116 else if( is == IS_SOLVED )
1123 \return solution and size of solution
1125 double* GLViewer_LineField::solution( int& theSize )
1127 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1130 if( myEndPoint.mySolveIndex == -1 )
1133 theSize = myCurCount+1;
1134 double* anArray = new double[theSize*4];
1136 GraphNode* aCurArray = getCurArray();
1138 int index = myEndPoint.mySolveIndex;
1139 for( int i = 0; i <= myCurCount; i++ )
1144 GLViewer_LineList* aLL = getLine( aCurArray[index].myLineIndex, aCurArray[index].myDim );
1145 aLL->readSegment( aCurArray[index].mySegmentindex, c1, c2 );
1147 if( aCurArray[index].myDim == FD_X )
1150 anArray[i*4+1] = aLL->mainCoord();
1151 anArray[i*4+2] = c2;
1152 anArray[i*4+3] = aLL->mainCoord();
1156 anArray[i*4] = aLL->mainCoord();
1157 anArray[i*4+1] = c1;
1158 anArray[i*4+2] = aLL->mainCoord();
1159 anArray[i*4+3] = c2;
1162 index = aCurArray[index].prevNodeIndex;
1169 \return current solution array
1171 GraphNode* GLViewer_LineField::getCurArray()
1173 if( !myGraphArray1 || !myGraphArray2 )
1176 if( myCurArrayIndex == 0)
1177 return myGraphArray1;
1179 return myGraphArray2;
1183 \return other solution array
1185 GraphNode* GLViewer_LineField::getSecArray()
1187 if( !myGraphArray1 || !myGraphArray2 )
1190 if( myCurArrayIndex == 0)
1191 return myGraphArray2;
1193 return myGraphArray1;
1197 \return maximum segment number
1199 int GLViewer_LineField::maxSegmentNum()
1201 if( !myXLineArray || !myYLineArray )
1205 for( int aDim = 0; aDim < 2; aDim++ )
1207 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
1209 int count = getLine( i, (FieldDim)aDim )->count();
1210 if( count > max_num )
1219 \return list of LileList by dimension
1220 \param theDim - dimension
1222 GLViewer_LineList** GLViewer_LineField::getLLArray( FieldDim theDim )
1224 if( theDim == FD_X )
1225 return myXLineArray;
1226 else if( theDim == FD_Y )
1227 return myYLineArray;