-
Notifications
You must be signed in to change notification settings - Fork 1
/
intersect.h
60 lines (55 loc) · 1.28 KB
/
intersect.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
#pragma once
#include "implicit_group.h"
#include <cgv/base/rebind.h>
template <typename T>
struct intersect_node :
public v3_func<T,T>,
public implicit_group
{
std::vector<v3_func<T,T>*> children;
intersect_node()
{
set_name("intersect");
}
unsigned int append_child(base_ptr child)
{
unsigned int i = implicit_group::append_child(child);
children.push_back(child->get_interface<v3_func<T,T> >());
return i;
}
T eval_and_get_index(const pnt_type& p, unsigned int& selected_i) const {
T value = children[0]->evaluate(p);
selected_i = 0;
for (unsigned int i=1; i<children.size(); ++i) {
T new_value = children[i]->evaluate(p);
if (new_value > value) {
selected_i = i;
value = new_value;
}
}
return value;
}
T evaluate(const pnt_type& p) const {
if (children.empty())
return 1;
unsigned int i;
return eval_and_get_index(p, i);
}
vec_type evaluate_gradient(const pnt_type& p) const {
if (children.empty())
return vec_type(0,0,0);
unsigned int i;
eval_and_get_index(p, i);
return children[i]->evaluate_gradient(p);
}
void create_gui()
{
static std::string heading("intersect");
add_view("", heading)->set("color", 0xffff00);
implicit_group::create_gui();
}
std::string get_type_name() const
{
return "intersect";
}
};