1 /* PaniniGeneral.h		15Jan2010 TKS
2 
3 Copyright (c) 2010, Thomas K Sharpless
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8     * Redistributions of source code must retain the above copyright
9       notice, this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above copyright
11       notice, this list of conditions and the following disclaimer in the
12       documentation and/or other materials provided with the distribution.
13     * Neither the name of the <organization> nor the
14       names of its contributors may be used to endorse or promote products
15       derived from this software without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 
29 This is the reference implementation of the General Pannini
30 Projection, an elaboration of the basic Pannini projection
31 discovered by Bruno Postle and Thomas Sharpless in December
32 2008 in paintings by Gian Paolo Pannini (1691-1765).
33 
34 It is a parameterized mapping between sphere and plane,
35 that gives synthetic perspective views on the plane when
36 the sphere holds a linear projection of the scene.  Sphere
37 coordinates (phi, theta) are equirectangular: longitude and
38 latitude angles, in radians, relative to a point on the equator.
39 Plane coordinates (h, v) are relative to the image of the same
40 point, typically but not necessarily the center point of
41 the view.  The plane y coordinate is negative upward, as is
42 typical in image processing software.
43 
44 There are 3 parameters:
45   d [0:infinity) controls horizontal compression
46   t [-1:1] controls vertical compression at top
47   b [-1:1] controls vertical compression at bottom
48 
49 There are functions to map cooridnates in either direction
50 and one to compute the maximum feasible field of view of the
51 plane image, given a d value and the projection angle limit
52 of your display system.
53 
54 Angles passed to and returned by panini_general_maxVAs()
55 are max view angles (half-FOVs) in radians.
56 
57 All 3 functions return an integer: 0: failure, 1: OK.
58 Computed coordinates and FOVs are returned in arguments
59 passed by address.
60 
61 */
62 int panini_general_toPlane	( double phi, double theta,
63 							  double* h,  double* v,
64 							  double d, double t, double b
65 							 );
66 int panini_general_toSphere	( double* phi, double* theta,
67 							  double  h,  double  v,
68 							  double d, double t, double b
69 							 );
70 int panini_general_maxVAs	( double d,
71 							  double maxProj,
72 							  double * maxView
73 							 );
74