Changeset 191 for trunk/VUT


Ignore:
Timestamp:
08/03/05 11:15:30 (19 years ago)
Author:
bittner
Message:

basic sampling strategies

Location:
trunk/VUT/GtpVisibilityPreprocessor
Files:
26 added
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/VUT/GtpVisibilityPreprocessor/src/AxisAlignedBox3.cpp

    r177 r191  
    549549// x,y,z are either 0 or 1; (0 .. min coordinate, 1 .. max coordinate) 
    550550void 
    551 AxisAlignedBox3::GetVertex(int N, Vector3 &vertex) const 
     551AxisAlignedBox3::GetVertex(const int N, Vector3 &vertex) const 
    552552{ 
    553553  switch (N) { 
     
    15261526  return (m == M) ? m : m + M; 
    15271527} 
     1528 
     1529int 
     1530AxisAlignedBox3::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 
     1538int 
     1539AxisAlignedBox3::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 
     1566Rectangle3 
     1567AxisAlignedBox3::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  
    22#define _AxisAlignedBox3_H__ 
    33 
    4  
     4#include "Rectangle3.h" 
    55#include "Matrix4x4.h" 
    66#include "Vector3.h" 
     
    232232  // x,y,z are either 0 or 1; (0 .. lower coordinate, 1 .. large coordinate) 
    233233  // (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 
    236242  // Returns 1, if the box includes on arbitrary face a given box 
    237243  int IsPiercedByBox(const AxisAlignedBox3 &box, int &axis) const; 
    238244 
     245 
     246  int GetFaceVisibilityMask(const Vector3 &position) const; 
     247  int GetFaceVisibilityMask(const Rectangle3 &rectangle) const; 
     248 
     249  Rectangle3 GetFace(const int face) const; 
     250   
    239251  // For a given point returns the region, where the point is located 
    240252  // there are 27 regions (0..26) .. determined by the planes embedding in the 
     
    243255  // R = 9*x + 3*y + z  ; e.g. region .. inside the box is 13. 
    244256  int GetRegionID(const Vector3 &point) const; 
    245  
     257   
    246258  // Set the corner point of rectangle on the face of bounding box 
    247259  // given by the index number and the rectangle lying on this face 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Camera.cpp

    r182 r191  
    11#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 
    48#include "Camera.h" 
    59#include "Ray.h" 
     
    711#include "Mesh.h" 
    812#include "Exporter.h" 
     13 
     14 
     15 
     16 
     17void 
     18InitDevIl() 
     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} 
    932 
    1033bool 
     
    1942 
    2043   
    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; 
    2649   
    2750  vector<Ray> rays; 
     
    3053 
    3154  Ray ray; 
     55 
    3256  for (y = 0; y < mHeight; y++) { 
    3357    cout<<"+"; 
    3458    for (x = 0; x < mWidth; x++) { 
    35       SetupRay(ray, x, y); 
     59      SetupRay(ray, x, mHeight - (y + 1)); 
    3660      if (tree->CastRay(ray)) 
    3761        if (ray.intersections.size()) { 
     
    4165          if (mesh->GetMesh()->mMaterial) 
    4266            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; 
    4972 
    5073        } 
     74      pbuffer+=components; 
    5175       
    5276      if (exportRays && (x==222) && (y==97)) 
    5377        rays.push_back(ray); 
    5478    } 
     79    //    pbuffer-=2*components*mWidth; 
    5580  } 
    5681   
     
    5883  cout<<"#RAY_CAST_TIME\n"; 
    5984  cout<<TimeDiff(t1, t2)<<"\n"; 
     85 
    6086   
    6187  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   
    6594  Exporter *exporter = NULL; 
    6695  if (exportRays) { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Exporter.h

    r176 r191  
    1818protected: 
    1919  string mFilename; 
    20   bool wireframe; 
     20  bool mWireframe; 
    2121  bool mUseForcedMaterial; 
    2222  Material mForcedMaterial; 
    2323 
     24  bool mExportRayDensity; 
     25   
    2426public: 
    2527   
    2628  Exporter(const string filename):mFilename(filename), 
    27                                   wireframe(false), 
    28                                   mUseForcedMaterial(false) 
     29                                  mWireframe(false), 
     30                                  mUseForcedMaterial(false), 
     31                                  mExportRayDensity(false) 
    2932  { 
    3033  } 
     
    4952  ExportIntersectable(Intersectable *object) = 0; 
    5053 
    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; } 
    5358 
    5459  void SetForcedMaterial(const Material &m) { 
  • trunk/VUT/GtpVisibilityPreprocessor/src/KdTree.cpp

    r181 r191  
    710710  return neighbors.size(); 
    711711} 
     712 
     713void 
     714KdTree::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 
     734int 
     735KdTree::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  
    88#include "AxisAlignedBox3.h" 
    99#include "Ray.h" 
     10#include "Pvs.h" 
    1011 
    1112   
     
    159160    mObjects.reserve(objects); 
    160161  } 
    161  
     162   
     163  void AddPassingRay(const Ray &ray, const int contributions) { 
     164    mPassingRays.AddRay(ray, contributions); 
     165  } 
    162166   
    163167  /** \sa KdNode::IsLeaf() */ 
    164168  virtual bool IsLeaf() const { return true; } 
     169   
     170 
     171   
    165172 
    166173  /** pointers to occluders contained in this node */ 
     
    169176  /** pointers to viewcells contained in this node */ 
    170177  //  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   
    171185}; 
    172186   
     
    268282  void 
    269283  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 { 
    272289    KdInterior *parent = node->mParent; 
    273290    if (parent == NULL) 
     
    295312                bool onlyUnmailed 
    296313                ); 
    297    
     314 
     315  int 
     316  CollectLeafPvs(); 
     317 
    298318protected: 
    299319 
     
    469489  AxisAlignedBox3 mBox; 
    470490  KdTreeStatistics mStat; 
    471  
     491   
    472492}; 
    473493   
  • trunk/VUT/GtpVisibilityPreprocessor/src/Makefile

    r181 r191  
    11############################################################################# 
    22# Makefile for building: preprocessor 
    3 # Generated by qmake (1.07a) (Qt 3.3.2) on: Mon Jul 18 20:55:14 2005 
     3# Generated by qmake (1.07a) (Qt 3.3.2) on: Tue Aug 02 22:47:09 2005 
    44# Project:  preprocessor.pro 
    55# Template: app 
     
    1313LEX             = flex 
    1414YACC            = byacc 
    15 CFLAGS  =       -nologo -Zm200 -W0 -MDd -Zi -GX  -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT 
    16 CXXFLAGS        =       -nologo -Zm200 -W0 -MDd -Zi -GX  -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT 
     15CFLAGS  =       -nologo -Zm200 -W0 -MD -O2 -GX  -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG 
     16CXXFLAGS        =       -nologo -Zm200 -W0 -MD -O2 -GX  -DUNICODE -DQT_DLL -DQT_THREAD_SUPPORT -DQT_NO_DEBUG 
    1717LEXFLAGS        = 
    1818YACCFLAGS       =-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" 
     19INCPATH =        -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" 
    2020LINK    =       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" 
     21LFLAGS  =       /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" 
     22LIBS    =        "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" 
    2323MOC             =       $(QTDIR)\bin\moc.exe 
    2424UIC             =       $(QTDIR)\bin\uic.exe 
     
    6161                X3dParser.cpp \ 
    6262                MeshKdTree.cpp \ 
    63                 Pvs.cpp 
     63                Pvs.cpp \ 
     64                MutualVisibility.cpp \ 
     65                Triangle3.cpp 
    6466OBJECTS =       Preprocessor.obj \ 
    6567                SamplingPreprocessor.obj \ 
     
    8385                X3dParser.obj \ 
    8486                MeshKdTree.obj \ 
    85                 Pvs.obj 
     87                Pvs.obj \ 
     88                MutualVisibility.obj \ 
     89                Triangle3.obj 
    8690FORMS =  
    8791UICDECLS =       
     
    167171        -$(DEL_FILE) MeshKdTree.obj 
    168172        -$(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 
    174175 
    175176 
     
    190191                Containers.h \ 
    191192                AxisAlignedBox3.h \ 
     193                Rectangle3.h \ 
    192194                Matrix4x4.h \ 
    193195                Vector3.h \ 
     
    210212                X3dExporter.h \ 
    211213                Environment.h \ 
    212                 Containers.h \ 
    213                 AxisAlignedBox3.h \ 
     214                MutualVisibility.h \ 
     215                Containers.h \ 
     216                AxisAlignedBox3.h \ 
     217                Rectangle3.h \ 
    214218                Matrix4x4.h \ 
    215219                Vector3.h \ 
     
    239243                Material.h \ 
    240244                Pvs.h \ 
     245                Rectangle3.h \ 
    241246                Vector3.h \ 
    242247                common.h \ 
     
    255260                Material.h \ 
    256261                Pvs.h \ 
     262                Rectangle3.h \ 
    257263                Vector3.h \ 
    258264                Containers.h \ 
     
    288294                AxisAlignedBox3.h \ 
    289295                Pvs.h \ 
     296                Rectangle3.h \ 
    290297                Containers.h \ 
    291298                Parser.h \ 
     
    300307                Containers.h \ 
    301308                AxisAlignedBox3.h \ 
     309                Rectangle3.h \ 
    302310                Matrix4x4.h \ 
    303311                Vector3.h \ 
     
    315323                Containers.h \ 
    316324                AxisAlignedBox3.h \ 
     325                Rectangle3.h \ 
    317326                Matrix4x4.h \ 
    318327                Vector3.h \ 
     
    343352                AxisAlignedBox3.h \ 
    344353                Ray.h \ 
     354                Rectangle3.h \ 
    345355                Matrix4x4.h \ 
    346356                Vector3.h \ 
     
    376386                Material.h \ 
    377387                Pvs.h \ 
     388                Rectangle3.h \ 
    378389                Vector3.h \ 
    379390                common.h \ 
     
    393404                Material.h \ 
    394405                Pvs.h \ 
     406                Rectangle3.h \ 
    395407                Containers.h \ 
    396408                 
     
    411423                AxisAlignedBox3.h \ 
    412424                common.h \ 
     425                Rectangle3.h \ 
    413426                Matrix4x4.h \ 
    414427                Plane3.h \ 
     
    431444                Material.h \ 
    432445                Pvs.h \ 
     446                Rectangle3.h \ 
    433447                Vector3.h \ 
    434448                common.h \ 
     
    447461                Material.h \ 
    448462                Pvs.h \ 
     463                Rectangle3.h \ 
    449464                Vector3.h \ 
    450465                Containers.h \ 
     
    456471                 
    457472 
     473MutualVisibility.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 
     486Triangle3.obj: Triangle3.cpp  \ 
     487                Triangle3.h \ 
     488                Vector3.h \ 
     489                common.h \ 
     490                 
     491 
    458492####### Install 
    459493 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Mesh.cpp

    r176 r191  
    22#include "Mesh.h" 
    33#include "MeshKdTree.h" 
     4#include "Triangle3.h" 
    45 
    56int MeshInstance::mailID = 21843194198; 
     
    6061    switch (ray.GetType()) { 
    6162    case Ray::GLOBAL_RAY: 
    62       ray.intersections.push_back(Ray::RayIntersection(t, instance, faceIndex)); 
     63      ray.intersections.push_back(Ray::Intersection(t, instance, faceIndex)); 
    6364      hit++; 
    6465      break; 
     
    101102  if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 
    102103    if (ray.intersections.size()) 
    103       ray.intersections[0] = Ray::RayIntersection(nearestT, instance, nearestFace); 
     104      ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace); 
    104105    else 
    105       ray.intersections.push_back(Ray::RayIntersection(nearestT, instance, nearestFace)); 
     106      ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace)); 
    106107  } 
    107108   
     
    135136  if ( hits && ray.GetType() == Ray::LOCAL_RAY ) { 
    136137    if (ray.intersections.size()) 
    137       ray.intersections[0] = Ray::RayIntersection(nearestT, instance, nearestFace); 
     138      ray.intersections[0] = Ray::Intersection(nearestT, instance, nearestFace); 
    138139    else 
    139       ray.intersections.push_back(Ray::RayIntersection(nearestT, instance, nearestFace)); 
     140      ray.intersections.push_back(Ray::Intersection(nearestT, instance, nearestFace)); 
    140141  } 
    141142   
     
    333334} 
    334335 
     336void 
     337Mesh::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  
    1010#include "Material.h" 
    1111 
    12  
     12class Triangle3; 
    1313class MeshInstance; 
    1414class MeshKdTree; 
     
    7373      delete mFaces[i]; 
    7474  } 
     75 
     76  void AddTriangle(const Triangle3 &triangle); 
    7577   
    7678  void AddFace(Face *face)  
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.cpp

    r177 r191  
    3939  KdPvsMap::iterator i = mEntries.begin(); 
    4040  for (int k = 0; k!=index && i != mEntries.end(); i++, k++); 
    41  
    4241  node = (*i).first; 
    4342  data = (*i).second; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Pvs.h

    r177 r191  
    55 
    66class KdNode; 
     7class Ray; 
    78 
    89struct LtKdNode 
     
    2930  int mSamples; 
    3031  KdPvsMap mEntries; 
     32   
     33  KdPvs():mSamples(0),mEntries() {} 
     34   
    3135  KdPvsData *Find(KdNode *node); 
    3236  int AddNodeSample(KdNode *node); 
     
    4044}; 
    4145 
     46 
     47 
    4248#endif 
    4349 
  • trunk/VUT/GtpVisibilityPreprocessor/src/Ray.cpp

    r162 r191  
    121121} 
    122122 
     123void 
     124PassingRaySet::Reset() 
     125{ 
     126  for (int i=0; i < 3*Resolution*Resolution; i++) 
     127    mDirectionalContributions[i] = 0; 
     128  mRays = 0; 
     129  mContributions = 0; 
     130} 
     131   
     132void 
     133PassingRaySet::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 
     141int 
     142PassingRaySet::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 
     160ostream & 
     161operator<<(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  
    2525  enum { NO_INTERSECTION=0, INTERSECTION_OUT_OF_LIMITS, INTERSECTION }; 
    2626 
    27   struct RayIntersection { 
     27  struct Intersection { 
    2828    // the point of intersection 
    2929    float mT; 
     
    3535    int mFace; 
    3636 
    37     RayIntersection(const float t, 
    38                     Intersectable *object, 
    39                     const int face):mT(t), mObject(object), mFace(face) {} 
    40  
    41     RayIntersection() {} 
     37    Intersection(const float t, 
     38                 Intersectable *object, 
     39                 const int face):mT(t), mObject(object), mFace(face) {} 
     40 
     41    Intersection() {} 
    4242 
    4343    bool operator<( 
    44                    const RayIntersection &b) const { 
     44                   const Intersection &b) const { 
    4545      return  
    4646        mT 
     
    5454  // corresponds to the spatial elementary cell 
    5555  /** intersection with the source object if any */ 
    56   RayIntersection sourceObject; 
    57    
    58   vector<RayIntersection> intersections; 
     56  Intersection sourceObject; 
     57   
     58  vector<Intersection> intersections; 
    5959  vector<KdLeaf *> leaves; 
    6060  vector<MeshInstance *> meshes; 
     
    7474  Ray() {} 
    7575 
     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  } 
    7683   
    7784  // Inititalize the ray again when already constructed 
     
    151158 
    152159  // 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]; } 
    155162   
    156163   
     
    220227 
    221228 
     229class PassingRaySet { 
     230public: 
     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}; 
    222247 
    223248 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.cpp

    r181 r191  
    44#include "X3dExporter.h" 
    55#include "Environment.h" 
     6#include "MutualVisibility.h" 
     7 
    68SamplingPreprocessor::SamplingPreprocessor() 
    79{ 
     
    3335 
    3436int 
    35 SamplingPreprocessor::AddNodeSamples(Intersectable *object, const Ray &ray) 
     37SamplingPreprocessor::AddNodeSamples(Intersectable *object, 
     38                                     const Ray &ray, 
     39                                     const int pass) 
    3640{ 
    3741  int contributingSamples = 0; 
    38  
    39   for (int j=0; j < ray.leaves.size(); j++) { 
     42  int j; 
     43  for (j=0; j < ray.leaves.size(); j++) { 
    4044    KdNode *node = GetNodeForPvs( ray.leaves[j] ); 
    4145    contributingSamples += object->mKdPvs.AddNodeSample(node); 
    4246  } 
    4347   
     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   
    4453  return contributingSamples; 
     54} 
     55 
     56 
     57void 
     58SamplingPreprocessor::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  } 
    4568} 
    4669 
     
    6386  int totalSamples = 0; 
    6487 
    65  
    6688  int pvsOut = Min((int)objects.size(), 10); 
    6789   
     
    7395    int passSampleContributions = 0; 
    7496    int passSamples = 0; 
    75         int index = 0; 
    76     KdNode *visibleNode = NULL; 
     97    int index = 0; 
    7798 
    7899    for (i =0; i < objects.size(); i++) { 
    79100      KdNode *nodeToSample = NULL; 
    80101      Intersectable *object = objects[i]; 
    81  
     102       
    82103      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      } 
    130155 
    131156      for (int k=0; k < mSamplesPerPass; k++) { 
    132                   object->GetRandomSurfacePoint(point, normal); 
    133                   if (nodeToSample) { 
    134                           int maxTries = 5; 
    135                           for (int tries = 0; tries < maxTries; tries++) { 
    136                                   direction = mKdTree->GetBox(nodeToSample).GetRandomPoint() - point; 
    137                                   if (DotProd(direction, normal) > Limits::Small) 
    138                                         break; 
    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          } 
    140165                 
    141                           if (tries == maxTries) 
    142                                   direction = UniformRandomVector(normal); 
    143                   } else 
    144                           direction = UniformRandomVector(normal); 
    145          
    146                   // construct a ray 
    147                   SetupRay(ray, point, direction); 
    148                   mKdTree->CastRay(ray); 
    149  
    150                   if (i < pvsOut) 
    151                           rays[i].push_back(ray); 
    152          
    153                   int sampleContributions = 0; 
     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; 
    154179         
    155180                   
    156                   if (ray.leaves.size()) { 
    157                           sampleContributions += AddNodeSamples(object, ray); 
     181        if (ray.leaves.size()) { 
     182          sampleContributions += AddNodeSamples(object, ray, pass); 
    158183           
    159                           if (ray.intersections.size()) { 
    160                                   sampleContributions += AddNodeSamples(ray.intersections[0].mObject, ray); 
    161                                   // check whether we can add this to the rays 
    162                                   for (int j = 0; j < pvsOut; j++) { 
    163                                           if (objects[j] == ray.intersections[0].mObject) { 
    164                                                   rays[j].push_back(ray); 
    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          } 
    168193                 
    169                           passSamples++; 
     194          passSamples++; 
    170195                         
    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 
    178205    totalSamples += passSamples; 
     206 
     207    //    if (pass>10) 
     208    //      HoleSamplingPass(); 
     209     
     210 
    179211    pass++; 
    180212     
     
    193225      endl; 
    194226  } 
     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   
    195239  bool exportRays = false; 
    196240  if (exportRays) { 
     
    214258      KdPvsMap::iterator i = object->mKdPvs.mEntries.begin(); 
    215259      Intersectable::NewMail(); 
    216         // avoid adding the object to the list 
     260      // avoid adding the object to the list 
    217261      object->Mail(); 
    218262      ObjectContainer visibleObjects; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/SamplingPreprocessor.h

    r176 r191  
    2424 
    2525  int 
    26   AddNodeSamples(Intersectable *object, const Ray &ray); 
     26  AddNodeSamples(Intersectable *object, const Ray &ray, const int pass); 
     27 
     28  void 
     29  HoleSamplingPass(); 
    2730 
    2831}; 
  • trunk/VUT/GtpVisibilityPreprocessor/src/X3dExporter.cpp

    r176 r191  
    145145 
    146146 
    147   if (wireframe) 
     147  if (mWireframe) 
    148148    stream<<"<IndexedLineSet ccw=\"TRUE\" coordIndex=\""<<endl; 
    149149  else 
     
    174174  stream<<"</Coordinate>"<<endl; 
    175175 
    176   if (wireframe) 
     176  if (mWireframe) 
    177177    stream<<"</IndexedLineSet>"<<endl; 
    178178  else 
     
    211211X3dExporter::ExportKdTree(const KdTree &tree) 
    212212{ 
     213  if (mExportRayDensity) { 
     214    return ExportKdTreeRayDensity(tree); 
     215  } 
     216   
    213217  stack<KdNode *> tStack; 
    214218 
     
    249253 
    250254 
     255bool 
     256X3dExporter::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  
    5757  virtual void 
    5858  ExportSceneNode(SceneGraphNode *node); 
    59    
     59 
     60  bool 
     61  ExportKdTreeRayDensity(const KdTree &tree); 
    6062 
    6163   
  • trunk/VUT/GtpVisibilityPreprocessor/src/default.env

    r177 r191  
    88#       filename glasgow1.x3d 
    99#       filename vienna.x3d 
    10         filename atlanta2.x3d 
     10#       filename atlanta2.x3d 
    1111#       filename soda.dat 
     12        filename soda5.dat 
    1213 
    1314} 
     
    5354 
    5455Sampling { 
    55         totalSamples    500000 
    56         samplesPerPass  2 
     56        totalSamples    1000000 
     57        samplesPerPass  5 
    5758} 
  • trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp

    r176 r191  
    4545    Camera camera; 
    4646    camera.LookAtBox(p->mKdTree->GetBox()); 
    47     camera.SnapImage("camera.png", p->mKdTree); 
     47    camera.SnapImage("camera.jpg", p->mKdTree); 
     48 
    4849     
    4950    camera.LookInBox(p->mKdTree->GetBox()); 
  • trunk/VUT/GtpVisibilityPreprocessor/src/preprocessor.pro

    r181 r191  
    66#win32:INCLUDEPATH += c:/STLport-4.6.2/stlport 
    77 
    8 INCLUDEPATH += ../src ../support/xerces/include  ../support/zlib/include ../support/boost 
     8INCLUDEPATH += ../src ../support/xerces/include  ../support/zlib/include ../support/boost ../support/devil/include 
    99 
    10 win32:LIBPATH += ../support/xerces/lib 
     10win32:LIBPATH += ../support/xerces/lib ../support/devil/lib 
    1111 
    1212#win32:LIBPATH += c:/STLport-4.6.2/lib 
    1313 
    1414# debuc config 
    15 CONFIG          += console warn_off thread debug 
     15CONFIG          += console warn_off thread release 
    1616 
    1717# RELEASE CONFIG 
     
    2020# DEPENDPATH    = ../../include 
    2121 
    22 win32:LIBS += xerces-c_2.lib 
     22win32:LIBS += xerces-c_2.lib devil.lib ilu.lib ilut.lib 
    2323 
    2424# Input 
     
    3131UnigraphicsParser.cpp X3dExporter.cpp SceneGraph.cpp Material.cpp \ 
    3232Matrix4x4.cpp Vector3.cpp AxisAlignedBox3.cpp Ray.cpp main.cpp Mesh.cpp \ 
    33 Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp Pvs.cpp 
     33Exporter.cpp Camera.cpp X3dParser.cpp MeshKdTree.cpp Pvs.cpp \ 
     34MutualVisibility.cpp Triangle3.cpp 
    3435 
    3536 
Note: See TracChangeset for help on using the changeset viewer.