commit 23164bb2ea5d52d7a4fe40cfc5582c0e167bd061
parent ee218e7585b762d47bd2f4fbebaafdfbc831a265
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 11 Apr 2017 18:24:32 +0200
Use Solstice solver's analytic spheres for Solstice's spheres.
Add the stacks parameter.
Diffstat:
5 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/doc/input b/doc/input
@@ -201,6 +201,7 @@
sphere:
radius: REAL # in ]0, INF)
[ slices: INTEGER ] # in [4, 4096]. Default 16
+[ stacks: INTEGER ] # in [2, 4096]. Default slices/2
<stl> ::=
stl:
diff --git a/src/parser/solparser_geometry.c b/src/parser/solparser_geometry.c
@@ -881,7 +881,7 @@ parse_sphere
const yaml_node_t* sphere,
struct solparser_shape_sphere_id* out_ishape)
{
- enum { RADIUS, SLICES };
+ enum { RADIUS, SLICES, STACKS };
struct solparser_shape_sphere* shape = NULL;
size_t ishape = SIZE_MAX;
intptr_t i, n;
@@ -906,6 +906,7 @@ parse_sphere
n = sphere->data.mapping.pairs.top - sphere->data.mapping.pairs.start;
shape->nslices = 16; /* default value */
+ shape->nstacks = 8; /* initial default value */
FOR_EACH(i, 0, n) {
yaml_node_t* key;
yaml_node_t* val;
@@ -932,6 +933,11 @@ parse_sphere
} else if(!strcmp((char*)key->data.scalar.value, "slices")) {
SETUP_MASK(SLICES, "slices");
res = parse_integer(parser, val, 4, 4096, &shape->nslices);
+ if(!(mask & BIT(STACKS)))
+ shape->nstacks = shape->nslices / 2; /* if unset, new default value */
+ } else if(!strcmp((char*)key->data.scalar.value, "stacks")) {
+ SETUP_MASK(STACKS, "stacks");
+ res = parse_integer(parser, val, 2, 4096, &shape->nstacks);
} else {
log_err(parser, key, "unknown sphere parameter `%s'.\n",
key->data.scalar.value);
diff --git a/src/parser/solparser_shape.h b/src/parser/solparser_shape.h
@@ -371,6 +371,7 @@ struct solparser_shape_cylinder {
struct solparser_shape_sphere {
double radius;
long nslices;
+ long nstacks;
};
struct solparser_shape_cuboid_id { size_t i; };
diff --git a/src/parser/yaml/test_ko_0.yaml b/src/parser/yaml/test_ko_0.yaml
@@ -881,6 +881,9 @@
# slices should be a number
- geometry: [ { sphere: { slices: "dummy" } } ]
---
+# stacks should be a number
+- geometry: [ { sphere: { stacks: "dummy" } } ]
+---
# -1 invalid
- geometry: [ { sphere: { radius: -1 } } ]
---
@@ -893,12 +896,21 @@
# 4097 invalid
- geometry: [ { sphere: { radius: 1, slices: 4097 } } ]
---
+# 0 invalid
+- geometry: [ { sphere: { radius: 1, stacks: 0 } } ]
+---
+# 4097 invalid
+- geometry: [ { sphere: { radius: 1, stacks: 4097 } } ]
+---
# 2x radius
- geometry: [ { sphere: { radius: 1, radius: 1 } } ]
---
# 2x slices
- geometry: [ { sphere: { slices: 10, slices: 10 } } ]
---
+# 2x stacks
+- geometry: [ { sphere: { stacks: 10, stacks: 10 } } ]
+---
#
# <stl> ::=
diff --git a/src/solstice_object.c b/src/solstice_object.c
@@ -201,7 +201,7 @@ create_cylinder
struct ssol_shape* ssol_shape = NULL;
struct ssol_analytic_surface analytic = SSOL_ANALYTIC_SURFACE_NULL__;
res_T res = RES_OK;
- ASSERT(solstice);
+ ASSERT(solstice && out_ssol_shape);
cylinder = solparser_get_shape_cylinder(solstice->parser, cylinder_id);
@@ -246,25 +246,34 @@ create_sphere
struct ssol_shape** out_ssol_shape)
{
const struct solparser_shape_sphere* sphere;
- struct s3dut_mesh* mesh = NULL;
struct ssol_shape* ssol_shape = NULL;
+ struct ssol_analytic_surface analytic = SSOL_ANALYTIC_SURFACE_NULL__;
res_T res = RES_OK;
ASSERT(solstice && out_ssol_shape);
sphere = solparser_get_shape_sphere(solstice->parser, sphere_id);
+
+ analytic.type = SSOL_ANALYTIC_SPHERE;
+ analytic.data.cylinder.radius = sphere->radius;
+ d33_set(analytic.transform, transform);
+ d3_set(analytic.transform + 9, transform + 9);
ASSERT(sphere->nslices > 0 && sphere->nslices < UINT_MAX);
- res = s3dut_create_sphere(solstice->allocator, sphere->radius,
- (unsigned)sphere->nslices, (unsigned)(sphere->nslices/2), &mesh);
+ ASSERT(sphere->nstacks > 0 && sphere->nstacks < UINT_MAX);
+ analytic.data.sphere.nslices = (unsigned)sphere->nslices;
+ analytic.data.sphere.nstacks = (unsigned)sphere->nstacks;
+
+ res = ssol_shape_create_analytic_surface(solstice->ssol, &ssol_shape);
if(res != RES_OK) {
- fprintf(stderr, "Could not create the sphere 3D data.\n");
+ fprintf(stderr, "Could not create a Solstice Solver analytic surface.\n");
goto error;
}
- res = create_ssol_shape_mesh(solstice, transform, mesh, &ssol_shape);
- if(res != RES_OK) goto error;
-
+ res = ssol_analytic_surface_setup(ssol_shape, &analytic);
+ if(res != RES_OK) {
+ fprintf(stderr, "Could not setup the Solstice Solver analytic surface.\n");
+ goto error;
+ }
exit:
- if(mesh) S3DUT(mesh_ref_put(mesh));
*out_ssol_shape = ssol_shape;
return res;
error: