Mercurial > cortex
changeset 182:f2552d61e8df
cleaned up sense-utils some more, tested system again.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 04 Feb 2012 07:44:48 -0700 |
parents | 0f1c7921d967 |
children | 446b115bddc2 |
files | org/sense-util.org |
diffstat | 1 files changed, 32 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
1.1 --- a/org/sense-util.org Sat Feb 04 07:31:08 2012 -0700 1.2 +++ b/org/sense-util.org Sat Feb 04 07:44:48 2012 -0700 1.3 @@ -6,16 +6,21 @@ 1.4 #+SETUPFILE: ../../aurellem/org/setup.org 1.5 #+INCLUDE: ../../aurellem/org/level-0.org 1.6 1.7 - 1.8 #+name: sense-util 1.9 #+begin_src clojure 1.10 -(ns cortex.sense) 1.11 -(cortex.import/mega-import-jme3) 1.12 -(import ij.process.ImageProcessor) 1.13 -(import java.awt.image.BufferedImage) 1.14 -(use 'cortex.util) 1.15 -(use 'cortex.world) 1.16 -(import jme3tools.converters.ImageToAwt) 1.17 +(ns cortex.sense 1.18 + "Here are functions usefull in the construction of two or more 1.19 + senses/effectors." 1.20 + {:author "Robert McInytre"} 1.21 + (:use (cortex world util)) 1.22 + (:import ij.process.ImageProcessor) 1.23 + (:import jme3tools.converters.ImageToAwt) 1.24 + (:import java.awt.image.BufferedImage) 1.25 + (:import com.jme3.collision.CollisionResults) 1.26 + (:import com.jme3.bounding.BoundingBox) 1.27 + (:import (com.jme3.scene Node Spatial)) 1.28 + (:import com.jme3.scene.control.AbstractControl) 1.29 + (:import (com.jme3.math Quaternion Vector3f))) 1.30 1.31 (defn meta-data 1.32 "Get the meta-data for a node created with blender." 1.33 @@ -25,8 +30,7 @@ 1.34 nil)) 1.35 1.36 (defn closest-node 1.37 - "Return the object in creature which is closest to the given node." 1.38 - ;;dylan"The closest object in creature to the given node." 1.39 + "Return the node in creature which is closest to the given node." 1.40 [#^Node creature #^Node eye] 1.41 (loop [radius (float 0.01)] 1.42 (let [results (CollisionResults.)] 1.43 @@ -71,7 +75,8 @@ 1.44 1.45 (defn filter-pixels 1.46 "List the coordinates of all pixels matching pred, within the bounds 1.47 - provided. Bounds -> [x0 y0 width height]" 1.48 + provided. 1.49 + bounds -> [x0 y0 width height]" 1.50 {:author "Dylan Holmes"} 1.51 ([pred #^BufferedImage image] 1.52 (filter-pixels pred image [0 0 (.getWidth image) (.getHeight image)])) 1.53 @@ -119,7 +124,7 @@ 1.54 (/ (reduce + coll) (count coll))) 1.55 1.56 (defn collapse-1d 1.57 - "One dimensional analogue of collapse" 1.58 + "One dimensional analogue of collapse." 1.59 [center line] 1.60 (let [length (count line) 1.61 num-above (count (filter (partial < center) line)) 1.62 @@ -129,7 +134,7 @@ 1.63 1.64 (defn collapse 1.65 "Take a set of pairs of integers and collapse them into a 1.66 - contigous bitmap." 1.67 + contigous bitmap with no \"holes\"." 1.68 [points] 1.69 (if (empty? points) [] 1.70 (let 1.71 @@ -157,30 +162,33 @@ 1.72 (map first row)) 1.73 (map second row))) 1.74 (partition-by second (sort-by second flattened)))) 1.75 - relocate 1.76 + relocated 1.77 (let [min-x (apply min (map first squeezed)) 1.78 min-y (apply min (map second squeezed))] 1.79 (map (fn [[x y]] 1.80 [(- x min-x) 1.81 (- y min-y)]) 1.82 squeezed))] 1.83 - relocate))) 1.84 + relocated))) 1.85 1.86 (defn world-to-local 1.87 - "Convert the world coordinates into coordinates relative to the 1.88 + "Convert the world coordinates into coordinates relative to the 1.89 object (i.e. local coordinates), taking into account the rotation 1.90 of object." 1.91 - [#^Spatial object world-coordinate] 1.92 - (.worldToLocal object world-coordinate nil)) 1.93 + [#^Spatial object world-coordinate] 1.94 + (.worldToLocal object world-coordinate nil)) 1.95 1.96 (defn local-to-world 1.97 - "Convert the local coordinates into coordinates into world relative 1.98 - coordinates" 1.99 - [#^Spatial object local-coordinate] 1.100 - (.localToWorld object local-coordinate nil)) 1.101 + "Convert the local coordinates into world relative coordinates" 1.102 + [#^Spatial object local-coordinate] 1.103 + (.localToWorld object local-coordinate nil)) 1.104 1.105 - 1.106 -(defn sense-nodes [parent-name] 1.107 +(defn sense-nodes 1.108 + "For each sense there is a special blender node whose children are 1.109 + considered markers for an instance of a that sense. This function 1.110 + generates functions to find those children, given the name of the 1.111 + special parent node." 1.112 + [parent-name] 1.113 (fn [#^Node creature] 1.114 (if-let [sense-node (.getChild creature parent-name)] 1.115 (seq (.getChildren sense-node))