Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef GLVIEWER_GEOM_H
00028 #define GLVIEWER_GEOM_H
00029
00030 #include "GLViewer.h"
00031
00032 #include <QRect>
00033 #include <QtOpenGL>
00034 #include <math.h>
00035
00036
00037
00038 #ifdef WIN32
00039 #pragma warning( disable:4251 )
00040 #endif
00041
00046 struct GLVIEWER_API GLViewer_Pnt
00047 {
00048 public:
00049 GLViewer_Pnt() : myX( 0. ), myY( 0. ) {};
00050 GLViewer_Pnt( GLfloat theX, GLfloat theY ) : myX( theX ), myY( theY ) {}
00051
00052 GLfloat x() const { return myX; }
00053 GLfloat y() const { return myY; }
00054 void setX( GLfloat theX ) { myX = theX; }
00055 void setY( GLfloat theY ) { myY = theY; }
00056 void setXY( GLfloat theX, GLfloat theY ) { myX = theX; myY = theY; }
00057 void move( GLfloat theDX, GLfloat theDY ) { myX += theDX; myY += theDY; }
00058
00059 private:
00060 GLfloat myX;
00061 GLfloat myY;
00062 };
00063
00064 typedef QList<GLViewer_Pnt> GLViewer_PntList;
00065
00070 class GLVIEWER_API GLViewer_Rect
00071 {
00072 public:
00073 GLViewer_Rect(): myLeft(0.0), myRight(0.0), myTop(0.0), myBottom(0.0){}
00074 GLViewer_Rect( float theLeft, float theRight, float theTop, float theBottom )
00075 : myLeft(theLeft), myRight(theRight), myTop(theTop), myBottom(theBottom) {}
00076 GLViewer_Rect( QRect theRect ) {
00077 myLeft = ( float )theRect.left(); myRight = ( float )theRect.right();
00078 myTop = ( float )theRect.top(); myBottom = ( float )theRect.bottom(); }
00079
00080 float left() const { return myLeft; }
00081 float right() const { return myRight; }
00082 float top() const { return myTop; }
00083 float bottom() const { return myBottom; }
00084
00085 float width() const { return fabs( myRight - myLeft ); }
00086 float height() const { return fabs( myTop - myBottom ); }
00087
00088 void setLeft( float theLeft ) { myLeft = theLeft; }
00089 void setRight( float theRight ) { myRight = theRight; }
00090 void setTop( float theTop ) { myTop = theTop; }
00091 void setBottom( float theBottom ) { myBottom = theBottom; }
00092
00093 void setCoords( float theLeft, float theRight, float theBottom, float theTop )
00094 { myLeft = theLeft; myRight = theRight; myBottom = theBottom; myTop = theTop; }
00095
00097 QRect toQRect() { return QRect( ( int )myLeft, ( int )myBottom,
00098 ( int )( myRight - myLeft ),
00099 ( int )( myTop - myBottom ) ); }
00100
00102 void setIsEmpty( bool on ) { myIsEmpty = on; }
00104 bool isEmpty() const { return myIsEmpty; }
00105
00107 bool isNull() const { return myLeft == 0.0 && myRight == 0.0 && myBottom == 0.0 && myTop == 0.0; }
00109 bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); }
00110
00112 bool contains( GLViewer_Pnt pnt ) { return ( pnt.x() > left() &&
00113 pnt.x() < right() &&
00114 pnt.y() > bottom() &&
00115 pnt.y() < top() ); }
00116
00117 void move( const float x, const float y )
00118 {
00119 myLeft += x;
00120 myRight += x;
00121 myTop += y;
00122 myBottom += y;
00123 }
00124
00125 protected:
00126 float myLeft;
00127 float myRight;
00128 float myTop;
00129 float myBottom;
00130
00131 bool myIsEmpty;
00132 };
00133
00138 class GLVIEWER_API GLViewer_Segment
00139 {
00140 public:
00141 GLViewer_Segment( const GLViewer_Pnt& thePnt1,
00142 const GLViewer_Pnt& thePnt2 );
00143
00145
00147 GLViewer_Segment( const GLViewer_Pnt& thePnt,
00148 const GLfloat theA,
00149 const GLfloat theB,
00150 const GLfloat theC );
00151 ~GLViewer_Segment();
00152
00153 bool HasIntersection( const GLViewer_Segment& theOther ) const;
00154
00155
00156 private:
00157 GLViewer_Pnt myPnt1;
00158 GLViewer_Pnt myPnt2;
00159 GLfloat myA;
00160 GLfloat myB;
00161 GLfloat myC;
00162 };
00163
00168 class GLVIEWER_API GLViewer_Poly
00169 {
00170 public:
00171 GLViewer_Poly( const GLViewer_PntList* thePoints );
00172 virtual ~GLViewer_Poly();
00173
00175 void AddPoint( GLViewer_Pnt& pnt ) { myPoints->append( pnt ); }
00176
00178 int Count() const { return myPoints->count(); }
00179
00181 virtual bool IsIn( const GLViewer_Pnt& thePnt ) const;
00182
00184 virtual bool IsCovers( const GLViewer_Poly& thePoly ) const;
00185
00187 virtual bool IsCovers( const GLViewer_Rect& theRect ) const;
00188
00189
00190 virtual bool HasIntersection( const GLViewer_Segment& theSegment ) const;
00191
00192 private:
00193 GLViewer_PntList* myPoints;
00194 };
00195
00196 #ifdef WIN32
00197 #pragma warning ( default:4251 )
00198 #endif
00199
00200 #endif