- Timestamp:
- 08/03/05 11:15:30 (19 years ago)
- Location:
- trunk/VUT/GtpVisibilityPreprocessor
- Files:
-
- 26 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp
r177 r191 549 549 // x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 550 550 void 551 AxisAlignedBox3::GetVertex( int N, Vector3 &vertex) const551 AxisAlignedBox3::GetVertex(const int N, Vector3 &vertex) const 552 552 { 553 553 switch (N) { … … 1526 1526 return (m == M) ? m : m + M; 1527 1527 } 1528 1529 int 1530 AxisAlignedBox3::GetFaceVisibilityMask(const Rectangle3 &rectangle) const 1531 { 1532 int mask = 0; 1533 for (int i=0; i < 4; i++) 1534 mask |= GetFaceVisibilityMask(rectangle.mVertices[i]); 1535 return mask; 1536 } 1537 1538 int 1539 AxisAlignedBox3::GetFaceVisibilityMask(const Vector3 &position) const { 1540 1541 // assume that we are not inside the box 1542 int c=0; 1543 1544 if (position.x<(mMin.x-Limits::Small)) 1545 c|=1; 1546 else 1547 if (position.x>(mMax.x+Limits::Small)) 1548 c|=2; 1549 1550 if (position.y<(mMin.y-Limits::Small)) 1551 c|=4; 1552 else 1553 if (position.y>(mMax.y+Limits::Small)) 1554 c|=8; 1555 1556 if (position.z<(mMin.z-Limits::Small)) 1557 c|=16; 1558 else 1559 if (position.z>(mMax.z+Limits::Small)) 1560 c|=32; 1561 1562 return c; 1563 } 1564 1565 1566 Rectangle3 1567 AxisAlignedBox3::GetFace(const int face) const 1568 { 1569 Vector3 v[4]; 1570 switch (face) { 1571 1572 case 0: 1573 v[3].SetValue(mMin.x,mMin.y,mMin.z); 1574 v[2].SetValue(mMin.x,mMax.y,mMin.z); 1575 v[1].SetValue(mMin.x,mMax.y,mMax.z); 1576 v[0].SetValue(mMin.x,mMin.y,mMax.z); 1577 break; 1578 1579 case 1: 1580 v[0].SetValue(mMax.x,mMin.y,mMin.z); 1581 v[1].SetValue(mMax.x,mMax.y,mMin.z); 1582 v[2].SetValue(mMax.x,mMax.y,mMax.z); 1583 v[3].SetValue(mMax.x,mMin.y,mMax.z); 1584 break; 1585 1586 case 2: 1587 v[3].SetValue(mMin.x,mMin.y,mMin.z); 1588 v[2].SetValue(mMin.x,mMin.y,mMax.z); 1589 v[1].SetValue(mMax.x,mMin.y,mMax.z); 1590 v[0].SetValue(mMax.x,mMin.y,mMin.z); 1591 break; 1592 1593 case 3: 1594 v[0].SetValue(mMin.x,mMax.y,mMin.z); 1595 v[1].SetValue(mMin.x,mMax.y,mMax.z); 1596 v[2].SetValue(mMax.x,mMax.y,mMax.z); 1597 v[3].SetValue(mMax.x,mMax.y,mMin.z); 1598 break; 1599 1600 case 4: 1601 v[3].SetValue(mMin.x,mMin.y,mMin.z); 1602 v[2].SetValue(mMax.x,mMin.y,mMin.z); 1603 v[1].SetValue(mMax.x,mMax.y,mMin.z); 1604 v[0].SetValue(mMin.x,mMax.y,mMin.z); 1605 break; 1606 1607 case 5: 1608 v[0].SetValue(mMin.x,mMin.y,mMax.z); 1609 v[1].SetValue(mMax.x,mMin.y,mMax.z); 1610 v[2].SetValue(mMax.x,mMax.y,mMax.z); 1611 v[3].SetValue(mMin.x,mMax.y,mMax.z); 1612 break; 1613 } 1614 1615 return Rectangle3(v[0], v[1], v[2], v[3]); 1616 } -
trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.h
r177 r191 2 2 #define _AxisAlignedBox3_H__ 3 3 4 4 #include "Rectangle3.h" 5 5 #include "Matrix4x4.h" 6 6 #include "Vector3.h" … … 232 232 // x,y,z are either 0 or 1; (0 .. lower coordinate, 1 .. large coordinate) 233 233 // (xmin,ymin, zmin) .. N = 0, (xmax, ymax, zmax) .. N= 7 234 void GetVertex(int N, Vector3 &vertex) const; 235 234 void GetVertex(const int N, Vector3 &vertex) const; 235 236 Vector3 GetVertex(const int N) const { 237 Vector3 v; 238 GetVertex(N, v); 239 return v; 240 } 241 236 242 // Returns 1, if the box includes on arbitrary face a given box 237 243 int IsPiercedByBox(const AxisAlignedBox3 &box, int &axis) const; 238 244 245 246 int GetFaceVisibilityMask(const Vector3 &position) const; 247 int GetFaceVisibilityMask(const Rectangle3 &rectangle) const; 248 249 Rectangle3 GetFace(const int face) const; 250 239 251 // For a given point returns the region, where the point is located 240 252 // there are 27 regions (0..26) .. determined by the planes embedding in the … … 243 255 // R = 9*x + 3*y + z ; e.g. region .. inside the box is 13. 244 256 int GetRegionID(const Vector3 &point) const; 245 257 246 258 // Set the corner point of rectangle on the face of bounding box 247 259 // given by the index number and the rectangle lying on this face -
trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp
r182 r191 1 1 #include <algorithm> 2 #include <qstring.h> 3 #include <qimage.h> 2 3 // the devil library 4 #include <IL/il.h> 5 #include <IL/ilu.h> 6 #include <IL/ilut.h> 7 4 8 #include "Camera.h" 5 9 #include "Ray.h" … … 7 11 #include "Mesh.h" 8 12 #include "Exporter.h" 13 14 15 16 17 void 18 InitDevIl() 19 { 20 ilInit(); 21 ILuint ImageName; 22 ilGenImages(1, &ImageName); 23 ilBindImage(ImageName); 24 ilEnable(IL_FILE_OVERWRITE); 25 26 // ilRegisterFormat(IL_RGBA); 27 // ilRegisterType(IL_FLOAT); 28 29 // ilEnable(IL_ORIGIN_SET); 30 // ilOriginFunc(IL_ORIGIN_UPPER_LEFT); 31 } 9 32 10 33 bool … … 19 42 20 43 21 #if QT_VERSION < 0x040000 22 QImage image(mWidth, mHeight, 32);23 #else 24 //QImage image(mWidth, mHeight, QImage::Format_RGB32);25 #endif 44 InitDevIl(); 45 int components = 4; 46 float *buffer = new float[components*mWidth*mHeight]; 47 float *pbuffer = buffer; 48 // - components*mWidth; 26 49 27 50 vector<Ray> rays; … … 30 53 31 54 Ray ray; 55 32 56 for (y = 0; y < mHeight; y++) { 33 57 cout<<"+"; 34 58 for (x = 0; x < mWidth; x++) { 35 SetupRay(ray, x, y);59 SetupRay(ray, x, mHeight - (y + 1)); 36 60 if (tree->CastRay(ray)) 37 61 if (ray.intersections.size()) { … … 41 65 if (mesh->GetMesh()->mMaterial) 42 66 color = mesh->GetMesh()->mMaterial->mDiffuseColor; 43 #if QT_VERSION < 0x040000 44 image.setPixel(x, y, qRgb(color.r*255, 45 color.g*255, 46 color.b*255 47 )); 48 #endif 67 68 pbuffer[0] = color.r; 69 pbuffer[1] = color.g; 70 pbuffer[2] = color.b; 71 pbuffer[3] = 1.0f; 49 72 50 73 } 74 pbuffer+=components; 51 75 52 76 if (exportRays && (x==222) && (y==97)) 53 77 rays.push_back(ray); 54 78 } 79 // pbuffer-=2*components*mWidth; 55 80 } 56 81 … … 58 83 cout<<"#RAY_CAST_TIME\n"; 59 84 cout<<TimeDiff(t1, t2)<<"\n"; 85 60 86 61 87 cout<<"Saving image"<<endl; 62 #if QT_VERSION < 0x040000 63 image.save(filename.c_str(), "PNG"); 64 #endif 88 89 ilRegisterType(IL_FLOAT); 90 ilTexImage(mWidth, mHeight, 1, 4, IL_RGBA, IL_FLOAT, buffer); 91 ilSaveImage((char *const)filename.c_str()); 92 delete buffer; 93 65 94 Exporter *exporter = NULL; 66 95 if (exportRays) { -
trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h
r176 r191 18 18 protected: 19 19 string mFilename; 20 bool wireframe;20 bool mWireframe; 21 21 bool mUseForcedMaterial; 22 22 Material mForcedMaterial; 23 23 24 bool mExportRayDensity; 25 24 26 public: 25 27 26 28 Exporter(const string filename):mFilename(filename), 27 wireframe(false), 28 mUseForcedMaterial(false) 29 mWireframe(false), 30 mUseForcedMaterial(false), 31 mExportRayDensity(false) 29 32 { 30 33 } … … 49 52 ExportIntersectable(Intersectable *object) = 0; 50 53 51 void SetWireframe() { wireframe = true; } 52 void SetFilled() { wireframe = false; } 54 void SetExportRayDensity(const bool d) { mExportRayDensity = d; } 55 56 void SetWireframe() { mWireframe = true; } 57 void SetFilled() { mWireframe = false; } 53 58 54 59 void SetForcedMaterial(const Material &m) { -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp
r181 r191 710 710 return neighbors.size(); 711 711 } 712 713 void 714 KdTree::CollectLeaves(vector<KdLeaf *> &leaves) 715 { 716 stack<KdNode *> nodeStack; 717 nodeStack.push(mRoot); 718 719 while (!nodeStack.empty()) { 720 KdNode *node = nodeStack.top(); 721 nodeStack.pop(); 722 if (node->IsLeaf()) { 723 KdLeaf *leaf = (KdLeaf *)node; 724 leaves.push_back(leaf); 725 } else { 726 KdInterior *interior = (KdInterior *)node; 727 nodeStack.push(interior->mBack); 728 nodeStack.push(interior->mFront); 729 } 730 } 731 } 732 733 734 int 735 KdTree::CollectLeafPvs() 736 { 737 int totalPvsSize = 0; 738 stack<KdNode *> nodeStack; 739 740 nodeStack.push(mRoot); 741 742 while (!nodeStack.empty()) { 743 KdNode *node = nodeStack.top(); 744 nodeStack.pop(); 745 if (node->IsLeaf()) { 746 KdLeaf *leaf = (KdLeaf *)node; 747 for (int j=0; j < leaf->mObjects.size(); j++) { 748 Intersectable *object = leaf->mObjects[j]; 749 if (!object->Mailed()) { 750 object->Mail(); 751 // add this node to pvs of all nodes it can see 752 KdPvsMap::iterator ni = object->mKdPvs.mEntries.begin(); 753 for (; ni != object->mKdPvs.mEntries.end(); ni++) { 754 KdNode *node = (*ni).first; 755 // $$ JB TEMPORARY solution -> should add object PVS or explictly computed 756 // kd tree PVS 757 if (leaf->mKdPvs.AddNodeSample(node)) 758 totalPvsSize++; 759 } 760 } 761 } 762 } else { 763 KdInterior *interior = (KdInterior *)node; 764 nodeStack.push(interior->mFront); 765 nodeStack.push(interior->mBack); 766 } 767 } 768 769 return totalPvsSize; 770 } -
trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.h
r177 r191 8 8 #include "AxisAlignedBox3.h" 9 9 #include "Ray.h" 10 #include "Pvs.h" 10 11 11 12 … … 159 160 mObjects.reserve(objects); 160 161 } 161 162 163 void AddPassingRay(const Ray &ray, const int contributions) { 164 mPassingRays.AddRay(ray, contributions); 165 } 162 166 163 167 /** \sa KdNode::IsLeaf() */ 164 168 virtual bool IsLeaf() const { return true; } 169 170 171 165 172 166 173 /** pointers to occluders contained in this node */ … … 169 176 /** pointers to viewcells contained in this node */ 170 177 // ViewCellContainer mViewCells; 178 179 /** Ray set description of the rays passing through this node */ 180 PassingRaySet mPassingRays; 181 182 /** PVS consisting of visible KdTree nodes */ 183 KdPvs mKdPvs; 184 171 185 }; 172 186 … … 268 282 void 269 283 CollectObjects(KdNode *n, ObjectContainer &objects); 270 271 AxisAlignedBox3 GetBox(const KdNode *node) const { 284 285 void 286 CollectLeaves(vector<KdLeaf *> &leaves); 287 288 AxisAlignedBox3 GetBox(const KdNode *node) const { 272 289 KdInterior *parent = node->mParent; 273 290 if (parent == NULL) … … 295 312 bool onlyUnmailed 296 313 ); 297 314 315 int 316 CollectLeafPvs(); 317 298 318 protected: 299 319 … … 469 489 AxisAlignedBox3 mBox; 470 490 KdTreeStatistics mStat; 471 491 472 492 }; 473 493 -
trunk/VUT/GtpVisibilityPreprocessor/src/Makefile
r181 r191 1 1 ############################################################################# 2 2 # Makefile for building: preprocessor 3 # Generated by qmake (1.07a) (Qt 3.3.2) on: Mon Jul 18 20:55:1420053 # Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Aug 02 22:47:09 2005 4 4 # Project: preprocessor.pro 5 5 # Template: app … … 13 13 LEX = flex 14 14 YACC = byacc 15 CFLAGS = -nologo -Zm200 -W0 -MD d -Zi -GX -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT16 CXXFLAGS = -nologo -Zm200 -W0 -MD d -Zi -GX -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT15 CFLAGS = -nologo -Zm200 -W0 -MD -O2 -GX -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG 16 CXXFLAGS = -nologo -Zm200 -W0 -MD -O2 -GX -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG 17 17 LEXFLAGS = 18 18 YACCFLAGS =-d 19 INCPATH = -I"..\src" -I"..\support\xerces\include" -I"..\support\zlib\include" -I"..\support\boost" -I" $(QTDIR)\include" -I"d:\gametools\svn\trunk\VUT\GtpVisibilityPreprocessor\src" -I"C:\Qt\3.3.2\mkspecs\win32-msvc"19 INCPATH = -I"..\src" -I"..\support\xerces\include" -I"..\support\zlib\include" -I"..\support\boost" -I"..\support\devil\include" -I"$(QTDIR)\include" -I"d:\gametools\svn\trunk\VUT\GtpVisibilityPreprocessor\src" -I"C:\Qt\3.3.2\mkspecs\win32-msvc" 20 20 LINK = link 21 LFLAGS = /NOLOGO /DEBUG /SUBSYSTEM:console /LIBPATH:"../support/xerces/lib" /LIBPATH:"$(QTDIR)\lib"22 LIBS = "qt-mt332.lib" "qtmain.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "imm32.lib" "winmm.lib" "wsock32.lib" "winspool.lib" "xerces-c_2.lib" " opengl32.lib" "glu32.lib" "delayimp.lib"21 LFLAGS = /NOLOGO delayimp.lib /DELAYLOAD:comdlg32.dll /DELAYLOAD:oleaut32.dll /DELAYLOAD:winmm.dll /DELAYLOAD:wsock32.dll /DELAYLOAD:winspool.dll /SUBSYSTEM:console /LIBPATH:"../support/xerces/lib" /LIBPATH:"../support/devil/lib" /LIBPATH:"$(QTDIR)\lib" 22 LIBS = "qt-mt332.lib" "qtmain.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "imm32.lib" "winmm.lib" "wsock32.lib" "winspool.lib" "xerces-c_2.lib" "devil.lib" "ilu.lib" "ilut.lib" "opengl32.lib" "glu32.lib" "delayimp.lib" 23 23 MOC = $(QTDIR)\bin\moc.exe 24 24 UIC = $(QTDIR)\bin\uic.exe … … 61 61 X3dParser.cpp \ 62 62 MeshKdTree.cpp \ 63 Pvs.cpp 63 Pvs.cpp \ 64 MutualVisibility.cpp \ 65 Triangle3.cpp 64 66 OBJECTS = Preprocessor.obj \ 65 67 SamplingPreprocessor.obj \ … … 83 85 X3dParser.obj \ 84 86 MeshKdTree.obj \ 85 Pvs.obj 87 Pvs.obj \ 88 MutualVisibility.obj \ 89 Triangle3.obj 86 90 FORMS = 87 91 UICDECLS = … … 167 171 -$(DEL_FILE) MeshKdTree.obj 168 172 -$(DEL_FILE) Pvs.obj 169 -$(DEL_FILE) preprocessor.pdb 170 -$(DEL_FILE) preprocessor.ilk 171 -$(DEL_FILE) vc*.pdb 172 -$(DEL_FILE) vc*.idb 173 173 -$(DEL_FILE) MutualVisibility.obj 174 -$(DEL_FILE) Triangle3.obj 174 175 175 176 … … 190 191 Containers.h \ 191 192 AxisAlignedBox3.h \ 193 Rectangle3.h \ 192 194 Matrix4x4.h \ 193 195 Vector3.h \ … … 210 212 X3dExporter.h \ 211 213 Environment.h \ 212 Containers.h \ 213 AxisAlignedBox3.h \ 214 MutualVisibility.h \ 215 Containers.h \ 216 AxisAlignedBox3.h \ 217 Rectangle3.h \ 214 218 Matrix4x4.h \ 215 219 Vector3.h \ … … 239 243 Material.h \ 240 244 Pvs.h \ 245 Rectangle3.h \ 241 246 Vector3.h \ 242 247 common.h \ … … 255 260 Material.h \ 256 261 Pvs.h \ 262 Rectangle3.h \ 257 263 Vector3.h \ 258 264 Containers.h \ … … 288 294 AxisAlignedBox3.h \ 289 295 Pvs.h \ 296 Rectangle3.h \ 290 297 Containers.h \ 291 298 Parser.h \ … … 300 307 Containers.h \ 301 308 AxisAlignedBox3.h \ 309 Rectangle3.h \ 302 310 Matrix4x4.h \ 303 311 Vector3.h \ … … 315 323 Containers.h \ 316 324 AxisAlignedBox3.h \ 325 Rectangle3.h \ 317 326 Matrix4x4.h \ 318 327 Vector3.h \ … … 343 352 AxisAlignedBox3.h \ 344 353 Ray.h \ 354 Rectangle3.h \ 345 355 Matrix4x4.h \ 346 356 Vector3.h \ … … 376 386 Material.h \ 377 387 Pvs.h \ 388 Rectangle3.h \ 378 389 Vector3.h \ 379 390 common.h \ … … 393 404 Material.h \ 394 405 Pvs.h \ 406 Rectangle3.h \ 395 407 Containers.h \ 396 408 … … 411 423 AxisAlignedBox3.h \ 412 424 common.h \ 425 Rectangle3.h \ 413 426 Matrix4x4.h \ 414 427 Plane3.h \ … … 431 444 Material.h \ 432 445 Pvs.h \ 446 Rectangle3.h \ 433 447 Vector3.h \ 434 448 common.h \ … … 447 461 Material.h \ 448 462 Pvs.h \ 463 Rectangle3.h \ 449 464 Vector3.h \ 450 465 Containers.h \ … … 456 471 457 472 473 MutualVisibility.obj: MutualVisibility.cpp \ 474 KdTree.h \ 475 AxisAlignedBox3.h \ 476 Ray.h \ 477 MutualVisibility.h \ 478 Containers.h \ 479 Rectangle3.h \ 480 Matrix4x4.h \ 481 Vector3.h \ 482 Plane3.h \ 483 common.h \ 484 485 486 Triangle3.obj: Triangle3.cpp \ 487 Triangle3.h \ 488 Vector3.h \ 489 common.h \ 490 491 458 492 ####### Install 459 493 -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp
r176 r191 2 2 #include "Mesh.h" 3 3 #include "MeshKdTree.h" 4 #include "Triangle3.h" 4 5 5 6 int MeshInstance::mailID = 21843194198; … … 60 61 switch (ray.GetType()) { 61 62 case Ray::GLOBAL_RAY: 62 ray.intersections.push_back(Ray:: RayIntersection(t, instance, faceIndex));63 ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex)); 63 64 hit++; 64 65 break; … … 101 102 if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 102 103 if (ray.intersections.size()) 103 ray.intersections[0] = Ray:: RayIntersection(nearestT, instance, nearestFace);104 ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace); 104 105 else 105 ray.intersections.push_back(Ray:: RayIntersection(nearestT, instance, nearestFace));106 ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace)); 106 107 } 107 108 … … 135 136 if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 136 137 if (ray.intersections.size()) 137 ray.intersections[0] = Ray:: RayIntersection(nearestT, instance, nearestFace);138 ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace); 138 139 else 139 ray.intersections.push_back(Ray:: RayIntersection(nearestT, instance, nearestFace));140 ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace)); 140 141 } 141 142 … … 333 334 } 334 335 336 void 337 Mesh::AddTriangle(const Triangle3 &triangle) 338 { 339 int index = mVertices.size(); 340 341 for (int i=0; i < 3; i++) { 342 mVertices.push_back(triangle.mVertices[i]); 343 } 344 345 AddFace(new Face(index + 0, index + 1, index + 2) ); 346 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.h
r176 r191 10 10 #include "Material.h" 11 11 12 12 class Triangle3; 13 13 class MeshInstance; 14 14 class MeshKdTree; … … 73 73 delete mFaces[i]; 74 74 } 75 76 void AddTriangle(const Triangle3 &triangle); 75 77 76 78 void AddFace(Face *face) -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.cpp
r177 r191 39 39 KdPvsMap::iterator i = mEntries.begin(); 40 40 for (int k = 0; k!=index && i != mEntries.end(); i++, k++); 41 42 41 node = (*i).first; 43 42 data = (*i).second; -
trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h
r177 r191 5 5 6 6 class KdNode; 7 class Ray; 7 8 8 9 struct LtKdNode … … 29 30 int mSamples; 30 31 KdPvsMap mEntries; 32 33 KdPvs():mSamples(0),mEntries() {} 34 31 35 KdPvsData *Find(KdNode *node); 32 36 int AddNodeSample(KdNode *node); … … 40 44 }; 41 45 46 47 42 48 #endif 43 49 -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp
r162 r191 121 121 } 122 122 123 void 124 PassingRaySet::Reset() 125 { 126 for (int i=0; i < 3*Resolution*Resolution; i++) 127 mDirectionalContributions[i] = 0; 128 mRays = 0; 129 mContributions = 0; 130 } 131 132 void 133 PassingRaySet::AddRay(const Ray &ray, const int contributions) 134 { 135 int i = GetEntryIndex(ray.GetDir()); 136 mRays++; 137 mContributions += contributions; 138 mDirectionalContributions[i] += contributions; 139 } 140 141 int 142 PassingRaySet::GetEntryIndex(const Vector3 &direction) const 143 { 144 // get face 145 int axis = direction.DrivingAxis(); 146 Vector3 dir; 147 float k = direction[axis]; 148 if ( k < 0.0f) 149 k = -k; 150 151 dir = direction/k; 152 float x, y; 153 dir.ExtractVerts(&x, &y, axis); 154 int ix = (x + 1.0f)*0.5f*Resolution; 155 int iy = (y + 1.0f)*0.5f*Resolution; 156 157 return Resolution*(Resolution*axis + iy) + ix; 158 } 159 160 ostream & 161 operator<<(ostream &s, const PassingRaySet &set) 162 { 163 s<<"Ray Set #rays="<<set.mRays<<" #contributions="<<set.mContributions<<endl; 164 for (int i=0; i < 3*sqr(PassingRaySet::Resolution); i++) 165 s<<set.mDirectionalContributions[i]<<" "; 166 s<<endl; 167 return s; 168 } -
trunk/VUT/GtpVisibilityPreprocessor/src/Ray.h
r176 r191 25 25 enum { NO_INTERSECTION=0, INTERSECTION_OUT_OF_LIMITS, INTERSECTION }; 26 26 27 struct RayIntersection {27 struct Intersection { 28 28 // the point of intersection 29 29 float mT; … … 35 35 int mFace; 36 36 37 RayIntersection(const float t,38 39 40 41 RayIntersection() {}37 Intersection(const float t, 38 Intersectable *object, 39 const int face):mT(t), mObject(object), mFace(face) {} 40 41 Intersection() {} 42 42 43 43 bool operator<( 44 const RayIntersection &b) const {44 const Intersection &b) const { 45 45 return 46 46 mT … … 54 54 // corresponds to the spatial elementary cell 55 55 /** intersection with the source object if any */ 56 RayIntersection sourceObject;57 58 vector< RayIntersection> intersections;56 Intersection sourceObject; 57 58 vector<Intersection> intersections; 59 59 vector<KdLeaf *> leaves; 60 60 vector<MeshInstance *> meshes; … … 74 74 Ray() {} 75 75 76 Intersectable *GetIntersectionObject(const int i) const { 77 return intersections[i].mObject; 78 } 79 80 Vector3 GetIntersectionPoint(const int i) const { 81 return Extrap(intersections[i].mT); 82 } 76 83 77 84 // Inititalize the ray again when already constructed … … 151 158 152 159 // the object on which the ray starts at 153 const RayIntersection* GetStartObject() const { return &intersections[0]; }154 const RayIntersection* GetStopObject() const { return &intersections[intersections.size()-1]; }160 const Intersection* GetStartObject() const { return &intersections[0]; } 161 const Intersection* GetStopObject() const { return &intersections[intersections.size()-1]; } 155 162 156 163 … … 220 227 221 228 229 class PassingRaySet { 230 public: 231 enum { Resolution = 2 }; 232 int mDirectionalContributions[3*Resolution*Resolution]; 233 int mRays; 234 int mContributions; 235 PassingRaySet() { 236 Reset(); 237 } 238 void 239 Reset(); 240 241 void AddRay(const Ray &ray, const int contributions); 242 int GetEntryIndex(const Vector3 &direction) const; 243 244 friend ostream &operator<<(ostream &s, const PassingRaySet &set); 245 246 }; 222 247 223 248 -
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; -
trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h
r176 r191 24 24 25 25 int 26 AddNodeSamples(Intersectable *object, const Ray &ray); 26 AddNodeSamples(Intersectable *object, const Ray &ray, const int pass); 27 28 void 29 HoleSamplingPass(); 27 30 28 31 }; -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp
r176 r191 145 145 146 146 147 if ( wireframe)147 if (mWireframe) 148 148 stream<<"<IndexedLineSet ccw=\"TRUE\" coordIndex=\""<<endl; 149 149 else … … 174 174 stream<<"</Coordinate>"<<endl; 175 175 176 if ( wireframe)176 if (mWireframe) 177 177 stream<<"</IndexedLineSet>"<<endl; 178 178 else … … 211 211 X3dExporter::ExportKdTree(const KdTree &tree) 212 212 { 213 if (mExportRayDensity) { 214 return ExportKdTreeRayDensity(tree); 215 } 216 213 217 stack<KdNode *> tStack; 214 218 … … 249 253 250 254 255 bool 256 X3dExporter::ExportKdTreeRayDensity(const KdTree &tree) 257 { 258 stack<KdNode *> tStack; 259 260 tStack.push(tree.GetRoot()); 261 262 bool fm = mUseForcedMaterial; 263 mUseForcedMaterial = true; 264 mForcedMaterial.mDiffuseColor.g = 1.0f; 265 mForcedMaterial.mDiffuseColor.b = 1.0f; 266 while (!tStack.empty()) { 267 KdNode *node = tStack.top(); 268 tStack.pop(); 269 if (node->IsLeaf()) { 270 AxisAlignedBox3 box = tree.GetBox(node); 271 Mesh *mesh = new Mesh; 272 273 // add 6 vertices of the box 274 int index = mesh->mVertices.size(); 275 for (int i=0; i < 8; i++) { 276 Vector3 v; 277 box.GetVertex(i, v); 278 mesh->mVertices.push_back(v); 279 } 280 mesh->AddFace(new Face(index + 0, index + 1, index + 3, index + 2) ); 281 mesh->AddFace(new Face(index + 0, index + 2, index + 6, index + 4) ); 282 mesh->AddFace(new Face(index + 4, index + 6, index + 7, index + 5) ); 283 284 mesh->AddFace(new Face(index + 3, index + 1, index + 5, index + 7) ); 285 mesh->AddFace(new Face(index + 0, index + 4, index + 5, index + 1) ); 286 mesh->AddFace(new Face(index + 2, index + 3, index + 7, index + 6) ); 287 288 289 // set the mesh material according to the ray density 290 KdLeaf *leaf = (KdLeaf *) node; 291 if (leaf->mPassingRays.mRays) { 292 float importance = leaf->mPassingRays.mContributions/(float)leaf->mPassingRays.mRays; 293 // float importance = leaf->mPassingRays.mContributions/1000.0f; 294 // float importance = leaf->mPassingRays.mRays/1000.0f; 295 ///(float)leaf->mPassingRays.mRays; 296 // mForcedMaterial.mDiffuseColor.r = log10(leaf->mPassingRays.mRays)/3.0f; 297 mForcedMaterial.mDiffuseColor.r = importance; 298 mForcedMaterial.mDiffuseColor.g = 1.0f - mForcedMaterial.mDiffuseColor.r; 299 ExportMesh(mesh); 300 } 301 delete mesh; 302 } else { 303 KdInterior *interior = (KdInterior *)node; 304 tStack.push(interior->mFront); 305 tStack.push(interior->mBack); 306 } 307 } 308 // restore the state of forced material 309 mUseForcedMaterial = fm; 310 return true; 311 } -
trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.h
r176 r191 57 57 virtual void 58 58 ExportSceneNode(SceneGraphNode *node); 59 59 60 bool 61 ExportKdTreeRayDensity(const KdTree &tree); 60 62 61 63 -
trunk/VUT/GtpVisibilityPreprocessor/src/default.env
r177 r191 8 8 # filename glasgow1.x3d 9 9 # filename vienna.x3d 10 filename atlanta2.x3d10 # filename atlanta2.x3d 11 11 # filename soda.dat 12 filename soda5.dat 12 13 13 14 } … … 53 54 54 55 Sampling { 55 totalSamples 50000056 samplesPerPass 256 totalSamples 1000000 57 samplesPerPass 5 57 58 } -
trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp
r176 r191 45 45 Camera camera; 46 46 camera.LookAtBox(p->mKdTree->GetBox()); 47 camera.SnapImage("camera.png", p->mKdTree); 47 camera.SnapImage("camera.jpg", p->mKdTree); 48 48 49 49 50 camera.LookInBox(p->mKdTree->GetBox()); -
trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro
r181 r191 6 6 #win32:INCLUDEPATH += c:/STLport-4.6.2/stlport 7 7 8 INCLUDEPATH += ../src ../support/xerces/include ../support/zlib/include ../support/boost 8 INCLUDEPATH += ../src ../support/xerces/include ../support/zlib/include ../support/boost ../support/devil/include 9 9 10 win32:LIBPATH += ../support/xerces/lib 10 win32:LIBPATH += ../support/xerces/lib ../support/devil/lib 11 11 12 12 #win32:LIBPATH += c:/STLport-4.6.2/lib 13 13 14 14 # debuc config 15 CONFIG += console warn_off thread debug15 CONFIG += console warn_off thread release 16 16 17 17 # RELEASE CONFIG … … 20 20 # DEPENDPATH = ../../include 21 21 22 win32:LIBS += xerces-c_2.lib 22 win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib 23 23 24 24 # Input … … 31 31 UnigraphicsParser.cpp X3dExporter.cpp SceneGraph.cpp Material.cpp \ 32 32 Matrix4x4.cpp Vector3.cpp AxisAlignedBox3.cpp Ray.cpp main.cpp Mesh.cpp \ 33 Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp Pvs.cpp 33 Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp Pvs.cpp \ 34 MutualVisibility.cpp Triangle3.cpp 34 35 35 36
Note: See TracChangeset
for help on using the changeset viewer.