1 // File: GLViewer_Geom.h
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 #ifndef GLVIEWER_GEOM_H
7 #define GLVIEWER_GEOM_H
12 #include <qvaluelist.h>
18 #pragma warning( disable:4251 )
21 /*! Struct GLViewer_Pnt
22 * Substitution of QPoint for OpenGL
25 struct GLVIEWER_API GLViewer_Pnt
28 GLViewer_Pnt() : myX( 0. ), myY( 0. ) {};
29 GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
31 GLfloat x() const { return myX; }
32 GLfloat y() const { return myY; }
33 void setX( GLfloat theX ) { myX = theX; }
34 void setY( GLfloat theY ) { myY = theY; }
35 void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
36 void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
43 typedef QValueList<GLViewer_Pnt> GLViewer_PntList;
45 /*! Class GLViewer_Rect
46 * Substitution of QRect for OpenGL
49 class GLVIEWER_API GLViewer_Rect
52 GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
53 GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
54 : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
55 GLViewer_Rect( QRect theRect ) {
56 myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
57 myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
59 float left() const { return myLeft; }
60 float right() const { return myRight; }
61 float top() const { return myTop; }
62 float bottom() const { return myBottom; }
64 float width() const { return fabs( myRight - myLeft ); }
65 float height() const { return fabs( myTop - myBottom ); }
67 void setLeft( float theLeft ) { myLeft = theLeft; }
68 void setRight( float theRight ) { myRight = theRight; }
69 void setTop( float theTop ) { myTop = theTop; }
70 void setBottom( float theBottom ) { myBottom = theBottom; }
72 void setCoords( float theLeft, float theRight, float theBottom, float theTop )
73 { myLeft = theLeft; myRight = theRight; myBottom = theBottom; myTop = theTop; }
75 //! \warning This method translate only rect format
76 QRect toQRect() { return QRect( ( int )myLeft, ( int )myBottom,
77 ( int )( myRight - myLeft ),
78 ( int )( myTop - myBottom ) ); }
80 //! On/off empty status
81 void setIsEmpty( bool on ) { myIsEmpty = on; }
82 //! Checks empty status
83 bool isEmpty() const { return myIsEmpty; }
85 //! Checks null status
86 bool isNull() const { return myLeft == 0.0 && myRight == 0.0 && myBottom == 0.0 && myTop == 0.0; }
87 //! Checks valid status
88 bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); }
90 //! Checks staus of contains point
91 bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
105 /*! Class GLViewer_Segment
106 * Segment for 2d detection
109 class GLVIEWER_API GLViewer_Segment
112 GLViewer_Segment( const GLViewer_Pnt& thePnt1,
113 const GLViewer_Pnt& thePnt2 );
115 //! Ordinary segment construction
116 /*!Construction of a ray with given equation Ax + By + C = 0 */
118 GLViewer_Segment( const GLViewer_Pnt& thePnt,
121 const GLfloat theC );
124 bool HasIntersection( const GLViewer_Segment& theOther ) const;
125 // Detects intersection with another segment or ray
135 /*! Class GLViewer_Poly
136 * Polygon for 2d detection
139 class GLVIEWER_API GLViewer_Poly
142 GLViewer_Poly( const GLViewer_PntList* thePoints );
143 virtual ~GLViewer_Poly();
145 //! Returns number of point
146 int Count() const { return myPoints->count(); }
148 //! Returns true if a point lies inside this polygon
149 virtual bool IsIn( const GLViewer_Pnt& thePnt ) const;
151 //! Returns true if a other polygon covers this polygon
152 virtual bool IsCovers( const GLViewer_Poly& thePoly ) const;
154 //! Likes the above function
155 virtual bool IsCovers( const GLViewer_Rect& theRect ) const;
157 // Returns true if intersection of this polygon with a segment or a ray not empty
158 virtual bool HasIntersection( const GLViewer_Segment& theSegment ) const;
162 GLViewer_PntList* myPoints;
166 #pragma warning ( default:4251 )