Salome HOME
Upgrade to paraview 5.4
[modules/gui.git] / src / GLViewer / GLViewer_Tools.cxx
index 5af5cd9bb1ff7ccf35c1f440a99f449a20d10af6..e1df5e0ead637df43db6ce64d4b4c56de5ec925b 100644 (file)
@@ -1,22 +1,44 @@
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  Author : OPEN CASCADE
 // File:      GLViewer_Tools.cxx
 // Created:   April, 2005
-// Author:    OCC team
-
-//#include "GLViewerAfx.h"
+//
 #include "GLViewer_Tools.h"
 
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#else
 #include <GL/gl.h>
+#endif
 
 #include <iostream>
+#include <string.h>
 
-using namespace std;
-
-/****************************************************************************
-**  Class:   GLViewer_LineList 
-**  Descr:   Tools for distinct line
-**  Module:  GLViewer
-**  Created: UI team, 27.10.05
-*****************************************************************************/
+/*!
+  Constructor
+  \param size - size of internal array
+*/
 GLViewer_LineList::GLViewer_LineList( int size )
 {
   myRealSize = 2*size;
@@ -27,18 +49,25 @@ GLViewer_LineList::GLViewer_LineList( int size )
 
   if( !myArray )
   {
-    cout << "Can't allocate memory: " << size << endl;
+    std::cout << "Can't allocate memory: " << size << std::endl;
     myRealSize = 0;
   }
   else
     memset( myArray, 0, myRealSize*sizeof(double) );
 }
 
+/*!
+  Destructor
+*/
 GLViewer_LineList::~GLViewer_LineList()
 {
   delete myArray;
 }
 
+/*!
+  Adds new line segment to list
+  \param coord1, coord2 - co-ordinates of points
+*/
 bool GLViewer_LineList::addSegment( double coord1, double coord2 )
 {
   if( coord1 > coord2 )
@@ -140,6 +169,11 @@ bool GLViewer_LineList::addSegment( double coord1, double coord2 )
   return true;
 }
 
+/*!
+  Gets info about segment
+  \param theIndex - index of segment
+  \param coord1, coord2 - co-ordinates of points
+*/
 bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord2 )
 {
   if( theIndex > mySegmentNumber || !myArray)
@@ -151,6 +185,10 @@ bool GLViewer_LineList::readSegment( int theIndex, double& coord1, double& coord
   return true;
 }
 
+/*!
+  \return true if line list covers point
+  \param thePoint - point co-ordinate
+*/
 int GLViewer_LineList::contains( double thePoint ) const
 {
   if( !myArray || mySegmentNumber == 0 )
@@ -164,6 +202,10 @@ int GLViewer_LineList::contains( double thePoint ) const
 
 }
 
+/*!
+  Removes segment
+  \param theIndex - segment index
+*/
 bool GLViewer_LineList::removeSegment( int theIndex )
 {
   if( theIndex > mySegmentNumber || !myArray)
@@ -180,6 +222,10 @@ bool GLViewer_LineList::removeSegment( int theIndex )
   return true;
 }
 
+/*!
+  Removes segment from line list
+  \param coord1, coord2 - co-ordinates of points
+*/
 bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
 {
   if( coord1 > coord2 )
@@ -332,21 +378,31 @@ bool GLViewer_LineList::removeSegment( double coord1, double coord2 )
   return true;
 }
 
+/*!
+  Clears line list
+*/
 void GLViewer_LineList::clear()
 {
   if( myArray )
     memset( myArray, 0, myRealSize*sizeof(double) );
 }
 
+/*!
+  Prints debug info about line list
+*/
 void GLViewer_LineList::print()
 {
-  cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
+  std::cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
   for( int i = 0; i < mySegmentNumber; i++ )
-    cout << "  " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
+    std::cout << "  " << myArray[2*i] << " " << myArray[2*i+1] << " | ";
 
-  cout << endl;
+  std::cout << std::endl;
 }
 
+/*!
+  Draws line list with help of OpenGL 
+  \param theDim - dimension
+*/
 void GLViewer_LineList::show( FieldDim theDim )
 {
   if( !myArray )
@@ -375,12 +431,10 @@ void GLViewer_LineList::show( FieldDim theDim )
   }
 }
 
-/****************************************************************************
-**  Class:   GLViewer_LineField 
-**  Descr:   Tools for solving 
-**  Module:  GLViewer
-**  Created: UI team, 27.10.05
-*****************************************************************************/
+
+/*!
+  Constructor
+*/
 GLViewer_LineField::GLViewer_LineField()
 {
   myCurArrayIndex = 0;
@@ -394,6 +448,10 @@ GLViewer_LineField::GLViewer_LineField()
   myXLineArray = NULL;
   myYLineArray = NULL;
 }
+
+/*!
+  Constructor
+*/
 GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, const int theYN )
 {
   myCurArrayIndex = 0;
@@ -425,6 +483,9 @@ GLViewer_LineField::GLViewer_LineField( const int theMAXSize, const int theXN, c
   }
 }
 
+/*!
+  Destructor
+*/
 GLViewer_LineField::~GLViewer_LineField()
 {
   if( myXLineArray )
@@ -450,11 +511,21 @@ GLViewer_LineField::~GLViewer_LineField()
     delete myGraphArray2;
 }
 
+/*!
+  Adds line
+*/
 void GLViewer_LineField::addLine( FieldDim theDim, GLViewer_LineList* )
 {
   //not implemented
 }
 
+/*!
+  Adds line
+  \param theDim - dimension
+  \param theMC - main co-ordinate
+  \param theBegin - start co-ordinate
+  \param theEnd - end co-ordinate
+*/
 void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegin, double theEnd )
 {
   GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
@@ -463,7 +534,12 @@ void GLViewer_LineField:: addLine( FieldDim theDim, double theMC, double theBegi
   addLine( theDim, aLL );
 }
 
-
+/*!
+  Adds line
+  \param theDim - dimension
+  \param theLL - main co-ordinate
+  \param thePosition - index in list
+*/
 int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, int thePosition )
 {
   if( !myXLineArray || !myYLineArray )
@@ -515,6 +591,14 @@ int GLViewer_LineField::insertLine( FieldDim theDim, GLViewer_LineList* theLL, i
   return -1;
 }
 
+/*!
+  Adds line
+  \param theDim - dimension
+  \param theMainCoord - main co-ordinate
+  \param theBegin - start co-ordinate
+  \param theEnd - end co-ordinate
+  \param thePosition - index in list
+*/
 int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double theBegin, double theEnd, int thePosition )
 {
   GLViewer_LineList* aLL = new GLViewer_LineList( 1 );
@@ -523,7 +607,9 @@ int GLViewer_LineField::insertLine( FieldDim theDim, double theMainCoord, double
   return insertLine( theDim, aLL, thePosition );
 }
 
-
+/*!
+  \return other dimension
+*/
 FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
 {
   if( theFD == FD_X )
@@ -532,6 +618,11 @@ FieldDim GLViewer_LineField::invertDim( FieldDim theFD )
     return FD_X;
 }
 
+/*!
+  \return line list
+  \param theIndex - index in list
+  \param tehFD - dimension
+*/
 GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
 {
   if( !myXLineArray || !myYLineArray )
@@ -555,6 +646,11 @@ GLViewer_LineList* GLViewer_LineField::getLine( int theIndex, FieldDim theFD )
   return NULL;
 }
 
+/*!
+  Sets borders of field
+  \param X1, X2 - minimal and maximal abscisses
+  \param Y1, Y2 - minimal and maximal ordinates
+*/
 void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2 )
 {
   if( !myXLineArray || !myYLineArray )
@@ -575,6 +671,11 @@ void GLViewer_LineField::setBorders( double X1, double X2, double Y1, double Y2
   }
 } 
 
+/*!
+  Adds rectangle
+  \param top, right - a corner of rectangle
+  \param bottom, left - other corner of rectangle
+*/
 void GLViewer_LineField::addRectangle( double top, double right, double bottom, double left )
 {
   if( !myXLineArray || !myYLineArray )
@@ -594,17 +695,23 @@ void GLViewer_LineField::addRectangle( double top, double right, double bottom,
   }
 }
 
+/*!
+  Prints debug info about line field
+*/
 void GLViewer_LineField::print()
 {
-  cout << "My X matrix Number: " << myXSize << endl;
+  std::cout << "My X matrix Number: " << myXSize << std::endl;
   for( int i = 0; i < myXSize; i++ )
     myXLineArray[i]->print();
 
-  cout << "My Y matrix Number: " << myYSize << endl;
+  std::cout << "My Y matrix Number: " << myYSize << std::endl;
   for( int j = 0; j < myYSize; j++ )
     myYLineArray[j]->print();
 }
 
+/*!
+  Draws field with help of OpenGL 
+*/
 void GLViewer_LineField::show()
 {
   for( int i = 0; i < myXSize; i++ )
@@ -623,9 +730,13 @@ void GLViewer_LineField::show()
   }
   glEnd();
   delete[] anArray;
-  cout << "Show function" << endl;
+  std::cout << "Show function" << std::endl;
 }
 
+/*!
+  \return size
+  \param theDim - dimension
+*/
 int GLViewer_LineField::getDimSize( FieldDim theDim )
 {
   if( theDim == FD_X )
@@ -636,6 +747,13 @@ int GLViewer_LineField::getDimSize( FieldDim theDim )
   return -1;
 }
 
+/*!
+  \return array of intersected indexes
+  \param theDim - dimension
+  \param theIndex - index
+  \param theLL - line with that intersection is checked
+  \param theSize - to return value of array size
+*/
 int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const GLViewer_LineList* theLL, int& theSize )
 {
   theSize = 0;
@@ -660,7 +778,11 @@ int* GLViewer_LineField::intersectIndexes( FieldDim theDim, int theIndex, const
   return anArray;
 }
 
-
+/*!
+  Sets start/end search point
+  \param thePoint - type of point (start: FP_Start; end: FP_End )
+  \param theX, theY - point co-ordinates
+*/
 bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY )
 {
   if( !myXLineArray || !myYLineArray )
@@ -712,6 +834,9 @@ bool GLViewer_LineField::setPoint( FieldPoint thePoint, double theX, double theY
     return false;
 }
 
+/*!
+  \return number of segments
+*/
 int GLViewer_LineField::segmentNumber()
 {
   if( !(myXLineArray || myYLineArray) )
@@ -725,6 +850,9 @@ int GLViewer_LineField::segmentNumber()
   return aNumber;
 }
 
+/*!
+  Removes all multiple segments
+*/
 void GLViewer_LineField::optimize()
 {
   if( !myXLineArray || !myYLineArray )
@@ -772,6 +900,10 @@ void GLViewer_LineField::optimize()
   }
 }
 
+/*!
+  Some prepare actions
+  Needs call setPoint before
+*/
 void GLViewer_LineField::initialize()
 {
   if( !myXLineArray || !myYLineArray )
@@ -825,6 +957,9 @@ void GLViewer_LineField::initialize()
   }
 }
 
+/*!
+  One iteration of algorithm
+*/
 void GLViewer_LineField::iteration()
 {
   int aParam = myCurCount;
@@ -856,6 +991,9 @@ void GLViewer_LineField::iteration()
   delete[] aNodes;
 }
 
+/*!
+  Checks for complete status
+*/
 GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
 {
   if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
@@ -873,7 +1011,7 @@ GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
           aCurArray[i].myLineIndex == myEndPoint.myXLineIndex && 
           aCurArray[i].mySegmentindex == myEndPoint.myXSegmentIndex )
       {
-        cout << "Algorithm complete X!!!!!!!" << endl;
+        std::cout << "Algorithm complete X!!!!!!!" << std::endl;
         myEndPoint.mySolveIndex = i;
         return IS_SOLVED;
       }
@@ -881,7 +1019,7 @@ GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
                aCurArray[i].myLineIndex == myEndPoint.myYLineIndex && 
                aCurArray[i].mySegmentindex == myEndPoint.myYSegmentIndex )
       {
-        cout << "Algorithm complete Y!!!!!!!" << endl;
+        std::cout << "Algorithm complete Y!!!!!!!" << std::endl;
         myEndPoint.mySolveIndex = i;  
         return IS_SOLVED;
       }
@@ -899,13 +1037,16 @@ GLViewer_LineField::IterationStatus GLViewer_LineField::checkComplete()
   else
     myCurArrayIndex = 0;
 
-  cout << "Number of ways: " << count << endl;
+  std::cout << "Number of ways: " << count << std::endl;
   if( count == 0 )
     return IS_LOOP;
 
   return IS_NOT_SOLVED;
 }
 
+/*!
+  Finds LineList by counts and returns indexes
+*/
 int* GLViewer_LineField::findByCount( int& theParam )
 {
   if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
@@ -930,6 +1071,9 @@ int* GLViewer_LineField::findByCount( int& theParam )
   return anArray;
 }
 
+/*!
+  Finds LineList by segment and dimension
+*/
 int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int theSegment, bool inCurArray )
 {
   if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 || getDimSize( theDim ) <= theLineIndex )
@@ -951,6 +1095,9 @@ int GLViewer_LineField::findBySegment( FieldDim theDim, int theLineIndex, int th
   return -1;
 }
 
+/*!
+  Main method, performs algorithm execution
+*/
 GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
 {
   if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
@@ -958,7 +1105,7 @@ GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
 
   while( true )
   {
-    cout << "-----------Iteration #" << myCurCount << "-------------" << endl;
+    std::cout << "-----------Iteration #" << myCurCount << "-------------" << std::endl;
     iteration();
 
     IterationStatus is = checkComplete();
@@ -972,6 +1119,9 @@ GLViewer_LineField::EndStatus GLViewer_LineField::startAlgorithm()
   return ES_SOLVED;
 }
 
+/*!
+  \return solution and size of solution
+*/
 double* GLViewer_LineField::solution( int& theSize )
 {
   if( !myXLineArray || !myYLineArray || !myGraphArray1 || !myGraphArray2 )
@@ -1015,6 +1165,9 @@ double* GLViewer_LineField::solution( int& theSize )
   return anArray;
 }
 
+/*!
+  \return current solution array
+*/
 GraphNode* GLViewer_LineField::getCurArray()
 {
   if( !myGraphArray1 || !myGraphArray2 )
@@ -1026,6 +1179,9 @@ GraphNode* GLViewer_LineField::getCurArray()
     return myGraphArray2;
 }
 
+/*!
+  \return other solution array
+*/
 GraphNode* GLViewer_LineField::getSecArray()
 {
   if( !myGraphArray1 || !myGraphArray2 )
@@ -1037,6 +1193,9 @@ GraphNode* GLViewer_LineField::getSecArray()
     return myGraphArray1;
 }
 
+/*!
+  \return maximum segment number
+*/
 int GLViewer_LineField::maxSegmentNum()
 {
   if( !myXLineArray || !myYLineArray )
@@ -1056,6 +1215,10 @@ int GLViewer_LineField::maxSegmentNum()
   return max_num;
 }
 
+/*!
+  \return list of LileList by dimension
+  \param theDim - dimension
+*/
 GLViewer_LineList** GLViewer_LineField::getLLArray( FieldDim theDim )
 {
   if( theDim == FD_X )