home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / PGEVENT.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  6KB  |  190 lines

  1. /* @(#)Z 1.8 com/src/imaging/polyclip/PGEvent.h, odimaging, od96os2, odos29646d 96/11/15 15:25:08 (96/10/29 09:26:34) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odimaging
  6.  *
  7.  *   CLASSES:   PGEvent
  8.  *              PGEventQueue
  9.  *
  10.  *   ORIGINS: 82,27
  11.  *
  12.  *
  13.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  14.  *   All Rights Reserved
  15.  *   Licensed Materials - Property of IBM
  16.  *   US Government Users Restricted Rights - Use, duplication or
  17.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  18.  *
  19.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  23.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  24.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  25.  *   OR PERFORMANCE OF THIS SOFTWARE.
  26.  */
  27. /*====END_GENERATED_PROLOG========================================
  28.  */
  29.  
  30. /********************************************************************/
  31. /*  Licensed Materials - Property of IBM                            */
  32. /*                                                                  */
  33. /*                                                                  */
  34. /* Copyright (C) International Business Machines Corp., 1994.       */
  35. /* Copyright (C) Apple Computer, Inc., 1994                         */
  36. /*                                                                  */
  37. /*  US Government Users Restricted Rights -                         */
  38. /*  Use, duplication, or disclosure restricted                      */
  39. /*  by GSA ADP Schedule Contract with IBM Corp.                     */
  40. /********************************************************************/
  41. /*  IBM Change History (most recent first):                         */
  42. /*          3/21/96 jab  Merge with DR4.                            */
  43. /*  120604  4/28/95 ced  Merge with B1C16 Apple code.               */
  44. /*                                                                  */
  45. /********************************************************************/
  46. /*
  47.   File:    PGEvent.h
  48.  
  49.   Contains:  Geometric event structure for the clipper.
  50.  
  51.    Owned by:   Jens Alfke (based on algorithm by A. C. Kilgour)
  52.  
  53.    Copyright:  ⌐ 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  54.  
  55.   Change History (most recent first):
  56.  
  57.        <3>   3/22/95 jpa      Added aet param to MergeWith [1230776]
  58.      <2>   6/30/94  jpa    Added dummy destructor for PGEvent to
  59.                   appease CodeWarrior compiler.
  60.      <1>   6/15/94  jpa    first checked in
  61.      ---------------------------Moved to ODSOM project.
  62.      <1>    5/9/94  jpa    first checked in
  63.    
  64.    In Progress:
  65.       
  66. */
  67.  
  68. #ifndef _PGEVENT_
  69. #define _PGEVENT_
  70.  
  71. #ifndef _EVENT_TEMPLATES_ 
  72. #ifndef _ALTPOINT_
  73. #include "AltPoint.h"
  74. #endif
  75. #else
  76. #include <stack.h>
  77. #include <vector.h>
  78. #endif 
  79.  
  80. #ifndef _ODTYPES_
  81. #include "ODTypes.h"
  82. #endif
  83.  
  84. #ifndef _EVENT_TEMPLATES_ 
  85. #ifndef _PRIORTYQ_
  86. #include "PriortyQ.h"
  87. #endif
  88. #endif
  89.  
  90. #ifndef _PGCOMMON_
  91. #include "PGCommon.h"
  92. #endif
  93.  
  94. #ifndef _PGEDGE_
  95. #include "PGEdge.h"
  96. #endif
  97.  
  98.  
  99. class PGContour;
  100. class PGEdge;
  101. class PGEdgeTable;
  102. class PGVertex;
  103. class PGEventQueue;
  104.  
  105.  
  106.  
  107. #ifdef _EVENT_TEMPLATES_
  108. class PGEvent :public ODPoint
  109. #else
  110. class PGEvent :public Sortable, public ODPoint
  111. #endif   // _EVENT_TEMPLATES_ 
  112. {
  113.   public:
  114.     PGEvent( );
  115.     ~PGEvent( )    { }          // Keeps CodeWarrior happy
  116.     PGEvent*  InitLocalMinEvent( const PGVertex* );
  117.     PGEvent*  InitLowEvent( const PGEdge* );
  118.     PGEvent*  InitIntersection( const PGEdge*, const PGEdge*,
  119.                     const ODPoint § );
  120.  
  121. #ifndef _EVENT_TEMPLATES_
  122.     virtual ODBoolean ComesBefore( const Sortable* ) const;    // From Sortable class
  123. #endif
  124.  
  125.     void     MergeWith( PGEvent*, PGEdgeTable &aet );
  126.     void    Process( PGEdgeTable&, PGEventQueue& );
  127.  
  128.   protected:
  129.     void    ConnectEdgePaths( PGEdgeTable &upperEdges );
  130.     void    ConnectAdjacentEdgePaths( PGEdgeTable &upperEdges, PGSense firstSense );
  131.  
  132.     PGEdge*    fFirstUpperEdge;    // 1st edge (in AET) of my upper-edge range
  133.     PGEdge*    fLastUpperEdge;      // Last edge of upper-edge range
  134.     PGEdgeTable  fLowerEdges;      // List of lower edges
  135. };
  136.  
  137.  
  138. #ifdef _EVENT_TEMPLATES_
  139.      
  140. struct less<PGEvent*> : binary_function<PGEvent*, PGEvent*, bool> {
  141.     bool operator()(PGEvent*& ev1, PGEvent*& ev2) const {
  142.      return (((ev1->y) != (ev2->y)) ? ((ev1->y)>(ev2->y)) : ((ev1->x)>(ev2->x)));}
  143. }; 
  144.  
  145. // In the OS/2 port, templates were used to improve performance as 
  146. // documented below.  In the DR4 port, we haven't implemented templates
  147. // yet so the following ifdef chooses between the OS/2 template version
  148. // and the DR4 version.  jab 4/12/96
  149.  
  150. // We use a template version of the priority queue class here so that we can
  151. // declare the comparison operator inline, rather than using a virtual method.
  152. // This improves the performance of the polygon clipper about 15%
  153.  
  154. class PGEventQueue : public priority_queue<vector<PGEvent*>, less<PGEvent*> >
  155. {
  156.   public:
  157.     PGEventQueue( ODULong suggestedSize )
  158.       : priority_queue<vector<PGEvent*>, less<PGEvent*> >()
  159.       { } // Can't adjust the vector size with the exiting priority_queue constructors
  160.     inline ODBoolean IsEmpty( ) const { return empty(); }
  161.     inline void Add(PGEvent* T) { push(T); }
  162.     void    AddIntersectionIfBelow( PGEdge*, PGEdge*, const PGEvent *curEv );
  163.     PGEvent*  First( )  const  { return top(); }
  164.     PGEvent*  RmvFirst( )      { value_type first = top();
  165.                  pop();
  166.                  return first; }
  167. };
  168.  
  169. #else  // _EVENT_TEMPLATES_
  170.  
  171. class PGEventQueue :private PriorityQueue
  172. {
  173.   public:
  174.     PGEventQueue( ODULong suggestedSize )
  175.       :PriorityQueue(suggestedSize)
  176.       { }
  177.  
  178.     PriorityQueue::IsEmpty;
  179.     PriorityQueue::Add;
  180.     
  181.     void    AddIntersectionIfBelow( PGEdge*, PGEdge*, const PGEvent *curEv );
  182.     
  183.     PGEvent*  First( )  const  {return (PGEvent*)PriorityQueue::GetFirst();}
  184.     PGEvent*  RmvFirst( )      {return (PGEvent*)PriorityQueue::RemoveFirst();}
  185. };
  186. #endif   // _EVENT_TEMPLATES_
  187.  
  188. #endif /*_PGEVENT_*/
  189.  
  190.