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 // Class: GLViewer_Pnt
22 // Descr: Substitution of QPoint for OpenGL
24 struct GLVIEWER_API GLViewer_Pnt
27 GLViewer_Pnt() : myX( 0. ), myY( 0. ) {};
28 GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
30 GLfloat x() const { return myX; }
31 GLfloat y() const { return myY; }
32 void setX( GLfloat theX ) { myX = theX; }
33 void setY( GLfloat theY ) { myY = theY; }
34 void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
35 void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
42 typedef QValueList<GLViewer_Pnt> GLViewer_PntList;
44 // Class: GLViewer_Rect
45 // Descr: Substitution of QRect for OpenGL
47 class GLVIEWER_API GLViewer_Rect
50 GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
51 GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
52 : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
53 GLViewer_Rect( QRect theRect ) {
54 myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
55 myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
57 float left() const { return myLeft; }
58 float right() const { return myRight; }
59 float top() const { return myTop; }
60 float bottom() const { return myBottom; }
62 float width() const { return fabs( myRight - myLeft ); }
63 float height() const { return fabs( myTop - myBottom ); }
65 void setLeft( float theLeft ) { myLeft = theLeft; }
66 void setRight( float theRight ) { myRight = theRight; }
67 void setTop( float theTop ) { myTop = theTop; }
68 void setBottom( float theBottom ) { myBottom = theBottom; }
70 void setCoords( float theLeft, float theRight, float theBottom, float theTop )
71 { myLeft = theLeft; myRight = theRight; myBottom = theBottom; myTop = theTop; }
73 QRect toQRect() { return QRect( ( int )myLeft, ( int )myBottom,
74 ( int )( myRight - myLeft ),
75 ( int )( myTop - myBottom ) ); }
77 void setIsEmpty( bool on ) { myIsEmpty = on; }
78 bool isEmpty() const { return myIsEmpty; }
80 bool isNull() const { return myLeft == 0.0 && myRight == 0.0 && myBottom == 0.0 && myTop == 0.0; }
81 bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); }
83 bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
97 // Class: GLViewer_Segment
98 // Descr: Segment for 2d detection
100 class GLVIEWER_API GLViewer_Segment
103 GLViewer_Segment( const GLViewer_Pnt& thePnt1,
104 const GLViewer_Pnt& thePnt2 );
105 // Ordinary segment construction
107 GLViewer_Segment( const GLViewer_Pnt& thePnt,
110 const GLfloat theC );
111 // Construction of a ray with given equation Ax + By + C = 0
115 bool HasIntersection( const GLViewer_Segment& theOther ) const;
116 // Detects intersection with another segment or ray
126 // Class: GLViewer_Poly
127 // Descr: Polygon for 2d detection
129 class GLVIEWER_API GLViewer_Poly
132 GLViewer_Poly( const GLViewer_PntList* thePoints );
133 virtual ~GLViewer_Poly();
135 int Count() const { return myPoints->count(); }
137 virtual bool IsIn( const GLViewer_Pnt& thePnt ) const;
138 //virtual bool IsIn( const GLViewer_Pnt& thePnt, const float tolerance = 0 ) const;
139 // Detects if a point lies inside this polygon
141 virtual bool IsCovers( const GLViewer_Poly& thePoly ) const;
142 // Detect if a other polygon covers this polygon
144 virtual bool IsCovers( const GLViewer_Rect& theRect ) const;
145 // likes the above function
147 virtual bool HasIntersection( const GLViewer_Segment& theSegment ) const;
148 // Detects intersection of this polygon with a segment or a ray
151 GLViewer_PntList* myPoints;
155 #pragma warning ( default:4251 )