00001 #ifndef U2D_CORE_H
00002 #define U2D_CORE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <math.h>
00029 #include <stdlib.h>
00030
00031
00032 #define DEFAULT_TOLL 0.000001
00033 #define PI 3.14159265358979
00034 #define MAX_PRIM_STRING 1024
00035 #define CIRCLE_APPROX 100000.0
00036 #define ELLIPSE_APPROX 100000.0
00037
00038 #define PR_LINE 1
00039 #define PR_CIRCLE 2
00040 #define PR_ELLIPSE 3
00041 #define PR_DATA 4
00042
00043
00044 #define SUCESS 0
00045
00046
00047 #define NO_FILE -1
00048 #define INVALID_FILE -2
00049 #define NOT_A_FILE -3
00050 #define NO_EXIST -4
00051
00052
00053 #define NOMEM -10
00054 #define UNKNOWN -256
00055
00056
00057
00058 #define rot_matrixX(angle, X, Y) ((X) * cos((angle) / 360.0 * 2.0 * PI) - (Y) * sin((angle) / 360.0 * 2.0 * PI))
00059 #define rot_matrixY(angle, X, Y) ((Y) * cos((angle) / 360.0 * 2.0 * PI) + (X) * sin((angle) / 360.0 * 2.0 * PI))
00060
00061
00062 typedef struct {
00063 double x;
00064 double y;
00065 } steiner;
00066
00067 typedef struct {
00068 double x;
00069 double y;
00070 double hdata;
00071 } backgrid;
00072
00073 class Primitive {
00074 public:
00075 Primitive();
00076 virtual ~Primitive(){ };
00077
00078
00079 int spline;
00080 double x1;
00081 double y1;
00082 double x2;
00083 double y2;
00084 char primname[34];
00085
00086
00087 double *data;
00088
00089 int maxdata;
00090 int curdata;
00091 double getdata(int x, int y);
00092 void setdata(int x, int y, double value);
00093 int allocatedata(int ndata);
00094
00095
00096 class Primitive *nextprimitive;
00097 class Primitive *prevprimitive;
00098 int type;
00099 int id;
00100
00101
00102
00103
00104
00105
00106 unsigned int element;
00107
00108
00109
00110 unsigned int object;
00111
00112
00113 unsigned int object_part;
00114
00115 bool isboundary;
00116
00117 int beginvertex;
00118 int endvertex;
00119
00120
00121 virtual double calc_area(double ref_x, double ref_y)=0;
00122 virtual void reverse()=0;
00123
00124 private:
00125
00126
00127
00128
00129
00130 virtual void find_extremes()=0;
00131 };
00132
00133 class Line : public Primitive {
00134 public:
00135 Line() {
00136 type = PR_LINE;
00137 }
00138 ~Line(){ }
00139 int set_coord(int spli,\
00140 double X1, double Y1,\
00141 double X2, double Y2);
00142 double calc_area(double ref_x, double ref_y);
00143 void reverse();
00144 void find_extremes(){ };
00145 };
00146
00147 class Circle : public Primitive {
00148 public:
00149 Circle() {
00150 type = PR_CIRCLE;
00151 }
00152 ~Circle() { }
00153 int spline;
00154 double radius;
00155 double centerx;
00156 double centery;
00157 double startarc;
00158 double endarc;
00159 int set_coord(int spli, double rad,\
00160 double centx, double centy,\
00161 double sarc, double earc);
00162 double calc_area(double ref_x, double ref_y);
00163 void reverse();
00164 private:
00165 void find_extremes();
00166 };
00167
00168 class Ellipse : public Primitive {
00169 public:
00170 Ellipse() {
00171 type = PR_ELLIPSE;
00172 }
00173 ~Ellipse() { }
00174 int spline;
00175 double semix;
00176 double semiy;
00177 double centerx;
00178 double centery;
00179 double startarc;
00180 double endarc;
00181 int set_coord(int spli,\
00182 double semx, double semy,\
00183 double centx, double centy,\
00184 double sarc, double earc);
00185 double calc_area(double ref_x, double ref_y);
00186 void reverse();
00187 private:
00188 void find_extremes();
00189 };
00190
00191 class Data : public Primitive {
00192 public:
00193 Data() {
00194 type = PR_DATA;
00195 filename = NULL;
00196 points = NULL;
00197 }
00198 ~Data() {
00199 if(filename != NULL){
00200 free(this->filename);
00201 }
00202 if(points != NULL){
00203 free(this->points);
00204 }
00205 }
00206 char *filename;
00207 int npoints;
00208 double *points;
00209 double trasx;
00210 double trasy;
00211 double rotation;
00212 int set_coord(const char* fname,\
00213 double tx, double ty,\
00214 double rot);
00215 double calc_area(double ref_x, double ref_y);
00216 void reverse();
00217 private:
00218 int allocatefilename(int length);
00219 void find_extremes();
00220 };
00221
00222
00223
00224
00225
00226
00227 bool isnear(double toll, double x1, double y1);
00228 bool isnear(double toll, double x1, double y1, double x2, double y2);
00229 bool isnear(double toll, Primitive *primX, Primitive *primY);
00230
00231
00232
00233
00234 double triangle_area(double ref_x, double ref_y,\
00235 double x1, double y1,\
00236 double x2, double y2);
00237
00238 class u2d_Core {
00239 public:
00240 u2d_Core();
00241 ~u2d_Core();
00242
00243
00244 Primitive *add_prim(int type);
00245 void del_prim(Primitive *oldprim);
00246 void move_insert_down_prim(Primitive *position, Primitive *insertion);
00247 int get_prim_number();
00248 Primitive *get_prim_list_start();
00249 Primitive *get_prim_list_end();
00250 char *get_prim_string(Primitive *curprim);
00251 Primitive *get_prim_by_label(const char *label);
00252 int get_vertex_n();
00253
00254
00255 int steiner_n;
00256 int backgrid_n;
00257 steiner *steiners;
00258 backgrid *backgrids;
00259
00260
00261 void find_objects();
00262
00263 int allocate_steiner(int number);
00264 int allocate_backgrid(int number);
00265 void set_steiner(int position, double x, double y);
00266 void set_backgrid(int position, double x, double y, double hdata);
00267
00268 void debug_cb();
00269
00270 private:
00271
00272 Primitive *firstprimitive;
00273 Primitive *lastprimitive;
00274 Primitive *new_prim(int type);
00275 void insert_down_prim(Primitive *position, Primitive *insertion);
00276 void remove_prim(Primitive *oldprim);
00277 char prim_string[1024];
00278 int elements;
00279 int vertex_n;
00280 int globalprimid;
00281
00282
00283 unsigned int last_object;
00284
00285
00286 int steiner_max_n;
00287 int backgrid_max_n;
00288 };
00289
00290 #endif