source: GTP/trunk/Lib/Vis/OnlineCullingCHC/src/VisibilityManager.cpp @ 2555

Revision 2555, 6.1 KB checked in by mattausch, 17 years ago (diff)

added partial implementation of chc++. problem: bounding box rendering in Ogre is VERY slow

Line 
1#include "VisibilityManager.h"
2#include "StopAndWaitCullingManager.h"
3#include "CoherentHierarchicalCullingManager.h"
4#include "FrustumCullingManager.h"
5#include "DummyPreprocessingManager.h"
6#include "RandomUpdateCullingManager.h"
7#include "CoherentHierarchicalCullingPlusPlusManager.h"
8#include "CullingLogManager.h"
9
10
11namespace GtpVisibility {
12
13//-----------------------------------------------------------------------
14VisibilityManager::VisibilityManager(VisibilityEnvironment *visEnvironment):
15mVisibilityThreshold(0),
16mCullingManager(NULL),
17mQueryManager(NULL),
18mPreprocessingManager(new DummyPreprocessingManager(NULL)),
19mVisibilityEnvironment(visEnvironment),
20mAssumedVisibilityForChc(0)
21{
22        SetCullingManager(VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING);
23}
24//-----------------------------------------------------------------------
25VisibilityManager::~VisibilityManager()
26{
27        delete mCullingManager;
28        delete mPreprocessingManager;
29        CullingLogManager::DelSingleton();
30}
31//-----------------------------------------------------------------------
32void VisibilityManager::SetCullingManager(VisibilityEnvironment::
33                                                                                  CullingManagerType ocmType)
34{
35        // change only if necessary
36        if (!mCullingManager || (mCullingManagerType != ocmType))
37        {
38                // delete old culling manager
39                if (mCullingManager)
40                        delete mCullingManager;
41
42                mCullingManagerType = ocmType;
43               
44                switch (ocmType)
45                {
46                case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
47                        {
48                                CoherentHierarchicalCullingManager *chcm = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
49                                chcm->SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
50                                mCullingManager = chcm;
51                        }
52                        break;
53                case VisibilityEnvironment::FRUSTUM_CULLING:
54                        mCullingManager = new FrustumCullingManager();
55                        break;
56                case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS:
57                        {
58                                CoherentHierarchicalCullingPlusPlusManager *chcm =
59                                        new CoherentHierarchicalCullingPlusPlusManager(mAssumedVisibilityForChc);
60                                mCullingManager = chcm;
61                        }
62                        break;
63                case VisibilityEnvironment::STOP_AND_WAIT_CULLING:
64                        mCullingManager = new StopAndWaitCullingManager();
65                        break;
66                default:
67                        mCullingManager = new CoherentHierarchicalCullingManager(mAssumedVisibilityForChc);
68                        break;
69                }
70
71                /////////
72                //-- set threshold
73
74                mCullingManager->SetVisibilityThreshold(mVisibilityThreshold); 
75        }
76}
77//-----------------------------------------------------------------------
78void VisibilityManager::SetVisibilityCullingThreshold(unsigned int visibilityThreshold)
79{
80        mVisibilityThreshold = visibilityThreshold;
81        mCullingManager->SetVisibilityThreshold(mVisibilityThreshold);
82}
83//-----------------------------------------------------------------------
84CullingManager *VisibilityManager::GetCullingManager()
85{
86        return mCullingManager;
87}
88//-----------------------------------------------------------------------
89void VisibilityManager::ApplyVisibilityCulling()
90{
91        mCullingManager->RenderScene();
92}
93//-----------------------------------------------------------------------
94VisibilityEnvironment::CullingManagerType VisibilityManager::GetCullingManagerType()
95{
96        return mCullingManagerType;
97}
98//-----------------------------------------------------------------------
99void VisibilityManager::SetQueryManager(QueryManager *queryManager)
100{
101        mQueryManager = queryManager;
102}
103//-----------------------------------------------------------------------
104QueryManager *VisibilityManager::GetQueryManager()
105{
106        return mQueryManager;
107}
108//-----------------------------------------------------------------------
109void VisibilityManager::SetAssumedVisibilityForChc(unsigned int assumedVisibility)                                                                       
110{
111        mAssumedVisibilityForChc = assumedVisibility;
112
113        switch (mCullingManagerType)
114        {
115        case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING:
116                static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
117                                SetAssumedVisibility(mAssumedVisibilityForChc);
118                break;
119        case VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS:
120                static_cast<CoherentHierarchicalCullingPlusPlusManager *>(mCullingManager)->
121                                SetAssumedVisibility(mAssumedVisibilityForChc);
122                break;
123        }
124}
125//-----------------------------------------------------------------------
126void VisibilityManager::SetRandomUpdateCandidatesForRuc(unsigned int randomCandidates)                                                                   
127{
128        mRandomCandidatesForRuc = randomCandidates;
129
130        if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS)
131        {
132                static_cast<RandomUpdateCullingManager *>(mCullingManager)->
133                                SetRandomCandidates(mRandomCandidatesForRuc);
134        }
135}
136//-----------------------------------------------------------------------
137VisibilityEnvironment *VisibilityManager::GetVisibilityEnvironment()
138{
139        return mVisibilityEnvironment;
140}
141//-----------------------------------------------------------------------
142unsigned int VisibilityManager::GetAssumedVisibilityForChc()
143{
144        return mAssumedVisibilityForChc;
145}
146//-----------------------------------------------------------------------
147unsigned int VisibilityManager::GetRandomUpdateCandidatesForRuc()
148{
149        return mRandomCandidatesForRuc;
150}
151//-----------------------------------------------------------------------
152void VisibilityManager::SetTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves)
153{
154        mTestGeometryForVisibleLeaves = testGeometryForVisibleLeaves;
155
156        if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING)
157        {
158                static_cast<CoherentHierarchicalCullingManager *>(mCullingManager)->
159                                SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
160        }
161        /*else if (mCullingManagerType == VisibilityEnvironment::COHERENT_HIERARCHICAL_CULLING_PLUSPLUS)
162        {
163                static_cast<RandomUpdateCullingManager *>(mCullingManager)->
164                                SetTestGeometryForVisibleLeaves(mTestGeometryForVisibleLeaves);
165        }*/
166}
167//-----------------------------------------------------------------------
168bool VisibilityManager::GetTestGeometryForVisibleLeaves()
169{
170        return mTestGeometryForVisibleLeaves;
171}
172
173} // namespace GtpVisibility
Note: See TracBrowser for help on using the repository browser.