-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIswi.cpp
More file actions
63 lines (58 loc) · 1.75 KB
/
Copy pathIswi.cpp
File metadata and controls
63 lines (58 loc) · 1.75 KB
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
#include "Iswi.hpp"
std::vector<std::vector<Vertex> > & Iswi::surface(std::vector<Vertex > & control, int x, int y, int width, int height)
{
std::vector<std::vector<Vertex> > *res = new std::vector<std::vector<Vertex> >;
std::vector<Vertex> tmp;
double divx = static_cast<double>(width) / static_cast<double>(x);
double divy = static_cast<double>(height) / static_cast<double>(y);
Iswi::_generate(control, x, y, width, height);
for (int i = 0; i < x; i++)
{
tmp.clear();
for (int j = 0; j < y; j++)
{
Vertex vtx = Vertex(i * divx, - (Iswi::_avg(control, i * divx, j * divy)), j * divy);
tmp.push_back(vtx);
}
res->push_back(tmp);
}
return *res;
}
void Iswi::_generate(std::vector<Vertex > & control, int x, int y, int width, int height)
{
double divx = static_cast<double>(width) / 50.0;
double divy = static_cast<double>(height) / 50.0;
Vertex vtx;
Vertex vtx2;
for (int i = -1; i <= 50; i++)
{
vtx = Vertex(i * divx, -height / 4.0, 0);
vtx2 = Vertex(i * divx, (y + 1) * (height / 4.0), 0);
control.push_back(vtx);
control.push_back(vtx2);
}
for (int j = 0; j < 50; j++)
{
vtx = Vertex(-width / 4.0, j * divy, 0);
vtx2 = Vertex((x + 1) * (width / 4.0), j * divy, 0);
control.push_back(vtx);
control.push_back(vtx2);
}
}
double Iswi::_avg(const std::vector<Vertex > &control, double x, double y)
{
double z = 0;
double tmp;
double save = 0;
std::vector<Vertex >::const_iterator it;
for (it = control.begin(); it != control.end(); ++it)
{
tmp = (std::pow(x - (*it).getX(), 2) + std::pow(y - (*it).getY(), 2));
if (tmp == 0)
return (*it).getZ();
z += (*it).getZ() / tmp;
save += 1.0 / tmp;
}
z /= save;
return z;
}