Changeset 223
- Timestamp:
- 08/08/05 23:44:02 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.cpp
r209 r223 27 27 Vector3 origin, direction; 28 28 GetRay(rayIndex, origin, direction); 29 return origin + direction*m Intersections[rayIndex][depth].mT;29 return origin + direction*mSamples[rayIndex].mIntersections[depth].mT; 30 30 } 31 31 … … 76 76 switch (axis) { 77 77 case 0: 78 sample1.m Intersections[0] = sample.mIntersections[0];79 sample1.m Intersections[3] = sample.mIntersections[3];80 81 sample2.m Intersections[1] = sample.mIntersections[1];82 sample2.m Intersections[2] = sample.mIntersections[2];78 sample1.mSamples[0].mIntersections = sample.mSamples[0].mIntersections; 79 sample1.mSamples[3].mIntersections = sample.mSamples[3].mIntersections; 80 81 sample2.mSamples[1].mIntersections = sample.mSamples[1].mIntersections; 82 sample2.mSamples[2].mIntersections = sample.mSamples[2].mIntersections; 83 83 break; 84 84 85 85 case 1: 86 sample1.m Intersections[0] = sample.mIntersections[0];87 sample1.m Intersections[1] = sample.mIntersections[1];88 89 sample2.m Intersections[2] = sample.mIntersections[2];90 sample2.m Intersections[2] = sample.mIntersections[3];86 sample1.mSamples[0].mIntersections = sample.mSamples[0].mIntersections; 87 sample1.mSamples[1].mIntersections = sample.mSamples[1].mIntersections; 88 89 sample2.mSamples[2].mIntersections = sample.mSamples[2].mIntersections; 90 sample2.mSamples[3].mIntersections = sample.mSamples[3].mIntersections; 91 91 break; 92 92 } … … 148 148 ) 149 149 { 150 Vector3 normal = target.Center() - source.Center(); 151 150 Vector3 sourceCenter = source.Center(); 151 Vector3 targetCenter = target.Center(); 152 Vector3 normal = Normalize(sourceCenter - targetCenter ); 153 152 154 Plane3 sourcePlane(normal, source.GetVertex(0)); 153 155 int i; … … 158 160 } 159 161 160 Plane3 targetPlane( -normal, target.GetVertex(0));162 Plane3 targetPlane(normal, target.GetVertex(0)); 161 163 for (i=1; i < 8; i++) { 162 164 Vector3 v = target.GetVertex(i); 163 if (targetPlane.Distance(v) >0)164 targetPlane = Plane3( -normal, v);165 if (targetPlane.Distance(v) < 0) 166 targetPlane = Plane3(normal, v); 165 167 } 166 168 … … 175 177 176 178 Vector3 yBasis = Normalize( CrossProd(normal, xBasis) ); 177 178 Plane3 bottomPlane(xBasis, source.Center()); 179 Plane3 sidePlane(yBasis, source.Center()); 180 181 // cast rays between corresponding vertices of the boxes 182 for (i=0; i < 8; i++) { 183 184 185 } 179 // cast rays between the centers of the boxes 180 Vector3 targetRCenter = targetPlane.FindIntersection(sourceCenter, 181 targetCenter); 182 183 Vector3 sourceRCenter = sourcePlane.FindIntersection(sourceCenter, 184 targetCenter); 185 186 187 Rectangle3 sourceRect; 188 Rectangle3 targetRect; 189 190 191 float scale = Magnitude(source.Size())*0.7f; 192 sourceRect.mVertices[0] = sourceRCenter - scale*xBasis - scale*yBasis; 193 sourceRect.mVertices[1] = sourceRCenter + scale*xBasis - scale*yBasis; 194 sourceRect.mVertices[2] = sourceRCenter + scale*xBasis + scale*yBasis; 195 sourceRect.mVertices[3] = sourceRCenter - scale*xBasis + scale*yBasis; 196 197 scale = Magnitude(target.Size())*0.7f; 198 targetRect.mVertices[0] = targetRCenter - scale*xBasis - scale*yBasis; 199 targetRect.mVertices[1] = targetRCenter + scale*xBasis - scale*yBasis; 200 targetRect.mVertices[2] = targetRCenter + scale*xBasis + scale*yBasis; 201 targetRect.mVertices[3] = targetRCenter - scale*xBasis + scale*yBasis; 202 203 AddInitialSamples(sourceRect, targetRect, samples); 204 205 // Plane3 bottomPlane(xBasis, source.Center()); 206 // Plane3 sidePlane(yBasis, source.Center()); 207 208 // // cast rays between corresponding vertices of the boxes 209 // for (i=0; i < 8; i++) { 210 // Vector3 v; 211 // bool coplanar; 212 // v = sourcePlane.FindIntersection(source.GetVertex(i), 213 // target.GetVertex(i), 214 // NULL, 215 // &coplanar); 216 // if (!coplanar) { 217 // // evaluate source and 218 219 // } 220 // } 186 221 187 222 // AddInitialSamples(sourceRectangle, targetRectangle, samples); … … 213 248 sprintf(filename, "samples%04d-%02d.x3d", id++, i); 214 249 Exporter *exporter = Exporter::GetExporter(filename); 250 251 exporter->SetWireframe(); 252 exporter->ExportBox(mSource); 253 exporter->ExportBox(mTarget); 254 215 255 exporter->SetFilled(); 216 256 … … 238 278 239 279 int 280 MutualVisibilitySampler::CastRays(RayShaft &shaft) 281 { 282 Ray ray; 283 int i; 284 285 for (i=0; i < 4; i++) { 286 Vector3 origin, direction; 287 shaft.GetRay(i, origin, direction); 288 // determine intersections with the boxes 289 ray.Init(origin, direction, Ray::LINE_SEGMENT); 290 float stmin, stmax, ttmin, ttmax; 291 if ( mSource.GetMinMaxT(ray, &stmin, &stmax) && mTarget.GetMinMaxT(ray, &ttmin, &ttmax) ) { 292 shaft.mSamples[i].mMinT = stmax; 293 shaft.mSamples[i].mMaxT = ttmin; 294 origin = ray.Extrap(stmax); 295 direction = ray.Extrap(ttmin) - origin; 296 // reinit the ray 297 ray.Init(origin, direction, Ray::LINE_SEGMENT); 298 if (!mKdTree->CastRay(ray)) 299 return VISIBLE; 300 } else { 301 shaft.mSamples[i].mMaxT = -1.0; 302 } 303 } 304 return INVISIBLE; 305 } 306 307 int 240 308 MutualVisibilitySampler::ComputeVisibility() 241 309 { 242 310 243 vector<RayShaft *> s amples;244 ConstructInitialSamples(mSource, mTarget, s amples);245 ExportSamples(s amples);246 247 stack<RayShaft *> s ampleStack;311 vector<RayShaft *> shafts; 312 ConstructInitialSamples(mSource, mTarget, shafts); 313 ExportSamples(shafts); 314 315 stack<RayShaft *> shaftStack; 248 316 249 317 250 318 251 319 Ray ray; 252 // now process the s amples as long as we have something to do253 while (!s ampleStack.empty()) {254 RayShaft *s ample = sampleStack.top();255 s ampleStack.pop();320 // now process the shafts as long as we have something to do 321 while (!shaftStack.empty()) { 322 RayShaft *shaft = shaftStack.top(); 323 shaftStack.pop(); 256 324 257 325 // // cast a new ray 258 326 // int triangleSplitEdge = SetupExtremalRay(sample, source, ray); 259 327 260 // if (!kdTree->CastRay(ray))261 //return VISIBLE;262 263 // // generate 2 new samples264 // RayShaft newSamples[2];265 // sample.Split(triangleSplitEdge, ray, newSamples[0], newSamples[1]);266 // for (i=0; i < 2; i++) {267 // newSamples[i].ComputeError();268 // if (newSamples[i].mError > solidAngleThreshold) {269 // sampleStack.push(newSamples[i]);270 // }271 // }272 // }273 } 274 275 for (int i=0; i < s amples.size(); i++)276 delete s amples[i];328 if (CastRays(*shaft) == VISIBLE) 329 return VISIBLE; 330 331 // // generate 2 new samples 332 // RayShaft newSamples[2]; 333 // sample.Split(triangleSplitEdge, ray, newSamples[0], newSamples[1]); 334 // for (i=0; i < 2; i++) { 335 // newSamples[i].ComputeError(); 336 // if (newSamples[i].mError > solidAngleThreshold) { 337 // sampleStack.push(newSamples[i]); 338 // } 339 // } 340 // } 341 } 342 343 for (int i=0; i < shafts.size(); i++) 344 delete shafts[i]; 277 345 return INVISIBLE; 278 346 } -
trunk/VUT/GtpVisibilityPreprocessor/src/MutualVisibility.h
r209 r223 13 13 }; 14 14 15 struct RaySample { 16 /// true if the sample really intersects both boxes 17 float mMinT; 18 float mMaxT; 19 /// intersections of the sample with the scene 20 vector<Ray::Intersection> mIntersections; 21 bool IsValid() const { return mMaxT > 0.0; } 22 }; 15 23 16 24 struct RayShaft { … … 25 33 Rectangle3 mTarget; 26 34 27 /// intersections with the scene 28 vector<Ray::Intersection> mIntersections[4]; 35 RaySample mSamples[4]; 29 36 30 37 void ComputeError(); … … 112 119 ); 113 120 121 int 122 CastRays(RayShaft &shaft); 123 114 124 void 115 125 ComputeError(RayShaft &sample); 116 126 117 127 void 118 128 ExportSamples(vector<RayShaft *> &samples); -
trunk/VUT/GtpVisibilityPreprocessor/src/Rectangle3.h
r221 r223 38 38 Rectangle3 &r1, 39 39 Rectangle3 &r2 40 ) const 41 42 {//TODO 43 } 40 ) const; 44 41 45 42 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r218 r223 91 91 92 92 while (totalSamples < mTotalSamples) 93 {94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 93 { 94 int passContributingSamples = 0; 95 int passSampleContributions = 0; 96 int passSamples = 0; 97 int index = 0; 98 99 for (i =0; i < objects.size(); i++) { 100 KdNode *nodeToSample = NULL; 101 Intersectable *object = objects[i]; 102 103 int pvsSize = object->mKdPvs.GetSize(); 104 105 if (0 && pvsSize) { 106 // mail all nodes from the pvs 107 Intersectable::NewMail(); 108 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 109 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 if (0 && pvsSize && pass == 50) {129 // mail all nodes from the pvs130 Intersectable::NewMail();131 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin();132 for (; i != object->mKdPvs.mEntries.end(); i++) {133 KdNode *node = (*i).first;134 node->Mail();135 }136 137 vector<KdNode *> invisibleNeighbors;138 // get all neighbors of all PVS nodes139 i = object->mKdPvs.mEntries.begin();140 141 142 143 144 145 146 for (int j=0; j < invisibleNeighbors.size(); j++)147 {148 int visibility = ComputeBoxVisibility(mKdTree,149 box,150 mKdTree->GetBox(invisibleNeighbors[j]),151 1.0f);152 }153 // now rank all the neighbors according to probability that a new154 // sample creates some contribution155 156 } 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 110 for (; i != object->mKdPvs.mEntries.end(); i++) { 111 KdNode *node = (*i).first; 112 node->Mail(); 113 } 114 115 int maxTries = 2*pvsSize; 116 117 for (int tries = 0; tries < 10; tries++) { 118 index = RandomValue(0, pvsSize - 1); 119 KdPvsData data; 120 KdNode *node; 121 object->mKdPvs.GetData(index, node, data); 122 nodeToSample = mKdTree->FindRandomNeighbor(node, true); 123 if (nodeToSample) 124 break; 125 } 126 } 127 128 129 if (pvsSize && pass == 50 ) { 130 // mail all nodes from the pvs 131 Intersectable::NewMail(); 132 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 133 for (; i != object->mKdPvs.mEntries.end(); i++) { 134 KdNode *node = (*i).first; 135 node->Mail(); 136 } 137 138 vector<KdNode *> invisibleNeighbors; 139 // get all neighbors of all PVS nodes 140 i = object->mKdPvs.mEntries.begin(); 141 for (; i != object->mKdPvs.mEntries.end(); i++) { 142 KdNode *node = (*i).first; 143 mKdTree->FindNeighbors(node, invisibleNeighbors, true); 144 AxisAlignedBox3 box = object->GetBox(); 145 for (int j=0; j < invisibleNeighbors.size(); j++) { 146 int visibility = ComputeBoxVisibility(mKdTree, 147 box, 148 mKdTree->GetBox(invisibleNeighbors[j]), 149 1.0f); 150 151 } 152 // now rank all the neighbors according to probability that a new 153 // sample creates some contribution 154 } 155 } 156 157 158 for (int k=0; k < mSamplesPerPass; k++) { 159 object->GetRandomSurfacePoint(point, normal); 160 161 if (nodeToSample) { 162 int maxTries = 5; 163 164 for (int tries = 0; tries < maxTries; tries++) { 165 direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 166 167 if (DotProd(direction, normal) > Limits::Small) 168 break; 169 } 170 171 if (tries == maxTries) 172 direction = UniformRandomVector(normal); 173 } 174 else 175 direction = UniformRandomVector(normal); 176 177 // construct a ray 178 SetupRay(ray, point, direction); 179 mKdTree->CastRay(ray); 180 181 if (i < pvsOut) 182 rays[i].push_back(ray); 183 184 int sampleContributions = 0; 185 186 187 if (ray.leaves.size()) { 188 sampleContributions += AddNodeSamples(object, ray, pass); 189 190 if (ray.intersections.size()) { 191 sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass); 192 // check whether we can add this to the rays 193 for (int j = 0; j < pvsOut; j++) { 194 if (objects[j] == ray.intersections[0].mObject) { 195 rays[j].push_back(ray); 196 } 197 } 198 } 199 200 passSamples++; 201 201 202 if (sampleContributions) { 203 passContributingSamples++; 204 passSampleContributions += sampleContributions; 205 } 206 } 207 } 202 if (sampleContributions) { 203 passContributingSamples++; 204 passSampleContributions += sampleContributions; 205 } 206 } 208 207 } 209 210 totalSamples += passSamples; 211 212 // if (pass>10) 213 // HoleSamplingPass(); 214 215 216 pass++; 217 218 int pvsSize = 0; 219 for (i=0; i < objects.size(); i++) { 220 Intersectable *object = objects[i]; 221 pvsSize += object->mKdPvs.GetSize(); 208 } 209 210 totalSamples += passSamples; 211 212 // if (pass>10) 213 // HoleSamplingPass(); 214 215 216 pass++; 217 218 int pvsSize = 0; 219 for (i=0; i < objects.size(); i++) { 220 Intersectable *object = objects[i]; 221 pvsSize += object->mKdPvs.GetSize(); 222 } 223 224 cout << "pass " << pass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 225 cout << "#totalSamples=" << totalSamples/1000 226 << "k #sampleContributions=" << passSampleContributions << " (" 227 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 228 << pvsSize/(float)objects.size() << endl 229 << "avg ray contrib=" << passSampleContributions/(float)passContributingSamples << endl; 222 230 } 223 224 cout << "pass " << pass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;225 cout << "#totalSamples=" << totalSamples/1000226 << "k #sampleContributions=" << passSampleContributions << " ("227 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS="228 << pvsSize/(float)objects.size() << endl229 << "avg ray contrib=" << passSampleContributions/(float)passContributingSamples << endl;230 }231 231 232 232 int totalPvsSize = mKdTree->CollectLeafPvs(); … … 235 235 // HoleSamplingPass(); 236 236 if (1) { 237 238 239 240 237 Exporter *exporter = Exporter::GetExporter("ray-density.x3d"); 238 exporter->SetExportRayDensity(true); 239 exporter->ExportKdTree(*mKdTree); 240 delete exporter; 241 241 } 242 242 243 243 bool exportRays = false; 244 244 if (exportRays) { 245 246 247 248 249 250 251 252 253 254 245 Exporter *exporter = NULL; 246 exporter = Exporter::GetExporter("sample-rays.x3d"); 247 exporter->SetWireframe(); 248 exporter->ExportKdTree(*mKdTree); 249 250 for (i=0; i < pvsOut; i++) 251 exporter->ExportRays(rays[i], 1000, RgbColor(1, 0, 0)); 252 exporter->SetFilled(); 253 254 delete exporter; 255 255 } 256 256 257 257 if (1) { 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 258 for (int k=0; k < pvsOut; k++) { 259 Intersectable *object = objects[k]; 260 char s[64]; 261 sprintf(s, "sample-pvs%04d.x3d", k); 262 Exporter *exporter = Exporter::GetExporter(s); 263 exporter->SetWireframe(); 264 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 265 266 Intersectable::NewMail(); 267 268 // avoid adding the object to the list 269 object->Mail(); 270 ObjectContainer visibleObjects; 271 for (; i != object->mKdPvs.mEntries.end(); i++) { 272 KdNode *node = (*i).first; 273 exporter->ExportBox(mKdTree->GetBox(node)); 274 mKdTree->CollectObjects(node, visibleObjects); 275 } 276 277 exporter->ExportRays(rays[k], 1000, RgbColor(0, 1, 0)); 278 exporter->SetFilled(); 279 280 for (int j = 0; j < visibleObjects.size(); j++) 281 exporter->ExportIntersectable(visibleObjects[j]); 282 283 Material m; 284 m.mDiffuseColor = RgbColor(1, 0, 0); 285 exporter->SetForcedMaterial(m); 286 exporter->ExportIntersectable(object); 287 288 delete exporter; 289 } 290 290 } 291 291
Note: See TracChangeset
for help on using the changeset viewer.