SCOREC core
Parallel unstructured mesh tools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gmi.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  Copyright 2014 Scientific Computation Research Center,
4  Rensselaer Polytechnic Institute. All rights reserved.
5 
6  This work is open source software, licensed under the terms of the
7  BSD license as described in the LICENSE file in the top-level directory.
8 
9 *******************************************************************************/
10 #ifndef GMI_H
11 #define GMI_H
12 
27 #include <stdio.h>
28 
29 struct gmi_ent;
30 
31 struct gmi_iter;
32 
33 struct gmi_model;
34 
38 struct gmi_set {
40  int n;
44  struct gmi_ent* e[1];
45 };
46 
59 struct gmi_model_ops {
61  struct gmi_iter* (*begin)(struct gmi_model* m, int dim);
63  struct gmi_ent* (*next)(struct gmi_model* m, struct gmi_iter* i);
65  void (*end)(struct gmi_model* m, struct gmi_iter* i);
67  int (*dim)(struct gmi_model* m, struct gmi_ent* e);
69  int (*tag)(struct gmi_model* m, struct gmi_ent* e);
71  struct gmi_ent* (*find)(struct gmi_model* m, int dim, int tag);
74  struct gmi_set* (*adjacent)(struct gmi_model* m, struct gmi_ent* e, int dim);
77  void (*eval)(struct gmi_model* m, struct gmi_ent* e,
78  double const p[2], double x[3]);
80  void (*reparam)(struct gmi_model* m, struct gmi_ent* from,
81  double const from_p[2], struct gmi_ent* to, double to_p[2]);
83  int (*periodic)(struct gmi_model* m, struct gmi_ent* e, int dim);
85  void (*range)(struct gmi_model* m, struct gmi_ent* e, int dim,
86  double r[2]);
88  void (*closest_point)(struct gmi_model* m, struct gmi_ent* e,
89  double const from[3], double to[3], double to_p[2]);
91  void (*normal)(struct gmi_model* m, struct gmi_ent* e,
92  double const p[2], double n[3]);
94  void (*first_derivative)(struct gmi_model* m, struct gmi_ent* e,
95  double const p[2], double t0[3], double t1[3]);
97  int (*is_point_in_region)(struct gmi_model* m, struct gmi_ent* e,
98  double p[3]);
100  void (*bbox)(struct gmi_model* m, struct gmi_ent* e,
101  double bmin[3], double bmax[3]);
103  int (*is_in_closure_of)(struct gmi_model* m, struct gmi_ent* e,
104  struct gmi_ent* et);
106  int (*is_discrete_ent)(struct gmi_model* m, struct gmi_ent* e);
108  void (*destroy)(struct gmi_model* m);
109 };
110 
112 struct gmi_model {
114  struct gmi_model_ops const* ops;
116  int n[4];
117 };
118 
120 typedef struct gmi_model* (*gmi_creator)(const char* filename);
121 
122 #ifdef __cplusplus
123 extern "C" {
124 #endif
125 
127 struct gmi_set* gmi_make_set(int n);
129 void gmi_free_set(struct gmi_set* s);
130 
133 struct gmi_iter* gmi_begin(struct gmi_model* m, int dim);
136 struct gmi_ent* gmi_next(struct gmi_model* m, struct gmi_iter* i);
138 void gmi_end(struct gmi_model* m, struct gmi_iter* i);
140 int gmi_dim(struct gmi_model* m, struct gmi_ent* e);
142 int gmi_tag(struct gmi_model* m, struct gmi_ent* e);
144 struct gmi_ent* gmi_find(struct gmi_model* m, int dim, int tag);
148 struct gmi_set* gmi_adjacent(struct gmi_model* m, struct gmi_ent* e, int dim);
150 int gmi_can_eval(struct gmi_model* m);
152 int gmi_can_get_closest_point(struct gmi_model* m);
154 int gmi_has_normal(struct gmi_model* m);
160 void gmi_eval(struct gmi_model* m, struct gmi_ent* e,
161  double const p[2], double x[3]);
169 void gmi_reparam(struct gmi_model* m, struct gmi_ent* from,
170  double const from_p[2], struct gmi_ent* to, double to_p[2]);
172 int gmi_periodic(struct gmi_model* m, struct gmi_ent* e, int dim);
174 void gmi_range(struct gmi_model* m, struct gmi_ent* e, int dim,
175  double r[2]);
177 void gmi_closest_point(struct gmi_model* m, struct gmi_ent* e,
178  double const from[3], double to[3], double to_p[2]);
180 void gmi_normal(struct gmi_model* m, struct gmi_ent* e,
181  double const p[2], double n[3]);
183 void gmi_first_derivative(struct gmi_model* m, struct gmi_ent* e,
184  double const p[2], double t0[3], double t1[3]);
186 int gmi_is_point_in_region(struct gmi_model* m, struct gmi_ent* e,
187  double point[3]);
189 int gmi_is_in_closure_of(struct gmi_model* m, struct gmi_ent* e,
190  struct gmi_ent* et);
192 void gmi_bbox(struct gmi_model* m, struct gmi_ent* e,
193  double bmin[3], double bmax[3]);
195 int gmi_is_discrete_ent(struct gmi_model* m, struct gmi_ent* e);
197 void gmi_destroy(struct gmi_model* m);
198 
208 void gmi_register(gmi_creator f, const char* ext);
215 struct gmi_model* gmi_load(const char* filename);
216 
224 void gmi_write_dmg(struct gmi_model* m, const char* filename);
225 
228 void gmi_fail(const char* why) __attribute__((noreturn));
229 
235 void gmi_fscanf(FILE* f, int n, const char* format, ...);
236 
237 int gmi_getline(char** line, size_t* cap, FILE* f);
238 int gmi_has_ext(const char* filename, const char* ext);
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 
244 #endif
int gmi_dim(struct gmi_model *m, struct gmi_ent *e)
get the dimension of a model entity
void gmi_end(struct gmi_model *m, struct gmi_iter *i)
free an iterator
int(* is_in_closure_of)(struct gmi_model *m, struct gmi_ent *e, struct gmi_ent *et)
implement gmi_is_in_closure_of
Definition: gmi.h:103
void(* destroy)(struct gmi_model *m)
implement gmi_destroy
Definition: gmi.h:108
void gmi_fail(const char *why) __attribute__((noreturn))
print the message as a gmi failure and abort
int gmi_is_in_closure_of(struct gmi_model *m, struct gmi_ent *e, struct gmi_ent *et)
check if e is in the closure of et
int(* is_point_in_region)(struct gmi_model *m, struct gmi_ent *e, double p[3])
implement gmi_is_point_in_region
Definition: gmi.h:97
int gmi_tag(struct gmi_model *m, struct gmi_ent *e)
get the tag of a model entity
void(* closest_point)(struct gmi_model *m, struct gmi_ent *e, double const from[3], double to[3], double to_p[2])
implement gmi_closest_point
Definition: gmi.h:88
struct gmi_model_ops const * ops
pointer to interface definition
Definition: gmi.h:114
void gmi_destroy(struct gmi_model *m)
destroy a geometric model
int gmi_has_normal(struct gmi_model *m)
check whether the model implements gmi_normal
struct gmi_ent * e[1]
array of model entity pointers
Definition: gmi.h:44
int(* is_discrete_ent)(struct gmi_model *m, struct gmi_ent *e)
implement gmi_is_discrete_ent
Definition: gmi.h:106
void gmi_bbox(struct gmi_model *m, struct gmi_ent *e, double bmin[3], double bmax[3])
get the bounding box of model entity e
void gmi_register(gmi_creator f, const char *ext)
register a new geometric modeler
int gmi_can_get_closest_point(struct gmi_model *m)
check whether the model gmi_closest_point
void(* range)(struct gmi_model *m, struct gmi_ent *e, int dim, double r[2])
implement gmi_range
Definition: gmi.h:85
the basic structure for all GMI models
Definition: gmi.h:112
struct gmi_ent * gmi_next(struct gmi_model *m, struct gmi_iter *i)
dereference and then increment an interator
int gmi_is_discrete_ent(struct gmi_model *m, struct gmi_ent *e)
check if e is a discrete entity
void gmi_range(struct gmi_model *m, struct gmi_ent *e, int dim, double r[2])
return the range of parametric coordinates along this dimension
int(* tag)(struct gmi_model *m, struct gmi_ent *e)
implement gmi_tag
Definition: gmi.h:69
void gmi_first_derivative(struct gmi_model *m, struct gmi_ent *e, double const p[2], double t0[3], double t1[3])
return first derivative
struct gmi_model * gmi_load(const char *filename)
load a geometric model file
model interface definition
Definition: gmi.h:59
void(* end)(struct gmi_model *m, struct gmi_iter *i)
implement gmi_end
Definition: gmi.h:65
void(* normal)(struct gmi_model *m, struct gmi_ent *e, double const p[2], double n[3])
implement gmi_normal
Definition: gmi.h:91
int gmi_can_eval(struct gmi_model *m)
check whether the model implements gmi_eval
int n
number of model entities
Definition: gmi.h:40
int gmi_periodic(struct gmi_model *m, struct gmi_ent *e, int dim)
return true iff the model entity is periodic around this dimension
void gmi_normal(struct gmi_model *m, struct gmi_ent *e, double const p[2], double n[3])
return normal vector at a parameter
void(* bbox)(struct gmi_model *m, struct gmi_ent *e, double bmin[3], double bmax[3])
implement gmi_bbox
Definition: gmi.h:100
struct gmi_iter * gmi_begin(struct gmi_model *m, int dim)
begin an iterator over model entities of one dimension
void gmi_write_dmg(struct gmi_model *m, const char *filename)
write a dmg (meshmodel) file
a set of model entities
Definition: gmi.h:38
void gmi_reparam(struct gmi_model *m, struct gmi_ent *from, double const from_p[2], struct gmi_ent *to, double to_p[2])
re-parameterize from one model entity to another
void(* reparam)(struct gmi_model *m, struct gmi_ent *from, double const from_p[2], struct gmi_ent *to, double to_p[2])
implement gmi_reparam
Definition: gmi.h:80
int n[4]
number of model entities per dimension
Definition: gmi.h:116
int(* dim)(struct gmi_model *m, struct gmi_ent *e)
implement gmi_dim
Definition: gmi.h:67
void gmi_free_set(struct gmi_set *s)
free a gmi_set
struct gmi_set * gmi_adjacent(struct gmi_model *m, struct gmi_ent *e, int dim)
query model entity adjacencies
void(* first_derivative)(struct gmi_model *m, struct gmi_ent *e, double const p[2], double t0[3], double t1[3])
implement gmi_first_derivative
Definition: gmi.h:94
void gmi_eval(struct gmi_model *m, struct gmi_ent *e, double const p[2], double x[3])
evaluate the parametric definition of a model boundary entity
struct gmi_ent * gmi_find(struct gmi_model *m, int dim, int tag)
lookup a model entity by dimension and tag
struct gmi_model *(* gmi_creator)(const char *filename)
model from file constructor, give to gmi_register
Definition: gmi.h:120
void(* eval)(struct gmi_model *m, struct gmi_ent *e, double const p[2], double x[3])
implement gmi_eval
Definition: gmi.h:77
struct gmi_set * gmi_make_set(int n)
allocate a gmi_set with (n) elements
void gmi_fscanf(FILE *f, int n, const char *format,...)
fscanf wrapper that checks return values
void gmi_closest_point(struct gmi_model *m, struct gmi_ent *e, double const from[3], double to[3], double to_p[2])
return closest point and its parameter
int(* periodic)(struct gmi_model *m, struct gmi_ent *e, int dim)
implement gmi_periodic
Definition: gmi.h:83
int gmi_is_point_in_region(struct gmi_model *m, struct gmi_ent *e, double point[3])
check if point is in region