瀏覽代碼

orient_outward_ao: account for distances from intersection points

Former-commit-id: 0651550825637ab3531516d7f252f62cbaa7e87f
Kenshi Takayama (kenshi 11 年之前
父節點
當前提交
96fbbcee23
共有 3 個文件被更改,包括 47 次插入23 次删除
  1. 6 0
      examples/patches/example.cpp
  2. 20 0
      examples/patches/example.sln
  3. 21 23
      include/igl/embree/orient_outward_ao.cpp

+ 6 - 0
examples/patches/example.cpp

@@ -645,6 +645,12 @@ void key(unsigned char key, int mouse_x, int mouse_y)
           s.camera.rotation);
           s.camera.rotation);
         break;
         break;
       }
       }
+    case 'u':
+        mouse_wheel(0, 1,mouse_x,mouse_y);
+        break;
+    case 'j':
+        mouse_wheel(0,-1,mouse_x,mouse_y);
+        break;
     default:
     default:
       if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
       if(!TwEventKeyboardGLUT(key,mouse_x,mouse_y))
       {
       {

+ 20 - 0
examples/patches/example.sln

@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example", "example.vcxproj", "{7F5B7683-7531-481C-8997-6221D7170894}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Win32 = Debug|Win32
+		Release|Win32 = Release|Win32
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{7F5B7683-7531-481C-8997-6221D7170894}.Debug|Win32.ActiveCfg = Debug|Win32
+		{7F5B7683-7531-481C-8997-6221D7170894}.Debug|Win32.Build.0 = Debug|Win32
+		{7F5B7683-7531-481C-8997-6221D7170894}.Release|Win32.ActiveCfg = Release|Win32
+		{7F5B7683-7531-481C-8997-6221D7170894}.Release|Win32.Build.0 = Release|Win32
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 21 - 23
include/igl/embree/orient_outward_ao.cpp

@@ -69,6 +69,7 @@ IGL_INLINE void igl::orient_outward_ao(
   }
   }
   
   
   // generate all the rays
   // generate all the rays
+  cout << "generating rays... ";
   uniform_real_distribution<double> rdist;
   uniform_real_distribution<double> rdist;
   mt19937 prng;
   mt19937 prng;
   prng.seed(time(0));
   prng.seed(time(0));
@@ -118,18 +119,20 @@ IGL_INLINE void igl::orient_outward_ao(
     }
     }
   }
   }
   
   
-  // occlusion count per component
-  vector<int> C_occlude_count_front(num_cc, 0);
-  vector<int> C_occlude_count_back (num_cc, 0);
-
-  //auto dbg_get_hit_point = [&] (embree::Hit hit) {
-  //  RowVector3d p0 = V.row(F2(hit.id0, 0));
-  //  RowVector3d p1 = V.row(F2(hit.id0, 1));
-  //  RowVector3d p2 = V.row(F2(hit.id0, 2));
-  //  RowVector3d p = (1 - hit.u - hit.v) * p0 + hit.u * p1 + hit.v * p2;
-  //  return p;
-  //};
+  // per component accumulation of occlusion distance
+  double dist_large = (V.colwise().maxCoeff() - V.colwise().minCoeff()).norm() * 1000;
+  vector<double> C_occlude_dist_front(num_cc, 0);
+  vector<double> C_occlude_dist_back (num_cc, 0);
 
 
+  auto get_dist = [&] (Hit hit, const Vector3d& origin) {
+    Vector3d p0 = V.row(F2(hit.id, 0));
+    Vector3d p1 = V.row(F2(hit.id, 1));
+    Vector3d p2 = V.row(F2(hit.id, 2));
+    Vector3d p = (1 - hit.u - hit.v) * p0 + hit.u * p1 + hit.v * p2;
+    return (p - origin).norm();
+  };
+  
+  cout << "shooting rays... ";
 #pragma omp parallel for
 #pragma omp parallel for
   for (int i = 0; i < ray_face.size(); ++i)
   for (int i = 0; i < ray_face.size(); ++i)
   {
   {
@@ -138,24 +141,18 @@ IGL_INLINE void igl::orient_outward_ao(
     Vector3d d = ray_dir [i];
     Vector3d d = ray_dir [i];
     int c = C(f);
     int c = C(f);
     Hit hit_front;
     Hit hit_front;
-    if (ei.intersectRay(o, d, hit_front))
-    {
-#pragma omp atomic
-      //RowVector3d hit_point = dbg_get_hit_point(hit_front);
-      C_occlude_count_front[c]++;
-    }
     Hit hit_back;
     Hit hit_back;
-    if (ei.intersectRay(o, -d, hit_back))
-    {
+    double dist_front = ei.intersectRay(o,  d, hit_front) ? get_dist(hit_front, o) : dist_large;
+    double dist_back  = ei.intersectRay(o, -d, hit_back ) ? get_dist(hit_back , o) : dist_large;
 #pragma omp atomic
 #pragma omp atomic
-      //RowVector3d hit_point = dbg_get_hit_point(hit_back);
-      C_occlude_count_back[c]++;
-    }
+    C_occlude_dist_front[c] += dist_front;
+#pragma omp atomic
+    C_occlude_dist_back [c] += dist_back;
   }
   }
   
   
   for(int c = 0;c<num_cc;c++)
   for(int c = 0;c<num_cc;c++)
   {
   {
-    I(c) = C_occlude_count_front[c] > C_occlude_count_back[c];
+    I(c) = C_occlude_dist_front[c] < C_occlude_dist_back[c];
   }
   }
   // flip according to I
   // flip according to I
   for(int f = 0;f<m;f++)
   for(int f = 0;f<m;f++)
@@ -165,6 +162,7 @@ IGL_INLINE void igl::orient_outward_ao(
       FF.row(f) = FF.row(f).reverse().eval();
       FF.row(f) = FF.row(f).reverse().eval();
     }
     }
   }
   }
+  cout << "done!\n";
 }
 }
 
 
 // Call with default parameters
 // Call with default parameters