pcb 4.1.1
An interactive printed circuit board layout editor.

gts.h

Go to the documentation of this file.
00001 /* GTS - Library for the manipulation of triangulated surfaces
00002  * Copyright (C) 1999 Stéphane Popinet
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public
00015  * License along with this library; if not, write to the
00016  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  * Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef __GTS_H__
00021 #define __GTS_H__
00022 
00023 #include <stdio.h>
00024 #include <glib.h>
00025 
00026 #define GTS_MAJOR_VERSION 0
00027 #define GTS_MINOR_VERSION 7
00028 #define GTS_MICRO_VERSION 6
00029 
00030 #ifdef __cplusplus
00031 extern "C" {
00032 #endif /* __cplusplus */
00033 
00034 /* Added based on glib.h by M J Loehr 01/01/01 */
00035 /* GTS version.
00036  * we prefix variable declarations so they can
00037  * properly get exported in windows dlls.
00038  */
00039 #ifdef NATIVE_WIN32
00040 #  ifdef GTS_COMPILATION
00041 #    define GTS_C_VAR __declspec(dllexport)
00042 #  else /* not GTS_COMPILATION */
00043 #    define GTS_C_VAR extern __declspec(dllimport)
00044 #  endif /* not GTS_COMPILATION */
00045 #else /* not NATIVE_WIN32 */
00046 #  define GTS_C_VAR extern
00047 #endif /* not NATIVE_WIN32 */
00048 
00049 GTS_C_VAR const guint gts_major_version;
00050 GTS_C_VAR const guint gts_minor_version;
00051 GTS_C_VAR const guint gts_micro_version;
00052 GTS_C_VAR const guint gts_interface_age;
00053 GTS_C_VAR const guint gts_binary_age;
00054 
00055 #define GTS_CHECK_VERSION(major,minor,micro)    \
00056     (gts_major_version > (major) || \
00057     (gts_major_version == (major) && gts_minor_version > (minor)) || \
00058     (gts_major_version == (major) && gts_minor_version == (minor) && \
00059      gts_micro_version >= (micro)))
00060 
00061 #define GTS_COMMENTS  "#!"
00062 #define GTS_MAINTAINER "popinet@users.sourceforge.net"
00063 
00064 
00065 
00066 
00067 void gts_predicates_init();
00068 
00069 
00070 /* Class declarations for base types */
00071 
00072 typedef struct _GtsObjectClassInfo     GtsObjectClassInfo;
00073 typedef struct _GtsObject        GtsObject;
00074 typedef struct _GtsObjectClass   GtsObjectClass;
00075 typedef struct _GtsPoint         GtsPoint;
00076 typedef struct _GtsPointClass    GtsPointClass;
00077 typedef struct _GtsVertex        GtsVertex;
00078 typedef struct _GtsVertexClass   GtsVertexClass;
00079 typedef struct _GtsSegment       GtsSegment;
00080 typedef struct _GtsSegmentClass  GtsSegmentClass;
00081 typedef struct _GtsEdge          GtsEdge;
00082 typedef struct _GtsEdgeClass     GtsEdgeClass;
00083 typedef struct _GtsTriangle      GtsTriangle;
00084 typedef struct _GtsTriangleClass GtsTriangleClass;
00085 typedef struct _GtsFace          GtsFace;
00086 typedef struct _GtsFaceClass     GtsFaceClass;
00087 typedef struct _GtsBBox          GtsBBox;
00088 typedef struct _GtsBBoxClass     GtsBBoxClass;
00089 typedef struct _GtsSurface       GtsSurface;
00090 typedef struct _GtsSurfaceClass  GtsSurfaceClass;
00091 
00092 typedef void         (*GtsObjectClassInitFunc) (GtsObjectClass * objclass);
00093 typedef void         (*GtsObjectInitFunc)      (GtsObject * obj);
00094 typedef void         (*GtsArgSetFunc)          (GtsObject * obj);
00095 typedef void         (*GtsArgGetFunc)          (GtsObject * obj);
00096 
00097 typedef gdouble                  GtsVector[3];
00098 typedef gdouble                  GtsVector4[4];
00099 typedef GtsVector4               GtsMatrix;
00107 typedef gdouble                  (*GtsKeyFunc)    (gpointer item,
00108                                                    gpointer data);
00109 typedef enum 
00110 { 
00111   GTS_OUT = -1,
00112   GTS_ON = 0,
00113   GTS_IN = 1
00114 } GtsIntersect;
00115 
00116 typedef struct _GtsColor         GtsColor;
00117 
00118 struct _GtsColor {
00119   gfloat r, g, b;
00120 };
00121 
00122 typedef gint   (*GtsFunc)              (gpointer item,
00123                                         gpointer data);
00124 
00125 /* misc.c */
00126 
00127 typedef struct _GtsFile GtsFile;
00128 
00129 typedef enum {
00130   GTS_NONE   = 1 << 8,
00131   GTS_INT    = 1 << 9,
00132   GTS_UINT   = 1 << 10,
00133   GTS_FLOAT  = 1 << 11,
00134   GTS_DOUBLE = 1 << 12,
00135   GTS_STRING = 1 << 13,
00136   GTS_FILE   = 1 << 14,
00137   GTS_ERROR  = 1 << 15
00138 } GtsTokenType;
00139 
00140 struct _GtsFile {
00141   FILE * fp;
00142   gchar * s, * s1;
00143   guint line, pos;
00144   GString * token;
00145   GtsTokenType type;
00146   gchar * error;
00147 
00148   guint curline, curpos;
00149   guint scope, scope_max;
00150   gint next_token;
00151   gchar * delimiters;
00152   gchar * comments;
00153   gchar * tokens;
00154 };
00155 
00156 typedef struct _GtsFileVariable GtsFileVariable;
00157 
00158 struct _GtsFileVariable {
00159   GtsTokenType type;
00160   gchar name[30];
00161   gboolean unique;
00162   gpointer data;
00163   gboolean set;
00164   guint line, pos;
00165 };
00166 
00167 
00168 GtsFile *      gts_file_new               (FILE * fp);
00169 GtsFile *      gts_file_new_from_string   (const gchar * s);
00170 void           gts_file_verror            (GtsFile * f,
00171                                            const gchar * format,
00172                                            va_list args);
00173 void           gts_file_error             (GtsFile * f,
00174                                            const gchar * format,
00175                                            ...);
00176 gint           gts_file_getc              (GtsFile * f);
00177 guint          gts_file_read              (GtsFile * f, 
00178                                            gpointer ptr, 
00179                                            guint size, 
00180                                            guint nmemb);
00181 gint           gts_file_getc_scope        (GtsFile * f);
00182 void           gts_file_next_token        (GtsFile * f);
00183 void           gts_file_first_token_after (GtsFile * f, 
00184                                            GtsTokenType type);
00185 void           gts_file_assign_start      (GtsFile * f, 
00186                                            GtsFileVariable * vars);
00187 GtsFileVariable * gts_file_assign_next    (GtsFile * f, 
00188                                            GtsFileVariable * vars);
00189 void           gts_file_assign_variables  (GtsFile * f, 
00190                                            GtsFileVariable * vars);
00191 void           gts_file_variable_error    (GtsFile * f, 
00192                                            GtsFileVariable * vars,
00193                                            const gchar * name,
00194                                            const gchar * format,
00195                                            ...);
00196 void           gts_file_destroy           (GtsFile * f);
00197 
00198 /* Objects: object.c */
00199 
00200 #ifdef GTS_CHECK_CASTS
00201 #  define GTS_OBJECT_CAST(obj, type, klass) ((type *) gts_object_check_cast (obj, klass))
00202 #  define GTS_OBJECT_CLASS_CAST(objklass, type, klass) ((type *) gts_object_class_check_cast (objklass, klass))
00203 #else  /* not GTS_CHECK_CASTS */
00204 #  define GTS_OBJECT_CAST(obj, type, klass)             ((type *) (obj))
00205 #  define GTS_OBJECT_CLASS_CAST(objklass, type, klass)  ((type *) (objklass))
00206 #endif /* not GTS_CHECK_CASTS */
00207 
00208 #define GTS_CLASS_NAME_LENGTH 40
00209 #define GTS_OBJECT(obj)          GTS_OBJECT_CAST (obj,\
00210                                                   GtsObject,\
00211                                                   gts_object_class ())
00212 #define GTS_OBJECT_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
00213                                                         GtsObjectClass,\
00214                                                         gts_object_class())
00215 #define GTS_IS_OBJECT(obj) (gts_object_is_from_class (obj,\
00216                                                       gts_object_class ()))
00217 
00218 typedef enum
00219 {
00220   GTS_DESTROYED         = 1 << 0,
00221   GTS_USER_FLAG         = 1 /* user flags start from here */
00222 } GtsObjectFlags;
00223 
00224 #define GTS_OBJECT_FLAGS(obj)             (GTS_OBJECT (obj)->flags)
00225 #define GTS_OBJECT_DESTROYED(obj)         ((GTS_OBJECT_FLAGS (obj) & GTS_DESTROYED) != 0)
00226 #define GTS_OBJECT_SET_FLAGS(obj,flag)    G_STMT_START{ (GTS_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END
00227 #define GTS_OBJECT_UNSET_FLAGS(obj,flag)  G_STMT_START{ (GTS_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END
00228 
00229 struct _GtsObjectClassInfo {
00230   gchar name[GTS_CLASS_NAME_LENGTH];
00231   guint object_size;
00232   guint class_size;
00233   GtsObjectClassInitFunc class_init_func;
00234   GtsObjectInitFunc object_init_func;
00235   GtsArgSetFunc arg_set_func;
00236   GtsArgGetFunc arg_get_func;
00237 };
00238 
00239 struct _GtsObject {
00240   GtsObjectClass * klass;
00241 
00242   gpointer reserved;
00243   guint32 flags;
00244 };
00245 
00246 struct _GtsObjectClass {
00247   GtsObjectClassInfo info;
00248   GtsObjectClass * parent_class;
00249 
00250   void        (* clone)      (GtsObject *, GtsObject *);
00251   void        (* destroy)    (GtsObject *);
00252   void        (* read)       (GtsObject **, GtsFile *);
00253   void        (* write)      (GtsObject *, FILE *);
00254   GtsColor    (* color)      (GtsObject *);
00255   void        (* attributes) (GtsObject *, GtsObject *);
00256 };
00257 
00258 gpointer         gts_object_class_new      (GtsObjectClass * parent_class,
00259                                             GtsObjectClassInfo * info);
00260 GtsObjectClass * gts_object_class          (void);
00261 gpointer         gts_object_check_cast     (gpointer object, 
00262                                             gpointer klass);
00263 gpointer         gts_object_class_check_cast (gpointer klass, 
00264                                               gpointer from);
00265 
00266 static inline
00267 gpointer gts_object_is_from_class (gpointer object,
00268                                    gpointer klass)
00269 {
00270   GtsObjectClass * c;
00271 
00272   g_return_val_if_fail (klass != NULL, NULL);
00273 
00274   if (object == NULL)
00275     return NULL;
00276 
00277   c = ((GtsObject *) object)->klass;
00278 
00279   g_return_val_if_fail (c != NULL, NULL);
00280 
00281   while (c) {
00282     if (c == klass)
00283       return object;
00284     c = c->parent_class;
00285   }
00286 
00287   return NULL;
00288 }
00289 
00290 static inline
00291 gpointer gts_object_class_is_from_class (gpointer klass,
00292                                          gpointer from)
00293 {
00294   GtsObjectClass * c;
00295 
00296   g_return_val_if_fail (klass != NULL, NULL);
00297   g_return_val_if_fail (from != NULL, NULL);
00298 
00299   c = (GtsObjectClass *) klass;
00300   while (c) {
00301     if (c == from)
00302       return klass;
00303     c = c->parent_class;
00304   }
00305 
00306   return NULL;
00307 }
00308 
00309 GtsObjectClass * gts_object_class_from_name     (const gchar * name);
00310 
00311 GtsObject *      gts_object_new                 (GtsObjectClass * klass);
00312 GtsObject *      gts_object_clone               (GtsObject * object);
00313 void             gts_object_attributes          (GtsObject * object, 
00314                                                  GtsObject * from);
00315 void             gts_object_init                (GtsObject * object, 
00316                                                  GtsObjectClass * klass);
00317 void             gts_object_reset_reserved      (GtsObject * object);
00318 void             gts_object_destroy             (GtsObject * object);
00319 void             gts_finalize                   (void);
00320 
00321 /* Ranges: surface.c */
00322 typedef struct _GtsRange               GtsRange;
00323 
00324 struct _GtsRange {
00325   gdouble min, max, sum, sum2, mean, stddev;
00326   guint n;
00327 };
00328 
00329 void gts_range_init         (GtsRange * r);
00330 void gts_range_reset        (GtsRange * r);
00331 void gts_range_add_value    (GtsRange * r, 
00332                              gdouble val);
00333 void gts_range_update       (GtsRange * r);
00334 void gts_range_print        (GtsRange * r, 
00335                              FILE * fptr);
00336 
00337 /* Points: point.c */
00338 
00339 #define GTS_IS_POINT(obj) (gts_object_is_from_class (obj,\
00340                                                      gts_point_class ()))
00341 #define GTS_POINT(obj)              GTS_OBJECT_CAST (obj,\
00342                                                      GtsPoint,\
00343                                                      gts_point_class ())
00344 #define GTS_POINT_CLASS(klass)      GTS_OBJECT_CLASS_CAST (klass,\
00345                                                            GtsPointClass,\
00346                                                            gts_point_class ())
00347 
00348 struct _GtsPoint {
00349   GtsObject object;
00350 
00351   gdouble x, y, z; /* must be contiguous (cast to robust functions) */
00352 };
00353 
00354 struct _GtsPointClass {
00355   GtsObjectClass parent_class;
00356   gboolean binary;
00357 };
00358 
00359 GtsPointClass * gts_point_class                      (void);
00360 GtsPoint *    gts_point_new                          (GtsPointClass * klass,
00361                                                       gdouble x, 
00362                                                       gdouble y, 
00363                                                       gdouble z);
00364 void          gts_point_set                          (GtsPoint * p, 
00365                                                       gdouble x, 
00366                                                       gdouble y, 
00367                                                       gdouble z);
00368 #define       gts_point_is_in_rectangle(p, p1, p2)   ((p)->x >= (p1)->x &&\
00369                                                       (p)->x <= (p2)->x &&\
00370                                                       (p)->y >= (p1)->y &&\
00371                                                       (p)->y <= (p2)->y &&\
00372                                                       (p)->z >= (p1)->z &&\
00373                                                       (p)->z <= (p2)->z)
00374 GtsPoint *    gts_segment_triangle_intersection      (GtsSegment * s,
00375                                                       GtsTriangle * t,
00376                                                       gboolean boundary,
00377                                                       GtsPointClass * klass);
00378 void          gts_point_transform                    (GtsPoint * p, 
00379                                                       GtsMatrix * m);
00380 gdouble       gts_point_distance                     (GtsPoint * p1,
00381                                                       GtsPoint * p2);
00382 gdouble       gts_point_distance2                    (GtsPoint * p1,
00383                                                       GtsPoint * p2);
00384 gdouble       gts_point_orientation_3d               (GtsPoint * p1,
00385                                                       GtsPoint * p2,
00386                                                       GtsPoint * p3,
00387                                                       GtsPoint * p4);
00388 gint          gts_point_orientation_3d_sos           (GtsPoint * p1,
00389                                                       GtsPoint * p2,
00390                                                       GtsPoint * p3,
00391                                                       GtsPoint * p4);
00392 GtsIntersect  gts_point_is_in_triangle               (GtsPoint * p,
00393                                                       GtsTriangle * t);
00394 gdouble       gts_point_in_circle                    (GtsPoint * p, 
00395                                                       GtsPoint * p1,
00396                                                       GtsPoint * p2,
00397                                                       GtsPoint * p3);
00398 gdouble       gts_point_in_sphere                    (GtsPoint * p, 
00399                                                       GtsPoint * p1,
00400                                                       GtsPoint * p2,
00401                                                       GtsPoint * p3,
00402                                                       GtsPoint * p4);
00403 gdouble       gts_point_in_triangle_circle           (GtsPoint * p, 
00404                                                       GtsTriangle * t);
00405 gdouble       gts_point_orientation                  (GtsPoint * p1,
00406                                                       GtsPoint * p2,
00407                                                       GtsPoint * p3);
00408 gint          gts_point_orientation_sos              (GtsPoint * p1,
00409                                                       GtsPoint * p2,
00410                                                       GtsPoint * p3);
00411 gdouble       gts_point_segment_distance2            (GtsPoint * p, 
00412                                                       GtsSegment * s);
00413 gdouble       gts_point_segment_distance             (GtsPoint * p, 
00414                                                       GtsSegment * s);
00415 void          gts_point_segment_closest              (GtsPoint * p, 
00416                                                       GtsSegment * s,
00417                                                       GtsPoint * closest);
00418 gdouble       gts_point_triangle_distance2           (GtsPoint * p, 
00419                                                       GtsTriangle * t);
00420 gdouble       gts_point_triangle_distance            (GtsPoint * p, 
00421                                                       GtsTriangle * t);
00422 void          gts_point_triangle_closest             (GtsPoint * p,
00423                                                       GtsTriangle * t,
00424                                                       GtsPoint * closest);
00425 gboolean      gts_point_is_inside_surface            (GtsPoint * p, 
00426                                                       GNode * tree,
00427                                                       gboolean is_open);
00428 
00429 /* Vertices: vertex.c */
00430 
00431 #define GTS_IS_VERTEX(obj)   (gts_object_is_from_class (obj,\
00432                                                         gts_vertex_class ()))
00433 #define GTS_VERTEX(obj)             GTS_OBJECT_CAST (obj,\
00434                                                      GtsVertex,\
00435                                                      gts_vertex_class ())
00436 #define GTS_VERTEX_CLASS(klass)     GTS_OBJECT_CLASS_CAST (klass,\
00437                                                            GtsVertexClass,\
00438                                                            gts_vertex_class ())
00439 struct _GtsVertex {
00440   GtsPoint p;
00441   
00442   GSList * segments;
00443 };
00444 
00445 struct _GtsVertexClass {
00446   GtsPointClass parent_class;
00447 
00448   void        (* intersection_attributes) (GtsVertex *, 
00449                                            GtsObject *, 
00450                                            GtsObject *);
00451 };
00452 
00453 GTS_C_VAR 
00454 gboolean      gts_allow_floating_vertices;
00455 
00456 GtsVertexClass * gts_vertex_class          (void);
00457 GtsVertex *   gts_vertex_new               (GtsVertexClass * klass,
00458                                             gdouble x,
00459                                             gdouble y,
00460                                             gdouble z);
00461 void          gts_vertex_replace           (GtsVertex * v, 
00462                                             GtsVertex * with);
00463 gboolean      gts_vertex_is_unattached     (GtsVertex * v);
00464 GtsSegment *  gts_vertices_are_connected   (GtsVertex * v1,
00465                                             GtsVertex * v2);
00466 GSList *      gts_vertex_triangles         (GtsVertex * v,
00467                                             GSList * list);
00468 GSList *      gts_vertex_faces             (GtsVertex * v,
00469                                             GtsSurface * surface,
00470                                             GSList * list);
00471 GSList *      gts_vertex_neighbors         (GtsVertex * v, 
00472                                             GSList * list,
00473                                             GtsSurface * surface);
00474 GSList *      gts_vertices_from_segments   (GSList * segments);
00475 gboolean      gts_vertex_is_boundary       (GtsVertex * v, 
00476                                             GtsSurface * surface);
00477 GList *       gts_vertices_merge           (GList * vertices, 
00478                                             gdouble epsilon,
00479                                             gboolean (* check) (GtsVertex *, GtsVertex *));
00480 GSList *      gts_vertex_fan_oriented      (GtsVertex * v, 
00481                                             GtsSurface * surface);
00482 guint         gts_vertex_is_contact        (GtsVertex * v, gboolean sever);
00483 
00484 /* GtsVertexNormal: Header */
00485 
00486 typedef struct _GtsVertexNormal         GtsVertexNormal;
00487 
00488 struct _GtsVertexNormal {
00489   /*< private >*/
00490   GtsVertex parent;
00491 
00492   /*< public >*/
00493   GtsVector n;
00494 };
00495 
00496 #define GTS_VERTEX_NORMAL(obj)            GTS_OBJECT_CAST (obj,\
00497                                                  GtsVertexNormal,\
00498                                                  gts_vertex_normal_class ())
00499 #define GTS_IS_VERTEX_NORMAL(obj)         (gts_object_is_from_class (obj,\
00500                                                  gts_vertex_normal_class ()))
00501 
00502 GtsVertexClass * gts_vertex_normal_class  (void);
00503 
00504 /* GtsColorVertex: Header */
00505 
00506 typedef struct _GtsColorVertex         GtsColorVertex;
00507 
00508 struct _GtsColorVertex {
00509   /*< private >*/
00510   GtsVertex parent;
00511 
00512   /*< public >*/
00513   GtsColor c;
00514 };
00515 
00516 #define GTS_COLOR_VERTEX(obj)            GTS_OBJECT_CAST (obj,\
00517                                                  GtsColorVertex,\
00518                                                  gts_color_vertex_class ())
00519 #define GTS_IS_COLOR_VERTEX(obj)         (gts_object_is_from_class (obj,\
00520                                                  gts_color_vertex_class ()))
00521 
00522 GtsVertexClass * gts_color_vertex_class  (void);
00523 
00524 /* Segments: segment.c */
00525 
00526 #define GTS_IS_SEGMENT(obj) (gts_object_is_from_class (obj,\
00527                                                        gts_segment_class ()))
00528 #define GTS_SEGMENT(obj)          GTS_OBJECT_CAST (obj,\
00529                                                    GtsSegment,\
00530                                                    gts_segment_class ())
00531 #define GTS_SEGMENT_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
00532                                                          GtsSegmentClass,\
00533                                                          gts_segment_class ())
00534 
00535 struct _GtsSegment {
00536   GtsObject object;
00537 
00538   GtsVertex * v1;
00539   GtsVertex * v2;
00540 };
00541 
00542 struct _GtsSegmentClass {
00543   GtsObjectClass parent_class;
00544 };
00545 
00546 GtsSegmentClass * gts_segment_class                  (void);
00547 GtsSegment *  gts_segment_new                        (GtsSegmentClass * klass,
00548                                                       GtsVertex * v1, 
00549                                                       GtsVertex * v2);
00550 #define       gts_segment_connect(s, e1, e2)         (((s)->v1 == e1 &&\
00551                                                        (s)->v2 == e2) || \
00552                                                       ((s)->v1 == e2 &&\
00553                                                        (s)->v2 == e1))
00554 #define       gts_segments_are_identical(s1, s2)     (((s1)->v1 == (s2)->v1 &&\
00555                                                        (s1)->v2 == (s2)->v2)\
00556                                                       ||\
00557                                                       ((s1)->v1 == (s2)->v2 &&\
00558                                                        (s1)->v2 == (s2)->v1))
00559 #define       gts_segments_touch(s1, s2)             ((s1)->v1 == (s2)->v1 ||\
00560                                                       (s1)->v1 == (s2)->v2 ||\
00561                                                       (s1)->v2 == (s2)->v1 ||\
00562                                                       (s1)->v2 == (s2)->v2)
00563 GtsIntersect  gts_segments_are_intersecting          (GtsSegment * s1,
00564                                                       GtsSegment * s2);
00565 GtsSegment *  gts_segment_is_duplicate               (GtsSegment * s);
00566 GtsVertex *   gts_segment_midvertex                  (GtsSegment * s,
00567                                                       GtsVertexClass * klass);
00568 GSList *      gts_segments_from_vertices             (GSList * vertices);
00569 gboolean      gts_segment_is_ok                      (GtsSegment * s);
00570 
00571 /* Edges: edge.c */
00572 
00573 #define GTS_IS_EDGE(obj)  (gts_object_is_from_class (obj,\
00574                                                      gts_edge_class ()))
00575 #define GTS_EDGE(obj)            GTS_OBJECT_CAST (obj,\
00576                                                   GtsEdge,\
00577                                                   gts_edge_class ())
00578 #define GTS_EDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
00579                                                         GtsEdgeClass,\
00580                                                         gts_edge_class ())
00581 
00582 struct _GtsEdge {
00583   GtsSegment segment;
00584 
00585   GSList * triangles;
00586 };
00587 
00588 struct _GtsEdgeClass {
00589   GtsSegmentClass parent_class;
00590 };
00591 
00592 GTS_C_VAR 
00593 gboolean      gts_allow_floating_edges;
00594 
00595 GtsEdgeClass * gts_edge_class                     (void);
00596 GtsEdge *     gts_edge_new                        (GtsEdgeClass * klass,
00597                                                    GtsVertex * v1,
00598                                                    GtsVertex * v2);
00605 #define       gts_edge_is_unattached(s) ((s)->triangles == NULL ? TRUE : FALSE)
00606 GtsFace *     gts_edge_has_parent_surface         (GtsEdge * e, 
00607                                                    GtsSurface * surface);
00608 GtsFace *     gts_edge_has_any_parent_surface     (GtsEdge * e);
00609 GtsFace *     gts_edge_is_boundary                (GtsEdge * e, 
00610                                                    GtsSurface * surface);
00611 void          gts_edge_replace                    (GtsEdge * e,
00612                                                    GtsEdge * with);
00613 GSList *      gts_edges_from_vertices             (GSList * vertices,
00614                                                    GtsSurface * parent);
00615 guint         gts_edge_face_number                (GtsEdge * e,
00616                                                    GtsSurface * s);
00617 gboolean      gts_edge_collapse_is_valid          (GtsEdge * e);
00618 gboolean      gts_edge_collapse_creates_fold      (GtsEdge * e, 
00619                                                    GtsVertex * v,
00620                                                    gdouble max);
00621 GtsEdge *     gts_edge_is_duplicate               (GtsEdge * e);
00622 GList *       gts_edges_merge                     (GList * edges);
00623 gboolean      gts_edge_belongs_to_tetrahedron     (GtsEdge * e);
00624 guint         gts_edge_is_contact                 (GtsEdge * e);
00625 void          gts_edge_swap                       (GtsEdge * e, 
00626                                                    GtsSurface * s);
00627 gboolean      gts_edge_manifold_faces             (GtsEdge * e, 
00628                                                    GtsSurface * s,
00629                                                    GtsFace ** f1, 
00630                                                    GtsFace ** f2);
00631 
00632 /* Triangles: triangle.c */
00633 
00634 #define GTS_IS_TRIANGLE(obj) (gts_object_is_from_class (obj,\
00635                                                         gts_triangle_class ()))
00636 #define GTS_TRIANGLE(obj)         GTS_OBJECT_CAST (obj,\
00637                                                    GtsTriangle,\
00638                                                    gts_triangle_class ())
00639 #define GTS_TRIANGLE_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
00640                                                          GtsTriangleClass,\
00641                                                          gts_triangle_class ())
00642 
00643 struct _GtsTriangle {
00644   GtsObject object;
00645 
00646   GtsEdge * e1;
00647   GtsEdge * e2;
00648   GtsEdge * e3;
00649 };
00650 
00651 struct _GtsTriangleClass {
00652   GtsObjectClass parent_class;
00653 };
00654 
00655 GtsTriangleClass * gts_triangle_class        (void);
00656 void        gts_triangle_set                 (GtsTriangle * triangle, 
00657                                               GtsEdge * e1, 
00658                                               GtsEdge * e2,
00659                                               GtsEdge * e3);
00660 GtsTriangle * gts_triangle_new               (GtsTriangleClass * klass, 
00661                                               GtsEdge * e1, 
00662                                               GtsEdge * e2,
00663                                               GtsEdge * e3);
00664 #define     gts_triangle_vertex(t) (GTS_SEGMENT (GTS_TRIANGLE (t)->e1)->v1 ==\
00665                                     GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v1 || \
00666                                     GTS_SEGMENT (GTS_TRIANGLE (t)->e1)->v2 ==\
00667                                     GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v1 ? \
00668                                     GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v2 :\
00669                                     GTS_SEGMENT (GTS_TRIANGLE (t)->e2)->v1)
00670 GtsVertex *   gts_triangle_vertex_opposite  (GtsTriangle * t, 
00671                                              GtsEdge * e);
00672 GtsEdge *     gts_triangle_edge_opposite    (GtsTriangle * t, 
00673                                              GtsVertex * v);
00674 gdouble       gts_triangles_angle           (GtsTriangle * t1,
00675                                              GtsTriangle * t2);
00676 gboolean      gts_triangles_are_compatible  (GtsTriangle * t1, 
00677                                              GtsTriangle * t2,
00678                                              GtsEdge * e);
00679 gdouble       gts_triangle_area             (GtsTriangle * t);
00680 gdouble       gts_triangle_perimeter        (GtsTriangle * t);
00681 gdouble       gts_triangle_quality          (GtsTriangle * t);
00682 void          gts_triangle_normal           (GtsTriangle * t, 
00683                                              gdouble * x, 
00684                                              gdouble * y, 
00685                                              gdouble * z);
00686 gdouble       gts_triangle_orientation      (GtsTriangle * t);
00687 void          gts_triangle_revert           (GtsTriangle * t);
00688 GSList *      gts_triangles_from_edges      (GSList * edges);
00689 void          gts_triangle_vertices_edges   (GtsTriangle * t, 
00690                                              GtsEdge * e,
00691                                              GtsVertex ** v1, 
00692                                              GtsVertex ** v2, 
00693                                              GtsVertex ** v3,
00694                                              GtsEdge ** e1,
00695                                              GtsEdge ** e2,
00696                                              GtsEdge ** e3);
00697 GtsTriangle * gts_triangle_enclosing        (GtsTriangleClass * klass,
00698                                              GSList * points, 
00699                                              gdouble scale);
00700 guint         gts_triangle_neighbor_number  (GtsTriangle * t);
00701 GSList *      gts_triangle_neighbors        (GtsTriangle * t);
00702 GtsEdge *     gts_triangles_common_edge     (GtsTriangle * t1,
00703                                              GtsTriangle * t2);
00704 GtsTriangle * gts_triangle_is_duplicate     (GtsTriangle * t);
00705 GtsTriangle * gts_triangle_use_edges        (GtsEdge * e1,
00706                                              GtsEdge * e2,
00707                                              GtsEdge * e3);
00708 gboolean      gts_triangle_is_ok            (GtsTriangle * t);
00709 void          gts_triangle_vertices         (GtsTriangle * t,
00710                                              GtsVertex ** v1,
00711                                              GtsVertex ** v2,
00712                                              GtsVertex ** v3);
00713 GtsPoint *    gts_triangle_circumcircle_center (GtsTriangle * t,
00714                                                 GtsPointClass * point_class);
00715 gboolean      gts_triangles_are_folded      (GSList * triangles,
00716                                              GtsVertex * A, GtsVertex * B,
00717                                              gdouble max);
00718 GtsObject *   gts_triangle_is_stabbed       (GtsTriangle * t,
00719                                              GtsPoint * p,
00720                                              gdouble * orientation);
00721 void          gts_triangle_interpolate_height (GtsTriangle * t, 
00722                                                GtsPoint * p);
00723 
00724 /* Faces: face.c */
00725 
00726 #define GTS_IS_FACE(obj) (gts_object_is_from_class (obj,\
00727                                                     gts_face_class ()))
00728 #define GTS_FACE(obj)          GTS_OBJECT_CAST (obj,\
00729                                                 GtsFace,\
00730                                                 gts_face_class ())
00731 #define GTS_FACE_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
00732                                                       GtsFaceClass,\
00733                                                       gts_face_class ())
00734 
00735 struct _GtsFace {
00736   GtsTriangle triangle;
00737 
00738   GSList * surfaces;
00739 };
00740 
00741 struct _GtsFaceClass {
00742   GtsTriangleClass parent_class;
00743 };
00744 
00745 GTS_C_VAR 
00746 gboolean      gts_allow_floating_faces;
00747 
00748 GtsFaceClass * gts_face_class                       (void);
00749 GtsFace *     gts_face_new                          (GtsFaceClass * klass,
00750                                                      GtsEdge * e1,
00751                                                      GtsEdge * e2,
00752                                                      GtsEdge * e3);
00753 gboolean      gts_face_has_parent_surface           (GtsFace * f,
00754                                                      GtsSurface * s);
00755 GSList *      gts_faces_from_edges                  (GSList * edges, 
00756                                                      GtsSurface * s);
00757 guint         gts_face_neighbor_number              (GtsFace * f, 
00758                                                      GtsSurface * s);
00759 GSList *      gts_face_neighbors                    (GtsFace * f, 
00760                                                      GtsSurface * s);
00761 void          gts_face_foreach_neighbor             (GtsFace * f, 
00762                                                      GtsSurface * s, 
00763                                                      GtsFunc func,
00764                                                      gpointer data);
00765 gboolean      gts_face_is_compatible                (GtsFace * f, 
00766                                                      GtsSurface * s);
00767 
00768 /* Matrices: matrix.c */
00769 
00770 #define       gts_vector_cross(C,A,B) ((C)[0] = (A)[1]*(B)[2] - (A)[2]*(B)[1],\
00771                                        (C)[1] = (A)[2]*(B)[0] - (A)[0]*(B)[2],\
00772                                        (C)[2] = (A)[0]*(B)[1] - (A)[1]*(B)[0])
00773 
00774 #define       gts_vector_init(v, p1, p2)   ((v)[0] = (p2)->x - (p1)->x,\
00775                                             (v)[1] = (p2)->y - (p1)->y,\
00776                                             (v)[2] = (p2)->z - (p1)->z)
00777 #define       gts_vector_scalar(v1, v2)    ((v1)[0]*(v2)[0] +\
00778                                             (v1)[1]*(v2)[1] +\
00779                                             (v1)[2]*(v2)[2])
00780 #define       gts_vector_norm(v)   (sqrt ((v)[0]*(v)[0] +\
00781                                           (v)[1]*(v)[1] +\
00782                                           (v)[2]*(v)[2]))
00783 #define       gts_vector_normalize(v) {\
00784   gdouble __gts_n = gts_vector_norm (v);\
00785   if (__gts_n > 0.) {\
00786     (v)[0] /= __gts_n;\
00787     (v)[1] /= __gts_n;\
00788     (v)[2] /= __gts_n;\
00789   }\
00790 }
00791 GtsMatrix * gts_matrix_new (gdouble a00, gdouble a01, gdouble a02, gdouble a03,
00792                             gdouble a10, gdouble a11, gdouble a12, gdouble a13,
00793                             gdouble a20, gdouble a21, gdouble a22, gdouble a23,
00794                             gdouble a30, gdouble a31, gdouble a32, gdouble a33);
00795 void gts_matrix_assign (GtsMatrix * m,
00796                         gdouble a00, gdouble a01, gdouble a02, gdouble a03,
00797                         gdouble a10, gdouble a11, gdouble a12, gdouble a13,
00798                         gdouble a20, gdouble a21, gdouble a22, gdouble a23,
00799                         gdouble a30, gdouble a31, gdouble a32, gdouble a33);
00800 GtsMatrix *   gts_matrix_projection                  (GtsTriangle * t);
00801 GtsMatrix *   gts_matrix_transpose                   (GtsMatrix * m);
00802 gdouble       gts_matrix_determinant                 (GtsMatrix * m);
00803 GtsMatrix *   gts_matrix_inverse                     (GtsMatrix * m);
00804 GtsMatrix *   gts_matrix3_inverse                    (GtsMatrix * m);
00805 void          gts_matrix_print                       (GtsMatrix * m, 
00806                                                       FILE * fptr);
00807 guint         gts_matrix_compatible_row              (GtsMatrix * A,
00808                                                       GtsVector b,
00809                                                       guint n,
00810                                                       GtsVector A1,
00811                                                       gdouble b1);
00812 guint         gts_matrix_quadratic_optimization      (GtsMatrix * A,
00813                                                       GtsVector b,
00814                                                       guint n,
00815                                                       GtsMatrix * H,
00816                                                       GtsVector c);
00817 GtsMatrix *   gts_matrix_product                     (GtsMatrix * m1, 
00818                                                       GtsMatrix * m2);
00819 GtsMatrix *   gts_matrix_zero                        (GtsMatrix * m);
00820 GtsMatrix *   gts_matrix_identity                    (GtsMatrix * m);
00821 GtsMatrix *   gts_matrix_scale                       (GtsMatrix * m, 
00822                                                       GtsVector s);
00823 GtsMatrix *   gts_matrix_translate                   (GtsMatrix * m, 
00824                                                       GtsVector t);
00825 GtsMatrix *   gts_matrix_rotate                      (GtsMatrix * m,
00826                                                       GtsVector r,
00827                                                       gdouble angle);
00828 void          gts_matrix_destroy                     (GtsMatrix * m);
00829 void          gts_vector_print                       (GtsVector v,
00830                                                       FILE * fptr);
00831 void          gts_vector4_print                      (GtsVector4 v, 
00832                                                       FILE * fptr);
00833 
00834 /* Kdtrees: kdtree.c */
00835 
00836 #define       gts_kdtree_destroy(tree)               g_node_destroy(tree)
00837 
00838 GNode *       gts_kdtree_new                         (GPtrArray * points,
00839                                                       int (*compare)
00840                                                       (const void *, 
00841                                                        const void *));
00842 GSList *      gts_kdtree_range                       (GNode * tree,
00843                                                       GtsBBox * bbox,
00844                                                       int (*compare)
00845                                                       (const void *, 
00846                                                       const void *));
00847 
00848 /* Bboxtrees: bbtree.c */
00849 
00859 typedef void   (*GtsBBTreeTraverseFunc)          (GtsBBox * bb1,
00860                                                   GtsBBox * bb2,
00861                                                   gpointer data);
00872 typedef gdouble (*GtsBBoxDistFunc)               (GtsPoint * p,
00873                                                   gpointer bounded);
00884 typedef GtsPoint * (*GtsBBoxClosestFunc)         (GtsPoint * p,
00885                                                   gpointer bounded);
00886 
00893 #define GTS_IS_BBOX(obj)  (gts_object_is_from_class (obj,\
00894                                                      gts_bbox_class ()))
00895 
00901 #define GTS_BBOX(obj)         GTS_OBJECT_CAST (obj,\
00902                                                GtsBBox,\
00903                                                gts_bbox_class ())
00904 
00910 #define GTS_BBOX_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
00911                                                      GtsBBoxClass,\
00912                                                      gts_bbox_class ())
00913 
00914 struct _GtsBBox {
00915   GtsObject object;
00916   gpointer bounded;
00917   gdouble x1, y1, z1;
00918   gdouble x2, y2, z2;
00919 };
00920 
00921 struct _GtsBBoxClass {
00922   GtsObjectClass parent_class;
00923 };
00924 
00925 GtsBBoxClass * gts_bbox_class                (void);
00926 GtsBBox *  gts_bbox_new                      (GtsBBoxClass * klass,
00927                                               gpointer bounded,
00928                                               gdouble x1, 
00929                                               gdouble y1, 
00930                                               gdouble z1,
00931                                               gdouble x2, 
00932                                               gdouble y2, 
00933                                               gdouble z2);
00934 void       gts_bbox_set                      (GtsBBox * bbox,
00935                                               gpointer bounded,
00936                                               gdouble x1, 
00937                                               gdouble y1, 
00938                                               gdouble z1,
00939                                               gdouble x2, 
00940                                               gdouble y2, 
00941                                               gdouble z2);
00942 GtsBBox *  gts_bbox_segment                  (GtsBBoxClass * klass,
00943                                               GtsSegment * s);
00944 GtsBBox *  gts_bbox_triangle                 (GtsBBoxClass * klass,
00945                                               GtsTriangle * t);
00946 GtsBBox *  gts_bbox_surface                  (GtsBBoxClass * klass, 
00947                                               GtsSurface * surface);
00948 GtsBBox *  gts_bbox_bboxes                   (GtsBBoxClass * klass,
00949                                               GSList * bboxes);
00950 GtsBBox *  gts_bbox_points                   (GtsBBoxClass * klass,
00951                                               GSList * points);
00959 #define    gts_bbox_point_is_inside(bbox, p) ((p)->x >= (bbox)->x1 &&\
00960                                              (p)->y >= (bbox)->y1 &&\
00961                                              (p)->z >= (bbox)->z1 &&\
00962                                              (p)->x <= (bbox)->x2 &&\
00963                                              (p)->y <= (bbox)->y2 &&\
00964                                              (p)->z <= (bbox)->z2)
00965 gboolean   gts_bboxes_are_overlapping        (GtsBBox * bb1, 
00966                                               GtsBBox * bb2);
00967 void       gts_bbox_draw                     (GtsBBox * bb, 
00968                                               FILE * fptr);
00969 gdouble    gts_bbox_diagonal2                (GtsBBox * bb);
00970 void       gts_bbox_point_distance2          (GtsBBox * bb, 
00971                                               GtsPoint * p,
00972                                               gdouble * min,
00973                                               gdouble * max);
00974 gboolean   gts_bbox_is_stabbed               (GtsBBox * bb, 
00975                                               GtsPoint * p);
00976 gboolean   gts_bbox_overlaps_triangle        (GtsBBox * bb,
00977                                               GtsTriangle * t);
00978 gboolean   gts_bbox_overlaps_segment         (GtsBBox * bb, 
00979                                               GtsSegment * s);
00980 
00981 GNode *    gts_bb_tree_new                   (GSList * bboxes);
00982 GNode *    gts_bb_tree_surface               (GtsSurface * s);
00983 GSList *   gts_bb_tree_stabbed               (GNode * tree, 
00984                                               GtsPoint * p);
00985 GSList *   gts_bb_tree_overlap               (GNode * tree, 
00986                                               GtsBBox * bbox);
00987 gboolean   gts_bb_tree_is_overlapping        (GNode * tree, 
00988                                               GtsBBox * bbox);
00989 void       gts_bb_tree_traverse_overlapping  (GNode * tree1, 
00990                                               GNode * tree2,
00991                                               GtsBBTreeTraverseFunc func,
00992                                               gpointer data);
00993 void       gts_bb_tree_draw                  (GNode * tree, 
00994                                               guint depth, 
00995                                               FILE * fptr);
00996 GSList *   gts_bb_tree_point_closest_bboxes  (GNode * tree, 
00997                                               GtsPoint * p);
00998 gdouble    gts_bb_tree_point_distance        (GNode * tree, 
00999                                               GtsPoint * p,
01000                                               GtsBBoxDistFunc distance,
01001                                               GtsBBox ** bbox);
01002 GtsPoint * gts_bb_tree_point_closest         (GNode * tree, 
01003                                               GtsPoint * p,
01004                                               GtsBBoxClosestFunc closest,
01005                                               gdouble * distance);
01006 void       gts_bb_tree_segment_distance      (GNode * tree, 
01007                                               GtsSegment * s,
01008                                               GtsBBoxDistFunc distance,
01009                                               gdouble delta,
01010                                               GtsRange * range);
01011 void       gts_bb_tree_triangle_distance     (GNode * tree, 
01012                                               GtsTriangle * t,
01013                                               GtsBBoxDistFunc distance,
01014                                               gdouble delta,
01015                                               GtsRange * range);
01016 void       gts_bb_tree_surface_distance      (GNode * tree,
01017                                               GtsSurface * s,
01018                                               GtsBBoxDistFunc distance,
01019                                               gdouble delta,
01020                                               GtsRange * range);
01021 void       gts_bb_tree_surface_boundary_distance 
01022                                              (GNode * tree,
01023                                               GtsSurface * s,
01024                                               GtsBBoxDistFunc distance,
01025                                               gdouble delta,
01026                                               GtsRange * range);
01027 void       gts_bb_tree_destroy               (GNode * tree, 
01028                                               gboolean free_leaves);
01029 
01030 /* Surfaces: surface.c */
01031 
01032 typedef struct _GtsSurfaceStats        GtsSurfaceStats;
01033 typedef struct _GtsSurfaceQualityStats GtsSurfaceQualityStats;
01034 typedef GtsVertex * (*GtsRefineFunc)   (GtsEdge * e,
01035                                         GtsVertexClass * klass,
01036                                         gpointer data);
01037 typedef GtsVertex * (*GtsCoarsenFunc)  (GtsEdge * e,
01038                                         GtsVertexClass * klass,
01039                                         gpointer data);
01040 typedef gboolean    (*GtsStopFunc)     (gdouble cost,
01041                                         guint nedge,
01042                                         gpointer data);
01043 
01044 struct _GtsSurfaceStats {
01045   guint n_faces;
01046   guint n_incompatible_faces;
01047   guint n_duplicate_faces;
01048   guint n_duplicate_edges;
01049   guint n_boundary_edges;
01050   guint n_non_manifold_edges;
01051   GtsRange edges_per_vertex, faces_per_edge;
01052   GtsSurface * parent;
01053 };
01054 
01055 struct _GtsSurfaceQualityStats {
01056   GtsRange face_quality;
01057   GtsRange face_area;
01058   GtsRange edge_length;
01059   GtsRange edge_angle;
01060   GtsSurface * parent;
01061 };
01062 
01063 struct _GtsSurface {
01064   GtsObject object;
01065 
01066 #ifdef USE_SURFACE_BTREE
01067   GTree * faces;
01068 #else /* not USE_SURFACE_BTREE */
01069   GHashTable * faces;
01070 #endif /* not USE_SURFACE_BTREE */
01071   GtsFaceClass * face_class;
01072   GtsEdgeClass * edge_class;
01073   GtsVertexClass * vertex_class;
01074   gboolean keep_faces;
01075 };
01076 
01077 struct _GtsSurfaceClass {
01078   GtsObjectClass parent_class;
01079 
01080   void (* add_face)    (GtsSurface *, GtsFace *);
01081   void (* remove_face) (GtsSurface *, GtsFace *);
01082 };
01083 
01084 #define GTS_IS_SURFACE(obj) (gts_object_is_from_class (obj,\
01085                                                        gts_surface_class ()))
01086 #define GTS_SURFACE(obj)         GTS_OBJECT_CAST (obj,\
01087                                                   GtsSurface,\
01088                                                   gts_surface_class ())
01089 #define GTS_SURFACE_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
01090                                                         GtsSurfaceClass,\
01091                                                         gts_surface_class ())
01092 
01093 GtsSurfaceClass * gts_surface_class        (void);
01094 GtsSurface * gts_surface_new               (GtsSurfaceClass * klass,
01095                                             GtsFaceClass * face_class,
01096                                             GtsEdgeClass * edge_class,
01097                                             GtsVertexClass * vertex_class);
01098 void         gts_surface_add_face          (GtsSurface * s, 
01099                                             GtsFace * f);
01100 void         gts_surface_remove_face       (GtsSurface * s, 
01101                                             GtsFace * f);
01102 guint        gts_surface_read              (GtsSurface * surface,
01103                                             GtsFile * f);
01104 gdouble      gts_surface_area              (GtsSurface * s);
01105 void         gts_surface_stats             (GtsSurface * s, 
01106                                             GtsSurfaceStats * stats);
01107 void         gts_surface_quality_stats     (GtsSurface * s, 
01108                                             GtsSurfaceQualityStats * stats);
01109 void         gts_surface_print_stats       (GtsSurface * s, 
01110                                             FILE * fptr);
01111 void         gts_surface_write             (GtsSurface * s, 
01112                                             FILE * fptr);
01113 void         gts_surface_write_oogl        (GtsSurface * s, 
01114                                             FILE * fptr);
01115 void         gts_surface_write_vtk         (GtsSurface * s, 
01116                                             FILE * fptr);
01117 void         gts_surface_write_oogl_boundary (GtsSurface * s, 
01118                                               FILE * fptr);
01119 void         gts_surface_foreach_vertex    (GtsSurface * s, 
01120                                             GtsFunc func, 
01121                                             gpointer data);
01122 void         gts_surface_foreach_edge      (GtsSurface * s, 
01123                                             GtsFunc func, 
01124                                             gpointer data);
01125 void         gts_surface_foreach_face      (GtsSurface * s,
01126                                             GtsFunc func, 
01127                                             gpointer data);
01128 guint        gts_surface_foreach_face_remove (GtsSurface * s,
01129                                               GtsFunc func, 
01130                                               gpointer data);
01131 typedef struct _GtsSurfaceTraverse GtsSurfaceTraverse;
01132 GtsSurfaceTraverse * gts_surface_traverse_new (GtsSurface * s,
01133                                                GtsFace * f);
01134 GtsFace *    gts_surface_traverse_next     (GtsSurfaceTraverse * t,
01135                                             guint * level);
01136 void         gts_surface_traverse_destroy  (GtsSurfaceTraverse * t);
01137 void         gts_surface_refine            (GtsSurface * surface,
01138                                             GtsKeyFunc cost_func,
01139                                             gpointer cost_data,
01140                                             GtsRefineFunc refine_func,
01141                                             gpointer refine_data,
01142                                             GtsStopFunc stop_func,
01143                                             gpointer stop_data);
01144 gboolean     gts_edge_collapse_is_valid    (GtsEdge * e);
01145 void         gts_surface_coarsen           (GtsSurface * surface,
01146                                             GtsKeyFunc cost_func,
01147                                             gpointer cost_data,
01148                                             GtsCoarsenFunc coarsen_func,
01149                                             gpointer coarsen_data,
01150                                             GtsStopFunc stop_func,
01151                                             gpointer stop_data,
01152                                             gdouble minangle);
01153 gboolean     gts_coarsen_stop_number       (gdouble cost, 
01154                                             guint nedge, 
01155                                             guint * min_number);
01156 gboolean     gts_coarsen_stop_cost         (gdouble cost, 
01157                                             guint nedge, 
01158                                             gdouble * max_cost);
01159 void         gts_surface_tessellate        (GtsSurface * s,
01160                                             GtsRefineFunc refine_func,
01161                                             gpointer refine_data);
01162 GtsSurface * gts_surface_generate_sphere   (GtsSurface * s,
01163                                             guint geodesation_order);
01164 GtsSurface * gts_surface_copy              (GtsSurface * s1,
01165                                             GtsSurface * s2);
01166 void         gts_surface_merge             (GtsSurface * s, 
01167                                             GtsSurface * with);
01168 gboolean     gts_surface_is_manifold       (GtsSurface * s);
01169 gboolean     gts_surface_is_closed         (GtsSurface * s);
01170 gboolean     gts_surface_is_orientable     (GtsSurface * s);
01171 gdouble      gts_surface_volume            (GtsSurface * s);
01172 gdouble      gts_surface_center_of_mass    (GtsSurface * s,
01173                                             GtsVector cm);
01174 gdouble      gts_surface_center_of_area    (GtsSurface * s,
01175                                             GtsVector cm);
01176 guint        gts_surface_vertex_number     (GtsSurface * s);
01177 guint        gts_surface_edge_number       (GtsSurface * s);
01178 guint        gts_surface_face_number       (GtsSurface * s);
01179 void         gts_surface_distance          (GtsSurface * s1, 
01180                                             GtsSurface * s2, 
01181                                             gdouble delta,
01182                                             GtsRange * face_range, 
01183                                             GtsRange * boundary_range);
01184 GSList *     gts_surface_boundary          (GtsSurface * surface);
01185 GSList *     gts_surface_split             (GtsSurface * s);
01186 
01187 /* Discrete differential operators: curvature.c */
01188 
01189 gboolean gts_vertex_mean_curvature_normal  (GtsVertex * v, 
01190                                             GtsSurface * s, 
01191                                             GtsVector Kh);
01192 gboolean gts_vertex_gaussian_curvature     (GtsVertex * v, 
01193                                             GtsSurface * s, 
01194                                             gdouble * Kg);
01195 void     gts_vertex_principal_curvatures   (gdouble Kh, 
01196                                             gdouble Kg, 
01197                                             gdouble * K1, 
01198                                             gdouble * K2);
01199 void     gts_vertex_principal_directions   (GtsVertex * v, 
01200                                             GtsSurface * s, 
01201                                             GtsVector Kh,
01202                                             gdouble Kg,
01203                                             GtsVector e1, 
01204                                             GtsVector e2);
01205 
01206 /* Volume optimization: vopt.c */
01207 typedef struct _GtsVolumeOptimizedParams   GtsVolumeOptimizedParams;
01208 
01209 struct _GtsVolumeOptimizedParams {
01210   gdouble volume_weight;
01211   gdouble boundary_weight;
01212   gdouble shape_weight;
01213 };
01214 
01215 GtsVertex *  gts_volume_optimized_vertex   (GtsEdge * edge,
01216                                             GtsVertexClass * klass,
01217                                             GtsVolumeOptimizedParams * params);
01218 gdouble      gts_volume_optimized_cost     (GtsEdge * e,
01219                                             GtsVolumeOptimizedParams * params);
01220 
01221 /* bool operations: boolean.c */
01222 
01223 GSList *     gts_surface_intersection      (GtsSurface * s1,
01224                                             GtsSurface * s2,
01225                                             GNode * faces_tree1,
01226                                             GNode * faces_tree2);
01227 
01228 typedef struct _GtsSurfaceInter         GtsSurfaceInter;
01229 typedef struct _GtsSurfaceInterClass    GtsSurfaceInterClass;
01241 typedef enum { GTS_1_OUT_2, 
01242                GTS_1_IN_2, 
01243                GTS_2_OUT_1, 
01244                GTS_2_IN_1 }             GtsBooleanOperation;
01245 
01252 #define GTS_IS_SURFACE_INTER(obj) (gts_object_is_from_class (obj,\
01253                                               gts_surface_inter_class ()))
01254 
01260 #define GTS_SURFACE_INTER(obj)         GTS_OBJECT_CAST (obj,\
01261                                                   GtsSurfaceInter,\
01262                                                   gts_surface_inter_class ())
01263 
01269 #define GTS_SURFACE_INTER_CLASS(klass) GTS_OBJECT_CLASS_CAST (klass,\
01270                                                  GtsSurfaceInterClass,\
01271                                                  gts_surface_inter_class ())
01272 
01273 struct _GtsSurfaceInter {
01274   GtsObject object;
01275 
01276   GtsSurface * s1;
01277   GtsSurface * s2;
01278   GSList * edges;
01279 };
01280 
01281 struct _GtsSurfaceInterClass {
01282   GtsObjectClass parent_class;
01283 };
01284 
01285 GtsSurfaceInterClass *
01286 gts_surface_inter_class          (void);
01287 GtsSurfaceInter *
01288 gts_surface_inter_new            (GtsSurfaceInterClass * klass,
01289                                   GtsSurface * s1,
01290                                   GtsSurface * s2,
01291                                   GNode * faces_tree1,
01292                                   GNode * faces_tree2,
01293                                   gboolean is_open1,
01294                                   gboolean is_open2);
01295 gboolean 
01296 gts_surface_inter_check          (GtsSurfaceInter * si,
01297                                   gboolean * closed);
01298 void 
01299 gts_surface_inter_boolean        (GtsSurfaceInter * si, 
01300                                   GtsSurface * surface,
01301                                   GtsBooleanOperation op);
01302 gboolean gts_surface_foreach_intersecting_face (GtsSurface * s,
01303                                             GtsBBTreeTraverseFunc func,
01304                                             gpointer data);
01305 GtsSurface * 
01306 gts_surface_is_self_intersecting (GtsSurface * s);
01307 
01308 /* Binary Heap: heap.c */
01309 
01310 typedef struct _GtsHeap         GtsHeap;
01311 
01312 GtsHeap *    gts_heap_new          (GCompareFunc compare_func);
01313 void         gts_heap_insert       (GtsHeap * heap, gpointer p);
01314 gpointer     gts_heap_remove_top   (GtsHeap * heap);
01315 gpointer     gts_heap_top          (GtsHeap * heap);
01316 void         gts_heap_thaw         (GtsHeap * heap);
01317 void         gts_heap_foreach      (GtsHeap * heap, 
01318                                     GFunc func,
01319                                     gpointer user_data);
01320 void         gts_heap_freeze       (GtsHeap * heap);
01321 guint        gts_heap_size         (GtsHeap * heap);
01322 void         gts_heap_destroy      (GtsHeap * heap);
01323 
01324 /* Extended Binary Heap: eheap.c */
01325 
01326 typedef struct _GtsEHeap         GtsEHeap;
01327 typedef struct _GtsEHeapPair     GtsEHeapPair;
01328 
01329 struct _GtsEHeap {
01330   GPtrArray * elts;
01331   GtsKeyFunc func;
01332   gpointer data;
01333   gboolean frozen, randomized;
01334 };
01335 
01342 struct _GtsEHeapPair {
01343   gpointer data;
01344   gdouble key;
01345   guint pos;
01346 };
01347 
01348 GtsEHeap *     gts_eheap_new          (GtsKeyFunc key_func,
01349                                        gpointer data);
01350 GtsEHeapPair * gts_eheap_insert       (GtsEHeap * heap, 
01351                                        gpointer p);
01352 GtsEHeapPair * gts_eheap_insert_with_key (GtsEHeap * heap, 
01353                                           gpointer p, 
01354                                           gdouble key);
01355 gpointer       gts_eheap_remove_top   (GtsEHeap * heap,
01356                                        gdouble * key);
01357 gpointer       gts_eheap_top          (GtsEHeap * heap, 
01358                                        gdouble * key);
01359 void           gts_eheap_thaw         (GtsEHeap * heap);
01360 void           gts_eheap_foreach      (GtsEHeap * heap, 
01361                                        GFunc func,
01362                                        gpointer data);
01363 gpointer       gts_eheap_remove       (GtsEHeap * heap, 
01364                                        GtsEHeapPair * p);
01365 void           gts_eheap_decrease_key (GtsEHeap * heap,
01366                                        GtsEHeapPair * p,
01367                                        gdouble new_key);
01368 void           gts_eheap_freeze       (GtsEHeap * heap);
01369 guint          gts_eheap_size         (GtsEHeap * heap);
01370 void           gts_eheap_update       (GtsEHeap * heap);
01371 gdouble        gts_eheap_key          (GtsEHeap * heap,
01372                                        gpointer p);
01373 void           gts_eheap_randomized   (GtsEHeap * heap, 
01374                                        gboolean randomized);
01375 void           gts_eheap_destroy      (GtsEHeap * heap);
01376 
01377 /* FIFO queues: fifo.c */
01378 
01379 typedef struct _GtsFifo GtsFifo;
01380 
01381 GtsFifo *      gts_fifo_new           (void);
01382 void           gts_fifo_write         (GtsFifo * fifo, 
01383                                        FILE * fp);
01384 void           gts_fifo_push          (GtsFifo * fifo, 
01385                                        gpointer data);
01386 gpointer       gts_fifo_pop           (GtsFifo * fifo);
01387 gpointer       gts_fifo_top           (GtsFifo * fifo);
01388 guint          gts_fifo_size          (GtsFifo * fifo);
01389 gboolean       gts_fifo_is_empty      (GtsFifo * fifo);
01390 void           gts_fifo_foreach       (GtsFifo * fifo, 
01391                                        GtsFunc func, 
01392                                        gpointer data);
01393 void           gts_fifo_reverse       (GtsFifo * fifo);
01394 void           gts_fifo_destroy       (GtsFifo * fifo);
01395 
01396 /* Progressive surfaces */
01397 
01398 /* split.c */
01399 
01400 typedef struct _GtsSplit      GtsSplit;
01401 typedef struct _GtsSplitClass GtsSplitClass;
01402 typedef struct _GtsSplitCFace GtsSplitCFace;
01403 
01404 struct _GtsSplit {
01405   GtsObject object;
01406 
01407   GtsVertex * v;
01408   GtsObject * v1;
01409   GtsObject * v2;
01410   GtsSplitCFace * cfaces;
01411   guint ncf;
01412 };
01413 
01414 struct _GtsSplitClass {
01415   GtsObjectClass parent_class;
01416 };
01417 
01418 #define GTS_IS_SPLIT(obj)    (gts_object_is_from_class (obj,\
01419                                                         gts_split_class ()))
01420 #define GTS_SPLIT(obj)              GTS_OBJECT_CAST (obj,\
01421                                                      GtsSplit,\
01422                                                      gts_split_class ())
01423 #define GTS_SPLIT_CLASS(klass)      GTS_OBJECT_CLASS_CAST (klass,\
01424                                                      GtsSplitClass,\
01425                                                      gts_split_class ())
01426 #define GTS_SPLIT_V1(vs)            (GTS_IS_SPLIT ((vs)->v1) ?\
01427                                      GTS_SPLIT ((vs)->v1)->v :\
01428                                      GTS_VERTEX ((vs)->v1))
01429 #define GTS_SPLIT_V2(vs)            (GTS_IS_SPLIT ((vs)->v2) ?\
01430                                      GTS_SPLIT ((vs)->v2)->v :\
01431                                      GTS_VERTEX ((vs)->v2))
01432 
01433 GtsSplitClass *  gts_split_class          (void);
01434 GtsSplit *       gts_split_new            (GtsSplitClass * klass,
01435                                            GtsVertex * v,
01436                                            GtsObject * o1,
01437                                            GtsObject * o2);
01438 void             gts_split_collapse       (GtsSplit * vs,
01439                                            GtsEdgeClass * klass,
01440                                            GtsEHeap * heap);
01441 void             gts_split_expand         (GtsSplit * vs, 
01442                                            GtsSurface * s,
01443                                            GtsEdgeClass * klass);
01444 typedef gboolean (*GtsSplitTraverseFunc)  (GtsSplit * vs,
01445                                            gpointer data);
01446 void             gts_split_traverse       (GtsSplit * root,
01447                                            GTraverseType        order,
01448                                            gint                 depth,
01449                                            GtsSplitTraverseFunc func,
01450                                            gpointer             data);
01451 guint            gts_split_height         (GtsSplit * root);
01452 
01453 /* psurface.c */
01454 
01455 typedef struct _GtsPSurface         GtsPSurface;
01456 typedef struct _GtsPSurfaceClass    GtsPSurfaceClass;
01457 
01458 struct _GtsPSurface {
01459   GtsObject object;
01460 
01461   GtsSurface * s;
01462   GPtrArray * split;
01463   GtsSplitClass * split_class;
01464   guint pos, min;
01465 
01466   GPtrArray * vertices;
01467   GPtrArray * faces;
01468 };
01469 
01470 struct _GtsPSurfaceClass {
01471   GtsObjectClass parent_class;
01472 };
01473 
01474 #define GTS_IS_PSURFACE(obj) (gts_object_is_from_class (obj,\
01475                                                         gts_psurface_class ()))
01476 #define GTS_PSURFACE(obj)           GTS_OBJECT_CAST (obj,\
01477                                                      GtsPSurface,\
01478                                                      gts_psurface_class ())
01479 #define GTS_PSURFACE_CLASS(klass)     GTS_OBJECT_CLASS_CAST (klass,\
01480                                                      GtsPSurfaceClass,\
01481                                                      gts_psurface_class ())
01482 #define GTS_PSURFACE_IS_CLOSED(ps)  (!(ps)->vertices)
01483 
01484 GtsPSurfaceClass * gts_psurface_class         (void);
01485 GtsPSurface * gts_psurface_new                (GtsPSurfaceClass * klass,
01486                                                GtsSurface * surface,
01487                                                GtsSplitClass * split_class,
01488                                                GtsKeyFunc cost_func,
01489                                                gpointer cost_data,
01490                                                GtsCoarsenFunc coarsen_func,
01491                                                gpointer coarsen_data,
01492                                                GtsStopFunc stop_func,
01493                                                gpointer stop_data,
01494                                                gdouble minangle);
01495 GtsSplit *    gts_psurface_add_vertex         (GtsPSurface * ps);
01496 GtsSplit *    gts_psurface_remove_vertex      (GtsPSurface * ps);
01497 guint         gts_psurface_max_vertex_number  (GtsPSurface * ps);
01498 guint         gts_psurface_min_vertex_number  (GtsPSurface * ps);
01499 void          gts_psurface_set_vertex_number  (GtsPSurface * ps, 
01500                                                guint n);
01501 guint         gts_psurface_get_vertex_number  (GtsPSurface * ps);
01502 void          gts_psurface_write              (GtsPSurface * ps,
01503                                                FILE * fptr);
01504 GtsPSurface * gts_psurface_open               (GtsPSurfaceClass * klass,
01505                                                GtsSurface * s,
01506                                                GtsSplitClass * split_class,
01507                                                GtsFile * f);
01508 GtsSplit *    gts_psurface_read_vertex        (GtsPSurface * ps, 
01509                                                GtsFile * fp);
01510 void          gts_psurface_close              (GtsPSurface * ps);
01511 void          gts_psurface_foreach_vertex     (GtsPSurface * ps, 
01512                                                GtsFunc func, 
01513                                                gpointer data);
01514 
01515 /* hsurface.c */
01516 
01517 typedef struct _GtsHSplit        GtsHSplit;
01518 typedef struct _GtsHSplitClass   GtsHSplitClass;
01519 typedef struct _GtsHSurface      GtsHSurface;
01520 typedef struct _GtsHSurfaceClass GtsHSurfaceClass;
01521 
01522 struct _GtsHSplit {
01523   GtsSplit split;
01524 
01525   GtsEHeapPair * index;
01526   GtsHSplit * parent;
01527   guint nchild;
01528 };
01529 
01530 struct _GtsHSplitClass {
01531   GtsSplitClass parent_class;
01532 };
01533 
01534 #define GTS_IS_HSPLIT(obj) (gts_object_is_from_class (obj,\
01535                                                       gts_hsplit_class ()))
01536 #define GTS_HSPLIT(obj)           GTS_OBJECT_CAST (obj,\
01537                                                    GtsHSplit,\
01538                                                    gts_hsplit_class ())
01539 #define GTS_HSPLIT_CLASS(klass)     GTS_OBJECT_CLASS_CAST (klass,\
01540                                                    GtsHSplitClass,\
01541                                                    gts_hsplit_class ())
01542 
01543 GtsHSplitClass * gts_hsplit_class             (void);
01544 GtsHSplit *   gts_hsplit_new                  (GtsHSplitClass * klass, 
01545                                                GtsSplit * vs);
01546 void          gts_hsplit_collapse             (GtsHSplit * hs,
01547                                                GtsHSurface * hsurface);
01548 void          gts_hsplit_expand               (GtsHSplit * hs,
01549                                                GtsHSurface * hsurface);
01550 void          gts_hsplit_force_expand         (GtsHSplit * hs,
01551                                                GtsHSurface * hsurface);
01552 
01553 struct _GtsHSurface {
01554   GtsObject object;
01555 
01556   GtsSurface * s;
01557   GSList * roots;
01558   GtsEHeap * expandable;
01559   GtsEHeap * collapsable;
01560   GPtrArray * split;
01561   guint nvertex;
01562 };
01563 
01564 struct _GtsHSurfaceClass {
01565   GtsObjectClass parent_class;
01566 };
01567 
01568 #define GTS_IS_HSURFACE(obj) (gts_object_is_from_class (obj,\
01569                                                         gts_hsurface_class ()))
01570 #define GTS_HSURFACE(obj)           GTS_OBJECT_CAST (obj,\
01571                                                      GtsHSurface,\
01572                                                      gts_hsurface_class ())
01573 #define GTS_HSURFACE_CLASS(klass)   GTS_OBJECT_CLASS_CAST (klass,\
01574                                                      GtsHSurfaceClass,\
01575                                                      gts_hsurface_class ())
01576 
01577 GtsHSurfaceClass * gts_hsurface_class    (void);
01578 GtsHSurface * gts_hsurface_new           (GtsHSurfaceClass * klass,
01579                                           GtsHSplitClass *   hsplit_class,
01580                                           GtsPSurface *      psurface,
01581                                           GtsKeyFunc         expand_key,
01582                                           gpointer           expand_data,
01583                                           GtsKeyFunc         collapse_key,
01584                                           gpointer           collapse_data);
01585 void          gts_hsurface_traverse      (GtsHSurface *        hsurface,
01586                                           GTraverseType        order,
01587                                           gint                 depth,
01588                                           GtsSplitTraverseFunc func,
01589                                           gpointer             data);
01590 void          gts_hsurface_foreach       (GtsHSurface *        hsurface,
01591                                           GTraverseType        order,
01592                                           GtsFunc              func,
01593                                           gpointer             data);
01594 guint         gts_hsurface_height        (GtsHSurface *        hsurface);
01595 
01596 /* Constrained Delaunay triangulation: cdt.c */
01597 
01604 #define GTS_IS_CONSTRAINT(obj)      (gts_object_is_from_class (obj,\
01605                                                     gts_constraint_class ()))
01606 
01612 #define GTS_CONSTRAINT(obj)          GTS_OBJECT_CAST (obj,\
01613                                                   GtsConstraint,\
01614                                                   gts_constraint_class ())
01615 
01621 #define GTS_CONSTRAINT_CLASS(klass)  GTS_OBJECT_CLASS_CAST (klass,\
01622                                                   GtsConstraintClass,\
01623                                                   gts_constraint_class ())
01624 
01625 struct _GtsConstraint {
01626   GtsEdge edge;
01627 };
01628 
01629 struct _GtsConstraintClass {
01630   GtsEdgeClass parent_class;
01631 };
01632 
01633 typedef struct _GtsConstraint        GtsConstraint;
01634 typedef struct _GtsConstraintClass   GtsConstraintClass;
01635 
01636 GtsConstraintClass * gts_constraint_class        (void);
01637 
01638 GtsFace *            gts_point_locate            (GtsPoint * p, 
01639                                                   GtsSurface * surface,
01640                                                   GtsFace * guess);
01641 GtsVertex *          gts_delaunay_add_vertex_to_face (GtsSurface * surface, 
01642                                                       GtsVertex * v,
01643                                                       GtsFace * f);
01644 GtsVertex *          gts_delaunay_add_vertex     (GtsSurface * surface, 
01645                                                   GtsVertex * v,
01646                                                   GtsFace * guess);
01647 void                 gts_delaunay_remove_vertex  (GtsSurface * surface, 
01648                                                   GtsVertex * v);
01649 GtsFace *            gts_delaunay_check          (GtsSurface * surface);
01650 GSList *             gts_delaunay_add_constraint (GtsSurface * surface,
01651                                                   GtsConstraint * c);
01652 void                 gts_delaunay_remove_hull    (GtsSurface * surface);
01653 
01654 /* GtsListFace: Header */
01655 
01656 typedef struct _GtsListFace         GtsListFace;
01657 
01658 struct _GtsListFace {
01659   /*< private >*/
01660   GtsFace parent;
01661 
01662   /*< public >*/
01663   GSList * points;
01664 };
01665 
01666 #define GTS_LIST_FACE(obj)            GTS_OBJECT_CAST (obj,\
01667                                                  GtsListFace,\
01668                                                  gts_list_face_class ())
01669 #define GTS_IS_LIST_FACE(obj)         (gts_object_is_from_class (obj,\
01670                                                  gts_list_face_class ()))
01671 
01672 GtsFaceClass *       gts_list_face_class         (void);
01673 
01674 /* Constrained Delaunay refinement: refine.c */
01675 
01676 typedef gboolean   (* GtsEncroachFunc)           (GtsVertex * v,
01677                                                   GtsEdge * e,
01678                                                   GtsSurface * s,
01679                                                   gpointer data);
01680 
01681 gboolean             gts_vertex_encroaches_edge  (GtsVertex * v, 
01682                                                   GtsEdge * e);
01683 GtsVertex *          gts_edge_is_encroached      (GtsEdge * e,
01684                                                   GtsSurface * s,
01685                                                   GtsEncroachFunc encroaches,
01686                                                   gpointer data);
01687 guint                gts_delaunay_conform        (GtsSurface * surface,
01688                                                   gint steiner_max,
01689                                                   GtsEncroachFunc encroaches,
01690                                                   gpointer data);
01691 guint                gts_delaunay_refine         (GtsSurface * surface,
01692                                                   gint steiner_max,
01693                                                   GtsEncroachFunc encroaches,
01694                                                   gpointer encroach_data,
01695                                                   GtsKeyFunc cost,
01696                                                   gpointer cost_data);
01697 
01698 /* Isosurfaces (marching cubes): iso.c */
01699 
01700 typedef struct _GtsGridPlane     GtsGridPlane;
01701 typedef struct _GtsIsoSlice      GtsIsoSlice;
01702 typedef struct _GtsCartesianGrid GtsCartesianGrid;
01703 
01704 struct _GtsGridPlane {
01705   GtsPoint ** p;
01706   guint nx, ny;
01707 };
01708 
01709 struct _GtsCartesianGrid {
01710   guint nx, ny, nz;
01711   gdouble x, dx, y, dy, z, dz;
01712 };
01713 
01714 typedef void (*GtsIsoCartesianFunc)         (gdouble ** a,
01715                                              GtsCartesianGrid g,
01716                                              guint i,
01717                                              gpointer data);
01718 
01719 GtsGridPlane * gts_grid_plane_new           (guint nx, 
01720                                              guint ny);
01721 void           gts_grid_plane_destroy       (GtsGridPlane * g);
01722 GtsIsoSlice *  gts_iso_slice_new            (guint nx, guint ny);
01723 void           gts_iso_slice_fill           (GtsIsoSlice * slice,
01724                                              GtsGridPlane * plane1,
01725                                              GtsGridPlane * plane2,
01726                                              gdouble ** f1,
01727                                              gdouble ** f2,
01728                                              gdouble iso,
01729                                              GtsVertexClass * klass);
01730 void           gts_iso_slice_fill_cartesian (GtsIsoSlice * slice,
01731                                              GtsCartesianGrid g,
01732                                              gdouble ** f1,
01733                                              gdouble ** f2,
01734                                              gdouble iso,
01735                                              GtsVertexClass * klass);
01736 void           gts_iso_slice_destroy        (GtsIsoSlice * slice);
01737 void           gts_isosurface_slice         (GtsIsoSlice * slice1,
01738                                              GtsIsoSlice * slice2,
01739                                              GtsSurface * surface);
01740 void           gts_isosurface_cartesian     (GtsSurface * surface,
01741                                              GtsCartesianGrid g,
01742                                              GtsIsoCartesianFunc f,
01743                                              gpointer data,
01744                                              gdouble iso);
01745 
01746 /* Isosurfaces (marching tetrahedra): isotetra.c */
01747 
01748 void           gts_isosurface_tetra         (GtsSurface * surface,
01749                                              GtsCartesianGrid g,
01750                                              GtsIsoCartesianFunc f,
01751                                              gpointer data,
01752                                              gdouble iso);
01753 void           gts_isosurface_tetra_bcl     (GtsSurface * surface,
01754                                              GtsCartesianGrid g,
01755                                              GtsIsoCartesianFunc f,
01756                                              gpointer data,
01757                                              gdouble iso);
01758 void           gts_isosurface_tetra_bounded (GtsSurface * surface,
01759                                              GtsCartesianGrid g,
01760                                              GtsIsoCartesianFunc f,
01761                                              gpointer data,
01762                                              gdouble iso);
01763 
01764 /* Named vertices, edges and triangles: named.c */
01765 
01766 #define GTS_NAME_LENGTH             40
01767 
01768 #define GTS_NVERTEX(obj)            GTS_OBJECT_CAST (obj,\
01769                                                      GtsNVertex,\
01770                                                      gts_nvertex_class ())
01771 #define GTS_NVERTEX_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
01772                                                            GtsNVertexClass,\
01773                                                            gts_nvertex_class())
01774 #define GTS_IS_NVERTEX(obj)         (gts_object_is_from_class (obj,\
01775                                        gts_nvertex_class ()))
01776 
01777 typedef struct _GtsNVertex          GtsNVertex;
01778 typedef struct _GtsNVertexClass     GtsNVertexClass;
01779 
01780 struct _GtsNVertex {
01781   GtsVertex parent;
01782   char name[GTS_NAME_LENGTH];
01783 };
01784 
01785 struct _GtsNVertexClass {
01786   GtsVertexClass parent_class;
01787 };
01788 
01789 GtsNVertexClass * gts_nvertex_class        (void);
01790 
01791 #define GTS_NEDGE(obj)            GTS_OBJECT_CAST (obj,\
01792                                                    GtsNEdge,\
01793                                                    gts_nedge_class ())
01794 #define GTS_NEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
01795                                                          GtsNEdgeClass,\
01796                                                          gts_nedge_class())
01797 #define GTS_IS_NEDGE(obj)         (gts_object_is_from_class (obj,\
01798                                        gts_nedge_class ()))
01799 
01800 typedef struct _GtsNEdge          GtsNEdge;
01801 typedef struct _GtsNEdgeClass     GtsNEdgeClass;
01802 
01803 struct _GtsNEdge {
01804   GtsEdge parent;
01805   char name[GTS_NAME_LENGTH];
01806 };
01807 
01808 struct _GtsNEdgeClass {
01809   GtsEdgeClass parent_class;
01810 };
01811 
01812 GtsNEdgeClass *   gts_nedge_class        (void);
01813 
01814 #define GTS_NFACE(obj)            GTS_OBJECT_CAST (obj,\
01815                                                    GtsNFace,\
01816                                                    gts_nface_class ())
01817 #define GTS_NFACE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
01818                                                          GtsNFaceClass,\
01819                                                          gts_nface_class())
01820 #define GTS_IS_NFACE(obj)         (gts_object_is_from_class (obj,\
01821                                        gts_nface_class ()))
01822 
01823 typedef struct _GtsNFace          GtsNFace;
01824 typedef struct _GtsNFaceClass     GtsNFaceClass;
01825 
01826 struct _GtsNFace {
01827   GtsFace parent;
01828   char name[GTS_NAME_LENGTH];
01829 };
01830 
01831 struct _GtsNFaceClass {
01832   GtsFaceClass parent_class;
01833 };
01834 
01835 GtsNFaceClass *       gts_nface_class        (void);
01836 
01837 /* Cluster object for out-of-core simplification: oocs.c */
01838 
01839 #define GTS_CLUSTER(obj)            GTS_OBJECT_CAST (obj,\
01840                                                    GtsCluster,\
01841                                                    gts_cluster_class ())
01842 #define GTS_CLUSTER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
01843                                                          GtsClusterClass,\
01844                                                          gts_cluster_class())
01845 #define GTS_IS_CLUSTER(obj)         (gts_object_is_from_class (obj,\
01846                                                    gts_cluster_class ()))
01847      
01848 typedef struct _GtsCluster         GtsCluster;
01849 typedef struct _GtsClusterClass    GtsClusterClass;
01850 typedef struct _GtsClusterId       GtsClusterId;
01851 
01852 struct _GtsClusterId {
01853   guint x, y, z;
01854 };
01855 
01856 struct _GtsCluster {
01857   GtsObject parent;
01858 
01859   GtsClusterId id;
01860   GtsVertex * v;
01861   guint n;
01862 };
01863 
01864 struct _GtsClusterClass {
01865   GtsObjectClass parent_class;
01866 
01867   void (* add) (GtsCluster * c, GtsPoint * p, gpointer data);
01868   void (* update) (GtsCluster * c);
01869 };
01870 
01871 GtsClusterClass * gts_cluster_class                (void);
01872 GtsCluster *      gts_cluster_new                  (GtsClusterClass * klass,
01873                                                     GtsClusterId id,
01874                                                     GtsVertexClass * vklass);
01875 void              gts_cluster_add                  (GtsCluster * c, 
01876                                                     GtsPoint * p,
01877                                                     gpointer data);
01878 void              gts_cluster_update               (GtsCluster * c);
01879 
01880 /* Cluster group object for out-of-core simplification: oocs.c */
01881 
01882 #define GTS_CLUSTER_GRID(obj)            GTS_OBJECT_CAST (obj,\
01883                                                    GtsClusterGrid,\
01884                                                    gts_cluster_grid_class ())
01885 #define GTS_CLUSTER_GRID_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
01886                                                    GtsClusterGridClass,\
01887                                                    gts_cluster_grid_class())
01888 #define GTS_IS_CLUSTER_GRID(obj)         (gts_object_is_from_class (obj,\
01889                                                    gts_cluster_grid_class ()))
01890      
01891 typedef struct _GtsClusterGrid         GtsClusterGrid;
01892 typedef struct _GtsClusterGridClass    GtsClusterGridClass;
01893 
01894 struct _GtsClusterGrid {
01895   GtsObject parent;
01896 
01897   GtsSurface * surface;
01898   GtsBBox * bbox;
01899   GtsVector size;
01900 
01901   GtsClusterClass * cluster_class;
01902   GHashTable * clusters;
01903 };
01904 
01905 struct _GtsClusterGridClass {
01906   GtsObjectClass parent_class;
01907 };
01908 
01909 GtsClusterGridClass * gts_cluster_grid_class (void);
01910 GtsClusterGrid *      gts_cluster_grid_new   (GtsClusterGridClass * klass,
01911                                               GtsClusterClass * cluster_class,
01912                                               GtsSurface * s,
01913                                               GtsBBox * bbox,
01914                                               gdouble delta);
01915 void           gts_cluster_grid_add_triangle (GtsClusterGrid * cluster_grid,
01916                                               GtsPoint * p1,
01917                                               GtsPoint * p2,
01918                                               GtsPoint * p3,
01919                                               gpointer data);
01920 GtsRange       gts_cluster_grid_update       (GtsClusterGrid * cluster_grid);
01921 
01922 /* Triangle strip generation: stripe.c */
01923 GSList *       gts_surface_strip             (GtsSurface * s);
01924 
01925 /* GtsContainee: container.c */
01926 
01927 typedef struct _GtsContainee         GtsContainee;
01928 typedef struct _GtsContaineeClass    GtsContaineeClass;
01929 typedef struct _GtsContainer         GtsContainer;
01930 typedef struct _GtsContainerClass    GtsContainerClass;
01931 
01932 struct _GtsContainee {
01933   GtsObject object;
01934 };
01935 
01936 struct _GtsContaineeClass {
01937   GtsObjectClass parent_class;
01938 
01939   void     (* add_container)    (GtsContainee *, GtsContainer *);
01940   void     (* remove_container) (GtsContainee *, GtsContainer *);
01941   void     (* foreach)          (GtsContainee *, GtsFunc, gpointer);
01942   gboolean (* is_contained)     (GtsContainee *, GtsContainer *);
01943   void     (* replace)          (GtsContainee *, GtsContainee *);
01944 };
01945 
01946 #define GTS_CONTAINEE(obj)            GTS_OBJECT_CAST (obj,\
01947                                                    GtsContainee,\
01948                                                    gts_containee_class ())
01949 #define GTS_CONTAINEE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
01950                                                          GtsContaineeClass,\
01951                                                          gts_containee_class())
01952 #define GTS_IS_CONTAINEE(obj)         (gts_object_is_from_class (obj,\
01953                                                    gts_containee_class ()))
01954      
01955 GtsContaineeClass * gts_containee_class        (void);
01956 GtsContainee *      gts_containee_new          (GtsContaineeClass * klass);
01957 gboolean            gts_containee_is_contained (GtsContainee * item, 
01958                                                 GtsContainer * c);
01959 void                gts_containee_replace      (GtsContainee * item,
01960                                                 GtsContainee * with);
01961 
01962 /* GtsSListContainee: container.c */
01963 
01964 typedef struct _GtsSListContainee         GtsSListContainee;
01965 typedef struct _GtsSListContaineeClass    GtsSListContaineeClass;
01966 
01967 struct _GtsSListContainee {
01968   GtsContainee containee;
01969 
01970   GSList * containers;
01971 };
01972 
01973 struct _GtsSListContaineeClass {
01974   GtsContaineeClass parent_class;
01975 };
01976 
01977 #define GTS_SLIST_CONTAINEE(obj)            GTS_OBJECT_CAST (obj,\
01978                                                    GtsSListContainee,\
01979                                                    gts_slist_containee_class ())
01980 #define GTS_SLIST_CONTAINEE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
01981                                                          GtsSListContaineeClass,\
01982                                                          gts_slist_containee_class())
01983 #define GTS_IS_SLIST_CONTAINEE(obj)         (gts_object_is_from_class (obj,\
01984                                                    gts_slist_containee_class ()))
01985      
01986 GtsSListContaineeClass * gts_slist_containee_class   (void);
01987 
01988 /* GtsContainer: container.c */
01989 
01990 struct _GtsContainer {
01991   GtsSListContainee object;
01992 };
01993 
01994 struct _GtsContainerClass {
01995   GtsSListContaineeClass parent_class;
01996 
01997   void  (* add)     (GtsContainer *, GtsContainee *);
01998   void  (* remove)  (GtsContainer *, GtsContainee *);
01999   void  (* foreach) (GtsContainer *, GtsFunc, gpointer);
02000   guint (* size)    (GtsContainer *);
02001 };
02002 
02003 #define GTS_CONTAINER(obj)            GTS_OBJECT_CAST (obj,\
02004                                                    GtsContainer,\
02005                                                    gts_container_class ())
02006 #define GTS_CONTAINER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02007                                                          GtsContainerClass,\
02008                                                          gts_container_class())
02009 #define GTS_IS_CONTAINER(obj)         (gts_object_is_from_class (obj,\
02010                                                    gts_container_class ()))
02011      
02012 GtsContainerClass * gts_container_class     (void);
02013 GtsContainer *      gts_container_new       (GtsContainerClass * klass);
02014 void                gts_container_add       (GtsContainer * c,
02015                                              GtsContainee * item);
02016 void                gts_container_remove    (GtsContainer * c,
02017                                              GtsContainee * item);
02018 void                gts_container_foreach   (GtsContainer * c,
02019                                              GtsFunc func,
02020                                              gpointer data);
02021 guint               gts_container_size      (GtsContainer * c);
02022 
02023 /* GtsHashContainer: container.c */
02024 
02025 typedef struct _GtsHashContainer         GtsHashContainer;
02026 typedef struct _GtsHashContainerClass    GtsHashContainerClass;
02027 
02028 struct _GtsHashContainer {
02029   GtsContainer c;
02030 
02031   GHashTable * items;
02032   gboolean frozen;
02033 };
02034 
02035 struct _GtsHashContainerClass {
02036   GtsContainerClass parent_class;
02037 };
02038 
02039 #define GTS_HASH_CONTAINER(obj)            GTS_OBJECT_CAST (obj,\
02040                                                    GtsHashContainer,\
02041                                                    gts_hash_container_class ())
02042 #define GTS_HASH_CONTAINER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02043                                                          GtsHashContainerClass,\
02044                                                          gts_hash_container_class())
02045 #define GTS_IS_HASH_CONTAINER(obj)         (gts_object_is_from_class (obj,\
02046                                                    gts_hash_container_class ()))
02047      
02048 GtsHashContainerClass * gts_hash_container_class (void);
02049 
02050 /* GtsSListContainer: container.c */
02051 
02052 typedef struct _GtsSListContainer         GtsSListContainer;
02053 typedef struct _GtsSListContainerClass    GtsSListContainerClass;
02054 
02055 struct _GtsSListContainer {
02056   GtsContainer c;
02057 
02058   GSList * items;
02059   gboolean frozen;
02060 };
02061 
02062 struct _GtsSListContainerClass {
02063   GtsContainerClass parent_class;
02064 };
02065 
02066 #define GTS_SLIST_CONTAINER(obj)            GTS_OBJECT_CAST (obj,\
02067                                                    GtsSListContainer,\
02068                                                    gts_slist_container_class ())
02069 #define GTS_SLIST_CONTAINER_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02070                                                          GtsSListContainerClass,\
02071                                                          gts_slist_container_class())
02072 #define GTS_IS_SLIST_CONTAINER(obj)         (gts_object_is_from_class (obj,\
02073                                                    gts_slist_container_class ()))
02074      
02075 GtsSListContainerClass * gts_slist_container_class (void);
02076 
02077 /* GtsGNode: graph.c */
02078 
02079 typedef struct _GtsGNode         GtsGNode;
02080 typedef struct _GtsGNodeClass    GtsGNodeClass;
02081 typedef struct _GtsGraph         GtsGraph;
02082 typedef struct _GtsGraphClass    GtsGraphClass;
02083 
02084 struct _GtsGNode {
02085   GtsSListContainer container;
02086 
02087   guint level;
02088 };
02089 
02090 struct _GtsGNodeClass {
02091   GtsSListContainerClass parent_class;
02092 
02093   gfloat (* weight) (GtsGNode *);
02094   void   (* write)  (GtsGNode *, FILE *);
02095 };
02096 
02097 #define GTS_GNODE(obj)            GTS_OBJECT_CAST (obj,\
02098                                                    GtsGNode,\
02099                                                    gts_gnode_class ())
02100 #define GTS_GNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02101                                                          GtsGNodeClass,\
02102                                                          gts_gnode_class())
02103 #define GTS_IS_GNODE(obj)         (gts_object_is_from_class (obj,\
02104                                                    gts_gnode_class ()))
02105 #define GTS_GNODE_NEIGHBOR(n,e)   (GTS_GEDGE (e)->n1 == n ? GTS_GEDGE (e)->n2 : GTS_GEDGE (e)->n2 == n ? GTS_GEDGE (e)->n1 : NULL)
02106      
02107 GtsGNodeClass * gts_gnode_class                (void);
02108 GtsGNode *      gts_gnode_new                  (GtsGNodeClass * klass);
02109 void            gts_gnode_foreach_neighbor     (GtsGNode * n, 
02110                                                 GtsGraph * g,
02111                                                 GtsFunc func,
02112                                                 gpointer data);
02113 void            gts_gnode_foreach_edge         (GtsGNode * n,
02114                                                 GtsGraph * g,
02115                                                 GtsFunc func,
02116                                                 gpointer data);
02117 guint           gts_gnode_degree               (GtsGNode * n,
02118                                                 GtsGraph * g);
02119 gfloat          gts_gnode_move_cost            (GtsGNode * n,
02120                                                 GtsGraph * src,
02121                                                 GtsGraph * dst);
02122 gfloat          gts_gnode_weight               (GtsGNode * n);
02123 
02124 GTS_C_VAR
02125 gboolean        gts_allow_floating_gnodes;
02126 
02127 /* GtsNGNode: graph.c */
02128 
02129 typedef struct _GtsNGNode         GtsNGNode;
02130 typedef struct _GtsNGNodeClass    GtsNGNodeClass;
02131 
02132 struct _GtsNGNode {
02133   GtsGNode node;
02134 
02135   guint id;
02136 };
02137 
02138 struct _GtsNGNodeClass {
02139   GtsGNodeClass parent_class;
02140 };
02141 
02142 #define GTS_NGNODE(obj)            GTS_OBJECT_CAST (obj,\
02143                                                    GtsNGNode,\
02144                                                    gts_ngnode_class ())
02145 #define GTS_NGNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02146                                                          GtsNGNodeClass,\
02147                                                          gts_ngnode_class())
02148 #define GTS_IS_NGNODE(obj)         (gts_object_is_from_class (obj,\
02149                                                    gts_ngnode_class ()))
02150      
02151 GtsNGNodeClass * gts_ngnode_class                (void);
02152 GtsNGNode *      gts_ngnode_new                  (GtsNGNodeClass * klass,
02153                                                   guint id);
02154 
02155 /* GtsWGNode: graph.c */
02156 
02157 typedef struct _GtsWGNode         GtsWGNode;
02158 typedef struct _GtsWGNodeClass    GtsWGNodeClass;
02159 
02160 struct _GtsWGNode {
02161   GtsGNode node;
02162   
02163   gfloat weight;
02164 };
02165 
02166 struct _GtsWGNodeClass {
02167   GtsGNodeClass parent_class;
02168 };
02169 
02170 #define GTS_WGNODE(obj)            GTS_OBJECT_CAST (obj,\
02171                                                    GtsWGNode,\
02172                                                    gts_wgnode_class ())
02173 #define GTS_WGNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02174                                                          GtsWGNodeClass,\
02175                                                          gts_wgnode_class())
02176 #define GTS_IS_WGNODE(obj)         (gts_object_is_from_class (obj,\
02177                                                    gts_wgnode_class ()))
02178      
02179 GtsWGNodeClass * gts_wgnode_class                (void);
02180 GtsWGNode *      gts_wgnode_new                  (GtsWGNodeClass * klass,
02181                                                   gfloat weight);
02182 
02183 /* GtsPNode */
02184 
02185 typedef struct _GtsPNode         GtsPNode;
02186 typedef struct _GtsPNodeClass    GtsPNodeClass;
02187 
02188 struct _GtsPNode {
02189   GtsGNode node;
02190 
02191   gpointer data;
02192 };
02193 
02194 struct _GtsPNodeClass {
02195   GtsGNodeClass parent_class;
02196 };
02197 
02198 #define GTS_PNODE(obj)            GTS_OBJECT_CAST (obj,\
02199                                                    GtsPNode,\
02200                                                    gts_pnode_class ())
02201 #define GTS_PNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02202                                                          GtsPNodeClass,\
02203                                                          gts_pnode_class())
02204 #define GTS_IS_PNODE(obj)         (gts_object_is_from_class (obj,\
02205                                                    gts_pnode_class ()))
02206      
02207 GtsPNodeClass * gts_pnode_class                (void);
02208 GtsPNode *      gts_pnode_new                  (GtsPNodeClass * klass,
02209                                                 gpointer data);
02210 
02211 /* GtsFNode */
02212 
02213 typedef struct _GtsFNode         GtsFNode;
02214 typedef struct _GtsFNodeClass    GtsFNodeClass;
02215 
02216 struct _GtsFNode {
02217   GtsGNode node;
02218 
02219   GtsFace * f;
02220 };
02221 
02222 struct _GtsFNodeClass {
02223   GtsGNodeClass parent_class;
02224 };
02225 
02226 #define GTS_FNODE(obj)            GTS_OBJECT_CAST (obj,\
02227                                                    GtsFNode,\
02228                                                    gts_fnode_class ())
02229 #define GTS_FNODE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02230                                                          GtsFNodeClass,\
02231                                                          gts_fnode_class())
02232 #define GTS_IS_FNODE(obj)         (gts_object_is_from_class (obj,\
02233                                                    gts_fnode_class ()))
02234      
02235 GtsFNodeClass * gts_fnode_class                (void);
02236 GtsFNode *      gts_fnode_new                  (GtsFNodeClass * klass,
02237                                                 GtsFace * f);
02238 
02239 /* GtsGEdge: graph.c */
02240 
02241 typedef struct _GtsGEdge         GtsGEdge;
02242 typedef struct _GtsGEdgeClass    GtsGEdgeClass;
02243 
02244 struct _GtsGEdge {
02245   GtsContainee containee;
02246 
02247   GtsGNode * n1;
02248   GtsGNode * n2;
02249 };
02250 
02251 struct _GtsGEdgeClass {
02252   GtsContaineeClass parent_class;
02253 
02254   GtsGEdge * (* link)   (GtsGEdge * e, GtsGNode * n1, GtsGNode * n2);
02255   gfloat     (* weight) (GtsGEdge * e);
02256   void       (* write)  (GtsGEdge * e, FILE * fp);
02257 };
02258 
02259 #define GTS_GEDGE(obj)            GTS_OBJECT_CAST (obj,\
02260                                                    GtsGEdge,\
02261                                                    gts_gedge_class ())
02262 #define GTS_GEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02263                                                          GtsGEdgeClass,\
02264                                                          gts_gedge_class())
02265 #define GTS_IS_GEDGE(obj)         (gts_object_is_from_class (obj,\
02266                                                    gts_gedge_class ()))
02267      
02268 GtsGEdgeClass * gts_gedge_class                (void);
02269 GtsGEdge *      gts_gedge_new                  (GtsGEdgeClass * klass,
02270                                                 GtsGNode * n1,
02271                                                 GtsGNode * n2);
02272 gfloat          gts_gedge_weight               (GtsGEdge * e);
02273 #define         gts_gedge_connects(e, a1, a2)\
02274    (((e)->n1 == a1 && (e)->n2 == a2) || ((e)->n1 == a2 && (e)->n2 == a1)) 
02275 
02276 /* GtsPGEdge: graph.c */
02277 
02278 typedef struct _GtsPGEdge         GtsPGEdge;
02279 typedef struct _GtsPGEdgeClass    GtsPGEdgeClass;
02280 
02281 struct _GtsPGEdge {
02282   GtsGEdge gedge;
02283 
02284   gpointer data;
02285 };
02286 
02287 struct _GtsPGEdgeClass {
02288   GtsGEdgeClass parent_class;
02289 };
02290 
02291 #define GTS_PGEDGE(obj)            GTS_OBJECT_CAST (obj,\
02292                                                    GtsPGEdge,\
02293                                                    gts_pgedge_class ())
02294 #define GTS_PGEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02295                                                          GtsPGEdgeClass,\
02296                                                          gts_pgedge_class())
02297 #define GTS_IS_PGEDGE(obj)         (gts_object_is_from_class (obj,\
02298                                                    gts_pgedge_class ()))
02299      
02300 GtsPGEdgeClass * gts_pgedge_class                (void);
02301 GtsPGEdge *      gts_pgedge_new                  (GtsPGEdgeClass * klass,
02302                                                   GtsGNode * n1,
02303                                                   GtsGNode * n2,
02304                                                   gpointer data);
02305 
02306 /* GtsWGEdge: graph.c */
02307 
02308 typedef struct _GtsWGEdge         GtsWGEdge;
02309 typedef struct _GtsWGEdgeClass    GtsWGEdgeClass;
02310 
02311 struct _GtsWGEdge {
02312   GtsGEdge gedge;
02313 
02314   gfloat weight;
02315 };
02316 
02317 struct _GtsWGEdgeClass {
02318   GtsGEdgeClass parent_class;
02319 };
02320 
02321 #define GTS_WGEDGE(obj)            GTS_OBJECT_CAST (obj,\
02322                                                    GtsWGEdge,\
02323                                                    gts_wgedge_class ())
02324 #define GTS_WGEDGE_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02325                                                          GtsWGEdgeClass,\
02326                                                          gts_wgedge_class())
02327 #define GTS_IS_WGEDGE(obj)         (gts_object_is_from_class (obj,\
02328                                                    gts_wgedge_class ()))
02329      
02330 GtsWGEdgeClass * gts_wgedge_class                (void);
02331 GtsWGEdge *      gts_wgedge_new                  (GtsWGEdgeClass * klass,
02332                                                   GtsGNode * n1,
02333                                                   GtsGNode * n2,
02334                                                   gfloat weight);
02335 
02336 /* GtsGraph: graph.c */
02337 
02338 struct _GtsGraph {
02339   GtsHashContainer object;
02340 
02341   GtsGraphClass * graph_class;
02342   GtsGNodeClass * node_class;
02343   GtsGEdgeClass * edge_class;
02344 };
02345 
02346 struct _GtsGraphClass {
02347   GtsHashContainerClass parent_class;
02348 
02349   gfloat (* weight) (GtsGraph *);
02350 };
02351 
02352 #define GTS_GRAPH(obj)            GTS_OBJECT_CAST (obj,\
02353                                                    GtsGraph,\
02354                                                    gts_graph_class ())
02355 #define GTS_GRAPH_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02356                                                          GtsGraphClass,\
02357                                                          gts_graph_class())
02358 #define GTS_IS_GRAPH(obj)         (gts_object_is_from_class (obj,\
02359                                                    gts_graph_class ()))
02360      
02361 GtsGraphClass * gts_graph_class                  (void);
02362 GtsGraph *      gts_graph_new                    (GtsGraphClass * klass,
02363                                                   GtsGNodeClass * node_class,
02364                                                   GtsGEdgeClass * edge_class);
02365 void            gts_graph_print_stats            (GtsGraph * g,
02366                                                   FILE * fp);
02367 typedef struct _GtsGraphTraverse GtsGraphTraverse;
02368 typedef enum   { GTS_BREADTH_FIRST
02369                }   GtsTraverseType;
02370 GtsGraphTraverse * gts_graph_traverse_new        (GtsGraph * g, 
02371                                                   GtsGNode * n,
02372                                                   GtsTraverseType type,
02373                                                   gboolean reinit);
02374 GtsGNode *         gts_graph_traverse_next       (GtsGraphTraverse * t);
02375 GtsGNode *         gts_graph_traverse_what_next  (GtsGraphTraverse * t);
02376 void               gts_graph_traverse_destroy    (GtsGraphTraverse * t);
02377 void               gts_graph_foreach_edge        (GtsGraph * g,
02378                                                   GtsFunc func,
02379                                                   gpointer data);
02380 gfloat             gts_graph_weight              (GtsGraph * g);
02381 guint              gts_graph_distance_sum        (GtsGraph * g, 
02382                                                   GtsGNode * center);
02383 GtsGNode *         gts_graph_farthest            (GtsGraph * g, 
02384                                                   GSList * gnodes);
02385 guint              gts_graph_edges_cut           (GtsGraph * g);
02386 gfloat             gts_graph_edges_cut_weight    (GtsGraph * g);
02387 void               gts_graph_write               (GtsGraph * g, 
02388                                                   FILE * fp);
02389 void               gts_graph_write_dot           (GtsGraph * g, 
02390                                                   FILE * fp);
02391 GtsGraph *         gts_graph_read                (GtsFile * fp);
02392 guint              gts_graph_read_jostle         (GtsGraph * g, 
02393                                                   GtsFile * fp);
02394 
02395 /* GtsWGraph: graph.c */
02396 
02397 typedef struct _GtsWGraph      GtsWGraph;
02398 typedef struct _GtsWGraphClass GtsWGraphClass;
02399 
02400 struct _GtsWGraph {
02401   GtsGraph graph;
02402 
02403   gfloat weight;
02404 };
02405 
02406 struct _GtsWGraphClass {
02407   GtsGraphClass parent_class;
02408 };
02409 
02410 #define GTS_WGRAPH(obj)            GTS_OBJECT_CAST (obj,\
02411                                                    GtsWGraph,\
02412                                                    gts_wgraph_class ())
02413 #define GTS_WGRAPH_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02414                                                          GtsWGraphClass,\
02415                                                          gts_wgraph_class())
02416 #define GTS_IS_WGRAPH(obj)         (gts_object_is_from_class (obj,\
02417                                                    gts_wgraph_class ()))
02418      
02419 GtsWGraphClass * gts_wgraph_class                (void);
02420 gfloat           gts_wgraph_weight_max           (GtsWGraph * wg);
02421 
02422 /* Surface graph: graph.c */
02423 
02424 GtsGraph *       gts_surface_graph_new           (GtsGraphClass * klass,
02425                                                   GtsSurface * s);
02426 GtsSurface *     gts_surface_graph_surface       (GtsGraph * surface_graph,
02427                                                   GtsSurface * s);
02428 
02429 /* Segments graph: graph.c */
02430 
02431 GtsGraph *       gts_segments_graph_new          (GtsGraphClass * klass,
02432                                                   GSList * segments);
02433 
02434 /* GtsGNodeSplit: pgraph.c */
02435 
02436 typedef struct _GtsGNodeSplit         GtsGNodeSplit;
02437 typedef struct _GtsGNodeSplitClass    GtsGNodeSplitClass;
02438 
02439 struct _GtsGNodeSplit {
02440   GtsObject object;
02441 
02442   GtsGNode * n;
02443   GtsObject * n1;
02444   GtsObject * n2;
02445 };
02446 
02447 struct _GtsGNodeSplitClass {
02448   GtsObjectClass parent_class;
02449 };
02450 
02451 #define GTS_GNODE_SPLIT(obj)            GTS_OBJECT_CAST (obj,\
02452                                                    GtsGNodeSplit,\
02453                                                    gts_gnode_split_class ())
02454 #define GTS_GNODE_SPLIT_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02455                                                          GtsGNodeSplitClass,\
02456                                                          gts_gnode_split_class())
02457 #define GTS_IS_GNODE_SPLIT(obj)         (gts_object_is_from_class (obj,\
02458                                                    gts_gnode_split_class ()))
02459 #define GTS_GNODE_SPLIT_N1(ns) (GTS_IS_GNODE_SPLIT ((ns)->n1) ? GTS_GNODE_SPLIT ((ns)->n1)->n : GTS_GNODE ((ns)->n1))
02460 #define GTS_GNODE_SPLIT_N2(ns) (GTS_IS_GNODE_SPLIT ((ns)->n2) ? GTS_GNODE_SPLIT ((ns)->n2)->n : GTS_GNODE ((ns)->n2))
02461      
02462 GtsGNodeSplitClass * gts_gnode_split_class    (void);
02463 GtsGNodeSplit *      gts_gnode_split_new      (GtsGNodeSplitClass * klass,
02464                                                GtsGNode * n,
02465                                                GtsObject * n1,
02466                                                GtsObject * n2);
02467 void                 gts_gnode_split_collapse (GtsGNodeSplit * ns,
02468                                                GtsGraph * g,
02469                                                GtsWGEdgeClass * klass);
02470 void                 gts_gnode_split_expand   (GtsGNodeSplit * ns,
02471                                                GtsGraph * g);
02472 
02473 /* GtsPGraph: pgraph.c */
02474 
02475 typedef struct _GtsPGraph         GtsPGraph;
02476 typedef struct _GtsPGraphClass    GtsPGraphClass;
02477 
02478 struct _GtsPGraph {
02479   GtsObject object;
02480 
02481   GtsGraph * g;
02482   GPtrArray * split;
02483   GArray * levels;
02484   GtsGNodeSplitClass * split_class;
02485   GtsWGEdgeClass * edge_class;
02486   guint pos, min, level;
02487 };
02488 
02489 struct _GtsPGraphClass {
02490   GtsObjectClass parent_class;
02491 };
02492 
02493 #define GTS_PGRAPH(obj)            GTS_OBJECT_CAST (obj,\
02494                                                    GtsPGraph,\
02495                                                    gts_pgraph_class ())
02496 #define GTS_PGRAPH_CLASS(klass)    GTS_OBJECT_CLASS_CAST (klass,\
02497                                                          GtsPGraphClass,\
02498                                                          gts_pgraph_class())
02499 #define GTS_IS_PGRAPH(obj)         (gts_object_is_from_class (obj,\
02500                                                    gts_pgraph_class ()))
02501      
02502 GtsPGraphClass * gts_pgraph_class            (void);
02503 GtsPGraph *      gts_pgraph_new              (GtsPGraphClass * klass,
02504                                               GtsGraph * g,
02505                                               GtsGNodeSplitClass * split_class,
02506                                               GtsWGNodeClass * node_class,
02507                                               GtsWGEdgeClass * edge_class,
02508                                               guint min);
02509 GtsGNodeSplit *  gts_pgraph_add_node         (GtsPGraph * pg);
02510 GtsGNodeSplit *  gts_pgraph_remove_node      (GtsPGraph * pg);
02511 void             gts_pgraph_set_node_number  (GtsPGraph *pg,
02512                                               guint n);
02513 guint            gts_pgraph_get_node_number  (GtsPGraph *pg);
02514 guint            gts_pgraph_min_node_number  (GtsPGraph *pg);
02515 guint            gts_pgraph_max_node_number  (GtsPGraph *pg);
02516 void             gts_pgraph_foreach_node     (GtsPGraph *pg,
02517                                               GtsFunc func,
02518                                               gpointer data);
02519 gboolean         gts_pgraph_down             (GtsPGraph * pg,
02520                                               GtsFunc func,
02521                                               gpointer data);
02522 /* Graph partition: partition.c */
02523 
02524 GSList *         gts_graph_bubble_partition           (GtsGraph * g, 
02525                                                        guint np, 
02526                                                        guint niter,
02527                                                        GtsFunc step_info,
02528                                                        gpointer data);
02529 guint            gts_graph_partition_edges_cut        (GSList * partition);
02530 gfloat           gts_graph_partition_edges_cut_weight (GSList * partition);
02531 void             gts_graph_partition_print_stats      (GSList * partition,
02532                                                        FILE * fp);
02533 gfloat           gts_graph_partition_balance          (GSList * partition);
02534 GSList *         gts_graph_partition_clone            (GSList * partition);
02535 GSList *         gts_graph_recursive_bisection        (GtsWGraph * wg,
02536                                                        guint n,
02537                                                        guint ntry,
02538                                                        guint mmax,
02539                                                        guint nmin,
02540                                                        gfloat imbalance);
02541 void             gts_graph_partition_destroy          (GSList * partition);
02542 
02543 /* Graph bisection: partition.c */
02544 
02545 typedef struct _GtsGraphBisection GtsGraphBisection;
02546 
02547 struct _GtsGraphBisection {
02548   GtsGraph * g;
02549   GtsGraph * g1;
02550   GtsGraph * g2;
02551   GHashTable * bg1;
02552   GHashTable * bg2;
02553 };
02554 
02555 gboolean            gts_graph_bisection_check      (GtsGraphBisection * bg);
02556 GtsGraphBisection * gts_graph_ggg_bisection        (GtsGraph * g, 
02557                                                     guint ntry);
02558 GtsGraphBisection * gts_graph_bfgg_bisection       (GtsGraph * g, 
02559                                                     guint ntry);
02560 gdouble             gts_graph_bisection_kl_refine  (GtsGraphBisection * bg,
02561                                                     guint mmax);
02562 gdouble             gts_graph_bisection_bkl_refine (GtsGraphBisection * bg,
02563                                                     guint mmax,
02564                                                     gfloat imbalance);
02565 GtsGraphBisection * gts_graph_bisection_new        (GtsWGraph * wg,
02566                                                     guint ntry,
02567                                                     guint mmax,
02568                                                     guint nmin,
02569                                                     gfloat imbalance);
02570 void                gts_graph_bisection_destroy    (GtsGraphBisection * bg,
02571                                                     gboolean destroy_graphs);
02572 
02573 #ifdef __cplusplus
02574 }
02575 #endif /* __cplusplus */
02576 
02577 #endif /* __GTS_H__ */