Browse Source

mesh quicklook generator example and sort rows example, readWRL from preview3d

Former-commit-id: a7a16fcf699de0ab45e7e93eda2af719d7cb13ca
Alec Jacobson (jalec 11 years ago
parent
commit
f292dec1c2

+ 1 - 0
.hgignore

@@ -8,6 +8,7 @@ syntax: glob
 example
 examples/bbw/bbw_demo_selfcontained/*
 examples/bbw/bbw_demo_selfcontained.zip
+examples/quicklook-mesh/Mesh.qlgenerator/*
 example_static
 example_header_only
 example1

+ 1 - 1
VERSION.txt

@@ -3,4 +3,4 @@
 # Anyone may increment Minor to indicate a small change.
 # Major indicates a large change or large number of changes (upload to website)
 # World indicates a substantial change or release
-0.3.1
+0.3.2

+ 20 - 0
examples/quicklook-mesh/Info.plist

@@ -14,6 +14,7 @@
 				<string>org.mesh</string>
 				<string>org.obj</string>
 				<string>org.off</string>
+				<string>org.wrl</string>
 			</array>
 		</dict>
 	</array>
@@ -120,6 +121,25 @@
 				</array>
 			</dict>
 		</dict>
+		<dict>
+			<key>UTTypeConformsTo</key>
+			<array>
+				<string>public.image</string>
+			</array>
+			<key>UTTypeDescription</key>
+			<string>Virtual Reality Modeling Language</string>
+			<key>UTTypeIdentifier</key>
+			<string>org.wrl</string>
+			<key>UTTypeReferenceURL</key>
+			<string>http://en.wikipedia.org/wiki/VRML#WRL_File_Format</string>
+			<key>UTTypeTagSpecification</key>
+			<dict>
+				<key>public.filename-extension</key>
+				<array>
+					<string>wrl</string>
+				</array>
+			</dict>
+		</dict>
 	</array>
 </dict>
 </plist>

+ 1 - 1
examples/quicklook-mesh/Makefile

@@ -49,7 +49,7 @@ INC+=$(EIGEN3_INC) $(LIBIGL_INC) $(GLU_INC) $(MESA_INC)
 .PHONY:
 
 Mesh.qlgenerator: Mesh.qlgenerator/Contents/MacOS/ \
-  Mesh.qlgenerator/Contents/Resources \
+  Mesh.qlgenerator/Contents/Resources/ \
   Mesh.qlgenerator/Contents/MacOS/Mesh \
   Mesh.qlgenerator/Contents/Info.plist
 

+ 8 - 0
examples/quicklook-mesh/README

@@ -15,3 +15,11 @@ To install issue:
 
 This will copy the directory ./Mesh.qlgenerator/ into /Library/QuickLook/ and
 reload the Quicklook Manager (so that you see your changes in Finder).
+
+= Dependencies =
+
+Install Mesa3D using macports. 
+
+    sudo port install mesa
+
+Then re-install mesa's GLU à la http://www.alecjacobson.com/weblog/?p=2827

+ 2 - 1
examples/quicklook-mesh/src/GeneratePreviewForURL.m

@@ -47,7 +47,8 @@ OSStatus GeneratePreviewForURL(
       cs = cs_buf;
     }
 
-    render_to_buffer(cs,bwidth,bheight,buffer);
+    const float TRANSPARENT_BLACK[4] = {0,0,0,0};
+    render_to_buffer(cs,TRANSPARENT_BLACK,bwidth,bheight,buffer);
     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
     CFDataRef rgbData = CFDataCreate(NULL, buffer, bwidth * bheight * 4);
     CGDataProviderRef provider = CGDataProviderCreateWithCFData(rgbData);

+ 2 - 1
examples/quicklook-mesh/src/GenerateThumbnailForURL.m

@@ -114,7 +114,8 @@ OSStatus GenerateThumbnailForURL(
       CFStringGetCString(file, cs_buf, [(NSString*)file length]+1, kCFStringEncodingUTF8);
       cs = cs_buf;
     }
-    render_to_buffer(cs,bwidth,bheight,buffer);
+    const float OPAQUE_WHITE[4] = {1,1,1,1};
+    render_to_buffer(cs,OPAQUE_WHITE,bwidth,bheight,buffer);
     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
     CFDataRef rgbData = CFDataCreate(NULL, buffer, bwidth * bheight * 4);
     CGDataProviderRef provider = CGDataProviderCreateWithCFData(rgbData);

+ 32 - 3
examples/quicklook-mesh/src/render_to_buffer.cpp

@@ -13,6 +13,8 @@ extern "C" {
 #include <igl/material_colors.h>
 #include <igl/pathinfo.h>
 #include <igl/readOBJ.h>
+#include <igl/readWRL.h>
+#include <igl/triangulate.h>
 #include <igl/readOFF.h>
 #include <igl/readMESH.h>
 #include <igl/boundary_faces.h>
@@ -34,6 +36,7 @@ static Eigen::MatrixXi F;
 static double bbd;
 static Eigen::Vector3d Vmean, Vmax,Vmin;
 static bool invert = false;
+static float background_color[4] = {0,0,0,1};
 
 // Small viewports struct for keeping track of size and camera info
 #define NUM_VIEWPORTS 6
@@ -243,7 +246,11 @@ void display()
 {
   using namespace std;
   using namespace igl;
-  glClearColor(0,0,0,0);
+  glClearColor(
+    background_color[0],
+    background_color[1],
+    background_color[2],
+    background_color[3]);
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_NORMALIZE);
@@ -329,6 +336,7 @@ void display()
 
 bool render_to_buffer(
   const char * filename,
+  const float * background_color,
   const int width,
   const int height,
   GLubyte * buffer)
@@ -338,16 +346,20 @@ bool render_to_buffer(
   using namespace Eigen;
   double ts = get_seconds();
 
+  copy(background_color,background_color+4,::background_color);
+
   // Read and prepare mesh
   // dirname, basename, extension and filename
   string d,b,ext,f;
   pathinfo(filename,d,b,ext,f);
   // Convert extension to lower case
   transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
+  vector<vector<double > > vV,vN,vTC;
+  vector<vector<int > > vF,vFTC,vFN;
   if(ext == "obj")
   {
     // Convert extension to lower case
-    if(!igl::readOBJ(filename,V,F))
+    if(!igl::readOBJ(filename,vV,vTC,vN,vF,vFTC,vFN))
     {
       red(width,height,buffer);
       return false;
@@ -355,7 +367,15 @@ bool render_to_buffer(
   }else if(ext == "off")
   {
     // Convert extension to lower case
-    if(!igl::readOFF(filename,V,F))
+    if(!igl::readOFF(filename,vV,vF,vN))
+    {
+      red(width,height,buffer);
+      return false;
+    }
+  }else if(ext == "wrl")
+  {
+    // Convert extension to lower case
+    if(!igl::readWRL(filename,vV,vF))
     {
       red(width,height,buffer);
       return false;
@@ -374,6 +394,15 @@ bool render_to_buffer(
       boundary_faces(T,F);
     }
   }
+  if(vV.size() > 0)
+  {
+    if(!list_to_matrix(vV,V))
+    {
+      red(width,height,buffer);
+      return false;
+    }
+    triangulate(vF,F);
+  }
   cout<<"IO: "<<(get_seconds()-ts)<<"s"<<endl;
   ts = get_seconds();
 

+ 2 - 0
examples/quicklook-mesh/src/render_to_buffer.h

@@ -3,6 +3,7 @@
 
 // Inputs:
 //   filename   path to mesh
+//   background  background color
 //   width  width of image buffer
 //   height  height of image buffer
 // Outputs:
@@ -10,6 +11,7 @@
 // Returns true only only upon success.
 bool render_to_buffer(
   const char * filename,
+  const float *background_color,
   const int width,
   const int height,
   GLubyte * buffer);

+ 5 - 0
examples/sortrows/IC.dmat

@@ -0,0 +1,5 @@
+1 4
+0
+1
+2
+3

+ 25 - 0
examples/sortrows/Makefile

@@ -0,0 +1,25 @@
+
+.PHONY: all
+
+# Shared flags etc.
+include ../../Makefile.conf
+
+all: example
+
+.PHONY: example
+
+igl_lib=../../
+eigen=$(DEFAULT_PREFIX)/include/eigen3/
+
+CFLAGS=-g
+inc=-I$(igl_lib)/include -I$(eigen)
+lib=-L$(igl_lib)/lib -ligl
+
+example: example.o
+	g++ $(CFLAGS) -o example example.o $(lib)
+
+example.o: example.cpp
+	g++ $(CFLAGS) -c example.cpp -o example.o $(inc)
+clean:
+	rm -f example.o
+	rm -f example

+ 9 - 0
examples/sortrows/README

@@ -0,0 +1,9 @@
+This is a simple example program that shows how to use the sort function on
+eigen matrices like matlab's sort function
+
+
+To Build:
+  make
+
+To Run:
+  ./example

+ 9 - 0
examples/sortrows/X.dmat

@@ -0,0 +1,9 @@
+2 4
+1
+2
+6
+7
+3
+4
+1
+2

+ 9 - 0
examples/sortrows/Y.dmat

@@ -0,0 +1,9 @@
+2 4
+-1.7272337110188889e-77
+-1.7272337110188889e-77
+-1.7272337110188889e-77
+-1.7272337110188889e-77
+-1.7272337110188889e-77
+-1.7272337110188889e-77
+-1.7272337110188889e-77
+-1.7272337110188889e-77

+ 76 - 0
examples/sortrows/example.cpp

@@ -0,0 +1,76 @@
+#include <Eigen/Dense>
+#include <iostream>
+#include <algorithm>
+#include <igl/sort.h>
+#include <igl/unique.h>
+#include <igl/get_seconds.h>
+#include <igl/colon.h>
+#include <igl/slice.h>
+#include <igl/sortrows.h>
+#include <igl/readDMAT.h>
+#include <igl/writeDMAT.h>
+
+int main(int argc, char * argv[])
+{
+  using namespace Eigen;
+  using namespace std;
+  using namespace igl;
+  //MatrixXd X;
+  //if(!readDMAT("X.dmat",X))
+  //{
+  //  X = MatrixXd::Random(766443,2);
+  //  for(int x = 0;x<X.size();x++)
+  //  {
+  //    X(x) = floor(X(x)*680);
+  //  }
+  //}
+  MatrixXd X(4,2);
+  //X << 1,2,1,2,1,1,2,2;
+  X << 1,3,2,4,6,1,7,2;
+  cout<<X<<endl<<endl;
+  typedef MatrixXi::Scalar Scalar;
+  bool ascending = false;
+  const int dim = 2;
+  double t;
+
+//#define NUM_RUNS 100
+//  MatrixXd Y;
+//  MatrixXi IX;
+//  t = get_seconds();
+//  for(int r = 0;r<NUM_RUNS;r++)
+//  sort(X,dim,ascending,Y,IX);
+//  cout<<(get_seconds()-t)/(double)NUM_RUNS<<endl;
+//  //cout<<Y<<endl<<endl;
+//  //cout<<IX<<endl<<endl;
+//  MatrixXd Y2;
+//  MatrixXi IX2;
+//  t = get_seconds();
+//  for(int r = 0;r<NUM_RUNS;r++)
+//  sort2(X,dim,ascending,Y2,IX2);
+//  cout<<(get_seconds()-t)/(double)NUM_RUNS<<endl;
+//  //cout<<Y2<<endl<<endl;
+//  //cout<<IX2<<endl<<endl;
+
+#define NUM_RUNS 1
+  MatrixXd Y;
+  VectorXi IA,IC;
+
+  t = get_seconds();
+  for(int r = 0;r<NUM_RUNS;r++)
+  unique_rows(X,Y,IA,IC);
+  cout<<(get_seconds()-t)/(double)NUM_RUNS<<endl;
+
+  t = get_seconds();
+  for(int r = 0;r<NUM_RUNS;r++)
+  sortrows(X,true,Y,IC);
+  cout<<(get_seconds()-t)/(double)NUM_RUNS<<endl;
+  writeDMAT("X.dmat",X,true);
+  writeDMAT("Y.dmat",Y,true);
+  writeDMAT("IC.dmat",IC,true);
+
+  //cout<<Y<<endl<<endl;
+  //cout<<IA<<endl<<endl;
+  //cout<<IC<<endl<<endl;
+  cout<<Y.rows()<<endl;
+
+}

+ 3 - 1
file-formats/index.html

@@ -38,7 +38,9 @@
     <li><a href=./rbr.html>.rbr</a> ASCII files for saving state of ReAntTweakBar</li>
     <li><a href=http://en.wikipedia.org/wiki/Truevision_TGA>.tga</a> Truevision TGA or TARGA image file format. IGLLIB supports only very basic reading and writing RGB/RGBA files without colormaps and (unverified) run-length compression.</li>
     <li><a href="./tgf.html">.tgf</a> ASCII files for representing control handle graphs</li>
-	<li><a href="./xml.html">.xml</a> XMLSerializer's file format containing the serialization of object data structures.</li>
+    <li><a href="http://en.wikipedia.org/wiki/VRML#WRL_File_Format">.wrl</a>
+    VRML (Virtual Reality Modeling Language) file format for 3D scenes.</li>
+    <li><a href="./xml.html">.xml</a> XMLSerializer's file format containing the serialization of object data structures.</li>
   </ul>
   <h3>Triangle mesh file format performance</h3>
   <p>