Class td_plot_base¶
- class o2sclpy.td_plot_base¶
A class for managing 3D visualizations
- png_counter = 0¶
Counter for PNGs from LaTeX used in td_mat()
- td_arrow(x1, y1, z1, x2, y2, z2, name='arrow', mat='white', r=0, tail_ratio=0.9, n_theta=20, head_width=3, coords='internal')¶
Documentation for o2graph command
td-arrow
:Create a 3D arrow (experimental)
Command-line arguments:
<x1> <y1> <z1> <x2> <y2> <z2> [kwargs]
This command plots and arrow (a combination of a cylinder for the body of the arrow and a cone for the head) from point (x1,y1,z1) to point (x2,y2,z2). By default, the arrow coordinates are specified in the internal coordinate system. If the keyword argument
coords
isuser
, then the coordinates are in the user coordinate system.The fraction of the length of the cylinder to the distance between the user-specified points is given in
tail_ratio
and defaults to 0.9. The valuer
is the radius of the cylinder, and the base of the code has a radius of twicer
. If the user-specified value ofr
is zero or negative, then the default value is used (the length of the arrow divided by 80). The argumentn_theta
specifies the number of vertices in the azimuthal direction. The total number of faces is always three timesn_theta
.
- td_axis_label(ldir: str, tex_label: str, tex_mat_name: str = '', end_mat_name: str = 'white', png_file: str = '', group_name: str = '', offset: float = 0.1, height: float = 0.1, flatten: str = 'white')¶
Documentation for o2graph command
td-axis-label
:Create a 3D axis label (experimental).
Command-lin<e arguments:
<ldir> <tex_label> [kwargs]
Create an axis label in the direction
ldir
with labeltex_label
.Direction,
ldir
, must be eitherx
,y
, orz
. The LaTeX image fromtex_label
will be stored in file namedpng_file
. A new material will be created from the LaTeX image, namedtex_mat_name
and added to the material list before the corresponding mesh is added. Iftex_mat_name
is empty, thenmat_xtitle
,mat_ytitle
, ormat_ztitle
will be used, depending on the direction. Ifgroup_name
is empty, thenx_title
,y_title
, orz_title
will be used, depending on the direction.The material named
end_mat_name
will be used for the two faces which do not have labels. Ifend_mat_name
is the default,white
, then a default white material will be created for that purpose. Otherwise, it is presumed the user has already added the material.The number
offset
is the offset of the label from the x-axis, in the internal coordinate system. The numberheight
is used for the height dimension of the faces with the LaTeX image, and the width is computed automatically from the aspect ratio of the LaTeX output.End of documentation for o2graph command
td-axis-label
.This function uses
o2sclpy.latex_prism()
,
- td_cyl(x1, y1, z1, x2, y2, z2, r, name='cyl', mat='white', n_theta=20, coords='internal', tex_ul=[0, 0, 0])¶
Documentation for o2graph command
td-cyl
:Create a 3D cylinder (experimental)
Command-line arguments:
<x1> <y1> <z1> <x2> <y2> <z2> <r> [kwargs]
This command plots a cylinder from point (x1,y1,z1) to point (x2,y2,z2) with radius r. The argument
n_theta
specifies the number of vertices in the azimuthal direction.
- td_den_plot(amp, args, cmap='', mat_name='white', normals=False)¶
Documentation for o2graph command
td-den-plot
:Create a 3D density plot (experimental).
Command-line arguments:
<x label> <y label> <z label> [kwargs]
Note that normals are typically not specified, because the density plot presumes flat shading. Blender, for example, uses smooth shading for GLTF files when normals are specified, and this can complicate the density plot.
- td_grid(n, name='grid', mat='white', auto_labels=False)¶
Documentation for o2graph command
td-grid
:Plot an axis in a 3d visualization (experimental)
Command-line arguments:
[kwargs]
Plot a grid of lines.
- td_icos(args, n_subdiv=0, r=0.04, phi_cut='', mat='white', coords='user', name='')¶
Documentation for o2graph command
td-icos
:Create a 3D icosphere (experimental).
Command-line arguments:
<x> <y> <z> [kwargs]
Plot an icosphere at the specified location. The allowed keyword arguments are
n_subdiv=0
, the number of subdivisions of the original icosahedron,r=0.04
, the radius of the icosphere in the internal coordinate system, andmat='white'
, the material to use for the icosphere surface, andname
, the name of the GLTF mesh. If the name is specified, the user is responsible for making sure that this name is unique. The phi_cut keyword argument does not yet work.Note that normals are typically not specified, because the icosphere presumes flat shading. Blender, for example, uses smooth shading for GLTF files when normals are specified, and this can complicate the texture mapping.
End of documentation for o2graph command
td-icos
.This function uses
o2sclpy.icosphere()
.
- td_light(ltype, loc=[0, 0, 0], ldir=[0, 0, -1], color=[1, 1, 1], intensity=1.0, lrange=None, name='', ica=0, oca=0.7853981633974483)¶
Documentation for o2graph command
td-light
:Create a 3D light source (experimental).
Command-line arguments:
<type> [kwargs]
Useful keyword arguments are loc=[0,0,0], ldir=[0,0,-1], color=[1,1,1], intensity=1.0, lrange=None, name=’’, ica=0, and oca=numpy.pi/4.0.
A light is just a python dictionary, with two additional entries, “location” for location and “direction” for direction.
- td_line(x1, y1, z1, x2, y2, z2, name='line', mat='', coords='user')¶
Documentation for o2graph command
td-line
:Plot a line in a 3d visualization (experimental)
Command-line arguments:
<x1> <y1> <z1> <x2> <y2> <z2> [kwargs]
Plot a line between the specified coordinates. Useful kwargs are
name='line'
, the name of the GLTF group,mat='white'
, the name of the material to use, andcoords='user'
, the coordinate system to use.By default, the line coordinates are specified in the internal coordinate system. If the keyword argument
coords
isuser
, then the coordinates are in the user coordinate system.Note that lines are not supported by all 3D viewing engines. They work on GLTF viewer and GLTF validator, but not on 3dviewer.net. I haven’t figured out how to get Blender to import GLTF lines yet. Points work better.
- td_mat(name: str, r: float, g: float, b: float, alpha: float = 1, metal: float = 0, rough: float = 1, ds: bool = True, txt: str = '', alpha_mode: str = 'opaque', alpha_cutoff: float = 0.5, efr: float = 0.0, efg: float = 0.0, efb: float = 0.0, packages: str = '', prefix: str = '', resize: bool = True)¶
Documentation for o2graph command
td-mat
:Create a 3D material (experimental)
Command-line arguments:
<name> <r> <g> <b> [kwargs]
Create a new material with the specified properties. The colors r, g, and b should be between 0 and 1.
Useful kwargs are:
* alpha: float=1 \ * metal: float=0 \ * rough: float=1 \ * ds: bool=True (double-sided) \ * txt: str='' (filename of the texture) \ * alpha_mode : str = 'opaque' \ * alpha_cutoff: float = 0.5 \ * efr: float = 0.0 (emissive factor; red channel) \ * efg: float = 0.0 (emissive factor; green channel) \ * efb: float = 0.0 (emissive factor; blue channel) \ * packages: str = '' \ * prefix: str = '' \ * resize: bool = True \
The value of alpha should be between 0 (fully transparent) and 1 (fully opaque).
Images are always resized to ensure the width and height are a power of 2. If
resize
is true, then the image is resized to fit the new width and height using the Pillow package. Otherwise, the color specified in r, g, and b is used to pad the edges if necessary. To pad with transparent pixels, setresize
to false andalpha
to zero.If the texture filename begins with the characters ‘cmap:’, a 256 by 2 png image is constructed with a matplotlib colormap. If it begins with ‘latex:’, then it is constructed from a LaTeX expression.
LaTeX textures are created in the working directory with the name
[td_wdir]/[prefix]latex%d.png
and then resized, if necessary, to files named[td_wdir]/[prefix]latexr%d.png
.End of documentation for o2graph command
td-mat
.This function uses
o2sclpy.latex_to_png()
,o2sclpy.cmap_to_png()
, ando2sclpy.png_power_two()
to generate textures and then creates an object of typeo2sclpy.td_plot_base.material
.
- td_ocamera(xmag=1.0, ymag=1.0, zfar=100.0, znear=0.01)¶
Desc
- td_pcamera(loc, ldir, aspect=1.0, yfov=0.7, zfar=100, znear=0.01)¶
Desc
- td_pgram(x1, y1, z1, x2, y2, z2, x3, y3, z3, name='pgram', mat='white', force_rect=False, match_txt=False, coords='user')¶
Documentation for o2graph command
td-pgram
:Plot a 3D parallelogram (experimental)
Command-line arguments:
<x1> <y1> <z1> <x2> <y2> <z2> <x3> <y3> <z3> [kwargs]
Plot a parallelogram with lower-left corner at (x1,y1,z1), lower-right corner at (x2,y2,z2), and upper-left corner at (x3,y3,z3). The coordinates of the upper-right corner are automatically computed. The parallelogram is two-dimensional and thus may disappear when viewed edge-on.
The allowed keyword arguments are name=’pgram’, mat=’white’, force_rect=False, match_txt=False and coords=’user’. The value
name
is the name of the associated mesh object. The valuemat
is the name of the material to be used. By default, a pure white material is created. Ifforce_rect
is true, then the parallelogram is forced to be a rectangle by shifting the upper-left corner along the vector defined by the lower corners. Ifmatch_txt
is true, then the parallelogram size is modified (by moving the corners closer to the lower-left corner) to fit the texture aspect ratio specified inmat
.End of documentation for o2graph command
td-pgram
.This function uses
o2sclpy.parallelogram()
,
- td_point(x1, y1, z1, name='point', mat_name='white', match_txt=False, coords='user')¶
Documentation for o2graph command
td-point
:Plot a 3D point (experimental)
Command-line arguments:
<x1> <y1> <z1> [kwargs]
End of documentation for o2graph command
td-point
.
- td_scatter(amp, args, mat_name: str = '', r: float = 0.04, n_subdiv: int = 0, metal: str = '', rough: str = '')¶
Documentation for o2graph command
td-scatter
:Create a 3D scatter plot (experimental).
Command-line arguments:
<x column> <y column> <z column> [r column, g column, b column] [kwargs]
Create a scatter plot from columns of a table object. The red, green and blue columns, if specified, are automatically no
Useful kwargs are
n_subdiv=0
, the number of subdivisions of the original icosahedron,r=0.04
, the radius of the icosphere in the internal coordinate system. The argumentmetal=''
, can either be a string containing a floating-point value between 0 and 1 to indicate the metalness, or the previxcol:
and then the name of the table column from which to take the value of the metalness. Similarly, the keywordrough=''
can be either a float or a string beginning withcol:
. If the value ofr
is less than or equal to zero, then the icospheres are written as points.If the x-, y- and z-limits are not set, then
td-scatter
uses the minimum and maximum values from the scattered points to set these limits so that the output will be normalized to be between 0 and 1.This function either creates all objects with the same material (by specifying a value for mat_name) or creates a new unique material for each point. You may need to create custom Python code for more sophisticated handling of the materials for the scatter plot.