templt.h

Go to the documentation of this file.
00001 
00002 /**********************************************************************
00003  *<
00004     FILE: templt.h
00005 
00006     DESCRIPTION:  Defines 2D Template Object
00007 
00008     CREATED BY: Tom Hudson
00009 
00010     HISTORY: created 31 October 1995
00011 
00012  *> Copyright (c) 1995, All Rights Reserved.
00013  **********************************************************************/
00014 
00015 #pragma once
00016 #include "maxheap.h"
00017 #include "CoreExport.h"
00018 #include <WTypes.h>
00019 #include "point2.h"
00020 #include "point3.h"
00021 #include "box3.h"
00022 // forward declarations
00023 class PolyLine;
00024 class Spline3D;
00025 
00026 // Intersection callbacks
00027 
00028 class IntersectionCallback2D: public MaxHeapOperators {
00029     public:
00030         virtual ~IntersectionCallback2D() {}
00031         virtual BOOL Intersect(Point2 p, int piece)=0; // Return FALSE to stop intersect tests
00032     };
00033 
00034 class IntersectionCallback3D: public MaxHeapOperators {
00035     public:
00036         virtual ~IntersectionCallback3D() {}
00037         virtual BOOL Intersect(Point3 p, int piece)=0; // Return FALSE to stop intersect tests
00038     };
00039 
00040 // A handy 2D floating-point box class
00041 
00053 class Box2D: public MaxHeapOperators {
00054     public:
00055         BOOL empty;
00056         Point2 min, max;
00058         Box2D() { empty = TRUE; }
00062         void SetEmpty() { empty = TRUE; }
00068         CoreExport Box2D& operator+=(const Point2& p);  // expand this box to include p
00069     };
00070 
00071 // This object is used to test shapes for self-intersection, clockwise status, point
00072 // surrounding and intersection with other templates.  The last and first points will be the
00073 // same if it is closed.
00074 
00075 class Template3D;
00076 
00092 class Template: public MaxHeapOperators {
00093     public:
00094         int points;
00095         BOOL closed;
00096         Point2 *pts;
00101         Template(Spline3D *spline);
00106         Template(PolyLine *line);
00107         Template(Template3D *t3);
00113         void Create(PolyLine *line);
00115         ~Template();
00117         int Points() { return points; }
00123         BOOL SurroundsPoint(Point2& point);
00127         BOOL IsClockWise();
00136         BOOL SelfIntersects(BOOL findAll = FALSE, IntersectionCallback2D *cb = NULL);
00147         BOOL Intersects(Template &t, BOOL findAll = FALSE, IntersectionCallback2D *cb = NULL);
00151         Box2D Bound();
00152     };
00153 
00154 // This is a version for 3D use -- the various tests (SurroundsPoint, SelfIntersects, etc.
00155 // are all performed on the X and Y coordinates only, discarding Z.  The IntersectionCallback
00156 // returns the intersection point on the template in 3D.
00157 
00158 class Template3D: public MaxHeapOperators {
00159     private:
00160         Template *template2D;
00161     public:
00162         int points;
00163         BOOL closed;
00164         Point3 *pts;
00165         Template3D(Spline3D *spline);
00166         Template3D(PolyLine *line);
00167         void Create(PolyLine *line);
00168         ~Template3D();
00169         int Points() { return points; }
00170         BOOL SurroundsPoint(Point2& point); // 2D test!
00171         BOOL IsClockWise(); // 2D test!
00172         BOOL SelfIntersects(BOOL findAll = FALSE, IntersectionCallback3D *cb = NULL);   // 2D test!
00173         BOOL Intersects(Template3D &t, BOOL findAll = FALSE, IntersectionCallback3D *cb = NULL); // 2D test!
00174         Box2D Bound();
00175         Box3 Bound3D();
00176         void Ready2DTemplate();
00177     };
00178