commit fa7ceed5addf465bd22181b795c59df86f68037a
parent d4796cc65e60ae8fba8e1e570135c3d746ed769d
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 18 Nov 2016 16:29:50 +0100
Implement the shape getters
Diffstat:
5 files changed, 132 insertions(+), 11 deletions(-)
diff --git a/doc/input b/doc/input
@@ -3,7 +3,8 @@
--------------------------------------------------------------------------------
# Declare materials
- material: &lambertian
- matte: { reflectivity: 1 }
+ matte:
+ reflectivity: 1
- material: &mirror
mirror: { reflectivity: 1, roughness: 0 }
@@ -83,7 +84,7 @@
- <item>
[ - <item> ... ]
-<items> ::=
+<item> ::=
<geometry>
| <material>
| <entity>
diff --git a/src/solstice_entity.h b/src/solstice_entity.h
@@ -41,7 +41,7 @@ struct solstice_entity_id { size_t i; };
#define HTABLE_KEY_FUNCTOR_COPY_AND_RELEASE str_copy_and_release
#define HTABLE_KEY_FUNCTOR_EQ str_eq
#define HTABLE_KEY_FUNCTOR_HASH str_hash
-#define HTABLE_DATA size_t
+#define HTABLE_DATA struct solstice_entity_id
#include <rsys/hash_table.h>
struct solstice_entity {
diff --git a/src/solstice_parser.c b/src/solstice_parser.c
@@ -1932,7 +1932,8 @@ entity_register_name
const size_t isolent)
{
struct solstice_entity* solent;
- size_t* pisolent;
+ struct solstice_entity_id* pisolent;
+ struct solstice_entity_id id;
res_T res = RES_OK;
ASSERT(parser && htable);
ASSERT(isolent < darray_entity_size_get(&parser->entities));
@@ -1947,7 +1948,8 @@ entity_register_name
return RES_BAD_ARG;
}
- res = htable_str2sols_set(htable, &solent->name, &isolent);
+ id.i = isolent;
+ res = htable_str2sols_set(htable, &solent->name, &id);
if(res != RES_OK) {
log_err(parser, entity, "could not register the entity.\n");
return res;
@@ -2009,7 +2011,7 @@ parse_entity_name
if(res != RES_OK) goto error;
if(strchr(str_cget(str), '.')) {
- log_err(parser, name, "invalid character `.' in the entity name `%s'.\n",
+ log_err(parser, name, "invalid character `.' in the entity name `%s'.\n",
str_cget(str));
goto error;
}
@@ -2818,14 +2820,14 @@ solstice_parser_find_entity
tk = strtok(cstr, ".");
htable = &parser->str2entities;
while(tk) {
- size_t* pientity;
+ struct solstice_entity_id* pientity;
str_set(&str_tk, tk);
pientity = htable_str2sols_find(htable, &str_tk);
if(!pientity) {
tk = NULL;
} else {
tk = strtok(NULL, ".");
- entity = darray_entity_data_get(&parser->entities) + *pientity;
+ entity = darray_entity_data_get(&parser->entities) + pientity->i;
htable = &entity->str2children;
}
}
@@ -2911,6 +2913,61 @@ solstice_parser_get_shape
return darray_shape_cdata_get(&parser->shapes) + shape.i;
}
+const struct solstice_shape_cuboid*
+solstice_parser_get_shape_cuboid
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_cuboid_id cuboid)
+{
+ ASSERT(parser && cuboid.i < darray_cuboid_size_get(&parser->cuboids));
+ return darray_cuboid_cdata_get(&parser->cuboids) + cuboid.i;
+}
+
+const struct solstice_shape_cylinder*
+solstice_parser_get_shape_cylinder
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_cylinder_id cylinder)
+{
+ ASSERT(parser && cylinder.i < darray_cylinder_size_get(&parser->cylinders));
+ return darray_cylinder_cdata_get(&parser->cylinders) + cylinder.i;
+}
+
+const struct solstice_shape_imported_geometry*
+solstice_parser_get_shape_obj
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_imported_geometry_id impgeom)
+{
+ ASSERT(parser && impgeom.i < darray_impgeom_size_get(&parser->objs));
+ return darray_impgeom_cdata_get(&parser->objs) + impgeom.i;
+}
+
+const struct solstice_shape_paraboloid*
+solstice_parser_get_shape_parabol
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_paraboloid_id paraboloid)
+{
+ ASSERT(parser && paraboloid.i < darray_paraboloid_size_get(&parser->parabols));
+ return darray_paraboloid_cdata_get(&parser->parabols) + paraboloid.i;
+}
+
+const struct solstice_shape_paraboloid*
+solstice_parser_get_shape_parabolic_cylinder
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_paraboloid_id paraboloid)
+{
+ ASSERT(parser);
+ ASSERT(paraboloid.i<darray_paraboloid_size_get(&parser->parabolic_cylinders));
+ return darray_paraboloid_cdata_get(&parser->parabolic_cylinders)+paraboloid.i;
+}
+
+const struct solstice_shape_plane*
+solstice_parser_get_shape_plane
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_plane_id plane)
+{
+ ASSERT(parser && plane.i < darray_plane_size_get(&parser->planes));
+ return darray_plane_cdata_get(&parser->planes) + plane.i;
+}
+
const struct solstice_shape_sphere*
solstice_parser_get_shape_sphere
(const struct solstice_parser* parser,
@@ -2920,6 +2977,22 @@ solstice_parser_get_shape_sphere
return darray_sphere_cdata_get(&parser->spheres) + sphere.i;
}
+const struct solstice_shape_imported_geometry*
+solstice_parser_get_shape_stl
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_imported_geometry_id impgeom)
+{
+ ASSERT(parser && impgeom.i < darray_impgeom_size_get(&parser->stls));
+ return darray_impgeom_cdata_get(&parser->stls) + impgeom.i;
+}
+
+const struct solstice_sun*
+solstice_parser_get_sun(const struct solstice_parser* parser)
+{
+ ASSERT(parser && parser->sun_key);
+ return &parser->sun;
+}
+
void
solstice_parser_entity_iterator_begin
(struct solstice_parser* parser,
diff --git a/src/solstice_parser.h b/src/solstice_parser.h
@@ -99,11 +99,50 @@ solstice_parser_get_shape
(const struct solstice_parser* parser,
const struct solstice_shape_id shape);
+extern LOCAL_SYM const struct solstice_shape_cuboid*
+solstice_parser_get_shape_cuboid
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_cuboid_id cuboid);
+
+extern LOCAL_SYM const struct solstice_shape_cylinder*
+solstice_parser_get_shape_cylinder
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_cylinder_id cylinder);
+
+extern LOCAL_SYM const struct solstice_shape_imported_geometry*
+solstice_parser_get_shape_obj
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_imported_geometry_id impgeom);
+
+extern LOCAL_SYM const struct solstice_shape_paraboloid*
+solstice_parser_get_shape_parabol
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_paraboloid_id paraboloid);
+
+extern LOCAL_SYM const struct solstice_shape_paraboloid*
+solstice_parser_get_shape_parabolic_cylinder
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_paraboloid_id paraboloid);
+
+extern LOCAL_SYM const struct solstice_shape_plane*
+solstice_parser_get_shape_plane
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_plane_id plane);
+
extern LOCAL_SYM const struct solstice_shape_sphere*
solstice_parser_get_shape_sphere
(const struct solstice_parser* parser,
const struct solstice_shape_sphere_id sphere);
+extern LOCAL_SYM const struct solstice_shape_imported_geometry*
+solstice_parser_get_shape_stl
+ (const struct solstice_parser* parser,
+ const struct solstice_shape_imported_geometry_id impgeom);
+
+extern LOCAL_SYM const struct solstice_sun*
+solstice_parser_get_sun
+ (const struct solstice_parser* parser);
+
extern LOCAL_SYM void
solstice_parser_entity_iterator_begin
(struct solstice_parser* parser,
@@ -133,10 +172,8 @@ solstice_entity_iterator_eq
static FINLINE struct solstice_entity_id
solstice_entity_iterator_get(struct solstice_entity_iterator* it)
{
- struct solstice_entity_id id;
ASSERT(it);
- id.i = *htable_str2sols_iterator_data_get(&it->it__);
- return id;
+ return *htable_str2sols_iterator_data_get(&it->it__);
}
#endif /* SOLSTICE_PARSER_H */
diff --git a/src/test_solstice_parser2.c b/src/test_solstice_parser2.c
@@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "solstice_parser.h"
+#include "solstice_sun.h"
#include "test_solstice_utils.h"
int
@@ -34,6 +35,7 @@ main(int argc, char** argv)
const struct solstice_material_matte* matte;
const struct solstice_material_mirror* mirror;
const struct solstice_shape_sphere* sphere;
+ const struct solstice_sun* sun;
double tmp[3];
FILE* stream;
@@ -156,6 +158,14 @@ main(int argc, char** argv)
entity3 = solstice_parser_find_entity(parser, "lvl 0.lvl1b.lvl2");
CHECK(entity3, entity2);
+ sun = solstice_parser_get_sun(parser);
+ NCHECK(sun, NULL);
+ CHECK(sun->dni, 1.0);
+ CHECK(sun->radang_distrib_type, SOLSTICE_SUN_RADANG_DISTRIB_DIRECTIONAL);
+ CHECK(darray_spectrum_data_size_get(&sun->spectrum), 1);
+ CHECK(darray_spectrum_data_cdata_get(&sun->spectrum)[0].wavelength, 1.0);
+ CHECK(darray_spectrum_data_cdata_get(&sun->spectrum)[0].data, 1.0);
+
CHECK(solstice_parser_load(parser), RES_BAD_OP);
solstice_parser_ref_put(parser);