Update domain name to kpe.io
[cl-photo.git] / tables.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          tables.lisp
6 ;;;; Purpose:       Returns tables of values
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  April 2005
9 ;;;;
10 ;;;; $Id: dof.lisp 10436 2005-04-21 15:36:01Z kevin $
11 ;;;;
12 ;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; cl-photo users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the GNU General Public License v2
16 ;;;; (http://www.gnu.org/licenses/gpl.html)
17 ;;;;
18 ;;;; *************************************************************************
19
20 (in-package #:photo)
21
22 (defparameter +f-stops+ '(1.4 2.0 2.8 4.0 5.6 8 11 16 22 32))
23 (defparameter +focal-lengths+ '(12 24 35 50 70 85 105 135 200 300 400 500 600))
24 (defparameter +distances-feet+ '(0.5 1 3 8 15 25 50 100 200))
25
26 (defun hyperfocal-table (focal-length coc &key (units :feet) (output *standard-output*))
27   (loop for f-stop in +f-stops+
28         do (format output "~4,1F ~,1F~%"
29                    f-stop (hyperfocal focal-length f-stop coc :units units)))
30   (values))
31
32 (defun aov-table (imager &key (output *standard-output*) (projection :rectilinear))
33   (let ((imager-dim (etypecase imager
34                       (cons imager)
35                       (symbol (imager-dimensions imager)))))
36     (format output "~5A ~5A ~5A ~5A~%" "FOCAL" "AOV-W" "AOV-H" "AOV-D")
37     (loop for focal-length in +focal-lengths+
38           do (let ((aov (multiple-value-list (aov focal-length (car imager-dim) (cdr imager-dim)
39                                                   :projection projection))))
40                (format output "~5D ~5,1F ~5,1F ~5,1F~%"
41                        focal-length (nth 0 aov) (nth 1 aov) (nth 2 aov)))))
42   (values))
43
44 (defun fov-table (imager focal-length
45                          &key (output *standard-output*) (projection :rectilinear)
46                          (units :feet))
47   (let ((imager-dim (etypecase imager
48                       (cons imager)
49                       (symbol (imager-dimensions imager))))
50         (distances (mapcar 'feet->mm +distances-feet+)))
51     (format output "~8A  ~6A ~6A ~6A ~6A~%" "DISTANCE" "WIDTH" "HEIGHT" "DIAGON" "MAG")
52     (loop for distance in distances
53           do (let ((fov (multiple-value-list (fov focal-length
54                                                   (car imager-dim) (cdr imager-dim)
55                                                   distance
56                                                   :projection projection))))
57                (format output "~8F: ~6F ~6F ~6F ~6F~%"
58                        (mm->length distance units)
59                        (nth 0 fov) (nth 1 fov) (nth 2 fov) (nth 3 fov)))))
60   (values))
61
62 (defun dof-table (focal-length coc &key (output *standard-output*) (units :feet))
63   (let ((distances (mapcar (lambda (mm) (mm->length mm units))
64                            (mapcar 'feet->mm +distances-feet+))))
65     (format output "~&~5A  " "FStop")
66     (dolist (distance distances)
67       (format output " ~10F " distance))
68     (format output "~%")
69     (dolist (f-stop +f-stops+)
70       (format output "~5,1F  " f-stop)
71       (dolist (distance distances)
72         (multiple-value-bind (near far dof mag blur) (dof focal-length f-stop distance coc
73                                                           :units units)
74           (declare (ignorable dof mag blur))
75           (when (minusp far) (setq far "Inf  "))
76           (format output "~5F/~5F " near far)))
77       (format output "~%")))
78   (values))