commit 6dd7610f99ef6fe1bd0e57097266202f3da83ba9
parent a67c5de5e1129793942c5b577a0288e84f7d97aa
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Fri, 13 Oct 2017 11:30:16 +0200
Add the s3dut_create_thick_truncated_super_shape function
Diffstat:
2 files changed, 63 insertions(+), 18 deletions(-)
diff --git a/src/s3dut.h b/src/s3dut.h
@@ -109,10 +109,10 @@ s3dut_create_cylinder
/* Create a triangulated cylinder centered in 0 discretized in `nslices' around
* the Z axis and `nstacks' along the Z axis. The top and the bottom ends of
* the cylinder can be closed or not with a triangle fan whose center is on the
- * Z axis, according to the `close_ends' argument bit mask. Face vertices are
- * CCW ordered with respect to the cylinder center, i.e. they are CW ordered
- * from the outside point of view.
- * Similar to s3dut_create_cylinder with the ability to close ends or not. */
+ * Z axis, according to the `cap_mask' argument. Face vertices are CCW ordered
+ * with respect to the cylinder center, i.e. they are CW ordered from the
+ * outside point of view. Similar to s3dut_create_cylinder with the ability to
+ * close ends or not. */
S3DUT_API res_T
s3dut_create_thin_cylinder
(struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
@@ -126,16 +126,16 @@ s3dut_create_thin_cylinder
/* Create a triangulated thick cylinder centered in 0 discretized in `nslices'
* around the Z axis and `nstacks' along the Z axis, with walls of thickness
* `thickness'. The top and the bottom of the cylinder can be closed or not,
- * according to the `close_ends' argument bit mask. Closed ends are closed by
- * a wall of thickness `thickness' made of 2 triangle fans centered on the Z
- * axis. Face vertices are CCW ordered with respect to the walls' inside, i.e.
- * they are CW ordered from any point of view outside of the walls. */
+ * according to the `cap_mask' argument. Closed ends are closed by a wall of
+ * thickness `thickness' made of 2 triangle fans centered on the Z axis. Face
+ * vertices are CCW ordered with respect to the walls' inside, i.e. they are
+ * CW ordered from any point of view outside of the walls. */
S3DUT_API res_T
s3dut_create_thick_cylinder
(struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
const double radius, /* In ]thickness, INF); exterior radius */
const double height, /* In ]min_height, INF); min_height = 0,
- tickness or 2*thickness according to close_ends */
+ tickness or 2*thickness according to cap_mask */
const double thickness, /* In ]0, INF) */
const unsigned nslices, /* # subdivisions around Z axis in [3, INF) */
const unsigned nstacks, /* # subdivision along Z axis in [1, INF) */
@@ -171,9 +171,8 @@ s3dut_create_hemisphere
* the sphere can be truncated at some specified z, according to the `z_range'
* parameter. If truncated, the top and the bottom of the sphere can be closed
* with a triangle fan whose center is on the Z axis or not, according to the
- * `close_ends' argument bit mask. Face vertices are CCW ordered with respect
- * to the sphere center, i.e. they are CW ordered from the outside point of
- * view. */
+ * `cap_mask' argument. Face vertices are CCW ordered with respect to the
+ * sphere center, i.e. they are CW ordered from the outside point of view. */
S3DUT_API res_T
s3dut_create_truncated_sphere
(struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
@@ -188,8 +187,8 @@ s3dut_create_truncated_sphere
* around the Z axis and `nstacks' along the Z axis, with walls of thickness
* `thickness'. The top and the bottom of the sphere can be truncated at some
* specified z, according to the `z_range' parameter. If truncated, the top and
- * the bottom of the sphere can be closed or not, according to the `close_ends'
- * argument bit mask. Closed ends are closed by a wall of thickness `thickness'
+ * the bottom of the sphere can be closed or not, according to the `cap_mask'
+ * argument. Closed ends are closed by a wall of thickness `thickness'
* made of 2 triangle fans centered on the Z axis. Face vertices are CCW
* ordered with respect to the walls' inside, i.e. they are CW ordered from any
* point of view outside of the walls. */
@@ -205,7 +204,7 @@ s3dut_create_thick_truncated_sphere
struct s3dut_mesh** sphere);
/* Create a triangulated super shape centered in 0 and discretized in `nslices'
- * around the Z axis and `nstacks' along the Z axnis. Face vertices are CCW
+ * around the Z axis and `nstacks' along the Z axis. Face vertices are CCW
* ordered with respect to the center of the super shape.
*
* Assuming a point with the spherical coordinates {r, theta, phi} - with r the
@@ -214,7 +213,8 @@ s3dut_create_thick_truncated_sphere
* the following relations:
* x = r0(theta)*cos(theta) * r1(phi)*cos(phi)
* y = r0(theta)*sin(theta) * r1(phi)*cos(phi)
- * z = r1(phi)*sin(phi) */
+ * z = r1(phi)*sin(phi)
+ * with r0 and r1 refering to the two super formulas. */
S3DUT_API res_T
s3dut_create_super_shape
(struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
@@ -225,4 +225,26 @@ s3dut_create_super_shape
const unsigned nstacks, /* # subdivisions along Z axis in [2, INF) */
struct s3dut_mesh** super_shape);
+/* Create a triangulated super shape centered in 0 and discretized in `nslices'
+ * around the Z axis and `nstacks' along the Z axis, with walls of thickness
+ * `thickness'. Refer to the comments of the s3dut_create_super_shape function
+ * for informations on super shape geometry. The top and the bottom of the
+ * super shape can be truncated at some specified z, according to the `z_range'
+ * parameter. If truncated, the top and the bottom of the super shape can be
+ * closed with a triangle fan whose center is on the Z axis or not, according
+ * to the `cap_mask' argument. Face vertices are CCW ordered with from the
+ * inside point of view. */
+S3DUT_API res_T
+s3dut_create_thick_truncated_super_shape
+ (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
+ const struct s3dut_super_formula* formula0,
+ const struct s3dut_super_formula* formula1,
+ const double radius, /* In [0, INF) */
+ const double thickness, /* In ]0, INF) */
+ const unsigned nslices, /* # subdivisions around Z axis in [3, INF) */
+ const unsigned nstacks, /* # subdivisions along Z axis in [2, INF) */
+ const double z_range[2], /* Clamp the sphere to z_range. NULL <=> no clamp */
+ const int cap_mask, /* Combination of s3dut_cap_flag. Ignored if no clamp */
+ struct s3dut_mesh** super_shape);
+
#endif /* S3DUT_H */
diff --git a/src/s3dut_super_shape.c b/src/s3dut_super_shape.c
@@ -58,12 +58,29 @@ super_formula_eval(const struct s3dut_super_formula* form, const double angle)
******************************************************************************/
res_T
s3dut_create_super_shape
+ (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
+ const struct s3dut_super_formula* formula0,
+ const struct s3dut_super_formula* formula1,
+ const double radius, /* In [0, INF) */
+ const unsigned nslices, /* # subdivisions around Z axis in [3, INF) */
+ const unsigned nstacks, /* # subdivisions along Z axis in [2, INF) */
+ struct s3dut_mesh** super_shape)
+{
+ return s3dut_create_thick_truncated_super_shape(allocator, formula0,
+ formula1, radius, 0, nslices, nstacks, NULL, 0, super_shape);
+}
+
+res_T
+s3dut_create_thick_truncated_super_shape
(struct mem_allocator* allocator,
const struct s3dut_super_formula* formula0,
const struct s3dut_super_formula* formula1,
const double radius,
+ const double thickness,
const unsigned nslices,
const unsigned nstacks,
+ const double z_range[2],
+ const int cap_mask,
struct s3dut_mesh** mesh)
{
struct s3dut_mesh* sshape = NULL;
@@ -71,12 +88,18 @@ s3dut_create_super_shape
size_t ivert;
res_T res = RES_OK;
- if(radius<=0 || !formula0 || !formula1 || nslices<3 || nstacks<2 || !mesh) {
+ if(!formula0 || !formula1 || !mesh) {
res = RES_BAD_ARG;
goto error;
}
- res = s3dut_create_sphere(allocator, radius, nslices, nstacks, &sshape);
+ if(thickness == 0) {
+ res = s3dut_create_truncated_sphere(allocator, radius, nslices, nstacks,
+ z_range, cap_mask, &sshape);
+ } else {
+ res = s3dut_create_thick_truncated_sphere(allocator, radius, thickness,
+ nslices, nstacks, z_range, cap_mask, &sshape);
+ }
if(res != RES_OK) goto error;
/* Positioned the sphere vertices wrt to the super formulas */