Changeset 1563 for GTP/trunk/Lib
- Timestamp:
- 10/03/06 22:03:58 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing
- Files:
-
- 2 added
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/FrontEnd/preprocessorFrontEnd.cpp
r1558 r1563 31 31 IMPLEMENT_APP(MyApp) 32 32 33 33 34 bool MyApp::OnInit() 34 35 { 35 36 // Create the main window 36 MyFrame *frame = new MyFrame( wxT("Notebook sample"));37 MyFrame *frame = new MyFrame(wxT("Preprocessor Frontend")); 37 38 38 39 // Problem with generic wxNotebook implementation whereby it doesn't size 39 40 // properly unless you set the size again 40 #if defined(__WXMOTIF__) 41 //#if defined(__WXMOTIF__) 42 // frame->SetSize(wxDefaultCoord, wxDefaultCoord, 1024, 768); 41 43 int width, height; 42 frame->GetSize(& width, &height);44 frame->GetSize(&width, &height); 43 45 frame->SetSize(wxDefaultCoord, wxDefaultCoord, width, height); 44 #endif46 //#endif 45 47 46 48 frame->Show(); … … 49 51 } 50 52 51 wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent) 53 54 wxPanel *MyFrame::CreateUserCreatedPage(wxBookCtrlBase *parent) 52 55 { 53 56 wxPanel *panel = new wxPanel(parent); 54 57 55 (void) new wxButton( 56 wxPoint(10, 10), wxDefaultSize 58 (void) new wxButton(panel, wxID_ANY, wxT("Button"), 59 wxPoint(10, 10), wxDefaultSize); 57 60 58 61 return panel; 59 62 } 60 63 61 wxPanel *CreateRadioButtonsPage(wxBookCtrlBase *parent) 64 65 wxPanel *MyFrame::CreatePreprocessorPage(wxBookCtrlBase *parent) 62 66 { 63 67 wxPanel *panel = new wxPanel(parent); 64 68 65 wxString animals[] = { wxT("Fox"), wxT("Hare"), wxT("Rabbit"), 66 wxT("Sabre-toothed tiger"), wxT("T Rex") }; 67 68 wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose one"), 69 wxDefaultPosition, wxDefaultSize, 5, animals, 2, wxRA_SPECIFY_ROWS); 70 71 wxString computers[] = { wxT("Amiga"), wxT("Commodore 64"), wxT("PET"), 72 wxT("Another") }; 73 74 wxRadioBox *radiobox2 = new wxRadioBox(panel, wxID_ANY, 75 wxT("Choose your favourite"), wxDefaultPosition, wxDefaultSize, 76 4, computers, 0, wxRA_SPECIFY_COLS); 69 wxString preprocessorType[] = {wxT("Rss"), wxT("Gvs"), wxT("None")}; 70 71 wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose preprocessor type"), 72 wxDefaultPosition, wxDefaultSize, 3, preprocessorType, 1, wxRA_SPECIFY_ROWS); 73 74 mDetectEmptyViewSpaceText = new wxTextCtrl(panel, wxID_ANY, "detect emtpy view space", 75 wxDefaultPosition, wxDefaultSize); 76 77 //mDetectEmptyViewSpaceCheckBox = new wxCheckBox(panel, wxID_ANY); 77 78 78 79 wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); 79 sizerPanel->Add(radiobox1, 2, wxEXPAND); 80 sizerPanel->Add(radiobox2, 1, wxEXPAND); 80 sizerPanel->Add(radiobox1, 1, wxEXPAND); 81 sizerPanel->Add(mDetectEmptyViewSpaceText, 1); 82 sizerPanel->Add(mDetectEmptyViewSpaceCheckBox, 1); 83 81 84 panel->SetSizer(sizerPanel); 82 85 … … 84 87 } 85 88 86 wxPanel *CreateVetoPage(wxBookCtrlBase *parent) 89 90 wxPanel *MyFrame::CreateViewCellsPage(wxBookCtrlBase *parent) 91 { 92 wxPanel *panel = new wxPanel(parent); 93 94 wxString viewSpaceHierarchy[] = {wxT("vspBsp"), wxT("vspOsp"), wxT("bsp")}; 95 96 wxRadioBox *radiobox1 = new wxRadioBox(panel, wxID_ANY, wxT("Choose view space hierarchy type"), 97 wxDefaultPosition, wxDefaultSize, 3, viewSpaceHierarchy, 1, wxRA_SPECIFY_ROWS); 98 99 wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); 100 sizerPanel->Add(radiobox1, 1, wxEXPAND); 101 panel->SetSizer(sizerPanel); 102 103 return panel; 104 } 105 106 107 /*wxPanel *CreateVetoPage(wxBookCtrlBase *parent) 87 108 { 88 109 wxPanel *panel = new wxPanel(parent); … … 92 113 93 114 return panel; 94 } 95 96 wxPanel *CreateBigButtonPage(wxBookCtrlBase *parent) 97 { 98 wxPanel *panel = new wxPanel(parent); 99 100 wxButton *buttonBig = new wxButton(panel, wxID_ANY, wxT("Maximized button")); 101 102 wxBoxSizer *sizerPanel = new wxBoxSizer(wxVERTICAL); 103 sizerPanel->Add(buttonBig, 1, wxEXPAND); 104 panel->SetSizer(sizerPanel); 105 106 return panel; 107 } 108 109 110 wxPanel *CreateInsertPage(wxBookCtrlBase *parent) 115 }*/ 116 117 118 /*wxPanel *CreateInsertPage(wxBookCtrlBase *parent) 111 119 { 112 120 wxPanel *panel = new wxPanel(parent); … … 117 125 118 126 return panel; 119 } 127 }*/ 128 120 129 121 130 int GetIconIndex(wxBookCtrlBase* bookCtrl) … … 133 142 } 134 143 135 void CreateInitialPages(wxBookCtrlBase *parent) 144 145 void MyFrame::CreateInitialPages(wxBookCtrlBase *parent) 136 146 { 137 147 // Create and add some panels to the notebook 138 139 wxPanel *panel = CreateRadioButtonsPage(parent); 140 parent->AddPage( panel, RADIOBUTTONS_PAGE_NAME, false, GetIconIndex(parent) ); 141 142 panel = CreateVetoPage(parent); 143 parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) ); 144 145 panel = CreateBigButtonPage(parent); 146 parent->AddPage( panel, MAXIMIZED_BUTTON_PAGE_NAME, false, GetIconIndex(parent) ); 147 148 panel = CreateInsertPage(parent); 149 parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) ); 148 wxPanel *panel = CreatePreprocessorPage(parent); 149 parent->AddPage(panel, PREPROCESSOR_PAGE_NAME, false, GetIconIndex(parent)); 150 151 panel = CreateViewCellsPage(parent); 152 parent->AddPage(panel, VIEWCELLS_PAGE_NAME, false, GetIconIndex(parent)); 153 154 //panel = CreateVetoPage(parent); 155 //parent->AddPage( panel, VETO_PAGE_NAME, false, GetIconIndex(parent) ); 156 157 //panel = CreateInsertPage(parent); 158 //parent->InsertPage( 0, panel, I_WAS_INSERTED_PAGE_NAME, false, GetIconIndex(parent) ); 150 159 151 160 parent->SetSelection(1); 152 161 } 153 162 154 wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName) 155 { 156 if 157 ( 158 pageName.Contains(INSERTED_PAGE_NAME) 159 || pageName.Contains(ADDED_PAGE_NAME) 160 ) 161 { 162 return CreateUserCreatedPage(parent); 163 } 164 165 if (pageName == I_WAS_INSERTED_PAGE_NAME) 166 { 167 return CreateInsertPage(parent); 168 } 169 170 if (pageName == VETO_PAGE_NAME) 171 { 172 return CreateVetoPage(parent); 173 } 174 175 if (pageName == RADIOBUTTONS_PAGE_NAME) 176 { 177 return CreateRadioButtonsPage(parent); 178 } 179 180 181 if (pageName == MAXIMIZED_BUTTON_PAGE_NAME) 182 { 183 return CreateBigButtonPage(parent); 163 164 wxPanel *MyFrame::CreatePage(wxBookCtrlBase *parent, const wxString&pageName) 165 { 166 167 if (pageName == VIEWCELLS_PAGE_NAME) 168 { 169 return CreateViewCellsPage(parent); 170 } 171 172 if (pageName == PREPROCESSOR_PAGE_NAME) 173 { 174 return CreatePreprocessorPage(parent); 184 175 } 185 176 … … 189 180 } 190 181 191 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size, 182 MyFrame::MyFrame(const wxString& title, 183 const wxPoint& pos, 184 const wxSize& size, 192 185 long style) 193 186 : wxFrame((wxWindow *) NULL, wxID_ANY, title, pos, size, style) 194 187 { 195 188 #if wxUSE_NOTEBOOK 196 m _type = ID_BOOK_NOTEBOOK;189 mType = ID_BOOK_NOTEBOOK; 197 190 #elif wxUSE_CHOICEBOOK 198 m _type = ID_BOOK_CHOICEBOOK;191 mType = ID_BOOK_CHOICEBOOK; 199 192 #elif wxUSE_LISTBOOK 200 m _type = ID_BOOK_LISTBOOK;193 mType = ID_BOOK_LISTBOOK; 201 194 #elif 202 195 #error "Don't use Notebook sample without any book enabled in wxWidgets build!" 203 196 #endif 204 197 205 m _orient = ID_ORIENT_DEFAULT;206 m _chkShowImages = true;207 m _multi = false;198 mOrient = ID_ORIENT_DEFAULT; 199 mChkShowImages = true; 200 mMulti = false; 208 201 209 202 SetIcon(wxICON(sample)); … … 212 205 wxMenu *menuType = new wxMenu; 213 206 #if wxUSE_NOTEBOOK 214 menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, 207 menuType->AppendRadioItem(ID_BOOK_NOTEBOOK, wxT("&Notebook\tCtrl-1")); 215 208 #endif 216 209 #if wxUSE_LISTBOOK 217 menuType->AppendRadioItem(ID_BOOK_LISTBOOK, 210 menuType->AppendRadioItem(ID_BOOK_LISTBOOK, wxT("&Listbook\tCtrl-2")); 218 211 #endif 219 212 #if wxUSE_CHOICEBOOK 220 213 menuType->AppendRadioItem(ID_BOOK_CHOICEBOOK, wxT("&Choicebook\tCtrl-3")); 221 214 #endif 222 menuType->Check(m_type, true); 215 216 menuType->Check(mType, true); 223 217 224 218 wxMenu *menuOrient = new wxMenu; … … 243 237 menuFile->AppendSeparator(); 244 238 menuFile->Append(wxID_EXIT, wxT("E&xit"), wxT("Quits the application")); 245 menuFile->Check(ID_SHOW_IMAGES, m _chkShowImages);246 menuFile->Check(ID_MULTI, m _multi);239 menuFile->Check(ID_SHOW_IMAGES, mChkShowImages); 240 menuFile->Check(ID_MULTI, mMulti); 247 241 248 242 wxMenuBar *menuBar = new wxMenuBar; … … 253 247 // books creation 254 248 255 m _panel = (wxPanel *)NULL;249 mPanel = (wxPanel *) NULL; 256 250 #if wxUSE_NOTEBOOK 257 m _notebook = (wxNotebook *)NULL;251 mNotebook = (wxNotebook *) NULL; 258 252 #endif 259 253 #if wxUSE_CHOICEBOOK 260 m _choicebook = (wxChoicebook *) NULL;254 mChoicebook = (wxChoicebook *) NULL; 261 255 #endif 262 256 #if wxUSE_LISTBOOK 263 m _listbook = (wxListbook *)NULL;257 mListbook = (wxListbook *) NULL; 264 258 #endif 265 259 … … 267 261 wxSize imageSize(32, 32); 268 262 269 m _imageList263 mImageList 270 264 = new wxImageList( imageSize.GetWidth(), imageSize.GetHeight() ); 271 265 272 m _imageList->Add266 mImageList->Add 273 267 ( 274 268 wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize) 275 269 ); 276 270 277 m _imageList->Add271 mImageList->Add 278 272 ( 279 273 wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize) 280 274 ); 281 275 282 m _imageList->Add276 mImageList->Add 283 277 ( 284 278 wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize) 285 279 ); 286 280 287 m _imageList->Add281 mImageList->Add 288 282 ( 289 283 wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize) 290 284 ); 291 285 292 m _panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,286 mPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 293 287 wxTAB_TRAVERSAL | wxCLIP_CHILDREN | wxNO_BORDER | wxNO_FULL_REPAINT_ON_RESIZE); 294 288 295 289 #if USE_LOG 296 m _text = new wxTextCtrl(m_panel, wxID_ANY, wxEmptyString,290 mText = new wxTextCtrl(mPanel, wxID_ANY, wxEmptyString, 297 291 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY); 298 292 299 m _logTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(m_text) );293 mLogTargetOld = wxLog::SetActiveTarget( new wxLogTextCtrl(mText) ); 300 294 #endif // USE_LOG 301 295 302 296 // Set sizers 303 m _sizerFrame = new wxBoxSizer(wxVERTICAL);297 mSizerFrame = new wxBoxSizer(wxVERTICAL); 304 298 305 299 #if USE_LOG 306 m _sizerFrame->Add(m_text, 1, wxEXPAND);300 mSizerFrame->Add(mText, 1, wxEXPAND); 307 301 #endif // USE_LOG 308 302 303 // create preprocessor front end 304 //mPreprocessorFrontEnd = new PreprocessorFrontEnd(); 309 305 RecreateBooks(); 310 311 m_panel->SetSizer(m_sizerFrame); 312 313 m_sizerFrame->Fit(this); 314 m_sizerFrame->SetSizeHints(this); 306 mPanel->SetSizer(mSizerFrame); 307 308 mSizerFrame->Fit(this); 309 mSizerFrame->SetSizeHints(this); 315 310 316 311 Centre(wxBOTH); 317 312 } 318 313 314 319 315 MyFrame::~MyFrame() 320 316 { 321 317 #if USE_LOG 322 delete wxLog::SetActiveTarget(m _logTargetOld);318 delete wxLog::SetActiveTarget(mLogTargetOld); 323 319 #endif // USE_LOG 324 320 325 if (m _imageList)326 { 327 delete m _imageList;328 m _imageList = (wxImageList *) NULL;321 if (mImageList) 322 { 323 delete mImageList; 324 mImageList = (wxImageList *) NULL; 329 325 } 330 326 } … … 347 343 #endif 348 344 349 #define RECREATE( wxBookType , idBook, oldBook , newBook )\345 #define RECREATE(wxBookType , idBook, oldBook, newBook) \ 350 346 { \ 351 347 int flags; \ 352 348 \ 353 switch ( m_orient )\349 switch (mOrient) \ 354 350 { \ 355 351 case ID_ORIENT_TOP: \ … … 372 368 flags = SelectFlag(idBook, wxNB_DEFAULT, wxLB_DEFAULT, wxCHB_DEFAULT); \ 373 369 } \ 374 375 if ( m_multi && ( idBook == ID_NOTEBOOK ) )\370 \ 371 if (mMulti && (idBook == ID_NOTEBOOK)) \ 376 372 flags |= wxNB_MULTILINE; \ 377 373 \ 378 374 wxBookType *oldBook = newBook; \ 379 375 \ 380 newBook = new wxBookType(m _panel, idBook,\376 newBook = new wxBookType(mPanel, idBook, \ 381 377 wxDefaultPosition, wxDefaultSize, \ 382 378 flags); \ 383 379 \ 384 if ( m_chkShowImages )\380 if (mChkShowImages) \ 385 381 { \ 386 newBook->SetImageList(m _imageList);\382 newBook->SetImageList(mImageList); \ 387 383 } \ 388 384 \ … … 400 396 } \ 401 397 \ 402 m _sizerFrame->Detach(oldBook);\398 mSizerFrame->Detach(oldBook); \ 403 399 \ 404 400 delete oldBook; \ … … 414 410 CreateInitialPages(newBook); \ 415 411 } \ 416 417 m_sizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, MARGIN);\418 419 m_sizerFrame->Hide(newBook); \ 420 } 412 \ 413 mSizerFrame->Insert(0, newBook, 5, wxEXPAND | wxALL, MARGIN); \ 414 mSizerFrame->Hide(newBook); \ 415 } 416 421 417 422 418 void MyFrame::RecreateBooks() 423 419 { 424 420 #if wxUSE_NOTEBOOK 425 RECREATE( wxNotebook , ID_NOTEBOOK , notebook , m_notebook);421 RECREATE(wxNotebook, ID_NOTEBOOK, notebook, mNotebook); 426 422 #endif 427 423 #if wxUSE_LISTBOOK 428 RECREATE( wxListbook , ID_LISTBOOK , listbook , m_listbook);424 // RECREATE(wxListbook, ID_LISTBOOK, listbook, mListbook); 429 425 #endif 430 426 #if wxUSE_CHOICEBOOK 431 RECREATE( wxChoicebook , ID_CHOICEBOOK , choicebook , m_choicebook);427 RECREATE(wxChoicebook, ID_CHOICEBOOK, choicebook, mChoicebook); 432 428 #endif 433 429 … … 435 431 } 436 432 433 437 434 wxBookCtrlBase *MyFrame::GetCurrentBook() 438 435 { 439 switch (m _type)436 switch (mType) 440 437 { 441 438 #if wxUSE_NOTEBOOK 442 case ID_BOOK_NOTEBOOK: return m _notebook;439 case ID_BOOK_NOTEBOOK: return mNotebook; 443 440 #endif 444 441 #if wxUSE_LISTBOOK 445 case ID_BOOK_LISTBOOK: return m _listbook;442 case ID_BOOK_LISTBOOK: return mListbook; 446 443 #endif 447 444 #if wxUSE_CHOICEBOOK 448 case ID_BOOK_CHOICEBOOK: return m _choicebook;445 case ID_BOOK_CHOICEBOOK: return mChoicebook; 449 446 #endif 450 447 } … … 454 451 void MyFrame::ShowCurrentBook() 455 452 { 456 switch(m _type)453 switch(mType) 457 454 { 458 455 #if wxUSE_NOTEBOOK 459 case ID_BOOK_NOTEBOOK: if(m_notebook) m_sizerFrame->Show(m_notebook); break; 456 case ID_BOOK_NOTEBOOK: 457 if (mNotebook) 458 { 459 mSizerFrame->Show(mNotebook); 460 } 461 462 break; 460 463 #endif 461 464 #if wxUSE_LISTBOOK 462 case ID_BOOK_LISTBOOK: if(m_listbook) m_sizerFrame->Show(m_listbook); break; 465 case ID_BOOK_LISTBOOK: 466 if (mListbook) 467 { 468 mSizerFrame->Show(mListbook); 469 break; 470 } 463 471 #endif 464 472 #if wxUSE_CHOICEBOOK 465 case ID_BOOK_CHOICEBOOK: if(m_choicebook) m_sizerFrame->Show(m_choicebook); break; 466 #endif 467 } 468 469 m_sizerFrame->Layout(); 473 case ID_BOOK_CHOICEBOOK: 474 if (mChoicebook) 475 { 476 mSizerFrame->Show(mChoicebook); 477 break; 478 } 479 #endif 480 } 481 482 mSizerFrame->Layout(); 470 483 } 471 484 … … 507 520 wxBookCtrlBase *currBook = GetCurrentBook(); 508 521 509 m _type = event.GetId();522 mType = event.GetId(); 510 523 511 524 if (currBook) 512 m _sizerFrame->Hide(currBook);525 mSizerFrame->Hide(currBook); 513 526 514 527 ShowCurrentBook(); … … 517 530 void MyFrame::OnOrient(wxCommandEvent& event) 518 531 { 519 m _orient = event.GetId();532 mOrient = event.GetId(); 520 533 RecreateBooks(); 521 m _sizerFrame->Layout();534 mSizerFrame->Layout(); 522 535 } 523 536 524 537 void MyFrame::OnShowImages(wxCommandEvent& event) 525 538 { 526 m _chkShowImages = event.IsChecked();539 mChkShowImages = event.IsChecked(); 527 540 RecreateBooks(); 528 m _sizerFrame->Layout();541 mSizerFrame->Layout(); 529 542 } 530 543 531 544 void MyFrame::OnMulti(wxCommandEvent& event) 532 545 { 533 m _multi = event.IsChecked();546 mMulti = event.IsChecked(); 534 547 RecreateBooks(); 535 m _sizerFrame->Layout();548 mSizerFrame->Layout(); 536 549 wxLogMessage(_T("Multiline setting works only in wxNotebook.")); 537 550 } … … 548 561 wxBookCtrlBase *currBook = GetCurrentBook(); 549 562 550 if ( currBook ) 551 { 552 wxPanel *panel = new wxPanel( currBook, wxID_ANY ); 563 if (currBook) 564 { 565 wxPanel *panel = new wxPanel(currBook, wxID_ANY); 566 553 567 (void) new wxButton( panel, wxID_ANY, wxT("First button"), 554 568 wxPoint(10, 10), wxDefaultSize ); … … 556 570 wxPoint(50, 100), wxDefaultSize ); 557 571 558 currBook->AddPage(panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"), 559 ++s_pageAdded), true, GetIconIndex(currBook) ); 560 } 561 } 572 currBook->AddPage( 573 panel, wxString::Format(ADDED_PAGE_NAME wxT("%u"), 574 ++ s_pageAdded), true, GetIconIndex(currBook) ); 575 } 576 } 577 562 578 563 579 void MyFrame::OnInsertPage(wxCommandEvent& WXUNUSED(event)) … … 567 583 wxBookCtrlBase *currBook = GetCurrentBook(); 568 584 569 if ( currBook)570 { 571 wxPanel *panel = CreateUserCreatedPage( currBook);585 if (currBook) 586 { 587 wxPanel *panel = CreateUserCreatedPage(currBook); 572 588 573 589 currBook->InsertPage( 0, panel, 574 wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++ s_pageIns), false,590 wxString::Format(INSERTED_PAGE_NAME wxT("%u"), ++ s_pageIns), false, 575 591 GetIconIndex(currBook) ); 576 592 … … 579 595 } 580 596 597 581 598 void MyFrame::OnDeleteCurPage(wxCommandEvent& WXUNUSED(event)) 582 599 { 583 600 wxBookCtrlBase *currBook = GetCurrentBook(); 584 601 585 if ( currBook)586 { 587 int sel = currBook->GetSelection();602 if (currBook) 603 { 604 const int sel = currBook->GetSelection(); 588 605 589 606 if (sel != wxNOT_FOUND) … … 600 617 if ( currBook ) 601 618 { 602 int page = currBook->GetPageCount();619 const int page = currBook->GetPageCount(); 603 620 604 621 if ( page != 0 ) … … 613 630 wxBookCtrlBase *currBook = GetCurrentBook(); 614 631 615 if ( currBook)632 if (currBook) 616 633 { 617 634 currBook->AdvanceSelection(); … … 643 660 644 661 wxString title; 645 title.Printf(wxT(" Notebook and friends(%d pages, selection: %s)"), nPages, selection.c_str());662 title.Printf(wxT("Preprocessor (%d pages, selection: %s)"), nPages, selection.c_str()); 646 663 647 664 SetTitle(title); … … 650 667 651 668 #if USE_LOG 652 #define BOOKEVENT_LOG m _text->SetInsertionPointEnd();669 #define BOOKEVENT_LOG mText->SetInsertionPointEnd(); 653 670 #else 654 671 #define BOOKEVENT_LOG -
GTP/trunk/Lib/Vis/Preprocessing/FrontEnd/preprocessorFrontEnd.h
r1558 r1563 29 29 DECLARE_APP(MyApp) 30 30 31 31 32 class MyFrame : public wxFrame 32 33 { 33 34 public: 34 MyFrame(const wxString& title, const wxPoint& pos = wxDefaultPosition, 35 const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE|wxCLIP_CHILDREN|wxNO_FULL_REPAINT_ON_RESIZE); 35 MyFrame(const wxString& title, 36 const wxPoint& pos = wxDefaultPosition, 37 const wxSize& size = wxDefaultSize, 38 long style = wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN | wxNO_FULL_REPAINT_ON_RESIZE); 36 39 37 40 virtual ~MyFrame(); … … 63 66 wxBookCtrlBase *GetCurrentBook(); 64 67 68 wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent); 69 wxPanel *CreatePreprocessorPage(wxBookCtrlBase *parent); 70 wxPanel *CreateViewCellsPage(wxBookCtrlBase *parent); 71 void CreateInitialPages(wxBookCtrlBase *parent); 72 wxPanel *CreatePage(wxBookCtrlBase *parent, const wxString&pageName); 73 65 74 private: 66 wxLog *m_logTargetOld;67 75 68 76 int SelectFlag(int id, int nb, int lb, int chb); … … 71 79 72 80 // Sample setup 73 int m _type;74 int m _orient;75 bool m _chkShowImages;76 bool m _multi;81 int mType; 82 int mOrient; 83 bool mChkShowImages; 84 bool mMulti; 77 85 86 wxLog *mLogTargetOld; 87 88 ///////// 78 89 // Controls 79 90 80 wxPanel *m_panel; // Panel containing notebook and other controls 91 /// Panel containing notebook and other controls 92 wxPanel *mPanel; 81 93 82 94 #if wxUSE_NOTEBOOK 83 wxNotebook *m _notebook;95 wxNotebook *mNotebook; 84 96 #endif 85 97 #if wxUSE_CHOICEBOOK 86 wxChoicebook *m _choicebook;98 wxChoicebook *mChoicebook; 87 99 #endif 88 100 #if wxUSE_LISTBOOK 89 wxListbook *m _listbook;101 wxListbook *mListbook; 90 102 #endif 91 103 92 104 #if USE_LOG 93 105 // Log window 94 wxTextCtrl *m _text;106 wxTextCtrl *mText; 95 107 #endif // USE_LOG 96 108 97 wxBoxSizer *m_sizerFrame; 109 wxTextCtrl *mDetectEmptyViewSpaceText; 110 wxCheckBox *mDetectEmptyViewSpaceCheckBox; 98 111 99 wxImageList *m_imageList; 112 wxBoxSizer *mSizerFrame; 113 wxImageList *mImageList; 100 114 101 115 DECLARE_EVENT_TABLE() … … 126 140 }; 127 141 142 143 /*class PreprocessorFrontEnd 144 { 145 wxPanel *CreateUserCreatedPage(wxBookCtrlBase *parent); 146 wxPanel *CreatePreprocessorPage(wxBookCtrlBase *parent); 147 wxPanel *CreateViewCellsPage(wxBookCtrlBase *parent); 148 149 MyFrame *mFrame; 150 }*/ 151 152 128 153 /* 129 154 Name of each notebook page. … … 131 156 to decide what type of page it is. 132 157 */ 158 #define PREPROCESSOR_PAGE_NAME wxT("Preprocessor") 159 #define VIEWCELLS_PAGE_NAME wxT("ViewCells") 133 160 134 161 #define I_WAS_INSERTED_PAGE_NAME wxT("Inserted") 135 #define RADIOBUTTONS_PAGE_NAME wxT("Radiobuttons")136 162 #define VETO_PAGE_NAME wxT("Veto") 137 163 #define MAXIMIZED_BUTTON_PAGE_NAME wxT("Maximized button") -
GTP/trunk/Lib/Vis/Preprocessing/FrontEnd/preprocessorFrontEnd.vcproj
r1558 r1563 92 92 Optimization="2" 93 93 InlineFunctionExpansion="1" 94 AdditionalIncludeDirectories=" $(WXWIN)\lib\vc_lib\msw,$(WXWIN)\include,.,$(WXWIN)\samples"94 AdditionalIncludeDirectories=""$(WXWIN)\lib\vc_lib\msw";"$(WXWIN)\include";.;"$(WXWIN)\samples"" 95 95 PreprocessorDefinitions="WIN32;__WXMSW__;_WINDOWS;NOPCH" 96 96 StringPooling="TRUE" … … 564 564 AdditionalOptions="/EHsc " 565 565 Optimization="0" 566 AdditionalIncludeDirectories=" $(WXWIN)\lib\vc_lib\mswd,$(WXWIN)\include,.,$(WXWIN)\samples"566 AdditionalIncludeDirectories=""$(WXWIN)\lib\vc_lib\mswd";"$(WXWIN)\include";.;"$(WXWIN)\samples";"$(WXWIN)\include\msvc"" 567 567 PreprocessorDefinitions="WIN32;_DEBUG;__WXMSW__;__WXDEBUG__;_WINDOWS;NOPCH" 568 568 BasicRuntimeChecks="3" -
GTP/trunk/Lib/Vis/Preprocessing/src/BvHierarchy.cpp
r1551 r1563 892 892 int nObjectsLeft = 0; 893 893 const int nTotalObjects = (int)tData.mNode->mObjects.size(); 894 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();894 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 895 895 896 896 SortableEntryContainer::const_iterator backObjectsStart = mSubdivisionCandidates->begin(); … … 1294 1294 const float area = box.SurfaceArea(); 1295 1295 1296 return (float)objects.size() * area / m HierarchyManager->GetViewSpaceBox().SurfaceArea();1296 return (float)objects.size() * area / mViewCellsManager->GetViewSpaceBox().SurfaceArea(); 1297 1297 } 1298 1298 else … … 1300 1300 //-- render cost heuristics 1301 1301 1302 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();1302 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1303 1303 // probability that view point lies in a view cell which sees this node 1304 1304 const float p = EvalViewCellsVolume(objects) / viewSpaceVol; … … 1712 1712 bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 1713 1713 1714 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();1714 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1715 1715 mTotalCost = (float)objects.size() * prop / viewSpaceVol; 1716 1716 … … 1822 1822 bvhLeaf->SetSubdivisionCandidate(oSubdivisionCandidate); 1823 1823 1824 const float viewSpaceVol = m HierarchyManager->GetViewSpaceBox().GetVolume();1824 const float viewSpaceVol = mViewCellsManager->GetViewSpaceBox().GetVolume(); 1825 1825 mTotalCost = (float)objects.size() * prop / viewSpaceVol; 1826 1826 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.cpp
r1551 r1563 184 184 SimpleRay sray(oldRay.mOrigin, p - oldRay.mOrigin); 185 185 186 VssRay *newRay = mRayCaster->CastRay(sray, mView SpaceBox, false);186 VssRay *newRay = mRayCaster->CastRay(sray, mViewCellsManager->GetViewSpaceBox(), false); 187 187 //cout << "\np1: " << p1 << "\np : " << p << "\np2: " << p2 << endl; 188 188 if (!newRay) return 0; … … 293 293 const VssRay &oldRay) 294 294 { 295 cout << "r";296 295 ++ mReverseSamples; 297 296 … … 393 392 const long startTime = GetTime(); 394 393 395 mViewSpaceBox = mKdTree->GetBox();396 394 Randomize(0); 397 395 … … 406 404 407 405 if (!mLoadViewCells) 408 { /// construct the view cells from the scratch 409 ConstructViewCells(mViewSpaceBox); 410 cout << "view cells loaded" << endl; 406 { 407 /// construct the view cells from the scratch 408 ConstructViewCells(); 409 cout << "finished view cell construction" << endl; 411 410 } 412 411 else if (1) 413 { cout << "here2255566" << endl;412 { 414 413 //-- load view cells from file 415 414 //-- test successful view cells loading by exporting them again 416 415 VssRayContainer dummies; 417 416 mViewCellsManager->Visualize(mObjects, dummies); 418 mViewCellsManager->ExportViewCells("test.xml. zip", mViewCellsManager->GetExportPvs(), mObjects);417 mViewCellsManager->ExportViewCells("test.xml.gz", mViewCellsManager->GetExportPvs(), mObjects); 419 418 } 420 419 -
GTP/trunk/Lib/Vis/Preprocessing/src/GvsPreprocessor.h
r1545 r1563 128 128 int mSamplingType; 129 129 130 AxisAlignedBox3 mViewSpaceBox;130 //AxisAlignedBox3 mViewSpaceBox; 131 131 float mEps; 132 132 float mThreshold; -
GTP/trunk/Lib/Vis/Preprocessing/src/GzBinFileInputStream.h
r1294 r1563 134 134 inline bool GzBinFileInputStream::getIsOpen() const 135 135 { 136 return bool (mStream.is_open());//(fSource != 0);136 return mStream.is_open() != 0;//(fSource != 0); 137 137 } 138 138 -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.cpp
r1557 r1563 163 163 } 164 164 165 165 /* 166 166 AxisAlignedBox3 HierarchyManager::GetViewSpaceBox() const 167 167 { 168 168 return mVspTree->mBoundingBox; 169 } 169 }*/ 170 170 171 171 … … 312 312 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 313 313 314 #if _DEBUG314 /*#if _DEBUG 315 315 cout << "view space: " << GetViewSpaceBox() << endl; 316 316 cout << "object space: " << GetObjectSpaceBox() << endl; 317 #endif 317 #endif*/ 318 318 319 319 mObjectSpaceSubdivisionType = mSavedObjectSpaceSubdivisionType; … … 709 709 cout << "\nfinished in " << TimeDiff(startTime, GetTime()) * 1e-3 << " secs" << endl; 710 710 711 #if _DEBUG711 /*#if _DEBUG 712 712 cout << "view space: " << GetViewSpaceBox() << endl; 713 713 cout << "object space: " << GetObjectSpaceBox() << endl; 714 #endif 714 #endif*/ 715 715 716 716 mHierarchyStats.Stop(); -
GTP/trunk/Lib/Vis/Preprocessing/src/HierarchyManager.h
r1557 r1563 195 195 /** Returns view space bounding box. 196 196 */ 197 AxisAlignedBox3 GetViewSpaceBox() const;197 //AxisAlignedBox3 GetViewSpaceBox() const; 198 198 /** Returns object space bounding box. 199 199 */ -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1545 r1563 422 422 /////// 423 423 //-- parse view cells construction method 424 424 425 Environment::GetSingleton()->GetBoolValue("ViewCells.loadFromFile", mLoadViewCells); 425 426 char buf[100]; … … 429 430 Environment::GetSingleton()->GetStringValue("ViewCells.filename", buf); 430 431 cout << "loading view cells from " << buf << endl; 432 431 433 mViewCellsManager = ViewCellsManager::LoadViewCells(buf, &mObjects, true); 434 432 435 if (!mViewCellsManager) 433 436 return false; … … 440 443 441 444 // default view space is the extent of the scene 442 mViewCellsManager->SetViewSpaceBox(mSceneGraph->GetBox()); 443 445 AxisAlignedBox3 box = mSceneGraph->GetBox(); 446 447 if (0) 448 { 449 // use a small box outside of the scene 450 box.Scale(Vector3(0.1f,0.5f,0.5f)); 451 box.Translate(Vector3(Magnitude(mSceneGraph->GetBox().Size())*0.5f, 0, 0)); 452 } 453 454 mViewCellsManager->SetViewSpaceBox(box); 455 444 456 bool loadVcGeometry; 445 457 Environment::GetSingleton()->GetBoolValue("ViewCells.loadGeometry", loadVcGeometry); … … 492 504 493 505 494 bool Preprocessor::ConstructViewCells(const AxisAlignedBox3 &viewSpaceBox) 495 { 496 mViewCellsManager->SetViewSpaceBox(viewSpaceBox); 497 506 bool Preprocessor::ConstructViewCells() 507 { 498 508 // construct view cells using it's own set of samples 499 509 mViewCellsManager->Construct(this); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1545 r1563 92 92 /** Construct viewcells from the scratch 93 93 */ 94 bool ConstructViewCells( const AxisAlignedBox3 &viewSpaceBox);94 bool ConstructViewCells(); 95 95 96 96 /** Returns the specified sample strategy, NULL if no valid strategy. -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.cpp
r1520 r1563 283 283 exporter->SetWireframe(); 284 284 285 if (1 || mViewSpaceBox) {285 if (1) { 286 286 exporter->SetForcedMaterial(RgbColor(1,0,1)); 287 287 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); … … 321 321 exporter->SetWireframe(); 322 322 323 if (1 || mViewSpaceBox) {323 if (1) { 324 324 exporter->SetForcedMaterial(RgbColor(1,0,1)); 325 325 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); … … 361 361 exporter->SetWireframe(); 362 362 exporter->ExportKdTree(*mKdTree); 363 364 if (mViewSpaceBox) {365 exporter->SetForcedMaterial(RgbColor(1,0,0));366 exporter->ExportBox(*mViewSpaceBox);367 exporter->ResetForcedMaterial();368 }369 363 370 364 exporter->SetForcedMaterial(RgbColor(0,0,1)); … … 510 504 int totalSamples = 0; 511 505 512 mViewSpaceBox = NULL;513 514 506 // if not already loaded, construct view cells from file 515 507 if (!mLoadViewCells) 516 508 { 517 if (1) 518 mViewCellsManager->SetViewSpaceBox(mKdTree->GetBox()); 519 else { 520 AxisAlignedBox3 box = mKdTree->GetBox(); 521 522 if (1) { 523 // use a small box outside of the scene 524 box.Scale(Vector3(0.1f,0.5f,0.5f)); 525 box.Translate(Vector3(Magnitude(mKdTree->GetBox().Size())*0.5f, 0, 0)); 526 } else { 527 float s = box.Size(0); 528 box.Scale(0.1f); 529 box.SetMin(0, box.Min(0) + s); 530 box.SetMax(0, box.Max(0) + s); 531 } 532 533 mViewCellsManager->SetViewSpaceBox(box); 534 } 535 536 // construct view cells using it's own set of samples 537 mViewCellsManager->Construct(this); 538 539 //-- several visualizations and statistics 540 Debug << "view cells construction finished: " << endl; 541 mViewCellsManager->PrintStatistics(Debug); 542 } 543 509 // construct view cells using it's own set of samples 510 mViewCellsManager->Construct(this); 511 512 //-- several visualizations and statistics 513 Debug << "view cells construction finished: " << endl; 514 mViewCellsManager->PrintStatistics(Debug); 515 } 516 544 517 545 518 int rssPass = 0; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssPreprocessor.h
r1281 r1563 38 38 bool mDirectionalSampling; 39 39 40 AxisAlignedBox3 *mViewSpaceBox;40 //AxisAlignedBox3 *mViewSpaceBox; 41 41 42 42 ofstream mStats; -
GTP/trunk/Lib/Vis/Preprocessing/src/RssTree.cpp
r1548 r1563 348 348 } else { 349 349 mRoots.resize(1); 350 RssTreeLeaf *leaf = new RssTreeLeaf(NULL, rays.size());350 RssTreeLeaf *leaf = new RssTreeLeaf(NULL, (int)rays.size()); 351 351 leaf->bbox.Initialize(); 352 352 leaf->dirBBox.Initialize(); … … 1897 1897 } 1898 1898 1899 return rays.size();1899 return (int)rays.size(); 1900 1900 } 1901 1901 -
GTP/trunk/Lib/Vis/Preprocessing/src/SamplingPreprocessor.cpp
r1520 r1563 118 118 119 119 Randomize(0); 120 121 long startTime = GetTime(); 122 120 const long startTime = GetTime(); 123 121 int totalSamples = 0; 124 122 … … 126 124 if (!mLoadViewCells) 127 125 { 128 ConstructViewCells(mKdTree->GetBox()); 129 } 130 131 132 126 ConstructViewCells(); 127 } 128 133 129 int samples = 0; 134 130 int i=0; -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.cpp
r1558 r1563 171 171 mTimeStamp(1), 172 172 mViewCellsTree(NULL), 173 mOutOfBoundsCellPartOfTree(false) 173 mOutOfBoundsCellPartOfTree(false), 174 mOutOfBoundsCell(NULL) 174 175 { 175 176 Randomize(); // initialise random generator for heuristics … … 956 957 { 957 958 tData = tStack.top(); 958 959 959 tStack.pop(); 960 960 … … 1010 1010 if (!mUsePredefinedViewCells) 1011 1011 { // generate new view cell for each leaf 1012 viewCell = new BspViewCell(); 1012 viewCell = new BspViewCell();cout << "g"; 1013 1013 } 1014 1014 else 1015 { 1015 { 1016 1016 // add predefined view cell to leaf 1017 1017 viewCell = dynamic_cast<BspViewCell *>(tData.mViewCell); 1018 1019 1018 // from now on out of bounds cell can be handled as any other cell, 1020 1019 // responsibility for deleting has been shifted 1021 if ( viewCell == mOutOfBoundsCell)1020 if (IsOutOfBounds(viewCell)) 1022 1021 { 1023 1022 mOutOfBoundsCellPartOfTree = true; 1024 1023 } 1024 1025 1025 } 1026 1026 … … 1035 1035 else 1036 1036 viewCell->SetVolume(probability); 1037 1038 1037 1039 1038 /////////// … … 1049 1048 } 1050 1049 1051 if (1)EvaluateLeafStats(tData); 1052 1053 1050 if (1) EvaluateLeafStats(tData); 1051 1054 1052 //////// 1055 1053 //-- clean up … … 2399 2397 { 2400 2398 // per definition out of bounds cell has zero volume 2401 if ( (*it) == mOutOfBoundsCell)2399 if (IsOutOfBounds(*it)) 2402 2400 continue; 2403 2401 … … 3325 3323 ViewCell *BspTree::GetViewCell(const Vector3 &point) 3326 3324 { 3327 if (mRoot == NULL) 3328 return NULL; 3329 3330 3331 stack<BspNode *> nodeStack; 3332 nodeStack.push(mRoot); 3333 3334 ViewCellLeaf *viewcell = NULL; 3335 3336 while (!nodeStack.empty()) { 3337 BspNode *node = nodeStack.top(); 3338 nodeStack.pop(); 3339 3340 if (node->IsLeaf()) { 3341 viewcell = dynamic_cast<BspLeaf *>(node)->mViewCell; 3342 break; 3343 } else { 3344 3345 BspInterior *interior = dynamic_cast<BspInterior *>(node); 3346 3347 // random decision 3348 if (interior->GetPlane().Side(point) < 0) 3349 nodeStack.push(interior->GetBack()); 3350 else 3351 nodeStack.push(interior->GetFront()); 3352 } 3353 } 3354 3355 return viewcell; 3325 if (mRoot == NULL) 3326 return NULL; 3327 3328 stack<BspNode *> nodeStack; 3329 nodeStack.push(mRoot); 3330 3331 ViewCellLeaf *viewcell = NULL; 3332 3333 while (!nodeStack.empty()) { 3334 BspNode *node = nodeStack.top(); 3335 nodeStack.pop(); 3336 3337 if (node->IsLeaf()) 3338 { 3339 viewcell = dynamic_cast<BspLeaf *>(node)->mViewCell; 3340 break; 3341 } 3342 else 3343 { 3344 3345 BspInterior *interior = dynamic_cast<BspInterior *>(node); 3346 3347 // random decision 3348 if (interior->GetPlane().Side(point) < 0) 3349 { 3350 nodeStack.push(interior->GetBack()); 3351 } 3352 else 3353 { 3354 nodeStack.push(interior->GetFront()); 3355 } 3356 } 3357 } 3358 3359 return viewcell; 3356 3360 } 3357 3361 -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellBsp.h
r1558 r1563 625 625 int _CastRay(Ray &ray); 626 626 627 /** Casts line segment between origin and termination and returns 628 view cells which are touched by the line. 629 */ 627 630 int CastLineSegment(const Vector3 &origin, 628 631 const Vector3 &termination, … … 630 633 ); 631 634 635 /** Returns view cell this point is located in. 636 */ 632 637 ViewCell *GetViewCell(const Vector3 &point); 633 638 … … 665 670 */ 666 671 BspLeaf *GetRandomLeaf(const bool onlyUnmailed = false); 667 668 672 669 673 /** Returns epsilon of this tree. -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsManager.cpp
r1557 r1563 233 233 Mesh *m = vc->GetMesh(); 234 234 235 if (m) { 236 m->ComputeBoundingBox(); 237 return m->mBox; 235 if (m) 236 { 237 m->ComputeBoundingBox(); 238 return m->mBox; 238 239 } 239 240 240 241 AxisAlignedBox3 box; 241 242 242 box.Initialize(); 243 243 … … 289 289 { 290 290 VssRayContainer::const_iterator it, it_end = rays.end(); 291 292 291 for (it = rays.begin(); it != it_end; ++ it) 293 292 { … … 298 297 { 299 298 VssRayContainer::const_iterator it, it_end = rays.end(); 300 301 299 for (it = rays.begin(); it != it_end; ++ it) 302 300 { 303 //(*it)->Unref();304 301 if (!(*it)->IsActive()) 305 302 delete (*it); … … 322 319 mPreprocessor = preprocessor; 323 320 324 321 325 322 /////////////////////////////////////////////////////// 326 323 //-- Initial sampling for the construction of the view cell hierarchy. … … 361 358 { 362 359 //-- export initial view cell partition 363 Debug << "\nView cells after initial sampling:\n" 364 << mCurrentViewCellsStats << endl; 360 Debug << "\nView cells after initial sampling:\n" << mCurrentViewCellsStats << endl; 365 361 366 362 const string filename("viewcells.wrl"); … … 428 424 429 425 430 #if 0 431 ///////////////432 //-- Get stats after the additional sampling step433 //-- and before the bottom-up mergestep434 435 EvaluateViewCellsStats(); 436 Debug << "\noriginal view cell partition before post process:\n"437 << mCurrentViewCellsStats << endl;438 439 mRenderer->RenderScene();440 SimulationStatistics ss;441 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss);442 443 Debug << ss << endl; 444 #endif 445 426 if (0) 427 { 428 /////////////// 429 //-- Get stats after the additional sampling step 430 //-- and before the bottom-up merge step 431 432 EvaluateViewCellsStats(); 433 Debug << "\noriginal view cell partition before post process:\n" 434 << mCurrentViewCellsStats << endl; 435 436 mRenderer->RenderScene(); 437 SimulationStatistics ss; 438 dynamic_cast<RenderSimulator *>(mRenderer)->GetStatistics(ss); 439 440 Debug << ss << endl; 441 } 446 442 447 443 //////////////////// … … 612 608 { 613 609 ViewCellsParser parser; 614 615 610 ViewCellsManager *vm = NULL; 616 611 617 612 if (parser.ParseViewCellsFile(filename, &vm, objects, bconverter)) 618 613 { 619 long startTime = GetTime();614 const long startTime = GetTime(); 620 615 621 616 vm->ResetViewCells(); … … 671 666 for (oit = objects.begin(); oit != oit_end; ++ oit) 672 667 { 673 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 674 const AxisAlignedBox3 box = mi->GetBox(); 668 const AxisAlignedBox3 box = (*oit)->GetBox(); 675 669 676 670 //////////// 677 671 //-- the bounding boxes 678 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\""672 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 679 673 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 680 674 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; … … 1262 1256 const bool extrudeBaseTriangles) 1263 1257 { 1264 bool success;1265 1266 1258 /// we use predefined view cells from now on 1267 1259 mUsePredefinedViewCells = true; … … 1271 1263 { 1272 1264 Environment::GetSingleton()->GetFloatValue("ViewCells.height", parser.mViewCellHeight); 1273 success = parser.ParseFile(filename, *this); 1265 const bool success = parser.ParseFile(filename, *this); 1266 1267 if (!success) 1268 return false; 1274 1269 } 1275 1270 else … … 1277 1272 // hack: use standard mesh loading 1278 1273 // create temporary scene graph for loading the view cells geometry 1274 // note: delete the meshes as they are created two times for transformed mesh instances. 1279 1275 SceneGraphNode *root = new SceneGraphNode(); 1280 success = parser.ParseFile(filename, root, true); 1281 1282 if (success) 1283 { 1284 ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 1285 for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 1276 const bool success = parser.ParseFile(filename, root, true); 1277 1278 if (!success) 1279 { 1280 DEL_PTR(root); 1281 return false; 1282 } 1283 1284 ObjectContainer::const_iterator oit, oit_end = root->mGeometry.end(); 1285 1286 for (oit = root->mGeometry.begin(); oit != oit_end; ++ oit) 1287 { 1288 Mesh *mesh; 1289 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1286 1290 { 1287 if ((*oit)->Type() == Intersectable::TRANSFORMED_MESH_INSTANCE) 1288 { 1289 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 1290 Mesh *mesh = MeshManager::GetSingleton()->CreateResource(); 1291 mit->GetTransformedMesh(*mesh); 1292 mesh->ComputeBoundingBox(); 1293 mViewCells.push_back(GenerateViewCell(mesh)); 1294 } 1295 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1296 { 1297 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 1298 mViewCells.push_back(GenerateViewCell(mit->GetMesh())); 1299 } 1291 TransformedMeshInstance *mit = dynamic_cast<TransformedMeshInstance *>(*oit); 1292 mesh = MeshManager::GetSingleton()->CreateResource(); 1293 mit->GetTransformedMesh(*mesh); 1300 1294 } 1301 } 1295 else if ((*oit)->Type() == Intersectable::MESH_INSTANCE) 1296 { 1297 MeshInstance *mit = dynamic_cast<MeshInstance *>(*oit); 1298 mesh = mit->GetMesh(); 1299 } 1300 mesh->ComputeBoundingBox(); 1301 mViewCells.push_back(GenerateViewCell(mesh)); 1302 } 1303 1302 1304 DEL_PTR(root); 1303 1305 } 1304 1306 1305 if (success) 1306 { 1307 // set view space box to bounding box of the view cells 1308 AxisAlignedBox3 bbox; 1309 bbox.Initialize(); 1310 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 1311 for (; it != it_end; ++ it) 1312 { 1313 bbox.Include(GetViewCellBox(*it)); 1314 } 1315 SetViewSpaceBox(bbox); 1316 1317 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry from file " << filename << endl; 1318 } 1319 1320 return success; 1307 // set view space box to bounding box of the view cells 1308 AxisAlignedBox3 bbox; 1309 bbox.Initialize(); 1310 ViewCellContainer::iterator it = mViewCells.begin(), it_end = mViewCells.end(); 1311 1312 for (; it != it_end; ++ it) 1313 { 1314 bbox.Include((*it)->GetMesh()->mBox); 1315 } 1316 1317 SetViewSpaceBox(bbox); 1318 cout << "view space box: " << bbox << endl; 1319 cout << "generated " << (int)mViewCells.size() << " view cells using the geometry " << filename << endl; 1320 1321 return true; 1321 1322 } 1322 1323 … … 2539 2540 VssRayContainer savedRays; 2540 2541 2542 // choose a a number of rays based on the ratio of cast rays / requested rays 2541 2543 const int limit = min(mInitialSamples, (int)rays.size()); 2542 2543 2544 VssRayContainer::const_iterator it, it_end = rays.end(); 2544 2545 2545 2546 const float prop = (float)limit / ((float)rays.size() + Limits::Small); 2546 2547 2547 for (it = rays.begin(); it != it_end; ++ it) 2548 2548 { … … 2785 2785 return; 2786 2786 2787 int savedColorCode = mColorCode;2787 const int savedColorCode = mColorCode; 2788 2788 2789 2789 if (1) // export final view cells … … 2989 2989 const AxisAlignedBox3 *sceneBox, 2990 2990 const AxisAlignedPlane *clipPlane 2991 ) const 2992 { 2993 // out of bounds cell 2994 //if (vc->GetId() == OUT_OF_BOUNDS_ID) return; 2995 2996 // export mesh if available 2997 if (vc->GetMesh()) 2998 { 2999 exporter->ExportMesh(vc->GetMesh()); 3000 return; 3001 } 3002 3003 // otherwise construct from leaves 2991 ) const 2992 { 3004 2993 if (clipPlane) 3005 2994 { … … 3018 3007 mBspTree->ConstructGeometry(*it, geom); 3019 3008 3020 const float eps = 0.000 00001f;3009 const float eps = 0.0001f; 3021 3010 const int cf = geom.Side(plane, eps); 3022 3011 … … 3032 3021 mViewSpaceBox, 3033 3022 eps); 3034 3023 3035 3024 if (back.Valid()) 3036 { 3025 { 3037 3026 exporter->ExportPolygons(back.GetPolys()); 3038 3027 } … … 3042 3031 else 3043 3032 { 3044 BspNodeGeometry geom; 3045 mBspTree->ConstructGeometry(vc, geom); 3046 exporter->ExportPolygons(geom.GetPolys()); 3033 // export mesh if available 3034 // TODO: some bug here? 3035 if (1 && vc->GetMesh()) 3036 { 3037 exporter->ExportMesh(vc->GetMesh()); 3038 } 3039 else 3040 { 3041 BspNodeGeometry geom; 3042 mBspTree->ConstructGeometry(vc, geom); 3043 exporter->ExportPolygons(geom.GetPolys()); 3044 } 3047 3045 } 3048 3046 } … … 3158 3156 for (oit = objects.begin(); oit != oit_end; ++ oit) 3159 3157 { 3160 MeshInstance *mi = dynamic_cast<MeshInstance *>(*oit); 3161 const AxisAlignedBox3 box = mi->GetBox(); 3158 const AxisAlignedBox3 box = (*oit)->GetBox(); 3162 3159 3163 stream << "<BoundingBox" << " id=\"" << mi->GetId() << "\""3160 stream << "<BoundingBox" << " id=\"" << (*oit)->GetId() << "\"" 3164 3161 << " min=\"" << box.Min().x << " " << box.Min().y << " " << box.Min().z << "\"" 3165 3162 << " max=\"" << box.Max().x << " " << box.Max().y << " " << box.Max().z << "\" />" << endl; … … 4123 4120 { 4124 4121 cout << "exporting view cells after post process ... "; 4125 4126 4122 if (0) 4127 { 4128 // export view space box 4123 { // export view space box 4129 4124 exporter->SetWireframe(); 4130 4125 exporter->ExportBox(mViewSpaceBox); … … 4133 4128 4134 4129 Material m; 4135 4136 4130 m.mDiffuseColor.r = 0.0f; 4137 4131 m.mDiffuseColor.g = 0.5f; … … 4140 4134 exporter->SetForcedMaterial(m); 4141 4135 4142 if ( 0&& mExportGeometry)4136 if (1 && mExportGeometry) 4143 4137 { 4144 4138 exporter->ExportGeometry(objects); 4145 4139 } 4146 4140 4147 // export rays4148 4141 if (0 && mExportRays) 4149 4142 { 4150 4143 exporter->ExportRays(visRays, RgbColor(1, 0, 0)); 4151 4144 } 4152 4153 4145 ExportViewCellsForViz(exporter, NULL, GetClipPlane()); 4154 4146 … … 4500 4492 ) const 4501 4493 { 4502 // out of bounds cell4503 //if (vc->GetId() == OUT_OF_BOUNDS_ID) return;4504 4494 if (clipPlane) 4505 4495 { … … 4513 4503 { 4514 4504 BspNodeGeometry geom; 4515 4516 4505 BspNodeGeometry front; 4517 4506 BspNodeGeometry back; … … 4545 4534 // export mesh if available 4546 4535 // TODO: some bug here? 4547 if ( 0&& vc->GetMesh())4536 if (1 && vc->GetMesh()) 4548 4537 { 4549 4538 exporter->ExportMesh(vc->GetMesh()); … … 5070 5059 5071 5060 // matt: hack for clamping scene 5072 AxisAlignedBox3 bbox = m HierarchyManager->GetViewSpaceBox();5061 AxisAlignedBox3 bbox = mViewSpaceBox; 5073 5062 bbox.Scale(Vector3(0.5, 1, 0.5)); 5074 5063 if (CLAMP_TO_BOX) -
GTP/trunk/Lib/Vis/Preprocessing/src/ViewCellsParser.cpp
r1558 r1563 850 850 851 851 // set view space box 852 mVspBspTree->mBo x = mViewSpaceBox;852 mVspBspTree->mBoundingBox = mViewSpaceBox; 853 853 854 854 ViewCellsMap::iterator vit, vit_end = mViewCells.end(); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.cpp
r1558 r1563 277 277 if (mesh) 278 278 { // // copy the mesh into polygons and add to BSP tree aabb 279 mBo x.Include(viewCells[i]->GetBox());279 mBoundingBox.Include(viewCells[i]->GetBox()); 280 280 polysSize += AddMeshToPolygons(mesh, 281 281 polys, … … 326 326 if (mesh) // copy the mesh data to polygons 327 327 { 328 mBo x.Include(object->GetBox()); // add to BSP tree aabb328 mBoundingBox.Include(object->GetBox()); // add to BSP tree aabb 329 329 AddMeshToPolygons(mesh, polys, NULL); 330 330 … … 344 344 if (forcedBoundingBox) 345 345 { 346 mBo x = *forcedBoundingBox;346 mBoundingBox = *forcedBoundingBox; 347 347 } 348 348 else // compute vsp tree bounding box 349 349 { 350 mBo x.Initialize();350 mBoundingBox.Initialize(); 351 351 352 352 VssRayContainer::const_iterator rit, rit_end = sampleRays.end(); … … 358 358 359 359 // compute bounding box of view space 360 mBo x.Include(ray->GetTermination());361 mBo x.Include(ray->GetOrigin());360 mBoundingBox.Include(ray->GetTermination()); 361 mBoundingBox.Include(ray->GetOrigin()); 362 362 } 363 363 } … … 393 393 Intersectable *obj = ray->mTerminationObject; 394 394 395 if ((mBo x.IsInside(ray->mTermination) || !forcedBoundingBox) &&395 if ((mBoundingBox.IsInside(ray->mTermination) || !forcedBoundingBox) && 396 396 obj && !obj->Mailed()) 397 397 { … … 419 419 //-- compute bounding box 420 420 if (!forcedBoundingBox) 421 mBo x.Include(ray->mTermination);422 } 423 424 if ((mBo x.IsInside(ray->mOrigin) || !forcedBoundingBox) &&421 mBoundingBox.Include(ray->mTermination); 422 } 423 424 if ((mBoundingBox.IsInside(ray->mOrigin) || !forcedBoundingBox) && 425 425 ray->mOriginObject && 426 426 !ray->mOriginObject->Mailed()) … … 460 460 461 461 // TODO: not very efficient to implictly cast between rays types 462 if (mBo x.GetRaySegment(hray, minT, maxT))462 if (mBoundingBox.GetRaySegment(hray, minT, maxT)) 463 463 { 464 464 float len = ray->Length(); … … 473 473 // normalize 474 474 if (mUseAreaForPvs) 475 mTermMinProbability *= mBo x.SurfaceArea();475 mTermMinProbability *= mBoundingBox.SurfaceArea(); 476 476 else 477 mTermMinProbability *= mBo x.GetVolume();477 mTermMinProbability *= mBoundingBox.GetVolume(); 478 478 479 479 … … 547 547 548 548 549 mTotalCost = tData.mPvs * tData.mProbability / mBo x.GetVolume();549 mTotalCost = tData.mPvs * tData.mProbability / mBoundingBox.GetVolume(); 550 550 mTotalPvsSize = tData.mPvs; 551 551 … … 652 652 tQueue.push(splitCandidate); 653 653 654 mTotalCost = tData.mPvs * tData.mProbability / mBo x.GetVolume();654 mTotalCost = tData.mPvs * tData.mProbability / mBoundingBox.GetVolume(); 655 655 mTotalPvsSize = tData.mPvs; 656 656 … … 948 948 949 949 float costDecr = 950 (cFront + cBack - cData) / mBo x.GetVolume();950 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 951 951 952 952 mTotalCost += costDecr; … … 1109 1109 1110 1110 const float costDecr = 1111 (cFront + cBack - cData) / mBo x.GetVolume();1111 (cFront + cBack - cData) / mBoundingBox.GetVolume(); 1112 1112 1113 1113 mTotalCost += costDecr; … … 1162 1162 *backData.mGeometry, 1163 1163 splitPlane, 1164 mBo x,1164 mBoundingBox, 1165 1165 //0.0f); 1166 1166 mEpsilon); … … 2003 2003 geomBack, 2004 2004 candidatePlane, 2005 mBo x,2005 mBoundingBox, 2006 2006 //0.0f); 2007 2007 mEpsilon); … … 2041 2041 const float newRenderCost = penaltyFront * pFront + penaltyBack * pBack; 2042 2042 2043 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBo x.GetVolume();2043 const float renderCostDecrease = (oldRenderCost - newRenderCost) / mBoundingBox.GetVolume(); 2044 2044 2045 2045 // take render cost of node into account to avoid being stuck in a local minimum 2046 normalizedOldRenderCost = oldRenderCost / mBo x.GetVolume();2046 normalizedOldRenderCost = oldRenderCost / mBoundingBox.GetVolume(); 2047 2047 2048 2048 return renderCostDecrease; … … 2108 2108 geomBack, 2109 2109 candidatePlane, 2110 mBo x,2110 mBoundingBox, 2111 2111 //0.0f); 2112 2112 mEpsilon); … … 2236 2236 *secondGeom, 2237 2237 interior->GetPlane(), 2238 mBo x,2238 mBoundingBox, 2239 2239 //0.0000001f); 2240 2240 mEpsilon); … … 2427 2427 AxisAlignedBox3 VspBspTree::GetBoundingBox() const 2428 2428 { 2429 return mBo x;2429 return mBoundingBox; 2430 2430 } 2431 2431 … … 2500 2500 float maxt, mint; 2501 2501 2502 if (!mBo x.GetRaySegment(ray, mint, maxt))2502 if (!mBoundingBox.GetRaySegment(ray, mint, maxt)) 2503 2503 return 0; 2504 2504 … … 2761 2761 PolygonContainer boxPolys; 2762 2762 2763 mBo x.ExtractPolys(boxPolys);2763 mBoundingBox.ExtractPolys(boxPolys); 2764 2764 vector<Plane3> boxPlanes; 2765 2765 … … 2930 2930 2931 2931 for (int j = 0; j < 4; ++ j) 2932 vertices.push_back(mBox.GetFace(i).mVertices[j]); 2932 { 2933 vertices.push_back(mBoundingBox.GetFace(i).mVertices[j]); 2934 } 2933 2935 2934 2936 Polygon3 *poly = new Polygon3(vertices); … … 2967 2969 2968 2970 if (backPoly->Valid(mEpsilon)) 2971 { 2969 2972 candidatePolys[i] = backPoly; 2973 } 2970 2974 else 2975 { 2971 2976 DEL_PTR(backPoly); 2977 } 2972 2978 2973 2979 // outside, don't need this 2974 2980 DEL_PTR(frontPoly); 2975 2981 break; 2982 2976 2983 // polygon outside of halfspace 2977 2984 case Polygon3::FRONT_SIDE: 2978 2985 DEL_PTR(candidatePolys[i]); 2979 2986 break; 2987 2980 2988 // just take polygon as it is 2981 2989 case Polygon3::BACK_SIDE: … … 2989 2997 { 2990 2998 geom.Add(candidatePolys[i], candidatePlanes[i]); 2991 // geom.mPolys.push_back(candidates[i]); 2992 } 2993 } 2999 } 3000 } 3001 } 3002 3003 3004 bool VspBspTree::IsOutOfBounds(ViewCell *vc) const 3005 { 3006 return vc->GetId() == OUT_OF_BOUNDS_ID; 3007 } 3008 3009 3010 void VspBspTree::SetViewCellsTree(ViewCellsTree *viewCellsTree) 3011 { 3012 mViewCellsTree = viewCellsTree; 2994 3013 } 2995 3014 … … 3009 3028 for (it = leaves.begin(); it != it_end; ++ it) 3010 3029 { 3011 if ( (*it) == mOutOfBoundsCell)3030 if (IsOutOfBounds(*it)) 3012 3031 continue; 3013 3032 … … 3120 3139 *bGeom, 3121 3140 interior->GetPlane(), 3122 mBo x,3141 mBoundingBox, 3123 3142 //0.0000001f); 3124 3143 eps); … … 3214 3233 *bGeom, 3215 3234 interior->GetPlane(), 3216 mBo x,3235 mBoundingBox, 3217 3236 //0.0000001f); 3218 3237 eps); … … 3709 3728 *secondGeom, 3710 3729 interior->GetPlane(), 3711 mBo x,3730 mBoundingBox, 3712 3731 //0.0000001f); 3713 3732 mEpsilon); -
GTP/trunk/Lib/Vis/Preprocessing/src/VspBspTree.h
r1545 r1563 356 356 int ComputeBoxIntersections(const AxisAlignedBox3 &box, ViewCellContainer &viewCells) const; 357 357 358 /// pointer to the hierarchy of view cells 359 ViewCellsTree *mViewCellsTree; 360 358 /** Pointer to the view cells tree. 359 */ 360 void SetViewCellsTree(ViewCellsTree *vct); 361 362 /** Returns true if this view cell prepresents 363 invalid view space. 364 */ 365 bool IsOutOfBounds(ViewCell *vc) const; 366 367 361 368 362 369 protected: … … 736 743 737 744 /// box around the whole view domain 738 AxisAlignedBox3 mBox; 739 740 745 AxisAlignedBox3 mBoundingBox; 746 747 /// pointer to the hierarchy of view cells 748 ViewCellsTree *mViewCellsTree; 749 750 741 751 //-- termination critera 742 752 -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.cpp
r1528 r1563 40 40 41 41 useViewspacePlane = mUseViewSpaceBox; //hack 42 43 mViewSpaceBox.Initialize();44 42 45 43 Debug << "*********** vss preprocessor options **************" << endl; … … 158 156 159 157 exporter->SetForcedMaterial(RgbColor(1,0,1)); 160 exporter->ExportBox(mView SpaceBox);158 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); 161 159 exporter->ResetForcedMaterial(); 162 160 … … 201 199 202 200 exporter->SetForcedMaterial(RgbColor(1,0,0)); 203 exporter->ExportBox(mView SpaceBox);201 exporter->ExportBox(mViewCellsManager->GetViewSpaceBox()); 204 202 exporter->ResetForcedMaterial(); 205 203 … … 373 371 Debug << "type: vss" << endl; 374 372 375 long startTime = GetTime(); 376 377 int totalSamples = 0; 378 379 380 AxisAlignedBox3 box(mKdTree->GetBox()); 381 382 if (!useViewspacePlane) { 383 float size = 0.05f; 384 float s = 0.5f - size; 385 float olds = Magnitude(box.Size()); 386 box.Enlarge(box.Size()*Vector3(-s)); 387 Vector3 translation = Vector3(-olds*0.1f, 0, 0); 388 box.SetMin(box.Min() + translation); 389 box.SetMax(box.Max() + translation); 390 } else { 391 392 // sample city like heights 393 box.SetMin(1, box.Min(1) + box.Size(1)*0.2f); 394 box.SetMax(1, box.Min(1) + box.Size(1)*0.3f); 395 } 396 397 if (use2dSampling) 398 box.SetMax(1, box.Min(1)); 399 400 cout << "use view space box=" << mUseViewSpaceBox << endl; 401 402 403 if (mUseViewSpaceBox) 404 { 405 if (!mEnlargeViewSpace) 406 { 407 mViewSpaceBox = AxisAlignedBox3(box); 408 } 409 else 410 { 411 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 412 413 if (0) 414 { 415 // HACK: enlarge in y directon 416 Vector3 size = mViewSpaceBox.Size(); 417 418 size[1] *= 1.25; 419 Vector3 enlarge(size[0] * 0.25f, size[1] * 0.0f, size[2] * 0.25f); 420 //Vector3 enlarge(size[0] * 4.0f, 0.0f, 0.0f); 421 422 mViewSpaceBox.Enlarge(enlarge); 423 mViewSpaceBox.SetMax(mViewSpaceBox.Max() + enlarge); 424 } 425 else 426 { 427 AxisAlignedBox3 tbox(mViewSpaceBox); 428 429 Vector3 size = mViewSpaceBox.Size(); 430 tbox.SetMax(0, mViewSpaceBox.Max(0) + size[0] * 0.5f); 431 tbox.SetMin(0, mViewSpaceBox.Min(0) + size[0]); 432 mViewSpaceBox = tbox; 433 } 434 } 435 } 436 else 437 { 438 mViewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 439 } 440 441 mSceneGraph->CollectObjects(&mObjects); 442 443 if (!mLoadViewCells) 444 { 445 //-- generate new view cells from the scratch 446 //-- for construction the manager uses it's own set of samples 447 ConstructViewCells(mViewSpaceBox); 448 } 373 const long startTime = GetTime(); 374 int totalSamples = 0; 375 376 if (mUseViewSpaceBox) 377 { 378 AxisAlignedBox3 viewSpaceBox; 379 viewSpaceBox.Initialize(); 380 381 viewSpaceBox = AxisAlignedBox3(mKdTree->GetBox()); 382 AxisAlignedBox3 tbox(mViewCellsManager->GetViewSpaceBox()); 383 384 const Vector3 size = tbox.Size(); 385 viewSpaceBox.SetMax(0, tbox.Max(0) + size[0] * 0.5f); 386 viewSpaceBox.SetMin(0, tbox.Min(0) + size[0]); 387 388 // change the view space of the view cells manager 389 mViewCellsManager->SetViewSpaceBox(viewSpaceBox); 390 } 391 392 393 mSceneGraph->CollectObjects(&mObjects); 394 395 if (!mLoadViewCells) 396 { 397 //-- generate new view cells from the scratch 398 //-- for construction the manager uses it's own set of samples 399 ConstructViewCells(); 400 } 449 401 #if 0 450 451 452 453 454 455 456 457 402 else 403 { 404 //-- load view cells from file 405 //-- test successful view cells loading by exporting them again 406 VssRayContainer dummies; 407 mViewCellsManager->Visualize(mObjects, dummies); 408 mViewCellsManager->ExportViewCells("test.xml.zip", mViewCellsManager->GetExportPvs(), mObjects); 409 } 458 410 #endif 459 411 460 VssTree *vssTree = NULL; 461 const long initialTime = GetTime(); 462 463 if (mLoadInitialSamples) 464 { 465 cout << "Loading samples from file ... "; 466 LoadSamples(mVssRays, mObjects); 467 cout << "finished\n" << endl; 468 totalSamples = (int)mVssRays.size(); 469 } 470 else 471 { 472 while (totalSamples < mInitialSamples) { 473 int passContributingSamples = 0; 474 int passSampleContributions = 0; 475 int passSamples = 0; 476 477 int index = 0; 478 479 int sampleContributions; 480 481 int s = Min(mSamplesPerPass, mInitialSamples); 482 for (int k=0; k < s; k++) 412 VssTree *vssTree = NULL; 413 const long initialTime = GetTime(); 414 415 if (mLoadInitialSamples) 416 { 417 cout << "Loading samples from file ... "; 418 LoadSamples(mVssRays, mObjects); 419 cout << "finished\n" << endl; 420 totalSamples = (int)mVssRays.size(); 421 } 422 else 423 { 424 while (totalSamples < mInitialSamples) { 425 int passContributingSamples = 0; 426 int passSampleContributions = 0; 427 int passSamples = 0; 428 429 int index = 0; 430 431 int sampleContributions; 432 433 int s = Min(mSamplesPerPass, mInitialSamples); 434 for (int k=0; k < s; k++) 435 { 436 Vector3 viewpoint; 437 438 mViewCellsManager->GetViewPoint(viewpoint); 439 const Vector3 direction = GetDirection(viewpoint, &mViewCellsManager->GetViewSpaceBox()); 440 441 const SimpleRay sray(viewpoint, direction); 442 sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewCellsManager->GetViewSpaceBox(), true); 443 444 if (sampleContributions) { 445 passContributingSamples ++; 446 passSampleContributions += sampleContributions; 447 } 448 passSamples++; 449 totalSamples++; 450 } 451 452 mPass++; 453 int pvsSize = 0; 454 float avgRayContrib = (passContributingSamples > 0) ? 455 passSampleContributions/(float)passContributingSamples : 0; 456 457 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 458 cout << "#TotalSamples=" << totalSamples/1000 459 << "#SampleContributions=" << passSampleContributions << " (" 460 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 461 << pvsSize/(float)mObjects.size() << endl 462 << "avg ray contrib=" << avgRayContrib << endl; 463 464 mStats << 465 "#Pass\n" <<mPass<<endl<< 466 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 467 "#TotalSamples\n" << totalSamples<< endl<< 468 "#SampleContributions\n" << passSampleContributions << endl << 469 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 470 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 471 "#AvgRayContrib\n" << avgRayContrib << endl; 472 } 473 474 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 475 476 477 478 } 479 480 481 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush; 482 Debug << (int)mVssRays.size() << " rays generated in " 483 << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl; 484 485 if (mStoreInitialSamples) 486 { 487 cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 488 ExportSamples(mVssRays); 489 cout << "finished\n" << endl; 490 491 /*VssRayContainer dummyRays; 492 LoadSamples(dummyRays, mObjects); 493 Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 494 495 for (int i = 0; i < (int)mVssRays.size(); ++ i) 483 496 { 484 Vector3 viewpoint; 485 486 mViewCellsManager->GetViewPoint(viewpoint); 487 const Vector3 direction = GetDirection(viewpoint, &mViewSpaceBox); 488 489 const SimpleRay sray(viewpoint, direction); 490 sampleContributions = mRayCaster->CastRay(sray, mVssRays, mViewSpaceBox, true); 491 492 if (sampleContributions) { 493 passContributingSamples ++; 494 passSampleContributions += sampleContributions; 497 Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl; 498 Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl; 499 }*/ 500 } 501 502 503 //int numExportRays = 2000; 504 int numExportRays = 0; 505 506 if (numExportRays) { 507 char filename[64]; 508 sprintf(filename, "vss-rays-initial.x3d"); 509 ExportRays(filename, mVssRays, numExportRays); 510 } 511 512 vssTree = new VssTree; 513 // viewcells = Construct(mVssRays); 514 515 vssTree->Construct(mVssRays, NULL); 516 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 517 518 if (0) ExportRays("kdtree.x3d", mVssRays, 10); 519 520 if (0) 521 { 522 ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0)); 523 ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(0,0,1)); 524 ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1)); 525 ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1)); 526 ExportVssTreeLeaves(vssTree, 10); 527 } 528 529 // viewcells->UpdatePVS(newVssRays); 530 // get viewcells as kd tree boxes 531 vector<AxisAlignedBox3> kdViewcells; 532 if (0) { 533 vector<KdLeaf *> leaves; 534 mKdTree->CollectLeaves(leaves); 535 vector<KdLeaf *>::const_iterator it; 536 int targetLeaves = 50; 537 float prob = targetLeaves/(float)leaves.size(); 538 for (it = leaves.begin(); it != leaves.end(); ++it) 539 if (RandomValue(0.0f,1.0f) < prob) 540 kdViewcells.push_back(mKdTree->GetBox(*it)); 541 542 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 543 cout<<"Initial average PVS size = "<<avgPvs<<endl; 544 } 545 546 547 int samples = 0; 548 int pass = 0; 549 550 551 // cast view cell samples 552 while (samples < mVssSamples) 553 { 554 555 int num = mVssSamplesPerPass; 556 SimpleRayContainer rays; 557 VssRayContainer vssRays; 558 559 if (!mUseImportanceSampling) { 560 for (int j=0; j < num; j++) { 561 Vector3 viewpoint; 562 mViewCellsManager->GetViewPoint(viewpoint); 563 Vector3 direction = GetDirection(viewpoint, NULL); 564 rays.push_back(SimpleRay(viewpoint, direction)); 495 565 } 496 passSamples++;497 totalSamples++;566 } else { 567 num = GenerateImportanceRays(vssTree, num, rays); 498 568 } 499 569 500 mPass++; 501 int pvsSize = 0; 502 float avgRayContrib = (passContributingSamples > 0) ? 503 passSampleContributions/(float)passContributingSamples : 0; 504 505 cout << "#Pass " << mPass << " : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 506 cout << "#TotalSamples=" << totalSamples/1000 507 << "#SampleContributions=" << passSampleContributions << " (" 508 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 509 << pvsSize/(float)mObjects.size() << endl 510 << "avg ray contrib=" << avgRayContrib << endl; 511 512 mStats << 513 "#Pass\n" <<mPass<<endl<< 514 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 515 "#TotalSamples\n" << totalSamples<< endl<< 516 "#SampleContributions\n" << passSampleContributions << endl << 517 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 518 "#AvgPVS\n"<< pvsSize/(float)mObjects.size() << endl << 519 "#AvgRayContrib\n" << avgRayContrib << endl; 520 } 521 522 cout << "#totalPvsSize=" << mKdTree->CollectLeafPvs() << endl; 523 524 525 526 } 527 528 529 cout << "#totalRayStackSize=" << (int)mVssRays.size() << endl << flush; 530 Debug << (int)mVssRays.size() << " rays generated in " 531 << TimeDiff(initialTime, GetTime()) * 1e-3 << " seconds" << endl; 532 533 if (mStoreInitialSamples) 534 { 535 cout << "Writing " << (int)mVssRays.size() << " samples to file ... "; 536 ExportSamples(mVssRays); 537 cout << "finished\n" << endl; 538 539 /*VssRayContainer dummyRays; 540 LoadSamples(dummyRays, mObjects); 541 Debug << "rays " << (int)mVssRays.size() << " " << dummyRays.size() << endl; 542 543 for (int i = 0; i < (int)mVssRays.size(); ++ i) 544 { 545 Debug << mVssRays[i]->GetOrigin() << " " << mVssRays[i]->GetTermination() << " " << mVssRays[i]->mOriginObject << " " << mVssRays[i]->mTerminationObject << endl; 546 Debug << dummyRays[i]->GetOrigin() << " " << dummyRays[i]->GetTermination() << " " << dummyRays[i]->mOriginObject << " " << dummyRays[i]->mTerminationObject << endl << endl; 547 }*/ 548 } 549 550 551 //int numExportRays = 2000; 552 int numExportRays = 0; 553 554 if (numExportRays) { 555 char filename[64]; 556 sprintf(filename, "vss-rays-initial.x3d"); 557 ExportRays(filename, mVssRays, numExportRays); 558 } 559 560 vssTree = new VssTree; 561 // viewcells = Construct(mVssRays); 562 563 vssTree->Construct(mVssRays, NULL); 564 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 565 566 if (0) ExportRays("kdtree.x3d", mVssRays, 10); 567 568 if (0) 569 { 570 ExportVssTree("vss-tree-100.x3d", vssTree, Vector3(1,0,0)); 571 ExportVssTree("vss-tree-001.x3d", vssTree, Vector3(0,0,1)); 572 ExportVssTree("vss-tree-101.x3d", vssTree, Vector3(1,0,1)); 573 ExportVssTree("vss-tree-101m.x3d", vssTree, Vector3(-1,0,-1)); 574 ExportVssTreeLeaves(vssTree, 10); 575 } 576 577 // viewcells->UpdatePVS(newVssRays); 578 // get viewcells as kd tree boxes 579 vector<AxisAlignedBox3> kdViewcells; 580 if (0) { 581 vector<KdLeaf *> leaves; 582 mKdTree->CollectLeaves(leaves); 583 vector<KdLeaf *>::const_iterator it; 584 int targetLeaves = 50; 585 float prob = targetLeaves/(float)leaves.size(); 586 for (it = leaves.begin(); it != leaves.end(); ++it) 587 if (RandomValue(0.0f,1.0f) < prob) 588 kdViewcells.push_back(mKdTree->GetBox(*it)); 589 590 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 591 cout<<"Initial average PVS size = "<<avgPvs<<endl; 592 } 593 594 595 int samples = 0; 596 int pass = 0; 597 598 599 // cast view cell samples 600 while (samples < mVssSamples) 601 { 602 603 int num = mVssSamplesPerPass; 604 SimpleRayContainer rays; 605 VssRayContainer vssRays; 606 607 if (!mUseImportanceSampling) { 608 for (int j=0; j < num; j++) { 609 Vector3 viewpoint; 610 mViewCellsManager->GetViewPoint(viewpoint); 611 Vector3 direction = GetDirection(viewpoint, NULL); 612 rays.push_back(SimpleRay(viewpoint, direction)); 613 } 614 } else { 615 num = GenerateImportanceRays(vssTree, num, rays); 616 } 617 618 CastRays(rays, vssRays, true); 619 vssTree->AddRays(vssRays); 620 621 if (0) { 622 int subdivided = vssTree->UpdateSubdivision(); 623 cout<<"subdivided leafs = "<<subdivided<<endl; 624 } 625 626 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 627 cout<<"Average PVS size = "<<avgPvs<<endl; 628 629 /// compute view cell contribution of rays 630 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 631 632 if (numExportRays) { 633 char filename[64]; 634 if (mUseImportanceSampling) 635 sprintf(filename, "vss-rays-i%04d.x3d", pass); 636 else 637 sprintf(filename, "vss-rays-%04d.x3d", pass); 638 639 ExportRays(filename, vssRays, numExportRays); 640 } 641 642 samples+=num; 643 float pvs = vssTree->GetAvgPvsSize(); 644 cout<<"*****************************\n"; 645 cout<<samples<<" avgPVS ="<<pvs<<endl; 646 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 647 cout<<"*****************************\n"; 648 // if (samples >= mVssSamples) break; 649 pass ++; 650 } 651 652 if (mTestBeamSampling && mUseGlRenderer) 653 { 654 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 655 } 656 657 if (0) Debug << vssTree->stat << endl; 658 659 if (0) 660 { 661 VssRayContainer viewCellRays; 662 // compute rays used for view cells construction 663 const int numRays = mViewCellsManager->GetVisualizationSamples(); 664 vssTree->CollectRays(viewCellRays, numRays); 665 } 666 667 668 //////////////////// 669 //-- render simulation after construction 670 671 mRenderSimulator->RenderScene(); 672 SimulationStatistics ss; 673 mRenderSimulator->GetStatistics(ss); 674 Debug << "\nFinal view cells partition render time\n" << ss << endl; 675 cout << "\nFinal view cells partition render time\n" << ss << endl; 676 677 delete vssTree; 678 679 return true; 680 } 681 682 } 570 CastRays(rays, vssRays, true); 571 vssTree->AddRays(vssRays); 572 573 if (0) { 574 int subdivided = vssTree->UpdateSubdivision(); 575 cout<<"subdivided leafs = "<<subdivided<<endl; 576 } 577 578 float avgPvs = GetAvgPvsSize(vssTree, kdViewcells); 579 cout<<"Average PVS size = "<<avgPvs<<endl; 580 581 /// compute view cell contribution of rays 582 mViewCellsManager->ComputeSampleContributions(vssRays, true, false); 583 584 if (numExportRays) { 585 char filename[64]; 586 if (mUseImportanceSampling) 587 sprintf(filename, "vss-rays-i%04d.x3d", pass); 588 else 589 sprintf(filename, "vss-rays-%04d.x3d", pass); 590 591 ExportRays(filename, vssRays, numExportRays); 592 } 593 594 samples+=num; 595 float pvs = vssTree->GetAvgPvsSize(); 596 cout<<"*****************************\n"; 597 cout<<samples<<" avgPVS ="<<pvs<<endl; 598 cout<<"VssTree root PVS size = "<<vssTree->GetRootPvsSize()<<endl; 599 cout<<"*****************************\n"; 600 // if (samples >= mVssSamples) break; 601 pass ++; 602 } 603 604 if (mTestBeamSampling && mUseGlRenderer) 605 { 606 TestBeamCasting(vssTree, mViewCellsManager, mObjects); 607 } 608 609 if (0) Debug << vssTree->stat << endl; 610 611 if (0) 612 { 613 VssRayContainer viewCellRays; 614 // compute rays used for view cells construction 615 const int numRays = mViewCellsManager->GetVisualizationSamples(); 616 vssTree->CollectRays(viewCellRays, numRays); 617 } 618 619 620 //////////////////// 621 //-- render simulation after construction 622 623 mRenderSimulator->RenderScene(); 624 SimulationStatistics ss; 625 mRenderSimulator->GetStatistics(ss); 626 Debug << "\nFinal view cells partition render time\n" << ss << endl; 627 cout << "\nFinal view cells partition render time\n" << ss << endl; 628 629 delete vssTree; 630 631 return true; 632 } 633 634 } -
GTP/trunk/Lib/Vis/Preprocessing/src/VssPreprocessor.h
r1486 r1563 26 26 bool mUseImportanceSampling; 27 27 bool mEnlargeViewSpace; 28 AxisAlignedBox3 mViewSpaceBox;28 //AxisAlignedBox3 mViewSpaceBox; 29 29 30 30 ofstream mStats;
Note: See TracChangeset
for help on using the changeset viewer.