Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GLViewer_Geom.h
Go to the documentation of this file.
1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 
23 // Author : OPEN CASCADE
24 // File: GLViewer_Geom.h
25 // Created: November, 2004
26 //
27 #ifndef GLVIEWER_GEOM_H
28 #define GLVIEWER_GEOM_H
29 
30 #include "GLViewer.h"
31 
32 #include <QRect>
33 #include <QtOpenGL>
34 #include <math.h>
35 
36 #ifdef WIN32
37 #pragma warning( disable:4251 )
38 #endif
39 
45 {
46 public:
47  GLViewer_Pnt() : myX( 0. ), myY( 0. ) {};
48  GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
49 
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; }
56 
57 private:
58  GLfloat myX;
59  GLfloat myY;
60 };
61 
63 
69 {
70 public:
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(); }
77 
78  float left() const { return myLeft; }
79  float right() const { return myRight; }
80  float top() const { return myTop; }
81  float bottom() const { return myBottom; }
82 
83  float width() const { return fabs( myRight - myLeft ); }
84  float height() const { return fabs( myTop - myBottom ); }
85 
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; }
90 
91  void setCoords( float theLeft, float theRight, float theBottom, float theTop )
92  { myLeft = theLeft; myRight = theRight; myBottom = theBottom; myTop = theTop; }
93 
95  QRect toQRect() { return QRect( ( int )myLeft, ( int )myBottom,
96  ( int )( myRight - myLeft ),
97  ( int )( myTop - myBottom ) ); }
98 
100  void setIsEmpty( bool on ) { myIsEmpty = on; }
102  bool isEmpty() const { return myIsEmpty; }
103 
105  bool isNull() const { return myLeft == 0.0 && myRight == 0.0 && myBottom == 0.0 && myTop == 0.0; }
107  bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); }
108 
110  bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
111  pnt.x() < right() &&
112  pnt.y() > bottom() &&
113  pnt.y() < top() ); }
114 
115  void move( const float x, const float y )
116  {
117  myLeft += x;
118  myRight += x;
119  myTop += y;
120  myBottom += y;
121  }
122 
123 protected:
124  float myLeft;
125  float myRight;
126  float myTop;
127  float myBottom;
128 
129  bool myIsEmpty;
130 };
131 
137 {
138 public:
139  GLViewer_Segment( const GLViewer_Pnt& thePnt1,
140  const GLViewer_Pnt& thePnt2 );
141 
143 
145  GLViewer_Segment( const GLViewer_Pnt& thePnt,
146  const GLfloat theA,
147  const GLfloat theB,
148  const GLfloat theC );
149  ~GLViewer_Segment();
150 
151  bool HasIntersection( const GLViewer_Segment& theOther ) const;
152  // Detects intersection with another segment or ray
153 
154 private:
157  GLfloat myA;
158  GLfloat myB;
159  GLfloat myC;
160 };
161 
167 {
168 public:
169  GLViewer_Poly( const GLViewer_PntList* thePoints );
170  virtual ~GLViewer_Poly();
171 
173  void AddPoint( GLViewer_Pnt& pnt ) { myPoints->append( pnt ); }
174 
176  int Count() const { return myPoints->count(); }
177 
179  virtual bool IsIn( const GLViewer_Pnt& thePnt ) const;
180 
182  virtual bool IsCovers( const GLViewer_Poly& thePoly ) const;
183 
185  virtual bool IsCovers( const GLViewer_Rect& theRect ) const;
186 
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;
189 
190 private:
192 };
193 
194 #ifdef WIN32
195 #pragma warning ( default:4251 )
196 #endif
197 
198 #endif