diff --git a/scheme/meep-ctl-swig.hpp b/scheme/meep-ctl-swig.hpp index ac1c70ddc..5b90aad66 100644 --- a/scheme/meep-ctl-swig.hpp +++ b/scheme/meep-ctl-swig.hpp @@ -57,7 +57,7 @@ ctlio::cnumber_list make_casimir_g_kz(double T, double dt, double sigma, meep::f ctlio::integer_list GDSII_layers(const char *fname); meep::volume GDSII_vol(const char *fname, int layer = -1, double zmin = 0, double zmax = 0); -ctlio::simple_prism_list get_GDSII_prisms(const char *GDSIIFile, int Layer = -1, double zmin = 0.0, double zmax = 0.0); +SCM get_GDSII_prism_data(const char *GDSIIFile, int Layer = -1, double zmin = 0.0, double zmax = 0.0); // wrapper around constructor to fool SWIG meep::volume_list *make_volume_list(const meep::volume &v, int c, std::complex weight, diff --git a/scheme/meep.cpp b/scheme/meep.cpp index 5cd225cd1..7dcee09de 100644 --- a/scheme/meep.cpp +++ b/scheme/meep.cpp @@ -214,19 +214,24 @@ volume GDSII_vol(const char *fname, int layer, double zmin, double zmax) { return meep_geom::get_GDSII_volume(fname, layer, zmin, zmax); } -ctlio::simple_prism_list get_GDSII_prisms(const char *GDSIIFile, int Layer, double zmin, double zmax) { +/* We have to jump through some hoops here because the geometric_object data type used + in meepgeom (from libctlgeom) is different from the generated ctlio::geometric_object. + So we take the list of prisms from meep_geom::get_GDSII_prisms and return a simple + Scheme list of triples (vertices height axis). meep.scm then defines a higher-level + function get-GDSII-prisms that constructs the actual prism objects again */ +SCM get_GDSII_prism_data(const char *GDSIIFile, int Layer, double zmin, double zmax) { geometric_object_list go = meep_geom::get_GDSII_prisms(NULL, GDSIIFile, Layer, zmin, zmax); - ctlio::simple_prism_list res; - res.num_items = go.num_items; - res.items = new ctlio::simple_prism[res.num_items]; - for (int i = 0; i < res.num_items; ++i) { + SCM res = SCM_EOL; + for (int i = go.num_items - 1; i >= 0; --i) { prism *p = go.items[i].subclass.prism_data; - res.items[i].vertices.num_items = p->vertices.num_items; - res.items[i].vertices.items = p->vertices.items; - res.items[i].height = p->height; - res.items[i].axis = p->axis; + res = scm_cons(scm_list_3(ctl_convert_list_to_scm(make_vector3_list(p->vertices.num_items, p->vertices.items)), + ctl_convert_number_to_scm(p->height), + ctl_convert_vector3_to_scm(p->axis)), + res); + free(p->vertices.items); + // fixme: free the rest of the prism data free(p); } delete[] go.items; return res; -} \ No newline at end of file +} diff --git a/scheme/meep.scm.in b/scheme/meep.scm.in index f08ed6da8..01233005c 100644 --- a/scheme/meep.scm.in +++ b/scheme/meep.scm.in @@ -1122,12 +1122,10 @@ (export-type (make-list-type 'integer)) -(define-class simple-prism no-parent - (define-property vertices no-default (make-list-type 'vector3)) - (define-property height no-default 'number) - (define-property axis no-default 'vector3)) -(export-type (make-list-type 'simple-prism)) - +(define* (get-GDSII-prisms m GDSIIFile #:optional (layer -1) (zmin 0) (zmax 0)) + (map (lambda (data) + (make prism (material m) (center auto-center) (vertices (car data)) (height (cadr data)) (axis (caddr data)))) + (get-GDSII-prism-data GDSIIFile layer zmin zmax))) ; **************************************************************** ; harminv functions for extracting bands, etcetera