Hexagon Cell  v.1.1.1
Cell.h
1 // Cell class
2 // Written by Sergey G. Kosov in 2013 for Project X
3 #pragma once
4 
5 #include "types.h"
6 
7 const double MIN_RADIUS = 1.0;
8 
9 namespace HexagonCells
10 {
12  typedef struct {
13  double R;
14  double r;
15  double S;
16  int N;
17  } cell_params;
18 
25  enum cell_int_app {
28  };
29 
30 
31  // ================================ Cell Class ================================
39  class CCell
40  {
41  friend class CMarker;
42 
43  public:
47  DllExport CCell(void);
53  DllExport CCell(CvSize imgSize, cell_int_app cellIntApp = CELL_AVG);
59  DllExport CCell(Mat &img, cell_int_app cellIntApp = CELL_AVG);
64  DllExport CCell(double R);
71  DllExport CCell(CvSize imgSize, double R, cell_int_app cellIntApp = CELL_AVG);
78  DllExport CCell(Mat &img, double R, cell_int_app cellIntApp = CELL_AVG);
79  DllExport ~CCell(void);
80 
84  DllExport void clear(void);
89  DllExport void setImage(Mat &img);
94  DllExport void setRadius(double R);
99  DllExport void setInterpolationApproach(cell_int_app cellIntApp);
100 
105  DllExport cell_params getInfo(void);
113  DllExport int getIDX(int x, int y);
122  DllExport int getNeighbourIDX(int idx, int i);
131  DllExport int * getNeighbourhood(int idx);
137  DllExport CvScalar getVal(int idx);
138 
139  // Brute - force functions
140  DllExport Mat getLUT(void) { return m_LUT; }
141  DllExport void setLUT(Mat &LUT) { LUT.copyTo(m_LUT); }
142 
143 
144  private:
145  int calculate_LUT(void); // 0 on success, error_code otherwise
146  int calculate_nCells(void); // 0 on success, error_code otherwise
147  int calculate_cellData(void); // 0 on success, error_code otherwise
148 
149  bool ifInsideCell(CvPoint2D64f x, CvPoint2D64f C) const;
150  static CvPoint2D64f getBoundaryPoint(CvPoint2D64f C, int i, double R);
151 
152 
153  // Coordinate translation functions (idx <-> h <-> d)
154  static Point idx2h(int idx, double R, CvSize imgSize); // index to hexagonal
155  inline int h2idx(Point c) const; // hexagonal to index
156  static CvPoint2D64f idx2d(int idx, double R, CvSize imgSize); // index to cartesian
157  inline int d2idx(CvPoint2D64f C); // cartesian to index
158  // static CvPoint2D64f h2d(Point c);
159  inline Point d2h(CvPoint2D64f C) const; // cartesian to hexagonal
160 
161 
162  private:
163  Mat m_img; // Mat(); // The image
164  CvSize m_imgSize; // cvSize(0, 0); //
165  Mat m_LUT; // Mat(); // Look-up table Mat(m_imgSize, CV_32SC1)
166  double m_R; // -1; // Hexagon outer radius
167  double m_r; // -1; // Hexagon inner radius
168  int m_nCells; // -1; // Number of of hexagons in the image
169  cell_int_app m_cellIntApp; // CELL_AVG; // Cell interpolation approach
170  Mat m_cellData; // Mat(); // Direct cell datas
171 
172 
173 
174  // Copy semantics are disabled
175  CCell(const CCell &rhs) {}
176  const CCell & operator= (const CCell & rhs) { return *this; }
177  };
178 
179 }
int N
Number of hexagons in the image.
Definition: Cell.h:16
int getNeighbourIDX(int idx, int i)
Returns the neighbouring cell index.
Definition: Cell.cpp:112
Cell class.
Definition: Cell.h:39
Mat getLUT(void)
Definition: Cell.h:140
cell_int_app
Cell interpolation approach.
Definition: Cell.h:25
void setRadius(double R)
(Re-) sets the hexagon outer radius
Definition: Cell.cpp:76
CvScalar getVal(int idx)
Returns the color of the specified cell.
Definition: Cell.cpp:153
double r
Hexagon inner radius.
Definition: Cell.h:14
void setInterpolationApproach(cell_int_app cellIntApp)
(Re-) sets the interpolation approach for cell color generation
Definition: Cell.cpp:89
double R
Hexagon outer radius.
Definition: Cell.h:13
Marker class.
Definition: Marker.h:16
void setLUT(Mat &LUT)
Definition: Cell.h:141
int * getNeighbourhood(int idx)
Returns all 6 neighbouring cell indexs.
Definition: Cell.cpp:146
int getIDX(int x, int y)
Returns the cell index.
Definition: Cell.cpp:107
cell_params getInfo(void)
Returns the cell parameters.
Definition: Cell.cpp:95
double S
Hexagon area in pixels.
Definition: Cell.h:15
Majority voting approach.
Definition: Cell.h:27
Average value approach.
Definition: Cell.h:26
void setImage(Mat &img)
(Re-) sets the image
Definition: Cell.cpp:60
CCell(void)
Default constuctor.
Definition: Cell.cpp:8
Cell parameters structure.
Definition: Cell.h:12
void clear(void)
Resets the class by releasing memory and setting the class variable by default.
Definition: Cell.cpp:49