commit 348cff3810baae116c46565b33881ded31c87ad2
parent 3aa6422c669636bdf3bf4bf304d3e6ea357826eb
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 23 Nov 2015 15:47:11 +0100
Update the super-shape distribution
The distribution of the whole set of attributes of the super shape are
now controllable.
Diffstat:
3 files changed, 74 insertions(+), 31 deletions(-)
diff --git a/src/schiff_args.c b/src/schiff_args.c
@@ -139,12 +139,13 @@ print_help(const char* binary)
" distributed with respect to the RDISTRIB distribution.\n",
SCHIFF_SPHERE_DEFAULT.nslices);
printf(
-" -u MDISTRIB,N2DISTRIB[,N]\n"
+" -u FORMULA0#FORMULA1[#N]\n"
" the soft particles are 3D super shapes discretized in N slices\n"
-" along 2PI. By default N is %u. The A, B, N0 and N1 parameters\n"
-" of the super formulas are fixed to 1 while the MDISTRIB and\n"
-" the N2DISTRIB control the distribution of the M, and N2\n"
-" supershape parameters, respectively.\n",
+" along 2PI. By default N is %u. The FORMULA<0|1> arguments\n"
+" control the parameter distribution of the superformulas. Each\n"
+" FORMULA is formated as \"A,B,M,N0,N1,N2\" where A, B, M, N0, N1\n"
+" and N2 are the parameter distributions of the corresponding\n"
+" superformula parmater.\n",
SCHIFF_SUPER_SHAPE_DEFAULT.nslices);
printf(
" -w A[:B]... list of wavelengths in vacuum (expressed in micron) to\n"
@@ -384,6 +385,46 @@ error:
}
static res_T
+parse_super_formula(const char* str, struct schiff_param formula[6])
+{
+ struct str buf;
+ char* tk;
+ char* tk_ctx;
+ int i;
+ res_T res = RES_OK;
+ ASSERT(str && formula);
+
+ str_init(&mem_default_allocator, &buf);
+
+ res = str_set(&buf, str);
+ if(res != RES_OK) {
+ fprintf(stderr,
+ "Not enough memory. Couldn't parse the super formula `%s'.\n",
+ str);
+ goto error;
+ }
+
+ tk = strtok_r(str_get(&buf), ",", &tk_ctx);
+ for(i=0; i < 6 && tk; ++i ) {
+ res = parse_param_distribution(tk, formula + i);
+ if(res != RES_OK) goto error;
+ tk = strtok_r(NULL, ",", &tk_ctx);
+ }
+
+ if(i != 6 || tk) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
+exit:
+ str_release(&buf);
+ return res;
+error:
+ fprintf(stderr, "Invalid super formula `%s'.\n", str);
+ goto exit;
+}
+
+static res_T
parse_super_shape_distribution(const char* str, struct schiff_args* args)
{
struct str buf;
@@ -408,14 +449,14 @@ parse_super_shape_distribution(const char* str, struct schiff_args* args)
goto error;
}
- /* Distribution of the M parameters */
- tk = strtok_r(str_get(&buf), ",", &tk_ctx);
- res = parse_param_distribution(tk, &args->geom.data.super_shape.M);
+ /* Distribution of the super formula 0 parameters */
+ tk = strtok_r(str_get(&buf), "#", &tk_ctx);
+ res = parse_super_formula(tk, args->geom.data.super_shape.formulas[0]);
if(res != RES_OK) goto error;
- /* Distribution of N2 parameters */
- tk = strtok_r(NULL, ",", &tk_ctx);
- res = parse_param_distribution(tk, &args->geom.data.super_shape.N2);
+ /* Distribution of the super formula 1 parameters */
+ tk = strtok_r(NULL, "#", &tk_ctx);
+ res = parse_super_formula(tk, args->geom.data.super_shape.formulas[1]);
if(res != RES_OK) goto error;
/* Super shape discretisation */
diff --git a/src/schiff_geometry.c b/src/schiff_geometry.c
@@ -34,8 +34,6 @@
#include <star/ssp.h>
#include <star/sschiff.h>
-enum { A, B, M, N0, N1, N2 }; /* Super formula arguments */
-
/* 3D Context of the sphere geometry */
struct sphere_context {
float radius; /* Sphere radius */
@@ -265,6 +263,7 @@ geometry_sample_super_shape
struct s3d_vertex_data attrib;
const struct schiff_super_shape* sshape;
size_t nverts, nprims;
+ int iform, iattr;
ASSERT(rng && mtl && shape && context);
ASSERT(distrib->geometry->type == SCHIFF_SUPER_SHAPE);
@@ -272,20 +271,11 @@ geometry_sample_super_shape
geom.mesh = distrib->mesh;
geom.type = SCHIFF_SUPER_SHAPE;
- geom.data.super_shape.formulas[0][A] = 1.0;
- geom.data.super_shape.formulas[0][B] = 1.0;
- geom.data.super_shape.formulas[0][N0] = 1.0;
- geom.data.super_shape.formulas[0][N1] = 1.0;
-
- geom.data.super_shape.formulas[1][A] = 1.0;
- geom.data.super_shape.formulas[1][B] = 1.0;
- geom.data.super_shape.formulas[1][N0] = 1.0;
- geom.data.super_shape.formulas[1][N1] = 1.0;
-
- geom.data.super_shape.formulas[0][M] = (float)eval_param(&sshape->M, rng);
- geom.data.super_shape.formulas[1][M] = (float)eval_param(&sshape->M, rng);
- geom.data.super_shape.formulas[0][N2] = (float)eval_param(&sshape->N2, rng);
- geom.data.super_shape.formulas[1][N2] = (float)eval_param(&sshape->N2, rng);
+ FOR_EACH(iform, 0, 2) {
+ FOR_EACH(iattr, 0, 6) {
+ geom.data.super_shape.formulas[iform][iattr] =
+ (float)eval_param(&sshape->formulas[iform][iattr], rng);
+ }}
attrib.usage = S3D_POSITION;
attrib.type = S3D_FLOAT3;
diff --git a/src/schiff_geometry.h b/src/schiff_geometry.h
@@ -78,13 +78,25 @@ struct schiff_cylinder {
static const struct schiff_cylinder SCHIFF_CYLINDER_DEFAULT =
SCHIFF_CYLINDER_DEFAULT__;
+enum { A, B, M, N0, N1, N2 }; /* Super formula arguments */
+
struct schiff_super_shape {
- struct schiff_param M;
- struct schiff_param N2;
+ struct schiff_param formulas[2][6];
unsigned nslices;
};
-#define SCHIFF_SUPER_SHAPE_DEFAULT__ \
- {SCHIFF_PARAM_DEFAULT__, SCHIFF_PARAM_DEFAULT__, 64}
+#define SCHIFF_SUPER_SHAPE_DEFAULT__ \
+ {{{SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__}, \
+ {SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__, \
+ SCHIFF_PARAM_DEFAULT__}}, 64}
static const struct schiff_super_shape SCHIFF_SUPER_SHAPE_DEFAULT =
SCHIFF_SUPER_SHAPE_DEFAULT__;