-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinhole.h
135 lines (113 loc) · 2.98 KB
/
pinhole.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// pinhole.h
// Pinhole Camera
//
// Created by SHAO Jiuru on 6/16/16.
// Copyright © 2016 UCLA. All rights reserved.
//
#ifndef pinhole_h
#define pinhole_h
#include <assert.h>
#include <iostream>
#include <vector>
#include "matm.h"
using namespace std;
const float TOLERANCE = float(1.0e-04);
enum WALLTYPE {yPos, yNeg, xNeg, xPos, zPos, zNeg};
struct Point
{
Point(float x0, float y0, float z0) { x = x0; y = y0; z = z0; }
Point& operator = (Point other);
bool operator == (Point other);
float x;
float y;
float z;
void print() {
cout << "p.x: " << x << endl;
cout << "p.y: " << y << endl;
cout << "p.z: " << z << endl;
cout << endl;
}
};
typedef Point Vec3;
struct Pixel
{
Pixel(int r, int g, int b) {R = r; G = g; B = b;}
Pixel() {}
Pixel& operator = (Pixel other);
unsigned char R;
unsigned char G;
unsigned char B;
//int a;
void print() const {
cout << "p.R: " << int(R) << endl;
cout << "p.G: " << int(G) << endl;
cout << "p.B: " << int(B) << endl;
}
};
const Pixel grey_pixel = Pixel(128, 128, 128);
const Point origin = Point(0.0, 0.0, 0.0);
struct Wall
{
Wall(int l, int h, int n, float rl, float rh, WALLTYPE t);
// Wall: Ax + By + Cz = D
float A, B, C;
int D;
int xDim;
int yDim;
int zDim;
int near;
// resolution of the picture
float length;
float height;
WALLTYPE type;
vector<Pixel> pixels;
// detect if a given point is on the wall
bool isOnWall(Point p) const;
// get the closest pixel to the point on the wall
Pixel get_pixel(Point p) const;
// get the intersection point(with a vector in parametrized form)
Point intersect(Vec3 dir, Point p) const;
bool getIntersection(Vec3 dir, Point cameraPos, Point& intersection) const;
void print() const;
void print_pic(int pos) const;
};
struct Surrounding
{
Surrounding(Wall* Front, Wall* Back, Wall* Left, Wall* Right, Wall* Ceil, Wall* Floor);
Surrounding() {};
Wall* yPos;
Wall* yNeg;
Wall* xPos;
Wall* xNeg;
Wall* zPos;
Wall* zNeg;
};
class Pinhole
{
public:
Pinhole(float aperture,
float hAngle,
float vAngle,
Point cameraPos,
float cameraDist,
Surrounding walls,
int xDim, int yDim,
int xLen, int yLen);
vector<Pixel> getImage() const { return imagePlane; }
void render();
void renderPixel(int x, int y);
void setColor(int x, int y, Pixel color);
private:
float aperture; // range of view
Point cameraPos;
float cameraDist; // distance of image plane
Surrounding walls;
int xDim, yDim; // resolution of image plane
int xLen, yLen; // size of image plane
float pixelSize;
mat3 rotationM_H; // rotation around z axis
mat3 rotationM_V; // rotation around x axis
vector<Pixel> imagePlane; // the final image produced
};
#endif /* pinhole_h */