 
 (def image-processing-executor (Executors/newFixedThreadPool 1))
  
-(defn add-tiles-at [memory-tiles [nx ny] affine-stage-to-pixel acquired-images tile-dimensions]
+(defn add-tiles-at [memory-tiles [nx ny] affine-stage-to-pixel acquired-images tile-dimensions
+                    settings]
   (swap! acquired-images conj [nx ny])
   (let [[tile-width tile-height] tile-dimensions]
     (doseq [image (doall (acquire-at (inverse-transform
                                        (Point. (* tile-width nx)
                                                (* tile-height ny))
-                                       affine-stage-to-pixel)))]
+                                       affine-stage-to-pixel)
+                                     settings))]
       (let [indices {:nx nx
                      :ny ny
                      :nz (get-in image [:tags "SliceIndex"])

      (core snapImage)
      (core getTaggedImage)))

(defn acquire-tagged-image-sequence []
  (let [acq-engine (AcquisitionEngine2010. gui)
        settings (-> gui .getAcquisitionEngine .getSequenceSettings
                     engine/convert-settings
                     (assoc :use-autofocus false
                            :frames nil
                            :positions nil
                            :numFrames 0))
        q (engine/run acq-engine settings false)]
    (take-while #(not= % TaggedImageQueue/POISON)
                (repeatedly #(.take q)))))

(defn acquire-processor-sequence []
  (map tagged-image-to-processor (acquire-tagged-image-sequence)))

(def acquire-processor-sequence* (memoize acquire-processor-sequence))

(defn acquire-at
  "Move the stage to position x,y and acquire a multi-dimensional
   sequence of images using the acquisition engine."
  ([x y]
    (acquire-at (Point2D$Double. x y)))
  ([^Point2D$Double stage-pos]
    (let [xy-stage (core getXYStageDevice)]
      (set-xy-position stage-pos)
      (acquire-processor-sequence)
      )))

;; run using acquisitions

;(defn share-positions []
;  (reactive/handle-update positions-atom
;                          (fn [old new]
   
(defn create-acquisition-settings []
  (-> gui .getAcquisitionEngine .getSequenceSettings
      engine/convert-settings
      (assoc :use-autofocus false
             :frames nil
             :positions nil
             :numFrames 0)))
                          

;; SAVE AND LOAD SETTINGS

