source: GTP/trunk/Lib/Vis/Preprocessing/manual/code/actualcode.tex @ 2066

Revision 2066, 10.7 KB checked in by mattausch, 18 years ago (diff)

worked on integration manual

Line 
1\input default.mac
2\keya{}\leftline{void\symbol{}\ \normal{}NV_PureKdTreeRenderAction\symbol{}::\normal{}TraverseNode\symbol{}(\normal{}KdTreeNode\symbol{}\ *\normal{}pCurrNode\symbol{}) }
3\leftline{ 1:\ \ \ $\{$ }
4\leftline{ 2:\ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}pCurrNode\symbol{}->\normal{}m_bLeaf\symbol{}) }
5\leftline{ 3:\ \ \ \ \ \ \ \ \ \ $\{$ }
6\leftline{ 4:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//\ this\ has\ a\ frame\ counter\ to\ prevent\ double\ rendering }
7\symbol{}\leftline{ 5:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}->\normal{}RenderGeometry\symbol{}(); }
8\leftline{ 6:\ \ \ \ \ \ \ \ \ \ $\}$ }
9\leftline{ 7:\ \ \ \ \ \ \ \ \ \ \keya{}else\symbol{} }
10\leftline{ 8:\ \ \ \ \ \ \ \ \ \ $\{$ }
11\leftline{ 9:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}Point3f\symbol{}\ \ \ \ \ \ \normal{}ptViewpoint\symbol{}\ \ =\ \normal{}GetState\symbol{}()->\normal{}GetCamera\symbol{}()->\normal{}GetPosition\symbol{}(); }
12\leftline{10:\ \ \  }
13\leftline{11:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//----\ insert\ the\ children\ in\ the\ reverse\ order\ as\ they\ shall\ be\ dealt\ with }
14\symbol{}\leftline{12:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}ptViewpoint\symbol{}[\normal{}pCurrNode\symbol{}->\normal{}m_iSplitAxis\symbol{}]\ >\ \normal{}pCurrNode\symbol{}->\normal{}m_fSplitValue\symbol{}) }
15\leftline{13:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
16\leftline{14:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}m_TraverseStack.Push\symbol{}(\normal{}pCurrNode\symbol{}->\normal{}m_pLeftChild\symbol{}); }
17\leftline{15:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}m_TraverseStack.Push\symbol{}(\normal{}pCurrNode\symbol{}->\normal{}m_pRightChild\symbol{}); }
18\leftline{16:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$ }
19\leftline{17:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}else\symbol{} }
20\leftline{18:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
21\leftline{19:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}m_TraverseStack.Push\symbol{}(\normal{}pCurrNode\symbol{}->\normal{}m_pRightChild\symbol{}); }
22\leftline{20:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}m_TraverseStack.Push\symbol{}(\normal{}pCurrNode\symbol{}->\normal{}m_pLeftChild\symbol{}); }
23\leftline{21:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$ }
24\leftline{22:\ \ \ \ \ \ \ \ \ \ $\}$\ \comment{}//\ no\ leaf }
25\symbol{}\leftline{23:\ \ \ $\}$ }
26\leftline{24:\ \ \  }
27\leftline{25:\ \ \  }
28\comment{}\leftline{26:\ \ \ //----\ the\ actual\ render\ algorithm }
29\keya{}\leftline{27:\ \ \ void\symbol{}\ \ \ \normal{}NV_PureKdTreeRenderAction\symbol{}::\normal{}RenderSorted\symbol{}() }
30\leftline{28:\ \ \ $\{$ }
31\leftline{29:\ \ \ \ \ \ \ \ \ \ \normal{}KdTreeNode\symbol{}\ \ \ \ *\ \normal{}pCurrNode\symbol{}; }
32\leftline{30:\ \ \ \ \ \ \ \ \ \ \keya{}int\symbol{}\ \ \ \ \ \ \normal{}iTestCounter\symbol{}\ \ \ \ =\ \normal{}0\symbol{}; }
33\leftline{31:\ \ \  }
34\leftline{32:\ \ \ \ \ \ \ \ \ \ \comment{}//----\ clear\ the\ two\ needed\ datastructures }
35\symbol{}\leftline{33:\ \ \ \ \ \ \ \ \ \ \normal{}m_TraverseStack.Clear\symbol{}(); }
36\leftline{34:\ \ \ \ \ \ \ \ \ \ \normal{}m_NVTestQueue.Clear\symbol{}(); }
37\leftline{35:\ \ \  }
38\leftline{36:\ \ \ \ \ \ \ \ \ \ \comment{}//----\ generate\ the\ occlusion\ queries }
39\symbol{}\leftline{37:\ \ \ \ \ \ \ \ \ \ \normal{}glGenOcclusionQueriesNV\symbol{}(\normal{}m_nNumNodes\symbol{},\ \normal{}m_pOcclusionQueries\symbol{}); }
40\leftline{38:\ \ \  }
41\leftline{39:\ \ \ \ \ \ \ \ \ \ \comment{}//----\ take\ the\ root\ as\ a\ start }
42\symbol{}\leftline{40:\ \ \ \ \ \ \ \ \ \ \normal{}m_pKdTree\symbol{}->\normal{}m_iPlaneMask\symbol{}\ \ \ \ \ \ \ =\ \normal{}0x3f\symbol{};\ \ \ \ \ \ \ \comment{}//\ =\ 0011\ 1111\ which\ means\ that\ at\ the\ beginning,\ all\ six\ planes\ have\ to\ frustum\ culled }
43\symbol{}\leftline{41:\ \ \ \ \ \ \ \ \ \ \normal{}m_TraverseStack.Push\symbol{}(\normal{}m_pKdTree\symbol{}); }
44\leftline{42:\ \ \  }
45\leftline{43:\ \ \ \ \ \ \ \ \ \ \comment{}//----\ the\ loop }
46\symbol{}\leftline{44:\ \ \ \ \ \ \ \ \ \ \keya{}while\symbol{}\ ((!\normal{}m_TraverseStack.Empty\symbol{}())\ ||\ (!\normal{}m_NVTestQueue.Empty\symbol{}())) }
47\leftline{45:\ \ \ \ \ \ \ \ \ \ $\{$ }
48\leftline{46:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}bool\symbol{}\ \normal{}result_available\symbol{}; }
49\leftline{47:\ \ \  }
50\leftline{48:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}while\symbol{}\ (!\normal{}m_NVTestQueue.Empty\symbol{}()\ \&\&\  }
51\leftline{49:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\normal{}m_TraverseStack.Empty\symbol{}()\ || }
52\leftline{50:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ (\normal{}result_available\symbol{}\ =\ \normal{}ResultAvailable\symbol{}(\normal{}m_NVTestQueue.GetFirst\symbol{}()->\normal{}m_nTest\symbol{})) }
53\leftline{51:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ) }
54\leftline{52:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ) }
55\leftline{53:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
56\leftline{54:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}\ =\ \normal{}m_NVTestQueue.GetFirst\symbol{}();\ \normal{}m_NVTestQueue.RemoveFirst\symbol{}(); }
57\leftline{55:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  }
58\leftline{56:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//\ the\ next\ line\ is\ only\ interesting\ if\ we\ want\ to\ avoid\ double\ rendering\ already\ here: }
59\symbol{}\leftline{57:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//bool\ was_visible\ =\ pCurrNode->m_bVisible\ \&\&\ (m_nLastVisitedId\ ==\ (GetCurrentFrame()\ -\ 1)); }
60\symbol{}\leftline{58:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  }
61\leftline{59:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//\ update\ visibility\ classification\ (this\ is\ the\ wait\ variety!) }
62\symbol{}\leftline{60:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}->\normal{}m_bVisible\symbol{}\ =\ \normal{}GetVisiblePixels\symbol{}(\normal{}pCurrNode\symbol{}->\normal{}m_nTest\symbol{})\ >\ \normal{}Settings\symbol{}::\normal{}Global\symbol{}()->\normal{}get_nvocc_pixel_treshold\symbol{}(); }
63\leftline{61:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}->\normal{}m_nLastVisitedId\symbol{}\ =\ \normal{}GetCurrentFrame\symbol{}(); }
64\leftline{62:\ \ \  }
65\leftline{63:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}pCurrNode\symbol{}->\normal{}m_bVisible\symbol{})\ \comment{}//\ \&\&\ !was_visible)\ \ \ \ \ \ //\ note:\ could\ prevent\ double\ rendering\ already\ here! }
66\symbol{}\leftline{64:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
67\leftline{65:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}->\normal{}MakeParentsVisible\symbol{}(); }
68\leftline{66:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}TraverseNode\symbol{}(\normal{}pCurrNode\symbol{}); }
69\leftline{67:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$\ \comment{}//\ visible }
70\symbol{}\leftline{68:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$ }
71\leftline{69:\ \ \  }
72\leftline{70:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//----\ the\ second\ part\ manages\ the\ distance\ heap }
73\symbol{}\leftline{71:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (!\normal{}m_TraverseStack.Empty\symbol{}()) }
74\leftline{72:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
75\leftline{73:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//----\ get\ the\ element\ with\ the\ lowest\ distance }
76\symbol{}\leftline{74:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}\ \ \ =\ \normal{}m_TraverseStack.Pop\symbol{}();\ \ \ \ \ \ \ \ \ \ \  }
77\leftline{75:\ \ \  }
78\leftline{76:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//\ question:\ what\ is\ the\ difference\ if\ we\ do\ frustum\ culling\ only\ after\ setting\ visibility? }
79\symbol{}\leftline{77:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}pCurrNode\symbol{}->\normal{}IsWithinViewFrustum\symbol{}()) }
80\leftline{78:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
81\leftline{79:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}bool\symbol{}\ \normal{}was_visible\symbol{}\ =\ \normal{}pCurrNode\symbol{}->\normal{}m_bVisible\symbol{}\ \&\&\ (\normal{}pCurrNode\symbol{}->\normal{}m_nLastVisitedId\symbol{}\ ==\ (\normal{}GetCurrentFrame\symbol{}()\ -\ \normal{}1\symbol{})); }
82\leftline{80:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  }
83\leftline{81:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//\ note:\ this\ is\ actually\ only\ done\ for\ internal\ nodes\ and\ could\ be\ skipped\ for\ leaf\ nodes }
84\symbol{}\leftline{82:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \comment{}//\ in\ which\ case\ leaf\ node\ double\ rendering\ could\ be\ prevented\ here\ (see\ above) }
85\symbol{}\leftline{83:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}->\normal{}m_bVisible\symbol{}\ =\ \normal{}FALSE\symbol{}; }
86\leftline{84:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}pCurrNode\symbol{}->\normal{}m_nLastVisitedId\symbol{}\ =\ \normal{}GetCurrentFrame\symbol{}(); }
87\leftline{85:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \  }
88\leftline{86:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}pCurrNode\symbol{}->\normal{}m_bLeaf\symbol{}\ ||\ !\normal{}was_visible\symbol{}) }
89\leftline{87:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
90\leftline{88:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}pCurrNode\symbol{}->\normal{}m_pSuccessor\symbol{}->\normal{}IssueNVTest\symbol{}(\normal{}m_pOcclusionQueries\symbol{}[\normal{}iTestCounter\symbol{}]))\ ++\normal{}iTestCounter\symbol{}; }
91\leftline{89:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}m_NVTestQueue.Append\symbol{}(\normal{}pCurrNode\symbol{}); }
92\leftline{90:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$ }
93\leftline{91:\ \ \  }
94\leftline{92:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \keya{}if\symbol{}\ (\normal{}was_visible\symbol{}) }
95\leftline{93:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\{$ }
96\leftline{94:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \normal{}TraverseNode\symbol{}(\normal{}pCurrNode\symbol{}); }
97\leftline{95:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$ }
98\leftline{96:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$ }
99\leftline{97:\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ $\}$ }
100\leftline{98:\ \ \ \ \ \ \ \ \ \ $\}$ }
101\leftline{99:\ \ \  }
102\leftline{100:\ \ \ \ \ \ \ \ \ \ \comment{}//----\ tell\ the\ driver\ that\ the\ occlusion\ queries\ won't\ be\ needed\ any\ more }
103\symbol{}\leftline{101:\ \ \ \ \ \ \ \ \ \ \normal{}glDeleteOcclusionQueriesNV\symbol{}(\normal{}m_nNumNodes\symbol{},\ \normal{}m_pOcclusionQueries\symbol{}); }
104\leftline{102:\ \ \  }
105\leftline{103:\ \ \ $\}$
Note: See TracBrowser for help on using the repository browser.