-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[voxel] update SVO & isosurface ns to current core API, add example
- Loading branch information
1 parent
d380b18
commit f732d61
Showing
5 changed files
with
466 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#+SETUPFILE: setup.org | ||
|
||
* geom.voxels examples | ||
|
||
#+BEGIN_SRC clojure :tangle ../babel/examples/example01.clj :mkdirp yes :padline no | ||
(ns example01 | ||
(:require | ||
[thi.ng.geom.core :as g] | ||
[thi.ng.geom.core.vector :refer [vec3]] | ||
[thi.ng.geom.voxel.svo :as svo] | ||
[thi.ng.geom.voxel.isosurface :as iso] | ||
[thi.ng.geom.mesh.io :as mio] | ||
[thi.ng.common.math.core :as m] | ||
[clojure.java.io :as io])) | ||
|
||
(def res (double 1/8)) | ||
(def wall 0.25) | ||
|
||
(defn gyroid ^double [s t p] | ||
"Evaluates gyroid function at scaled point `p`." | ||
(let [[x y z] (g/* p s)] | ||
(- (m/abs | ||
(+ (* (Math/cos x) (Math/sin z)) | ||
(* (Math/cos y) (Math/sin x)) | ||
(* (Math/cos z) (Math/sin y)))) | ||
t))) | ||
|
||
(def delete-voxels #(first (svo/delete-at % %2))) | ||
|
||
(defn voxel-box | ||
[tree op flt range] | ||
(->> (for [x range y range, z range] (vec3 x y z)) | ||
(filter flt) | ||
(svo/apply-voxels op tree))) | ||
|
||
(time | ||
(def v | ||
(reduce | ||
(fn [tree [op r]] (voxel-box tree op identity r)) | ||
(svo/voxeltree 32 res) | ||
[[svo/set-at (range 10 20 res)] [svo/set-at (range 15 25 res)]]))) | ||
|
||
(time | ||
(def v2 | ||
(reduce | ||
(fn [tree [op r]] (voxel-box tree op identity r)) | ||
v [[delete-voxels (range (+ 10 wall) (- 20 wall) res)] | ||
[delete-voxels (range (+ 15 wall) (- 25 wall) res)]]))) | ||
|
||
(time | ||
(def v3 | ||
(reduce | ||
(fn [tree [op r]] | ||
(voxel-box tree op #(m/in-range? 0.0 10.0 (gyroid 1.0 1.2 %)) r)) | ||
v2 [[svo/set-at (range (+ 10 wall) (- 20 wall) res)] | ||
[svo/set-at (range (+ 15 wall) (- 25 wall) res)]]))) | ||
|
||
(time | ||
(def v4 | ||
(reduce | ||
(fn [tree [f rx ry rz]] (svo/apply-voxels f tree (for [x rx y ry z rz] (vec3 x y z)))) | ||
v3 [[delete-voxels (range 9 26 res) (range 9 26 res) (range 18 26 res)]]))) | ||
|
||
(time (with-open [o (io/output-stream "foo.stl")] (mio/write-stl o (g/tessellate (iso/surface-mesh v4 11 0.5))))) | ||
#+END_SRC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#+SETUPFILE: ../../src/setup.org | ||
#+TITLE: thi.ng/geom-voxel | ||
|
||
* About the project | ||
|
||
** Overview | ||
|
||
This is a sub-module of [[file:../../src/index.org][thi.ng/geom]] and is in early stage development. | ||
The module is providing an early, experimental, not very efficient | ||
implementation of a sparse voxel octree (SVO) and functions to compute | ||
an isosurface mesh from an SVO. | ||
|
||
** Status | ||
|
||
ALPHA quality, in active development. | ||
|
||
* Namespaces | ||
|
||
- [[./svo.org][thi.ng.geom.voxel.svo]] | ||
- [[./isosurface.org][thi.ng.geom.voxel.isosurface]] | ||
- [[./examples.org][examples]] | ||
|
||
* Tests | ||
|
||
* Module definition | ||
|
||
** Building & testing this project | ||
|
||
Please see the [[file:../../src/index.org][parent project]] for further information. | ||
|
||
** Injected properties :noexport: | ||
|
||
This template uses shared project configuration defined in [[../../src/config.org][config.org]]. | ||
Module specific settings are defined below: | ||
|
||
#+BEGIN_SRC clojure :exports none :noweb-ref project-name | ||
thi.ng/geom-voxel | ||
#+END_SRC | ||
|
||
#+BEGIN_SRC clojure :exports none :noweb yes :noweb-ref cljs-artefact-path | ||
target/geom-voxel-<<conf-version()>>.js | ||
#+END_SRC | ||
|
||
** Leiningen project file :noexport: | ||
|
||
#+BEGIN_SRC clojure :tangle ../babel/project.clj :noweb yes :mkdirp yes :padline no | ||
(defproject <<project-name>> "<<conf-version()>>" | ||
:description "thi.ng geometry kit - voxel module" | ||
:url "<<conf-project-url>>" | ||
:license {:name "Apache Software License" | ||
:url "http://www.apache.org/licenses/LICENSE-2.0" | ||
:distribution :repo} | ||
:scm {:name "git" | ||
:url "<<conf-project-url>>"} | ||
|
||
:min-lein-version "2.4.0" | ||
|
||
:dependencies [<<dep-clj>> | ||
[thi.ng/geom-core "<<conf-version()>>"] | ||
[thi.ng/geom-types "<<conf-version()>>"] | ||
[thi.ng/geom-meshops "<<conf-version()>>"]] | ||
|
||
:source-paths ["src/cljx"] | ||
:test-paths ["<<conf-gen-test-path>>"] | ||
|
||
:profiles {:dev {:dependencies [<<dep-cljs>> | ||
<<dep-criterium>>] | ||
:plugins [<<dep-cljx>> | ||
<<dep-cljsbuild>> | ||
<<dep-cljs-test>>] | ||
:global-vars {*warn-on-reflection* true} | ||
:jvm-opts ^:replace [] | ||
:auto-clean false | ||
:prep-tasks [["cljx" "once"]] | ||
:aliases {"cleantest" ["do" "clean," "cljx" "once," "test," "cljsbuild" "test"]}}} | ||
|
||
:cljx {:builds [{:source-paths ["src/cljx"] | ||
:output-path "<<conf-gen-source-path>>" | ||
:rules :clj} | ||
{:source-paths ["src/cljx"] | ||
:output-path "<<conf-gen-source-path>>" | ||
:rules :cljs} | ||
{:source-paths ["test/cljx"] | ||
:output-path "<<conf-gen-test-path>>" | ||
:rules :clj} | ||
{:source-paths ["test/cljx"] | ||
:output-path "<<conf-gen-test-path>>" | ||
:rules :cljs}]} | ||
|
||
:cljsbuild {:builds [{:source-paths ["<<conf-gen-source-path>>" "<<conf-gen-test-path>>"] | ||
:id "simple" | ||
:compiler {:output-to "<<cljs-artefact-path>>" | ||
:optimizations :whitespace | ||
:pretty-print true}}] | ||
:test-commands {"unit-tests" ["phantomjs" :runner "<<cljs-artefact-path>>"]}} | ||
|
||
:pom-addition [:developers [:developer | ||
[:name "Karsten Schmidt"] | ||
[:url "http://postspectacular.com"] | ||
[:timezone "0"]]]) | ||
#+END_SRC | ||
|
||
** Accessing library version during runtime | ||
|
||
The autogenerated namespace =thi.ng.geom.voxel.version= contains a single | ||
symbol =version= holding the version string defined above: | ||
|
||
#+BEGIN_SRC clojure :noweb yes | ||
(use 'thi.ng.geom.voxel.version) | ||
|
||
(prn version) | ||
; "<<conf-version()>>" | ||
#+END_SRC | ||
|
||
*** Version namespace :noexport: | ||
|
||
#+BEGIN_SRC clojure :tangle ../babel/src/cljx/thi/ng/geom/voxel/version.cljx :noweb yes :mkdirp yes :padline no | ||
(ns thi.ng.geom.voxel.version) | ||
(def version "<<conf-version()>>") | ||
#+END_SRC | ||
|
||
** Contributors | ||
|
||
| *Name* | *Role* | *Website* | | ||
| [[mailto:[email protected]][Karsten Schmidt]] | initiator & principal developer | [[http://postspectacular.com][postspectacular.com]] | | ||
| | | [[http://thi.ng][thi.ng]] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.