-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_setting.cc
91 lines (79 loc) · 2.99 KB
/
view_setting.cc
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
#include "view_setting.h"
#include "common.h"
#include "geometry.h"
#include <cmath>
#include <vector>
#include <Eigen/Dense>
namespace view_setting {
// Generate uniform randle samples.
void GenerateUniformRandomSamples(int num_samples,
std::vector<Eigen::Vector3d> *samples) {
double u = 0.0, theta = 0.0;
srand(0);
samples->clear();
for (int i = 0; i < num_samples; ++i) {
// Get a random number [-1, 1].
u = -1.0 + (2.0 * rand()) / RAND_MAX;
// Get a random number [0, 2 * PI].
theta = 2.0 * (2.0 * rand()) / RAND_MAX * kPi;
// Generate the eye location.
double v = sqrt(1 - u * u);
samples->push_back(Eigen::Vector3d(v * cos(theta), v * sin(theta), u));
}
}
// Generate cylindrical samples in the XZ plane.
void GenerateCylindricalSamples(int num_samples,
std::vector<Eigen::Vector3d> *samples) {
double delta = 2.0 * kPi / num_samples, theta = 0.0;
samples->clear();
for (int i = 0; i < num_samples; ++i) {
samples->push_back(Eigen::Vector3d(cos(theta), 0.0, sin(theta)));
theta += delta;
}
}
// Generate samples using the vertices of an icosahedron.
void GenerateIcosahedronSamples(std::vector<Eigen::Vector3d> *samples) {
static const Eigen::Vector3d kIcosahedronVertices[12] = {
{-1.0, kGoldenRatio, 0.0}, {1.0, kGoldenRatio, 0.0},
{-1.0, -kGoldenRatio, 0.0}, {1.0, -kGoldenRatio, 0.0},
{0.0, -1.0, kGoldenRatio}, {0.0, 1.0, kGoldenRatio},
{0.0, -1.0, -kGoldenRatio}, {0.0, 1.0, -kGoldenRatio},
{kGoldenRatio, 0.0, -1.0}, {kGoldenRatio, 0.0, 1.0},
{-kGoldenRatio, 0.0, -1.0}, {-kGoldenRatio, 0.0, 1.0},
};
samples->clear();
for (int i = 0; i < 12; ++i) samples->push_back(kIcosahedronVertices[i]);
}
// Generate a batch of render view_settings.
// Using the input mesh, there will be n view_settings generated.
void GenerateViewSettings(const geometry::Mesh *mesh,
RenderSampleType sample_type, int num_samples,
int width, int height, ViewSettings *view_settings) {
// The radius to use.
double radius = 10.0;
// Generate samples.
std::vector<Eigen::Vector3d> samples;
switch (sample_type) {
case kIcosahedronSample:
GenerateIcosahedronSamples(&samples);
break;
case kCylinderSample:
GenerateCylindricalSamples(num_samples, &samples);
break;
case kUniformRandomSample:
default:
GenerateUniformRandomSamples(num_samples, &samples);
break;
}
// Generate render views based on the choice of sampling.
ViewSetting view_setting;
view_settings->view_setting_list.clear();
for (int i = 0; i < samples.size(); ++i) {
view_setting = ViewSetting(width, height, radius * samples[i],
Eigen::Vector3d(0.0, 1.0, 0.0), false, 0.0001,
100, 45.0, Eigen::Vector3d(0.0, 0.0, 0.0));
view_settings->view_setting_list.push_back(view_setting);
}
view_settings->which = 0;
}
} // namespace view_setting