;;; DOC: 
;;; - put "data" in index.
;;; - document with-local-viewables carefully (see comment above it in patch-8)
;;; - unify and document compound picture dialogs.
;;; - fft is orthonormalized

;;; viewable-matrix: dot-product on viewable-matrix should check that lengths are the same!

;;; array-ops: Mul/add/div/sub on number/array should check for 0.0 or 1.0.
;;; Then can get rid of checks in viewable-matrix ops (patch-4)!

;;;; BAD DEPENDENCIES:
;;; gaussian-noise depends on check-probability
;;; matrix-inverse requires svd

;;;; TODO:
;;; fix error message in apply-filter/expand-filter to use ~S
;;; put gamma back in grays (useful for hardcopy)
;;; port QMF's

--------------------------------------------------------------------------
BUGS:

Top-level software question/confusion: Should we 1) continue adding to
generic-ops.lisp, getting rid of redundant code in imops,
discrete-functions, etc.  OR, 2) should we make the imops call C code
directly (fixing them to be floating point).  (I don't like the idea
of assuming that the data slot exists and calling the method
on it, the latter is more efficient, and I think images will always be
floats - EPS.)  The other question is whether we will ever extend to
allow multi-dimensional images.  There is lots of code (esp. display
code) that depends on them being 2D.  It seems silly to allow them to
have arbitrary dimensionality: then they're no different than arrays.

1D vs. 2D images: Get rid of one-d-image class altogether: They're no
longer necessary (used to be needed to dispatch the display code) (see
initialize-instance for filters for how to get display working
properly). Also get rid of one-d-image-pair, one-d-complex-image.
Crop on true vect-n image produeces 1xn result!  Either 1)
allow user to create any shape 1D image (n, nx1, 1xn) and provide a
"reshape" method to displace an array of a different shape (problem:
multiple pointers to same allocated array space will break the orphan
memory-management!) or 2) Coerce 1D images (including slices) into a
standard shape (n-vector), and modify functions (eg paste) to treat
them as if they are a particular shape....  I prefer the latter -EPS

Sort out foreground/background issues.  Screen background is used to
clear panes, and as background of drawings (should these have their
own background?).  Screen FOREGROUND is used for default line-drawing
color.  Changing screen colors should uptdate all pictures (eg
pasteups and graph flipbooks).

- surface-plot: get rid of z-size.  Use z-scale instead.  Provide
:origin (point camera looks at) This is important for displaying
flipbooks of surface-plots.

**** Flipbook bug: If you modify a sub-image of a sequence and have a
flipbook of grays displayed, the corresponding sub-picture will be
re-scaled, even if independent-parmaters is nil.  THis is hard to fix,
but pretty broken.

history is busted for image-sequences.

vertical format pasteups of image-pairs (e.g., 32x32 ramps) screwed up.

Flipbook/overlay dialogs should indicate current frame

Flipbook of bitmap/gray shouldn't clear pane when single-stepping.
Should we specialize the method on the sub-picture type?
What's the difference?  Speed is not an issue when single-stepping. -DH

Use (similar) in matrix-ops result arguments, so that allocated
arrays generate allocated arrays.
	
load-image screws up on getting history out of the detfile.  Should
probably not bother, although save-image should write it!

copy-swapped-32bit breaks on servers with swapped bytes (e.g.
DECstations).  need to check the Xbyteorder AND the Xbitorder of the
Ximage.  GROSS.

make-slice on pasteup pictures of image-sequences breaks if handed a 
bad x or y coord!

- Check use of color-register code.

Strange color allocation warning: "Can't find or create a color that
matches :COLORMAP"

 Should allow user to set :rgb-bits to '(0 0 0).

We should mark selected pane somehow (draw one-pixel rectangle around
boundary, or put a check-mark in the title bar?)

vector-fields currently ignore arrow-head-length and base-position slots
contour-plots ignore color, and don't use density correctly

zoom doesn't work on flipbooks of bitmaps

Function dialogs shouldn't go away when you click "Execute".

Defaults dialogs should be able to use initarg keywords that do not
correspond to slots (eg. :density in vector-fields)

--------------------------------------------------------------------------
IMPROVEMENTS:

Get rid of REAGAN in the tutorial.

Hesitation in dragging gray images 

pasteups;  Needs a rewrite!
	- should be generalized to work with any type of sub-picture. (eg,
	bitmaps, graphs, etc) To do this, add optional y-offset and
	x-offset parameters to compute-picture so we can have generic
	specification of sub-picture displacement wrt some base position.
	- Don't need horizontal pasteups:  the default display for pairs should
	just be pasteup, and then the slots can be filled
	automatically from reset-picture-defaults!
        - should be default display type for one-d-image-pairs as side
        by side graphs (currently, we are using flipbooks).
        - Provide position-messages

slice: lose the slice class; result is a 1-d image anyway.

flipbooks: should be able to make any subset of the picture parameters
independent.  Could do this by making the independent-parameters slot
of the flipbook hold a list of keywords.  In dialogs, provide a
checkbox with each sub-picture parameter.

compound pictures (flipbook/overlay/pasteup): unify treatment of
independent-parameters.  in particular, do we need
reset-sub-picture-defaults (in overlay), or can we just use
reset-compound-picture-defaults (in flipbook).

Why don't discrete-functions inherit from one-d-images?  Seems like
we'd get a lot of methods for free that way....

Make default and function dialogs come up above or below control
panel, depending on its location (see code for picture parameters).

** Get rid of *screen-list*: make an instances slot in the screen object.

Make keyword args explicit for all top-level (exported) fucntions.

- replace calls to viewable-list with frame or (aref data) to avoid consing

- make gauss-out recursive.

write internal32-blah  functions.

- define apply-filter on vectors and on arrays.  Can we make it 
simpler/cleaner?

Screens: set gray-shades, etc, via reinitialize-instance rather than
setf.  To do this we have to 1) change the clos-extensions code to
handle non-slot initargs, 2) get rid of setf methods, 3) change dialog
code to have it call reinitialize-instance by default.

matrix: 
	- Should probably replace as much of this code as possible
	with linpack code, which is public domain and well-maintained.
	- Should not pass non-static arrays to C code (either do
	  without-interrupts, or copy to static)
	- Some internal-* routines are in lisp, should be in C
	- Speed up C code in matrix.c
	- Let user know if inverse funtion returns a pseudo-inverse
          by returning :singular as second value.
	- Clean up matrix inverse:
	   tmp matrices should be keywords, so user can avoid consing
	   error check that matrix is tall and skinny (or that 
	   dimensions-limit <= row-dim).

- write flip-x, flip-y, flip-xy, resample and rotate on arrays.
*	- put check-size into all array-ops.
*	- take check-size out of all who call array-ops 
          (e.g., imops, discrete-fnctn ops)

- write expand-filter for sequences.  Add edge handlers (note that
these can be done more easily than in space, since we can pad an image
sequence without duplicating data -- just stick sub-images into the list)
- apply-filter on images and df's should call these.
- filters should probably use static arrays.
- filters really shouldn't include grid and edge-handler.   these could just be
  args to the apply-filter/expand-filter functions.  But then a filter
  is just an array: why not just use an image!
- optional ORIGIN argument to specify center tap of filter.
- make hex-filters a module.
- fix sep filters to: make y-filter a y-filter? (copy); work if passed
  a list and a sep filter (curently makes the second a non-sep filter); 
  collapse out extra dimensions? (eg, get rid of dimensions 1);

Documentation:
 - make lmeth and lfun macros work as in Steele. See lispdoc.tex.
 - Tell user how to rebind mouse (setq *default-pane-interests* ...)

- Discrete-functions, and point-operation: add interpolator
keyword/slot.  Write C code to use the proper interpolator (cubic or
linear).  Same for periodic-point-operation.

- write internal1-paste in C for faster display of bit-images.  Also
  write all comparison ops in C.
- Write masked versions of imops: special variable *bit-mask* holds a
  bit-image and allows operations to be performed on selected
  subregions!  Write if., when. etc.
- Set of macros to do when., if.: use special variable mask.

Allow a "try again" option for the "out of static heap space" 
error (ie. allow user to destroy an image)

Lucid is not well protected against overgrowing the static space.
Add stuff to heap-status that returns total amount of static space
used by heaps.  Check in expand-heap to see if this is geting close to
the growth-limit.

fileio: raw-files.lisp containing  data writers/readers (with skip-bytes)
        dat-files.lisp containing datfile stuff
        generic-files.lisp for reading general CLOS objects.

Use lucid::read-array (hopefully faster) in fileio code.

Provide method to restart dead mouse process (code in
/u/eero/obvius/revive-mouse-process.lisp doesn't work).

Check set-not-current and set-result for excess dispatching/consing.

- re-dither zoomed bitmaps.

- Should use lucid:advise to alter the "set" function.

dialogs: Needs a major rewrite, especially the function dialogs
        - Make the update function a method on the dlg and the object.
        - On clicking "Apply", slot dialog should run reinitialize-instance 
          by default.
	- optional args: should be able to have these depend on previous args!
	- Pass optional args if there are keywords specified. (eg hardcopy)
	- Function dialogs: mechanism to adjust defautls (use advice)?
	- Info dialog (in place of describe-viewable mouse binding):
	pop up dialog with last mod time (use universal-time for current slot), 
	standard info (like dims) and stuff on info-list.  Also, we
	need a "statistics" info window (eg, pop up statistical info
	on an image), and a "print-values" readout window that is
	scrollable!

** Generic drawing frob (collects up any drawing commands, with graphic
   context info).  Knows how to "render" itself to various output
   devices, clipping to dimensions ...  Use this to replace the more
   specialized vf-frob, graph-frob, and sp-frob.  Get rid of all
   references to lispview in drawing.lisp, graph.lisp,
   surface-plot.lisp, contour-plot.lisp, overlay.lisp.

** Generic graphic-context (i.e., extend to work with
   postscript-printer and any other output device).  For drawings (vf,
   sp, graph) this needs system-independent foreground/background
   colors.  Provide a "with-graphics-context" macro (like that for lispview)
   Probably also needs a generic font object (this is a pain): abstract
   out text-sizing stuff (need a routine to compute height/width of a string
   in a given font.)
   Should be able to get rid of lispview:: calls in overlay, drawing,
   surface-plot, and graph: this code should be window-system independent!
   Use this stuff in graphs: line-widths should work in hardcopy.  
   - abstract out colors in a system-indepedent way (use keywords).
   Make full use of color-register.lisp code

Hardcopy:
   Put date/name/history in file.  
   Document x-scale and y-scale better these are necessary to 1)
   change aspect ratio, 2) use postscript resolution-independent scaling.
   Units in inches, or points (what is default PostScript unit)?
   Provide feedback: pop up emacs status buffer if emacs is running.  
   Don't load user's profile when executing.  

* File i/o.  Generic save-viewable code (check in CMU utilities).
  save history in descriptor files!  Save info-list and display-type too,
  Reading data file of length 0 wedges OBVIUS - This should be protected. 
  viewable-type, etc to file. Other formats?  Add byte-order args to
  read/write-float-array. Provide load-raw-image which takes
  :element-type keyword, guesses size (and asks for user
  confirmation), and takes :header-size (in bytes) to skip over any
  header info.
*       - Finish writing constructor functions on any type of object (e.g., use
	for list-from-array).  Eval'ing a constructor should make a copy of the 
	object.  Use this to save datfiles in a generic way!  Also will need a 
	"print-readably" function that takes s-expressions and prints (to any stream)
	something that the reader would turn into that form.  
	Ex: (print-readably (list 'a 'b)) --> "'(a b)". 

Can we put the :destroyed keyword into the current slot?

destroying pictures and frobs is inefficient:
	currently the frob data is in static-arrays-of gray
	destroy on gray frees these arrays and then calls destroy on the frob
	destroy on the frob frees them again.

list-ops: 
	Make mean and variance work with lists of anything.
	Make shuffle handle indices (also, shuffle in array-ops).

** provide set-defaults

- gray-dither should be a (possibley class-allocated) slot in gray
(called dither-p), NOT in the screen.

** Can we speed up with-result?  We're losing bigtime at the moment:
either due to set-not-current or set-history....

** EMacs: Fix C-c . to use  the TAGS table.

- in calls to defclass: add doc-strings, :auto :default-initargs, types.

- Getp should list user-settable parmaeters separately from non-settable.

- would be nice if you could pass :self as :-> arg for unary ops.
Then you could do things like (mul (add im1 im2) num :-> :self)

Need to be able to draw lines into pictures and then pull them back.

Need :ignore-zeros arg in skew and kurtosis.

- Should draw-lines work for float coordinate arrays? (it is 30% slower, but
  allows us to zoom without calling compute-picture again...)  Hard call.

Do compile-load, obv-compile-load correctly, using the
lcl:*load-source-pathname-types* variable.  (see
~eero/lisp-init.lisp).

Laplacian pyramids should require two filters (as a default, they are
	the same).  One is used to build the gaussian pyramid.  The other is
	used to create the laplacian levels AND to collapse the pyramid (a
	Laplacian pyramid reconstructs perfectly for ANY choice of these two
	filters, no matter how awful the filters are).  Also, laplacian
	pyramids currently build one more level than asked for.  If you ask
	for a one level LP, you should get something with a single laplacian
	level (the size of the original image), and a (smaller) gaussian
	image.

Check gaussian-pyramid for one-d-images.  Make laplacian-pyramid work
	for one-d-images.  Check one-d-qmf-pyramids.  Display
	one-d-pyramids as multigraphs (ugh!), make a new class.

Make-slice should just call crop.

We need a bitmap/pyramid present method (for dithering pyramids)

Write bit-pyramids for thresholding pyramids and for multiplying by masks.

** Should allow user to initialize defaults (make a class slot with the default-defaults!)

** Overlay title-bars?
** handle destruction of one overlayed viewale (remove from overlay).  
** Want to be able to overlay any graph on any other graph, regardless of
   what the underlying viewable is.  Currently, overlays are very limited.
   E.g., discrete-functions must have the same origin, increment, and 
   size to be overlayed.  This is hard because transformation from vbl-data 
   to graph depends on lots of things including zoom parameter and size of
   data vector.


Write circular-shift on general arrays/lists.

List-ops are inefficient: should loop over list, instead of using nth.

Normalize on vectors (in matrix.lisp) should call C code.

Outer-product on viewable-sequences should check if the sequences are
eq (a common case) and then only do half as many computations.

Modify viewable-matrix ops so that they have the same default keywords
as the ops on the sub-viewables.  These keep becoming inconsistent!!
We probably want to write apply-unary-vm-ops that can operate on the
keyword list.

mouse: - interactive-crop currently for images ONLY. (i.e. a
	picture-dependent interest), but we should write it for sequences too.
	- write interactive-paste
        - drag code should operate with methods
	- picture-dependent interests: should be done with methods! 
          (allow inheritance etc)
	- lengthen/shorten bindings for vector fields. (boost-contrast)
	- Get rid of set-selected-pane in many mouse clicks (cycle, 
	- Crop should echo the command to the listener.
	- Provide method to restart dead mouse process.

** More space between graph labels
-  Graphs: how can we allow the user to specify a graph-coord/pixel
   relationship?  This is messy.  Slot dependencies: modifying vbl, should reset graph
   :x-range :y-range, etc.  What to do about log of negative numbers?

** all funcs could check to see if args are destroyed...

*memory: 
	- The garbage-collector should respect the event queue!!  UGGGH.
	- allocate-array should take :initial-contents

viewable:
	Don't bind result name until after computation (in
	with-result macro) so that if there's an error, we don't
	clobber the old symbol.  This is hard.

Add a :replicate keyword to the upsample function.

Write check-size on pyramids to compare tree structure.  Currently, it
	just craps out with a lisp error which would be pretty confusing to
	the user.

--------------------------------------------------------------------------
NEW FEATURES:

- Port QMF pyramids and steerable pyrarmids 

Write a mixed-radix dft (slow).

** Add linear-combination method. (a * im1 + b * im2 + c)

- Write interleave method (takes an image-matrix and interleaves the
data arrays).

- Add median filtering code.

Add general affine-warp function (like warp, but requires no vector
field).  Rewrite rotate (defaults to pi/2) and resample methods.

** slices at arbitrary angles.  Also circular slices!

** Provide (impulse-respons filt), and (power-spectrum filter)

** write SNR function.

** Write "inverse" method for dfs (see /u/eero/lisp/noise/anti-coring.lisp).
Must check for monotonicity.

- Add EJ's multivariate gaussian-noise function, relies on matrix and on 
row operations.

User interface: buttons/menues on pane.  Get rid of pictures in Parametes menu.

Add menu of loadable modules

** Put Emacs texinfo mode stuff into documentation, so that it can be
used to automatically generate Emacs info files (se message from Mike
Clarkson)

- describe-viewable mouse binding should print into a window, not the listener.
  same with print-values.
- print-values should take a scale parameter (default computed automatically).
  maybe also a :max-field-length arg.

- add Kalman filter?

-  New picture type: surface-plot-movie.  Like surface plot, but allow
   user to generate a sequence of views (specify num-frames, and either
   a list of parameter lists (keywords) or a function to generate them.

-  New picture type: point cloud.  Perspective projection of a set of
   points, with optional axes.   Allow INTERACTIVE user rotation.
   I started writing this in ~heeger/lisp/obvius/spin.lisp.  -DH

-  New picture and viewable types: viewable contains range and intensity
   (texture) image or function.  Picture displays texture-mapped 3D
   surface (like surface plot).  As with surface-plot-movie, should
   also allow user to generate movies of this....  [/u/eero/obvius/range-maps.lisp]

Write a fast version of make-fractal using pyramids.

Write sum-of, product-of for images. Maybe just write geometric-mean!

Rewrite loop-over-image-pixels, and loop-over-image-positions using
def-loop-method.  [POTENTIALLY HARD]


- numerical magnifier.

*Write array-ops for bit and (unsigned-byte arrays).  
	For bit arrays, we can call the commonlisp functions (bit-ior, etc). 

Associate with each image a very low resolution icon (e.g. 32x32
	or 64x64) so that you can browse through a whole mess of images a page
	at a time. (E.g. the images you are currently working with, or a set
	of stored images).  At 32x32 you could look at 64 baby images in a 256
	x 256 window.

** Write "run-in-background" function to execute code in background
   (only allow one of these to run at a time).  Perhaps allow a second
   i/o stream, sot that user can continue to use the *lisp* buffer
   without makeing a mess?  Use this for displaying movies....

- Interactive paste command (how should this work?)
  args to paste method should be :x, :y

* Keep list of all viewables in a class-allocated slot called
  "instances".  When user calls ogc, should list these, allowing user
  to display them or inspect them

*  show shrunken image for panes (render with small zoom!)

** Catch keypresses in panes -- pass back to Emacs (too slow?)

;- device hierarchy:
;    device / monitor (output) / screen (pane-list) / cmap-screen (cmap)
;- monitor has "inverse-lut" to map floats [0,1] onto its DISCRETE set of
;  output values.  Operation is assumed smooth (monitonic, too?)
;- cmap-screen has additional gray-lut and color-lut.  this is a
;  discrete-to-discrete mapping (and may include crude gamma-correction), and
;  will use the float-into-8bit-lut fn.
;- split float-to-8bit-lut into two fns, but also keep the combined one.
;- get rid of gamma slot in grays (no more individual gamma).

--------------------------------------------------------------------------
DOC: 

Document compile-if-necessary, especially :compiler-optimizations and
:umask.

Use cmu's psgrapher (in /v/pkg/cmu-cl) to create plots of viewable and
picture inheritance?  (actually want these in TeX picture mode, not
PostScript, since not everybody has psfig).

* viewables - motivate display & memory purposes.  Destructive mod.
Atomic V. compound

** mention psfig in postscript section...

- Explain what window-system/window-manager stuff (eg OpenWindows
stuff in .Xdefaults, window names in .twmrc) affects obvius.

- start an obvius-FAQ list.

- EMACS:  fix keymap for choosing definition.
 
- Explain how to add new ops (generic-ops?, user-macros, imops, matrices)
