Merge pull request #23 from ryantimpe/rglModels

Documentation and website updates for the 0.2 release
This commit is contained in:
Ryan Timpe
2019-11-03 15:45:46 -05:00
committed by GitHub
49 changed files with 132 additions and 14 deletions

View File

@@ -9,6 +9,7 @@
## 3D Models
* `build_bricks()` now renders models in {rgl}, rather than {rayshader}. Most options for the rendering have changed. Use `build_brick_rayshader()` for previous output.
* Support for transparent bricks. See `build_colors()` for list of color names.
----

View File

@@ -8,6 +8,18 @@
#' Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.
#' @param trans_alpha Default 0.5. Alpha level for transparent bricks.
#' @param view_levels Numeric array of Levels/z values to display. Leave as 'NULL' to include all.
#' @examples \dontrun{
#' #This is a brick
#'brick <- data.frame(
#' Level="A",
#' X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
#' X2 = rep(3,4)
#')
#'
#'brick %>%
#' bricks_from_table() %>%
#' build_bricks()
#' }
#' @return 3D brick model rendered in the 'rgl' package.
#' @family 3D Models
#' @export

View File

@@ -43,7 +43,7 @@ layer_from_bricks <- function(brick_list, brick_type = "brick", lev=1, brick_res
hd = 30,
uhd = 60)
}
#Use below is edge calculation
# Optimized color only in HD bricks >20 pixels
@@ -94,8 +94,8 @@ layer_from_bricks <- function(brick_list, brick_type = "brick", lev=1, brick_res
dplyr::mutate(x_mid = median(x), y_mid = median(y),
stud = ((x-x_mid)^2 + (y-y_mid)^2)^(1/2) <= (ex_size * (5/8 * (1/2))),
stud_color = dplyr::between(((x-x_mid)^2 + (y-y_mid)^2)^(1/2),
(ex_size * (5/8 * (1/2))) - 1,
(ex_size * (5/8 * (1/2))) + 1
(ex_size * (5/8 * (1/2))) - 1,
(ex_size * (5/8 * (1/2))) + 1
)) %>%
dplyr::ungroup() %>%
dplyr::mutate(elevation = ifelse(stud, elevation+0.5, elevation)) %>%
@@ -176,13 +176,25 @@ layer_from_bricks <- function(brick_list, brick_type = "brick", lev=1, brick_res
#' @param water Default 'FALSE'. If 'TRUE', a water layer is rendered.
#' @param waterdepth Default '0'. Water level.
#' @param ... All other inputs from rayshader::plot_3d() EXCEPT \code{hillshade}, \code{soliddepth}, \code{zscale}, and \code{shadow}.
#' @return 3D brick model rendered in the 'rgl' package.
#' @examples \dontrun{
#' #This is a brick
#'brick <- data.frame(
#' Level="A",
#' X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
#' X2 = rep(3,4)
#')
#'
#'brick %>%
#' bricks_from_table() %>%
#' build_bricks()
#' }
#' @return 3D brick model rendered in the 'rayshader' package.
#' @family 3D Models
#' @export
#'
build_bricks_rayshader <- function(brick_list, brick_type = "brick", brick_res = "sd",
view_levels = NULL, solidcolor = "#a3a2a4",
water = FALSE, waterdepth = 0, ...){
view_levels = NULL, solidcolor = "#a3a2a4",
water = FALSE, waterdepth = 0, ...){
#Requires Rayshader
if (!requireNamespace("rayshader", quietly = TRUE)) {
stop("Package \"rayshader\" needed for this function to work. Please install it.",
@@ -198,7 +210,7 @@ build_bricks_rayshader <- function(brick_list, brick_type = "brick", brick_res =
if(is.null(view_levels)){
view_levels <- unique(img_lego$Level)
}
for(ii in view_levels){
brick_layer <- brick_list %>%
layer_from_bricks(ii, brick_type = brick_type, brick_res = brick_res)
@@ -216,7 +228,7 @@ build_bricks_rayshader <- function(brick_list, brick_type = "brick", brick_res =
solidcolor=solidcolor, shadow = FALSE,
water = FALSE, waterdepth = 0, ...)
}
}
}

View File

@@ -121,12 +121,20 @@ scaled_to_colors <- function(image_list, method = "cie94",
#No transparent colors in mosaics
dplyr::filter(!Trans_lego)
} else{
brick_table <- color_table
# if(any(stringr::str_detect(color_table$Color, stringr::fixed("Tr. ")))){
# warning("Transparent bricks cannot be used in mosaics. Removing from color_table.")
# }
brick_table <- color_table %>%
#No transparent colors in mosaics
dplyr::filter(!stringr::str_detect(Color, stringr::fixed("Tr. ")))
}
#Set up color palette... used standard way or with Dithering
if(any(c("universal", "generic", "special") %in% color_palette)){
brick_table <- brick_table %>%
#No transparent colors in mosaics
dplyr::filter(!Trans_lego) %>%
dplyr::filter(tolower(Palette) %in% color_palette)
} else {
#Black and white is simpler... cut the colors into 4 groups, then assign lightest = white, darkest = black

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@@ -11,6 +11,7 @@ reference:
contents:
- starts_with("bricks_")
- build_bricks
- build_bricks_rayshader
- title: ggplot Extension
desc: Brick bar charts in ggplot
contents:

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View File

@@ -193,7 +193,8 @@
<a class="sourceLine" id="cb4-5" title="5"><span class="st"> </span><span class="kw"><a href="../reference/build_bricks_rayshader.html">build_bricks_rayshader</a></span>(<span class="dt">theta =</span> <span class="dv">135</span>, <span class="dt">phi =</span> <span class="dv">45</span>)</a>
<a class="sourceLine" id="cb4-6" title="6"></a>
<a class="sourceLine" id="cb4-7" title="7">rayshader<span class="op">::</span><span class="kw"><a href="https://rdrr.io/pkg/rayshader/man/render_snapshot.html">render_snapshot</a></span>(<span class="dt">clear =</span> <span class="ot">TRUE</span>)</a></code></pre></div>
<p><img src="models-from-other_files/figure-html/bricks_rayshader-2.png" width="384"><img src="models-from-other_files/figure-html/bricks_rayshader-1.png" width="384"> This example is rendered using <code><a href="../reference/build_bricks_rayshader.html">build_bricks_rayshader()</a></code>, which a bit faster for very large sets.</p>
<p><img src="models-from-other_files/figure-html/bricks_rayshader-2.png" width="384"></p>
<p>This example is rendered using <code><a href="../reference/build_bricks_rayshader.html">build_bricks_rayshader()</a></code>, which a bit faster for very large sets.</p>
</div>
</div>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

After

Width:  |  Height:  |  Size: 337 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@@ -7,6 +7,15 @@
color: #ffffff;
}
.navbar-default .navbar-toggle .icon-bar {
background-color: #ffffff;
}
.navbar-default .navbar-nav>li>a:focus, .navbar-default .navbar-nav>li>a:hover {
color: #FAC80A;
background-color: transparent;
}
.navbar-default .navbar-link {
color: white;
font-weight: bold;

View File

@@ -164,6 +164,7 @@
<ul>
<li>
<code><a href="../reference/build_bricks.html">build_bricks()</a></code> now renders models in {rgl}, rather than {rayshader}. Most options for the rendering have changed. Use <code>build_brick_rayshader()</code> for previous output.</li>
<li>Support for transparent bricks. See <code><a href="../reference/build_colors.html">build_colors()</a></code> for list of color names.</li>
</ul>
<hr>
</div>

View File

@@ -200,6 +200,19 @@ Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.</p></td>
<code><a href='bricks_from_table.html'>bricks_from_table</a></code>,
<code><a href='build_bricks_rayshader.html'>build_bricks_rayshader</a></code></p></div>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
<pre class="examples"><div class='input'><span class='kw'>if</span> (<span class='fl'>FALSE</span>) {
<span class='co'>#This is a brick</span>
<span class='no'>brick</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span>(
<span class='kw'>Level</span><span class='kw'>=</span><span class='st'>"A"</span>,
<span class='kw'>X1</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>), <span class='co'>#The number 3 is the brickrID for 'bright red'</span>
<span class='kw'>X2</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>)
)
<span class='no'>brick</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='bricks_from_table.html'>bricks_from_table</a></span>() <span class='kw'>%&gt;%</span>
<span class='fu'>build_bricks</span>()
}</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<h2>Contents</h2>
@@ -207,6 +220,7 @@ Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.</p></td>
<li><a href="#arguments">Arguments</a></li>
<li><a href="#value">Value</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#examples">Examples</a></li>
</ul>
</div>

View File

@@ -195,7 +195,7 @@ Enter a value for a custom resolution. High resolutions take longer to render.</
<h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
<p>3D brick model rendered in the 'rgl' package.</p>
<p>3D brick model rendered in the 'rayshader' package.</p>
<h2 class="hasAnchor" id="see-also"><a class="anchor" href="#see-also"></a>See also</h2>
<div class='dont-index'><p>Other 3D Models: <code><a href='bricks_from_coords.html'>bricks_from_coords</a></code>,
@@ -205,6 +205,19 @@ Enter a value for a custom resolution. High resolutions take longer to render.</
<code><a href='bricks_from_table.html'>bricks_from_table</a></code>,
<code><a href='build_bricks.html'>build_bricks</a></code></p></div>
<h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
<pre class="examples"><div class='input'><span class='kw'>if</span> (<span class='fl'>FALSE</span>) {
<span class='co'>#This is a brick</span>
<span class='no'>brick</span> <span class='kw'>&lt;-</span> <span class='fu'><a href='https://rdrr.io/r/base/data.frame.html'>data.frame</a></span>(
<span class='kw'>Level</span><span class='kw'>=</span><span class='st'>"A"</span>,
<span class='kw'>X1</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>), <span class='co'>#The number 3 is the brickrID for 'bright red'</span>
<span class='kw'>X2</span> <span class='kw'>=</span> <span class='fu'><a href='https://rdrr.io/r/base/rep.html'>rep</a></span>(<span class='fl'>3</span>,<span class='fl'>4</span>)
)
<span class='no'>brick</span> <span class='kw'>%&gt;%</span>
<span class='fu'><a href='bricks_from_table.html'>bricks_from_table</a></span>() <span class='kw'>%&gt;%</span>
<span class='fu'><a href='build_bricks.html'>build_bricks</a></span>()
}</div></pre>
</div>
<div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
<h2>Contents</h2>
@@ -212,6 +225,7 @@ Enter a value for a custom resolution. High resolutions take longer to render.</
<li><a href="#arguments">Arguments</a></li>
<li><a href="#value">Value</a></li>
<li><a href="#see-also">See also</a></li>
<li><a href="#examples">Examples</a></li>
</ul>
</div>

View File

@@ -215,6 +215,12 @@
<p><code><a href="build_bricks.html">build_bricks()</a></code> </p>
</td>
<td><p>Build 3D brick model with rgl</p></td>
</tr><tr>
<td>
<p><code><a href="build_bricks_rayshader.html">build_bricks_rayshader()</a></code> </p>
</td>
<td><p>Build 3D brick model with rayshader.</p></td>
</tr>
</tbody><tbody>
<tr>

View File

@@ -29,6 +29,20 @@ Set to 'TRUE' and rgl_lit='FALSE' for cartoon-looking bricks.}
\description{
Build 3D brick model with rgl
}
\examples{
\dontrun{
#This is a brick
brick <- data.frame(
Level="A",
X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
X2 = rep(3,4)
)
brick \%>\%
bricks_from_table() \%>\%
build_bricks()
}
}
\seealso{
Other 3D Models: \code{\link{bricks_from_coords}},
\code{\link{bricks_from_excel}},

View File

@@ -27,11 +27,25 @@ Enter a value for a custom resolution. High resolutions take longer to render.}
\item{...}{All other inputs from rayshader::plot_3d() EXCEPT \code{hillshade}, \code{soliddepth}, \code{zscale}, and \code{shadow}.}
}
\value{
3D brick model rendered in the 'rgl' package.
3D brick model rendered in the 'rayshader' package.
}
\description{
Build 3D brick model with rayshader.
}
\examples{
\dontrun{
#This is a brick
brick <- data.frame(
Level="A",
X1 = rep(3,4), #The number 3 is the brickrID for 'bright red'
X2 = rep(3,4)
)
brick \%>\%
bricks_from_table() \%>\%
build_bricks()
}
}
\seealso{
Other 3D Models: \code{\link{bricks_from_coords}},
\code{\link{bricks_from_excel}},

View File

@@ -7,6 +7,15 @@
color: #ffffff;
}
.navbar-default .navbar-toggle .icon-bar {
background-color: #ffffff;
}
.navbar-default .navbar-nav>li>a:focus, .navbar-default .navbar-nav>li>a:hover {
color: #FAC80A;
background-color: transparent;
}
.navbar-default .navbar-link {
color: white;
font-weight: bold;

View File

@@ -39,6 +39,7 @@ mosaic <- png::readPNG(demo_img) %>%
mosaic %>% build_mosaic()
```
```{r bricks_6a, rgl=TRUE, dev='png', echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
mosaic %>%
bricks_from_mosaic(highest_el = "dark") %>%
@@ -62,7 +63,7 @@ rgl::par3d(userMatrix = rgl::rotate3d(custom_rotation, 0, 0, pi/4 ,1))
* `max_height` is the number of bricks stacked at the mosaic's highest point. The default is 12.
* `img_size` is the number of bricks on each side of the model. The default is 48.
```{r bricks_rayshader, rgl=TRUE, dev='png', echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
```{r bricks_rayshader, echo=TRUE, warning=FALSE, message=FALSE, fig.width=4, fig.height=4}
library(rayshader)
#Example from rayshader.com
@@ -95,4 +96,5 @@ rayshader_object %>%
rayshader::render_snapshot(clear = TRUE)
```
This example is rendered using `build_bricks_rayshader()`, which a bit faster for very large sets.