Changeset 608 for trunk/VUT/GtpVisibilityPreprocessor
- Timestamp:
- 02/08/06 20:32:42 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.cpp
r599 r608 13 13 #include <Cg/cgGL.h> 14 14 15 #include <QVBoxLayout> 16 15 17 static CGcontext sCgContext = NULL; 16 18 static CGprogram sCgFragmentProgram = NULL; … … 43 45 mViewPoint = mSceneGraph->GetBox().Center(); 44 46 mViewDirection = Vector3(0,0,1); 47 45 48 // timerId = startTimer(10); 46 49 // debug coords for atlanta 47 mViewPoint = Vector3(3473, 6.778, -1699);48 mViewDirection = Vector3(-0.2432, 0, 0.97);50 // mViewPoint = Vector3(3473, 6.778, -1699); 51 // mViewDirection = Vector3(-0.2432, 0, 0.97); 49 52 50 53 mFrame = 0; … … 205 208 { 206 209 QString s; 207 s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f)", 210 int vc = 0; 211 if (mViewCellsManager) 212 vc = mViewCellsManager->GetViewCells().size(); 213 s.sprintf("frame:%04d viewpoint:(%4.1f,%4.1f,%4.1f) dir:(%4.1f,%4.1f,%4.1f) viewcells:%04d", 208 214 mFrame, 209 215 mViewPoint.x, … … 212 218 mViewDirection.x, 213 219 mViewDirection.y, 214 mViewDirection.z 215 220 mViewDirection.z, 221 vc 216 222 ); 217 223 renderText(0,20,s); … … 433 439 434 440 441 void 442 GlRendererWidget::SetupProjection(const int w, const int h) 443 { 444 if (!mTopView) 445 GlRenderer::SetupProjection(w, h); 446 else { 447 glViewport(0, 0, w, h); 448 glMatrixMode(GL_PROJECTION); 449 glLoadIdentity(); 450 gluPerspective(50.0, 1.0, 0.1, 20.0*Magnitude(mSceneGraph->GetBox().Diagonal())); 451 glMatrixMode(GL_MODELVIEW); 452 } 453 } 454 435 455 float 436 456 GlRendererWidget::RenderErrors() … … 444 464 SetupCamera(); 445 465 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 446 447 466 467 double eq[4]; 468 eq[0] = mSceneCutPlane.mNormal.x; 469 eq[1] = mSceneCutPlane.mNormal.y; 470 eq[2] = mSceneCutPlane.mNormal.z; 471 eq[3] = mSceneCutPlane.mD; 472 473 if (mCutScene) { 474 glClipPlane(GL_CLIP_PLANE0, eq); 475 glEnable(GL_CLIP_PLANE0); 476 } 477 448 478 if (mDetectEmptyViewSpace) 449 479 glEnable( GL_CULL_FACE ); … … 553 583 } 554 584 585 glDisable(GL_CLIP_PLANE0); 586 555 587 return pErrorPixels; 556 588 } … … 697 729 GlRendererWidget::paintGL() 698 730 { 699 if (mRenderViewCells) 731 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 732 733 734 RenderErrors(); 735 RenderInfo(); 736 737 if (mRenderViewCells) 700 738 RenderViewCells(); 701 else { 702 RenderErrors(); 703 RenderInfo(); 704 } 705 739 706 740 mFrame++; 707 741 } … … 714 748 GlRenderer::SetupCamera(); 715 749 else { 716 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; 717 Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, 718 -1, 719 mViewDirection.y); 720 721 Vector3 target = mViewPoint + dist*mViewDirection; 722 Vector3 up(0,1,0); 723 724 glLoadIdentity(); 725 gluLookAt(pos.x, pos.y, pos.z, 726 target.x, target.y, target.z, 727 up.x, up.y, up.z); 750 if (0) { 751 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*0.05; 752 Vector3 pos = mViewPoint - dist*Vector3(mViewDirection.x, 753 -1, 754 mViewDirection.y); 755 756 Vector3 target = mViewPoint + dist*mViewDirection; 757 Vector3 up(0,1,0); 758 759 glLoadIdentity(); 760 gluLookAt(pos.x, pos.y, pos.z, 761 target.x, target.y, target.z, 762 up.x, up.y, up.z); 763 } else { 764 float dist = Magnitude(mSceneGraph->GetBox().Diagonal())*mTopDistance; 765 Vector3 pos = mViewPoint + dist*Vector3(0, 766 1, 767 0); 768 769 Vector3 target = mViewPoint; 770 Vector3 up(mViewDirection.x, 0, mViewDirection.z); 771 772 glLoadIdentity(); 773 gluLookAt(pos.x, pos.y, pos.z, 774 target.x, target.y, target.z, 775 up.x, up.y, up.z); 776 777 } 728 778 } 729 779 … … 736 786 case Qt::Key_T: 737 787 mTopView = !mTopView; 788 SetupProjection(width(), height()); 738 789 updateGL(); 739 790 break; … … 746 797 break; 747 798 } 748 799 } 800 801 802 RendererControlWidget::RendererControlWidget(QWidget * parent, Qt::WFlags f): 803 QWidget(parent, f) 804 { 805 806 QVBoxLayout *vl = new QVBoxLayout; 807 setLayout(vl); 808 809 QWidget *vbox = new QGroupBox("ViewCells", this); 810 layout()->addWidget(vbox); 811 812 vl = new QVBoxLayout; 813 vbox->setLayout(vl); 814 815 QSlider *slider = new QSlider(Qt::Horizontal, vbox); 816 vl->addWidget(slider); 817 slider->show(); 818 slider->setRange(1, 10000); 819 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 820 slider->setValue(500); 821 822 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetViewCellGranularity(int))); 823 824 825 826 QWidget *hbox = new QWidget(vbox); 827 vl->addWidget(hbox); 828 QHBoxLayout *hlayout = new QHBoxLayout; 829 hbox->setLayout(hlayout); 830 831 QCheckBox *cb = new QCheckBox("Show viewcells", hbox); 832 hlayout->addWidget(cb); 833 cb->setChecked(false); 834 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetShowViewCells(bool))); 835 836 vbox->resize(800,100); 837 838 839 vbox = new QGroupBox("Rendering", this); 840 layout()->addWidget(vbox); 841 842 vl = new QVBoxLayout; 843 vbox->setLayout(vl); 844 845 slider = new QSlider(Qt::Horizontal, vbox); 846 vbox->layout()->addWidget(slider); 847 slider->show(); 848 slider->setRange(0, 1000); 849 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 850 slider->setValue(1000); 851 852 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetSceneCut(int))); 853 854 855 cb = new QCheckBox("Cut view cells", vbox); 856 vbox->layout()->addWidget(cb); 857 cb->setChecked(false); 858 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutViewCells(bool))); 859 860 cb = new QCheckBox("Cut scene", vbox); 861 vbox->layout()->addWidget(cb); 862 cb->setChecked(false); 863 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetCutScene(bool))); 864 865 866 slider = new QSlider(Qt::Horizontal, vbox); 867 vbox->layout()->addWidget(slider); 868 slider->show(); 869 slider->setRange(1, 1000); 870 slider->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); 871 slider->setValue(500); 872 873 connect(slider, SIGNAL(valueChanged(int)), SIGNAL(SetTopDistance(int))); 874 875 cb = new QCheckBox("Top View", vbox); 876 vbox->layout()->addWidget(cb); 877 cb->setChecked(false); 878 connect(cb, SIGNAL(toggled(bool)), SIGNAL(SetTopView(bool))); 879 880 881 adjustSize(); 749 882 } 750 883 … … 761 894 mTopView = false; 762 895 mRenderViewCells = false; 763 764 QSlider *slider = new QSlider(this); 765 slider->show(); 766 slider->setRange(1, 10000); 767 768 connect(slider, SIGNAL(valueChanged(int)), this, SLOT(SetViewcellGranularity(int))); 769 } 770 771 void 772 GlRendererWidget::SetViewcellGranularity(int number) 896 mTopDistance = 1.0f; 897 mCutViewCells = false; 898 mCutScene = false; 899 900 RendererControlWidget *cw = new RendererControlWidget(NULL); 901 connect(cw, SIGNAL(SetViewCellGranularity(int)), this, SLOT(SetViewCellGranularity(int))); 902 connect(cw, SIGNAL(SetSceneCut(int)), this, SLOT(SetSceneCut(int))); 903 connect(cw, SIGNAL(SetTopDistance(int)), this, SLOT(SetTopDistance(int))); 904 connect(cw, SIGNAL(SetShowViewCells(bool)), this, SLOT(SetShowViewCells(bool))); 905 connect(cw, SIGNAL(SetTopView(bool)), this, SLOT(SetTopView(bool))); 906 connect(cw, SIGNAL(SetCutViewCells(bool)), this, SLOT(SetCutViewCells(bool))); 907 connect(cw, SIGNAL(SetCutScene(bool)), this, SLOT(SetCutScene(bool))); 908 909 cw->show(); 910 } 911 912 void 913 GlRendererWidget::SetViewCellGranularity(int number) 773 914 { 774 915 mViewCellsManager->CollectViewCells(number); … … 777 918 778 919 void 920 GlRendererWidget::SetSceneCut(int number) 921 { 922 // assume the cut plane can only be aligned with xz plane 923 // shift it along y according to number, which is percentage of the bounding 924 // box position 925 if (mViewCellsManager) { 926 AxisAlignedBox3 box = mViewCellsManager->GetViewSpaceBox(); 927 Vector3 p = box.Min() + (number/1000.0f)*box.Max(); 928 mSceneCutPlane.mNormal = Vector3(0,-1,0); 929 mSceneCutPlane.mD = -DotProd(mSceneCutPlane.mNormal, p); 930 updateGL(); 931 } 932 } 933 934 void 935 GlRendererWidget::SetTopDistance(int number) 936 { 937 mTopDistance = number/1000.0f; 938 updateGL(); 939 } 940 941 void 779 942 GlRendererWidget::RenderViewCells() 780 943 { … … 782 945 783 946 SetupCamera(); 784 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 785 947 glEnable(GL_CULL_FACE); 948 glCullFace(GL_FRONT); 949 double eq[4]; 950 eq[0] = mSceneCutPlane.mNormal.x; 951 eq[1] = mSceneCutPlane.mNormal.y; 952 eq[2] = mSceneCutPlane.mNormal.z; 953 eq[3] = mSceneCutPlane.mD; 954 955 if (mCutViewCells) { 956 glClipPlane(GL_CLIP_PLANE0, eq); 957 glEnable(GL_CLIP_PLANE0); 958 } 959 786 960 int i; 787 961 ViewCellContainer &viewcells = mViewCellsManager->GetViewCells(); 788 962 for (i=0; i < viewcells.size(); i++) { 789 963 ViewCell *vc = viewcells[i]; 790 Mesh *m = vc->GetMesh(); 791 float r = RandomValue(0.5, 1.0); 792 float g = RandomValue(0.5, 1.0); 793 float b = RandomValue(0.5, 1.0); 794 795 glColor3f(r, g, b); 796 //SetupMaterial(m->mMaterial); 797 964 // Mesh *m = vc->GetMesh(); 965 RgbColor c = vc->GetColor(); 966 glColor3f(c.r, c.g, c.b); 798 967 RenderViewCell(vc); 799 968 } 969 970 glDisable(GL_CLIP_PLANE0); 800 971 801 972 } -
trunk/VUT/GtpVisibilityPreprocessor/src/GlRenderer.h
r599 r608 99 99 100 100 101 v oid101 virtual void 102 102 SetupProjection(const int w, const int h); 103 103 … … 179 179 180 180 181 class RendererControlWidget : public QWidget 182 { 183 Q_OBJECT 184 public: 185 RendererControlWidget(QWidget * parent = 0, Qt::WFlags f = 0); 186 187 signals: 188 189 SetViewCellGranularity(int); 190 SetSceneCut(int); 191 SetTopDistance(int); 192 193 SetShowViewCells(bool); 194 SetTopView(bool); 195 SetCutViewCells(bool); 196 SetCutScene(bool); 197 198 }; 181 199 182 200 class GlRendererWidget : public QGLWidget, public GlRenderer … … 190 208 bool mTopView; 191 209 bool mRenderViewCells; 210 bool mCutViewCells; 211 bool mCutScene; 212 213 Plane3 mSceneCutPlane; 214 float mTopDistance; 192 215 193 216 GlRendererWidget(SceneGraph *sceneGraph, … … 223 246 virtual int GetHeight() const { return height(); } 224 247 248 virtual void 249 SetupProjection(const int w, const int h); 225 250 226 251 void … … 229 254 public slots: 230 255 void 231 SetViewcellGranularity(int number); 232 256 SetViewCellGranularity(int number); 257 258 void 259 SetSceneCut(int cut); 260 261 void 262 SetTopDistance(int dist); 263 264 void SetShowViewCells(bool b) { 265 mRenderViewCells = b; 266 updateGL(); 267 } 268 269 void SetTopView(bool b) { 270 mTopView = b; 271 updateGL(); 272 } 273 274 void SetCutViewCells(bool b) { 275 mCutViewCells = b; 276 updateGL(); 277 } 278 void SetCutScene(bool b) { 279 mCutScene = b; 280 updateGL(); 281 } 233 282 234 283 }; … … 253 302 void initPbuffer(); 254 303 304 255 305 GlRendererBuffer *mRenderBuffer; 256 306 … … 258 308 int mSamples; 259 309 Intersectable *mSourceObject; 310 260 311 private: 261 312 GLuint dynamicTexture; -
trunk/VUT/GtpVisibilityPreprocessor/src/Material.cpp
r162 r608 10 10 11 11 Material m; 12 m.mDiffuseColor = 13 RgbColor(a + Random(b), 14 a + Random(b), 15 a + Random(b)); 12 m.mDiffuseColor = RandomColor(a, b); 16 13 17 14 return m; 18 15 } 19 16 17 18 RgbColor 19 RandomColor(const float a, const float b) 20 { 21 return RgbColor(a + Random(b), 22 a + Random(b), 23 a + Random(b)); 24 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Material.h
r386 r608 18 18 { 19 19 } 20 20 21 friend RgbColor 22 RandomColor(const float a=0.0f, const float b=1.0f); 23 21 24 }; 22 25 … … 32 35 { 33 36 } 34 35 36 37 38 39 40 37 38 Material(const RgbColor &color):mDiffuseColor(color), 39 mAmbientColor(color), 40 mSpecularColor(0,0,0) 41 { 42 } 43 41 44 friend Material RandomMaterial(); 42 45 -
trunk/VUT/GtpVisibilityPreprocessor/src/RssPreprocessor.cpp
r587 r608 298 298 exporter->SetFilled(); 299 299 // $$JB temporarily do not export the scene 300 if ( 0)300 if (1) 301 301 exporter->ExportScene(mSceneGraph->mRoot); 302 302 exporter->SetWireframe(); -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r607 r608 606 606 if (mViewCellsManager->EqualToSpatialNode(mergedVc)) 607 607 ++ mergeStats.siblings; 608 mergedVc->SetCost(realExpectedCost); 608 609 609 610 if (((mergeStats.merged % statsOut) == 0) || … … 664 665 ViewCellInterior *root = mViewCellsManager->MergeViewCells(activeViewCells); 665 666 root->SetMergeCost(totalRenderCost); 667 // $$JB keep this 0 temporarilly 668 root->SetCost(0.0f); 669 666 670 mRoot = root; 667 671 } … … 693 697 Debug << mergeStats << endl << endl; 694 698 695 699 // assign colors for the view cells so that at least one is always consistent 700 AssignRandomColors(); 696 701 //TODO: should return sample contributions? 697 702 return mergeStats.merged; … … 1533 1538 1534 1539 1540 void 1541 ViewCellsTree::AssignRandomColors() 1542 { 1543 TraversalQueue tqueue; 1544 tqueue.push(mRoot); 1545 mRoot->SetColor(RandomColor(0.3f, 1.0f)); 1546 while (!tqueue.empty()) 1547 { 1548 ViewCell *vc = tqueue.top(); 1549 1550 // save the view cells if it is a leaf or if enough view cells have already been traversed 1551 // because of the priority queue, this will be the optimal set of v 1552 if (!vc->IsLeaf()) { 1553 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1554 1555 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1556 float maxProbability = -1.0f; 1557 ViewCell *maxViewCell = NULL; 1558 for (it = interior->mChildren.begin(); it != it_end; ++ it) { 1559 ViewCell *v = *it; 1560 // set random color 1561 v->SetColor(RandomColor(0.3f, 1.0f)); 1562 if (v->GetVolume() > maxProbability) { 1563 maxProbability = v->GetVolume(); 1564 maxViewCell = v; 1565 } 1566 maxViewCell->SetColor(vc->GetColor()); 1567 tqueue.push(v); 1568 } 1569 1570 } 1571 1572 tqueue.pop(); 1573 } 1574 } 1575 1576 /** Get costs resulting from each merge step. */ 1577 void 1578 ViewCellsTree::GetCostFunction(vector<float> &costFunction) 1579 { 1580 TraversalQueue tqueue; 1581 tqueue.push(mRoot); 1582 while (!tqueue.empty()) { 1583 ViewCell *vc = tqueue.top(); 1584 1585 // save the view cells if it is a leaf or if enough view cells have already been traversed 1586 // because of the priority queue, this will be the optimal set of v 1587 if (!vc->IsLeaf()) { 1588 ViewCellInterior *interior = dynamic_cast<ViewCellInterior *>(vc); 1589 costFunction.push_back(interior->GetCost()); 1590 1591 ViewCellContainer::const_iterator it, it_end = interior->mChildren.end(); 1592 1593 for (it = interior->mChildren.begin(); it != it_end; ++ it) { 1594 tqueue.push(*it); 1595 } 1596 1597 } 1598 1599 tqueue.pop(); 1600 } 1601 } 1602 1603 1535 1604 void ViewCellsTree::UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat) 1536 1605 { -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.h
r605 r608 6 6 #include "Ray.h" 7 7 #include "Statistics.h" 8 #include "Material.h" 8 9 //namespace GtpVisibilityPreprocessor { 9 10 … … 107 108 int Type() const; 108 109 109 110 void SetParent(ViewCellInterior *parent); 110 111 111 112 /** Adds a passing ray to the passing ray container. … … 147 148 148 149 149 150 150 /** set color for visiualizations */ 151 void SetColor(const RgbColor &color) { 152 mColor = color; 153 } 154 155 /** get color for visualuzations */ 156 RgbColor GetColor() const { 157 return mColor; 158 } 159 160 151 161 /// parent view cell in the view cell hierarchy 152 162 ViewCellInterior *mParent; … … 201 211 202 212 bool mValid; 213 214 /** color used for consistent visualization */ 215 RgbColor mColor; 203 216 }; 204 217 … … 221 234 ViewCellContainer mChildren; 222 235 236 void SetCost(const float c) { 237 mCost = c; 238 } 239 float GetCost() const { 240 return mCost; 241 } 242 243 protected: 244 /** overall cost resulting from the merge */ 245 float mCost; 223 246 }; 224 247 … … 279 302 int RefineViewCells(const VssRayContainer &rays, const ObjectContainer &objects); 280 303 304 /** Assign colors to the viewcells so that they can be renderered interactively without 305 color flickering. 306 */ 307 void AssignRandomColors(); 281 308 /** Updates view cell stats for this particular view cell 282 309 */ 283 310 void UpdateViewCellsStats(ViewCell *vc, ViewCellsStatistics &vcStat); 284 311 312 313 /** Get costs resulting from each merge step. */ 314 void GetCostFunction(vector<float> &costFunction); 315 285 316 286 317 /** Returns optimal set of view cells for a given number of view cells. -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r599 r608 25 25 # type vss 26 26 type rss 27 detectEmptyViewSpace false27 detectEmptyViewSpace true 28 28 pvsRenderErrorSamples 10000 29 29 quitOnFinish false … … 72 72 73 73 RssPreprocessor { 74 samplesPerPass 500 00074 samplesPerPass 500 75 75 initialSamples 100 76 76 vssSamples 100 77 vssSamplesPerPass 100 000077 vssSamplesPerPass 100 78 78 useImportanceSampling true 79 79 … … 219 219 exportRays true 220 220 exportGeometry true 221 exportMergedViewCells true222 useCuttingPlane true221 exportMergedViewCells false 222 useCuttingPlane false 223 223 cuttingPlaneAxis 1 224 224 } … … 283 283 VspBspTree { 284 284 Construction { 285 samples 300000285 samples 1000000 286 286 epsilon 0.005 287 287 randomize false … … 330 330 331 331 332 maxViewCells 10000332 maxViewCells 50000 333 333 334 334 # used for pvs criterium
Note: See TracChangeset
for help on using the changeset viewer.