From 82c798c0db395e1f2aa725d1c74bc24f014751cc Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 24 Jun 2005 11:47:39 +0000 Subject: [PATCH] *** empty log message *** --- src/GLViewer/GLViewer_Detector.cxx | 210 ----------------------------- src/GLViewer/GLViewer_Detector.h | 73 ---------- 2 files changed, 283 deletions(-) delete mode 100644 src/GLViewer/GLViewer_Detector.cxx delete mode 100644 src/GLViewer/GLViewer_Detector.h diff --git a/src/GLViewer/GLViewer_Detector.cxx b/src/GLViewer/GLViewer_Detector.cxx deleted file mode 100644 index fcd31a55c..000000000 --- a/src/GLViewer/GLViewer_Detector.cxx +++ /dev/null @@ -1,210 +0,0 @@ -// File: GLViewer_Detector.cxx -// Created: 11/16/2004 14:19:07 -// Author: Sergey ANIKIN -// Copyright: CEA 2004 - -#include - -#define FAR_POINT 1e10 // Value used as a "very distant" co-ordinate -#define TOLERANCE 1e-3 - -//================================================================ -// Class : GLViewer_Segment -// Description : -//================================================================ - -//================================================================ -// Function : GLViewer_Segment -// Purpose : constructs a real segment bounded by two points -//================================================================ -GLViewer_Segment::GLViewer_Segment( const GLViewer_Pnt& thePnt1, - const GLViewer_Pnt& thePnt2 ) -: myPnt1( thePnt1 ), - myPnt2( thePnt2 ) -{ - myA = myPnt1.y() - myPnt2.y(); - myB = myPnt2.x() - myPnt1.x(); - myC = myPnt1.x() * myPnt2.y() - myPnt2.x() * myPnt1.y(); -} - -//================================================================ -// Function : GLViewer_Segment -// Purpose : constructs a ray starting at and directed -// along positive X axis direction (or Y axis if vertical ) -//================================================================ -GLViewer_Segment::GLViewer_Segment( const GLViewer_Pnt& thePnt, - const GLfloat theA, - const GLfloat theB, - const GLfloat theC ) -: myPnt1( thePnt ), - myA( theA ), - myB( theB ), - myC( theC ) -{ - if ( fabs( myB ) < TOLERANCE ) - myPnt2 = GLViewer_Pnt( myPnt1.x(), FAR_POINT ); - else - myPnt2 = GLViewer_Pnt( FAR_POINT, - myA / myB * FAR_POINT - myC / myB ); -} - -//================================================================ -// Function : GLViewer_Segment -// Purpose : destructor, does nothing -//================================================================ -GLViewer_Segment::~GLViewer_Segment() -{ -} - -//================================================================ -// Function : HasIntersection -// Purpose : detects intersection with segment -//================================================================ -bool GLViewer_Segment::HasIntersection( const GLViewer_Segment& theOther ) const -{ - bool aRes = false; - GLfloat aDiv = myA * theOther.myB - myB * theOther.myA; - if ( fabs( aDiv ) > TOLERANCE ) - { - GLfloat aX = ( myB * theOther.myC - theOther.myB * myC ) / aDiv; - GLfloat aX11 = myPnt1.x() > myPnt2.x() ? myPnt2.x() : myPnt1.x(); - GLfloat aX12 = myPnt1.x() > myPnt2.x() ? myPnt1.x() : myPnt2.x(); - GLfloat aX21 = theOther.myPnt1.x() > theOther.myPnt2.x() ? theOther.myPnt2.x() : theOther.myPnt1.x(); - GLfloat aX22 = theOther.myPnt1.x() > theOther.myPnt2.x() ? theOther.myPnt1.x() : theOther.myPnt2.x(); - - GLfloat aY = ( myC * theOther.myA - theOther.myC * myA ) / aDiv; - GLfloat aY11 = myPnt1.y() > myPnt2.y() ? myPnt2.y() : myPnt1.y(); - GLfloat aY12 = myPnt1.y() > myPnt2.y() ? myPnt1.y() : myPnt2.y(); - GLfloat aY21 = theOther.myPnt1.y() > theOther.myPnt2.y() ? theOther.myPnt2.y() : theOther.myPnt1.y(); - GLfloat aY22 = theOther.myPnt1.y() > theOther.myPnt2.y() ? theOther.myPnt1.y() : theOther.myPnt2.y(); - - if ( fabs( aX11 - aX12 ) > TOLERANCE ) - aRes = aX11 < aX && aX < aX12; - else - aRes = aY11 < aY && aY < aY12; - - if ( aRes ) - { - if ( fabs( aX21 - aX22 ) > TOLERANCE ) - aRes = aX21 < aX && aX < aX22; - else - aRes = aY21 < aY && aY < aY22; - } - } - - return aRes; -} - -//================================================================ -// Class : GLViewer_Poly -// Description : -//================================================================ - -//================================================================ -// Function : GLViewer_Poly -// Purpose : constructs a closed polygon from the given ordered list of points -//================================================================ -GLViewer_Poly::GLViewer_Poly( const GLViewer_PntList* thePoints ) -: myPoints( (GLViewer_PntList*)thePoints ) -{ -} - -//================================================================ -// Function : ~GLViewer_Poly -// Purpose : destructor, mustn't be deleted here! -//================================================================ -GLViewer_Poly::~GLViewer_Poly() -{ -} - -//================================================================ -// Function : IsIn -// Purpose : returns true if lies within this polygon -//================================================================ -bool GLViewer_Poly::IsIn( const GLViewer_Pnt& thePnt ) const -{ - if ( !myPoints ) - return false; - - int aNbInter = 0; - GLViewer_Segment aRay( thePnt, 0., 1., -thePnt.y() ); - - GLViewer_PntList::const_iterator it1 = myPoints->begin(); - GLViewer_PntList::const_iterator it2 = myPoints->begin(); - ++it2; - for ( ; it1 != myPoints->end(); ++it1, ++it2 ) - { - if ( it2 == myPoints->end() ) - it2 = myPoints->begin(); - - if ( aRay.HasIntersection( GLViewer_Segment( *it1, *it2 ) ) ) - aNbInter++; - } - - return ( aNbInter % 2 == 1 ); -} - -//================================================================ -// Function : IsCovers -// Purpose : returns true if covers this polygon -//================================================================ -bool GLViewer_Poly::IsCovers( const GLViewer_Poly& thePoly ) const -{ - if ( !myPoints || !thePoly.Count() ) - return false; - - GLViewer_PntList::const_iterator it = myPoints->begin(); - - for ( ; it != myPoints->end(); ++it ) - { - if( !thePoly.IsIn( *it ) ) - return false; - } - - return true; -} - -//================================================================ -// Function : IsCovers -// Purpose : returns true if covers this polygon -//================================================================ -bool GLViewer_Poly::IsCovers( const GLViewer_Rect& theRect ) const -{ - if ( !myPoints ) //needs check for - return false; - - GLViewer_PntList aList; - GLViewer_PntList::iterator it = aList.begin(); - - aList.insert( it, GLViewer_Pnt( theRect.left(), theRect.top() ) ); - aList.insert( it, GLViewer_Pnt( theRect.right(), theRect.top() ) ); - aList.insert( it, GLViewer_Pnt( theRect.right(), theRect.bottom() ) ); - aList.insert( it, GLViewer_Pnt( theRect.left(), theRect.bottom() ) ); - - return IsCovers( GLViewer_Poly( &aList ) ); -} - -//================================================================ -// Function : HasIntersection -// Purpose : looks for any -//================================================================ -bool GLViewer_Poly::HasIntersection( const GLViewer_Segment& theSegment ) const -{ - if ( !myPoints ) - return false; - - bool aRes = false; - GLViewer_PntList::const_iterator it1 = myPoints->begin(); - GLViewer_PntList::const_iterator it2 = myPoints->begin(); - ++it2; - for ( ; !aRes && it1 != myPoints->end(); ++it1, ++it2 ) - { - if ( it2 == myPoints->end() ) - it2 = myPoints->begin(); - - aRes = theSegment.HasIntersection( GLViewer_Segment( *it1, *it2 ) ); - } - - return aRes; -} - - diff --git a/src/GLViewer/GLViewer_Detector.h b/src/GLViewer/GLViewer_Detector.h deleted file mode 100644 index c1394ee4f..000000000 --- a/src/GLViewer/GLViewer_Detector.h +++ /dev/null @@ -1,73 +0,0 @@ -// File: GLViewer_Detector.h -// Created: 11/16/2004 09:33:22 -// Author: Sergey ANIKIN -// Copyright: CEA 2004 - -#ifndef GLVIEWER_DETECTOR_H -#define GLVIEWER_DETECTOR_H - -#include - -//================================================================ -// Class : GLViewer_Segment -// Description : segment for 2d detection -//================================================================ -class GLVIEWER_EXPORT GLViewer_Segment -{ -public: - GLViewer_Segment( const GLViewer_Pnt& thePnt1, - const GLViewer_Pnt& thePnt2 ); - // Ordinary segment construction - - GLViewer_Segment( const GLViewer_Pnt& thePnt, - const GLfloat theA, - const GLfloat theB, - const GLfloat theC ); - // Construction of a ray with given equation Ax + By + C = 0 - - ~GLViewer_Segment(); - - bool HasIntersection( const GLViewer_Segment& theOther ) const; - // Detects intersection with another segment or ray - -private: - GLViewer_Pnt myPnt1; - GLViewer_Pnt myPnt2; - GLfloat myA; - GLfloat myB; - GLfloat myC; -}; - -//================================================================ -// Class : GLViewer_Poly -// Description : polygon for 2d detection -//================================================================ -class GLVIEWER_EXPORT GLViewer_Poly -{ -public: - GLViewer_Poly( const GLViewer_PntList* thePoints ); - virtual ~GLViewer_Poly(); - - - int Count() const { return myPoints->count(); } - virtual bool IsIn( const GLViewer_Pnt& thePnt ) const; - // Detects if a point lies inside this polygon - - virtual bool IsCovers( const GLViewer_Poly& thePoly ) const; - // Detect if a other polygon covers this polygon - - virtual bool IsCovers( const GLViewer_Rect& theRect ) const; - // likes the above function - - virtual bool HasIntersection( const GLViewer_Segment& theSegment ) const; - // Detects intersection of this polygon with a segment or a ray - -private: - GLViewer_PntList* myPoints; -}; - -#endif - -#ifdef _MSC_VER -#pragma once -#endif -- 2.39.2