// grid.h: definitions for grid data structure
// 15-869, assignment 2: View Transformation
//
// some terminology comes from the paper:
//	Head-Tracked Stereoscopic Display Using Image Warping
//	Leonard McMillan and Gary Bishop
//	Stereoscopic Displays and Virtual Reality Systems II
//	SPIE Proceedings 2409, Feb.  1995. 
//
// Paul Heckbert	28 Sept 1999

#ifndef GRID_H
#define GRID_H

struct Point3 {
    float x, y, z;

    Point3()
	{};
    Point3(float x_, float y_, float z_)
	{x = x_; y = y_; z = z_;};
};				// generic 3-D point

// IMPORTANT:
// for more notes on coordinate systems, read all comments in
// transform_points() and extract_camera() in ivgrid.cxx


struct Gpoint {			// data stored at grid point

    float gz;			// depth in grid space
				// McMillan calls this delta

    unsigned char r, g, b;	// color
};

struct Grid_data {		// grid of depth and color info

    int nx, ny;			// number of rows and columns

    Gpoint **grid;		// two dimensional array of zrgb points
				// index it like this: grid[gy][gx],
				//   where 0<=gx<nx, 0<=gy<ny

    // the following four vectors are in world space
    // (see McMillan's paper)
    Point3 cam;   // position of camera (a.k.a. cdot)
    Point3 ovec;  // vector from camera to corner of projection plane
    Point3 uvec;  // vector in grid x direction
    Point3 vvec;  // vector in grid y direction

    Grid_data(int nx_, int ny_);// allocate a grid of nx_ by ny_ points
    ~Grid_data();

    int inventor_read_and_resample(char *filename);
	// read Open Inventor file and resample it into a grid
	// returns 1 if success, 0 if failure (e.g. bad filename)

    void print();		// print the grid
};

#endif
