Line | |
---|
1 | #ifndef _IMGBSP_H |
---|
2 | #define _IMGBSP_H |
---|
3 | |
---|
4 | |
---|
5 | #include "IMGNodeBsp.h" |
---|
6 | |
---|
7 | namespace IMG { |
---|
8 | |
---|
9 | class Bsp { |
---|
10 | public: |
---|
11 | inline Bsp() : root(NULL), countleaf(0), counttotal(0){}; |
---|
12 | |
---|
13 | inline void SetRoot(NodeBsp * node) { |
---|
14 | root = node; |
---|
15 | counttotal++; |
---|
16 | }; |
---|
17 | |
---|
18 | inline void Print() { |
---|
19 | printf("\nImprimint Arbre BSP, num nodes leaf: %d, totals: %d", countleaf, counttotal); |
---|
20 | Print(root); |
---|
21 | }; |
---|
22 | |
---|
23 | inline void PrintLeaf() { |
---|
24 | PrintLeaf(root); |
---|
25 | }; |
---|
26 | |
---|
27 | inline NodeBsp * Insert(int w, int h, int idcluster) { |
---|
28 | //printf("\nInsret dins Bsp: %d, %d", w, h); |
---|
29 | |
---|
30 | NodeBsp *node = root->Insert (w,h); |
---|
31 | |
---|
32 | //printf("\nNode on s'insertarà finalment éS: "); node->Print(); |
---|
33 | |
---|
34 | if (idcluster != -1) |
---|
35 | { |
---|
36 | node->SetId (idcluster); |
---|
37 | countleaf++; |
---|
38 | } |
---|
39 | else counttotal++; |
---|
40 | |
---|
41 | //Copiar pixels de la imatge al node |
---|
42 | |
---|
43 | return node; |
---|
44 | }; |
---|
45 | |
---|
46 | inline NodeBsp * Get(int i) { |
---|
47 | return root->Get (root, i); |
---|
48 | }; |
---|
49 | |
---|
50 | |
---|
51 | private: |
---|
52 | NodeBsp * root; |
---|
53 | |
---|
54 | int countleaf; |
---|
55 | |
---|
56 | int counttotal; |
---|
57 | |
---|
58 | inline void Print(NodeBsp * node) { |
---|
59 | if (!node) return; |
---|
60 | node->Print(); |
---|
61 | Print(node->GetChild(0)); |
---|
62 | Print(node->GetChild(1)); |
---|
63 | }; |
---|
64 | |
---|
65 | inline void PrintLeaf(NodeBsp * node) { |
---|
66 | if (!node) return; |
---|
67 | |
---|
68 | |
---|
69 | if (node->GetChild(0) == NULL && node->GetChild(1) == NULL) node->Print(); |
---|
70 | |
---|
71 | PrintLeaf (node->GetChild(0)); |
---|
72 | PrintLeaf (node->GetChild(1)); |
---|
73 | |
---|
74 | }; |
---|
75 | |
---|
76 | |
---|
77 | public: |
---|
78 | ~Bsp(); |
---|
79 | |
---|
80 | }; |
---|
81 | |
---|
82 | } |
---|
83 | #endif |
---|
Note: See
TracBrowser
for help on using the repository browser.