STL (STereoLithography) file library.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
real(kind=wp), | private, | parameter | :: | zero | = | 0.0_wp | |
real(kind=wp), | private, | parameter | :: | one | = | 1.0_wp | |
real(kind=wp), | private, | parameter | :: | deg2rad | = | acos(-1.0_wp)/180.0_wp |
degrees to radians |
real(kind=wp), | private, | parameter, dimension(3) | :: | x_unit | = | [one, zero, zero] |
x-axis unit vector |
real(kind=wp), | private, | parameter, dimension(3) | :: | y_unit | = | [zero, one, zero] |
y-axis unit vector |
real(kind=wp), | private, | parameter, dimension(3) | :: | z_unit | = | [zero, zero, one] |
z-axis unit vector |
a 3D triangular plate. [note that the order of the vertices defines the surface normal via the right-hand rule]
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
real(kind=wp), | public, | dimension(3) | :: | v1 | = | zero |
first vertex |
real(kind=wp), | public, | dimension(3) | :: | v2 | = | zero |
second vertex |
real(kind=wp), | public, | dimension(3) | :: | v3 | = | zero |
third vertex |
the main class for STL file I/O.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
integer, | private | :: | n_plates | = | 0 |
number of plates |
|
integer, | private | :: | chunk_size | = | 1000 |
expand |
|
type(plate), | private, | dimension(:), allocatable | :: | plates |
the array of plates |
procedure, public :: write_ascii_stl_file | |
procedure, public :: write_binary_stl_file | |
procedure, public :: read => read_binary_stl_file | |
procedure, public :: read_tab_file | |
procedure, public :: destroy => destroy_stl_file | |
procedure, public :: add_plate | |
procedure, public :: add_sphere | |
procedure, public :: add_cylinder | |
procedure, public :: add_curve | |
procedure, public :: add_cone | |
procedure, public :: add_arrow | |
procedure, public :: add_axes | |
procedure, public :: shift_mesh | |
procedure, public :: set_chunk_size | |
procedure, private :: generate_circle | |
procedure, private :: compute_vertex_scale |
Compute the scale factor for the vertices (for writing to a file).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(in) | :: | me | |||
real(kind=wp), | intent(in), | optional | :: | bounding_box |
scale vertices so that model fits in a box of this size (if <=0, no scaling is done) |
scale factor
Returns true if the two vectors are perpendicular.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | v1 | ||
real(kind=wp), | intent(in), | dimension(:) | :: | v2 |
Normal vector for the plate (computed using right hand rule).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(3) | :: | v1 |
first vertex of the triangle [x,y,z] |
|
real(kind=wp), | intent(in), | dimension(3) | :: | v2 |
second vertex of the triangle [x,y,z] |
|
real(kind=wp), | intent(in), | dimension(3) | :: | v3 |
third vertex of the triangle [x,y,z] |
surface normal vector
3x1 Unit vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(3) | :: | r |
Vector cross product.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(3) | :: | a | ||
real(kind=wp), | intent(in), | dimension(3) | :: | b |
Convert spherical (r,alpha,beta) to Cartesian (x,y,z).
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | r |
magnitude |
||
real(kind=wp), | intent(in) | :: | alpha |
right ascension [deg] |
||
real(kind=wp), | intent(in) | :: | beta |
declination [deg] |
[x,y,z] vector
Rotate a 3x1 vector in space, given an axis and angle of rotation.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(3) | :: | v |
vector to rotate |
|
real(kind=wp), | intent(in), | dimension(3) | :: | k |
rotation axis |
|
real(kind=wp), | intent(in) | :: | theta |
rotation angle [deg] |
result
The projection of one vector onto another vector.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(:) | :: | a |
the original vector |
|
real(kind=wp), | intent(in), | dimension(size(a)) | :: | b |
the vector to project on to |
the projection of a onto b
Project a vector onto a plane.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in), | dimension(3) | :: | a |
the original vector |
|
real(kind=wp), | intent(in), | dimension(3) | :: | b |
the plane to project on to (a normal vector) |
the projection of a onto the b plane
Destroy an stl_file
.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me |
Set the chunk size in the class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
integer, | intent(in) | :: | chunk_size |
must be >0 |
Add a plate to the class.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(3) | :: | v1 |
first vertex |
|
real(kind=wp), | intent(in), | dimension(3) | :: | v2 |
second vertex |
|
real(kind=wp), | intent(in), | dimension(3) | :: | v3 |
third vertex |
Generate a binary STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(in) | :: | me | |||
character(len=*), | intent(in) | :: | filename |
STL file name |
||
integer, | intent(out) | :: | istat |
|
||
real(kind=wp), | intent(in), | optional | :: | bounding_box |
scale vertices so that model fits in a box of this size (if <=0, no scaling is done) |
Read a binary STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(out) | :: | me | |||
character(len=*), | intent(in) | :: | filename |
STL file name |
||
integer, | intent(out) | :: | istat |
|
Read a text vertex-facet file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(out) | :: | me | |||
character(len=*), | intent(in) | :: | filename |
Vertex-facet file name |
||
integer, | intent(out) | :: | istat |
|
Generate an ascii STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(in) | :: | me | |||
character(len=*), | intent(in) | :: | filename |
STL file name |
||
character(len=*), | intent(in) | :: | modelname |
the solid name (should not contain spaces) |
||
integer, | intent(out) | :: | istat |
|
||
real(kind=wp), | intent(in), | optional | :: | bounding_box |
scale vertices so that model fits in a box of this size (if <=0, no scaling is done) |
Shift the vertex coordinates so that there are no non-positive components.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me |
Add a sphere to an STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(3) | :: | center |
coordinates of sphere center [x,y,z] |
|
real(kind=wp), | intent(in) | :: | radius |
radius of the sphere |
||
integer, | intent(in) | :: | num_lat_points |
number of latitude points (not counting poles) |
||
integer, | intent(in) | :: | num_lon_points |
number of longitude points |
Add a cylinder to an STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(3) | :: | v1 |
coordinates of initial point |
|
real(kind=wp), | intent(in), | dimension(3) | :: | v2 |
coordinates of final point |
|
real(kind=wp), | intent(in) | :: | radius |
radius of the cylinder |
||
integer, | intent(in) | :: | num_points |
number of point on the circle (>=3) |
||
logical, | intent(in) | :: | initial_cap |
add a cap plate to the initial point |
||
logical, | intent(in) | :: | final_cap |
add a cap plate to the final point |
||
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | initial_normal |
outward normal vector for initial circle |
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | final_normal |
outward normal vector for final circle |
real(kind=wp), | intent(out), | optional, | dimension(3) | :: | final_normal_used |
outward normal vector for final circle actually used |
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | initial_vector |
vector to use to generate the initial circle (x_unit by default) |
real(kind=wp), | intent(out), | optional, | dimension(3) | :: | final_initial_vector_used |
the initial vector used for the final cap to generate the points |
Add a cone to an STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(3) | :: | v1 |
coordinates of initial point (bottom of the cone) |
|
real(kind=wp), | intent(in), | dimension(3) | :: | v2 |
coordinates of final point (point of the cone) |
|
real(kind=wp), | intent(in) | :: | radius |
radius of the cone (the bottom plate) |
||
integer, | intent(in) | :: | num_points |
number of point on the circle (>=3) |
||
logical, | intent(in) | :: | initial_cap |
add a cap plate to the initial point (bottom) |
||
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | initial_normal |
outward normal vector for initial plate (bottom) |
Add x,y,z axes to an STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(3) | :: | origin |
coordinates of the origin of the axes |
|
real(kind=wp), | intent(in), | dimension(3) | :: | vx |
x axis vector |
|
real(kind=wp), | intent(in), | dimension(3) | :: | vy |
y axis vector |
|
real(kind=wp), | intent(in), | dimension(3) | :: | vz |
z axis vector |
|
real(kind=wp), | intent(in) | :: | radius |
radius of the cylinder |
||
integer, | intent(in) | :: | num_points |
number of point on the circle (>=3) |
||
real(kind=wp), | intent(in) | :: | arrowhead_radius_factor |
arrowhead cone radius factor (multiple of cylinder radius) |
||
real(kind=wp), | intent(in) | :: | arrowhead_length_factor |
arrowhead tip length factor (multiple of vector length) |
Add an arrow to an STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(3) | :: | origin |
coordinates of the origin of the axes |
|
real(kind=wp), | intent(in), | dimension(3) | :: | v |
vector |
|
real(kind=wp), | intent(in) | :: | radius |
radius of the cylinder |
||
integer, | intent(in) | :: | num_points |
number of point on the circle (>=3) |
||
real(kind=wp), | intent(in) | :: | arrowhead_radius_factor |
arrowhead cone radius factor (multiple of cylinder radius) |
||
real(kind=wp), | intent(in) | :: | arrowhead_length_factor |
arrowhead tip length factor (multiple of vector length) |
Generate the points in a circle, and optionally add it as a plate.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(3) | :: | c |
center of the circle |
|
real(kind=wp), | intent(in) | :: | radius |
radius of the cylinder |
||
real(kind=wp), | intent(in), | dimension(3) | :: | n |
normal vector to the circle |
|
integer, | intent(in) | :: | nc |
number of points on the circle (must be at least 3) |
||
logical, | intent(in) | :: | add_circle |
to also add to the circle as a plate |
||
real(kind=wp), | intent(out), | dimension(:,:), allocatable | :: | circle |
points on the circle |
|
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | initial_vector |
vector to use to generate the initial circle (x_unit by default) |
logical, | intent(in), | optional | :: | cw |
generate the points in the clockwise direction abound n (default is false) |
Add a curve to an STL file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(stl_file), | intent(inout) | :: | me | |||
real(kind=wp), | intent(in), | dimension(:) | :: | x |
x coordinate array |
|
real(kind=wp), | intent(in), | dimension(:) | :: | y |
y coordinate array |
|
real(kind=wp), | intent(in), | dimension(:) | :: | z |
z coordinate array |
|
real(kind=wp), | intent(in) | :: | radius |
radius of the cylinder |
||
integer, | intent(in) | :: | num_points |
number of point on the cylinder perimeter |
||
logical, | intent(in), | optional | :: | initial_cap |
add a cap plate to the initial point |
|
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | initial_normal |
outward normal vector for initial circle |
logical, | intent(in), | optional | :: | final_cap |
add a cap plate to the final point |
|
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | final_normal |
outward normal vector for final circle |
real(kind=wp), | intent(in), | optional, | dimension(3) | :: | initial_vector |
vector to use to generate the first circle (x_unit by default) |