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) GTK_CHECK_CAST (obj, gtk_plot_dt_get_type (), GtkPlotDT) 29 #define GTK_TYPE_PLOT_DT (gtk_plot_dt_get_type ()) 30 31 #define GTK_PLOT_DT_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_plot_dt_get_type(), GtkPlotDTClass) 32 #define GTK_IS_PLOT_DT(obj) GTK_CHECK_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 struct _GtkPlotDTnode 43 { 44 gdouble x, y, z; /* actual coordinates */ 45 gdouble px, py, pz; /* pixel coordinates */ 46 gint id; /* some kind of 'meta-data' for external use */ 47 gint a,b,c,d; /* neighbour node indices in quadrilateral mode */ 48 gint boundary_marker; 49 }; 50 51 struct _GtkPlotDTtriangle 52 { 53 gint a, b, c; 54 GtkPlotDTnode *na, *nb, *nc; 55 double radius; /* radius-square */ 56 GtkPlotDTnode ccenter; /* center of circle */ 57 double area; /* twice the triangle's area */ 58 GtkPlotDTnode min,max; /* the bounding box */ 59 GtkPlotDTtriangle *nn[3]; /* neighbours */ 60 gboolean visited; /* auxiliary variable for sweeping though list */ 61 }; 62 63 /* a progress indicator function with optional 'cancel' functionality 64 * 65 * returns '0' for normal operation 66 * or any arbitrary code to request immediate abortion 67 */ 68 typedef gint (*GtkPlotDTprogressbarFunc) (double progress); 69 70 71 /* data needed for a delaunay triangulation 72 * 73 * the nodes are held in an expanding array (use gtk_plot_dt_expand()!) 74 * 75 */ 76 struct _GtkPlotDT 77 { 78 GtkObject object; 79 80 gboolean quadrilateral; 81 gboolean subsampling; 82 83 gint node_0; /* lowest node-index (may be negative!) */ 84 gint node_cnt; /* number of nodes */ 85 gint node_max; /* maximum number of nodes */ 86 GtkPlotDTnode *nodes; /* the nodes themselves */ 87 GtkPlotDTnode *tmp_nodes; /* index<0: tmpnodes[-1-index] */ 88 89 GList *triangles; 90 GCompareFunc compare_func; 91 92 GtkPlotDTprogressbarFunc pbar; 93 }; 94 95 struct _GtkPlotDTClass 96 { 97 GtkObjectClass parent_class; 98 99 gboolean (* add_node) (GtkPlotDT *data, 100 GtkPlotDTnode node); 101 GtkPlotDTnode*(* get_node) (GtkPlotDT *data, 102 gint idx); 103 gboolean (* triangulate) (GtkPlotDT *data); 104 void (* clear) (GtkPlotDT *data); 105 }; 106 107 GtkType gtk_plot_dt_get_type (void); 108 GtkObject* gtk_plot_dt_new (gint num); 109 void gtk_plot_dt_set_quadrilateral (GtkPlotDT *data, 110 gboolean set); 111 void gtk_plot_dt_set_subsampling (GtkPlotDT *data, 112 gboolean set); 113 gboolean gtk_plot_dt_add_node (GtkPlotDT *data, 114 GtkPlotDTnode node); 115 GtkPlotDTnode * gtk_plot_dt_get_node (GtkPlotDT *data, 116 gint idx); 117 gboolean gtk_plot_dt_triangulate (GtkPlotDT *data); 118 void gtk_plot_dt_clear (GtkPlotDT *data); 119 120 121 #ifdef __cplusplus 122 } 123 #endif /* __cplusplus */ 124 125 126 #endif /* __GTK_PLOT_DELAUNAY_H__ */ 127