1 // Copyright (C) 2007-2008 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.
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
22 // Author : OPEN CASCADE
23 // File: GLViewer_Tools.cxx
24 // Created: April, 2005
26 #include "GLViewer_Tools.h"
35 \param size - size of internal array
37 GLViewer_LineList::GLViewer_LineList( int size )
43 myArray = new double[myRealSize];
47 std::cout << "Can't allocate memory: " << size << std::endl;
51 memset( myArray, 0, myRealSize*sizeof(double) );
57 GLViewer_LineList::~GLViewer_LineList()
63 Adds new line segment to list
64 \param coord1, coord2 - co-ordinates of points
66 bool GLViewer_LineList::addSegment( double coord1, double coord2 )
75 if( 2*mySegmentNumber == myRealSize || !myArray )
80 while( index < mySegmentNumber)
82 readSegment( index, c1, c2 );
83 if( coord1 < c1 && coord2 < c1 )
85 for( int i = mySegmentNumber; i > index - 1; i--)
87 myArray[2*i] = myArray[2*i-2]; //2*(i-1)
88 myArray[2*i+1] = myArray[2*i-1];//2*(i-1)+1
92 // mySegmentNumber; what is means ?
95 else if( coord1 < c1 && coord2 < c2 )
97 myArray[index*2] = coord1;
100 else if( c1 < coord1 && coord2 < c2 )
104 else if( coord1 < c2 && c2 < coord2 )
107 myArray[2*index] = coord1;
109 if( index != mySegmentNumber - 1 )
111 for( int i = index+1; i < mySegmentNumber; i++ )
113 if( coord2 < myArray[2*i] )
115 myArray[2*index+1] = coord2;
118 for( int j = 0; i+j < mySegmentNumber;j++ )
120 myArray[2*(index+1+j)] = myArray[2*(i+j)];
121 myArray[2*(index+1+j)+1] = myArray[2*(i+j)+1];
123 for( int k = 0; k < mySegmentNumber - i; k++ )
125 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
126 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
128 mySegmentNumber -= i - index-1;
132 else if( coord2 < myArray[2*i+1] )
134 myArray[2*index+1] = myArray[2*i+1];
136 for( int j = index+1; j < mySegmentNumber-1;j++ )
138 myArray[2*j] = myArray[2*(i+j-index)];
139 myArray[2*j+1] = myArray[2*(i+j-index)+1];
141 for( int k = 0; k < mySegmentNumber - i-1; k++ )
143 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
144 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
146 mySegmentNumber -= i - index;
153 myArray[2*index+1] = coord2;
160 myArray[mySegmentNumber*2] = coord1;
161 myArray[mySegmentNumber*2+1] = coord2;
168 Gets info about segment
169 \param theIndex - index of segment
170 \param coord1, coord2 - co-ordinates of points
172 bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord2 )
174 if( theIndex > mySegmentNumber || !myArray)
177 coord1 = myArray[theIndex*2];
178 coord2 = myArray[theIndex*2+1];
184 \return true if line list covers point
185 \param thePoint - point co-ordinate
187 int GLViewer_LineList::contains( double thePoint ) const
189 if( !myArray || mySegmentNumber == 0 )
192 for( int i = 0; i < mySegmentNumber; i++ )
193 if( myArray[2*i] <= thePoint && thePoint <= myArray[2*i+1] )
202 \param theIndex - segment index
204 bool GLViewer_LineList::removeSegment( int theIndex )
206 if( theIndex > mySegmentNumber || !myArray)
209 for( int i = theIndex; i < mySegmentNumber; i++ )
211 myArray[i*2] = myArray[(i+1)*2];
212 myArray[i*2+1] = myArray[(i+1)*2+1];
215 myArray[mySegmentNumber*2] = 0.0;
216 myArray[mySegmentNumber*2+1] = 0.0;
221 Removes segment from line list
222 \param coord1, coord2 - co-ordinates of points
224 bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
226 if( coord1 > coord2 )
228 double temp = coord1;
233 if( 2*mySegmentNumber == myRealSize || !myArray )
238 while( index < mySegmentNumber)
240 readSegment( index, c1, c2 );
241 if( coord1 < c1 && coord2 < c1 )
246 else if( coord1 < c1 && coord2 < c2 )
248 myArray[index*2] = coord2;
251 else if( c1 < coord1 && coord2 < c2 )
253 if( 2*mySegmentNumber == myRealSize )
255 for( int i = mySegmentNumber; i > index + 1; i-- )
257 myArray[2*i] = myArray[2*(i-1)];
258 myArray[2*i+1] = myArray[2*(i-1)+1];
260 myArray[2*(index+1)+1] = myArray[2*index+1];
261 myArray[2*(index+1)] = coord2;
262 myArray[2*index+1] = coord1;
266 else if( coord1 < c2 && c2 < coord2 )
270 myArray[2*index+1] = coord1;
273 if( index != mySegmentNumber - 1 )
275 for( int i = index+1; i < mySegmentNumber; i++ )
277 if( coord2 < myArray[2*i] )
281 for( int j = 1; i+j-1 < mySegmentNumber;j++ )
283 myArray[2*(index+j)] = myArray[2*(i+j-1)];
284 myArray[2*(index+j)+1] = myArray[2*(i+j-1)+1];
286 for( int k = 0; k < mySegmentNumber - i; k++ )
288 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
289 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
291 mySegmentNumber -= i - index -1;
297 for( int j = 0; index + j + 1 < mySegmentNumber;j++ )
299 myArray[2*(index+j)] = myArray[2*(index+j+1)];
300 myArray[2*(index+j)+1] = myArray[2*(index+j+1)+1];
303 myArray[2*(mySegmentNumber - 1)] = 0.0;
304 myArray[2*(mySegmentNumber - 1)+1] = 0.0;
314 else if( coord2 < myArray[2*i+1] )
321 myArray[2*index] = coord2;
322 myArray[2*index+1] = myArray[2*i+1];
324 for( int j = 1; i+j < mySegmentNumber;j++ )
326 myArray[2*(index+j)] = myArray[2*(i+j)];
327 myArray[2*(index+j)+1] = myArray[2*(i+j)+1];
329 for( int k = 0; k < mySegmentNumber - i - 1; k++ )
331 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
332 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
334 mySegmentNumber -= i - index;
340 myArray[2*(index+1)] = coord2;
345 myArray[2*(index)] = coord2;
346 myArray[2*(index)+1] = myArray[2*(index+1)+1];
347 for( int j = index+1; j < mySegmentNumber-1; j++ )
349 myArray[2*j] = myArray[2*(j+1)];
350 myArray[2*j+1] = myArray[2*(j+1)+1];
353 myArray[2*mySegmentNumber] = 0.0;
354 myArray[2*mySegmentNumber+1] = 0.0;
366 myArray[2*index] = 0.0;
367 myArray[2*index+1] = 0.0;
379 void GLViewer_LineList::clear()
382 memset( myArray, 0, myRealSize*sizeof(double) );
386 Prints debug info about line list
388 void GLViewer_LineList::print()
390 std::cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
391 for( int i = 0; i < mySegmentNumber; i++ )
392 std::cout << " " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
394 std::cout << std::endl;
398 Draws line list with help of OpenGL
399 \param theDim - dimension
401 void GLViewer_LineList::show( FieldDim theDim )
406 glColor3f( 1.0, 0.0, 1.0 );
410 for( int i = 0; i < mySegmentNumber; i++ )
412 glVertex2d( myArray[2*i], myMainCoord );
413 glVertex2d( myArray[2*i+1], myMainCoord );
417 else if( theDim == FD_Y )
420 for( int i = 0; i < mySegmentNumber; i++ )
422 glVertex2d( myMainCoord, myArray[2*i] );
423 glVertex2d( myMainCoord, myArray[2*i+1] );
433 GLViewer_LineField::GLViewer_LineField()
436 myGraphArray1 = NULL;
437 myGraphArray2 = NULL;
450 GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, const int theYN )
453 myGraphArray1 = NULL;
454 myGraphArray2 = NULL;
458 if( theXN <= 0 || theYN <= 0 )
467 myXLineArray = new GLViewer_LineList*[theXN];
468 myYLineArray = new GLViewer_LineList*[theYN];
470 for( int i = 0; i < theXN; i++ )
471 myXLineArray[i] = new GLViewer_LineList( theMAXSize );
473 for( int j = 0; j < theYN; j++ )
474 myYLineArray[j] = new GLViewer_LineList( theMAXSize );
484 GLViewer_LineField::~GLViewer_LineField()
488 for( int i = 0; i < myXSize; i++ )
489 delete myXLineArray[i];
496 for( int j = 0; j < myYSize; j++ )
497 delete myYLineArray[j];
503 delete myGraphArray1;
506 delete myGraphArray2;
512 void GLViewer_LineField::addLine( FieldDim theDim, GLViewer_LineList* )
519 \param theDim - dimension
520 \param theMC - main co-ordinate
521 \param theBegin - start co-ordinate
522 \param theEnd - end co-ordinate
524 void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegin, double theEnd )
526 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
527 aLL->addSegment( theBegin, theEnd );
528 aLL->setMainCoord( theMC );
529 addLine( theDim, aLL );
534 \param theDim - dimension
535 \param theLL - main co-ordinate
536 \param thePosition - index in list
538 int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, int thePosition )
540 if( !myXLineArray || !myYLineArray )
543 GLViewer_LineList** anArray = getLLArray( theDim );
547 int size = getDimSize( theDim );
549 if( thePosition >= size )
551 else if( thePosition < 0 )
553 if( anArray[size-1]->count() != 0 ) // no more space
556 for( int i = 0; i < size; i++ )
558 if( anArray[i]->count() == 0 )
565 double cur_mc = anArray[i]->mainCoord();
566 if( theLL->mainCoord() < cur_mc )
568 for( int j = 0; j+i+1 < size; j++ )
570 delete anArray[size-j-1];
571 anArray[size-j-1] = anArray[size-j-2];
581 delete anArray[thePosition];
582 anArray[thePosition] = theLL;
591 \param theDim - dimension
592 \param theMainCoord - main co-ordinate
593 \param theBegin - start co-ordinate
594 \param theEnd - end co-ordinate
595 \param thePosition - index in list
597 int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double theBegin, double theEnd, int thePosition )
599 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
600 aLL->addSegment( theBegin, theEnd );
601 aLL->setMainCoord( theMainCoord );
602 return insertLine( theDim, aLL, thePosition );
606 \return other dimension
608 FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
618 \param theIndex - index in list
619 \param tehFD - dimension
621 GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
623 if( !myXLineArray || !myYLineArray )
628 if( theIndex > myXSize )
631 return myXLineArray[theIndex];
633 else if( theFD == FD_Y )
635 if( theIndex > myYSize )
638 return myYLineArray[theIndex];
645 Sets borders of field
646 \param X1, X2 - minimal and maximal abscisses
647 \param Y1, Y2 - minimal and maximal ordinates
649 void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2 )
651 if( !myXLineArray || !myYLineArray )
654 for( int i = 0; i < myXSize; i++ )
656 myXLineArray[i]->clear();
657 myXLineArray[i]->addSegment( X1, X2 );
658 myXLineArray[i]->setMainCoord( Y1 + (Y2-Y1)*(double(i)/(myXSize-1)) );
661 for( int j = 0; j < myYSize; j++ )
663 myYLineArray[j]->clear();
664 myYLineArray[j]->addSegment( Y1, Y2 );
665 myYLineArray[j]->setMainCoord( X1 + (X2-X1)*(double(j)/(myYSize-1)) );
671 \param top, right - a corner of rectangle
672 \param bottom, left - other corner of rectangle
674 void GLViewer_LineField::addRectangle( double top, double right, double bottom, double left )
676 if( !myXLineArray || !myYLineArray )
678 for( int i = 0; i < myXSize; i++ )
680 double mainCoord = myXLineArray[i]->mainCoord();
681 if( mainCoord < top && mainCoord > bottom )
682 myXLineArray[i]->removeSegment( left, right );
685 for( int j = 0; j < myYSize; j++ )
687 double mainCoord = myYLineArray[j]->mainCoord();
688 if( mainCoord < right && mainCoord > left )
689 myYLineArray[j]->removeSegment( bottom, top );
694 Prints debug info about line field
696 void GLViewer_LineField::print()
698 std::cout << "My X matrix Number: " << myXSize << std::endl;
699 for( int i = 0; i < myXSize; i++ )
700 myXLineArray[i]->print();
702 std::cout << "My Y matrix Number: " << myYSize << std::endl;
703 for( int j = 0; j < myYSize; j++ )
704 myYLineArray[j]->print();
708 Draws field with help of OpenGL
710 void GLViewer_LineField::show()
712 for( int i = 0; i < myXSize; i++ )
713 getLine( i, FD_X )->show( FD_X );
715 for( int j = 0; j < myYSize; j++ )
716 getLine( j, FD_Y )->show( FD_Y );
718 double* anArray = solution( count );
719 glColor3f( 1.0, 0.0, 0.0 );
721 for( int k = 0; k < count; k++ )
723 glVertex2d( anArray[4*k], anArray[4*k+1] );
724 glVertex2d( anArray[4*k+2], anArray[4*k+3] );
728 std::cout << "Show function" << std::endl;
733 \param theDim - dimension
735 int GLViewer_LineField::getDimSize( FieldDim theDim )
739 else if( theDim == FD_Y )
746 \return array of intersected indexes
747 \param theDim - dimension
748 \param theIndex - index
749 \param theLL - line with that intersection is checked
750 \param theSize - to return value of array size
752 int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL, int& theSize )
755 if( !myXLineArray || !myYLineArray )
758 int aDimSize = getDimSize( theDim );
759 int* anArray = new int[aDimSize*2 ];
761 for( int i = 0; i < aDimSize; i++ )
763 GLViewer_LineList* aLL = getLine( i, theDim );
764 int index = aLL->contains( theLL->mainCoord() );
765 if( index != -1 && theLL->contains( aLL->mainCoord() ) == theIndex )
767 anArray[theSize*2] = i;
768 anArray[theSize*2+1] = index;
777 Sets start/end search point
778 \param thePoint - type of point (start: FP_Start; end: FP_End )
779 \param theX, theY - point co-ordinates
781 bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY )
783 if( !myXLineArray || !myYLineArray )
787 int xSeg = -1, ySeg = -1;
788 for( i = 0; i < myXSize; i++ )
790 GLViewer_LineList* aLL = getLine( i, FD_X );
791 if( aLL->mainCoord() == theY )
793 xSeg = aLL->contains( theX );
798 for( j = 0; j < myYSize; j++ )
800 GLViewer_LineList* aLL = getLine( j, FD_Y );
801 if( aLL->mainCoord() == theX )
803 ySeg = aLL->contains( theY );
808 if( xSeg != -1 && ySeg != -1 )
810 if( thePoint == FP_Start )
812 myStartPoint.myXLineIndex = i;
813 myStartPoint.myXSegmentIndex = xSeg;
814 myStartPoint.myYLineIndex = j;
815 myStartPoint.myYSegmentIndex = ySeg;
816 myStartPoint.mySolveIndex = -1;
820 myEndPoint.myXLineIndex = i;
821 myEndPoint.myXSegmentIndex = xSeg;
822 myEndPoint.myYLineIndex = j;
823 myEndPoint.myYSegmentIndex = ySeg;
824 myEndPoint.mySolveIndex = -1;
833 \return number of segments
835 int GLViewer_LineField::segmentNumber()
837 if( !(myXLineArray || myYLineArray) )
841 for( int aDim = 0; aDim < 2; aDim++ )
842 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
843 aNumber += getLine( i, (FieldDim)aDim )->count();
849 Removes all multiple segments
851 void GLViewer_LineField::optimize()
853 if( !myXLineArray || !myYLineArray )
856 for( int aDim = 0; aDim < 2; aDim++ )
858 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
860 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
861 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
863 // int index = i; unused
865 aLL->readSegment( k, a1, a2 );
866 for( int l = i+1, m = getDimSize( (FieldDim)aDim ); l < m; l++ )
869 GLViewer_LineList* aCurLL = getLine( l, (FieldDim)aDim );
870 for( int j = 0, count = aCurLL->count(); j < count; j++ )
873 aCurLL->readSegment( j, c1, c2 );
874 if( a1 == c1 && a2 == c2 )
876 if( !(aDim == 0 && myStartPoint.myXLineIndex == l && myStartPoint.myXSegmentIndex == j) &&
877 !(aDim == 0 && myEndPoint.myXLineIndex == l && myEndPoint.myXSegmentIndex == j) &&
878 !(aDim == 1 && myStartPoint.myYLineIndex == l && myStartPoint.myYSegmentIndex == j) &&
879 !(aDim == 1 && myEndPoint.myYLineIndex == l && myEndPoint.myYSegmentIndex == j) )
880 aCurLL->removeSegment( j );
890 if( end == -1 || end == 1)
900 Needs call setPoint before
902 void GLViewer_LineField::initialize()
904 if( !myXLineArray || !myYLineArray )
907 int size = segmentNumber();
912 myGraphArray1 = new GraphNode[size];
913 myGraphArray2 = new GraphNode[size];
918 for( int aDim = 0; aDim < 2; aDim++ )
920 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
922 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
923 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
925 myGraphArray1[index].myCount = size;
926 myGraphArray1[index].myDim = (FieldDim)aDim;
927 myGraphArray1[index].myLineIndex = i;
928 myGraphArray1[index].mySegmentindex = k;
929 myGraphArray1[index].prevNodeIndex = -1;
931 myGraphArray2[index].myCount = size;
932 myGraphArray2[index].myDim = (FieldDim)aDim;
933 myGraphArray2[index].myLineIndex = i;
934 myGraphArray2[index].mySegmentindex = k;
935 myGraphArray2[index].prevNodeIndex = -1;
937 if( !isXSet && aDim == FD_X && myStartPoint.myXLineIndex == i && myStartPoint.myXSegmentIndex == k )
939 myGraphArray1[index].myCount = 0;
943 if( aDim == FD_Y && !isYSet && myStartPoint.myYLineIndex == i && myStartPoint.myYSegmentIndex == k )
945 myGraphArray1[index].myCount = 0;
956 One iteration of algorithm
958 void GLViewer_LineField::iteration()
960 int aParam = myCurCount;
963 int* aNodes = findByCount( aParam );
964 GraphNode* aCurArray = getCurArray();
966 for( int i = 0; i < aParam; i++ )
968 GraphNode aCurNode = aCurArray[aNodes[i]];
970 int* aInterNodes = intersectIndexes( invertDim( aCurNode.myDim ), aCurNode.mySegmentindex,
971 getLine( aCurNode.myLineIndex, aCurNode.myDim ), aSize );
972 for( int j = 0; j < aSize; j++ )
974 int index = findBySegment( invertDim( aCurNode.myDim ), aInterNodes[2*j], aInterNodes[2*j+1], false );
976 if( aCurArray[index].myCount > myCurCount )
978 aCurArray[index].myCount = myCurCount;
979 aCurArray[index].prevNodeIndex = aNodes[i];
983 delete[] aInterNodes;
990 Checks for complete status
992 GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
994 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
998 GraphNode* aCurArray = getCurArray(),
999 * aSecArray = getSecArray();
1001 for( int i = 0, n = segmentNumber(); i < n; i++ )
1003 if( aCurArray[i].myCount != aSecArray[i].myCount )
1005 if( aCurArray[i].myDim == FD_X &&
1006 aCurArray[i].myLineIndex == myEndPoint.myXLineIndex &&
1007 aCurArray[i].mySegmentindex == myEndPoint.myXSegmentIndex )
1009 std::cout << "Algorithm complete X!!!!!!!" << std::endl;
1010 myEndPoint.mySolveIndex = i;
1013 else if( aCurArray[i].myDim == FD_Y &&
1014 aCurArray[i].myLineIndex == myEndPoint.myYLineIndex &&
1015 aCurArray[i].mySegmentindex == myEndPoint.myYSegmentIndex )
1017 std::cout << "Algorithm complete Y!!!!!!!" << std::endl;
1018 myEndPoint.mySolveIndex = i;
1024 aSecArray[i].myCount = aCurArray[i].myCount;
1025 aSecArray[i].prevNodeIndex = aCurArray[i].prevNodeIndex;
1030 if( myCurArrayIndex == 0)
1031 myCurArrayIndex = 1;
1033 myCurArrayIndex = 0;
1035 std::cout << "Number of ways: " << count << std::endl;
1039 return IS_NOT_SOLVED;
1043 Finds LineList by counts and returns indexes
1045 int* GLViewer_LineField::findByCount( int& theParam )
1047 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1050 int count = segmentNumber();
1051 int* anArray = new int[count];
1054 GraphNode* aCurArray = getCurArray();
1055 for( int i = 0; i < count; i++ )
1057 GraphNode aCurNode = aCurArray[i];
1058 if( aCurNode.myCount == theParam )
1070 Finds LineList by segment and dimension
1072 int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int theSegment, bool inCurArray )
1074 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 || getDimSize( theDim ) <= theLineIndex )
1077 GraphNode* aCurArray;
1079 aCurArray = getCurArray();
1081 aCurArray = getSecArray();
1083 for( int i = 0, n = segmentNumber(); i < n; i++ )
1085 GraphNode aCurNode = aCurArray[i];
1086 if( aCurNode.myDim == theDim && aCurNode.myLineIndex == theLineIndex && aCurNode.mySegmentindex == theSegment )
1094 Main method, performs algorithm execution
1096 GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
1098 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1103 std::cout << "-----------Iteration #" << myCurCount << "-------------" << std::endl;
1106 IterationStatus is = checkComplete();
1107 if( is == IS_ERROR )
1109 else if( is == IS_LOOP )
1111 else if( is == IS_SOLVED )
1118 \return solution and size of solution
1120 double* GLViewer_LineField::solution( int& theSize )
1122 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1125 if( myEndPoint.mySolveIndex == -1 )
1128 theSize = myCurCount+1;
1129 double* anArray = new double[theSize*4];
1131 GraphNode* aCurArray = getCurArray();
1133 int index = myEndPoint.mySolveIndex;
1134 for( int i = 0; i <= myCurCount; i++ )
1139 GLViewer_LineList* aLL = getLine( aCurArray[index].myLineIndex, aCurArray[index].myDim );
1140 aLL->readSegment( aCurArray[index].mySegmentindex, c1, c2 );
1142 if( aCurArray[index].myDim == FD_X )
1145 anArray[i*4+1] = aLL->mainCoord();
1146 anArray[i*4+2] = c2;
1147 anArray[i*4+3] = aLL->mainCoord();
1151 anArray[i*4] = aLL->mainCoord();
1152 anArray[i*4+1] = c1;
1153 anArray[i*4+2] = aLL->mainCoord();
1154 anArray[i*4+3] = c2;
1157 index = aCurArray[index].prevNodeIndex;
1164 \return current solution array
1166 GraphNode* GLViewer_LineField::getCurArray()
1168 if( !myGraphArray1 || !myGraphArray2 )
1171 if( myCurArrayIndex == 0)
1172 return myGraphArray1;
1174 return myGraphArray2;
1178 \return other solution array
1180 GraphNode* GLViewer_LineField::getSecArray()
1182 if( !myGraphArray1 || !myGraphArray2 )
1185 if( myCurArrayIndex == 0)
1186 return myGraphArray2;
1188 return myGraphArray1;
1192 \return maximum segment number
1194 int GLViewer_LineField::maxSegmentNum()
1196 if( !myXLineArray || !myYLineArray )
1200 for( int aDim = 0; aDim < 2; aDim++ )
1202 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
1204 int count = getLine( i, (FieldDim)aDim )->count();
1205 if( count > max_num )
1214 \return list of LileList by dimension
1215 \param theDim - dimension
1217 GLViewer_LineList** GLViewer_LineField::getLLArray( FieldDim theDim )
1219 if( theDim == FD_X )
1220 return myXLineArray;
1221 else if( theDim == FD_Y )
1222 return myYLineArray;