| Title: | Tools for Working with 3D Surface Measurements |
|---|---|
| Description: | The x3p file format is specified in ISO standard 5436:2000 to describe 3d surface measurements. 'x3ptools' allows reading, writing and basic modifications to the 3D surface measurements. |
| Authors: | Heike Hofmann [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-6216-5183>), Susan Vanderplas [aut] (ORCID: <https://orcid.org/0000-0002-3803-0972>), Yuhang Lin [aut] (ORCID: <https://orcid.org/0000-0002-3600-9889>), Ganesh Krishnan [aut], Eric Hare [aut] (ORCID: <https://orcid.org/0000-0002-4277-3146>) |
| Maintainer: | Heike Hofmann <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.4.9000 |
| Built: | 2026-05-19 07:41:20 UTC |
| Source: | https://github.com/heike/x3ptools |
Helper function
convert_raster_to_png(raster)convert_raster_to_png(raster)
raster |
raster image |
png object
Convert a data frame into an x3p file
df_to_x3p(dframe, var = "value")df_to_x3p(dframe, var = "value")
dframe |
data frame. |
var |
name of the variable containing the surface measurements. Defaults to "value". |
x3p object
dim.x3p expands the generic dim method for x3p objects and returns (mainly) the dimensions of the surface matrix.
## S3 method for class 'x3p' dim(x)## S3 method for class 'x3p' dim(x)
x |
an x3p object |
a vector of length three. The first two integers contain width and height of the surface scan, the third dimension is either 1 or 2, depending on whether there is a mask (2) or not (1).
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo)
head.x3p expands the generic head method for x3p objects. It gives a summary of the most relevant 3p meta information and returns the object invisibly.
## S3 method for class 'x3p' head(x, n = 6L, ...)## S3 method for class 'x3p' head(x, n = 6L, ...)
x |
x3p object |
n |
number of rows/columns of the matrix |
... |
extra parameters passed to head.matrix() |
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) head(logo)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) head(logo)
image.x3p expands the generic image method for x3p objects.
This image function creates a raster image to show the surface of an x3p file.
Due to some inconsistency in the mapping of the origin (0,0), (choice between top left or bottom left) image functions from different packages will result in different images.
## S3 method for class 'x3p' image(x, ...)## S3 method for class 'x3p' image(x, ...)
x |
an x3p object |
... |
parameters passed into image |
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) image(logo)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) image(logo)
LEAs (land-engraved areas) are created on the outside of a bullet during the firing process. Depending on the rifling inside the barrel, multiple lands exist for each barrel. Striation marks in these land engraved areas are used in forensic labs to determine whether two bullets were fired from the same firearm.
lealea
x3p object
data(lea) image(lea) if (interactive()) x3p_image(lea)data(lea) image(lea) if (interactive()) x3p_image(lea)
print.x3p expands the generic print method for x3p objects. It gives a summary of the most relevant x3p meta information and returns the object invisibly.
## S3 method for class 'x3p' print(x, ...)## S3 method for class 'x3p' print(x, ...)
x |
x3p object |
... |
ignored |
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) print(logo)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) print(logo)
STL (STereo Lithographic) files describe 3d objects as mesh objects. Here, we assume that the 3d object consists of a 3d surface on the top of a rectangular, equi-spaced 2d grid. We further assume, that each node of the STL file describes the x-y location of an actual measurement. These measurements are then converted into the surface matrix of an x3p object. The resolution is derived from the distance between consecutive x and y nodes.
stl_to_x3p(stl)stl_to_x3p(stl)
stl |
STL file object or path to the file |
x3p object
## Not run: # the website https://touchterrain.geol.iastate.edu/ allows a download # of a 3d printable terrain model. For an example we suggest to download a file from there. gc <- rgl::readSTL("<PATH TO STL FILE>", plot=FALSE) x3p <- stl_to_x3p(gc) ## End(Not run)## Not run: # the website https://touchterrain.geol.iastate.edu/ allows a download # of a 3d printable terrain model. For an example we suggest to download a file from there. gc <- rgl::readSTL("<PATH TO STL FILE>", plot=FALSE) x3p <- stl_to_x3p(gc) ## End(Not run)
TMD files are used in telemetry, specifically, they are a native format used by GelSight to store 3d topographic surface scans.
tmd_to_x3p(tmd_path, yaml_path = NA, verbose = TRUE)tmd_to_x3p(tmd_path, yaml_path = NA, verbose = TRUE)
tmd_path |
path to TMD file |
yaml_path |
path to corresponding yaml file with meta information.
If set to |
verbose |
boolean |
The algorithm is based on GelSight's MatLab routine readtmd.m published as
part of the Github repository
gelsightinc/gsmatlab
x3p file of the scan. Some rudimentary information will be filled in, information of scanning process, and parameter settings need to be added manually.
#x3p <- tmd_to_x3p("~/Downloads/Sc04.Pl044.Ma4.SB.An80.Pb.DirFo.SizL.tmd") # #x3p <- tmd_to_x3p("~/Downloads/Sc04.Pl044.Ma4.SB.An80.Pb.DirFo.SizL.tmd", # yaml_path="~/Downloads/scan.yaml") ##x3p <- tmd_to_x3p("~/Downloads/Sc04.Pl044.Ma4.SB.An80.Pb.DirFo.SizL.tmd") # #x3p <- tmd_to_x3p("~/Downloads/Sc04.Pl044.Ma4.SB.An80.Pb.DirFo.SizL.tmd", # yaml_path="~/Downloads/scan.yaml") #
An example part of a wire cut in x3p format. The wire cut is part of a CSAFE study
involving 1.5 mm Aluminium wires cut by Kaiweet wire-cutters.
wirewire
x3p object
Annotations in an x3p object are legend entries for each color of a mask.
x3p_add_annotation(x3p, color, annotation)x3p_add_annotation(x3p, color, annotation)
x3p |
x3p object |
color |
name or hex value of color |
annotation |
character value describing the region |
x3p object with the added annotations
## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) color_logo <- png::readPNG(system.file("csafe-color.png", package="x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) x3p_image(logoplus, multiply=50, size = c(741, 419),zoom = 0.5) logoplus <- x3p_add_annotation(logoplus, "#FFFFFFFF", "background") logoplus <- x3p_add_annotation(logoplus, "#818285FF", "text") logoplus <- x3p_add_annotation(logoplus, "#F6BD47FF", "fingerprint") logoplus <- x3p_add_annotation(logoplus, "#D2202FFF", "fingerprint") logoplus <- x3p_add_annotation(logoplus, "#92278FFF", "fingerprint") x3p_add_legend(logoplus) ## End(Not run)## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) color_logo <- png::readPNG(system.file("csafe-color.png", package="x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) x3p_image(logoplus, multiply=50, size = c(741, 419),zoom = 0.5) logoplus <- x3p_add_annotation(logoplus, "#FFFFFFFF", "background") logoplus <- x3p_add_annotation(logoplus, "#818285FF", "text") logoplus <- x3p_add_annotation(logoplus, "#F6BD47FF", "fingerprint") logoplus <- x3p_add_annotation(logoplus, "#D2202FFF", "fingerprint") logoplus <- x3p_add_annotation(logoplus, "#92278FFF", "fingerprint") x3p_add_legend(logoplus) ## End(Not run)
Add a grid of lines to overlay the surface of an x3p object. Lines are added to a mask. In case no mask exists, one is created.
x3p_add_grid( x3p, spaces, size = c(1, 3, 5), color = c("grey50", "black", "darkred") )x3p_add_grid( x3p, spaces, size = c(1, 3, 5), color = c("grey50", "black", "darkred") )
x3p |
x3p object |
spaces |
space between grid lines, doubled for x |
size |
width (in pixels) of the lines |
color |
(vector of) character values to describe color of lines |
x3p object with added vertical lines in the mask
## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) # ten vertical lines across: logoplus <- x3p_add_grid(logo, spaces = 50e-6, size = c(1, 3, 5), color = c("grey50", "black", "darkred") ) x3p_image(logoplus, size = c(741, 419), zoom = 0.5) ## End(Not run)## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) # ten vertical lines across: logoplus <- x3p_add_grid(logo, spaces = 50e-6, size = c(1, 3, 5), color = c("grey50", "black", "darkred") ) x3p_image(logoplus, size = c(741, 419), zoom = 0.5) ## End(Not run)
Add horizontal lines to overlay the surface of an x3p object. Lines are added to a mask. In case no mask exists, one is created.
x3p_add_hline(x3p, yintercept, size = 5, color = "#e6bf98")x3p_add_hline(x3p, yintercept, size = 5, color = "#e6bf98")
x3p |
x3p object |
yintercept |
(vector of) numerical values for the position of the lines. |
size |
width (in pixels) of the line |
color |
(vector of) character values to describe color of lines |
x3p object with added vertical lines in the mask
## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) color_logo <- magick::image_read(system.file("csafe-color.png", package = "x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) # five horizontal lines at equal intervals: logoplus <- x3p_add_hline(logo, seq(0, 418 * 6.4500e-7, length = 5), size = 3) x3p_image(logoplus, size = c(741, 419), zoom = 0.5) ## End(Not run)## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) color_logo <- magick::image_read(system.file("csafe-color.png", package = "x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) # five horizontal lines at equal intervals: logoplus <- x3p_add_hline(logo, seq(0, 418 * 6.4500e-7, length = 5), size = 3) x3p_image(logoplus, size = c(741, 419), zoom = 0.5) ## End(Not run)
Display the legend for colors and annotations in the active rgl window. In case no rgl window is opened, a new window displaying the x3p file (using default sizes and zoom) opens.
x3p_add_legend(x3p, colors = NULL)x3p_add_legend(x3p, colors = NULL)
x3p |
x3p object with a mask |
colors |
named character vector of colors (in hex format by default), names contain annotations |
x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) ## Not run: # run when rgl can open window on the device x3p_image(x3p) x3p_add_legend(x3p) # add legend ## End(Not run)x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) ## Not run: # run when rgl can open window on the device x3p_image(x3p) x3p_add_legend(x3p) # add legend ## End(Not run)
Create a mask for an x3p object in case it does not have a mask yet. Masks are used for overlaying colors on the bullets surface.
x3p_add_mask(x3p, mask = NULL)x3p_add_mask(x3p, mask = NULL)
x3p |
x3p object |
mask |
raster matrix of colors with the same dimensions as the x3p surface. If NULL, an object of the right size will be created. |
x3p object with added/changed mask
x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) # x3p file has mask consisting color raster image: x3p$mask[1:5,1:5] ## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) color_logo <- png::readPNG(system.file("csafe-color.png", package="x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) x3p_image(logoplus, multiply=50, size = c(741, 419),zoom = 0.5) ## End(Not run)x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) # x3p file has mask consisting color raster image: x3p$mask[1:5,1:5] ## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) color_logo <- png::readPNG(system.file("csafe-color.png", package="x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) x3p_image(logoplus, multiply=50, size = c(741, 419),zoom = 0.5) ## End(Not run)
Add a region a mask. The region is specfied as TRUE values in a matrix of the same dimensions as the existing mask. In case no mask exists, one is created.
x3p_add_mask_layer(x3p, mask, color = "red", annotation = "")x3p_add_mask_layer(x3p, mask, color = "red", annotation = "")
x3p |
x3p object |
mask |
logical matrix of the same dimension as the surface matrix. Values of TRUE are assumed to be added in the mask, values of FALSE are being ignored. |
color |
name or hex value of color |
annotation |
character value describing the region |
x3p object with changed mask
Use a specified template to overwrite the general info in the x3p object (and structure of the feature info, if needed).
x3p_add_meta(x3p, template = NULL) addtemplate_x3p(x3p, template = NULL)x3p_add_meta(x3p, template = NULL) addtemplate_x3p(x3p, template = NULL)
x3p |
x3p object |
template |
file path to xml template, use NULL for in-built package template |
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # exchange meta information for general x3p information: logo <- x3p_add_meta(logo, template = system.file("templateXML.xml", package="x3ptools")) logo$general.infologo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # exchange meta information for general x3p information: logo <- x3p_add_meta(logo, template = system.file("templateXML.xml", package="x3ptools")) logo$general.info
Add vertical lines to overlay the surface of an x3p object. Lines are added to a mask. In case no mask exists, one is created.
x3p_add_vline(x3p, xintercept, size = 5, color = "#e6bf98")x3p_add_vline(x3p, xintercept, size = 5, color = "#e6bf98")
x3p |
x3p object |
xintercept |
(vector of) numerical values for the position of the lines. |
size |
width (in pixels) of the line |
color |
(vector of) character values to describe color of lines |
x3p object with added vertical lines in the mask
## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) logo_color <- magick::image_read(system.file("csafe-color.png", package = "x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(logo_color)) # ten vertical lines across: logoplus <- x3p_add_vline(logo, seq(0, 740 * 6.4500e-7, length = 5), size = 3) x3p_image(logoplus, size = c(741, 419), zoom = 0.5) ## End(Not run)## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) logo_color <- magick::image_read(system.file("csafe-color.png", package = "x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(logo_color)) # ten vertical lines across: logoplus <- x3p_add_vline(logo, seq(0, 740 * 6.4500e-7, length = 5), size = 3) x3p_image(logoplus, size = c(741, 419), zoom = 0.5) ## End(Not run)
Calculate blockwise summary statistics on the surface matrix of an x3p. If the x3p object has a mask, the mode of the mask value
x3p_average(x3p, b = 10, f = mean, ...)x3p_average(x3p, b = 10, f = mean, ...)
x3p |
x3p object |
b |
positive integer value, block size |
f |
function aggregate function |
... |
parameters passed on to function f. Make sure to use na.rm = T as needed. |
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) small <- x3p_average(logo)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) small <- x3p_average(logo)
Apply gradient-based color shading to the mask of a 3d topographic surface.
Gradients are determined empirically based on sequentical row- (or column-)wise
differences of surface values.
The direction parameter determines the direction of differencing.
If direction is "vertical", columns in the surface matrix are
differenced to identify whether 'vertical' stripes exist.
x3p_bin_stripes( x3p, direction = "vertical", colors = rev(c("#b12819", "#d7301f", "#e16457", "#ffffff", "#5186a2", "#175d82", "#134D6B")), freqs = c(0, 0.05, 0.1, 0.3, 0.7, 0.9, 0.95, 1) )x3p_bin_stripes( x3p, direction = "vertical", colors = rev(c("#b12819", "#d7301f", "#e16457", "#ffffff", "#5186a2", "#175d82", "#134D6B")), freqs = c(0, 0.05, 0.1, 0.3, 0.7, 0.9, 0.95, 1) )
x3p |
object containing a 3d topographic surface |
direction |
in which the stripes are created: |
colors |
vector of colors |
freqs |
vector of values corresponding to color frequency (turned into quantiles of the differenced values) |
x3p object with mask colored by discretized surface gradient
data(wire) x3p <- wire if (interactive()) x3p_image(x3p, size = c(400, 400), zoom=0.8) x3p_with <- x3p_bin_stripes(x3p, direction="vertical") x3p_with <- x3p_bin_stripes(x3p, direction="vertical", colors=c("#b12819","#ffffff","#134D6B"), freqs=c(0, 0.3, 0.7, 1)) if (interactive()) x3p_image(x3p_with, size = c(400, 400), zoom=0.8) data(lea) if (interactive()) { lea %>% x3p_bin_stripes() %>% x3p_image() # default stripes # three colors only lea %>% x3p_bin_stripes( colors=c("#b12819","#ffffff","#134D6B"), freqs=c(0, 0.3, 0.7, 1)) %>% x3p_image() }data(wire) x3p <- wire if (interactive()) x3p_image(x3p, size = c(400, 400), zoom=0.8) x3p_with <- x3p_bin_stripes(x3p, direction="vertical") x3p_with <- x3p_bin_stripes(x3p, direction="vertical", colors=c("#b12819","#ffffff","#134D6B"), freqs=c(0, 0.3, 0.7, 1)) if (interactive()) x3p_image(x3p_with, size = c(400, 400), zoom=0.8) data(lea) if (interactive()) { lea %>% x3p_bin_stripes() %>% x3p_image() # default stripes # three colors only lea %>% x3p_bin_stripes( colors=c("#b12819","#ffffff","#134D6B"), freqs=c(0, 0.3, 0.7, 1)) %>% x3p_image() }
In the active rgl window select a circle on the scan's surface by clicking on three points along the circumference. Make sure that x3p file and the rgl window match. If no rgl window is active, an rgl window opens with the scan.
x3p_circle_select(x3p, col = "#FF0000", update = TRUE)x3p_circle_select(x3p, col = "#FF0000", update = TRUE)
x3p |
x3p file |
col |
character value of the selection color |
update |
boolean value, whether the rgl window should be updated to show the selected circle |
x3p file with selected circle in mask
## Not run: if (interactive) { if (!file.exists("fadul1-1.x3p")) { url <- "https://tsapps.nist.gov/NRBTD/Studies/CartridgeMeasurement/DownloadMeasurement" file <- "2d9cc51f-6f66-40a0-973a-a9292dbee36d" download.file(file.path(url, file), destfile="fadul1-1.x3p") } x3p <- x3p_read("fadul1-1.x3p") x3p_image(x3p, size=c(500,500), zoom=.8) x3p <- x3p_circle_select(x3p, update=TRUE, col="#FF0000") logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size=c(500,500), zoom = 1) x3p_circle_select(logo, update=TRUE, col="#00FF00") } ## End(Not run)## Not run: if (interactive) { if (!file.exists("fadul1-1.x3p")) { url <- "https://tsapps.nist.gov/NRBTD/Studies/CartridgeMeasurement/DownloadMeasurement" file <- "2d9cc51f-6f66-40a0-973a-a9292dbee36d" download.file(file.path(url, file), destfile="fadul1-1.x3p") } x3p <- x3p_read("fadul1-1.x3p") x3p_image(x3p, size=c(500,500), zoom=.8) x3p <- x3p_circle_select(x3p, update=TRUE, col="#FF0000") logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size=c(500,500), zoom = 1) x3p_circle_select(logo, update=TRUE, col="#00FF00") } ## End(Not run)
Cuts out a rectangle of size width x height from the location (x, y) of an x3p object. x and y specify the bottom right corner of the rectangle. In case the dimensions of the surface matrix do not allow for the full dimensions of the rectangle cutout the dimensions are adjusted accordingly.
x3p_crop(x3p, x = 1, y = 1, width = 128, height = 128)x3p_crop(x3p, x = 1, y = 1, width = 128, height = 128)
x3p |
x3p object |
x |
integer, location (in pixels) of the leftmost side of the rectangle, |
y |
integer, location (in pixels) of the leftmost side of the rectangle, |
width |
integer, width (in pixels) of the rectangle, |
height |
integer, height (in pixels) of the rectangle, |
x3p object of the cropped location expanded by list element offset that contains the coordinates of the cropped piece within the parent.
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # crop the x3p file to just the CSAFE logo logo_only <- x3p_crop(logo, x=20, y=50, width = 255 ,height =310) logo_only <- x3p_crop(logo, x=20, y=50, width = 255 ,height =510) # x3p_image(logo_only, size=c(500,500), zoom = 1)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # crop the x3p file to just the CSAFE logo logo_only <- x3p_crop(logo, x=20, y=50, width = 255 ,height =310) logo_only <- x3p_crop(logo, x=20, y=50, width = 255 ,height =510) # x3p_image(logo_only, size=c(500,500), zoom = 1)
Makes the currently active rgl object darker by removing a light source. Once all light sources are removed the object can not be any darker.
x3p_darker()x3p_darker()
x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) ## Not run: x3p_image(x3p) # run when rgl can open window on the device x3p_darker() # remove a light source ## End(Not run)x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) ## Not run: x3p_image(x3p) # run when rgl can open window on the device x3p_darker() # remove a light source ## End(Not run)
Deletes mask and its annotations from an x3p file.
x3p_delete_mask(x3p)x3p_delete_mask(x3p)
x3p |
x3p object |
x3p object without the mask
If a mask is present, a subset of the surface matrix is extracted based on specified value(s).
x3p_extract(x3p, mask_vals)x3p_extract(x3p, mask_vals)
x3p |
x3p object |
mask_vals |
vector of mask value(s) |
x3p object
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # add a mask logo <- x3p_add_mask(logo) mask <- t(logo$surface.matrix==median(logo$surface.matrix)) logo <- x3p_add_mask_layer(logo, mask, color = "red", annotation = "median") x3p_extract(logo, "#cd7f32") # x3p_image(logo, size=c(500,500), zoom = 1)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # add a mask logo <- x3p_add_mask(logo) mask <- t(logo$surface.matrix==median(logo$surface.matrix)) logo <- x3p_add_mask_layer(logo, mask, color = "red", annotation = "median") x3p_extract(logo, "#cd7f32") # x3p_image(logo, size=c(500,500), zoom = 1)
In the active rgl device select a line on the 3d surface by clicking on start and end-point (order matters). These points define the beginning and end of a line segment.
The line segment is drawn on the mask of the x3p object.
The line object is returned as part of the x3p object, if line_result is set to TRUE
x3p_extract_profile( x3p, col = "#FF0000", update = TRUE, line_result = "equi-spaced", scale_to = NA, multiply = 5, linewidth = 1 )x3p_extract_profile( x3p, col = "#FF0000", update = TRUE, line_result = "equi-spaced", scale_to = NA, multiply = 5, linewidth = 1 )
x3p |
x3p file |
col |
character value of the selection color |
update |
boolean value, whether the rgl window should be updated to show the selected circle |
line_result |
enhance result by a data frame of the line: NULL for no, "raw" for data frame of original x and y (in the mask) and projected x onto the line, "equi-spaced" (default) returns a data frame with equispaced x values after fitting a loess smooth to the raw values. Note that variable x indicates the direction from first click (x=0) to the second click (max x). |
scale_to |
numeric value of the resolution in the returned line. Only applies to equi-spaced |
multiply |
integer value, factor to multiply surface values. Only applied if update is true. Defaults to 5, |
linewidth |
line width of the extracted line. Defaults to 1. |
x3p file with identified line in the mask. Depending on the setting of line_result
additional information on the line is attached as a data frame.
## Not run: if (interactive) { x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) x3p %>% image_x3p(size=dim(x3p$surface.matrix), multiply=1, zoom=.3) x3p <- x3p_extract_profile(x3p, update=TRUE, col="#FFFFFF") x3p$line_df %>% ggplot(aes(x = x, y = value)) + geom_line() x3p$line_df$y <- 1 sigs <- bulletxtrctr::cc_get_signature(ccdata = x3p$line_df, grooves = list(groove=range(x3p$line_df$x)), span1 = 0.75, span2 = 0.03) sigs %>% ggplot(aes(x = x)) + geom_line(aes(y = raw_sig), colour = "grey50") + geom_line(aes(y = sig), size = 1) + theme_bw() } ## End(Not run)## Not run: if (interactive) { x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) x3p %>% image_x3p(size=dim(x3p$surface.matrix), multiply=1, zoom=.3) x3p <- x3p_extract_profile(x3p, update=TRUE, col="#FFFFFF") x3p$line_df %>% ggplot(aes(x = x, y = value)) + geom_line() x3p$line_df$y <- 1 sigs <- bulletxtrctr::cc_get_signature(ccdata = x3p$line_df, grooves = list(groove=range(x3p$line_df$x)), span1 = 0.75, span2 = 0.03) sigs %>% ggplot(aes(x = x)) + geom_line(aes(y = raw_sig), colour = "grey50") + geom_line(aes(y = sig), size = 1) + theme_bw() } ## End(Not run)
The 3d topographic surface is split into multiple segments of width width (in pixels)
using an overlap of 10% between segments. For each segment, a line is extracted (with x3p_extract_profile).
Line segments are projected onto the mask of the initial x3p object and exported as a lines attribute.
x3p_extract_profile_segments( x3p, width, overlap = 10, col = "#FF0000", linewidth = 11, line_result = "equi-spaced", scale_to = NA, verbose = TRUE )x3p_extract_profile_segments( x3p, width, overlap = 10, col = "#FF0000", linewidth = 11, line_result = "equi-spaced", scale_to = NA, verbose = TRUE )
x3p |
object |
width |
segment width |
overlap |
percentage of overlap between segments |
col |
color |
linewidth |
integer value specifying the width for the profile |
line_result |
enhance result by the line: NULL for no, "raw" for a list of data frames of original x and y (in the mask) and
projected x onto the line, "equi-spaced" (default) returns a single data frame with equi-spaced x values after fitting a loess smooth to the raw values.
Note that variable x indicates the direction from first click (x=0) to
the second click (max x) in steps of |
scale_to |
positive number indicating the resolution for the line returned. |
verbose |
logical |
x3p object with added lines attribute.
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo <- x3p_m_to_mum(logo) if(interactive()) x3p_extract_profile_segments(logo, 850, col="#ffffff", linewidth=5)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo <- x3p_m_to_mum(logo) if(interactive()) x3p_extract_profile_segments(logo, 850, col="#ffffff", linewidth=5)
Flip the surface matrix of an x3p file along the x axis.
x3p_flip_x(x3p) x_flip_x3p(x3p)x3p_flip_x(x3p) x_flip_x3p(x3p)
x3p |
x3p object |
x3p object in which the x coordinate is reversed.
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) ## Not run: x3p_image(logo) ## End(Not run) # flip the y-axis for the old ISO standard: logoflip <- x3p_flip_x(logo) dim(logoflip$surface.matrix) ## Not run: x3p_image(logoflip) ## End(Not run)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) ## Not run: x3p_image(logo) ## End(Not run) # flip the y-axis for the old ISO standard: logoflip <- x3p_flip_x(logo) dim(logoflip$surface.matrix) ## Not run: x3p_image(logoflip) ## End(Not run)
One of the major changes between the previous two ISO standards is the way the y axis is defined in a scan. The entry (0,0) used to refer to the top left corner of a scan, now it refers to the bottom right corner, which means that all legacy x3p files have to flip their y axis in order to conform to the newest ISO norm.
x3p_flip_y(x3p) y_flip_x3p(x3p)x3p_flip_y(x3p) y_flip_x3p(x3p)
x3p |
x3p object |
x3p object in which the y coordinate is reversed.
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) ## Not run: x3p_image(logo) ## End(Not run) # flip the y-axis for the old ISO standard: logoflip <- x3p_flip_y(logo) dim(logoflip$surface.matrix) ## Not run: x3p_image(logoflip) ## End(Not run)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) ## Not run: x3p_image(logo) ## End(Not run) # flip the y-axis for the old ISO standard: logoflip <- x3p_flip_y(logo) dim(logoflip$surface.matrix) ## Not run: x3p_image(logoflip) ## End(Not run)
Interactive selection of region of interest
x3p_fuzzyselect(x3p, col = "#FF0000", mad = 5, type = "plane", update = TRUE)x3p_fuzzyselect(x3p, col = "#FF0000", mad = 5, type = "plane", update = TRUE)
x3p |
x3p file |
col |
character value of the selection color |
mad |
scalar |
type |
only "plane" is implemented at the moment |
update |
boolean value, whether the rgl window should be updated to show the selected rectangle |
x3p file with updated mask
## Not run: if (interactive) { if (!file.exists("fadul1-1.x3p")) { url <- "https://tsapps.nist.gov/NRBTD/Studies/CartridgeMeasurement/DownloadMeasurement" file <- "2d9cc51f-6f66-40a0-973a-a9292dbee36d" download.file(file.path(url, file), destfile="fadul1-1.x3p") } x3p <- x3p_read("fadul1-1.x3p") x3p_image(x3p, size=c(500,500), zoom=.8) x3p <- x3p_fuzzyselect(x3p, update=TRUE, col="#FF0000") logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size=c(500,500), zoom = 1) x3p_fuzzyselect(logo, update=TRUE, col="#00FF00") } ## End(Not run)## Not run: if (interactive) { if (!file.exists("fadul1-1.x3p")) { url <- "https://tsapps.nist.gov/NRBTD/Studies/CartridgeMeasurement/DownloadMeasurement" file <- "2d9cc51f-6f66-40a0-973a-a9292dbee36d" download.file(file.path(url, file), destfile="fadul1-1.x3p") } x3p <- x3p_read("fadul1-1.x3p") x3p_image(x3p, size=c(500,500), zoom=.8) x3p <- x3p_fuzzyselect(x3p, update=TRUE, col="#FF0000") logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size=c(500,500), zoom = 1) x3p_fuzzyselect(logo, update=TRUE, col="#00FF00") } ## End(Not run)
Scans in x3p format capture 3d topogographic surfaces. According to ISO standard ISO5436 - 2000 scans are supposed to be captured in meters. For microscopic images capture in meters might be impractical.
x3p_get_scale(x3p)x3p_get_scale(x3p)
x3p |
object |
numeric value of resolution per pixel
Plot an interactive surface plot of the x3p matrix. This implementation uses the rgl package.
In case rgl.useNULL is set to TRUE (i.e. no separate window will be opened), an rgl widget
can be used to show the surface in the viewer window (see the example).
x3p_image( x3p, file = NULL, col = "#cd7f32", size = 750, zoom = 0.35, multiply = 5, update = FALSE, ... ) image_x3p( x3p, file = NULL, col = "#cd7f32", size = 750, zoom = 0.35, multiply = 5, ... )x3p_image( x3p, file = NULL, col = "#cd7f32", size = 750, zoom = 0.35, multiply = 5, update = FALSE, ... ) image_x3p( x3p, file = NULL, col = "#cd7f32", size = 750, zoom = 0.35, multiply = 5, ... )
x3p |
x3p object |
file |
file name for saving, if file is NULL the opengl device stays open. The file extension determines the type of output. Possible extensions are png, stl (suitable for 3d printing), or svg. |
col |
color specification |
size |
vector of width and height. If only one value is given, height or width will be adjusted proportionally to the dimensions of the surface matrix of the scan to reach an upper bound of size. |
zoom |
numeric value indicating the amount of zoom |
multiply |
exaggerate the relief by factor multiply |
update |
Boolean value indicating whether a scene should be updated (defaults to FALSE). If FALSE, a new rgl device is opened. |
... |
not used |
save <- getOption("rgl.useNULL") options(rgl.useNULL=TRUE) logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size = c(741, 419), zoom=0.5) # add crosscut: logoplus <- x3p_add_hline(logo, yintercept = 50*.645e-6, color = "#e6bf98", size = 5) x3p_image(logoplus, size = c(741, 419), zoom=0.5) widget <- rgl::rglwidget() if (interactive()) widget options(rgl.useNULL=save)save <- getOption("rgl.useNULL") options(rgl.useNULL=TRUE) logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size = c(741, 419), zoom=0.5) # add crosscut: logoplus <- x3p_add_hline(logo, yintercept = 50*.645e-6, color = "#e6bf98", size = 5) x3p_image(logoplus, size = c(741, 419), zoom=0.5) widget <- rgl::rglwidget() if (interactive()) widget options(rgl.useNULL=save)
An interpolated scan is created at specified resolutions resx, resy in x and y direction.
The interpolation is based on na.approx from the zoo package. It is possible to create interpolations at a higher resolution than the one specified in the data itself, but it is not recommended to do so.
x3p_interpolate can also be used as a way to linearly interpolate any missing values in an existing scan without changing the resolution.
x3p_interpolate(x3p, resx = 1e-06, resy = resx, maxgap = 1) interpolate_x3p(x3p, resx = 1e-06, resy = resx, maxgap = 1)x3p_interpolate(x3p, resx = 1e-06, resy = resx, maxgap = 1) interpolate_x3p(x3p, resx = 1e-06, resy = resx, maxgap = 1)
x3p |
x3p object |
resx |
numeric value specifying the new resolution for the x axis. |
resy |
numeric value specifying the new resolution for the y axis. |
maxgap |
integer variable used in |
interpolated x3p object
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # resolution: logo$header.info$incrementX # change resolution to 1 micron = 1e-6 meters logo2 <- x3p_interpolate(logo, resx = 1e-6) logo2$header.info$incrementXlogo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # resolution: logo$header.info$incrementX # change resolution to 1 micron = 1e-6 meters logo2 <- x3p_interpolate(logo, resx = 1e-6) logo2$header.info$incrementX
Make the currently active rgl object lighter. Adds a light source. Up to eight light sources can be added. Alternatively, any rgl light source can be added (see light3d).
x3p_lighter()x3p_lighter()
x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) ## Not run: x3p_image(x3p) # run when rgl can open window on the device x3p_lighter() # add a light source ## End(Not run)x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) ## Not run: x3p_image(x3p) # run when rgl can open window on the device x3p_lighter() # add a light source ## End(Not run)
ISO standard 5436_2 asks for specification of values in meters. For topographic surfaces collected by microscopes values in microns are more readable. Besides scaling the values in the surface matrix, corresponding increments are changed to microns as well.
x3p_m_to_mum(x3p)x3p_m_to_mum(x3p)
x3p |
x3p file with header information in meters |
x3p with header information in microns
Retrieve color definitions and annotations from the mask. If available, results in a named vector of colors.
x3p_mask_legend(x3p)x3p_mask_legend(x3p)
x3p |
x3p object with a mask |
named vector of colors, names show annotations. In case no annotations exist NULL is returned.
x3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) x3p_mask_legend(x3p) # annotations and color hex definitionsx3p <- x3p_read(system.file("sample-land.x3p", package="x3ptools")) x3p_mask_legend(x3p) # annotations and color hex definitions
For each x value of the surface matrix add a region to the mask of an x3p object corresponding to the area between two specified quantiles.
x3p_mask_quantile( x3p, quantiles = c(0.25, 0.75), color = "red", annotation = "quantile-region" )x3p_mask_quantile( x3p, quantiles = c(0.25, 0.75), color = "red", annotation = "quantile-region" )
x3p |
x3p object |
quantiles |
vector of quantiles between which surface matrix values are included in the mask |
color |
name or hex value of color |
annotation |
character value describing the region |
x3p object with changed mask
Identify xml fields in the meta file of an x3p object by name and modify content if uniquely described.
x3p_modify_xml(x3p, element, value)x3p_modify_xml(x3p, element, value)
x3p |
x3p object |
element |
character or integer. In case of character, name of xml field in the meta file. Note that element can contain regular expressions, e.g. |
value |
character. Value to be given to the xml field in the meta file. |
x3p object with changed meta information
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_show_xml(logo, "creator") x3p_modify_xml(logo, "creator", "I did that") x3p_show_xml(logo, 20) x3p_modify_xml(logo, 20, "I did that, too")logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_show_xml(logo, "creator") x3p_modify_xml(logo, "creator", "I did that") x3p_show_xml(logo, 20) x3p_modify_xml(logo, 20, "I did that, too")
Append information to the current comment of the x3p object. If there is no comment, a comment will be included in Record2 (general info)
x3p_paste_comment(x3p, comment, sep = ", ")x3p_paste_comment(x3p, comment, sep = ", ")
x3p |
x3p object |
comment |
character value with the appendage |
sep |
character value to use for separating between existing and new comments |
x3p object with expanded comment
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo %>% x3p_paste_comment("*** added to the current comment ***")logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo %>% x3p_paste_comment("*** added to the current comment ***")
Read file in x3p format. x3p formats describe 3d topological surface according to ISO standard ISO5436 – 2000. x3p files are a container format implemented as a zip archive of a folder consisting of an xml file of meta information and a binary matrix of numeric surface measurements.
x3p_read(file, size = NA, quiet = T, tmpdir = NULL) read_x3p(file, size = NA, quiet = T, tmpdir = NULL)x3p_read(file, size = NA, quiet = T, tmpdir = NULL) read_x3p(file, size = NA, quiet = T, tmpdir = NULL)
file |
The file path to the x3p file, or an url to an x3p file |
size |
size in bytes to use for reading the binary file. If not specified, default is used. Will be overwritten if specified in the xml meta file. |
quiet |
for url downloads, show download progress? |
tmpdir |
temporary directory to use to extract the x3p file (default NULL uses tempdir() to set a directory). |
x3p object consisting of a list of the surface matrix and the four records as specified in the ISO standard
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools"))logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools"))
Read data from an x-y-z file
x3p_read_dat(dat, delim = " ", col_names = FALSE)x3p_read_dat(dat, delim = " ", col_names = FALSE)
dat |
path to the x-y-z file |
delim |
character determining delimiter |
col_names |
logical value - does the first line of the file contain the column names? Default is set to FALSE. |
x3p object
This function is provided with a path to a folder, it will search recursively for all x3p files within the folder, read the x3p files, and return the results as part of a tibble dataset.
x3p_read_folder(path)x3p_read_folder(path)
path |
character string to a folder |
tibble with two variables: source contains the file path to the x3p file, and x3p is a list variable of x3p objects.
# example code path <- dirname(system.file("csafe-logo.x3p", package="x3ptools")) x3p_read_folder(path) # show all x3p files installed with x3ptools# example code path <- dirname(system.file("csafe-logo.x3p", package="x3ptools")) x3p_read_folder(path) # show all x3p files installed with x3ptools
plux files are zip containers of 3d topographic scans in a format proprietary to Sensofarâ„¢.
One of the files in the container is the file index.xml which contains meta-information on the instrument, scan settings, date, and creator.
This information is added to the x3p meta-information.
x3p_read_plux(plux)x3p_read_plux(plux)
plux |
path to plux file |
xml of general information as stored in the plux file
Rotate the surface matrix and mask of an x3p object. Also adjust meta information.
x3p_rotate(x3p, angle = 90) rotate_x3p(x3p, angle = 90)x3p_rotate(x3p, angle = 90) rotate_x3p(x3p, angle = 90)
x3p |
x3p object |
angle |
rotate counter-clockwise by angle in degrees. |
## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) color_logo <- png::readPNG(system.file("csafe-color.png", package = "x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) dim(logoplus$surface.matrix) dim(logoplus$mask) x3p_image(logoplus, multiply = 50, size = c(741, 419), zoom = 0.5) logoplus60 <- x3p_rotate(x3p = logoplus, angle = 60) dim(logoplus60$surface.matrix) dim(logoplus60$mask) x3p_image(logoplus60, multiply = 50, size = c(741, 419), zoom = 0.75) ## End(Not run)## Not run: logo <- x3p_read(system.file("csafe-logo.x3p", package = "x3ptools")) color_logo <- png::readPNG(system.file("csafe-color.png", package = "x3ptools")) logoplus <- x3p_add_mask(logo, as.raster(color_logo)) dim(logoplus$surface.matrix) dim(logoplus$mask) x3p_image(logoplus, multiply = 50, size = c(741, 419), zoom = 0.5) logoplus60 <- x3p_rotate(x3p = logoplus, angle = 60) dim(logoplus60$surface.matrix) dim(logoplus60$mask) x3p_image(logoplus60, multiply = 50, size = c(741, 419), zoom = 0.75) ## End(Not run)
Sample from an x3p object
x3p_sample(x3p, m = 2, mY = m, offset = 0, offsetY = offset) sample_x3p(x3p, m = 2, mY = m, offset = 0, offsetY = offset)x3p_sample(x3p, m = 2, mY = m, offset = 0, offsetY = offset) sample_x3p(x3p, m = 2, mY = m, offset = 0, offsetY = offset)
x3p |
x3p object |
m |
integer value - every mth value is included in the sample |
mY |
integer value - every mth value is included in the sample in x direction and every mYth value is included in y direction |
offset |
integer value between 0 and m-1 to specify offset of the sample |
offsetY |
integer value between 0 and mY-1 to specify different offsets for x and y direction |
down-sampled x3p object
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) # down-sample to one-fourth of the image: logo4 <- x3p_sample(logo, m=4) dim(logo4$surface.matrix) ## Not run: x3p_image(logo) x3p_image(logo4) ## End(Not run)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) # down-sample to one-fourth of the image: logo4 <- x3p_sample(logo, m=4) dim(logo4$surface.matrix) ## Not run: x3p_image(logo) x3p_image(logo4) ## End(Not run)
x3p objects can be presented in different units. ISO standard 5436_2 asks for specification of values in meters. For topographic surfaces collected by microscopes values in microns are more readable. This functions allows to convert between different units.
x3p_scale_unit(x3p, scale_by)x3p_scale_unit(x3p, scale_by)
x3p |
object in x3p format, 3d topographic surface. |
scale_by |
numeric value. Value the surface to be scaled by. While not enforced, values of |
x3p with header information in microns
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo # measurements in meters x3p_scale_unit(logo, scale_by=10^6) # measurements in micronslogo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo # measurements in meters x3p_scale_unit(logo, scale_by=10^6) # measurements in microns
Interactive selection of rectangular area on the mask of an x3p object. Once the function runs, the active rgl window is brought to the front. Select the window with a click, then use click & drag to select a rectangular area. On release, this area is marked in the mask and (if update is TRUE) appears in the selection color in the active rgl window.
x3p_select(x3p, col = "#FF0000", update = TRUE)x3p_select(x3p, col = "#FF0000", update = TRUE)
x3p |
x3p file |
col |
character value of the selection color |
update |
boolean value, whether the rgl window should be updated to show the selected rectangle |
x3p file with selection in mask
## Not run: if (interactive) { if (!file.exists("fadul1-1.x3p")) { url <- "https://tsapps.nist.gov/NRBTD/Studies/CartridgeMeasurement/DownloadMeasurement" file <- "2d9cc51f-6f66-40a0-973a-a9292dbee36d" download.file(file.path(url, file), destfile="fadul1-1.x3p") } x3p <- x3p_read("fadul1-1.x3p") x3p_image(x3p, size=c(500,500), zoom=.8) x3p <- x3p_select(x3p, update=TRUE, col="#FF0000") logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size=c(500,500), zoom = 1) x3p_select(logo, update=TRUE, col="#00FF00") } ## End(Not run)## Not run: if (interactive) { if (!file.exists("fadul1-1.x3p")) { url <- "https://tsapps.nist.gov/NRBTD/Studies/CartridgeMeasurement/DownloadMeasurement" file <- "2d9cc51f-6f66-40a0-973a-a9292dbee36d" download.file(file.path(url, file), destfile="fadul1-1.x3p") } x3p <- x3p_read("fadul1-1.x3p") x3p_image(x3p, size=c(500,500), zoom=.8) x3p <- x3p_select(x3p, update=TRUE, col="#FF0000") logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_image(logo, size=c(500,500), zoom = 1) x3p_select(logo, update=TRUE, col="#00FF00") } ## End(Not run)
Apply color shading to the mask of a 3d topographic surface.
x3p_shade_mask( x3p, colors = rev(c("#b12819", "#d7301f", "#e16457", "#ffffff", "#5186a2", "#175d82", "#134D6B")), freqs = c(0, 0.05, 0.25, 0.45, 0.55, 0.75, 0.95, 1) )x3p_shade_mask( x3p, colors = rev(c("#b12819", "#d7301f", "#e16457", "#ffffff", "#5186a2", "#175d82", "#134D6B")), freqs = c(0, 0.05, 0.25, 0.45, 0.55, 0.75, 0.95, 1) )
x3p |
object containing a 3d topographic surface |
colors |
vector of colors |
freqs |
vector of values corresponding to color frequency (turned into quantiles of the differenced values) |
x3p object with color-shaded mask
## Not run: data(wire) x3p <- wire x3p_image(x3p, size = c(400, 400), zoom=0.8) x3p_with <- x3p %>% x3p_shade_mask() x3p_image(x3p_with, size = c(400, 400), zoom=0.8) data(lea) lea %>% x3p_shade_mask() %>% x3p_image() lea %>% x3p_shade_mask(freqs = c(0, 0.05, 0.1, 0.3,0.7, 0.9, 0.95, 1)) %>% x3p_image() ## End(Not run)## Not run: data(wire) x3p <- wire x3p_image(x3p, size = c(400, 400), zoom=0.8) x3p_with <- x3p %>% x3p_shade_mask() x3p_image(x3p_with, size = c(400, 400), zoom=0.8) data(lea) lea %>% x3p_shade_mask() %>% x3p_image() lea %>% x3p_shade_mask(freqs = c(0, 0.05, 0.1, 0.3,0.7, 0.9, 0.95, 1)) %>% x3p_image() ## End(Not run)
Identify xml fields by name and show content.
x3p_show_xml(x3p, element, verbose = TRUE)x3p_show_xml(x3p, element, verbose = TRUE)
x3p |
x3p object |
element |
character or integer (vector). In case of character, name of xml field in the meta file. Note that element can contain regular expressions, e.g. |
verbose |
boolean should warning be shown? |
list of exact field names and their contents
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_show_xml(logo, "creator") # all fields containing the word "creator" x3p_show_xml(logo, "axis") x3p_show_xml(logo, "CZ.AxisType") # show all fields: x3p_show_xml(logo, "*") # show first five fields x3p_show_xml(logo, 1:5)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) x3p_show_xml(logo, "creator") # all fields containing the word "creator" x3p_show_xml(logo, "axis") x3p_show_xml(logo, "CZ.AxisType") # show all fields: x3p_show_xml(logo, "*") # show first five fields x3p_show_xml(logo, 1:5)
Make a snapshot of the current rgl device and save it to file. Options for file formats are png, svg, and stl (for 3d printing).
x3p_snapshot(file)x3p_snapshot(file)
file |
file name for saving. The file extension determines the type of output. Possible extensions are png, stl (suitable for 3d printing), or svg. |
An x3p file consists of a list with meta info and a 2d matrix with scan depths. fortify turns the matrix into a data frame, using the parameters of the header as necessary.
x3p_to_df(x3p)x3p_to_df(x3p)
x3p |
a file in x3p format as returned by function x3p_read |
data frame with variables x, y, and value and meta function in attribute
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo_df <- x3p_to_df(logo) head(logo_df)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo_df <- x3p_to_df(logo) head(logo_df)
Transpose the surface matrix of an x3p object. Also adjust meta information.
x3p_transpose(x3p) transpose_x3p(x3p)x3p_transpose(x3p) transpose_x3p(x3p)
x3p |
x3p object |
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) ## Not run: x3p_image(logo) ## End(Not run) # transpose the image logotp <- x3p_transpose(logo) dim(logotp$surface.matrix) ## Not run: x3p_image(logotp) ## End(Not run)logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) dim(logo$surface.matrix) ## Not run: x3p_image(logo) ## End(Not run) # transpose the image logotp <- x3p_transpose(logo) dim(logotp$surface.matrix) ## Not run: x3p_image(logotp) ## End(Not run)
Trims rows and columns from the edges of a surface matrix that contain missing values only.
x3p_trim_na(x3p, ratio = 1)x3p_trim_na(x3p, ratio = 1)
x3p |
x3p object |
ratio |
ratio between zero and one, indicating the percent of values that need to be missing in each row and column, for the row or column to be removed |
x3p object of the same or smaller dimension where missing values are removed from the boundaries
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo$surface.matrix[logo$surface.matrix == median(logo$surface.matrix)] <- NA x3p_trim_na(logo) # reduced to dimension: 668 by 268logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) logo$surface.matrix[logo$surface.matrix == median(logo$surface.matrix)] <- NA x3p_trim_na(logo) # reduced to dimension: 668 by 268
Write an x3p object to a file
x3p_write(x3p, file, size = 8, quiet = F, create_dir = T) write_x3p(x3p, file, size = 8, quiet = F)x3p_write(x3p, file, size = 8, quiet = F, create_dir = T) write_x3p(x3p, file, size = 8, quiet = F)
x3p |
x3p object |
file |
path to where the file should be written |
size |
integer. The number of bytes per element in the surface matrix used for creating the binary file. Use size = 4 for 32 bit IEEE 754 floating point numbers and size = 8 for 64 bit IEEE 754 floating point number (default). |
quiet |
suppress messages |
create_dir |
boolean. create directory for saving file, if necessary. Posts a message in case a directory is created. |
logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # write a copy of the file into a temporary file x3p_write(logo, file = tempfile(fileext="x3p"))logo <- x3p_read(system.file("csafe-logo.x3p", package="x3ptools")) # write a copy of the file into a temporary file x3p_write(logo, file = tempfile(fileext="x3p"))