Browse Source

moved orient_outward_ao to embree/, coding mostly done w/o OpenMP

Former-commit-id: c626b9c59f4d5e73edfa8dea737040c0266573a2
kenshi84 11 years ago
parent
commit
2321c816d1

+ 14 - 4
examples/patches/example.cpp

@@ -28,7 +28,7 @@
 #include <igl/boost/components.h>
 #include <igl/boost/bfs_orient.h>
 #include <igl/orient_outward.h>
-#include <igl/orient_outward_ao.h>
+#include <igl/embree/orient_outward_ao.h>
 
 #include <Eigen/Core>
 #include <Eigen/Geometry>
@@ -316,7 +316,7 @@ void display()
   glTranslated(0,floor_offset,0);
   const float GREY[4] = {0.5,0.5,0.6,1.0};
   const float DARK_GREY[4] = {0.2,0.2,0.3,1.0};
-  draw_floor(GREY,DARK_GREY);
+  //draw_floor(GREY,DARK_GREY);
   glPopMatrix();
 
   pop_scene();
@@ -538,7 +538,17 @@ void init_patches()
   }
   bfs_orient(F,F,CC);
   VectorXi I;
-  orient_outward(V,F,CC,F,I);
+  char c;
+  cout << "use ambient occlusion to determine patch orientation? (y/n):";
+  cin >> c;
+  if (c == 'y')
+  {
+    orient_outward_ao(V,F,CC,F.rows() * 100,F,I);
+  }
+  else
+  {
+    orient_outward(V,F,CC,F,I);
+  }
   double num_cc = (double)CC.maxCoeff()+1.0;
   cout<<"There are "<<num_cc<<" 'manifold/orientable' patches of faces."<<endl;
   randomly_color(CC,s.C);
@@ -726,7 +736,7 @@ int main(int argc, char * argv[])
   animation_start_time = get_seconds();
 
   // Init antweakbar
-  glutInitDisplayString( "rgba depth double samples>=8 ");
+  glutInitDisplayString( "rgba depth double ");   // samples>=8 somehow not supported on Kenshi's machines...?
   glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH)/2.0,glutGet(GLUT_SCREEN_HEIGHT)/2.0);
   glutCreateWindow("patches");
   glutDisplayFunc(display);

+ 33 - 10
examples/patches/example.vcxproj

@@ -41,9 +41,14 @@
   <PropertyGroup Label="UserMacros" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <LinkIncremental>true</LinkIncremental>
+    <IncludePath>C:\Users\kenshi\dev\igl_hg\ext_toolboxes\embree-1.1beta\common;$(IncludePath)</IncludePath>
+    <OutDir>$(ProjectDir)\</OutDir>
+    <TargetName>$(ProjectName)d</TargetName>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <LinkIncremental>false</LinkIncremental>
+    <IncludePath>C:\Users\kenshi\dev\igl_hg\ext_toolboxes\embree-1.1beta\common;$(IncludePath)</IncludePath>
+    <OutDir>$(ProjectDir)\</OutDir>
   </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
@@ -80,19 +85,37 @@
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="..\..\include\igl\orient_outward.cpp">
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-    </ClCompile>
-    <ClCompile Include="..\..\include\igl\orient_outward_ao.cpp">
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\filename.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\library.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\platform.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\stl\string.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\sync\condition.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\sync\mutex.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\sysinfo.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\taskscheduler_standard.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\thread.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh2\bvh2.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh2\bvh2_builder.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh2\bvh2_intersector.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4mb\bvh4mb.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4mb\bvh4mb_builder.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4mb\bvh4mb_intersector.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4\bvh4.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4\bvh4_builder.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4\bvh4_intersector.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\accel.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\alloc.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\heuristic_binning.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\heuristic_spatial.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\primrefgen.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\splitter.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\splitter_fallback.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\splitter_parallel.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\stat.cpp" />
     <ClCompile Include="example.cpp" />
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="..\..\include\igl\orient_outward.h" />
-    <ClInclude Include="..\..\include\igl\orient_outward_ao.h" />
+    <ClInclude Include="..\..\include\igl\embree\orient_outward_ao.h" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">

+ 91 - 4
examples/patches/example.vcxproj.filters

@@ -2,16 +2,103 @@
 <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <ClCompile Include="example.cpp" />
-    <ClCompile Include="..\..\include\igl\orient_outward.cpp" />
-    <ClCompile Include="..\..\include\igl\orient_outward_ao.cpp" />
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh2\bvh2_builder.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh2\bvh2_intersector.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh2\bvh2.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4\bvh4_intersector.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4\bvh4.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4\bvh4_builder.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4mb\bvh4mb_intersector.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4mb\bvh4mb.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\bvh4mb\bvh4mb_builder.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\splitter_fallback.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\splitter_parallel.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\stat.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\accel.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\alloc.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\heuristic_binning.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\heuristic_spatial.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\primrefgen.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\rtcore\common\splitter.cpp">
+      <Filter>embree-1.1beta\rtcore</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\platform.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\sysinfo.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\taskscheduler_standard.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\thread.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\filename.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\library.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\stl\string.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\sync\mutex.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\..\ext_toolboxes\embree-1.1beta\common\sys\sync\condition.cpp">
+      <Filter>embree-1.1beta\common</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Filter Include="igl">
       <UniqueIdentifier>{53eff656-6473-409c-9ad5-cac1983d91e1}</UniqueIdentifier>
     </Filter>
+    <Filter Include="embree-1.1beta">
+      <UniqueIdentifier>{6d281f01-62c5-4083-90e7-1e9d55cf793c}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="embree-1.1beta\rtcore">
+      <UniqueIdentifier>{ded8eb8e-e3c8-4405-9234-dd048cbb197d}</UniqueIdentifier>
+    </Filter>
+    <Filter Include="embree-1.1beta\common">
+      <UniqueIdentifier>{0c5327d6-c9c7-4e16-a8e3-d3ae7f7b42d9}</UniqueIdentifier>
+    </Filter>
   </ItemGroup>
   <ItemGroup>
-    <ClInclude Include="..\..\include\igl\orient_outward_ao.h" />
-    <ClInclude Include="..\..\include\igl\orient_outward.h" />
+    <ClInclude Include="..\..\include\igl\embree\orient_outward_ao.h" />
   </ItemGroup>
 </Project>

+ 48 - 25
include/igl/orient_outward_ao.cpp → include/igl/embree/orient_outward_ao.cpp

@@ -1,9 +1,9 @@
 #include "orient_outward_ao.h"
-#include "per_face_normals.h"
-#include "barycenter.h"
-#include "doublearea.h"
-#include "matlab_format.h"
-#include "embree/ambient_occlusion.h"
+#include "../per_face_normals.h"
+#include "../barycenter.h"
+#include "../doublearea.h"
+#include "../matlab_format.h"
+#include "ambient_occlusion.h"
 #include <iostream>
 #include <random>
 
@@ -11,6 +11,9 @@ template <
   typename DerivedV, 
   typename DerivedF, 
   typename DerivedC, 
+  typename PointMatrixType,
+  typename FaceMatrixType,
+  typename RowVector3,
   typename DerivedFF, 
   typename DerivedI>
 IGL_INLINE void igl::orient_outward_ao(
@@ -44,16 +47,16 @@ IGL_INLINE void igl::orient_outward_ao(
   double minarea = A.minCoeff();
   mt19937 engine;
   engine.seed(time(0));
-  vector<int> ddist_probability(m);
-  for (int f = 0; f < m; ++f)
-      ddist_probability[f] = static_cast<int>(A(f) * 100. / minarea);
-  discrete_distribution<int> ddist(dist_probability.begin(), dist_probability.end());
+  Matrix<int, Dynamic, 1> A_int = (A * 100.0 / minarea).cast<int>();
+  auto ddist_func = [&] (double i) { return A_int(static_cast<int>(i)); };
+  discrete_distribution<int> ddist(m, 0, m, ddist_func);      // simple ctor of (Iter, Iter) not provided by the stupid VC11 impl...
   uniform_real_distribution<double> rdist;
-  VectorXi face_occluded_front(m, 0);
-  VectorXi face_occluded_back (m, 0);
-#pragma omp parallel for
-  for (int i = 0; i < num_samples; ++i) {
-    int f = dist(engine);   // select face with probability proportional to face area
+  Matrix<int, Dynamic, 1> C_occlude_count;        // +1 when front ray is occluded, -1 when back ray is occluded
+  C_occlude_count.setZero(m, 1);
+//#pragma omp parallel for
+  for (int i = 0; i < num_samples; ++i)
+  {
+    int f = ddist(engine);   // select face with probability proportional to face area
     double t0 = rdist(engine);
     double t1 = rdist(engine);
     double t2 = rdist(engine);
@@ -65,18 +68,20 @@ IGL_INLINE void igl::orient_outward_ao(
     RowVector3d n = N.row(f);
     bool is_backside = rdist(engine) < 0.5;
     if (is_backside)
+    {
         n *= -1;
+    }
     Matrix<typename DerivedV::Scalar,Dynamic,1> S;
     ambient_occlusion(ei, p, n, 1, S);
-  
+    if (S(0) > 0)
+    {
+      C_occlude_count(C(f)) += is_backside ? -1 : 1;
+    }
+
   }
-  // take area weighted average
   for(int c = 0;c<num_cc;c++)
   {
-    //dot(c) /= (typename DerivedV::Scalar) totA(c);
-    //if(dot(c) < 0)
-    bool b = true;
-    I(c) = b;
+    I(c) = C_occlude_count(c) > 0;
   }
   // flip according to I
   for(int f = 0;f<m;f++)
@@ -88,8 +93,26 @@ IGL_INLINE void igl::orient_outward_ao(
   }
 }
 
-#ifndef IGL_HEADER_ONLY
-// Explicit template specialization
-template void igl::orient_outward_ao<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
-#endif
-
+// EmbreeIntersector generated on the fly
+template <
+  typename DerivedV, 
+  typename DerivedF, 
+  typename DerivedC, 
+  typename DerivedFF, 
+  typename DerivedI>
+IGL_INLINE void igl::orient_outward_ao(
+  const Eigen::PlainObjectBase<DerivedV> & V,
+  const Eigen::PlainObjectBase<DerivedF> & F,
+  const Eigen::PlainObjectBase<DerivedC> & C,
+  const int num_samples,
+  Eigen::PlainObjectBase<DerivedFF> & FF,
+  Eigen::PlainObjectBase<DerivedI> & I)
+{
+  using namespace igl;
+  using namespace Eigen;
+  EmbreeIntersector<
+    PlainObjectBase<DerivedV>,
+    PlainObjectBase<DerivedF>,
+    Matrix<typename DerivedV::Scalar,3,1> > ei(V,F);
+  return orient_outward_ao(V, F, C, ei, num_samples, FF, I);
+}

+ 21 - 3
include/igl/orient_outward_ao.h → include/igl/embree/orient_outward_ao.h

@@ -1,6 +1,6 @@
 #ifndef IGL_ORIENT_OUTWARD_AO_H
 #define IGL_ORIENT_OUTWARD_AO_H
-#include "igl_inline.h"
+#include "../igl_inline.h"
 #include <Eigen/Core>
 namespace igl
 {
@@ -10,8 +10,8 @@ namespace igl
     typename FaceMatrixType,
     typename RowVector3>
   class EmbreeIntersector;
-  // Orient each component (identified by C) of a mesh (V,F) so the normals on
-  // average point away from the patch's centroid.
+  // Orient each component (identified by C) of a mesh (V,F) using ambient occlusion 
+  // such that the front side is less occluded than back side
   //
   // Inputs:
   //   V            #V by 3 list of vertex positions
@@ -27,6 +27,9 @@ namespace igl
     typename DerivedV, 
     typename DerivedF, 
     typename DerivedC, 
+    typename PointMatrixType,
+    typename FaceMatrixType,
+    typename RowVector3,
     typename DerivedFF, 
     typename DerivedI>
   IGL_INLINE void orient_outward_ao(
@@ -37,6 +40,21 @@ namespace igl
     const int num_samples,
     Eigen::PlainObjectBase<DerivedFF> & FF,
     Eigen::PlainObjectBase<DerivedI> & I);
+  
+  // EmbreeIntersector generated on the fly
+  template <
+    typename DerivedV, 
+    typename DerivedF, 
+    typename DerivedC, 
+    typename DerivedFF, 
+    typename DerivedI>
+  IGL_INLINE void orient_outward_ao(
+    const Eigen::PlainObjectBase<DerivedV> & V,
+    const Eigen::PlainObjectBase<DerivedF> & F,
+    const Eigen::PlainObjectBase<DerivedC> & C,
+    const int num_samples,
+    Eigen::PlainObjectBase<DerivedFF> & FF,
+    Eigen::PlainObjectBase<DerivedI> & I);
 };
 
 #ifdef IGL_HEADER_ONLY