-
Notifications
You must be signed in to change notification settings - Fork 4
/
DepthCamera.h
221 lines (171 loc) · 4.92 KB
/
DepthCamera.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#pragma once
//
// デプスセンサ関連の基底クラス
//
// 補助プログラム
#include "gg.h"
using namespace gg;
// 計算用のシェーダ
#include "Compute.h"
// メッシュの描画
#include "Mesh.h"
// 標準ライブラリ
#include <memory>
class DepthCamera
{
// エラーメッセージ
const char *message;
// フィルタのサイズ
static constexpr int filterSize[] = { 5, 5 };
// バイラテラルフィルタの距離に対する重みと値に対する分散
struct Weight
{
std::array<GLfloat, filterSize[0]> columnWeight;
std::array<GLfloat, filterSize[1]> rowWeight;
float variance;
};
// カメラ座標における法線ベクトルを格納するバッファオブジェクト
GLuint normalBuffer;
// 法線ベクトルを計算するシェーダ
static std::unique_ptr<Compute> normal;
// 法線ベクトルを求めるカメラ座標のイメージユニットの uniform 変数 point の場所
static GLuint pointLoc;
protected:
// エラーメッセージを設定する
void setMessage(const char *message)
{
this->message = message;
}
// カメラ座標のデータ型
using Point = std::array<GLfloat, 3>;
// テクスチャ座標のデータ型
using Uvmap = std::array<GLfloat, 2>;
// 法線ベクトルのデータ型
using Normal = std::array<GLfloat, 4>;
// カラーのデータ型
using Color = std::array<GLubyte, 3>;
// デプスセンサのサイズ
int depthWidth, depthHeight;
// デプスデータを格納するテクスチャ
GLuint depthTexture;
// カラーセンサのサイズ
int colorWidth, colorHeight;
// カラーデータを格納するテクスチャ
GLuint colorTexture;
// デプスデータから変換したカメラ座標を格納するテクスチャ
GLuint pointTexture;
// カメラ座標に対応したテクスチャ座標を格納するバッファオブジェクト
GLuint uvmapBuffer;
// バイラテラルフィルタの距離に対する重みを格納する Shader Storage Buffer Object
GLuint weightBuffer;
// テクスチャとバッファオブジェクトを作成してポイント数を返す
int makeTexture();
// 描画するメッシュ
static std::unique_ptr<Mesh> mesh;
public:
// エラーメッセージを取り出す
const char *getMessage() const
{
return message;
}
// イメージユニット
enum ImageUnits
{
DepthImageUnit = 0,
PointImageUnit,
MapperImageUnit
};
// 結合ポイント
enum BindingPoints
{
// 0, 1 は GgSimpleShader で使っている
UvmapBinding = 2,
WeightBinding,
NormalBinding
};
// コンストラクタ
DepthCamera();
// コピーコンストラクタ (コピー禁止)
DepthCamera(const DepthCamera &w) = delete;
// 代入 (代入禁止)
DepthCamera &operator=(const DepthCamera &w) = delete;
// デストラクタ
virtual ~DepthCamera();
// 使用可能なら true を返す
bool isOpend() const
{
return message == nullptr;
}
// デプスセンサのサイズを得る
void getDepthResolution(int *width, int *height) const
{
*width = depthWidth;
*height = depthHeight;
}
// カラーセンサのサイズを得る
void getColorResolution(int *width, int *height) const
{
*width = colorWidth;
*height = colorHeight;
}
// デプスデータを格納するテクスチャを得る
GLuint getDepthTexture() const
{
return depthTexture;
}
// カラーデータを格納するテクスチャを得る
GLuint getColorTexture() const
{
return colorTexture;
}
// カメラ座標を格納するテクスチャを得る
GLuint getPointTexture() const
{
return pointTexture;
}
// テクスチャ座標を格納するバッファオブジェクトを得る
GLuint getUvmapBuffer() const
{
return uvmapBuffer;
}
// 法線ベクトルを格納するバッファオブジェクトを得る
GLuint getNormalBuffer() const
{
return normalBuffer;
}
// 法線ベクトルの計算
GLuint getNormal() const;
// バイラテラルフィルタの分散を設定する
void setVariance(float columnVariance, float rowVariance, float valueVariance) const;
// デプスセンサの姿勢
GgMatrix attitude;
// 目種の描画
void draw()
{
mesh->draw(depthWidth, depthHeight);
}
// デプスデータを取得する
virtual GLuint getDepth()
{
glBindTexture(GL_TEXTURE_2D, depthTexture);
return depthTexture;
}
// カメラ座標を取得する
virtual GLuint getPoint()
{
glBindTexture(GL_TEXTURE_2D, pointTexture);
return pointTexture;
}
// カメラ座標を算出する
virtual GLuint getPosition()
{
glBindTexture(GL_TEXTURE_2D, pointTexture);
return pointTexture;
}
// カラーデータを取得する
virtual GLuint getColor()
{
glBindTexture(GL_TEXTURE_2D, colorTexture);
return colorTexture;
}
};