# How to add a public method to 3d-plot-area%?

**URL:** <https://racket.discourse.group/t/how-to-add-a-public-method-to-3d-plot-area/2971>\
**Category:** Questions & Answers\
**Tags:** question, plot\
**Created:** [June 18, 2024, 9:40am UTC](https://racket.discourse.group/t/how-to-add-a-public-method-to-3d-plot-area/2971 "2024-06-18T09:40:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rscho](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rscho/32/726_2.png) [@rscho](https://racket.discourse.group/u/rscho)\
**Post date:** [June 18, 2024, 9:40am UTC](https://racket.discourse.group/t/how-to-add-a-public-method-to-3d-plot-area/2971/1 "2024-06-18T09:40:42Z")

</div>

Hi, I am trying to build a new 3d renderer for the `plot` package. The renderer is a 3d matrix viewer, where each index in the matrix matches a voxel in the plot. The current implementation is inspired by the existing [rectangles3d renderer](https://docs.racket-lang.org/plot/renderer3d.html#%28def._%28%28lib._plot%2Fmain..rkt%29._rectangles3d%29%29)

It seems one of the initial steps is to make a `put-voxels` method in the public API of `3d-plot-area%`. This code compiles and typechecks, and can be seen at [https://github.com/Rscho314/plot/blob/raoul\_voxel/plot-lib/plot/private/plot3d/plot-area.rkt](https://github.com/Rscho314/plot/blob/raoul_voxel/plot-lib/plot/private/plot3d/plot-area.rkt).

But the method is not seen when I try to use the API, such as in [https://github.com/Rscho314/plot/blob/raoul\_voxel/plot-lib/plot/private/plot3d/voxel.rkt](https://github.com/Rscho314/plot/blob/raoul_voxel/plot-lib/plot/private/plot3d/voxel.rkt).

How can I make my new method visible ? Thanks !

---

<div class="post-metadata">

**Author:** ![alexh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexh/32/315_2.png) [@alexh](https://racket.discourse.group/u/alexh)\
**Post date:** [June 19, 2024, 11:20am UTC](https://racket.discourse.group/t/how-to-add-a-public-method-to-3d-plot-area/2971/2 "2024-06-19T11:20:40Z")

</div>

I had a look at the code, and I don't see what the problem could be - it should work. Can you post the error message you get when you try to run it?

* * *

On a separate note, and if I understood your code correctly, I think you can easily use the existing `rectangles3d` renderer to plot voxels. You just need to write a function which converts the 3d boolean matrix into 3D rectangles:

```scheme
(define (voxel-model->plot-rectangles vm)
  (for/list ([(zs z) (in-indexed vm)] #:when zs
             [(ys y) (in-indexed zs)] #:when ys
             [(xs x) (in-indexed ys)] #:when xs)
    (vector (ivl x (add1 x))
            (ivl y (add1 y))
            (ivl z (add1 z)))))

```

Here is an example, rendering a voxel matrix:

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/f/f86390b275a114b49e58a1c593a80d2e47e3d5cb.png)

... and the source code is here:

> <https://gist.github.com/alex-hhh/c48d577046a1f4095669b3473d8180a4>

Alex.

---

<div class="post-metadata">

**Author:** ![bdeket](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/bdeket/32/1835_2.png) [@bdeket](https://racket.discourse.group/u/bdeket)\
**Post date:** [June 19, 2024, 5:09pm UTC](https://racket.discourse.group/t/how-to-add-a-public-method-to-3d-plot-area/2971/3 "2024-06-19T17:09:39Z")

</div>

Sorry if this is obvious, but did you set up your plot clone up as the installed package? Because otherwise `(require plot/utils)` is still referring to the standard install that does not have your updates.  
(... having been bitten myself by this when working on the plot library...)

---

<div class="post-metadata">

**Author:** ![rscho](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rscho/32/726_2.png) [@rscho](https://racket.discourse.group/u/rscho)\
**Post date:** [June 20, 2024, 1:38pm UTC](https://racket.discourse.group/t/how-to-add-a-public-method-to-3d-plot-area/2971/4 "2024-06-20T13:38:47Z")

</div>

Indeed, I forgot to `raco setup plot`, thanks for reminding me!

# EDIT:

I solved the problem with `raco setup plot`. Apparently, `plot/compat` had to be installed separately.

# EDIT 2:

For new methods to be visible, the symbols have to be reprovided in `plot/no-gui.rkt`. I then had to `raco setup -c --pkgs plot` and again `raco setup plot` for the symbols to finally become accessible.

@alexh when I try to `raco setup plot` on a clean local copy of `racket/plot`, build fails with the following (racket 8.13, Linux install as non-root user):

> raco setup: --- summary of errors --- [15:27:32]  
> raco setup: error: during making for /plot-doc/plot  
> raco setup: plot-doc/plot/scribblings/compat.scrbl:5:21: cannot open module file  
> raco setup: module path: plot/compat  
> raco setup: path: /home/raoul/Desktop/racket\_plot/plot/plot-gui-lib/plot/compat.rkt  
> raco setup: system error: no such file or directory; rkt\_err=3  
> raco setup: compiling: /plot-doc/plot/scribblings/compat.scrbl  
> raco setup: error: during building docs for /plot-doc/plot/scribblings/plot.scrbl  
> raco setup: plot-doc/plot/scribblings/compat.scrbl:5:21: cannot open module file  
> raco setup: module path: plot/compat  
> raco setup: path: /home/raoul/Desktop/racket\_plot/plot/plot-gui-lib/plot/compat.rkt  
> raco setup: system error: no such file or directory; rkt\_err=3

Would you know where I'm doing it wrong ? Thx !

I am aware `rectangles3d` can be used for cube voxels. My goal is to use other space-filling polygons, such as the truncated octahedron and friends. It could certainly be done by using the existing plotting facilities, but I thought it might be interesting to others and was perhaps worth a PR.
