// ------------------------------------------------------------------------ // This program is complementary material for the book: // // Frank Nielsen // // Visual Computing: Geometry, Graphics, and Vision // // ISBN: 1-58450-427-7 // // Charles River Media, Inc. // // // All programs are available at http://www.charlesriver.com/visualcomputing/ // // You may use this program for ACADEMIC and PERSONAL purposes ONLY. // // // The use of this program in a commercial product requires EXPLICITLY // written permission from the author. The author is NOT responsible or // liable for damage or loss that may be caused by the use of this program. // // Copyright (c) 2005. Frank Nielsen. All rights reserved. // ------------------------------------------------------------------------ // ------------------------------------------------------------------------ // File: sphericalmapping.cpp // // Description: Map a Cartesian image to a theta phi spherical image // (provide field of view) // ------------------------------------------------------------------------ #include "stdafx.h" #include #include #define max(a,b) ((a)>(b) ? (a) : (b)) #define min(a,b) ((a)>(b) ? (b) : (a)) #define max2(a,b) ((a)>(b) ? (a) : (b)) #define min2(a,b) ((a)>(b) ? (b) : (a)) #define max4(a,b,c,d) max2(max2(a,b),max2(c,d)) #define min4(a,b,c,d) min2(min2(a,b),min2(c,d)) #define M_PI 3.1415926 inline void Cartesian2Spherical(double X, double Y, double Z, double &theta, double &phi) { theta=atan2(X,Z); phi=atan2(Y,sqrt(X*X+Z*Z)); } void ImgSphere(unsigned char* img, unsigned char * res, int w, int h, double focal) { int i,j; double theta, phi; int x,y,cx,cy; unsigned char r,g,b; double theta1, phi1, theta2, phi2,theta3, phi3,theta4, phi4; double mp,mt,Mt,Mp; int index,indeximg; double X,Y,P,T; cx=w/2; cy=h/2; Cartesian2Spherical((double)(-cx),(double)(0.0),focal, theta1, phi1); Cartesian2Spherical((double)(cx),(double)(0.0),focal, theta2, phi2); Cartesian2Spherical((double)(0.0),(double)(cy),focal, theta3, phi3); Cartesian2Spherical((double)(0.0),(double)(-cy),focal, theta4, phi4); mp=min4(phi1, phi2, phi3, phi4); Mp=max4(phi1, phi2, phi3, phi4); mt=min4(theta1,theta2,theta3,theta4); Mt=max4(theta1,theta2,theta3,theta4); cerr <<"Phi min:"<> w >> h; IN >> maxc; IN.get(dummy1); img=new unsigned char[3*w*h]; IN.read((char *)img, 3*w*h); IN.close(); return img; }