1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : OPEN CASCADE
22 // File: GLViewer_Tools.cxx
23 // Created: April, 2005
25 #include "GLViewer_Tools.h"
33 \param size - size of internal array
35 GLViewer_LineList::GLViewer_LineList( int size )
41 myArray = new double[myRealSize];
45 std::cout << "Can't allocate memory: " << size << std::endl;
49 memset( myArray, 0, myRealSize*sizeof(double) );
55 GLViewer_LineList::~GLViewer_LineList()
61 Adds new line segment to list
62 \param coord1, coord2 - co-ordinates of points
64 bool GLViewer_LineList::addSegment( double coord1, double coord2 )
73 if( 2*mySegmentNumber == myRealSize || !myArray )
78 while( index < mySegmentNumber)
80 readSegment( index, c1, c2 );
81 if( coord1 < c1 && coord2 < c1 )
83 for( int i = mySegmentNumber; i > index - 1; i--)
85 myArray[2*i] = myArray[2*i-2]; //2*(i-1)
86 myArray[2*i+1] = myArray[2*i-1];//2*(i-1)+1
90 // mySegmentNumber; what is means ?
93 else if( coord1 < c1 && coord2 < c2 )
95 myArray[index*2] = coord1;
98 else if( c1 < coord1 && coord2 < c2 )
102 else if( coord1 < c2 && c2 < coord2 )
105 myArray[2*index] = coord1;
107 if( index != mySegmentNumber - 1 )
109 for( int i = index+1; i < mySegmentNumber; i++ )
111 if( coord2 < myArray[2*i] )
113 myArray[2*index+1] = coord2;
116 for( int j = 0; i+j < mySegmentNumber;j++ )
118 myArray[2*(index+1+j)] = myArray[2*(i+j)];
119 myArray[2*(index+1+j)+1] = myArray[2*(i+j)+1];
121 for( int k = 0; k < mySegmentNumber - i; k++ )
123 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
124 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
126 mySegmentNumber -= i - index-1;
130 else if( coord2 < myArray[2*i+1] )
132 myArray[2*index+1] = myArray[2*i+1];
134 for( int j = index+1; j < mySegmentNumber-1;j++ )
136 myArray[2*j] = myArray[2*(i+j-index)];
137 myArray[2*j+1] = myArray[2*(i+j-index)+1];
139 for( int k = 0; k < mySegmentNumber - i-1; k++ )
141 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
142 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
144 mySegmentNumber -= i - index;
151 myArray[2*index+1] = coord2;
158 myArray[mySegmentNumber*2] = coord1;
159 myArray[mySegmentNumber*2+1] = coord2;
166 Gets info about segment
167 \param theIndex - index of segment
168 \param coord1, coord2 - co-ordinates of points
170 bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord2 )
172 if( theIndex > mySegmentNumber || !myArray)
175 coord1 = myArray[theIndex*2];
176 coord2 = myArray[theIndex*2+1];
182 \return true if line list covers point
183 \param thePoint - point co-ordinate
185 int GLViewer_LineList::contains( double thePoint ) const
187 if( !myArray || mySegmentNumber == 0 )
190 for( int i = 0; i < mySegmentNumber; i++ )
191 if( myArray[2*i] <= thePoint && thePoint <= myArray[2*i+1] )
200 \param theIndex - segment index
202 bool GLViewer_LineList::removeSegment( int theIndex )
204 if( theIndex > mySegmentNumber || !myArray)
207 for( int i = theIndex; i < mySegmentNumber; i++ )
209 myArray[i*2] = myArray[(i+1)*2];
210 myArray[i*2+1] = myArray[(i+1)*2+1];
213 myArray[mySegmentNumber*2] = 0.0;
214 myArray[mySegmentNumber*2+1] = 0.0;
219 Removes segment from line list
220 \param coord1, coord2 - co-ordinates of points
222 bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
224 if( coord1 > coord2 )
226 double temp = coord1;
231 if( 2*mySegmentNumber == myRealSize || !myArray )
236 while( index < mySegmentNumber)
238 readSegment( index, c1, c2 );
239 if( coord1 < c1 && coord2 < c1 )
244 else if( coord1 < c1 && coord2 < c2 )
246 myArray[index*2] = coord2;
249 else if( c1 < coord1 && coord2 < c2 )
251 if( 2*mySegmentNumber == myRealSize )
253 for( int i = mySegmentNumber; i > index + 1; i-- )
255 myArray[2*i] = myArray[2*(i-1)];
256 myArray[2*i+1] = myArray[2*(i-1)+1];
258 myArray[2*(index+1)+1] = myArray[2*index+1];
259 myArray[2*(index+1)] = coord2;
260 myArray[2*index+1] = coord1;
264 else if( coord1 < c2 && c2 < coord2 )
268 myArray[2*index+1] = coord1;
271 if( index != mySegmentNumber - 1 )
273 for( int i = index+1; i < mySegmentNumber; i++ )
275 if( coord2 < myArray[2*i] )
279 for( int j = 1; i+j-1 < mySegmentNumber;j++ )
281 myArray[2*(index+j)] = myArray[2*(i+j-1)];
282 myArray[2*(index+j)+1] = myArray[2*(i+j-1)+1];
284 for( int k = 0; k < mySegmentNumber - i; k++ )
286 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
287 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
289 mySegmentNumber -= i - index -1;
295 for( int j = 0; index + j + 1 < mySegmentNumber;j++ )
297 myArray[2*(index+j)] = myArray[2*(index+j+1)];
298 myArray[2*(index+j)+1] = myArray[2*(index+j+1)+1];
301 myArray[2*(mySegmentNumber - 1)] = 0.0;
302 myArray[2*(mySegmentNumber - 1)+1] = 0.0;
312 else if( coord2 < myArray[2*i+1] )
319 myArray[2*index] = coord2;
320 myArray[2*index+1] = myArray[2*i+1];
322 for( int j = 1; i+j < mySegmentNumber;j++ )
324 myArray[2*(index+j)] = myArray[2*(i+j)];
325 myArray[2*(index+j)+1] = myArray[2*(i+j)+1];
327 for( int k = 0; k < mySegmentNumber - i - 1; k++ )
329 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
330 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
332 mySegmentNumber -= i - index;
338 myArray[2*(index+1)] = coord2;
343 myArray[2*(index)] = coord2;
344 myArray[2*(index)+1] = myArray[2*(index+1)+1];
345 for( int j = index+1; j < mySegmentNumber-1; j++ )
347 myArray[2*j] = myArray[2*(j+1)];
348 myArray[2*j+1] = myArray[2*(j+1)+1];
351 myArray[2*mySegmentNumber] = 0.0;
352 myArray[2*mySegmentNumber+1] = 0.0;
364 myArray[2*index] = 0.0;
365 myArray[2*index+1] = 0.0;
377 void GLViewer_LineList::clear()
380 memset( myArray, 0, myRealSize*sizeof(double) );
384 Prints debug info about line list
386 void GLViewer_LineList::print()
388 std::cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
389 for( int i = 0; i < mySegmentNumber; i++ )
390 std::cout << " " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
392 std::cout << std::endl;
396 Draws line list with help of OpenGL
397 \param theDim - dimension
399 void GLViewer_LineList::show( FieldDim theDim )
404 glColor3f( 1.0, 0.0, 1.0 );
408 for( int i = 0; i < mySegmentNumber; i++ )
410 glVertex2d( myArray[2*i], myMainCoord );
411 glVertex2d( myArray[2*i+1], myMainCoord );
415 else if( theDim == FD_Y )
418 for( int i = 0; i < mySegmentNumber; i++ )
420 glVertex2d( myMainCoord, myArray[2*i] );
421 glVertex2d( myMainCoord, myArray[2*i+1] );
431 GLViewer_LineField::GLViewer_LineField()
434 myGraphArray1 = NULL;
435 myGraphArray2 = NULL;
448 GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, const int theYN )
451 myGraphArray1 = NULL;
452 myGraphArray2 = NULL;
456 if( theXN <= 0 || theYN <= 0 )
465 myXLineArray = new GLViewer_LineList*[theXN];
466 myYLineArray = new GLViewer_LineList*[theYN];
468 for( int i = 0; i < theXN; i++ )
469 myXLineArray[i] = new GLViewer_LineList( theMAXSize );
471 for( int j = 0; j < theYN; j++ )
472 myYLineArray[j] = new GLViewer_LineList( theMAXSize );
482 GLViewer_LineField::~GLViewer_LineField()
486 for( int i = 0; i < myXSize; i++ )
487 delete myXLineArray[i];
494 for( int j = 0; j < myYSize; j++ )
495 delete myYLineArray[j];
501 delete myGraphArray1;
504 delete myGraphArray2;
510 void GLViewer_LineField::addLine( FieldDim theDim, GLViewer_LineList* )
517 \param theDim - dimension
518 \param theMC - main co-ordinate
519 \param theBegin - start co-ordinate
520 \param theEnd - end co-ordinate
522 void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegin, double theEnd )
524 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
525 aLL->addSegment( theBegin, theEnd );
526 aLL->setMainCoord( theMC );
527 addLine( theDim, aLL );
532 \param theDim - dimension
533 \param theLL - main co-ordinate
534 \param thePosition - index in list
536 int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, int thePosition )
538 if( !myXLineArray || !myYLineArray )
541 GLViewer_LineList** anArray = getLLArray( theDim );
545 int size = getDimSize( theDim );
547 if( thePosition >= size )
549 else if( thePosition < 0 )
551 if( anArray[size-1]->count() != 0 ) // no more space
554 for( int i = 0; i < size; i++ )
556 if( anArray[i]->count() == 0 )
563 double cur_mc = anArray[i]->mainCoord();
564 if( theLL->mainCoord() < cur_mc )
566 for( int j = 0; j+i+1 < size; j++ )
568 delete anArray[size-j-1];
569 anArray[size-j-1] = anArray[size-j-2];
579 delete anArray[thePosition];
580 anArray[thePosition] = theLL;
589 \param theDim - dimension
590 \param theMainCoord - main co-ordinate
591 \param theBegin - start co-ordinate
592 \param theEnd - end co-ordinate
593 \param thePosition - index in list
595 int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double theBegin, double theEnd, int thePosition )
597 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
598 aLL->addSegment( theBegin, theEnd );
599 aLL->setMainCoord( theMainCoord );
600 return insertLine( theDim, aLL, thePosition );
604 \return other dimension
606 FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
616 \param theIndex - index in list
617 \param tehFD - dimension
619 GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
621 if( !myXLineArray || !myYLineArray )
626 if( theIndex > myXSize )
629 return myXLineArray[theIndex];
631 else if( theFD == FD_Y )
633 if( theIndex > myYSize )
636 return myYLineArray[theIndex];
643 Sets borders of field
644 \param X1, X2 - minimal and maximal abscisses
645 \param Y1, Y2 - minimal and maximal ordinates
647 void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2 )
649 if( !myXLineArray || !myYLineArray )
652 for( int i = 0; i < myXSize; i++ )
654 myXLineArray[i]->clear();
655 myXLineArray[i]->addSegment( X1, X2 );
656 myXLineArray[i]->setMainCoord( Y1 + (Y2-Y1)*(double(i)/(myXSize-1)) );
659 for( int j = 0; j < myYSize; j++ )
661 myYLineArray[j]->clear();
662 myYLineArray[j]->addSegment( Y1, Y2 );
663 myYLineArray[j]->setMainCoord( X1 + (X2-X1)*(double(j)/(myYSize-1)) );
669 \param top, right - a corner of rectangle
670 \param bottom, left - other corner of rectangle
672 void GLViewer_LineField::addRectangle( double top, double right, double bottom, double left )
674 if( !myXLineArray || !myYLineArray )
676 for( int i = 0; i < myXSize; i++ )
678 double mainCoord = myXLineArray[i]->mainCoord();
679 if( mainCoord < top && mainCoord > bottom )
680 myXLineArray[i]->removeSegment( left, right );
683 for( int j = 0; j < myYSize; j++ )
685 double mainCoord = myYLineArray[j]->mainCoord();
686 if( mainCoord < right && mainCoord > left )
687 myYLineArray[j]->removeSegment( bottom, top );
692 Prints debug info about line field
694 void GLViewer_LineField::print()
696 std::cout << "My X matrix Number: " << myXSize << std::endl;
697 for( int i = 0; i < myXSize; i++ )
698 myXLineArray[i]->print();
700 std::cout << "My Y matrix Number: " << myYSize << std::endl;
701 for( int j = 0; j < myYSize; j++ )
702 myYLineArray[j]->print();
706 Draws field with help of OpenGL
708 void GLViewer_LineField::show()
710 for( int i = 0; i < myXSize; i++ )
711 getLine( i, FD_X )->show( FD_X );
713 for( int j = 0; j < myYSize; j++ )
714 getLine( j, FD_Y )->show( FD_Y );
716 double* anArray = solution( count );
717 glColor3f( 1.0, 0.0, 0.0 );
719 for( int k = 0; k < count; k++ )
721 glVertex2d( anArray[4*k], anArray[4*k+1] );
722 glVertex2d( anArray[4*k+2], anArray[4*k+3] );
726 std::cout << "Show function" << std::endl;
731 \param theDim - dimension
733 int GLViewer_LineField::getDimSize( FieldDim theDim )
737 else if( theDim == FD_Y )
744 \return array of intersected indexes
745 \param theDim - dimension
746 \param theIndex - index
747 \param theLL - line with that intersection is checked
748 \param theSize - to return value of array size
750 int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL, int& theSize )
753 if( !myXLineArray || !myYLineArray )
756 int aDimSize = getDimSize( theDim );
757 int* anArray = new int[aDimSize*2 ];
759 for( int i = 0; i < aDimSize; i++ )
761 GLViewer_LineList* aLL = getLine( i, theDim );
762 int index = aLL->contains( theLL->mainCoord() );
763 if( index != -1 && theLL->contains( aLL->mainCoord() ) == theIndex )
765 anArray[theSize*2] = i;
766 anArray[theSize*2+1] = index;
775 Sets start/end search point
776 \param thePoint - type of point (start: FP_Start; end: FP_End )
777 \param theX, theY - point co-ordinates
779 bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY )
781 if( !myXLineArray || !myYLineArray )
785 int xSeg = -1, ySeg = -1;
786 for( i = 0; i < myXSize; i++ )
788 GLViewer_LineList* aLL = getLine( i, FD_X );
789 if( aLL->mainCoord() == theY )
791 xSeg = aLL->contains( theX );
796 for( j = 0; j < myYSize; j++ )
798 GLViewer_LineList* aLL = getLine( j, FD_Y );
799 if( aLL->mainCoord() == theX )
801 ySeg = aLL->contains( theY );
806 if( xSeg != -1 && ySeg != -1 )
808 if( thePoint == FP_Start )
810 myStartPoint.myXLineIndex = i;
811 myStartPoint.myXSegmentIndex = xSeg;
812 myStartPoint.myYLineIndex = j;
813 myStartPoint.myYSegmentIndex = ySeg;
814 myStartPoint.mySolveIndex = -1;
818 myEndPoint.myXLineIndex = i;
819 myEndPoint.myXSegmentIndex = xSeg;
820 myEndPoint.myYLineIndex = j;
821 myEndPoint.myYSegmentIndex = ySeg;
822 myEndPoint.mySolveIndex = -1;
831 \return number of segments
833 int GLViewer_LineField::segmentNumber()
835 if( !(myXLineArray || myYLineArray) )
839 for( int aDim = 0; aDim < 2; aDim++ )
840 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
841 aNumber += getLine( i, (FieldDim)aDim )->count();
847 Removes all multiple segments
849 void GLViewer_LineField::optimize()
851 if( !myXLineArray || !myYLineArray )
854 for( int aDim = 0; aDim < 2; aDim++ )
856 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
858 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
859 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
861 // int index = i; unused
863 aLL->readSegment( k, a1, a2 );
864 for( int l = i+1, m = getDimSize( (FieldDim)aDim ); l < m; l++ )
867 GLViewer_LineList* aCurLL = getLine( l, (FieldDim)aDim );
868 for( int j = 0, count = aCurLL->count(); j < count; j++ )
871 aCurLL->readSegment( j, c1, c2 );
872 if( a1 == c1 && a2 == c2 )
874 if( !(aDim == 0 && myStartPoint.myXLineIndex == l && myStartPoint.myXSegmentIndex == j) &&
875 !(aDim == 0 && myEndPoint.myXLineIndex == l && myEndPoint.myXSegmentIndex == j) &&
876 !(aDim == 1 && myStartPoint.myYLineIndex == l && myStartPoint.myYSegmentIndex == j) &&
877 !(aDim == 1 && myEndPoint.myYLineIndex == l && myEndPoint.myYSegmentIndex == j) )
878 aCurLL->removeSegment( j );
888 if( end == -1 || end == 1)
898 Needs call setPoint before
900 void GLViewer_LineField::initialize()
902 if( !myXLineArray || !myYLineArray )
905 int size = segmentNumber();
910 myGraphArray1 = new GraphNode[size];
911 myGraphArray2 = new GraphNode[size];
916 for( int aDim = 0; aDim < 2; aDim++ )
918 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
920 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
921 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
923 myGraphArray1[index].myCount = size;
924 myGraphArray1[index].myDim = (FieldDim)aDim;
925 myGraphArray1[index].myLineIndex = i;
926 myGraphArray1[index].mySegmentindex = k;
927 myGraphArray1[index].prevNodeIndex = -1;
929 myGraphArray2[index].myCount = size;
930 myGraphArray2[index].myDim = (FieldDim)aDim;
931 myGraphArray2[index].myLineIndex = i;
932 myGraphArray2[index].mySegmentindex = k;
933 myGraphArray2[index].prevNodeIndex = -1;
935 if( !isXSet && aDim == FD_X && myStartPoint.myXLineIndex == i && myStartPoint.myXSegmentIndex == k )
937 myGraphArray1[index].myCount = 0;
941 if( aDim == FD_Y && !isYSet && myStartPoint.myYLineIndex == i && myStartPoint.myYSegmentIndex == k )
943 myGraphArray1[index].myCount = 0;
954 One iteration of algorithm
956 void GLViewer_LineField::iteration()
958 int aParam = myCurCount;
961 int* aNodes = findByCount( aParam );
962 GraphNode* aCurArray = getCurArray();
964 for( int i = 0; i < aParam; i++ )
966 GraphNode aCurNode = aCurArray[aNodes[i]];
968 int* aInterNodes = intersectIndexes( invertDim( aCurNode.myDim ), aCurNode.mySegmentindex,
969 getLine( aCurNode.myLineIndex, aCurNode.myDim ), aSize );
970 for( int j = 0; j < aSize; j++ )
972 int index = findBySegment( invertDim( aCurNode.myDim ), aInterNodes[2*j], aInterNodes[2*j+1], false );
974 if( aCurArray[index].myCount > myCurCount )
976 aCurArray[index].myCount = myCurCount;
977 aCurArray[index].prevNodeIndex = aNodes[i];
981 delete[] aInterNodes;
988 Checks for complete status
990 GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
992 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
996 GraphNode* aCurArray = getCurArray(),
997 * aSecArray = getSecArray();
999 for( int i = 0, n = segmentNumber(); i < n; i++ )
1001 if( aCurArray[i].myCount != aSecArray[i].myCount )
1003 if( aCurArray[i].myDim == FD_X &&
1004 aCurArray[i].myLineIndex == myEndPoint.myXLineIndex &&
1005 aCurArray[i].mySegmentindex == myEndPoint.myXSegmentIndex )
1007 std::cout << "Algorithm complete X!!!!!!!" << std::endl;
1008 myEndPoint.mySolveIndex = i;
1011 else if( aCurArray[i].myDim == FD_Y &&
1012 aCurArray[i].myLineIndex == myEndPoint.myYLineIndex &&
1013 aCurArray[i].mySegmentindex == myEndPoint.myYSegmentIndex )
1015 std::cout << "Algorithm complete Y!!!!!!!" << std::endl;
1016 myEndPoint.mySolveIndex = i;
1022 aSecArray[i].myCount = aCurArray[i].myCount;
1023 aSecArray[i].prevNodeIndex = aCurArray[i].prevNodeIndex;
1028 if( myCurArrayIndex == 0)
1029 myCurArrayIndex = 1;
1031 myCurArrayIndex = 0;
1033 std::cout << "Number of ways: " << count << std::endl;
1037 return IS_NOT_SOLVED;
1041 Finds LineList by counts and returns indexes
1043 int* GLViewer_LineField::findByCount( int& theParam )
1045 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1048 int count = segmentNumber();
1049 int* anArray = new int[count];
1052 GraphNode* aCurArray = getCurArray();
1053 for( int i = 0; i < count; i++ )
1055 GraphNode aCurNode = aCurArray[i];
1056 if( aCurNode.myCount == theParam )
1068 Finds LineList by segment and dimension
1070 int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int theSegment, bool inCurArray )
1072 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 || getDimSize( theDim ) <= theLineIndex )
1075 GraphNode* aCurArray;
1077 aCurArray = getCurArray();
1079 aCurArray = getSecArray();
1081 for( int i = 0, n = segmentNumber(); i < n; i++ )
1083 GraphNode aCurNode = aCurArray[i];
1084 if( aCurNode.myDim == theDim && aCurNode.myLineIndex == theLineIndex && aCurNode.mySegmentindex == theSegment )
1092 Main method, performs algorithm execution
1094 GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
1096 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1101 std::cout << "-----------Iteration #" << myCurCount << "-------------" << std::endl;
1104 IterationStatus is = checkComplete();
1105 if( is == IS_ERROR )
1107 else if( is == IS_LOOP )
1109 else if( is == IS_SOLVED )
1116 \return solution and size of solution
1118 double* GLViewer_LineField::solution( int& theSize )
1120 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1123 if( myEndPoint.mySolveIndex == -1 )
1126 theSize = myCurCount+1;
1127 double* anArray = new double[theSize*4];
1129 GraphNode* aCurArray = getCurArray();
1131 int index = myEndPoint.mySolveIndex;
1132 for( int i = 0; i <= myCurCount; i++ )
1137 GLViewer_LineList* aLL = getLine( aCurArray[index].myLineIndex, aCurArray[index].myDim );
1138 aLL->readSegment( aCurArray[index].mySegmentindex, c1, c2 );
1140 if( aCurArray[index].myDim == FD_X )
1143 anArray[i*4+1] = aLL->mainCoord();
1144 anArray[i*4+2] = c2;
1145 anArray[i*4+3] = aLL->mainCoord();
1149 anArray[i*4] = aLL->mainCoord();
1150 anArray[i*4+1] = c1;
1151 anArray[i*4+2] = aLL->mainCoord();
1152 anArray[i*4+3] = c2;
1155 index = aCurArray[index].prevNodeIndex;
1162 \return current solution array
1164 GraphNode* GLViewer_LineField::getCurArray()
1166 if( !myGraphArray1 || !myGraphArray2 )
1169 if( myCurArrayIndex == 0)
1170 return myGraphArray1;
1172 return myGraphArray2;
1176 \return other solution array
1178 GraphNode* GLViewer_LineField::getSecArray()
1180 if( !myGraphArray1 || !myGraphArray2 )
1183 if( myCurArrayIndex == 0)
1184 return myGraphArray2;
1186 return myGraphArray1;
1190 \return maximum segment number
1192 int GLViewer_LineField::maxSegmentNum()
1194 if( !myXLineArray || !myYLineArray )
1198 for( int aDim = 0; aDim < 2; aDim++ )
1200 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
1202 int count = getLine( i, (FieldDim)aDim )->count();
1203 if( count > max_num )
1212 \return list of LileList by dimension
1213 \param theDim - dimension
1215 GLViewer_LineList** GLViewer_LineField::getLLArray( FieldDim theDim )
1217 if( theDim == FD_X )
1218 return myXLineArray;
1219 else if( theDim == FD_Y )
1220 return myYLineArray;