Эх сурвалжийг харах

bug fix in orient_outward_ao: be careful with degenerate triangles

Former-commit-id: e0f6fd6955555c0b0515de8da888cfaa90a7149d
Kenshi Takayama (kenshi 11 жил өмнө
parent
commit
8fef989fdc

+ 0 - 1
examples/patches/example.vcxproj

@@ -87,7 +87,6 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="..\..\..\kt84\dbg.cpp" />
     <ClCompile Include="..\..\external\embree\embree\builders\heuristic_binning.cpp" />
     <ClCompile Include="..\..\external\embree\embree\builders\heuristic_spatial.cpp" />
     <ClCompile Include="..\..\external\embree\embree\builders\primrefgen.cpp" />

+ 0 - 1
examples/patches/example.vcxproj.filters

@@ -143,7 +143,6 @@
     <ClCompile Include="..\..\external\embree\embree\embree.cpp">
       <Filter>embree</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\..\kt84\dbg.cpp" />
   </ItemGroup>
   <ItemGroup>
     <Filter Include="igl">

+ 13 - 4
include/igl/embree/orient_outward_ao.cpp

@@ -5,6 +5,8 @@
 #include "EmbreeIntersector.h"
 #include <iostream>
 #include <random>
+#include <ctime>
+#include <limits>
 
 template <
   typename DerivedV, 
@@ -47,7 +49,11 @@ IGL_INLINE void igl::orient_outward_ao(
   // face area
   Matrix<typename DerivedV::Scalar,Dynamic,1> A;
   doublearea(V,F,A);
-  double area_min = A.minCoeff();
+  double area_min = numeric_limits<double>::max();
+  for (int f = 0; f < m; ++f)
+  {
+    area_min = A(f) != 0 && A(f) < area_min ? A(f) : area_min;
+  }
   double area_total = A.sum();
   
   // determine number of rays per component according to its area
@@ -68,7 +74,7 @@ IGL_INLINE void igl::orient_outward_ao(
   cout << "generating rays... ";
   uniform_real_distribution<float> rdist;
   mt19937 prng;
-  prng.seed(0);
+  prng.seed(time(nullptr));
   vector<int     > ray_face;
   vector<Vector3f> ray_ori;
   vector<Vector3f> ray_dir;
@@ -77,6 +83,10 @@ IGL_INLINE void igl::orient_outward_ao(
   ray_dir .reserve(total_num_rays);
   for (int c = 0; c < num_cc; ++c)
   {
+    if (area_per_component[c] == 0)
+    {
+      continue;
+    }
     vector<int> CF;     // set of faces per component
     vector<int> CF_area;
     for (int f = 0; f < m; ++f)
@@ -92,7 +102,7 @@ IGL_INLINE void igl::orient_outward_ao(
     discrete_distribution<int> ddist(CF.size(), 0, CF.size(), ddist_func);      // simple ctor of (Iter, Iter) not provided by the stupid VC11 impl...
     for (int i = 0; i < num_rays_per_component[c]; ++i)
     {
-      int f     = CF[ddist(prng)];    // select face with probability proportional to face area
+      int f    = CF[ddist(prng)];    // select face with probability proportional to face area
       float t0 = rdist(prng);        // random barycentric coordinate
       float t1 = rdist(prng);
       float t2 = rdist(prng);
@@ -104,7 +114,6 @@ IGL_INLINE void igl::orient_outward_ao(
                  + t1 * V.row(F(f,1)).template cast<float>().eval()
                  + t2 * V.row(F(f,2)).template cast<float>().eval();
       Vector3f n = N.row(f).cast<float>();
-      assert(n != Vector3f::Zero());
       // random direction in hemisphere around n (avoid too grazing angle)
       Vector3f d;
       while (true) {