rasdaman complete source
polycutout.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
40 /*
41  This module is intended to perform polygon cut out operation. It supports the exact ESRI specifications
42  regarding "clean" polygons, this means: not self intersecting, closed, if you walk from an point to the
43  next of edge the inside is on the right. It also supports multiple rings, but the outer one has to have
44  the "inside" inside.
45  Don't forget that the rasdaman coordinates are with x left->right and y top->down, or at least
46  I have considered them so because of the usual coordinates of tiffs
47 */
48 
49 #ifndef _R_POLYGON_CUT_OUT_HH
50 #define _R_POLYGON_CUT_OUT_HH
51 
52 #include <iosfwd>
53 #include <vector>
54 #include <list>
55 #include <string>
56 using std::string;
57 using std::list;
58 using std::vector;
59 using std::ostream;
60 
61 #include "raslib/point.hh"
62 #include "raslib/minterval.hh"
63 #include "rasodmg/polygon.hh"
64 
65 
66 //@ManMemo: Module: {\bf rasodmg}
67 
68 
72 class r_SegmentIterator
73 {
74 public:
75  r_SegmentIterator(r_Point&,r_Point&);
76  void reset();
77  r_Point next();
78  bool hasMore();
79  int cosFunc(); // limited use,1000 * cos(alfa)
80 private:
81  void swap(r_Range&, r_Range&);
82  r_Point createCurrentPoint();
83 
84  r_Point start;
85  r_Point end;
86  int cadran;
87 
88  r_Range dx,dy;
89  r_Range cx,cy;
90  int beta;
91 };
92 
96 class r_Line
97 {
98 public:
99  r_Line();
100  r_Line(double,double,double);
101  r_Line(r_Point&,r_Point&);
102  double getA();
103  double getB();
104  double getC();
105  float ecuatia(r_Point&);
106 private:
107  double a,b,c;
108  friend ostream& operator<<(ostream&,r_Line&);
109 };
110 
111 
115 class r_PolygonCutOut
116 {
117 public:
118  r_PolygonCutOut();
119  ~r_PolygonCutOut();
120  void setImageSize(r_Range width, r_Range height);
121 
122  void setMArray(r_GMarray& myArray);
123  void addPolygon(const r_Polygon&);
124 
125  bool fillMArrayInside(const string& bgr = "") throw(r_Error);
126  bool fillMArrayOutside(const string& bgr = "") throw(r_Error);
127 
128  // just for debugging
129  void print(int onlyLine=-1);
130  void printLine(r_Range line);
131 
132 private:
133  bool compute();
134  void eraseLine( r_Range, r_Range, r_Range y, const string& bgr ) throw(r_Error);
135 
136  r_Range imgWidth,imgHeight;
137  r_Range imgX,imgY; // - the origin of the mdd domain
138 
139  r_GMarray *mArray;
140 
141  std::list<r_Polygon> polygons;
142 
143  struct TablePoint
144  {
145  r_Range x;
146  int inside; // where the inside is, -1 left, +1 right, 0 hor. line
147  int cosFunc;
148  bool operator==(TablePoint&);
149  };
150 
151  r_Range tableWidth;
152  r_Range tableHeight;
153  TablePoint *table;
154  int *usedCount;
155  TablePoint& getTP(r_Range line, r_Range column);
156 
157  bool initTable();
158  void clearTables();
159  int computeTableWidth();
160 
161 
162  int computeInside(r_Point start, r_Point end);
163  void computeOneSegment(r_Point start, r_Point end, int inside);
164  void computeOneHorSegment(r_Point start, r_Point end);
165  void ordonateLine(int line);
166  void minimizeLine(int line);
167  void replacePoint(r_Range line,r_Range col,int inside, int cosFunc);
168  void addPoint(r_Range line,r_Range col,int inside, int cosFunc);
169 
170 };
171 
172 #endif
bool operator==(const OId::OIdPrimitive one, const OId &two)
template std::ostream & operator<<(const vector< KeyObject > &, std::ostream &)