1 /* gtkplotdt - delaunay triangulization algorithm for gtk+ 2 * Copyright 2001 Andy Thaller <thaller@ph.tum.de> 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library 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 GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public 15 * License along with this library; if not, write to the 16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 * Boston, MA 02111-1307, USA. 18 */ 19 20 #ifndef __GTK_PLOT_DELAUNAY_H__ 21 #define __GTK_PLOT_DELAUNAY_H__ 22 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif /* __cplusplus */ 27 28 #define GTK_PLOT_DT(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, gtk_plot_dt_get_type (), GtkPlotDT) 29 #define G_TYPE_PLOT_DT (gtk_plot_dt_get_type ()) 30 31 #define GTK_PLOT_DT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, gtk_plot_dt_get_type(), GtkPlotDTClass) 32 #define GTK_IS_PLOT_DT(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, gtk_plot_dt_get_type ()) 33 34 35 typedef struct _GtkPlotDTnode GtkPlotDTnode; 36 typedef struct _GtkPlotDTsegment GtkPlotDTsegment; 37 typedef struct _GtkPlotDTtriangle GtkPlotDTtriangle; 38 typedef struct _GtkPlotDT GtkPlotDT; 39 typedef struct _GtkPlotDTClass GtkPlotDTClass; 40 41 /* A 2D-node for the delaunay triangulation */ 42 /** 43 * GtkPlotDTnode: 44 * 45 * The GtkPlotDTnode struct contains only private data. 46 * It should only be accessed through the functions described below. 47 */ 48 struct _GtkPlotDTnode 49 { 50 /*< private >*/ 51 gdouble x, y, z; /* actual coordinates */ 52 gdouble px, py, pz; /* pixel coordinates */ 53 gint id; /* some kind of 'meta-data' for external use */ 54 gint a,b,c,d; /* neighbour node indices in quadrilateral mode */ 55 gint boundary_marker; 56 }; 57 58 /** 59 * GtkPlotDTtriangle: 60 * 61 * The GtkPlotDTtriangle struct contains only private data. 62 * It should only be accessed through the functions described below. 63 */ 64 struct _GtkPlotDTtriangle 65 { 66 /*< private >*/ 67 gint a, b, c; 68 GtkPlotDTnode *na, *nb, *nc; 69 double radius; /* radius-square */ 70 GtkPlotDTnode ccenter; /* center of circle */ 71 double area; /* twice the triangle's area */ 72 GtkPlotDTnode min,max; /* the bounding box */ 73 GtkPlotDTtriangle *nn[3]; /* neighbours */ 74 gboolean visited; /* auxiliary variable for sweeping though list */ 75 }; 76 77 /* a progress indicator function with optional 'cancel' functionality 78 * 79 * returns '0' for normal operation 80 * or any arbitrary code to request immediate abortion 81 */ 82 typedef gint (*GtkPlotDTprogressbarFunc) (double progress); 83 84 85 /* data needed for a delaunay triangulation 86 * 87 * the nodes are held in an expanding array (use gtk_plot_dt_expand()!) 88 * 89 */ 90 struct _GtkPlotDT 91 { 92 GtkObject object; 93 94 gboolean quadrilateral; 95 gboolean subsampling; 96 97 gint node_0; /* lowest node-index (may be negative!) */ 98 gint node_cnt; /* number of nodes */ 99 gint node_max; /* maximum number of nodes */ 100 GtkPlotDTnode *nodes; /* the nodes themselves */ 101 GtkPlotDTnode *tmp_nodes; /* index<0: tmpnodes[-1-index] */ 102 103 GList *triangles; 104 GCompareFunc compare_func; 105 106 GtkPlotDTprogressbarFunc pbar; 107 }; 108 109 struct _GtkPlotDTClass 110 { 111 GtkObjectClass parent_class; 112 113 gboolean (* add_node) (GtkPlotDT *data, 114 GtkPlotDTnode node); 115 GtkPlotDTnode*(* get_node) (GtkPlotDT *data, 116 gint idx); 117 gboolean (* triangulate) (GtkPlotDT *data); 118 void (* clear) (GtkPlotDT *data); 119 }; 120 121 GType gtk_plot_dt_get_type (void); 122 GtkObject* gtk_plot_dt_new (gint num); 123 void gtk_plot_dt_set_quadrilateral (GtkPlotDT *dt, 124 gboolean set); 125 void gtk_plot_dt_set_subsampling (GtkPlotDT *dt, 126 gboolean set); 127 gboolean gtk_plot_dt_add_node (GtkPlotDT *data, 128 GtkPlotDTnode node); 129 GtkPlotDTnode * gtk_plot_dt_get_node (GtkPlotDT *data, 130 gint idx); 131 gboolean gtk_plot_dt_triangulate (GtkPlotDT *data); 132 void gtk_plot_dt_clear (GtkPlotDT *data); 133 134 135 #ifdef __cplusplus 136 } 137 #endif /* __cplusplus */ 138 139 140 #endif /* __GTK_PLOT_DELAUNAY_H__ */ 141