Version: 9.16.0
GLViewer_Geom.h
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, 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 <cmath>
35
36#ifdef WIN32
37#pragma warning( disable:4251 )
38#endif
39
45{
46public:
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
57private:
58 GLfloat myX;
59 GLfloat myY;
60};
61
63
69{
70public:
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
123protected:
124 float myLeft;
125 float myRight;
126 float myTop;
127 float myBottom;
128
130};
131
137{
138public:
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 );
150
151 bool HasIntersection( const GLViewer_Segment& theOther ) const;
152 // Detects intersection with another segment or ray
153
154private:
157 GLfloat myA;
158 GLfloat myB;
159 GLfloat myC;
160};
161
167{
168public:
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
190private:
192};
193
194#ifdef WIN32
195#pragma warning ( default:4251 )
196#endif
197
198#endif
#define GLVIEWER_API
Macro for exports.
Definition: GLViewer.h:37
QList< GLViewer_Pnt > GLViewer_PntList
Definition: GLViewer_Geom.h:62
Definition: GLViewer_Geom.h:167
int Count() const
Returns number of point.
Definition: GLViewer_Geom.h:176
void AddPoint(GLViewer_Pnt &pnt)
Adds point to polygon.
Definition: GLViewer_Geom.h:173
GLViewer_PntList * myPoints
Definition: GLViewer_Geom.h:191
Definition: GLViewer_Geom.h:69
bool isNull() const
Checks null status.
Definition: GLViewer_Geom.h:105
GLViewer_Rect()
Definition: GLViewer_Geom.h:71
void move(const float x, const float y)
Definition: GLViewer_Geom.h:115
float myLeft
Definition: GLViewer_Geom.h:124
void setTop(float theTop)
Definition: GLViewer_Geom.h:88
float myTop
Definition: GLViewer_Geom.h:126
GLViewer_Rect(QRect theRect)
Definition: GLViewer_Geom.h:74
void setLeft(float theLeft)
Definition: GLViewer_Geom.h:86
float top() const
Definition: GLViewer_Geom.h:80
float height() const
Definition: GLViewer_Geom.h:84
float myRight
Definition: GLViewer_Geom.h:125
float width() const
Definition: GLViewer_Geom.h:83
GLViewer_Rect(float theLeft, float theRight, float theTop, float theBottom)
Definition: GLViewer_Geom.h:72
float right() const
Definition: GLViewer_Geom.h:79
bool isEmpty() const
Checks empty status.
Definition: GLViewer_Geom.h:102
bool myIsEmpty
Definition: GLViewer_Geom.h:129
bool contains(GLViewer_Pnt pnt)
Checks staus of contains point.
Definition: GLViewer_Geom.h:110
float bottom() const
Definition: GLViewer_Geom.h:81
void setBottom(float theBottom)
Definition: GLViewer_Geom.h:89
void setCoords(float theLeft, float theRight, float theBottom, float theTop)
Definition: GLViewer_Geom.h:91
float left() const
Definition: GLViewer_Geom.h:78
QRect toQRect()
Definition: GLViewer_Geom.h:95
float myBottom
Definition: GLViewer_Geom.h:127
bool isValid() const
Checks valid status.
Definition: GLViewer_Geom.h:107
void setIsEmpty(bool on)
On/off empty status.
Definition: GLViewer_Geom.h:100
void setRight(float theRight)
Definition: GLViewer_Geom.h:87
Definition: GLViewer_Geom.h:137
GLViewer_Pnt myPnt2
Definition: GLViewer_Geom.h:156
GLViewer_Pnt myPnt1
Definition: GLViewer_Geom.h:155
GLfloat myB
Definition: GLViewer_Geom.h:158
GLfloat myC
Definition: GLViewer_Geom.h:159
GLfloat myA
Definition: GLViewer_Geom.h:157
Definition: GLViewer_Geom.h:45
GLViewer_Pnt()
Definition: GLViewer_Geom.h:47
void setX(GLfloat theX)
Definition: GLViewer_Geom.h:52
void setY(GLfloat theY)
Definition: GLViewer_Geom.h:53
GLfloat myY
Definition: GLViewer_Geom.h:59
GLfloat y() const
Definition: GLViewer_Geom.h:51
GLViewer_Pnt(GLfloat theX, GLfloat theY)
Definition: GLViewer_Geom.h:48
void setXY(GLfloat theX, GLfloat theY)
Definition: GLViewer_Geom.h:54
GLfloat myX
Definition: GLViewer_Geom.h:58
GLfloat x() const
Definition: GLViewer_Geom.h:50
void move(GLfloat theDX, GLfloat theDY)
Definition: GLViewer_Geom.h:55