Skip to content

Commit

Permalink
[meshops] remove cljx dependency, switch to clj1.7 reader conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed May 25, 2015
1 parent 2742d32 commit 127d83b
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 85 deletions.
12 changes: 6 additions & 6 deletions geom-meshops/src/csg.org
Original file line number Diff line number Diff line change
Expand Up @@ -217,18 +217,18 @@ meshes.
** Complete namespace definition
#+BEGIN_SRC clojure :tangle ../babel/src/cljx/thi/ng/geom/mesh/csg.cljx :noweb yes :mkdirp yes :padline no
(ns thi.ng.geom.mesh.csg
,#+cljs
(:require-macros
[thi.ng.macromath.core :as mm])
#?(:cljs
(:require-macros
[thi.ng.math.macros :as mm]))
(:require
[thi.ng.geom.core :as g]
[thi.ng.geom.core.vector :as v :refer [vec3 V3X V3Y]]
[thi.ng.geom.basicmesh :as bm]
[thi.ng.geom.plane :as p]
[thi.ng.geom.types.utils :as tu]
[thi.ng.common.data.core :as d]
[thi.ng.common.math.core :as m :refer [PI TWO_PI *eps*]]
,#+clj [thi.ng.macromath.core :as mm]))
[thi.ng.dstruct.core :as d]
[thi.ng.math.core :as m :refer [PI TWO_PI *eps*]]
#?(:clj [thi.ng.math.macros :as mm])))

(declare csg-polygon)

Expand Down
12 changes: 6 additions & 6 deletions geom-meshops/src/delaunay.org
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ is to add additional point(s) in the center.

#+BEGIN_SRC clojure :tangle ../babel/src/cljx/thi/ng/geom/mesh/delaunay.cljx :noweb yes :mkdirp yes :padline no
(ns thi.ng.geom.mesh.delaunay
,#+cljs (:require-macros [thi.ng.macromath.core :as mm])
#?(:cljs (:require-macros [thi.ng.math.macros :as mm]))
(:require
[thi.ng.geom.core :as g]
[thi.ng.geom.triangle :refer [circumcircle-raw triangle2]]
[thi.ng.common.math.core :as m :refer [*eps* delta=]]
,#+clj [thi.ng.macromath.core :as mm])
#+clj
(:import
[thi.ng.geom.types Triangle2]))
[thi.ng.math.core :as m :refer [*eps* delta=]]
#?(:clj [thi.ng.math.macros :as mm]))
#?(:clj
(:import
[thi.ng.geom.types Triangle2])))

<<delaunay>>
#+END_SRC
32 changes: 8 additions & 24 deletions geom-meshops/src/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,21 @@ target/geom-meshops-<<conf-version()>>.js
:min-lein-version "2.4.0"

:dependencies [<<dep-clj>>
<<dep-cljs>>
[thi.ng/geom-core "<<conf-version()>>"]
[thi.ng/geom-types "<<conf-version()>>"]]

:source-paths ["src/cljx"]
:test-paths ["<<conf-gen-test-path>>"]
:source-paths ["src"]
:test-paths ["test"]

:profiles {:dev {:dependencies [<<dep-cljs>>
<<dep-criterium>>]
:plugins [<<dep-cljx>>
<<dep-cljsbuild>>
:profiles {:dev {:dependencies [<<dep-criterium>>]
:plugins [<<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>>"]
:aliases {"cleantest" ["do" "clean," "test," "cljsbuild" "test"]}}}

:cljsbuild {:builds [{:source-paths ["src" "test"]
:id "simple"
:compiler {:output-to "<<cljs-artefact-path>>"
:optimizations :whitespace
Expand Down
84 changes: 48 additions & 36 deletions geom-meshops/src/meshio.org
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,24 @@
- [[#complete-namespace-definition][Complete namespace definition]]

* thi.ng.geom.mesh.io
** TODO make CLJS compatible

** TODO make CLJS compatible
** Configuration parameters

#+BEGIN_SRC clojure :noweb-ref config
(def ^:dynamic *precision* 5)
#+END_SRC

** STL

#+BEGIN_SRC clojure :noweb-ref stl
(defn write-stl
"Writes the given mesh as binary STL to output stream. Mesh is
automatically tessellated into triangles."
[^OutputStream stream mesh]
(let [faces (g/faces mesh)
fnormals (g/face-normals mesh true)]
(.write stream #+clj (byte-array 80) #+cljs (into-array (repeat 80 0)))
(.write stream #?(:clj (byte-array 80) :cljs (into-array (repeat 80 0))))
(b/write-int32-le stream (count faces))
(doseq [[a b c :as f] faces]
(b/write-vec3-le stream (or (get fnormals f) (gu/ortho-normal f)))
Expand All @@ -34,24 +37,26 @@
(b/write-vec3-le stream c)
(b/write-int16-le stream 0))
stream))

(defn read-stl
"Reads faces from binary STL inputstream and adds them to given (or new) mesh."
([stream]
(read-stl stream (bm/basic-mesh)))
(read-stl stream (bm/basic-mesh)))
([^InputStream stream mesh]
(.read stream #+clj (byte-array 80) #+cljs (make-array 80))
(loop [mesh mesh, i (b/read-int32-le stream)]
(if (pos? i)
(let [_ (b/read-vec3-le stream)
a (vec3 (b/read-vec3-le stream))
b (vec3 (b/read-vec3-le stream))
c (vec3 (b/read-vec3-le stream))
_ (b/read-int16-le stream)]
(recur (g/add-face mesh [a b c]) (dec i)))
mesh))))
(.read stream #?(:clj (byte-array 80) :cljs (make-array 80)))
(loop [mesh mesh, i (b/read-int32-le stream)]
(if (pos? i)
(let [_ (b/read-vec3-le stream)
a (vec3 (b/read-vec3-le stream))
b (vec3 (b/read-vec3-le stream))
c (vec3 (b/read-vec3-le stream))
_ (b/read-int16-le stream)]
(recur (g/add-face mesh [a b c]) (dec i)))
mesh))))
#+END_SRC

** PLY

#+BEGIN_SRC clojure :noweb-ref ply
(defn write-ply
"Writes the given mesh as binary PLY to output stream. For
Expand All @@ -62,7 +67,7 @@
vindex (zipmap vertices (range))
vnormals (g/vertex-normals mesh false)
faces (g/faces mesh)
fhead #+clj (byte-array 1) #+cljs (make-array 1)
^bytes fhead #?(:clj (byte-array 1) :cljs (make-array 1))
write-props (fn [props]
(doseq [p props]
(b/write-str-bytes
Expand All @@ -85,28 +90,32 @@
(when (seq vnormals)
(b/write-vec3-le stream (get vnormals v))))
(doseq [f (g/faces mesh)]
(#+clj aset-byte #+cljs aset fhead 0 (byte (count f)))
(aset fhead 0 (byte (count f)))
(.write stream fhead)
(write-vindex f))
stream))
#+END_SRC

** TODO OBJ
- Note taken on [2015-03-15 Sun 01:49] \\
update to use protocols

#+BEGIN_SRC clojure :noweb-ref obj
(defn write-obj
[^OutputStream stream {:keys [vertices vnormals faces]}]
(let [vertices (keys vertices)
has-vnormals? (not (nil? (seq vnormals)))
fmt-fn (fn [prefix]
,#+clj (let [ff (str "%1." *precision* "f ")
ff (str prefix " " ff ff ff "\n")]
#(format ff (double %1) (double %2) (double %3)))
,#+cljs #(str
prefix " "
(.toFixed (js/Number. %1) *precision*) " "
(.toFixed (js/Number. %2) *precision*) " "
(.toFixed (js/Number. %3) *precision*) "\n"))
#?(:clj
(let [ff (str "%1." *precision* "f ")
ff (str prefix " " ff ff ff "\n")]
#(format ff (double %1) (double %2) (double %3)))
:cljs
#(str
prefix " "
(.toFixed (js/Number. %1) *precision*) " "
(.toFixed (js/Number. %2) *precision*) " "
(.toFixed (js/Number. %3) *precision*) "\n")))
fmt-vertex (fmt-fn "v")
fmt-vnormal (fmt-fn "vn")
fmt-fvert (if has-vnormals? #(str % "//" %2 " ") #(str % " "))
Expand All @@ -133,19 +142,23 @@
(fmt-face (map #(inc (get vindex %)) fverts)))))
stream))
#+END_SRC

** OFF

#+BEGIN_SRC clojure :noweb-ref off
(defn write-off
[^OutputStream stream mesh]
(let [vertices (g/vertices mesh)
faces (g/faces mesh)
fmt-vertex
,#+clj (let [ff (str "%1." *precision* "f ")
ff (str ff ff ff "\n")]
#(format ff (double %1) (double %2) (double %3)))
,#+cljs #(str (.toFixed (js/Number. %1) *precision*) " "
(.toFixed (js/Number. %2) *precision*) " "
(.toFixed (js/Number. %3) *precision*) "\n")
#?(:clj
(let [ff (str "%1." *precision* "f ")
ff (str ff ff ff "\n")]
#(format ff (double %1) (double %2) (double %3)))
:cljs
#(str (.toFixed (js/Number. %1) *precision*) " "
(.toFixed (js/Number. %2) *precision*) " "
(.toFixed (js/Number. %3) *precision*) "\n"))
vindex (zipmap vertices (range))]
(b/write-str-bytes stream "OFF\n")
(b/write-str-bytes stream (str (count vertices) " " (count faces) " 0\n"))
Expand All @@ -155,13 +168,12 @@
(doseq [fverts faces]
(b/write-str-bytes
stream
(->> (concat [(count fverts)] " "
(map #(str (vindex %) " ") fverts)
"\n")
(->> (concat [(count fverts)] " " (map #(str (vindex %) " ") fverts) "\n")
(apply str))))))
#+END_SRC

** Complete namespace definition

#+BEGIN_SRC clojure :tangle ../babel/src/cljx/thi/ng/geom/mesh/io.cljx :noweb yes :mkdirp yes :padline no
(ns thi.ng.geom.mesh.io
(:require
Expand All @@ -171,9 +183,9 @@
[thi.ng.geom.basicmesh :as bm]
[thi.ng.geom.triangle :as t]
[thi.ng.common.data.byteutils :as b])
,#+clj
(:import
[java.io OutputStream InputStream]))
#?(:clj
(:import
[java.io OutputStream InputStream])))

<<config>>

Expand Down
4 changes: 2 additions & 2 deletions geom-meshops/src/meshops.org
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
#+BEGIN_SRC clojure :tangle ../babel/src/cljx/thi/ng/geom/mesh/ops.cljx :noweb yes :mkdirp yes :padline no
(ns thi.ng.geom.mesh.ops
(:require
[thi.ng.common.math.core :as m]
[thi.ng.math.core :as m]
[thi.ng.geom.core :as g]
[thi.ng.geom.core.utils :as gu]
[thi.ng.geom.core.intersect :as isec]
Expand All @@ -134,7 +134,7 @@
[thi.ng.geom.gmesh :as gm]
[thi.ng.geom.spatialtree :as st]
[thi.ng.geom.types.utils :as tu]
[thi.ng.common.data.core :as d]
[thi.ng.dstruct.core :as d]
[clojure.set :as set]))

<<ops>>
Expand Down
6 changes: 3 additions & 3 deletions geom-meshops/src/polyhedra.org
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ returns either a =BasicMesh= or =GMesh= instance.

#+BEGIN_SRC clojure :tangle ../babel/src/cljx/thi/ng/geom/mesh/polyhedra.cljx :noweb yes :mkdirp yes :padline no
(ns thi.ng.geom.mesh.polyhedra
,#+cljs (:require-macros [thi.ng.macromath.core :as mm])
#?(:cljs (:require-macros [thi.ng.math.macros :as mm]))
(:require
[thi.ng.geom.core :as g]
[thi.ng.geom.core.vector :as v :refer [vec3]]
[thi.ng.geom.basicmesh :as bm]
[thi.ng.geom.gmesh :as gm]
[thi.ng.common.math.core :as m :refer [PHI PI SQRT2 SQRT3]]
,#+clj [thi.ng.macromath.core :as mm]))
[thi.ng.math.core :as m :refer [PHI PI SQRT2 SQRT3]]
#?(:clj [thi.ng.math.macros :as mm])))

<<polyhedra>>
#+END_SRC
6 changes: 3 additions & 3 deletions geom-meshops/src/slicing.org
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@
[thi.ng.geom.mesh.ops :as ops]
[thi.ng.geom.types.utils :as tu]
[clojure.java.io :as io]
[thi.ng.common.math.core :as m]
[thi.ng.common.data.core :as d]
[thi.ng.math.core :as m]
[thi.ng.dstruct.core :as d]
[thi.ng.common.data.intervaltree :as it]
[thi.ng.macromath.core :as mm])
[thi.ng.math.macros :as mm])
(:import
(java.awt.image BufferedImage)
(java.awt Graphics2D RenderingHints Color Font GradientPaint)
Expand Down
10 changes: 5 additions & 5 deletions geom-meshops/src/subdivision.org
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Based on reference: [[https://en.wikipedia.org/wiki/Catmull%25E2%2580%2593Clark_
centroids as values."
[faces]
(->> faces
,#+cljs (seq)
#?(:cljs (seq))
(r/map (fn [f] [f (gu/centroid f)]))
(fold-into-map)))

Expand Down Expand Up @@ -113,7 +113,7 @@ Based on reference: [[https://en.wikipedia.org/wiki/Catmull%25E2%2580%2593Clark_
[{:keys [faces edges] :as m}]
(let [e-points (ds-edge-midpoints (keys edges))]
(->> faces
,#+cljs (seq)
#?(:cljs (seq))
(r/map (fn [f] [f (ds-face-points* f e-points)]))
(fold-into-map))))

Expand Down Expand Up @@ -141,7 +141,7 @@ Based on reference: [[https://en.wikipedia.org/wiki/Catmull%25E2%2580%2593Clark_
(let [vn (gm/vertex-neighbors* mesh v)]
(if (< 2 (count vn))
(->> vn
,#+cljs (seq)
#?(:cljs (seq))
(r/map
(fn [n]
(let [f1 (f-points (some #(if (= n (:prev %)) (:f %)) v-faces))
Expand Down Expand Up @@ -229,7 +229,7 @@ you're not sure your mesh contains only triangles, pass it through
([mesh omega]
(let [e-points (bf-edge-points (:edges mesh) omega)]
(->> (g/faces mesh)
,#+cljs (seq)
#?(:cljs (seq))
(r/mapcat
(fn [f] (bf-faces-from-edge-points e-points f)))
(g/into (g/clear* mesh))))))
Expand All @@ -245,7 +245,7 @@ you're not sure your mesh contains only triangles, pass it through
[thi.ng.geom.core.vector :as v :refer [vec3]]
[thi.ng.geom.gmesh :as gm]
[thi.ng.geom.triangle :as t]
[thi.ng.common.data.core :as d]
[thi.ng.dstruct.core :as d]
[thi.ng.common.error :as err]
[clojure.core.reducers :as r]))

Expand Down

0 comments on commit 127d83b

Please sign in to comment.