Changeset 568 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 01/23/06 15:44:19 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCellsManager.cpp
r567 r568 2097 2097 //-- refines the merged view cells 2098 2098 RefineViewCells(postProcessRays, objects); 2099 // collapse sibling leaves that share the same view cell 2100 mVspBspTree->CollapseTree(); 2101 2102 ResetViewCells(); 2103 2104 // real meshes are only contructed only at this stage 2105 FinalizeViewCells(true); 2106 2107 // write view cells to disc 2108 if (mExportViewCells) 2109 { 2110 char buff[100]; 2111 environment->GetStringValue("ViewCells.filename", buff); 2112 string vcFilename(buff); 2113 2114 ExportViewCells(buff); 2115 } 2116 2117 return 0; 2118 } 2119 2120 2121 int VspBspViewCellsManager::GetType() const 2122 { 2123 return VSP_BSP; 2124 } 2125 2126 2127 bool VspBspViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 2128 { 2129 if (!ViewCellsConstructed()) 2130 return ViewCellsManager::GetViewPoint(viewPoint); 2131 2132 // TODO: set reasonable limit 2133 const int limit = 20; 2134 2135 for (int i = 0; i < limit; ++ i) 2136 { 2137 viewPoint = mViewSpaceBox.GetRandomPoint(); 2138 if (mVspBspTree->ViewPointValid(viewPoint)) 2139 { 2140 return true; 2141 } 2142 } 2143 Debug << "failed to find valid view point, taking " << viewPoint << endl; 2144 return false; 2145 } 2146 2147 2148 bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 2149 { 2150 return mViewSpaceBox.IsInside(viewPoint) && 2151 mVspBspTree->ViewPointValid(viewPoint); 2152 } 2153 2154 2155 void VspBspViewCellsManager::Visualize(const ObjectContainer &objects, 2156 const VssRayContainer &sampleRays) 2157 { 2158 if (!ViewCellsConstructed()) 2159 return; 2160 2161 VssRayContainer visRays; 2162 GetRaySets(sampleRays, mVisualizationSamples, visRays); 2163 2164 if (1) // export view cells 2165 { 2166 cout << "exporting view cells after post process ... "; 2167 Exporter *exporter = Exporter::GetExporter("final_view_cells.x3d"); 2168 2099 2100 //-- export shuffled view cells 2101 if (1) 2102 { 2103 cout << "exporting shuffled view cells ... "; 2104 2105 Exporter *exporter = Exporter::GetExporter("shuffled_view_cells.x3d"); 2169 2106 if (exporter) 2170 2107 { … … 2181 2118 } 2182 2119 2183 // export rays 2184 if (mExportRays) 2120 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 2121 2122 Material vm, lm; 2123 2124 for (vit = mViewCells.begin(); vit != mViewCells.end(); ++ vit) 2185 2125 { 2186 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 2126 BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 2127 2128 vm = RandomMaterial(); 2129 2130 lm = vm; 2131 2132 vm.mDiffuseColor.r -= 0.45f; 2133 vm.mDiffuseColor.g -= 0.45f; 2134 vm.mDiffuseColor.b -= 0.45f; 2135 2136 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2137 2138 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2139 { 2140 BspLeaf *leaf = *lit; 2141 2142 if (leaf->Mailed()) 2143 exporter->SetForcedMaterial(lm); 2144 else 2145 exporter->SetForcedMaterial(vm); 2146 2147 BspNodeGeometry geom; 2148 mVspBspTree->ConstructGeometry(leaf, geom); 2149 exporter->ExportPolygons(geom.mPolys); 2150 } 2187 2151 } 2188 2152 2189 ExportViewCellsForViz(exporter);2190 2153 delete exporter; 2191 2154 } 2192 } 2193 2194 // export shuffled view cells 2195 if (1) 2196 { 2197 cout << "exporting shuffled view cells ..."; 2198 2199 Exporter *exporter = Exporter::GetExporter("shuffled_view_cells.x3d"); 2155 2156 2157 cout << "finished" << endl; 2158 } 2159 2160 // collapse sibling leaves that share the same view cell 2161 mVspBspTree->CollapseTree(); 2162 2163 ResetViewCells(); 2164 2165 // real meshes are only contructed only at this stage 2166 FinalizeViewCells(true); 2167 2168 // write view cells to disc 2169 if (mExportViewCells) 2170 { 2171 char buff[100]; 2172 environment->GetStringValue("ViewCells.filename", buff); 2173 string vcFilename(buff); 2174 2175 ExportViewCells(buff); 2176 } 2177 2178 return 0; 2179 } 2180 2181 2182 int VspBspViewCellsManager::GetType() const 2183 { 2184 return VSP_BSP; 2185 } 2186 2187 2188 bool VspBspViewCellsManager::GetViewPoint(Vector3 &viewPoint) const 2189 { 2190 if (!ViewCellsConstructed()) 2191 return ViewCellsManager::GetViewPoint(viewPoint); 2192 2193 // TODO: set reasonable limit 2194 const int limit = 20; 2195 2196 for (int i = 0; i < limit; ++ i) 2197 { 2198 viewPoint = mViewSpaceBox.GetRandomPoint(); 2199 if (mVspBspTree->ViewPointValid(viewPoint)) 2200 { 2201 return true; 2202 } 2203 } 2204 Debug << "failed to find valid view point, taking " << viewPoint << endl; 2205 return false; 2206 } 2207 2208 2209 bool VspBspViewCellsManager::ViewPointValid(const Vector3 &viewPoint) const 2210 { 2211 return mViewSpaceBox.IsInside(viewPoint) && 2212 mVspBspTree->ViewPointValid(viewPoint); 2213 } 2214 2215 2216 void VspBspViewCellsManager::Visualize(const ObjectContainer &objects, 2217 const VssRayContainer &sampleRays) 2218 { 2219 if (!ViewCellsConstructed()) 2220 return; 2221 2222 VssRayContainer visRays; 2223 GetRaySets(sampleRays, mVisualizationSamples, visRays); 2224 2225 if (1) // export view cells 2226 { 2227 cout << "exporting view cells after post process ... "; 2228 Exporter *exporter = Exporter::GetExporter("final_view_cells.x3d"); 2229 2200 2230 if (exporter) 2201 2231 { … … 2212 2242 } 2213 2243 2214 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 2215 2216 Material vm, lm; 2217 2218 for (vit = mViewCells.begin(); vit != mViewCells.end(); ++ vit) 2244 // export rays 2245 if (mExportRays) 2219 2246 { 2220 BspViewCell *vc = dynamic_cast<BspViewCell *>(*vit); 2221 2222 vm = RandomMaterial(); 2223 2224 lm = vm; 2225 2226 vm.mDiffuseColor.r -= 0.45f; 2227 vm.mDiffuseColor.g -= 0.45f; 2228 vm.mDiffuseColor.b -= 0.45f; 2229 2230 vector<BspLeaf *>::const_iterator lit, lit_end = vc->mLeaves.end(); 2231 2232 for (lit = vc->mLeaves.begin(); lit != lit_end; ++ lit) 2233 { 2234 BspLeaf *leaf = *lit; 2235 2236 if (leaf->Mailed()) 2237 exporter->SetForcedMaterial(lm); 2238 else 2239 exporter->SetForcedMaterial(vm); 2240 2241 BspNodeGeometry geom; 2242 mVspBspTree->ConstructGeometry(leaf, geom); 2243 exporter->ExportPolygons(geom.mPolys); 2244 } 2247 exporter->ExportRays(visRays, RgbColor(0, 1, 0)); 2245 2248 } 2246 2249 2250 ExportViewCellsForViz(exporter); 2247 2251 delete exporter; 2248 2252 } 2249 2250 2251 cout << "finished" << endl;2252 2253 } 2253 2254 -
trunk/VUT/GtpVisibilityPreprocessor/src/VspBspTree.cpp
r566 r568 1980 1980 bool isAdjacent = true; 1981 1981 1982 if (1)1982 /* if (1) 1983 1983 { 1984 1984 // test all planes of current node if still adjacent … … 2014 2014 } 2015 2015 } 2016 } 2016 }*/ 2017 2017 // neighbor was found 2018 2018 if (isAdjacent) … … 3092 3092 int VspBspTree::RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects) 3093 3093 { 3094 int shuffled = 0;3095 3096 3094 Debug << "refining " << (int)mMergeQueue.size() << " candidates " << endl; 3095 3097 3096 BspLeaf::NewMail(); 3098 3097 … … 3116 3115 queue<BspMergeCandidate> *backQueue = &queue2; 3117 3116 3117 #if 1 3118 3118 Exporter *exporter = Exporter::GetExporter("neighors.x3d"); 3119 3119 … … 3125 3125 3126 3126 // HACK for visualization 3127 /*ViewCellContainer viewCells; 3128 ViewCell::NewMail(); 3129 CollectViewCells(mRoot, true, viewCells, true); 3130 for (int i = 0; i < viewCells.size(); ++i) 3131 viewCells[i]->SetId((int)RandomValue(0, Real(256*256*256))); 3132 */ 3133 Material m; 3134 m.mDiffuseColor.r = 0; 3135 m.mDiffuseColor.g = 0; 3136 m.mDiffuseColor.b = 0; 3137 3127 //ViewCellContainer viewCells; 3128 //ViewCell::NewMail(); 3129 //CollectViewCells(mRoot, true, viewCells, true); 3130 //for (int i = 0; i < viewCells.size(); ++i) 3131 // viewCells[i]->SetId((int)RandomValue(0, Real(256*256*256))); 3132 3133 3138 3134 while (!mMergeQueue.empty()) 3139 3135 { … … 3142 3138 mMergeQueue.pop(); 3143 3139 3144 3145 3140 // visualize neighbors 3146 m = RandomMaterial();3141 Material m = RandomMaterial(); 3147 3142 exporter->SetForcedMaterial(m); 3148 3149 BspNodeGeometry geom1, geom2; 3150 3151 ConstructGeometry(mc.GetLeaf1(), geom1); 3152 ConstructGeometry(mc.GetLeaf1(), geom2); 3153 3154 //m.mDiffuseColor.r = (mc.GetLeaf1()->GetViewCell()->GetId() & 256)/ 255.0f; 3155 //m.mDiffuseColor.g = ((mc.GetLeaf1()->GetViewCell()->GetId()>>8) & 256)/ 255.0f; 3156 //m.mDiffuseColor.b = ((mc.GetLeaf1()->GetViewCell()->GetId()>>16) & 256)/ 255.0f; 3157 exporter->SetForcedMaterial(m); 3158 exporter->ExportPolygons(geom1.mPolys); 3159 3160 //m.mDiffuseColor.r = (mc.GetLeaf2()->GetViewCell()->GetId() & 256)/ 255.0f; 3161 //m.mDiffuseColor.g = ((mc.GetLeaf2()->GetViewCell()->GetId()>>8) & 256)/ 255.0f; 3162 //m.mDiffuseColor.b = ((mc.GetLeaf2()->GetViewCell()->GetId()>>16) & 256)/ 255.0f; 3163 //exporter->SetForcedMaterial(m); 3164 exporter->ExportPolygons(geom2.mPolys); 3143 3144 3145 if (!mc.GetLeaf1()->Mailed()) 3146 { 3147 BspNodeGeometry geom1; 3148 ConstructGeometry(mc.GetLeaf1(), geom1); 3149 //m.mDiffuseColor.r = (mc.GetLeaf1()->GetViewCell()->GetId() & 256)/ 255.0f; 3150 //m.mDiffuseColor.g = ((mc.GetLeaf1()->GetViewCell()->GetId()>>8) & 256)/ 255.0f; 3151 //m.mDiffuseColor.b = ((mc.GetLeaf1()->GetViewCell()->GetId()>>16) & 256)/ 255.0f; 3152 //exporter->SetForcedMaterial(m); 3153 exporter->ExportPolygons(geom1.mPolys); 3154 mc.GetLeaf1()->Mail(); 3155 } 3156 3157 if (!mc.GetLeaf2()->Mailed()) 3158 { 3159 BspNodeGeometry geom2; 3160 ConstructGeometry(mc.GetLeaf2(), geom2); 3161 //m.mDiffuseColor.r = (mc.GetLeaf2()->GetViewCell()->GetId() & 256)/ 255.0f; 3162 //m.mDiffuseColor.g = ((mc.GetLeaf2()->GetViewCell()->GetId()>>8) & 256)/ 255.0f; 3163 //m.mDiffuseColor.b = ((mc.GetLeaf2()->GetViewCell()->GetId()>>16) & 256)/ 255.0f; 3164 //exporter->SetForcedMaterial(m); 3165 exporter->ExportPolygons(geom2.mPolys); 3166 mc.GetLeaf2()->Mail(); 3167 } 3165 3168 } 3166 3169 … … 3170 3173 delete exporter; 3171 3174 } 3172 3175 #else 3176 while (!mMergeQueue.empty()) 3177 { 3178 BspMergeCandidate mc = mMergeQueue.top(); 3179 shuffleQueue->push(mc); 3180 mMergeQueue.pop(); 3181 } 3182 #endif 3173 3183 const int numPasses = 5; 3174 3184 int pass = 0; 3175 3185 int passShuffled = 0; 3176 3186 int shuffled = 0; 3187 3188 BspLeaf::NewMail(); 3177 3189 3178 3190 do … … 3220 3232 } 3221 3233 3222 /*inline int SubtractedPvsSize(BspViewCell *vc, BspLeaf *l, const ObjectPvs &pvs2) 3234 3235 // recomputes pvs size minus pvs of leaf l 3236 #if 0 3237 inline int SubtractedPvsSize(BspViewCell *vc, BspLeaf *l, const ObjectPvs &pvs2) 3223 3238 { 3224 3239 ObjectPvs pvs; … … 3228 3243 pvs.AddPvs(*(*it)->mPvs); 3229 3244 return pvs.GetSize(); 3230 }*/ 3231 3245 } 3246 #endif 3247 3248 // computes pvs1 minus pvs2 3232 3249 inline int SubtractedPvsSize(ObjectPvs pvs1, const ObjectPvs &pvs2) 3233 3250 { … … 3240 3257 //const int pvs1 = SubtractedPvsSize(vc1, leaf, *leaf->mPvs); 3241 3258 const int pvs1 = SubtractedPvsSize(vc1->GetPvs(), *leaf->mPvs); 3259 3242 3260 const int pvs2 = AddedPvsSize(vc2->GetPvs(), *leaf->mPvs); 3243 3261 3244 // don t'shuffle leaves with pvs > max3262 // don't shuffle leaves with pvs > max 3245 3263 if (pvs1 + pvs2 > mViewCellsManager->GetMaxPvsSize()) 3246 3264 return 1e15f;
Note: See TracChangeset
for help on using the changeset viewer.