Changeset 2017 for GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
- Timestamp:
- 01/22/07 23:35:03 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r2015 r2017 238 238 mEvaluationSamplingType = SamplingStrategy::REVERSE_OBJECT_BASED_DISTRIBUTION; 239 239 } 240 /*else if (strcmp(buf, "interior") == 0)241 {242 mEvaluationSamplingType = SamplingStrategy::OBJECTS_INTERIOR_DISTRIBUTION;243 }*/244 240 else 245 241 { … … 311 307 312 308 309 ViewCell *ViewCellsManager::GetViewCellById(const int id) 310 { 311 ViewCellContainer::const_iterator vit, vit_end = mViewCells.end(); 312 313 for (vit = mViewCells.begin(); vit != vit_end; ++ vit) 314 { 315 if ((*vit)->GetId() == id) 316 return (*vit); 317 } 318 return NULL; 319 } 320 321 322 bool ViewCellsManager::ExportRandomViewCells(const string &filename, 323 const vector<ViewCellPoints *> &viewCells) 324 { 325 std::ofstream outStream; 326 outStream.open(filename.c_str()); 327 328 vector<ViewCellPoints *>::const_iterator vit, vit_end = viewCells.end(); 329 330 for (vit = viewCells.begin(); vit != vit_end; ++ vit) 331 { 332 ViewCell *vc = (*vit)->first; 333 334 outStream << "v " << vc->GetId() << endl; 335 336 SimpleRayContainer viewPoints; 337 338 SimpleRayContainer::const_iterator pit, pit_end = (*vit)->second.end(); 339 340 for (pit = (*vit)->second.begin(); pit != pit_end; ++ pit) 341 { 342 const Vector3 pt = (*pit).mOrigin; 343 const Vector3 dir = (*pit).mDirection; 344 345 outStream << "p " << pt.x << " " << pt.y << " " << pt.z 346 << " " << dir.x << " " << dir.y << " " << dir.z << endl; 347 } 348 } 349 350 return true; 351 } 352 353 354 bool ViewCellsManager::GenerateRandomViewCells(vector<ViewCellPoints *> &viewCells, 355 const int nViewCells, 356 const int nViewPoints) 357 { 358 ViewCellContainer rViewCells; 359 360 cout << "generating " << nViewCells << " random view cells" << endl; 361 GenerateRandomViewCells(rViewCells, nViewCells); 362 363 cout << "finished" << endl; 364 365 //for (int i = 0; i < viewCells.size(); ++ i) 366 // cout << "vc " << i << ": " << viewCells[i]->GetId() << endl; 367 368 cout << "generating " << nViewPoints << " view points per view cell" << endl; 369 ViewCellContainer::const_iterator vit, vit_end = rViewCells.end(); 370 371 for (vit = rViewCells.begin(); vit != vit_end; ++ vit) 372 { 373 ViewCell *vc = *vit; 374 375 ViewCellPoints *vcPts = new ViewCellPoints(); 376 viewCells.push_back(vcPts); 377 378 vcPts->first = vc; 379 380 SimpleRayContainer viewPoints; 381 // generate random view points 382 GenerateViewPoints(vc, nViewPoints, viewPoints); 383 384 SimpleRayContainer::const_iterator pit, pit_end = viewPoints.end(); 385 386 for (pit = viewPoints.begin(); pit != pit_end; ++ pit) 387 { 388 vcPts->second.push_back(*pit); 389 } 390 } 391 392 return true; 393 } 394 395 396 bool ViewCellsManager::ImportRandomViewCells(const string &filename, 397 vector<ViewCellPoints *> &viewCells) 398 { 399 ifstream inStream(filename.c_str()); 400 if (!inStream.is_open()) 401 return false; 402 403 ViewCellPoints *currentViewCell = NULL; 404 405 string buf; 406 while (!(getline(inStream, buf)).eof()) 407 { 408 switch (buf[0]) 409 { 410 case 'v': 411 { 412 int id; 413 sscanf(buf.c_str(), "v %d", &id); 414 415 currentViewCell = new ViewCellPoints(); 416 currentViewCell->first = GetViewCellById(id); 417 418 viewCells.push_back(currentViewCell); 419 break; 420 } 421 case 'p': 422 { 423 Vector3 pt, dir; 424 sscanf(buf.c_str(), "p %f %f %f %f %f %f", &pt.x, &pt.y, &pt.z, &dir.x, &dir.y, &dir.z); 425 426 SimpleRay ray(pt, dir, 0, 1); 427 currentViewCell->second.push_back(ray); 428 break; 429 } 430 default: 431 break; 432 } 433 } 434 435 return true; 436 } 437 438 439 bool ViewCellsManager::GenerateViewPoints(ViewCell *viewCell, 440 const int numViewPoints, 441 SimpleRayContainer &viewPoints) 442 { 443 bool success = true; 444 int generatedPts = 0; 445 int i = 0; 446 447 while (generatedPts < numViewPoints) 448 { 449 SimpleRay pt; 450 451 if (GenerateViewPoint(viewCell, pt)) 452 { 453 ++ generatedPts; 454 viewPoints.push_back(pt); 455 } 456 457 // savety criterium 458 if (++ i > numViewPoints + 100000) 459 { 460 return false; 461 } 462 } 463 464 return true; 465 } 466 467 468 bool ViewCellsManager::GenerateViewPoint(ViewCell *viewCell, 469 SimpleRay &ray) 470 { 471 // do not use this function since it could return different viewpoints for 472 // different executions of the algorithm 473 int tries = 0; 474 Vector3 viewPoint, direction; 475 const int maxTries = 100; 476 477 while (1) 478 { 479 // hack 480 if (!viewCell->GetMesh()) 481 CreateMesh(viewCell); 482 483 Mesh *mesh = viewCell->GetMesh(); 484 AxisAlignedBox3 box = mesh->mBox; 485 //cout <<"box: " << box << endl; 486 /*Vector3 pVector = Vector3(halton.GetNumber(1), 487 halton.GetNumber(2), 488 halton.GetNumber(3));*/ 489 490 Vector3 pVector = Vector3(Random(1.0f), 491 Random(1.0f), 492 Random(1.0f)); 493 494 viewPoint = box.GetPoint(pVector); 495 496 //const Vector3 dVector = Vector3(2 * M_PI * halton.GetNumber(4), M_PI*halton.GetNumber(5),0.0f); 497 const Vector3 dVector = Vector3(2 * M_PI * Random(1.0f), M_PI * Random(1.0f), 0.0f); 498 direction = Normalize(Vector3(sin(dVector.x), 0.0f, cos(dVector.x))); 499 //halton.GenerateNext(); 500 501 //cout << "vp: " << viewPoint << endl; 502 //cout << "dir: " << direction << endl; 503 504 ViewCell *v = GetViewCell(viewPoint); 505 506 if (v && v->GetValid()) 507 { 508 //cout << "validating view point" << endl; 509 510 mPreprocessor->GetRenderer()->mViewPoint = viewPoint; 511 mPreprocessor->GetRenderer()->mViewDirection = direction; 512 513 if (mPreprocessor->GetRenderer()->ValidViewPoint()) 514 { 515 cout << "view point valid" << endl; 516 break; 517 } 518 } 519 520 // generate a new vector 521 //halton.GenerateNext(); 522 523 //if (!box.IsInside(viewPoint)) 524 // cout << "error!" << endl; 525 if (++ tries > maxTries) 526 return false; 527 } 528 529 ray = SimpleRay(viewPoint, direction, 0, 1); 530 //cout << "view point generated: " << viewPoint << " " << direction << endl; 531 532 return true; 533 } 534 535 536 bool ViewCellsManager::IsValidViewSpace(ViewCell *vc) 537 { 538 SimpleRay simpleRay; 539 //check if view point can be generated 540 return GenerateViewPoint(vc, simpleRay); 541 } 542 543 544 bool ViewCellsManager::GenerateRandomViewCells(ViewCellContainer &viewCells, 545 const int numViewCells) 546 { 547 int generatedViewCells = 0; 548 //HaltonSequence halton; 549 //float r[1]; 550 551 ViewCell::NewMail(); 552 553 while (generatedViewCells < numViewCells) 554 { 555 // savety criterium 556 const int tries = 100000 + generatedViewCells; 557 int i = 0; 558 559 // generate next view cell 560 while (1) 561 { 562 //halton.GetNext(1, r); 563 //const int idx = (int)(r[0] * mViewCells.size() - 1.0f); 564 const int idx = (int)RandomValue(0.0f, (float)mViewCells.size() - 0.5f); 565 566 ViewCell *viewCell = GetViewCell(idx); 567 568 if (!viewCell->Mailed()) 569 { 570 viewCell->Mail(); 571 572 // check for valid view space 573 if (IsValidViewSpace(viewCell)) 574 { 575 // valid view cell found 576 viewCells.push_back(viewCell); 577 578 ++ generatedViewCells; 579 //cout << "view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl; 580 break; 581 } 582 else 583 { 584 cout << "error: invalid view cell " << generatedViewCells << " generated: " << viewCell->GetId() << endl; 585 } 586 } 587 588 if (++ i == tries) // no new view cell fond 589 { 590 cerr << "big error! no view cell found" << endl; 591 return false; 592 } 593 } 594 } 595 596 return true; 597 } 598 599 313 600 ViewCellsManager::~ViewCellsManager() 314 601 { … … 575 862 mRenderer->RenderScene(); 576 863 SimulationStatistics ss; 577 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);864 static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 578 865 579 866 Debug << ss << endl; … … 1616 1903 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1617 1904 { 1618 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit);1905 TransformedMeshInstance *mit = static_cast<TransformedMeshInstance *>(*oit); 1619 1906 mesh = MeshManager::GetSingleton()->CreateResource(); 1620 1907 mit->GetTransformedMesh(*mesh); … … 1622 1909 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1623 1910 { 1624 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit);1911 MeshInstance *mit = static_cast<MeshInstance *>(*oit); 1625 1912 mesh = mit->GetMesh(); 1626 1913 } … … 2608 2895 for (lit = leaves.begin(); lit != lit_end; ++ lit) 2609 2896 { 2610 dynamic_cast<ViewCellLeaf *>(*lit)->SetActiveViewCell(vc);2897 static_cast<ViewCellLeaf *>(*lit)->SetActiveViewCell(vc); 2611 2898 } 2612 2899 } … … 2648 2935 for (it = objects.begin(); it != it_end; ++ it) 2649 2936 { 2650 MeshInstance *mi = dynamic_cast<MeshInstance *>(*it);2937 MeshInstance *mi = static_cast<MeshInstance *>(*it); 2651 2938 const AxisAlignedBox3 box = mi->GetBox(); 2652 2939 … … 2671 2958 for (it = objects.begin(); it != it_end; ++ it) 2672 2959 { 2673 MeshInstance *mi = dynamic_cast<MeshInstance *>(*it);2960 MeshInstance *mi = static_cast<MeshInstance *>(*it); 2674 2961 const AxisAlignedBox3 box = mi->GetBox(); 2675 2962 Vector3 bmin = box.Min(); … … 3252 3539 //-- interior node => propagate pvs up the tree 3253 3540 3254 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(root);3541 ViewCellInterior *interior = static_cast<ViewCellInterior *>(root); 3255 3542 3256 3543 // reset interior pvs … … 3920 4207 3921 4208 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 3922 4209 3923 4210 IncludeNodeGeomInMesh(geom, *mesh); 4211 mesh->ComputeBoundingBox(); 4212 3924 4213 vc->SetMesh(mesh); 3925 4214 } … … 4101 4390 if (root->IsLeaf()) 4102 4391 { 4103 BspLeaf *leaf = dynamic_cast<BspLeaf *>(root);4392 BspLeaf *leaf = static_cast<BspLeaf *>(root); 4104 4393 leaf->GetViewCell()->SetMergeCost(0.0f); 4105 4394 return leaf->GetViewCell(); 4106 4395 } 4107 4396 4108 BspInterior *interior = dynamic_cast<BspInterior *>(root);4397 BspInterior *interior = static_cast<BspInterior *>(root); 4109 4398 ViewCellInterior *viewCellInterior = new ViewCellInterior(); 4110 4399 … … 4243 4532 4244 4533 for (int i = 0; i < leafOut; ++ i) 4245 kdLeaves.push_back( dynamic_cast<KdLeaf *>(mKdTree->GetRandomLeaf()));4534 kdLeaves.push_back(static_cast<KdLeaf *>(mKdTree->GetRandomLeaf())); 4246 4535 4247 4536 for (int i = 0; i < kdLeaves.size(); ++ i) … … 4406 4695 for (it = leaves.begin(); it != it_end; ++ it) 4407 4696 { 4408 KdViewCell *kdVc = dynamic_cast<KdViewCell *>(*it);4697 KdViewCell *kdVc = static_cast<KdViewCell *>(*it); 4409 4698 exporter->ExportBox(mKdTree->GetBox(kdVc->mLeaves[0])); 4410 4699 } … … 4746 5035 4747 5036 SimulationStatistics ss; 4748 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);5037 static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 4749 5038 Debug << "render time before refine\n\n" << ss << endl; 4750 5039 … … 4826 5115 4827 5116 cout << "\nview cells partition render time before compress" << endl << endl;; 4828 dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene();5117 static_cast<RenderSimulator *>(mRenderer)->RenderScene(); 4829 5118 SimulationStatistics ss; 4830 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);5119 static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 4831 5120 cout << ss << endl; 4832 5121 … … 4857 5146 if (root->IsLeaf()) 4858 5147 { 4859 BspLeaf *leaf = dynamic_cast<BspLeaf *>(root);5148 BspLeaf *leaf = static_cast<BspLeaf *>(root); 4860 5149 leaf->GetViewCell()->SetMergeCost(0.0f); 4861 5150 return leaf->GetViewCell(); … … 4863 5152 4864 5153 4865 BspInterior *interior = dynamic_cast<BspInterior *>(root);5154 BspInterior *interior = static_cast<BspInterior *>(root); 4866 5155 ViewCellInterior *viewCellInterior = new ViewCellInterior(); 4867 5156 … … 5095 5384 for (vit = leaves.begin(); vit != vit_end; ++ vit) 5096 5385 { 5097 BspLeaf *vcLeaf = dynamic_cast<BspViewCell *>(*vit)->mLeaves[0];5386 BspLeaf *vcLeaf = static_cast<BspViewCell *>(*vit)->mLeaves[0]; 5098 5387 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 5099 5388 … … 5387 5676 for (int j = 0; j < (int)leaves.size(); ++ j) 5388 5677 { 5389 BspLeaf *leaf = dynamic_cast<BspViewCell *>(leaves[i])->mLeaves[0];5678 BspLeaf *leaf = static_cast<BspViewCell *>(leaves[i])->mLeaves[0]; 5390 5679 5391 5680 if (i != j) 5392 5681 { 5393 BspLeaf *leaf2 = dynamic_cast<BspViewCell *>(leaves[j])->mLeaves[0];5682 BspLeaf *leaf2 =static_cast<BspViewCell *>(leaves[j])->mLeaves[0]; 5394 5683 const int dist = mVspBspTree->TreeDistance(leaf, leaf2); 5395 5684 … … 5422 5711 5423 5712 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 5713 5424 5714 IncludeNodeGeomInMesh(geom, *mesh); 5715 mesh->ComputeBoundingBox(); 5425 5716 5426 5717 vc->SetMesh(mesh); … … 5500 5791 { 5501 5792 // TODO: do I still need this here? 5502 if (0) 5503 mVspBspTree->RepairViewCellsLeafLists(); 5793 if (0) mVspBspTree->RepairViewCellsLeafLists(); 5504 5794 } 5505 5795 … … 5748 6038 5749 6039 cout << "\nview cells partition render time before compress" << endl << endl; 5750 dynamic_cast<RenderSimulator *>(mRenderer)->RenderScene();6040 static_cast<RenderSimulator *>(mRenderer)->RenderScene(); 5751 6041 SimulationStatistics ss; 5752 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);6042 static_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 5753 6043 cout << ss << endl; 5754 6044 … … 5782 6072 if (root->IsLeaf()) 5783 6073 { 5784 VspLeaf *leaf = dynamic_cast<VspLeaf *>(root);6074 VspLeaf *leaf = static_cast<VspLeaf *>(root); 5785 6075 leaf->GetViewCell()->SetMergeCost(0.0f); 5786 6076 return leaf->GetViewCell(); 5787 6077 } 5788 6078 5789 VspInterior *interior = dynamic_cast<VspInterior *>(root);6079 VspInterior *interior = static_cast<VspInterior *>(root); 5790 6080 ViewCellInterior *viewCellInterior = new ViewCellInterior(); 5791 6081 … … 5861 6151 for (it = leaves.begin(); it != it_end; ++ it) 5862 6152 { 5863 VspViewCell *vspVc = dynamic_cast<VspViewCell *>(*it);6153 VspViewCell *vspVc = static_cast<VspViewCell *>(*it); 5864 6154 VspLeaf *l = vspVc->mLeaves[0]; 5865 6155 … … 5927 6217 ObjectPvsEntry entry = pit.Next(); 5928 6218 5929 BvhNode *node = dynamic_cast<BvhNode *>(entry.mObject);6219 BvhNode *node = static_cast<BvhNode *>(entry.mObject); 5930 6220 5931 6221 // hack!! … … 6165 6455 for (vit = leaves.begin(); vit != vit_end; ++ vit) 6166 6456 { 6167 VspLeaf *vcLeaf = dynamic_cast<VspViewCell *>(*vit)->mLeaves[0];6457 VspLeaf *vcLeaf = static_cast<VspViewCell *>(*vit)->mLeaves[0]; 6168 6458 VssRayContainer::const_iterator rit, rit_end = vcLeaf->mVssRays.end(); 6169 6459 … … 6311 6601 void VspOspViewCellsManager::CreateMesh(ViewCell *vc) 6312 6602 { 6313 // matt: TODO6314 6603 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 6315 6604 6316 6605 ViewCellContainer leaves; 6317 6606 mViewCellsTree->CollectLeaves(vc, leaves); … … 6321 6610 for (it = leaves.begin(); it != it_end; ++ it) 6322 6611 { 6323 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0];6612 VspLeaf *leaf = static_cast<VspViewCell *>(*it)->mLeaves[0]; 6324 6613 const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf); 6325 6614 IncludeBoxInMesh(box, *mesh); 6326 6615 } 6327 6616 6617 mesh->ComputeBoundingBox(); 6618 6328 6619 vc->SetMesh(mesh); 6329 6620 } … … 6349 6640 for (it = leaves.begin(); it != it_end; ++ it) 6350 6641 { 6351 VspLeaf *leaf = dynamic_cast<VspViewCell *>(*it)->mLeaves[0];6642 VspLeaf *leaf = static_cast<VspViewCell *>(*it)->mLeaves[0]; 6352 6643 6353 6644 const AxisAlignedBox3 box = mHierarchyManager->GetVspTree()->GetBoundingBox(leaf);
Note: See TracChangeset
for help on using the changeset viewer.