- Timestamp:
- 08/03/05 11:15:30 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r181 r191 4 4 #include "X3dExporter.h" 5 5 #include "Environment.h" 6 #include "MutualVisibility.h" 7 6 8 SamplingPreprocessor::SamplingPreprocessor() 7 9 { … … 33 35 34 36 int 35 SamplingPreprocessor::AddNodeSamples(Intersectable *object, const Ray &ray) 37 SamplingPreprocessor::AddNodeSamples(Intersectable *object, 38 const Ray &ray, 39 const int pass) 36 40 { 37 41 int contributingSamples = 0; 38 39 for ( intj=0; j < ray.leaves.size(); j++) {42 int j; 43 for (j=0; j < ray.leaves.size(); j++) { 40 44 KdNode *node = GetNodeForPvs( ray.leaves[j] ); 41 45 contributingSamples += object->mKdPvs.AddNodeSample(node); 42 46 } 43 47 48 if (pass > 10) 49 for (j=1; j < ray.leaves.size() - 1; j++) { 50 ray.leaves[j]->AddPassingRay(ray, contributingSamples ? 1 : 0); 51 } 52 44 53 return contributingSamples; 54 } 55 56 57 void 58 SamplingPreprocessor::HoleSamplingPass() 59 { 60 vector<KdLeaf *> leaves; 61 mKdTree->CollectLeaves(leaves); 62 63 // go through all the leaves and evaluate their passing contribution 64 for (int i=0 ; i < leaves.size(); i++) { 65 KdLeaf *leaf = leaves[i]; 66 cout<<leaf->mPassingRays<<endl; 67 } 45 68 } 46 69 … … 63 86 int totalSamples = 0; 64 87 65 66 88 int pvsOut = Min((int)objects.size(), 10); 67 89 … … 73 95 int passSampleContributions = 0; 74 96 int passSamples = 0; 75 int index = 0; 76 KdNode *visibleNode = NULL; 97 int index = 0; 77 98 78 99 for (i =0; i < objects.size(); i++) { 79 100 KdNode *nodeToSample = NULL; 80 101 Intersectable *object = objects[i]; 81 102 82 103 int pvsSize = object->mKdPvs.GetSize(); 83 84 85 if (pvsSize) { 86 // mail all nodes from the pvs 87 Intersectable::NewMail(); 88 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 89 for (; i != object->mKdPvs.mEntries.end(); i++) { 90 KdNode *node = (*i).first; 91 node->Mail(); 92 } 93 int maxTries = 2*pvsSize; 94 95 for (int tries = 0; tries < 10; tries++) { 96 index = RandomValue(0, pvsSize - 1); 97 KdPvsData data; 98 object->mKdPvs.GetData(index, visibleNode, data); 99 nodeToSample = mKdTree->FindRandomNeighbor(visibleNode, true); 100 if (nodeToSample) 101 break; 102 } 103 } 104 105 if (0 && pvsSize) { 106 // mail all nodes from the pvs 107 Intersectable::NewMail(); 108 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 109 for (; i != object->mKdPvs.mEntries.end(); i++) { 110 KdNode *node = (*i).first; 111 node->Mail(); 112 } 113 114 vector<KdNode *> invisibleNeighbors; 115 // get all neighbors of all PVS nodes 116 i = object->mKdPvs.mEntries.begin(); 117 for (; i != object->mKdPvs.mEntries.end(); i++) { 118 KdNode *node = (*i).first; 119 mKdTree->FindNeighbors(visibleNode, invisibleNeighbors, true); 120 } 121 122 KdPvsData data; 123 KdNode *visibleNode; 124 object->mKdPvs.GetData(index, visibleNode, data); 125 nodeToSample = mKdTree->FindRandomNeighbor(visibleNode, true); 126 if (nodeToSample) 127 break; 128 } 129 104 105 if (0 && pvsSize) { 106 // mail all nodes from the pvs 107 Intersectable::NewMail(); 108 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 109 for (; i != object->mKdPvs.mEntries.end(); i++) { 110 KdNode *node = (*i).first; 111 node->Mail(); 112 } 113 int maxTries = 2*pvsSize; 114 115 for (int tries = 0; tries < 10; tries++) { 116 index = RandomValue(0, pvsSize - 1); 117 KdPvsData data; 118 KdNode *node; 119 object->mKdPvs.GetData(index, node, data); 120 nodeToSample = mKdTree->FindRandomNeighbor(node, true); 121 if (nodeToSample) 122 break; 123 } 124 } 125 126 if (0 && pvsSize && pass == 100 ) { 127 // mail all nodes from the pvs 128 Intersectable::NewMail(); 129 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 130 for (; i != object->mKdPvs.mEntries.end(); i++) { 131 KdNode *node = (*i).first; 132 node->Mail(); 133 } 134 135 vector<KdNode *> invisibleNeighbors; 136 // get all neighbors of all PVS nodes 137 i = object->mKdPvs.mEntries.begin(); 138 for (; i != object->mKdPvs.mEntries.end(); i++) { 139 KdNode *node = (*i).first; 140 mKdTree->FindNeighbors(node, invisibleNeighbors, true); 141 AxisAlignedBox3 box = object->GetBox(); 142 for (int j=0; j < invisibleNeighbors.size(); j++) { 143 int visibility = ComputeBoxVisibility(mKdTree, 144 box, 145 mKdTree->GetBox(invisibleNeighbors[j]), 146 1.0f); 147 148 } 149 150 151 // now rank all the neighbors according to probability that a new 152 // sample creates some contribution 153 } 154 } 130 155 131 156 for (int k=0; k < mSamplesPerPass; k++) { 132 133 134 135 136 137 138 139 157 object->GetRandomSurfacePoint(point, normal); 158 if (nodeToSample) { 159 int maxTries = 5; 160 for (int tries = 0; tries < maxTries; tries++) { 161 direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 162 if (DotProd(direction, normal) > Limits::Small) 163 break; 164 } 140 165 141 142 143 144 145 146 147 148 149 150 151 152 153 166 if (tries == maxTries) 167 direction = UniformRandomVector(normal); 168 } else 169 direction = UniformRandomVector(normal); 170 171 // construct a ray 172 SetupRay(ray, point, direction); 173 mKdTree->CastRay(ray); 174 175 if (i < pvsOut) 176 rays[i].push_back(ray); 177 178 int sampleContributions = 0; 154 179 155 180 156 157 sampleContributions += AddNodeSamples(object, ray);181 if (ray.leaves.size()) { 182 sampleContributions += AddNodeSamples(object, ray, pass); 158 183 159 160 sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray);161 162 163 164 165 166 167 184 if (ray.intersections.size()) { 185 sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 186 // check whether we can add this to the rays 187 for (int j = 0; j < pvsOut; j++) { 188 if (objects[j] == ray.intersections[0].mObject) { 189 rays[j].push_back(ray); 190 } 191 } 192 } 168 193 169 194 passSamples++; 170 195 171 if (sampleContributions) { 172 passContributingSamples++; 173 passSampleContributions += sampleContributions; 174 } 175 } 176 } 177 } 196 if (sampleContributions) { 197 passContributingSamples++; 198 passSampleContributions += sampleContributions; 199 } 200 } 201 } 202 } 203 204 178 205 totalSamples += passSamples; 206 207 // if (pass>10) 208 // HoleSamplingPass(); 209 210 179 211 pass++; 180 212 … … 193 225 endl; 194 226 } 227 228 int totalPvsSize = mKdTree->CollectLeafPvs(); 229 cout<<"#totalPvsSize="<<totalPvsSize<<endl; 230 231 // HoleSamplingPass(); 232 if (1) { 233 Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 234 exporter->SetExportRayDensity(true); 235 exporter->ExportKdTree(*mKdTree); 236 delete exporter; 237 } 238 195 239 bool exportRays = false; 196 240 if (exportRays) { … … 214 258 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 215 259 Intersectable::NewMail(); 216 260 // avoid adding the object to the list 217 261 object->Mail(); 218 262 ObjectContainer visibleObjects;
Note: See TracChangeset
for help on using the changeset viewer.