-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBranchModel.h
More file actions
84 lines (68 loc) · 1.74 KB
/
BranchModel.h
File metadata and controls
84 lines (68 loc) · 1.74 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef MODELBRANCH_H
#define MODELBRANCH_H
#include <vector>
/*
* ModelBranch składa się z listy ModelNode. W skład gałęzi wchodzą kolejne Nody, mające największy promień.
* Pozostałe Nody tworzą kolejne gałęzie.
*/
class BranchModel
{
public:
std::vector<BranchModel*> childBranches;
//tablica z węzłami gałęzi. Zawsza posiada przynajmniej 2 elementy.
std::vector<NodeModel*> nodeModelList;
BranchModel *parentBranch;
//Pozycja gałęzi względem gałęzi rodzica;
//UWAGA: to jest ten sam obiekt co w obiekcie NodeModel w gałęzi-rodzicu
Point3d *position;
BranchModel(BranchModel *parentBranch, Point3d* branchPosition)
{
this->parentBranch = parentBranch;
position = branchPosition;
}
~BranchModel()
{
for(unsigned int i=0; i<nodeModelList.size(); i++)
{
delete nodeModelList[i];
}
for(unsigned int i=0; i<childBranches.size(); i++)
{
delete childBranches[i];
}
}
//zwraca wskaźnik na punkt, do którego został doczepiony NodeModel
Point3d* addNewNodeModel(Node *node)
{
Point3d* result = new Point3d();
result->add(node->point);
result->sub(getAbsolutePosition());
NodeModel *nodeModel = new NodeModel(result, node->r);
nodeModelList.push_back(nodeModel);
return result;
}
void addChildBranch(BranchModel *branch)
{
childBranches.push_back(branch);
}
Point3d getAbsolutePosition()
{
BranchModel *parent = this->parentBranch;
Point3d result;
result.add(*this->position);
while(parent)
{
result.add(*parent->position);
parent = parent->parentBranch;
}
return result;
}
Point3d getAbsoluteNodePosition(NodeModel *node)
{
Point3d result;
result.add(getAbsolutePosition());
result.add(*node->position);
return result;
}
};
#endif /* MODELBRANCH_H */