2015-02-14 23:32:58 +01:00
|
|
|
/** \file
|
|
|
|
* STL file format.
|
|
|
|
*
|
|
|
|
* Parse an STL file into an easily traversed structure.
|
|
|
|
*/
|
|
|
|
#ifndef _stl3d_h_
|
|
|
|
#define _stl3d_h_
|
|
|
|
|
|
|
|
#include "v3.h"
|
|
|
|
|
|
|
|
typedef struct stl_vertex stl_vertex_t;
|
|
|
|
typedef struct stl_face stl_face_t;
|
|
|
|
|
|
|
|
#define STL_MAX_FACES 64
|
|
|
|
|
|
|
|
struct stl_vertex {
|
|
|
|
v3_t p;
|
|
|
|
int num_face;
|
|
|
|
stl_face_t *face[STL_MAX_FACES];
|
2015-02-14 23:59:08 +01:00
|
|
|
int face_num[STL_MAX_FACES]; // which vertex on the face
|
2015-02-14 23:32:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct stl_face
|
|
|
|
{
|
|
|
|
stl_vertex_t * vertex[3];
|
2015-02-15 01:01:12 +01:00
|
|
|
stl_face_t * face[3];
|
|
|
|
double angle[3];
|
2015-02-14 23:32:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int num_vertex;
|
|
|
|
stl_vertex_t * vertex;
|
|
|
|
|
|
|
|
int num_face;
|
|
|
|
stl_face_t * face;
|
|
|
|
} stl_3d_t;
|
|
|
|
|
|
|
|
|
|
|
|
stl_3d_t *
|
|
|
|
stl_3d_parse(
|
|
|
|
int fd
|
|
|
|
);
|
|
|
|
|
2015-02-15 20:35:42 +01:00
|
|
|
|
|
|
|
/** Generate the list of vertices that are coplanar given a starting
|
|
|
|
* vertex in the stl file.
|
|
|
|
*
|
|
|
|
* vertex_list should have enough space to contain at least as many
|
|
|
|
* vertices as in the stl file.
|
|
|
|
*
|
|
|
|
* if face_used is not null it will be populated with which faces
|
|
|
|
* have been traversed during the search. it should have enough size
|
|
|
|
* to contain all of the faces in the file.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
stl_trace_face(
|
|
|
|
const stl_3d_t * const stl,
|
|
|
|
const stl_face_t * const f_start,
|
|
|
|
const stl_vertex_t ** vertex_list,
|
2015-02-15 22:03:41 +01:00
|
|
|
int * const face_used,
|
|
|
|
int start_vertex
|
2015-02-15 20:35:42 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
2015-02-15 20:55:43 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
v3_t origin;
|
|
|
|
v3_t x;
|
|
|
|
v3_t y;
|
|
|
|
v3_t z;
|
|
|
|
} refframe_t;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
refframe_init(
|
|
|
|
refframe_t * ref,
|
|
|
|
const v3_t p0,
|
|
|
|
const v3_t p1,
|
|
|
|
const v3_t p2
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2015-02-15 22:13:32 +01:00
|
|
|
void
|
|
|
|
refframe_inset(
|
|
|
|
const refframe_t * const ref,
|
|
|
|
const double inset_dist,
|
|
|
|
double * const x_out,
|
|
|
|
double * const y_out,
|
|
|
|
const v3_t p0, // previous point
|
|
|
|
const v3_t p1, // current point to inset
|
|
|
|
const v3_t p2 // next point
|
|
|
|
);
|
|
|
|
|
2015-02-15 20:55:43 +01:00
|
|
|
/** Project a 3D point onto a 2D space */
|
|
|
|
void
|
|
|
|
v3_project(
|
|
|
|
const refframe_t * const ref,
|
|
|
|
const v3_t p_in,
|
|
|
|
double * const x_out,
|
|
|
|
double * const y_out
|
|
|
|
);
|
|
|
|
|
2015-05-03 21:12:01 +02:00
|
|
|
/** Project a point in a reference frame back into 3D */
|
|
|
|
v3_t
|
|
|
|
refframe_project(
|
|
|
|
const refframe_t * const ref,
|
|
|
|
const v3_t p
|
|
|
|
);
|
2015-02-15 20:55:43 +01:00
|
|
|
|
2015-02-14 23:32:58 +01:00
|
|
|
#endif
|