-
Notifications
You must be signed in to change notification settings - Fork 0
/
Desc.cpp
119 lines (104 loc) · 3.73 KB
/
Desc.cpp
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
#include "og_pch.hpp"
#include "Desc.hpp"
namespace og
{
void BranchDesc::SetFromNode(const pugi::xml_node & level)
{
pugi::xml_node attrib_set = level.child("mid");
for( pugi::xml_node node = attrib_set.first_child(); node; node = node.next_sibling() )
{
if( strcmp( node.name(), "geotropism" ) == 0)
{
mid.light_attraction = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "first_split" ) == 0)
{
mid.first_split_distance = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "segment_length" ) == 0)
{
mid.segment_length = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "split_frequency" ) == 0)
{
mid.split_frequency = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "length" ) == 0)
{
mid.total_length = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "split_angle" ) == 0)
{
mid.split_angle = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "bud_growth_samples" ) == 0)
{
mid.bud_growth_samples = StrToStd<uint16_t>( node.child_value() );
}
}
attrib_set = level.child("var");
for( pugi::xml_node node = attrib_set.first_child(); node; node = node.next_sibling() )
{
if( strcmp( node.name(), "geotropism" ) == 0)
{
var.light_attraction = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "first_split" ) == 0)
{
var.first_split_distance = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "segment_length" ) == 0)
{
var.segment_length = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "split_frequency" ) == 0)
{
var.split_frequency = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "length" ) == 0)
{
var.total_length = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "split_angle" ) == 0)
{
var.split_angle = StrToStd<float>( node.child_value() );
}
else if( strcmp( node.name(), "bud_growth_samples" ) == 0)
{
var.bud_growth_samples = StrToStd<uint16_t>( node.child_value() );
}
}
}
BranchDesc::BranchDesc(const pugi::xml_node & node)
{
SetFromNode(node);
}
BranchDesc::BranchDesc(const pugi::xml_node & node, const BranchDesc & defaults) :
mid(defaults.mid),
var(defaults.var)
{
SetFromNode(node);
}
TreeDesc::TreeDesc(const pugi::xml_node & tree_root)
{
species = tree_root.child_value("species");
max_levels = static_cast<uint8_t>(StrToStd<uint32_t>(tree_root.child_value("max_levels"))); //Need to interpret as int then cast, otherwise it's read as ASCII char.
// Allocate memory to hold the midpoint and variation for the values in each branch level.
levels.resize(max_levels);
const pugi::xml_node data_node = tree_root.child ( "data" );
pugi::xml_node node = data_node.child ( "base_splits" );
base_splits[MID] = StrToStd<float> ( node.child_value ( "mid" ) );
base_splits[VAR] = StrToStd<float> ( node.child_value ( "var" ) );
node = data_node.child ( "defaults" );
defaults.reset(new BranchDesc(node));
node = data_node.child ( "levels" );
for( pugi::xml_node level = node.first_child(); level; level = level.next_sibling() )
{
size_t index = level.attribute ( "id" ).as_uint();
if ( index >= max_levels )
continue;
/* Set the level to the default values */
levels[index].reset(new BranchDesc(level,(*defaults)));
}
}
}