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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_Tools.cxx
23 // Created: April, 2005
25 //#include "GLViewerAfx.h"
26 #include "GLViewer_Tools.h"
34 \param size - size of internal array
36 GLViewer_LineList::GLViewer_LineList( int size )
42 myArray = new double[myRealSize];
46 cout << "Can't allocate memory: " << size << endl;
50 memset( myArray, 0, myRealSize*sizeof(double) );
56 GLViewer_LineList::~GLViewer_LineList()
62 Adds new line segment to list
63 \param coord1, coord2 - co-ordinates of points
65 bool GLViewer_LineList::addSegment( double coord1, double coord2 )
74 if( 2*mySegmentNumber == myRealSize || !myArray )
79 while( index < mySegmentNumber)
81 readSegment( index, c1, c2 );
82 if( coord1 < c1 && coord2 < c1 )
84 for( int i = mySegmentNumber; i > index - 1; i--)
86 myArray[2*i] = myArray[2*i-2]; //2*(i-1)
87 myArray[2*i+1] = myArray[2*i-1];//2*(i-1)+1
91 // mySegmentNumber; what is means ?
94 else if( coord1 < c1 && coord2 < c2 )
96 myArray[index*2] = coord1;
99 else if( c1 < coord1 && coord2 < c2 )
103 else if( coord1 < c2 && c2 < coord2 )
106 myArray[2*index] = coord1;
108 if( index != mySegmentNumber - 1 )
110 for( int i = index+1; i < mySegmentNumber; i++ )
112 if( coord2 < myArray[2*i] )
114 myArray[2*index+1] = coord2;
117 for( int j = 0; i+j < mySegmentNumber;j++ )
119 myArray[2*(index+1+j)] = myArray[2*(i+j)];
120 myArray[2*(index+1+j)+1] = myArray[2*(i+j)+1];
122 for( int k = 0; k < mySegmentNumber - i; k++ )
124 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
125 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
127 mySegmentNumber -= i - index-1;
131 else if( coord2 < myArray[2*i+1] )
133 myArray[2*index+1] = myArray[2*i+1];
135 for( int j = index+1; j < mySegmentNumber-1;j++ )
137 myArray[2*j] = myArray[2*(i+j-index)];
138 myArray[2*j+1] = myArray[2*(i+j-index)+1];
140 for( int k = 0; k < mySegmentNumber - i-1; k++ )
142 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
143 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
145 mySegmentNumber -= i - index;
152 myArray[2*index+1] = coord2;
159 myArray[mySegmentNumber*2] = coord1;
160 myArray[mySegmentNumber*2+1] = coord2;
167 Gets info about segment
168 \param theIndex - index of segment
169 \param coord1, coord2 - co-ordinates of points
171 bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord2 )
173 if( theIndex > mySegmentNumber || !myArray)
176 coord1 = myArray[theIndex*2];
177 coord2 = myArray[theIndex*2+1];
183 \return true if line list covers point
184 \param thePoint - point co-ordinate
186 int GLViewer_LineList::contains( double thePoint ) const
188 if( !myArray || mySegmentNumber == 0 )
191 for( int i = 0; i < mySegmentNumber; i++ )
192 if( myArray[2*i] <= thePoint && thePoint <= myArray[2*i+1] )
201 \param theIndex - segment index
203 bool GLViewer_LineList::removeSegment( int theIndex )
205 if( theIndex > mySegmentNumber || !myArray)
208 for( int i = theIndex; i < mySegmentNumber; i++ )
210 myArray[i*2] = myArray[(i+1)*2];
211 myArray[i*2+1] = myArray[(i+1)*2+1];
214 myArray[mySegmentNumber*2] = 0.0;
215 myArray[mySegmentNumber*2+1] = 0.0;
220 Removes segment from line list
221 \param coord1, coord2 - co-ordinates of points
223 bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
225 if( coord1 > coord2 )
227 double temp = coord1;
232 if( 2*mySegmentNumber == myRealSize || !myArray )
237 while( index < mySegmentNumber)
239 readSegment( index, c1, c2 );
240 if( coord1 < c1 && coord2 < c1 )
245 else if( coord1 < c1 && coord2 < c2 )
247 myArray[index*2] = coord2;
250 else if( c1 < coord1 && coord2 < c2 )
252 if( 2*mySegmentNumber == myRealSize )
254 for( int i = mySegmentNumber; i > index + 1; i-- )
256 myArray[2*i] = myArray[2*(i-1)];
257 myArray[2*i+1] = myArray[2*(i-1)+1];
259 myArray[2*(index+1)+1] = myArray[2*index+1];
260 myArray[2*(index+1)] = coord2;
261 myArray[2*index+1] = coord1;
265 else if( coord1 < c2 && c2 < coord2 )
269 myArray[2*index+1] = coord1;
272 if( index != mySegmentNumber - 1 )
274 for( int i = index+1; i < mySegmentNumber; i++ )
276 if( coord2 < myArray[2*i] )
280 for( int j = 1; i+j-1 < mySegmentNumber;j++ )
282 myArray[2*(index+j)] = myArray[2*(i+j-1)];
283 myArray[2*(index+j)+1] = myArray[2*(i+j-1)+1];
285 for( int k = 0; k < mySegmentNumber - i; k++ )
287 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
288 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
290 mySegmentNumber -= i - index -1;
296 for( int j = 0; index + j + 1 < mySegmentNumber;j++ )
298 myArray[2*(index+j)] = myArray[2*(index+j+1)];
299 myArray[2*(index+j)+1] = myArray[2*(index+j+1)+1];
302 myArray[2*(mySegmentNumber - 1)] = 0.0;
303 myArray[2*(mySegmentNumber - 1)+1] = 0.0;
313 else if( coord2 < myArray[2*i+1] )
320 myArray[2*index] = coord2;
321 myArray[2*index+1] = myArray[2*i+1];
323 for( int j = 1; i+j < mySegmentNumber;j++ )
325 myArray[2*(index+j)] = myArray[2*(i+j)];
326 myArray[2*(index+j)+1] = myArray[2*(i+j)+1];
328 for( int k = 0; k < mySegmentNumber - i - 1; k++ )
330 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
331 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
333 mySegmentNumber -= i - index;
339 myArray[2*(index+1)] = coord2;
344 myArray[2*(index)] = coord2;
345 myArray[2*(index)+1] = myArray[2*(index+1)+1];
346 for( int j = index+1; j < mySegmentNumber-1; j++ )
348 myArray[2*j] = myArray[2*(j+1)];
349 myArray[2*j+1] = myArray[2*(j+1)+1];
352 myArray[2*mySegmentNumber] = 0.0;
353 myArray[2*mySegmentNumber+1] = 0.0;
365 myArray[2*index] = 0.0;
366 myArray[2*index+1] = 0.0;
378 void GLViewer_LineList::clear()
381 memset( myArray, 0, myRealSize*sizeof(double) );
385 Prints debug info about line list
387 void GLViewer_LineList::print()
389 cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
390 for( int i = 0; i < mySegmentNumber; i++ )
391 cout << " " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
397 Draws line list with help of OpenGL
398 \param theDim - dimension
400 void GLViewer_LineList::show( FieldDim theDim )
405 glColor3f( 1.0, 0.0, 1.0 );
409 for( int i = 0; i < mySegmentNumber; i++ )
411 glVertex2d( myArray[2*i], myMainCoord );
412 glVertex2d( myArray[2*i+1], myMainCoord );
416 else if( theDim == FD_Y )
419 for( int i = 0; i < mySegmentNumber; i++ )
421 glVertex2d( myMainCoord, myArray[2*i] );
422 glVertex2d( myMainCoord, myArray[2*i+1] );
432 GLViewer_LineField::GLViewer_LineField()
435 myGraphArray1 = NULL;
436 myGraphArray2 = NULL;
449 GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, const int theYN )
452 myGraphArray1 = NULL;
453 myGraphArray2 = NULL;
457 if( theXN <= 0 || theYN <= 0 )
466 myXLineArray = new GLViewer_LineList*[theXN];
467 myYLineArray = new GLViewer_LineList*[theYN];
469 for( int i = 0; i < theXN; i++ )
470 myXLineArray[i] = new GLViewer_LineList( theMAXSize );
472 for( int j = 0; j < theYN; j++ )
473 myYLineArray[j] = new GLViewer_LineList( theMAXSize );
483 GLViewer_LineField::~GLViewer_LineField()
487 for( int i = 0; i < myXSize; i++ )
488 delete myXLineArray[i];
495 for( int j = 0; j < myYSize; j++ )
496 delete myYLineArray[j];
502 delete myGraphArray1;
505 delete myGraphArray2;
511 void GLViewer_LineField::addLine( FieldDim theDim, GLViewer_LineList* )
518 \param theDim - dimension
519 \param theMC - main co-ordinate
520 \param theBegin - start co-ordinate
521 \param theEnd - end co-ordinate
523 void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegin, double theEnd )
525 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
526 aLL->addSegment( theBegin, theEnd );
527 aLL->setMainCoord( theMC );
528 addLine( theDim, aLL );
533 \param theDim - dimension
534 \param theLL - main co-ordinate
535 \param thePosition - index in list
537 int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, int thePosition )
539 if( !myXLineArray || !myYLineArray )
542 GLViewer_LineList** anArray = getLLArray( theDim );
546 int size = getDimSize( theDim );
548 if( thePosition >= size )
550 else if( thePosition < 0 )
552 if( anArray[size-1]->count() != 0 ) // no more space
555 for( int i = 0; i < size; i++ )
557 if( anArray[i]->count() == 0 )
564 double cur_mc = anArray[i]->mainCoord();
565 if( theLL->mainCoord() < cur_mc )
567 for( int j = 0; j+i+1 < size; j++ )
569 delete anArray[size-j-1];
570 anArray[size-j-1] = anArray[size-j-2];
580 delete anArray[thePosition];
581 anArray[thePosition] = theLL;
590 \param theDim - dimension
591 \param theMainCoord - main co-ordinate
592 \param theBegin - start co-ordinate
593 \param theEnd - end co-ordinate
594 \param thePosition - index in list
596 int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double theBegin, double theEnd, int thePosition )
598 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
599 aLL->addSegment( theBegin, theEnd );
600 aLL->setMainCoord( theMainCoord );
601 return insertLine( theDim, aLL, thePosition );
605 \return other dimension
607 FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
617 \param theIndex - index in list
618 \param tehFD - dimension
620 GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
622 if( !myXLineArray || !myYLineArray )
627 if( theIndex > myXSize )
630 return myXLineArray[theIndex];
632 else if( theFD == FD_Y )
634 if( theIndex > myYSize )
637 return myYLineArray[theIndex];
644 Sets borders of field
645 \param X1, X2 - minimal and maximal abscisses
646 \param Y1, Y2 - minimal and maximal ordinates
648 void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2 )
650 if( !myXLineArray || !myYLineArray )
653 for( int i = 0; i < myXSize; i++ )
655 myXLineArray[i]->clear();
656 myXLineArray[i]->addSegment( X1, X2 );
657 myXLineArray[i]->setMainCoord( Y1 + (Y2-Y1)*(double(i)/(myXSize-1)) );
660 for( int j = 0; j < myYSize; j++ )
662 myYLineArray[j]->clear();
663 myYLineArray[j]->addSegment( Y1, Y2 );
664 myYLineArray[j]->setMainCoord( X1 + (X2-X1)*(double(j)/(myYSize-1)) );
670 \param top, right - a corner of rectangle
671 \param bottom, left - other corner of rectangle
673 void GLViewer_LineField::addRectangle( double top, double right, double bottom, double left )
675 if( !myXLineArray || !myYLineArray )
677 for( int i = 0; i < myXSize; i++ )
679 double mainCoord = myXLineArray[i]->mainCoord();
680 if( mainCoord < top && mainCoord > bottom )
681 myXLineArray[i]->removeSegment( left, right );
684 for( int j = 0; j < myYSize; j++ )
686 double mainCoord = myYLineArray[j]->mainCoord();
687 if( mainCoord < right && mainCoord > left )
688 myYLineArray[j]->removeSegment( bottom, top );
693 Prints debug info about line field
695 void GLViewer_LineField::print()
697 cout << "My X matrix Number: " << myXSize << endl;
698 for( int i = 0; i < myXSize; i++ )
699 myXLineArray[i]->print();
701 cout << "My Y matrix Number: " << myYSize << endl;
702 for( int j = 0; j < myYSize; j++ )
703 myYLineArray[j]->print();
707 Draws field with help of OpenGL
709 void GLViewer_LineField::show()
711 for( int i = 0; i < myXSize; i++ )
712 getLine( i, FD_X )->show( FD_X );
714 for( int j = 0; j < myYSize; j++ )
715 getLine( j, FD_Y )->show( FD_Y );
717 double* anArray = solution( count );
718 glColor3f( 1.0, 0.0, 0.0 );
720 for( int k = 0; k < count; k++ )
722 glVertex2d( anArray[4*k], anArray[4*k+1] );
723 glVertex2d( anArray[4*k+2], anArray[4*k+3] );
727 cout << "Show function" << endl;
732 \param theDim - dimension
734 int GLViewer_LineField::getDimSize( FieldDim theDim )
738 else if( theDim == FD_Y )
745 \return array of intersected indexes
746 \param theDim - dimension
747 \param theIndex - index
748 \param theLL - line with that intersection is checked
749 \param theSize - to return value of array size
751 int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL, int& theSize )
754 if( !myXLineArray || !myYLineArray )
757 int aDimSize = getDimSize( theDim );
758 int* anArray = new int[aDimSize*2 ];
760 for( int i = 0; i < aDimSize; i++ )
762 GLViewer_LineList* aLL = getLine( i, theDim );
763 int index = aLL->contains( theLL->mainCoord() );
764 if( index != -1 && theLL->contains( aLL->mainCoord() ) == theIndex )
766 anArray[theSize*2] = i;
767 anArray[theSize*2+1] = index;
776 Sets start/end search point
777 \param thePoint - type of point (start: FP_Start; end: FP_End )
778 \param theX, theY - point co-ordinates
780 bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY )
782 if( !myXLineArray || !myYLineArray )
786 int xSeg = -1, ySeg = -1;
787 for( i = 0; i < myXSize; i++ )
789 GLViewer_LineList* aLL = getLine( i, FD_X );
790 if( aLL->mainCoord() == theY )
792 xSeg = aLL->contains( theX );
797 for( j = 0; j < myYSize; j++ )
799 GLViewer_LineList* aLL = getLine( j, FD_Y );
800 if( aLL->mainCoord() == theX )
802 ySeg = aLL->contains( theY );
807 if( xSeg != -1 && ySeg != -1 )
809 if( thePoint == FP_Start )
811 myStartPoint.myXLineIndex = i;
812 myStartPoint.myXSegmentIndex = xSeg;
813 myStartPoint.myYLineIndex = j;
814 myStartPoint.myYSegmentIndex = ySeg;
815 myStartPoint.mySolveIndex = -1;
819 myEndPoint.myXLineIndex = i;
820 myEndPoint.myXSegmentIndex = xSeg;
821 myEndPoint.myYLineIndex = j;
822 myEndPoint.myYSegmentIndex = ySeg;
823 myEndPoint.mySolveIndex = -1;
832 \return number of segments
834 int GLViewer_LineField::segmentNumber()
836 if( !(myXLineArray || myYLineArray) )
840 for( int aDim = 0; aDim < 2; aDim++ )
841 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
842 aNumber += getLine( i, (FieldDim)aDim )->count();
848 Removes all multiple segments
850 void GLViewer_LineField::optimize()
852 if( !myXLineArray || !myYLineArray )
855 for( int aDim = 0; aDim < 2; aDim++ )
857 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
859 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
860 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
862 // int index = i; unused
864 aLL->readSegment( k, a1, a2 );
865 for( int l = i+1, m = getDimSize( (FieldDim)aDim ); l < m; l++ )
868 GLViewer_LineList* aCurLL = getLine( l, (FieldDim)aDim );
869 for( int j = 0, count = aCurLL->count(); j < count; j++ )
872 aCurLL->readSegment( j, c1, c2 );
873 if( a1 == c1 && a2 == c2 )
875 if( !(aDim == 0 && myStartPoint.myXLineIndex == l && myStartPoint.myXSegmentIndex == j) &&
876 !(aDim == 0 && myEndPoint.myXLineIndex == l && myEndPoint.myXSegmentIndex == j) &&
877 !(aDim == 1 && myStartPoint.myYLineIndex == l && myStartPoint.myYSegmentIndex == j) &&
878 !(aDim == 1 && myEndPoint.myYLineIndex == l && myEndPoint.myYSegmentIndex == j) )
879 aCurLL->removeSegment( j );
889 if( end == -1 || end == 1)
899 Needs call setPoint before
901 void GLViewer_LineField::initialize()
903 if( !myXLineArray || !myYLineArray )
906 int size = segmentNumber();
911 myGraphArray1 = new GraphNode[size];
912 myGraphArray2 = new GraphNode[size];
917 for( int aDim = 0; aDim < 2; aDim++ )
919 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
921 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
922 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
924 myGraphArray1[index].myCount = size;
925 myGraphArray1[index].myDim = (FieldDim)aDim;
926 myGraphArray1[index].myLineIndex = i;
927 myGraphArray1[index].mySegmentindex = k;
928 myGraphArray1[index].prevNodeIndex = -1;
930 myGraphArray2[index].myCount = size;
931 myGraphArray2[index].myDim = (FieldDim)aDim;
932 myGraphArray2[index].myLineIndex = i;
933 myGraphArray2[index].mySegmentindex = k;
934 myGraphArray2[index].prevNodeIndex = -1;
936 if( !isXSet && aDim == FD_X && myStartPoint.myXLineIndex == i && myStartPoint.myXSegmentIndex == k )
938 myGraphArray1[index].myCount = 0;
942 if( aDim == FD_Y && !isYSet && myStartPoint.myYLineIndex == i && myStartPoint.myYSegmentIndex == k )
944 myGraphArray1[index].myCount = 0;
955 One iteration of algorithm
957 void GLViewer_LineField::iteration()
959 int aParam = myCurCount;
962 int* aNodes = findByCount( aParam );
963 GraphNode* aCurArray = getCurArray();
965 for( int i = 0; i < aParam; i++ )
967 GraphNode aCurNode = aCurArray[aNodes[i]];
969 int* aInterNodes = intersectIndexes( invertDim( aCurNode.myDim ), aCurNode.mySegmentindex,
970 getLine( aCurNode.myLineIndex, aCurNode.myDim ), aSize );
971 for( int j = 0; j < aSize; j++ )
973 int index = findBySegment( invertDim( aCurNode.myDim ), aInterNodes[2*j], aInterNodes[2*j+1], false );
975 if( aCurArray[index].myCount > myCurCount )
977 aCurArray[index].myCount = myCurCount;
978 aCurArray[index].prevNodeIndex = aNodes[i];
982 delete[] aInterNodes;
989 Checks for complete status
991 GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
993 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
997 GraphNode* aCurArray = getCurArray(),
998 * aSecArray = getSecArray();
1000 for( int i = 0, n = segmentNumber(); i < n; i++ )
1002 if( aCurArray[i].myCount != aSecArray[i].myCount )
1004 if( aCurArray[i].myDim == FD_X &&
1005 aCurArray[i].myLineIndex == myEndPoint.myXLineIndex &&
1006 aCurArray[i].mySegmentindex == myEndPoint.myXSegmentIndex )
1008 cout << "Algorithm complete X!!!!!!!" << endl;
1009 myEndPoint.mySolveIndex = i;
1012 else if( aCurArray[i].myDim == FD_Y &&
1013 aCurArray[i].myLineIndex == myEndPoint.myYLineIndex &&
1014 aCurArray[i].mySegmentindex == myEndPoint.myYSegmentIndex )
1016 cout << "Algorithm complete Y!!!!!!!" << endl;
1017 myEndPoint.mySolveIndex = i;
1023 aSecArray[i].myCount = aCurArray[i].myCount;
1024 aSecArray[i].prevNodeIndex = aCurArray[i].prevNodeIndex;
1029 if( myCurArrayIndex == 0)
1030 myCurArrayIndex = 1;
1032 myCurArrayIndex = 0;
1034 cout << "Number of ways: " << count << endl;
1038 return IS_NOT_SOLVED;
1042 Finds LineList by counts and returns indexes
1044 int* GLViewer_LineField::findByCount( int& theParam )
1046 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1049 int count = segmentNumber();
1050 int* anArray = new int[count];
1053 GraphNode* aCurArray = getCurArray();
1054 for( int i = 0; i < count; i++ )
1056 GraphNode aCurNode = aCurArray[i];
1057 if( aCurNode.myCount == theParam )
1069 Finds LineList by segment and dimension
1071 int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int theSegment, bool inCurArray )
1073 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 || getDimSize( theDim ) <= theLineIndex )
1076 GraphNode* aCurArray;
1078 aCurArray = getCurArray();
1080 aCurArray = getSecArray();
1082 for( int i = 0, n = segmentNumber(); i < n; i++ )
1084 GraphNode aCurNode = aCurArray[i];
1085 if( aCurNode.myDim == theDim && aCurNode.myLineIndex == theLineIndex && aCurNode.mySegmentindex == theSegment )
1093 Main method, performs algorithm execution
1095 GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
1097 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1102 cout << "-----------Iteration #" << myCurCount << "-------------" << endl;
1105 IterationStatus is = checkComplete();
1106 if( is == IS_ERROR )
1108 else if( is == IS_LOOP )
1110 else if( is == IS_SOLVED )
1117 \return solution and size of solution
1119 double* GLViewer_LineField::solution( int& theSize )
1121 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1124 if( myEndPoint.mySolveIndex == -1 )
1127 theSize = myCurCount+1;
1128 double* anArray = new double[theSize*4];
1130 GraphNode* aCurArray = getCurArray();
1132 int index = myEndPoint.mySolveIndex;
1133 for( int i = 0; i <= myCurCount; i++ )
1138 GLViewer_LineList* aLL = getLine( aCurArray[index].myLineIndex, aCurArray[index].myDim );
1139 aLL->readSegment( aCurArray[index].mySegmentindex, c1, c2 );
1141 if( aCurArray[index].myDim == FD_X )
1144 anArray[i*4+1] = aLL->mainCoord();
1145 anArray[i*4+2] = c2;
1146 anArray[i*4+3] = aLL->mainCoord();
1150 anArray[i*4] = aLL->mainCoord();
1151 anArray[i*4+1] = c1;
1152 anArray[i*4+2] = aLL->mainCoord();
1153 anArray[i*4+3] = c2;
1156 index = aCurArray[index].prevNodeIndex;
1163 \return current solution array
1165 GraphNode* GLViewer_LineField::getCurArray()
1167 if( !myGraphArray1 || !myGraphArray2 )
1170 if( myCurArrayIndex == 0)
1171 return myGraphArray1;
1173 return myGraphArray2;
1177 \return other solution array
1179 GraphNode* GLViewer_LineField::getSecArray()
1181 if( !myGraphArray1 || !myGraphArray2 )
1184 if( myCurArrayIndex == 0)
1185 return myGraphArray2;
1187 return myGraphArray1;
1191 \return maximum segment number
1193 int GLViewer_LineField::maxSegmentNum()
1195 if( !myXLineArray || !myYLineArray )
1199 for( int aDim = 0; aDim < 2; aDim++ )
1201 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
1203 int count = getLine( i, (FieldDim)aDim )->count();
1204 if( count > max_num )
1213 \return list of LileList by dimension
1214 \param theDim - dimension
1216 GLViewer_LineList** GLViewer_LineField::getLLArray( FieldDim theDim )
1218 if( theDim == FD_X )
1219 return myXLineArray;
1220 else if( theDim == FD_Y )
1221 return myYLineArray;