KSquare Utilities
ConvexHull.h
Go to the documentation of this file.
1 #ifndef _CONVEXHULL_
2 #define _CONVEXHULL_
3 
4 //**********************************************************************
5 //* Originally Developed by Tong Luo as a Java Applet. *
6 //* *
7 //* Feb-28-03 Ported to c++ by Kurt Kramer to work with Raster class. *
8 //* *
9 //**********************************************************************
10 
11 /*
12  * ConvexHull.java
13  *
14  * Created on April 7, 2002, 10:52 PM
15  */
16 
17 
18 #include "KKBaseTypes.h"
19 #include "MorphOp.h"
20 
21 
22 namespace KKB
23 {
24  #ifndef _POINT_
25  class Point;
26  typedef Point* PointPtr;
27  class PointList;
28  typedef PointList* PointListPtr;
29  #endif
30 
31 
32  #ifndef _RASTER_
33  class Raster;
34  typedef Raster* RasterPtr;
35  typedef Raster const* RasterConstPtr;
36  #endif
37 
38 
39  /**
40  *@brief Operator that will create a Convex Hull of a supplied image.
41  */
42  class ConvexHull: public MorphOp
43  {
44  public:
45  ConvexHull ();
46 
47  virtual ~ConvexHull ();
48 
50 
51  virtual RasterPtr PerformOperation (RasterConstPtr _image);
52 
53  RasterPtr Filter (const Raster& src);
54 
55 
56  /*
57  *@brief Will perform Convex-hull on 'src' and place result into 'dest'.
58  *@returns Returns dest.
59  */
60  RasterPtr Filter (const Raster& src,
61  RasterPtr dest
62  );
63 
64 
66 
67  void Draw (Raster& output);
68 
69 
70  /**
71  *@brief Build list of the upper and lower points in the image.
72  *@details for each column in the image where there is at least one foreground pixel will add
73  * one point to 'upperPoints' for the pixel with the smallest row and one point to 'lowerPoints'
74  * for the pixel with the largest row.
75  *@param[in] input Source image that we are to generate a Convex Hull for.
76  */
77  void Store (const Raster& input);
78 
79 
80  private:
81  void AllocateMemory ();
82  void CleanUpMemory ();
83 
84  inline double Distance (Point& p1,
85  Point& p2
86  );
87 
88  void BuildLowerLink ();
89 
90  void BuildUpperLink ();
91 
92  void CalcConvexArea (RasterPtr raster);
93 
94  double ConvexArea2 ();
95 
96  void DrawLine (Raster& raster,
97  Point& p1,
98  Point& p2,
99  uchar pixVal
100  );
101 
102  void Merge ();
103 
104  kkint32 RelativeCCW (Point& sp,
105  Point& ep,
106  Point& p
107  );
108 
109  static
110  double TriangleArea (Point& a,
111  Point& b,
112  Point& c
113  );
114 
115 
116  kkint32 convexArea;
117  PointListPtr upperPoints;
118  PointListPtr lowerPoints;
119  PointListPtr upper;
120  PointListPtr lower;
121  };
122 
124 } /* namespace KKB; */
125 
126 #endif
__int32 kkint32
Definition: KKBaseTypes.h:88
A class that is used by to represent a single image in memory.
Definition: Raster.h:108
ConvexHull * ConvexHullPtr
Definition: ConvexHull.h:123
Used by Raster class and MorphOp derived classes to denote a single pixel location in Raster image...
Definition: Point.h:20
KKTHread * KKTHreadPtr
RasterPtr Filter(const Raster &src, RasterPtr dest)
Definition: ConvexHull.cpp:128
unsigned char uchar
Unsigned character.
Definition: KKBaseTypes.h:77
kkint32 ConvexArea()
Definition: ConvexHull.cpp:189
RasterPtr Filter(const Raster &src)
Returns a image that represents the convex-hull of the 'src' image. param[in] src Source image that c...
Definition: ConvexHull.cpp:88
void Draw(Raster &output)
Definition: ConvexHull.cpp:438
Operator that will create a Convex Hull of a supplied image.
Definition: ConvexHull.h:42
Base class for all Morphological operations.
Definition: MorphOp.h:44
virtual RasterPtr PerformOperation(RasterConstPtr _image)
Definition: ConvexHull.cpp:73
Container object used to maintaining a list of pixel locations.
Definition: Point.h:75
void Store(const Raster &input)
Build list of the upper and lower points in the image.
Definition: ConvexHull.cpp:738
virtual OperationType Operation() const
Definition: ConvexHull.h:49
virtual ~ConvexHull()
Definition: ConvexHull.cpp:46