Back to index

salome-gui  6.5.0
Public Member Functions | Private Attributes
GLViewer_LineList Class Reference

Tools for distinct line This class implmented interface for segment operations: add, cut, remove and etc. More...

#include <GLViewer_Tools.h>

List of all members.

Public Member Functions

 GLViewer_LineList (int)
 Constructor.
virtual ~GLViewer_LineList ()
 Destructor.
int count () const
 Returns number of segments.
int size () const
 Returns real size.
bool addSegment (double coord1, double coord2)
 Adds new line segment to list.
bool removeSegment (int index)
 Removes segment.
bool removeSegment (double coord1, double coord2)
 Removes segment from line list.
bool readSegment (int index, double &coord1, double &coord2)
 Gets info about segment.
int contains (double thePoint) const
 Returns index of segment, else -1.
void setMainCoord (double theVal)
 Sets level of segments.
double mainCoord () const
void clear ()
 Clears line list.
void print ()
 Prints debug info about line list.
void show (FieldDim)
 Draws line list with help of OpenGL.
GLViewer_LineListoperator= (GLViewer_LineList)

Private Attributes

double * myArray
int myRealSize
int mySegmentNumber
double myMainCoord

Detailed Description

Tools for distinct line This class implmented interface for segment operations: add, cut, remove and etc.

Memory does not changed and allocated only one time

Definition at line 63 of file GLViewer_Tools.h.


Constructor & Destructor Documentation

Constructor.

Parameters:
size- size of internal array

Definition at line 38 of file GLViewer_Tools.cxx.

{
  myRealSize = 2*size;
  mySegmentNumber = 0;
  myMainCoord = 0.0;

  myArray = new double[myRealSize];

  if( !myArray )
  {
    std::cout << "Can't allocate memory: " << size << std::endl;
    myRealSize = 0;
  }
  else
    memset( myArray, 0, myRealSize*sizeof(double) );
}

Here is the call graph for this function:

Destructor.

Definition at line 58 of file GLViewer_Tools.cxx.

{
  delete myArray;
}

Member Function Documentation

bool GLViewer_LineList::addSegment ( double  coord1,
double  coord2 
)

Adds new line segment to list.

Parameters:
coord1,coord2- co-ordinates of points

Definition at line 67 of file GLViewer_Tools.cxx.

{
  if( coord1 > coord2 )
  {
    double temp = coord1;
    coord1 = coord2;
    coord2 = temp;
  }

  if( 2*mySegmentNumber == myRealSize || !myArray )
    return false;

  int index = 0;
  double c1, c2;
  while( index < mySegmentNumber)
  {
    readSegment( index, c1, c2 );
    if( coord1 < c1 && coord2 < c1 )
    {
      for( int i = mySegmentNumber; i > index - 1; i--)
      {
        myArray[2*i] = myArray[2*i-2]; //2*(i-1)
        myArray[2*i+1] = myArray[2*i-1];//2*(i-1)+1
      }
      myArray[0] = coord1;
      myArray[1] = coord2;
      // mySegmentNumber; what is means ?
      return true;
    }
    else if( coord1 < c1 && coord2 < c2 )
    {
      myArray[index*2] = coord1;
      return true;
    }
    else if( c1 < coord1 && coord2 < c2 )
    {
      return true;
    }
    else if( coord1 < c2 && c2 < coord2 )
    {
      if( c1 > coord1 )
        myArray[2*index] = coord1;

      if( index != mySegmentNumber - 1 )
      {
        for( int i = index+1; i < mySegmentNumber; i++ )
        {
          if( coord2 < myArray[2*i] )
          {
            myArray[2*index+1] = coord2;
            if( index+1 != i )
            {
              for( int j = 0; i+j < mySegmentNumber;j++ )
              {
                myArray[2*(index+1+j)] = myArray[2*(i+j)];
                myArray[2*(index+1+j)+1] = myArray[2*(i+j)+1];
              }
              for( int k = 0; k < mySegmentNumber - i; k++ )
              {
                myArray[2*(mySegmentNumber - 1- k)] = 0.0;
                myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
              }
              mySegmentNumber -= i - index-1;
            }            
            return true;
          }
          else if( coord2 < myArray[2*i+1] )
          {
            myArray[2*index+1] = myArray[2*i+1];
            
            for( int j = index+1; j < mySegmentNumber-1;j++ )
            {
              myArray[2*j] = myArray[2*(i+j-index)];
              myArray[2*j+1] = myArray[2*(i+j-index)+1];
            }
            for( int k = 0; k < mySegmentNumber - i-1; k++ )
            {
              myArray[2*(mySegmentNumber - 1- k)] = 0.0;
              myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
            }
            mySegmentNumber -= i - index;
            return true;
          }
        }
      }
      else
      {
        myArray[2*index+1] = coord2;
        return true;
      }
    }    
    index++;
  }

  myArray[mySegmentNumber*2] = coord1;
  myArray[mySegmentNumber*2+1] = coord2;
  mySegmentNumber++;

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Clears line list.

Definition at line 380 of file GLViewer_Tools.cxx.

{
  if( myArray )
    memset( myArray, 0, myRealSize*sizeof(double) );
}

Here is the caller graph for this function:

int GLViewer_LineList::contains ( double  thePoint) const

Returns index of segment, else -1.

Returns:
true if line list covers point
Parameters:
thePoint- point co-ordinate

Definition at line 188 of file GLViewer_Tools.cxx.

{
  if( !myArray || mySegmentNumber == 0 )
    return -1;

  for( int i = 0; i < mySegmentNumber; i++ )
    if( myArray[2*i] <= thePoint && thePoint <= myArray[2*i+1] )
      return i;

  return -1;

}

Here is the caller graph for this function:

int GLViewer_LineList::count ( ) const [inline]

Returns number of segments.

Definition at line 70 of file GLViewer_Tools.h.

{ return mySegmentNumber; }

Here is the caller graph for this function:

double GLViewer_LineList::mainCoord ( ) const [inline]

Definition at line 85 of file GLViewer_Tools.h.

{ return myMainCoord; }

Here is the caller graph for this function:

GLViewer_LineList& GLViewer_LineList::operator= ( GLViewer_LineList  )

Prints debug info about line list.

Definition at line 389 of file GLViewer_Tools.cxx.

{
  std::cout << "MainCoord: " << myMainCoord <<" SIZE: " << myRealSize << " ENum: " << mySegmentNumber << " :::";
  for( int i = 0; i < mySegmentNumber; i++ )
    std::cout << "  " << myArray[2*i] << " " << myArray[2*i+1] << " | ";

  std::cout << std::endl;
}
bool GLViewer_LineList::readSegment ( int  theIndex,
double &  coord1,
double &  coord2 
)

Gets info about segment.

Parameters:
theIndex- index of segment
coord1,coord2- co-ordinates of points

Definition at line 173 of file GLViewer_Tools.cxx.

{
  if( theIndex > mySegmentNumber || !myArray)
    return false;

  coord1 = myArray[theIndex*2];
  coord2 = myArray[theIndex*2+1];

  return true;
}

Here is the caller graph for this function:

bool GLViewer_LineList::removeSegment ( int  theIndex)

Removes segment.

Parameters:
theIndex- segment index

Definition at line 205 of file GLViewer_Tools.cxx.

{
  if( theIndex > mySegmentNumber || !myArray)
    return false;

  for( int i = theIndex; i < mySegmentNumber; i++ )
  {
    myArray[i*2] = myArray[(i+1)*2];
    myArray[i*2+1] = myArray[(i+1)*2+1];
  }
  mySegmentNumber--;
  myArray[mySegmentNumber*2] = 0.0;
  myArray[mySegmentNumber*2+1] = 0.0;
  return true;
}

Here is the caller graph for this function:

bool GLViewer_LineList::removeSegment ( double  coord1,
double  coord2 
)

Removes segment from line list.

Parameters:
coord1,coord2- co-ordinates of points

Definition at line 225 of file GLViewer_Tools.cxx.

{
  if( coord1 > coord2 )
  {
    double temp = coord1;
    coord1 = coord2;
    coord2 = temp;
  }

  if( 2*mySegmentNumber == myRealSize || !myArray )
    return false;

  int index = 0;
  double c1, c2;
  while( index < mySegmentNumber)
  {
    readSegment( index, c1, c2 );
    if( coord1 < c1 && coord2 < c1 )
    {
      //nothing
      return true;
    }
    else if( coord1 < c1 && coord2 < c2 )
    {
      myArray[index*2] = coord2;
      return true;
    }
    else if( c1 < coord1 && coord2 < c2 )
    {
      if( 2*mySegmentNumber == myRealSize )
        return false;
      for( int i = mySegmentNumber; i > index + 1; i-- )
      {
        myArray[2*i] = myArray[2*(i-1)];
        myArray[2*i+1] = myArray[2*(i-1)+1];
      }
      myArray[2*(index+1)+1] = myArray[2*index+1];
      myArray[2*(index+1)] = coord2;
      myArray[2*index+1] = coord1;
      mySegmentNumber++;
      return true;
    }
    else if( coord1 < c2 && c2 < coord2 )
    {
      if( c1 < coord1 )
      {
        myArray[2*index+1] = coord1;
      }

      if( index != mySegmentNumber - 1 )
      {
        for( int i = index+1; i < mySegmentNumber; i++ )
        {
          if( coord2 < myArray[2*i] )
          {
            if( index+1 != i )
            {
              for( int j = 1; i+j-1 < mySegmentNumber;j++ )
              {
                myArray[2*(index+j)] = myArray[2*(i+j-1)];
                myArray[2*(index+j)+1] = myArray[2*(i+j-1)+1];
              }
              for( int k = 0; k < mySegmentNumber - i; k++ )
              {
                myArray[2*(mySegmentNumber - 1- k)] = 0.0;
                myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
              }
              mySegmentNumber -= i - index -1;
            }
            else
            {
              if( !(c1 < coord1) )
              {
                for( int j = 0; index + j + 1 < mySegmentNumber;j++ )
                {
                  myArray[2*(index+j)] = myArray[2*(index+j+1)];
                  myArray[2*(index+j)+1] = myArray[2*(index+j+1)+1];
                }
                  
                myArray[2*(mySegmentNumber - 1)] = 0.0;
                myArray[2*(mySegmentNumber - 1)+1] = 0.0;
                
                mySegmentNumber --;
              }

            }

            return true;

          }
          else if( coord2 < myArray[2*i+1] )
          {
            if( index+1 != i )
            {
              if( c1 < coord1 )
                index++;

              myArray[2*index] = coord2;
              myArray[2*index+1] = myArray[2*i+1];
            
              for( int j = 1; i+j < mySegmentNumber;j++ )
              {
                myArray[2*(index+j)] = myArray[2*(i+j)];
                myArray[2*(index+j)+1] = myArray[2*(i+j)+1];
              }
              for( int k = 0; k < mySegmentNumber - i - 1; k++ )
              {
                myArray[2*(mySegmentNumber - 1- k)] = 0.0;
                myArray[2*(mySegmentNumber - 1- k)+1] = 0.0;
              }
              mySegmentNumber -= i - index;
            }
            else
            {
              if( c1 < coord1 )
              {
                myArray[2*(index+1)] = coord2;
                return true;
              }
              else
              {
                myArray[2*(index)] = coord2;
                myArray[2*(index)+1] = myArray[2*(index+1)+1];
                for( int j = index+1; j < mySegmentNumber-1; j++ )
                {
                  myArray[2*j] = myArray[2*(j+1)];
                  myArray[2*j+1] = myArray[2*(j+1)+1];
                }
                mySegmentNumber--;
                myArray[2*mySegmentNumber] = 0.0;
                myArray[2*mySegmentNumber+1] = 0.0;
              }
            }
            return true;
          }
        }
      }
      else
      {
        if( !(c1 < coord1) )
        {
          mySegmentNumber--;
          myArray[2*index] = 0.0;
          myArray[2*index+1] = 0.0;
        }
      }
    }    
    index++;
  }
  return true;
}

Here is the call graph for this function:

void GLViewer_LineList::setMainCoord ( double  theVal) [inline]

Sets level of segments.

Definition at line 84 of file GLViewer_Tools.h.

{ myMainCoord = theVal; }

Here is the caller graph for this function:

Draws line list with help of OpenGL.

Parameters:
theDim- dimension

Definition at line 402 of file GLViewer_Tools.cxx.

{
  if( !myArray )
    return;

  glColor3f( 1.0, 0.0, 1.0 );
  if( theDim == FD_X )
  {
    glBegin( GL_LINES );
      for( int i = 0; i < mySegmentNumber; i++ )
      {
        glVertex2d( myArray[2*i], myMainCoord );
        glVertex2d( myArray[2*i+1], myMainCoord );
      }
    glEnd();
  }
  else if( theDim == FD_Y )
  {
    glBegin( GL_LINES );
      for( int i = 0; i < mySegmentNumber; i++ )
      {
        glVertex2d( myMainCoord, myArray[2*i]  );
        glVertex2d( myMainCoord, myArray[2*i+1] );
      }
    glEnd();
  }
}

Here is the caller graph for this function:

int GLViewer_LineList::size ( ) const [inline]

Returns real size.

Definition at line 72 of file GLViewer_Tools.h.

{ return myRealSize; }

Here is the caller graph for this function:


Member Data Documentation

double* GLViewer_LineList::myArray [private]

Definition at line 95 of file GLViewer_Tools.h.

Definition at line 99 of file GLViewer_Tools.h.

Definition at line 96 of file GLViewer_Tools.h.

Definition at line 97 of file GLViewer_Tools.h.


The documentation for this class was generated from the following files: