- Timestamp:
- 01/23/06 15:44:19 (18 years ago)
- File:
-
- 1 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
Note: See TracChangeset
for help on using the changeset viewer.