Changeset 256 for trunk/VUT/GtpVisibilityPreprocessor/src
- Timestamp:
- 08/28/05 15:13:06 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor/src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.cpp
r242 r256 154 154 } 155 155 156 157 Vector3 158 Polygon3::Center() const 159 { 160 int i; 161 Vector3 sum = mVertices[0]; 162 for (i=1; i < mVertices.size(); i++) 163 sum += mVertices[i]; 164 165 return sum/i; 166 } 167 168 169 void 170 Polygon3::Scale(const float scale) 171 { 172 int i; 173 Vector3 center = Center(); 174 for (i=0; i < mVertices.size(); i++) { 175 mVertices[i] = center + scale*(mVertices[i] - center); 176 } 177 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Polygon3.h
r242 r256 53 53 int Side(const Plane3 &plane) const; 54 54 55 /** Scales the polygon about its center 56 */ 57 void Scale(const float scale); 58 59 /** Computes the center of mass of the polygon 60 */ 61 Vector3 Center() const; 62 63 55 64 /** Deletes all polygons om the queue. 56 65 */ -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp
r245 r256 5 5 #include "Environment.h" 6 6 #include "MutualVisibility.h" 7 #include "Polygon3.h" 7 8 8 9 SamplingPreprocessor::SamplingPreprocessor() … … 37 38 int 38 39 SamplingPreprocessor::AddNodeSamples(Intersectable *object, 39 const Ray &ray,40 const int pass)40 const Ray &ray 41 ) 41 42 { 42 43 int contributingSamples = 0; … … 47 48 } 48 49 49 if ( pass > 10)50 if (mPass > 10) 50 51 for (j=1; j < ray.leaves.size() - 1; j++) { 51 52 ray.leaves[j]->AddPassingRay(ray, contributingSamples ? 1 : 0); … … 67 68 cout<<leaf->mPassingRays<<endl; 68 69 } 70 } 71 72 73 int 74 SamplingPreprocessor::CastRay(Intersectable *object, Ray &ray) 75 { 76 mKdTree->CastRay(ray); 77 int sampleContributions = 0; 78 if (ray.leaves.size()) { 79 sampleContributions += AddNodeSamples(object, ray); 80 81 if (ray.intersections.size()) { 82 sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray); 83 } 84 } 85 return sampleContributions; 69 86 } 70 87 … … 121 138 122 139 140 void 141 SamplingPreprocessor::CastEdgeSamples( 142 Intersectable *object, 143 const Vector3 &point, 144 Mesh &mesh, 145 const int samples 146 ) 147 { 148 Ray ray; 149 int i; 150 for (i=0; i < samples; i++) { 151 // pickup a random face of each mesh 152 int face = RandomValue(0, mesh.mFaces.size()-1); 153 154 Polygon3 poly(mesh.mFaces[face], &mesh); 155 poly.Scale(1.001); 156 // now extend a random edge of the face 157 int edge = RandomValue(0, poly.mVertices.size()-1); 158 float t = RandomValue(0.0f,1.0f); 159 Vector3 target = t*poly.mVertices[edge] + (1.0f-t)*poly.mVertices[(edge + 1)% 160 poly.mVertices.size()]; 161 SetupRay(ray, point, target - point); 162 CastRay(object, ray); 163 } 164 } 123 165 124 166 bool … … 137 179 138 180 int i; 139 int pass = 0;140 181 int totalSamples = 0; 141 182 … … 144 185 vector<Ray> rays[10]; 145 186 146 while (totalSamples < mTotalSamples) 147 { 148 int passContributingSamples = 0; 149 int passSampleContributions = 0; 150 int passSamples = 0; 151 int index = 0; 152 153 for (i =0; i < objects.size(); i++) { 154 KdNode *nodeToSample = NULL; 155 Intersectable *object = objects[i]; 187 while (totalSamples < mTotalSamples) { 188 int passContributingSamples = 0; 189 int passSampleContributions = 0; 190 int passSamples = 0; 191 int index = 0; 192 193 for (i =0; i < objects.size(); i++) { 194 KdNode *nodeToSample = NULL; 195 Intersectable *object = objects[i]; 196 197 int pvsSize = object->mKdPvs.GetSize(); 198 199 200 201 if (0 && pvsSize) { 202 // mail all nodes from the pvs 203 Intersectable::NewMail(); 204 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 205 206 for (; i != object->mKdPvs.mEntries.end(); i++) { 207 KdNode *node = (*i).first; 208 node->Mail(); 209 } 210 211 int maxTries = 2*pvsSize; 212 213 for (int tries = 0; tries < 10; tries++) { 214 index = RandomValue(0, pvsSize - 1); 215 KdPvsData data; 216 KdNode *node; 217 object->mKdPvs.GetData(index, node, data); 218 nodeToSample = mKdTree->FindRandomNeighbor(node, true); 219 if (nodeToSample) 220 break; 221 } 222 } 223 224 if (0 && pvsSize && mPass == 1000 ) { 225 // mail all nodes from the pvs 226 Intersectable::NewMail(); 227 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 228 for (; i != object->mKdPvs.mEntries.end(); i++) { 229 KdNode *node = (*i).first; 230 node->Mail(); 231 } 232 233 vector<KdNode *> invisibleNeighbors; 234 // get all neighbors of all PVS nodes 235 i = object->mKdPvs.mEntries.begin(); 236 for (; i != object->mKdPvs.mEntries.end(); i++) { 237 KdNode *node = (*i).first; 238 mKdTree->FindNeighbors(node, invisibleNeighbors, true); 239 AxisAlignedBox3 box = object->GetBox(); 240 for (int j=0; j < invisibleNeighbors.size(); j++) { 241 int visibility = ComputeBoxVisibility(mSceneGraph, 242 mKdTree, 243 box, 244 mKdTree->GetBox(invisibleNeighbors[j]), 245 1e-6f); 246 // exit(0); 247 } 248 // now rank all the neighbors according to probability that a new 249 // sample creates some contribution 250 } 251 } 252 253 254 object->GetRandomSurfacePoint(point, normal); 255 bool viewcellSample = true; 256 int sampleContributions; 257 if (viewcellSample) { 258 nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point)); 259 260 for (int k=0; k < mSamplesPerPass; k++) { 261 262 if (nodeToSample) { 263 int maxTries = 5; 264 265 for (int tries = 0; tries < maxTries; tries++) { 266 direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 267 268 if (DotProd(direction, normal) > Limits::Small) 269 break; 270 } 271 272 if (tries == maxTries) 273 direction = UniformRandomVector(normal); 274 } 275 else { 276 direction = UniformRandomVector(normal); 277 } 278 279 // construct a ray 280 SetupRay(ray, point, direction); 281 sampleContributions = CastRay(object, ray); 282 } 283 } else { 284 // edge samples 285 // get random visible mesh 286 // object->GetRandomVisibleMesh(Plane3(normal, point)); 287 288 289 } 290 291 292 if ( i < pvsOut ) 293 rays[i].push_back(ray); 294 295 if (ray.intersections.size()) { 296 // check whether we can add this to the rays 297 for (int j = 0; j < pvsOut; j++) { 298 if (objects[j] == ray.intersections[0].mObject) { 299 rays[j].push_back(ray); 300 } 301 } 302 } 303 304 passSamples++; 305 306 if (sampleContributions) { 307 passContributingSamples++; 308 passSampleContributions += sampleContributions; 309 } 310 } 311 312 156 313 157 int pvsSize = object->mKdPvs.GetSize(); 158 159 160 161 if (0 && pvsSize) { 162 // mail all nodes from the pvs 163 Intersectable::NewMail(); 164 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 165 166 for (; i != object->mKdPvs.mEntries.end(); i++) { 167 KdNode *node = (*i).first; 168 node->Mail(); 169 } 170 171 int maxTries = 2*pvsSize; 172 173 for (int tries = 0; tries < 10; tries++) { 174 index = RandomValue(0, pvsSize - 1); 175 KdPvsData data; 176 KdNode *node; 177 object->mKdPvs.GetData(index, node, data); 178 nodeToSample = mKdTree->FindRandomNeighbor(node, true); 179 if (nodeToSample) 180 break; 181 } 314 totalSamples += passSamples; 315 316 // if (pass>10) 317 // HoleSamplingPass(); 318 319 320 mPass++; 321 322 int pvsSize = 0; 323 for (i=0; i < objects.size(); i++) { 324 Intersectable *object = objects[i]; 325 pvsSize += object->mKdPvs.GetSize(); 326 } 327 328 cout << "#Pass " << mPass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl; 329 cout << "#TotalSamples=" << totalSamples/1000 330 << "k #SampleContributions=" << passSampleContributions << " (" 331 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS=" 332 << pvsSize/(float)objects.size() << endl 333 << "avg ray contrib=" << passSampleContributions/(float)passContributingSamples << endl; 334 335 336 mStats << 337 "#Pass\n" <<mPass<<endl<< 338 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<< 339 "#TotalSamples\n" << totalSamples<< endl<< 340 "#SampleContributions\n" << passSampleContributions << endl << 341 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl << 342 "#AvgPVS\n"<< pvsSize/(float)objects.size() << endl << 343 "#AvgRayContrib\n" << passSampleContributions/(float)passContributingSamples << endl; 182 344 } 183 345 184 if (0 && pvsSize && pass == 1000 ) {185 // mail all nodes from the pvs186 Intersectable::NewMail();187 KdPvsMap::iterator i = object->mKdPvs.mEntries.begin();188 for (; i != object->mKdPvs.mEntries.end(); i++) {189 KdNode *node = (*i).first;190 node->Mail();191 }192 193 vector<KdNode *> invisibleNeighbors;194 // get all neighbors of all PVS nodes195 i = object->mKdPvs.mEntries.begin();196 for (; i != object->mKdPvs.mEntries.end(); i++) {197 KdNode *node = (*i).first;198 mKdTree->FindNeighbors(node, invisibleNeighbors, true);199 AxisAlignedBox3 box = object->GetBox();200 for (int j=0; j < invisibleNeighbors.size(); j++) {201 int visibility = ComputeBoxVisibility(mSceneGraph,202 mKdTree,203 box,204 mKdTree->GetBox(invisibleNeighbors[j]),205 1e-6f);206 // exit(0);207 }208 // now rank all the neighbors according to probability that a new209 // sample creates some contribution210 }211 }212 213 object->GetRandomSurfacePoint(point, normal);214 nodeToSample = mKdTree->GetRandomLeaf(Plane3(normal, point));215 216 for (int k=0; k < mSamplesPerPass; k++) {217 218 if (nodeToSample) {219 int maxTries = 5;220 221 for (int tries = 0; tries < maxTries; tries++) {222 direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point;223 224 if (DotProd(direction, normal) > Limits::Small)225 break;226 }227 228 if (tries == maxTries)229 direction = UniformRandomVector(normal);230 }231 else {232 direction = UniformRandomVector(normal);233 }234 235 // construct a ray236 SetupRay(ray, point, direction);237 mKdTree->CastRay(ray);238 239 if ( i < pvsOut )240 rays[i].push_back(ray);241 242 int sampleContributions = 0;243 244 if (ray.leaves.size()) {245 sampleContributions += AddNodeSamples(object, ray, pass);246 247 if (ray.intersections.size()) {248 sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray, pass);249 // check whether we can add this to the rays250 for (int j = 0; j < pvsOut; j++) {251 if (objects[j] == ray.intersections[0].mObject) {252 rays[j].push_back(ray);253 }254 }255 }256 257 passSamples++;258 259 if (sampleContributions) {260 passContributingSamples++;261 passSampleContributions += sampleContributions;262 }263 }264 }265 }266 267 totalSamples += passSamples;268 269 // if (pass>10)270 // HoleSamplingPass();271 272 273 pass++;274 275 int pvsSize = 0;276 for (i=0; i < objects.size(); i++) {277 Intersectable *object = objects[i];278 pvsSize += object->mKdPvs.GetSize();279 }280 281 cout << "#Pass " << pass<<" : t = " << TimeDiff(startTime, GetTime())*1e-3 << "s" << endl;282 cout << "#TotalSamples=" << totalSamples/1000283 << "k #SampleContributions=" << passSampleContributions << " ("284 << 100*passContributingSamples/(float)passSamples<<"%)" << " avgPVS="285 << pvsSize/(float)objects.size() << endl286 << "avg ray contrib=" << passSampleContributions/(float)passContributingSamples << endl;287 288 289 mStats <<290 "#Pass\n" <<pass<<endl<<291 "#Time\n" << TimeDiff(startTime, GetTime())*1e-3 << endl<<292 "#TotalSamples\n" << totalSamples<< endl<<293 "#SampleContributions\n" << passSampleContributions << endl <<294 "#PContributingSamples\n"<<100*passContributingSamples/(float)passSamples<<endl <<295 "#AvgPVS\n"<< pvsSize/(float)objects.size() << endl <<296 "#AvgRayContrib\n" << passSampleContributions/(float)passContributingSamples << endl;297 }298 299 346 int totalPvsSize = mKdTree->CollectLeafPvs(); 300 347 cout << "#totalPvsSize=" << totalPvsSize << endl; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r245 r256 16 16 class SamplingPreprocessor : public Preprocessor { 17 17 public: 18 int mPass; 19 18 20 int mSamplesPerPass; 19 21 int mTotalSamples; … … 33 35 34 36 int 35 AddNodeSamples(Intersectable *object, const Ray &ray , const int pass);37 AddNodeSamples(Intersectable *object, const Ray &ray); 36 38 37 39 void 38 40 HoleSamplingPass(); 41 42 int 43 CastRay(Intersectable *object, Ray &ray); 44 45 void 46 CastEdgeSamples( 47 Intersectable *object, 48 const Vector3 &point, 49 Mesh &mesh, 50 const int samples 51 ); 39 52 40 53 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/ViewCell.cpp
r245 r256 64 64 { 65 65 Intersectable *object = objects[i]; 66 66 67 67 // extract the mesh instances 68 68 if (object->Type() == Intersectable::MESH_INSTANCE)
Note: See TracChangeset
for help on using the changeset viewer.