1 // Copyright (C) 2007-2014 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_Geom.h
25 // Created: November, 2004
27 #ifndef GLVIEWER_GEOM_H
28 #define GLVIEWER_GEOM_H
37 #pragma warning( disable:4251 )
40 /*! Struct GLViewer_Pnt
41 * Substitution of QPoint for OpenGL
44 struct GLVIEWER_API GLViewer_Pnt
47 GLViewer_Pnt() : myX( 0. ), myY( 0. ) {};
48 GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
50 GLfloat x() const { return myX; }
51 GLfloat y() const { return myY; }
52 void setX( GLfloat theX ) { myX = theX; }
53 void setY( GLfloat theY ) { myY = theY; }
54 void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
55 void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
62 typedef QList<GLViewer_Pnt> GLViewer_PntList;
64 /*! Class GLViewer_Rect
65 * Substitution of QRect for OpenGL
68 class GLVIEWER_API GLViewer_Rect
71 GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
72 GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
73 : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
74 GLViewer_Rect( QRect theRect ) {
75 myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
76 myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
78 float left() const { return myLeft; }
79 float right() const { return myRight; }
80 float top() const { return myTop; }
81 float bottom() const { return myBottom; }
83 float width() const { return fabs( myRight - myLeft ); }
84 float height() const { return fabs( myTop - myBottom ); }
86 void setLeft( float theLeft ) { myLeft = theLeft; }
87 void setRight( float theRight ) { myRight = theRight; }
88 void setTop( float theTop ) { myTop = theTop; }
89 void setBottom( float theBottom ) { myBottom = theBottom; }
91 void setCoords( float theLeft, float theRight, float theBottom, float theTop )
92 { myLeft = theLeft; myRight = theRight; myBottom = theBottom; myTop = theTop; }
94 //! \warning This method translate only rect format
95 QRect toQRect() { return QRect( ( int )myLeft, ( int )myBottom,
96 ( int )( myRight - myLeft ),
97 ( int )( myTop - myBottom ) ); }
99 //! On/off empty status
100 void setIsEmpty( bool on ) { myIsEmpty = on; }
101 //! Checks empty status
102 bool isEmpty() const { return myIsEmpty; }
104 //! Checks null status
105 bool isNull() const { return myLeft == 0.0 && myRight == 0.0 && myBottom == 0.0 && myTop == 0.0; }
106 //! Checks valid status
107 bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); }
109 //! Checks staus of contains point
110 bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
112 pnt.y() > bottom() &&
115 void move( const float x, const float y )
132 /*! Class GLViewer_Segment
133 * Segment for 2d detection
136 class GLVIEWER_API GLViewer_Segment
139 GLViewer_Segment( const GLViewer_Pnt& thePnt1,
140 const GLViewer_Pnt& thePnt2 );
142 //! Ordinary segment construction
143 /*!Construction of a ray with given equation Ax + By + C = 0 */
145 GLViewer_Segment( const GLViewer_Pnt& thePnt,
148 const GLfloat theC );
151 bool HasIntersection( const GLViewer_Segment& theOther ) const;
152 // Detects intersection with another segment or ray
162 /*! Class GLViewer_Poly
163 * Polygon for 2d detection
166 class GLVIEWER_API GLViewer_Poly
169 GLViewer_Poly( const GLViewer_PntList* thePoints );
170 virtual ~GLViewer_Poly();
172 //! Adds point to polygon
173 void AddPoint( GLViewer_Pnt& pnt ) { myPoints->append( pnt ); }
175 //! Returns number of point
176 int Count() const { return myPoints->count(); }
178 //! Returns true if a point lies inside this polygon
179 virtual bool IsIn( const GLViewer_Pnt& thePnt ) const;
181 //! Returns true if a other polygon covers this polygon
182 virtual bool IsCovers( const GLViewer_Poly& thePoly ) const;
184 //! Likes the above function
185 virtual bool IsCovers( const GLViewer_Rect& theRect ) const;
187 // Returns true if intersection of this polygon with a segment or a ray not empty
188 virtual bool HasIntersection( const GLViewer_Segment& theSegment ) const;
191 GLViewer_PntList* myPoints;
195 #pragma warning ( default:4251 )