-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimplicit_base.cxx
70 lines (59 loc) · 1.6 KB
/
implicit_base.cxx
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
#include "implicit_base.h"
/// set new scene update handler
template <typename T>
void implicit_base<T>::set_update_handler(scene_update_handler* uh)
{
update_handler = uh;
}
/// to be called if scene has changed due to gui interaction
template <typename T>
void implicit_base<T>::update_scene()
{
if (update_handler)
update_handler->update_scene();
}
/// callback for functions that update the scene description without the implicit function
template <typename T>
void implicit_base<T>::update_description()
{
if (update_handler)
update_handler->update_description();
}
/// constructor sets default gui color
template <typename T>
implicit_base<T>::implicit_base() : color(0.5f, 0.5f, 0.5f, 1.0f)
{
gui_color = 0x888888;
update_handler = 0;
}
template <typename T>
std::string implicit_base<T>::get_type_name() const
{
return "implicit_base";
}
/// interface for evaluation of the gradient with central differences based default implementation
template <typename T>
typename implicit_base<T>::vec_type implicit_base<T>::evaluate_gradient(const pnt_type& p) const
{
static crd_type epsilon = 5 * std::numeric_limits<T>::epsilon();
static crd_type inv_2_eps = T(2)/epsilon;
vec_type g;
pnt_type q(p);
for (unsigned i = 0; i<3; ++i) {
q(i) += epsilon;
g(i) = evaluate(q);
q(i) = p(i) - epsilon;
g(i) -= evaluate(q);
g(i) *= inv_2_eps;
q(i) = p(i);
}
return g;
}
/// return primitive color
template <typename T>
typename implicit_base<T>::clr_type implicit_base<T>::evaluate_color(const pnt_type& p) const
{
return color;
}
template class implicit_base<float>;
template class implicit_base<double>;