Changeset 580 for trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
- Timestamp:
- 02/01/06 19:29:59 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r569 r580 16 16 class VspKdLeaf; 17 17 class KdLeaf; 18 class ViewCellInterior; 19 class MergeCandidate; 20 class ViewCellsManager; 18 21 19 22 /** Statistics for a view cell partition. … … 78 81 }; 79 82 83 80 84 /** 81 85 View cell with an optional mesh representation 82 86 */ 87 88 83 89 class ViewCell: public MeshInstance 84 90 { … … 93 99 */ 94 100 virtual ~ViewCell() {} 101 95 102 /** Returns Pvs. 96 103 */ … … 100 107 int Type() const; 101 108 109 void SetParent(ViewCellInterior *parent); 110 102 111 /** Adds a passing ray to the passing ray container. 103 112 */ … … 124 133 virtual void UpdateViewCellsStats(ViewCellsStatistics &vcStat); 125 134 126 /// Ray set description of the rays passing through this node. 127 PassingRaySet mPassingRays; 135 /** if this view cell is the root of a view cell hierarchy 136 */ 137 bool IsRoot() const; 138 139 /** Returns parent view cell. 140 */ 141 ViewCellInterior *GetParent() const; 142 143 144 /** Sets the mesh for this view cell. 145 */ 146 void SetMesh(Mesh *mesh); 147 148 void SetValid(const bool valid); 149 bool GetValid() const; 150 151 152 153 154 /// parent view cell in the view cell hierarchy 155 ViewCellInterior *mParent; 128 156 129 157 /// Rays piercing this view cell. 130 158 RayContainer mPiercingRays; 131 159 132 /** Sets the mesh for this view cell. 133 */ 134 void SetMesh(Mesh *mesh); 135 136 void SetValid(const bool valid); 137 bool GetValid() const; 160 161 /** if this is a view cell correspending to a leaf in a hierarchy. 162 */ 163 virtual bool IsLeaf() const = 0; 138 164 139 165 static bool SmallerPvs(const ViewCell *a, … … 142 168 } 143 169 170 171 void SetTimeStamp(const int timeStamp); 172 int GetTimeStamp() const; 173 static void NewMail(const int reserve = 1) { 174 sMailId += sReservedMailboxes; 175 sReservedMailboxes = reserve; 176 } 177 void Mail() { mMailbox = sMailId; } 178 bool Mailed() const { return mMailbox == sMailId; } 179 180 void Mail(const int mailbox) { mMailbox = sMailId + mailbox; } 181 bool Mailed(const int mailbox) const { return mMailbox == sMailId + mailbox; } 182 183 int IncMail() { return ++mMailbox - sMailId; } 184 185 186 187 // last mail id -> warning not thread safe! 188 // both mailId and mailbox should be unique for each thread!!! 189 static int sMailId; 190 static int sReservedMailboxes; 191 192 144 193 protected: 145 194 … … 150 199 float mArea; 151 200 201 int mTimeStamp; 152 202 153 203 bool mValid; 204 }; 205 206 207 class ViewCellInterior: public ViewCell 208 { 209 public: 210 ViewCellInterior(); 211 ~ViewCellInterior(); 212 213 ViewCellInterior(Mesh *mesh); 214 215 216 /** Sets pointer from parent to child and vice versa. 217 */ 218 void SetupChildLink(ViewCell *l); 219 bool IsLeaf() const; 220 221 ViewCellContainer mChildren; 222 154 223 }; 155 224 … … 158 227 */ 159 228 template<typename T> 160 class HierarchyViewCell: public ViewCell229 class ViewCellLeaf: public ViewCell 161 230 { 162 231 public: 163 HierarchyViewCell<T>(): mLeaves(0) {} 164 HierarchyViewCell<T>(Mesh *mesh): 165 ViewCell(mesh), mLeaves(0) {} 232 233 ViewCellLeaf<T>(): mLeaf(NULL) {} 234 ViewCellLeaf<T>(Mesh *mesh): 235 ViewCell(mesh), mLeaf(NULL) {} 166 236 167 237 void UpdateViewCellsStats(ViewCellsStatistics &vcStat) … … 169 239 ViewCell::UpdateViewCellsStats(vcStat); 170 240 171 if ((int)mLeaves.size() > vcStat.maxLeaves) 172 vcStat.maxLeaves = (int)mLeaves.size(); 173 vcStat.leaves += (int)mLeaves.size(); 174 } 175 176 /// Leaves of the hierarchy which are part of this view cell. 177 std::vector<T> mLeaves; 178 }; 179 180 181 typedef HierarchyViewCell<BspLeaf *> BspViewCell; 182 typedef HierarchyViewCell<KdLeaf *> KdViewCell; 183 typedef HierarchyViewCell<VspKdLeaf *> VspKdViewCell; 184 241 //if ((int)mLeaves.size() > vcStat.maxLeaves) 242 // vcStat.maxLeaves = (int)mLeaves.size(); 243 //vcStat.leaves += (int)mLeaves.size(); 244 } 245 246 bool IsLeaf() const 247 { 248 return true; 249 } 250 251 /// Leaf of some hierarchy which is part of this view cell. 252 T mLeaf; 253 }; 254 255 256 typedef ViewCellLeaf<BspLeaf *> BspViewCell; 257 typedef ViewCellLeaf<KdLeaf *> KdViewCell; 258 typedef ViewCellLeaf<VspKdLeaf *> VspKdViewCell; 259 260 261 262 class ViewCellsTree 263 { 264 public: 265 ViewCellsTree(ViewCellsManager *vcm); 266 ~ViewCellsTree(); 267 268 /** Returns number of leaves this view cell consists of. 269 */ 270 int GetSize(ViewCell *vc) const; 271 272 /** Collects leaves corresponding to a view cell. 273 */ 274 void CollectLeaves(ViewCell *vc, ViewCellContainer &leaves) const; 275 276 /** Merges view cells according to some cost heuristics. 277 */ 278 int ConstructMergeTree(const VssRayContainer &rays, const ObjectContainer &objects); 279 280 /** Refines view cells using shuffling, i.e., border leaves 281 of two view cells are exchanged if the resulting view cells 282 are tested to be "better" than the old ones. 283 @returns number of refined view cells 284 */ 285 int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 286 287 /** Compresses the pvs of the view cells. 288 */ 289 void CompressViewCellsPvs(); 290 291 /** Returns optimal set of view cells for a given number of view cells. 292 */ 293 void CollectBestViewCellSet(ViewCellContainer &viewCells, const int numViewCells); 294 295 protected: 296 297 298 ////////////////////////////////////////////////////////////// 299 // merge options // 300 ////////////////////////////////////////////////////////////// 301 302 303 /** Returns cost of this leaf according to current heuristics. 304 */ 305 float GetCostHeuristics(ViewCell *vc) const; 306 307 /** Returns cost of leaf. 308 */ 309 float GetRenderCost(ViewCell *vc) const; 310 311 /** Evaluates the merge cost of this merge candidate pair. 312 */ 313 void EvalMergeCost(MergeCandidate &mc) const; 314 315 /** Variance of leaf. 316 */ 317 float GetVariance(ViewCell *vc) const; 318 319 /** Standard deviation of leaf. 320 */ 321 float GetDeviation(ViewCell *vc) const; 322 323 /** Recalculates this merge candidate and sets valid. 324 */ 325 void SetMergeCandidateValid(MergeCandidate &mc) const; 326 327 /** Merge view cells of leaves l1 and l2. 328 @returns difference in pvs size 329 */ 330 ViewCellInterior *MergeViewCells(ViewCell *l, ViewCell *r, int &pvsDiff); //const; 331 332 /** Shuffles, i.e. takes border leaf from view cell 1 and adds it 333 to view cell 2. 334 */ 335 void ShuffleLeaf(ViewCell *leaf, ViewCell *vc1, ViewCell *vc2) const; 336 337 /** Shuffles the leaves, i.e., tests if exchanging 338 the leaves helps in improving the view cells. 339 */ 340 bool ShuffleLeaves(ViewCell *l, ViewCell *r) const; 341 342 /** Calculates cost for merge of view cell 1 and 2. 343 */ 344 float EvalShuffleCost(ViewCell *leaf, ViewCell *vc1, ViewCell *vc2) const; 345 346 /** Exports a snapshot of the merged view cells to disc. 347 */ 348 void ExportMergedViewCells(ViewCellContainer &viewCells, 349 const ObjectContainer &objects, 350 const int numNewViewCells); 351 352 353 354 /** merge queue must be reset after some time because expected value 355 may not be valid. 356 */ 357 void ResetMergeQueue(); 358 359 /** Updates the current top level of view cells. 360 */ 361 int UpdateMergedViewCells(ViewCellContainer &viewCells); 362 363 364 365 ViewCellsManager *mViewCellsManager; 366 ViewCell *mRoot; 367 368 /// if merge visualization should be shown 369 bool mExportMergedViewCells; 370 371 372 373 ViewCellContainer mInactiveViewCells; 374 ViewCellContainer mActiveViewCells; 375 376 /// weights between variance and render cost increase (must be between zero and one) 377 float mRenderCostWeight; 378 379 /// overall cost used to normalize cost ratio 380 float mOverallCost; 381 float mExpectedCost; 382 float mDeviation; 383 float mAvgRenderCost; 384 385 int mUseAreaForPvs; 386 387 int mNumViewCells; 388 389 /// minimal number of view cells 390 int mMergeMinViewCells; 391 /// maximal cost ratio for the merge 392 float mMergeMaxCostRatio; 393 394 ofstream mStats; 395 396 typedef priority_queue<MergeCandidate> MergeQueue; 397 398 MergeQueue mMergeQueue; 399 400 401 402 }; 403 404 405 /** 406 Candidate for leaf merging based on priority. 407 */ 408 class MergeCandidate 409 { 410 friend class ViewCellsTree; 411 412 public: 413 414 MergeCandidate(ViewCell *l, ViewCell *r); 415 416 /** If this merge pair is still valid. 417 */ 418 bool IsValid() const; 419 420 421 friend bool operator<(const MergeCandidate &leafa, const MergeCandidate &leafb) 422 { 423 return leafb.GetMergeCost() < leafa.GetMergeCost(); 424 } 425 426 void SetLeftViewCell(ViewCell *l); 427 void SetRightViewCell(ViewCell *l); 428 429 ViewCell *GetLeftViewCell() const; 430 ViewCell *GetRightViewCell() const; 431 432 ViewCell *GetInitialLeftViewCell() const; 433 ViewCell *GetInitialRightViewCell() const; 434 435 /** Returns the increase of the standard deviation of this merge candidate. 436 */ 437 float GetDeviationIncr() const; 438 439 /** Merge cost of this candidate pair. 440 */ 441 float GetMergeCost() const; 442 443 /** Render cost of this candidate. 444 */ 445 float GetRenderCost() const; 446 447 static float sRenderCostWeight; 448 449 protected: 450 451 /// render cost increase by this merge 452 float mRenderCost; 453 /// increase / decrease of standard deviation 454 float mDeviationIncr; 455 456 ViewCell *mLeftViewCell; 457 ViewCell *mRightViewCell; 458 459 ViewCell *mInitialLeftViewCell; 460 ViewCell *mInitialRightViewCell; 461 }; 462 463 464 class MergeStatistics: public StatisticsBase 465 { 466 public: 467 468 int merged; 469 int siblings; 470 int candidates; 471 int nodes; 472 473 int accTreeDist; 474 int maxTreeDist; 475 476 Real collectTime; 477 Real mergeTime; 478 479 Real overallCost; 480 481 Real expectedRenderCost; 482 Real deviation; 483 Real heuristics; 484 485 // Constructor 486 MergeStatistics() 487 { 488 Reset(); 489 } 490 491 double AvgTreeDist() const {return (double)accTreeDist / (double)merged;}; 492 493 void Reset() 494 { 495 nodes = 0; 496 merged = 0; 497 siblings = 0; 498 candidates = 0; 499 500 accTreeDist = 0; 501 maxTreeDist = 0; 502 503 collectTime = 0; 504 mergeTime = 0; 505 overallCost = 0; 506 507 expectedRenderCost = 0; 508 deviation = 0; 509 heuristics = 0; 510 511 } 512 513 void Print(ostream &app) const; 514 515 friend ostream &operator<<(ostream &s, const MergeStatistics &stat) 516 { 517 stat.Print(s); 518 return s; 519 } 520 }; 185 521 186 522 #endif
Note: See TracChangeset
for help on using the changeset viewer.