- Timestamp:
- 07/18/05 11:27:52 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 6 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/scripts/preprocessor.pro
r65 r177 4 4 TARGET = preprocessor 5 5 6 INCLUDEPATH += ../ include6 INCLUDEPATH += ../src 7 7 8 8 # debuc config -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r162 r177 1508 1508 1509 1509 1510 int 1511 AxisAlignedBox3::Side(const Plane3 &plane) const 1512 { 1513 Vector3 v; 1514 int i, m=3, M=-3, s; 1515 1516 for (i=0;i<8;i++) { 1517 GetVertex(i, v); 1518 if((s = plane.Side(v)) < m) 1519 m=s; 1520 if(s > M) 1521 M=s; 1522 if (m && m==-M) 1523 return 0; 1524 } 1525 1526 return (m == M) ? m : m + M; 1527 } -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r170 r177 104 104 105 105 106 int 107 Side(const Plane3 &plane) const; 106 108 107 109 // Overlap returns 1 if the two axis-aligned boxes overlap .. even weakly … … 123 125 124 126 virtual int IsInside(const Vector3 &v) const; 125 127 126 128 // Test if the box is really sensefull 127 129 virtual bool IsCorrect(); … … 167 169 // 1 ... the cube contains fully the box 168 170 int MutualPositionWithCube(const Vector3 ¢er, float halfSize) const; 171 172 173 Vector3 GetRandomPoint() { 174 Vector3 size = Size(); 175 return mMin + Vector3(RandomValue(0, size.x), 176 RandomValue(0, size.y), 177 RandomValue(0, size.z)); 178 } 169 179 170 180 // Returns the smallest axis-aligned box that includes all points … … 181 191 const Matrix4x4 &tform); 182 192 193 183 194 // returns true when two boxes are completely equal 184 195 friend inline int operator== (const AxisAlignedBox3 &A, const AxisAlignedBox3 &B); -
trunk/VUT/GtpVisibilityPreprocessor/src/Environment.cpp
r170 r177 1141 1141 "0.1"); 1142 1142 1143 RegisterOption("Sampling.totalSamples", 1144 optInt, 1145 "-total_samples=", 1146 "1000000"); 1147 1148 RegisterOption("Sampling.samplesPerPass", 1149 optInt, 1150 "-total_samples=", 1151 "10"); 1152 1143 1153 1144 1154 } -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
r176 r177 7 7 8 8 9 10 11 KdNode::KdNode(KdInterior *parent):mParent(parent) 9 int KdNode::mailID = 1; 10 11 12 KdNode::KdNode(KdInterior *parent):mParent(parent), mailbox(0) 12 13 { 13 14 if (parent) … … 633 634 } 634 635 } 636 637 // Find random neighbor which was not mailed 638 KdNode * 639 KdTree::FindRandomNeighbor(KdNode *n, 640 bool onlyUnmailed 641 ) 642 { 643 stack<KdNode *> nodeStack; 644 645 nodeStack.push(mRoot); 646 647 AxisAlignedBox3 box = GetBox(n); 648 int mask = rand(); 649 650 while (!nodeStack.empty()) { 651 KdNode *node = nodeStack.top(); 652 nodeStack.pop(); 653 if (node->IsLeaf()) { 654 if ( node != n && (!onlyUnmailed || !node->Mailed()) ) 655 return node; 656 } else { 657 KdInterior *interior = (KdInterior *)node; 658 if (interior->mPosition > box.Max(interior->mAxis)) 659 nodeStack.push(interior->mBack); 660 else 661 if (interior->mPosition < box.Min(interior->mAxis)) 662 nodeStack.push(interior->mFront); 663 else { 664 // random decision 665 if (mask&1) 666 nodeStack.push(interior->mBack); 667 else 668 nodeStack.push(interior->mFront); 669 mask = mask>>1; 670 } 671 } 672 } 673 674 return NULL; 675 } -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h
r176 r177 86 86 class KdNode { 87 87 public: 88 static int mailID; 89 int mailbox; 90 91 void Mail() { mailbox = mailID; } 92 static void NewMail() { mailID++; } 93 bool Mailed() const { return mailbox == mailID; } 94 95 88 96 KdNode(KdInterior *parent); 89 97 … … 277 285 } 278 286 287 KdNode * 288 FindRandomNeighbor(KdNode *n, 289 bool onlyUnmailed 290 ); 291 292 int 293 FindNeighbors(KdNode *n, 294 vector<KdNode *> &neighbors, 295 bool onlyUnmailed 296 ); 297 279 298 protected: 280 299 -
trunk/VUT/GtpVisibilityPreprocessor/src/Plane3.h
r162 r177 23 23 } 24 24 25 float Distance(const Vector3 &v) const { 26 return DotProd(v, mNormal) + mD; 27 } 28 29 int Side(const Vector3 &v, const float threshold = 1e-6) const { 30 return signum(Distance(v), threshold); 31 } 32 25 33 friend ostream &operator<<(ostream &s, const Plane3 p) { 26 34 s<<p.mNormal<<" "<<p.mD; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r176 r177 3 3 #include "SamplingPreprocessor.h" 4 4 #include "X3dExporter.h" 5 5 #include "Environment.h" 6 6 SamplingPreprocessor::SamplingPreprocessor() 7 7 { 8 8 // this should increase coherence of the samples 9 mSamplesPerPass = 1;10 mTotalSamples = 1e8;11 mKdPvsDepth = 10 ;9 environment->GetIntValue("Sampling.samplesPerPass", mSamplesPerPass); 10 environment->GetIntValue("Sampling.totalSamples", mTotalSamples); 11 mKdPvsDepth = 100; 12 12 13 13 } … … 75 75 76 76 for (i =0; i < objects.size(); i++) { 77 KdNode *nodeToSample = NULL; 78 Intersectable *object = objects[i]; 79 80 int pvsSize = object->mKdPvs.GetSize(); 81 82 if (0 && pvsSize) { 83 // mail all nodes from the pvs 84 Intersectable::NewMail(); 85 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 86 for (; i != object->mKdPvs.mEntries.end(); i++) { 87 KdNode *node = (*i).first; 88 node->Mail(); 89 } 90 int maxTries = 2*pvsSize; 91 for (int tries = 0; tries < 10; tries++) { 92 int index = RandomValue(0, pvsSize - 1); 93 KdPvsData data; 94 KdNode *visibleNode; 95 object->mKdPvs.GetData(index, visibleNode, data); 96 nodeToSample = mKdTree->FindRandomNeighbor(visibleNode, true); 97 if (nodeToSample) 98 break; 99 } 100 } 101 102 if (pvsSize) { 103 // mail all nodes from the pvs 104 Intersectable::NewMail(); 105 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 106 for (; i != object->mKdPvs.mEntries.end(); i++) { 107 KdNode *node = (*i).first; 108 node->Mail(); 109 } 110 vector<KdNode *> invisibleNeighbors; 111 // get all neighbors of all PVS nodes 112 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 113 for (; i != object->mKdPvs.mEntries.end(); i++) { 114 KdNode *node = (*i).first; 115 mKdTree->FindNeighbors(visibleNode, invisibleNeighbors, true); 116 } 117 118 KdPvsData data; 119 KdNode *visibleNode; 120 object->mKdPvs.GetData(index, visibleNode, data); 121 nodeToSample = mKdTree->FindRandomNeighbor(visibleNode, true); 122 if (nodeToSample) 123 break; 124 } 125 126 77 127 for (int k=0; k < mSamplesPerPass; k++) { 78 Intersectable *object = objects[i];79 128 object->GetRandomSurfacePoint(point, normal); 80 direction = UniformRandomVector(normal); 129 if (nodeToSample) { 130 int maxTries = 5; 131 for (int tries = 0; tries < maxTries; tries++) { 132 direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 133 if (DotProd(direction, normal) > Limits::Small) 134 break; 135 } 136 if (tries == maxTries) 137 direction = UniformRandomVector(normal); 138 } else 139 direction = UniformRandomVector(normal); 140 81 141 // construct a ray 82 142 SetupRay(ray, point, direction); … … 114 174 for (i=0; i < objects.size(); i++) { 115 175 Intersectable *object = objects[i]; 116 pvsSize += object->mKdPvs. mEntries.size();176 pvsSize += object->mKdPvs.GetSize(); 117 177 } 118 178 … … 120 180 cout<<"#totalSamples="<<totalSamples/1000<< 121 181 "k #sampleContributions="<<passSampleContributions<< 122 " ("<<100*passContributingSamples/passSamples<<"%)"<< 123 " avgPVS="<<pvsSize/(float)objects.size()<<endl; 182 " ("<<100*passContributingSamples/(float)passSamples<<"%)"<< 183 " avgPVS="<<pvsSize/(float)objects.size()<<endl<< 184 "avg ray contrib="<<passSampleContributions/(float)passContributingSamples<< 185 endl; 124 186 } 125 187 bool exportRays = false; -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r176 r177 8 8 # filename glasgow1.x3d 9 9 # filename vienna.x3d 10 #filename atlanta2.x3d11 filename soda.dat10 filename atlanta2.x3d 11 # filename soda.dat 12 12 13 13 } … … 52 52 53 53 54 Sampling Preprocessor{55 56 54 Sampling { 55 totalSamples 500000 56 samplesPerPass 2 57 57 } -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r176 r177 8 8 INCLUDEPATH += ../src ../support/xerces/include ../support/zlib/include ../support/boost 9 9 10 win32:LIBPATH += ../support/ expat/lib ../support/xerces/lib10 win32:LIBPATH += ../support/xerces/lib 11 11 12 12 #win32:LIBPATH += c:/STLport-4.6.2/lib
Note: See TracChangeset
for help on using the changeset viewer.