1 // Copyright (C) 2007-2016 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"
36 \param size - size of internal array
38 GLViewer_LineList::GLViewer_LineList( int size )
44 myArray = new double[myRealSize];
48 std::cout << "Can't allocate memory: " << size << std::endl;
52 memset( myArray, 0, myRealSize*sizeof(double) );
58 GLViewer_LineList::~GLViewer_LineList()
64 Adds new line segment to list
65 \param coord1, coord2 - co-ordinates of points
67 bool GLViewer_LineList::addSegment( double coord1, double coord2 )
76 if( 2*mySegmentNumber == myRealSize || !myArray )
81 while( index < mySegmentNumber)
83 readSegment( index, c1, c2 );
84 if( coord1 < c1 && coord2 < c1 )
86 for( int i = mySegmentNumber; i > index - 1; i--)
88 myArray[2*i] = myArray[2*i-2]; //2*(i-1)
89 myArray[2*i+1] = myArray[2*i-1];//2*(i-1)+1
93 // mySegmentNumber; what is means ?
96 else if( coord1 < c1 && coord2 < c2 )
98 myArray[index*2] = coord1;
101 else if( c1 < coord1 && coord2 < c2 )
105 else if( coord1 < c2 && c2 < coord2 )
108 myArray[2*index] = coord1;
110 if( index != mySegmentNumber - 1 )
112 for( int i = index+1; i < mySegmentNumber; i++ )
114 if( coord2 < myArray[2*i] )
116 myArray[2*index+1] = coord2;
119 for( int j = 0; i+j < mySegmentNumber;j++ )
121 myArray[2*(index+1+j)] = myArray[2*(i+j)];
122 myArray[2*(index+1+j)+1] = myArray[2*(i+j)+1];
124 for( int k = 0; k < mySegmentNumber - i; k++ )
126 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
127 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
129 mySegmentNumber -= i - index-1;
133 else if( coord2 < myArray[2*i+1] )
135 myArray[2*index+1] = myArray[2*i+1];
137 for( int j = index+1; j < mySegmentNumber-1;j++ )
139 myArray[2*j] = myArray[2*(i+j-index)];
140 myArray[2*j+1] = myArray[2*(i+j-index)+1];
142 for( int k = 0; k < mySegmentNumber - i-1; k++ )
144 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
145 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
147 mySegmentNumber -= i - index;
154 myArray[2*index+1] = coord2;
161 myArray[mySegmentNumber*2] = coord1;
162 myArray[mySegmentNumber*2+1] = coord2;
169 Gets info about segment
170 \param theIndex - index of segment
171 \param coord1, coord2 - co-ordinates of points
173 bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord2 )
175 if( theIndex > mySegmentNumber || !myArray)
178 coord1 = myArray[theIndex*2];
179 coord2 = myArray[theIndex*2+1];
185 \return true if line list covers point
186 \param thePoint - point co-ordinate
188 int GLViewer_LineList::contains( double thePoint ) const
190 if( !myArray || mySegmentNumber == 0 )
193 for( int i = 0; i < mySegmentNumber; i++ )
194 if( myArray[2*i] <= thePoint && thePoint <= myArray[2*i+1] )
203 \param theIndex - segment index
205 bool GLViewer_LineList::removeSegment( int theIndex )
207 if( theIndex > mySegmentNumber || !myArray)
210 for( int i = theIndex; i < mySegmentNumber; i++ )
212 myArray[i*2] = myArray[(i+1)*2];
213 myArray[i*2+1] = myArray[(i+1)*2+1];
216 myArray[mySegmentNumber*2] = 0.0;
217 myArray[mySegmentNumber*2+1] = 0.0;
222 Removes segment from line list
223 \param coord1, coord2 - co-ordinates of points
225 bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
227 if( coord1 > coord2 )
229 double temp = coord1;
234 if( 2*mySegmentNumber == myRealSize || !myArray )
239 while( index < mySegmentNumber)
241 readSegment( index, c1, c2 );
242 if( coord1 < c1 && coord2 < c1 )
247 else if( coord1 < c1 && coord2 < c2 )
249 myArray[index*2] = coord2;
252 else if( c1 < coord1 && coord2 < c2 )
254 if( 2*mySegmentNumber == myRealSize )
256 for( int i = mySegmentNumber; i > index + 1; i-- )
258 myArray[2*i] = myArray[2*(i-1)];
259 myArray[2*i+1] = myArray[2*(i-1)+1];
261 myArray[2*(index+1)+1] = myArray[2*index+1];
262 myArray[2*(index+1)] = coord2;
263 myArray[2*index+1] = coord1;
267 else if( coord1 < c2 && c2 < coord2 )
271 myArray[2*index+1] = coord1;
274 if( index != mySegmentNumber - 1 )
276 for( int i = index+1; i < mySegmentNumber; i++ )
278 if( coord2 < myArray[2*i] )
282 for( int j = 1; i+j-1 < mySegmentNumber;j++ )
284 myArray[2*(index+j)] = myArray[2*(i+j-1)];
285 myArray[2*(index+j)+1] = myArray[2*(i+j-1)+1];
287 for( int k = 0; k < mySegmentNumber - i; k++ )
289 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
290 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
292 mySegmentNumber -= i - index -1;
298 for( int j = 0; index + j + 1 < mySegmentNumber;j++ )
300 myArray[2*(index+j)] = myArray[2*(index+j+1)];
301 myArray[2*(index+j)+1] = myArray[2*(index+j+1)+1];
304 myArray[2*(mySegmentNumber - 1)] = 0.0;
305 myArray[2*(mySegmentNumber - 1)+1] = 0.0;
315 else if( coord2 < myArray[2*i+1] )
322 myArray[2*index] = coord2;
323 myArray[2*index+1] = myArray[2*i+1];
325 for( int j = 1; i+j < mySegmentNumber;j++ )
327 myArray[2*(index+j)] = myArray[2*(i+j)];
328 myArray[2*(index+j)+1] = myArray[2*(i+j)+1];
330 for( int k = 0; k < mySegmentNumber - i - 1; k++ )
332 myArray[2*(mySegmentNumber - 1- k)] = 0.0;
333 myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
335 mySegmentNumber -= i - index;
341 myArray[2*(index+1)] = coord2;
346 myArray[2*(index)] = coord2;
347 myArray[2*(index)+1] = myArray[2*(index+1)+1];
348 for( int j = index+1; j < mySegmentNumber-1; j++ )
350 myArray[2*j] = myArray[2*(j+1)];
351 myArray[2*j+1] = myArray[2*(j+1)+1];
354 myArray[2*mySegmentNumber] = 0.0;
355 myArray[2*mySegmentNumber+1] = 0.0;
367 myArray[2*index] = 0.0;
368 myArray[2*index+1] = 0.0;
380 void GLViewer_LineList::clear()
383 memset( myArray, 0, myRealSize*sizeof(double) );
387 Prints debug info about line list
389 void GLViewer_LineList::print()
391 std::cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
392 for( int i = 0; i < mySegmentNumber; i++ )
393 std::cout << " " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
395 std::cout << std::endl;
399 Draws line list with help of OpenGL
400 \param theDim - dimension
402 void GLViewer_LineList::show( FieldDim theDim )
407 glColor3f( 1.0, 0.0, 1.0 );
411 for( int i = 0; i < mySegmentNumber; i++ )
413 glVertex2d( myArray[2*i], myMainCoord );
414 glVertex2d( myArray[2*i+1], myMainCoord );
418 else if( theDim == FD_Y )
421 for( int i = 0; i < mySegmentNumber; i++ )
423 glVertex2d( myMainCoord, myArray[2*i] );
424 glVertex2d( myMainCoord, myArray[2*i+1] );
434 GLViewer_LineField::GLViewer_LineField()
437 myGraphArray1 = NULL;
438 myGraphArray2 = NULL;
451 GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, const int theYN )
454 myGraphArray1 = NULL;
455 myGraphArray2 = NULL;
459 if( theXN <= 0 || theYN <= 0 )
468 myXLineArray = new GLViewer_LineList*[theXN];
469 myYLineArray = new GLViewer_LineList*[theYN];
471 for( int i = 0; i < theXN; i++ )
472 myXLineArray[i] = new GLViewer_LineList( theMAXSize );
474 for( int j = 0; j < theYN; j++ )
475 myYLineArray[j] = new GLViewer_LineList( theMAXSize );
485 GLViewer_LineField::~GLViewer_LineField()
489 for( int i = 0; i < myXSize; i++ )
490 delete myXLineArray[i];
497 for( int j = 0; j < myYSize; j++ )
498 delete myYLineArray[j];
504 delete myGraphArray1;
507 delete myGraphArray2;
513 void GLViewer_LineField::addLine( FieldDim theDim, GLViewer_LineList* )
520 \param theDim - dimension
521 \param theMC - main co-ordinate
522 \param theBegin - start co-ordinate
523 \param theEnd - end co-ordinate
525 void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegin, double theEnd )
527 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
528 aLL->addSegment( theBegin, theEnd );
529 aLL->setMainCoord( theMC );
530 addLine( theDim, aLL );
535 \param theDim - dimension
536 \param theLL - main co-ordinate
537 \param thePosition - index in list
539 int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, int thePosition )
541 if( !myXLineArray || !myYLineArray )
544 GLViewer_LineList** anArray = getLLArray( theDim );
548 int size = getDimSize( theDim );
550 if( thePosition >= size )
552 else if( thePosition < 0 )
554 if( anArray[size-1]->count() != 0 ) // no more space
557 for( int i = 0; i < size; i++ )
559 if( anArray[i]->count() == 0 )
566 double cur_mc = anArray[i]->mainCoord();
567 if( theLL->mainCoord() < cur_mc )
569 for( int j = 0; j+i+1 < size; j++ )
571 delete anArray[size-j-1];
572 anArray[size-j-1] = anArray[size-j-2];
582 delete anArray[thePosition];
583 anArray[thePosition] = theLL;
592 \param theDim - dimension
593 \param theMainCoord - main co-ordinate
594 \param theBegin - start co-ordinate
595 \param theEnd - end co-ordinate
596 \param thePosition - index in list
598 int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double theBegin, double theEnd, int thePosition )
600 GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
601 aLL->addSegment( theBegin, theEnd );
602 aLL->setMainCoord( theMainCoord );
603 return insertLine( theDim, aLL, thePosition );
607 \return other dimension
609 FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
619 \param theIndex - index in list
620 \param tehFD - dimension
622 GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
624 if( !myXLineArray || !myYLineArray )
629 if( theIndex > myXSize )
632 return myXLineArray[theIndex];
634 else if( theFD == FD_Y )
636 if( theIndex > myYSize )
639 return myYLineArray[theIndex];
646 Sets borders of field
647 \param X1, X2 - minimal and maximal abscisses
648 \param Y1, Y2 - minimal and maximal ordinates
650 void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2 )
652 if( !myXLineArray || !myYLineArray )
655 for( int i = 0; i < myXSize; i++ )
657 myXLineArray[i]->clear();
658 myXLineArray[i]->addSegment( X1, X2 );
659 myXLineArray[i]->setMainCoord( Y1 + (Y2-Y1)*(double(i)/(myXSize-1)) );
662 for( int j = 0; j < myYSize; j++ )
664 myYLineArray[j]->clear();
665 myYLineArray[j]->addSegment( Y1, Y2 );
666 myYLineArray[j]->setMainCoord( X1 + (X2-X1)*(double(j)/(myYSize-1)) );
672 \param top, right - a corner of rectangle
673 \param bottom, left - other corner of rectangle
675 void GLViewer_LineField::addRectangle( double top, double right, double bottom, double left )
677 if( !myXLineArray || !myYLineArray )
679 for( int i = 0; i < myXSize; i++ )
681 double mainCoord = myXLineArray[i]->mainCoord();
682 if( mainCoord < top && mainCoord > bottom )
683 myXLineArray[i]->removeSegment( left, right );
686 for( int j = 0; j < myYSize; j++ )
688 double mainCoord = myYLineArray[j]->mainCoord();
689 if( mainCoord < right && mainCoord > left )
690 myYLineArray[j]->removeSegment( bottom, top );
695 Prints debug info about line field
697 void GLViewer_LineField::print()
699 std::cout << "My X matrix Number: " << myXSize << std::endl;
700 for( int i = 0; i < myXSize; i++ )
701 myXLineArray[i]->print();
703 std::cout << "My Y matrix Number: " << myYSize << std::endl;
704 for( int j = 0; j < myYSize; j++ )
705 myYLineArray[j]->print();
709 Draws field with help of OpenGL
711 void GLViewer_LineField::show()
713 for( int i = 0; i < myXSize; i++ )
714 getLine( i, FD_X )->show( FD_X );
716 for( int j = 0; j < myYSize; j++ )
717 getLine( j, FD_Y )->show( FD_Y );
719 double* anArray = solution( count );
720 glColor3f( 1.0, 0.0, 0.0 );
722 for( int k = 0; k < count; k++ )
724 glVertex2d( anArray[4*k], anArray[4*k+1] );
725 glVertex2d( anArray[4*k+2], anArray[4*k+3] );
729 std::cout << "Show function" << std::endl;
734 \param theDim - dimension
736 int GLViewer_LineField::getDimSize( FieldDim theDim )
740 else if( theDim == FD_Y )
747 \return array of intersected indexes
748 \param theDim - dimension
749 \param theIndex - index
750 \param theLL - line with that intersection is checked
751 \param theSize - to return value of array size
753 int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL, int& theSize )
756 if( !myXLineArray || !myYLineArray )
759 int aDimSize = getDimSize( theDim );
760 int* anArray = new int[aDimSize*2 ];
762 for( int i = 0; i < aDimSize; i++ )
764 GLViewer_LineList* aLL = getLine( i, theDim );
765 int index = aLL->contains( theLL->mainCoord() );
766 if( index != -1 && theLL->contains( aLL->mainCoord() ) == theIndex )
768 anArray[theSize*2] = i;
769 anArray[theSize*2+1] = index;
778 Sets start/end search point
779 \param thePoint - type of point (start: FP_Start; end: FP_End )
780 \param theX, theY - point co-ordinates
782 bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY )
784 if( !myXLineArray || !myYLineArray )
788 int xSeg = -1, ySeg = -1;
789 for( i = 0; i < myXSize; i++ )
791 GLViewer_LineList* aLL = getLine( i, FD_X );
792 if( aLL->mainCoord() == theY )
794 xSeg = aLL->contains( theX );
799 for( j = 0; j < myYSize; j++ )
801 GLViewer_LineList* aLL = getLine( j, FD_Y );
802 if( aLL->mainCoord() == theX )
804 ySeg = aLL->contains( theY );
809 if( xSeg != -1 && ySeg != -1 )
811 if( thePoint == FP_Start )
813 myStartPoint.myXLineIndex = i;
814 myStartPoint.myXSegmentIndex = xSeg;
815 myStartPoint.myYLineIndex = j;
816 myStartPoint.myYSegmentIndex = ySeg;
817 myStartPoint.mySolveIndex = -1;
821 myEndPoint.myXLineIndex = i;
822 myEndPoint.myXSegmentIndex = xSeg;
823 myEndPoint.myYLineIndex = j;
824 myEndPoint.myYSegmentIndex = ySeg;
825 myEndPoint.mySolveIndex = -1;
834 \return number of segments
836 int GLViewer_LineField::segmentNumber()
838 if( !(myXLineArray || myYLineArray) )
842 for( int aDim = 0; aDim < 2; aDim++ )
843 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
844 aNumber += getLine( i, (FieldDim)aDim )->count();
850 Removes all multiple segments
852 void GLViewer_LineField::optimize()
854 if( !myXLineArray || !myYLineArray )
857 for( int aDim = 0; aDim < 2; aDim++ )
859 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
861 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
862 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
864 // int index = i; unused
866 aLL->readSegment( k, a1, a2 );
867 for( int l = i+1, m = getDimSize( (FieldDim)aDim ); l < m; l++ )
870 GLViewer_LineList* aCurLL = getLine( l, (FieldDim)aDim );
871 for( int j = 0, count = aCurLL->count(); j < count; j++ )
874 aCurLL->readSegment( j, c1, c2 );
875 if( a1 == c1 && a2 == c2 )
877 if( !(aDim == 0 && myStartPoint.myXLineIndex == l && myStartPoint.myXSegmentIndex == j) &&
878 !(aDim == 0 && myEndPoint.myXLineIndex == l && myEndPoint.myXSegmentIndex == j) &&
879 !(aDim == 1 && myStartPoint.myYLineIndex == l && myStartPoint.myYSegmentIndex == j) &&
880 !(aDim == 1 && myEndPoint.myYLineIndex == l && myEndPoint.myYSegmentIndex == j) )
881 aCurLL->removeSegment( j );
891 if( end == -1 || end == 1)
901 Needs call setPoint before
903 void GLViewer_LineField::initialize()
905 if( !myXLineArray || !myYLineArray )
908 int size = segmentNumber();
913 myGraphArray1 = new GraphNode[size];
914 myGraphArray2 = new GraphNode[size];
919 for( int aDim = 0; aDim < 2; aDim++ )
921 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
923 GLViewer_LineList* aLL = getLine( i, (FieldDim)aDim );
924 for( int k =0, aSegNum = aLL->count(); k < aSegNum; k++ )
926 myGraphArray1[index].myCount = size;
927 myGraphArray1[index].myDim = (FieldDim)aDim;
928 myGraphArray1[index].myLineIndex = i;
929 myGraphArray1[index].mySegmentindex = k;
930 myGraphArray1[index].prevNodeIndex = -1;
932 myGraphArray2[index].myCount = size;
933 myGraphArray2[index].myDim = (FieldDim)aDim;
934 myGraphArray2[index].myLineIndex = i;
935 myGraphArray2[index].mySegmentindex = k;
936 myGraphArray2[index].prevNodeIndex = -1;
938 if( !isXSet && aDim == FD_X && myStartPoint.myXLineIndex == i && myStartPoint.myXSegmentIndex == k )
940 myGraphArray1[index].myCount = 0;
944 if( aDim == FD_Y && !isYSet && myStartPoint.myYLineIndex == i && myStartPoint.myYSegmentIndex == k )
946 myGraphArray1[index].myCount = 0;
957 One iteration of algorithm
959 void GLViewer_LineField::iteration()
961 int aParam = myCurCount;
964 int* aNodes = findByCount( aParam );
965 GraphNode* aCurArray = getCurArray();
967 for( int i = 0; i < aParam; i++ )
969 GraphNode aCurNode = aCurArray[aNodes[i]];
971 int* aInterNodes = intersectIndexes( invertDim( aCurNode.myDim ), aCurNode.mySegmentindex,
972 getLine( aCurNode.myLineIndex, aCurNode.myDim ), aSize );
973 for( int j = 0; j < aSize; j++ )
975 int index = findBySegment( invertDim( aCurNode.myDim ), aInterNodes[2*j], aInterNodes[2*j+1], false );
977 if( aCurArray[index].myCount > myCurCount )
979 aCurArray[index].myCount = myCurCount;
980 aCurArray[index].prevNodeIndex = aNodes[i];
984 delete[] aInterNodes;
991 Checks for complete status
993 GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
995 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
999 GraphNode* aCurArray = getCurArray(),
1000 * aSecArray = getSecArray();
1002 for( int i = 0, n = segmentNumber(); i < n; i++ )
1004 if( aCurArray[i].myCount != aSecArray[i].myCount )
1006 if( aCurArray[i].myDim == FD_X &&
1007 aCurArray[i].myLineIndex == myEndPoint.myXLineIndex &&
1008 aCurArray[i].mySegmentindex == myEndPoint.myXSegmentIndex )
1010 std::cout << "Algorithm complete X!!!!!!!" << std::endl;
1011 myEndPoint.mySolveIndex = i;
1014 else if( aCurArray[i].myDim == FD_Y &&
1015 aCurArray[i].myLineIndex == myEndPoint.myYLineIndex &&
1016 aCurArray[i].mySegmentindex == myEndPoint.myYSegmentIndex )
1018 std::cout << "Algorithm complete Y!!!!!!!" << std::endl;
1019 myEndPoint.mySolveIndex = i;
1025 aSecArray[i].myCount = aCurArray[i].myCount;
1026 aSecArray[i].prevNodeIndex = aCurArray[i].prevNodeIndex;
1031 if( myCurArrayIndex == 0)
1032 myCurArrayIndex = 1;
1034 myCurArrayIndex = 0;
1036 std::cout << "Number of ways: " << count << std::endl;
1040 return IS_NOT_SOLVED;
1044 Finds LineList by counts and returns indexes
1046 int* GLViewer_LineField::findByCount( int& theParam )
1048 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1051 int count = segmentNumber();
1052 int* anArray = new int[count];
1055 GraphNode* aCurArray = getCurArray();
1056 for( int i = 0; i < count; i++ )
1058 GraphNode aCurNode = aCurArray[i];
1059 if( aCurNode.myCount == theParam )
1071 Finds LineList by segment and dimension
1073 int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int theSegment, bool inCurArray )
1075 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 || getDimSize( theDim ) <= theLineIndex )
1078 GraphNode* aCurArray;
1080 aCurArray = getCurArray();
1082 aCurArray = getSecArray();
1084 for( int i = 0, n = segmentNumber(); i < n; i++ )
1086 GraphNode aCurNode = aCurArray[i];
1087 if( aCurNode.myDim == theDim && aCurNode.myLineIndex == theLineIndex && aCurNode.mySegmentindex == theSegment )
1095 Main method, performs algorithm execution
1097 GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
1099 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1104 std::cout << "-----------Iteration #" << myCurCount << "-------------" << std::endl;
1107 IterationStatus is = checkComplete();
1108 if( is == IS_ERROR )
1110 else if( is == IS_LOOP )
1112 else if( is == IS_SOLVED )
1119 \return solution and size of solution
1121 double* GLViewer_LineField::solution( int& theSize )
1123 if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
1126 if( myEndPoint.mySolveIndex == -1 )
1129 theSize = myCurCount+1;
1130 double* anArray = new double[theSize*4];
1132 GraphNode* aCurArray = getCurArray();
1134 int index = myEndPoint.mySolveIndex;
1135 for( int i = 0; i <= myCurCount; i++ )
1140 GLViewer_LineList* aLL = getLine( aCurArray[index].myLineIndex, aCurArray[index].myDim );
1141 aLL->readSegment( aCurArray[index].mySegmentindex, c1, c2 );
1143 if( aCurArray[index].myDim == FD_X )
1146 anArray[i*4+1] = aLL->mainCoord();
1147 anArray[i*4+2] = c2;
1148 anArray[i*4+3] = aLL->mainCoord();
1152 anArray[i*4] = aLL->mainCoord();
1153 anArray[i*4+1] = c1;
1154 anArray[i*4+2] = aLL->mainCoord();
1155 anArray[i*4+3] = c2;
1158 index = aCurArray[index].prevNodeIndex;
1165 \return current solution array
1167 GraphNode* GLViewer_LineField::getCurArray()
1169 if( !myGraphArray1 || !myGraphArray2 )
1172 if( myCurArrayIndex == 0)
1173 return myGraphArray1;
1175 return myGraphArray2;
1179 \return other solution array
1181 GraphNode* GLViewer_LineField::getSecArray()
1183 if( !myGraphArray1 || !myGraphArray2 )
1186 if( myCurArrayIndex == 0)
1187 return myGraphArray2;
1189 return myGraphArray1;
1193 \return maximum segment number
1195 int GLViewer_LineField::maxSegmentNum()
1197 if( !myXLineArray || !myYLineArray )
1201 for( int aDim = 0; aDim < 2; aDim++ )
1203 for( int i = 0, n = getDimSize( (FieldDim)aDim ); i < n; i++ )
1205 int count = getLine( i, (FieldDim)aDim )->count();
1206 if( count > max_num )
1215 \return list of LileList by dimension
1216 \param theDim - dimension
1218 GLViewer_LineList** GLViewer_LineField::getLLArray( FieldDim theDim )
1220 if( theDim == FD_X )
1221 return myXLineArray;
1222 else if( theDim == FD_Y )
1223 return myYLineArray;