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

Make file encoding option an enum. (#1619)

Jérémie Dumas 5 жил өмнө
parent
commit
062e3823c3

+ 21 - 0
include/igl/FileEncoding.h

@@ -0,0 +1,21 @@
+// This file is part of libigl, a simple c++ geometry processing library.
+//
+// Copyright (C) 2020 Jérémie Dumas <[email protected]>
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
+// obtain one at http://mozilla.org/MPL/2.0/.
+#ifndef IGL_FILEENCODING_H
+#define IGL_FILEENCODING_H
+
+namespace igl
+{
+
+enum class FileEncoding {
+  Binary,
+  Ascii
+};
+
+}
+
+#endif

+ 18 - 18
include/igl/writePLY.cpp

@@ -45,7 +45,7 @@ bool writePLY(
   const std::vector<std::string> & EDheader,
   const std::vector<std::string> & EDheader,
 
 
   const std::vector<std::string> & comments,
   const std::vector<std::string> & comments,
-  bool isBinary
+  FileEncoding encoding
    )
    )
 {
 {
     typedef typename DerivedV::Scalar VScalar;
     typedef typename DerivedV::Scalar VScalar;
@@ -155,7 +155,7 @@ bool writePLY(
       file.get_comments().push_back(a);
       file.get_comments().push_back(a);
 
 
     // Write a binary file
     // Write a binary file
-    file.write(ply_stream, isBinary);
+    file.write(ply_stream, (encoding == FileEncoding::Binary));
 
 
     return true;
     return true;
 }
 }
@@ -188,12 +188,12 @@ bool writePLY(
   const std::vector<std::string> & EDheader,
   const std::vector<std::string> & EDheader,
 
 
   const std::vector<std::string> & comments,
   const std::vector<std::string> & comments,
-  bool isBinary
+  FileEncoding encoding
    )
    )
 {
 {
   try
   try
   {
   {
-    if(isBinary)
+    if(encoding == FileEncoding::Binary)
     {
     {
       std::filebuf fb_binary;
       std::filebuf fb_binary;
       fb_binary.open(filename , std::ios::out | std::ios::binary);
       fb_binary.open(filename , std::ios::out | std::ios::binary);
@@ -202,7 +202,7 @@ bool writePLY(
         std::cerr << "writePLY: Error opening file " << filename << std::endl;
         std::cerr << "writePLY: Error opening file " << filename << std::endl;
         return false; //throw std::runtime_error("failed to open " + filename);
         return false; //throw std::runtime_error("failed to open " + filename);
       }
       }
-      return writePLY(outstream_binary,V,F,E,N,UV,VD,VDheader,FD,FDheader,ED,EDheader,comments,isBinary);
+      return writePLY(outstream_binary,V,F,E,N,UV,VD,VDheader,FD,FDheader,ED,EDheader,comments,encoding);
     } else {
     } else {
       std::filebuf fb_ascii;
       std::filebuf fb_ascii;
       fb_ascii.open(filename, std::ios::out);
       fb_ascii.open(filename, std::ios::out);
@@ -211,7 +211,7 @@ bool writePLY(
         std::cerr << "writePLY: Error opening file " << filename << std::endl;
         std::cerr << "writePLY: Error opening file " << filename << std::endl;
         return false; //throw std::runtime_error("failed to open " + filename);
         return false; //throw std::runtime_error("failed to open " + filename);
       }
       }
-      return writePLY(outstream_ascii,V,F,E,N,UV,VD,VDheader,FD,FDheader,ED,EDheader,comments,isBinary);
+      return writePLY(outstream_ascii,V,F,E,N,UV,VD,VDheader,FD,FDheader,ED,EDheader,comments,encoding);
     }
     }
   }
   }
   catch(const std::exception& e)
   catch(const std::exception& e)
@@ -234,7 +234,7 @@ bool writePLY(
   Eigen::MatrixXd _dummy;
   Eigen::MatrixXd _dummy;
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
-  return writePLY(filename,V,F,_dummy, _dummy, _dummy, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, true);
+  return writePLY(filename,V,F,_dummy, _dummy, _dummy, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary);
 }
 }
 
 
 template <
 template <
@@ -252,7 +252,7 @@ bool writePLY(
   Eigen::MatrixXd _dummy;
   Eigen::MatrixXd _dummy;
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
-  return writePLY(filename,V,F,E, _dummy, _dummy, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, true);
+  return writePLY(filename,V,F,E, _dummy, _dummy, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary);
 }
 }
 
 
 
 
@@ -273,7 +273,7 @@ bool writePLY(
   Eigen::MatrixXd _dummy;
   Eigen::MatrixXd _dummy;
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
-  return writePLY(filename,V,F,_dummy, N,UV, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, true);
+  return writePLY(filename,V,F,_dummy, N,UV, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary);
 }
 }
 
 
 template <
 template <
@@ -295,7 +295,7 @@ bool writePLY(
   Eigen::MatrixXd _dummy;
   Eigen::MatrixXd _dummy;
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
-  return writePLY(filename,V,F,E, N,UV, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, true);
+  return writePLY(filename,V,F,E, N,UV, _dummy, _dummy_header, _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, FileEncoding::Binary);
 }
 }
 
 
 template <
 template <
@@ -306,14 +306,14 @@ bool writePLY(
   const std::string & filename,
   const std::string & filename,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedF> & F,
-  bool force_ascii
+  FileEncoding encoding
    )
    )
 {
 {
   Eigen::MatrixXd _dummy(0,0);
   Eigen::MatrixXd _dummy(0,0);
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
   return writePLY(filename,V,F,_dummy, _dummy,_dummy, _dummy, _dummy_header,
   return writePLY(filename,V,F,_dummy, _dummy,_dummy, _dummy, _dummy_header,
-                         _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, force_ascii);
+                         _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, encoding);
 }
 }
 
 
 template <
 template <
@@ -326,14 +326,14 @@ bool writePLY(
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedE> & E,
   const Eigen::MatrixBase<DerivedE> & E,
-  bool force_ascii
+  FileEncoding encoding
    )
    )
 {
 {
   Eigen::MatrixXd _dummy(0,0);
   Eigen::MatrixXd _dummy(0,0);
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
   return writePLY(filename,V,F,E, _dummy,_dummy, _dummy, _dummy_header,
   return writePLY(filename,V,F,E, _dummy,_dummy, _dummy, _dummy_header,
-                         _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, force_ascii);
+                         _dummy, _dummy_header, _dummy, _dummy_header, _dummy_header, encoding);
 }
 }
 
 
 
 
@@ -361,7 +361,7 @@ bool writePLY(
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
   return writePLY(filename,V,F,_dummy, N, UV, VD, VDheader,
   return writePLY(filename,V,F,_dummy, N, UV, VD, VDheader,
-                         _dummy, _dummy_header, _dummy, _dummy_header, comments, true);
+                         _dummy, _dummy_header, _dummy, _dummy_header, comments, FileEncoding::Binary);
 }
 }
 
 
 
 
@@ -391,7 +391,7 @@ bool writePLY(
   std::vector<std::string> _dummy_header;
   std::vector<std::string> _dummy_header;
 
 
   return writePLY(filename,V,F,E, N, UV, VD, VDheader,
   return writePLY(filename,V,F,E, N, UV, VD, VDheader,
-                         _dummy, _dummy_header, _dummy, _dummy_header, comments, true);
+                         _dummy, _dummy_header, _dummy, _dummy_header, comments, FileEncoding::Binary);
 
 
 }
 }
 
 
@@ -404,6 +404,6 @@ bool writePLY(
 #ifdef IGL_STATIC_LIBRARY
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // Explicit template instantiation
 template bool igl::writePLY<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
 template bool igl::writePLY<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
-template bool igl::writePLY<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<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool);
-template bool igl::writePLY<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, bool);
+template bool igl::writePLY<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<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, igl::FileEncoding);
+template bool igl::writePLY<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<float, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, igl::FileEncoding);
 #endif
 #endif

+ 10 - 9
include/igl/writePLY.h

@@ -1,6 +1,7 @@
 #ifndef IGL_WRITEPLY_H
 #ifndef IGL_WRITEPLY_H
 #define IGL_WRITEPLY_H
 #define IGL_WRITEPLY_H
 #include <igl/igl_inline.h>
 #include <igl/igl_inline.h>
+#include <igl/FileEncoding.h>
 
 
 #include <string>
 #include <string>
 #include <iostream>
 #include <iostream>
@@ -16,7 +17,7 @@ namespace igl
   //   Derived from Eigen matrix parameters
   //   Derived from Eigen matrix parameters
   // Inputs:
   // Inputs:
   //  ply_stream  ply file output stream
   //  ply_stream  ply file output stream
-  //   V  (#V,3) matrix of vertex positions 
+  //   V  (#V,3) matrix of vertex positions
   //   F  (#F,3) list of face indices into vertex positions
   //   F  (#F,3) list of face indices into vertex positions
   //   E  (#E,2) list of edge indices into vertex positions
   //   E  (#E,2) list of edge indices into vertex positions
   //   N  (#V,3) list of normals
   //   N  (#V,3) list of normals
@@ -28,7 +29,7 @@ namespace igl
   //   ED (#E,*) additional edge data
   //   ED (#E,*) additional edge data
   //   Eheader (#E) list of edge data headers
   //   Eheader (#E) list of edge data headers
   //   comments (*) file comments
   //   comments (*) file comments
-  //   isBinary - bool, to set binary or ascii file format
+  //   encoding - enum, to set binary or ascii file format
   // Returns true on success, false on errors
   // Returns true on success, false on errors
   template <
   template <
   typename DerivedV,
   typename DerivedV,
@@ -58,7 +59,7 @@ bool writePLY(
   const std::vector<std::string> & EDheader,
   const std::vector<std::string> & EDheader,
 
 
   const std::vector<std::string> & comments,
   const std::vector<std::string> & comments,
-  bool isBinary
+  FileEncoding encoding
    );
    );
 
 
   // write triangular mesh to ply file
   // write triangular mesh to ply file
@@ -67,7 +68,7 @@ bool writePLY(
   //   Derived from Eigen matrix parameters
   //   Derived from Eigen matrix parameters
   // Inputs:
   // Inputs:
   //  filename  ply file name
   //  filename  ply file name
-  //   V  (#V,3) matrix of vertex positions 
+  //   V  (#V,3) matrix of vertex positions
   //   F  (#F,3) list of face indices into vertex positions
   //   F  (#F,3) list of face indices into vertex positions
   //   E  (#E,2) list of edge indices into vertex positions
   //   E  (#E,2) list of edge indices into vertex positions
   //   N  (#V,3) list of normals
   //   N  (#V,3) list of normals
@@ -79,7 +80,7 @@ bool writePLY(
   //   ED (#E,*) additional edge data
   //   ED (#E,*) additional edge data
   //   Eheader (#E) list of edge data headers
   //   Eheader (#E) list of edge data headers
   //   comments (*) file comments
   //   comments (*) file comments
-  //   isBinary - bool, to set binary or ascii file format
+  //   encoding - enum, to set binary or ascii file format
   // Returns true on success, false on errors
   // Returns true on success, false on errors
 template <
 template <
   typename DerivedV,
   typename DerivedV,
@@ -109,7 +110,7 @@ bool writePLY(
   const std::vector<std::string> & EDheader,
   const std::vector<std::string> & EDheader,
 
 
   const std::vector<std::string> & comments,
   const std::vector<std::string> & comments,
-  bool isBinary
+  FileEncoding encoding
    );
    );
 
 
 template <
 template <
@@ -175,8 +176,8 @@ bool writePLY(
   const std::string & filename,
   const std::string & filename,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedF> & F,
-  bool force_ascii
-   );   
+  FileEncoding encoding
+   );
 
 
 template <
 template <
   typename DerivedV,
   typename DerivedV,
@@ -188,7 +189,7 @@ bool writePLY(
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedE> & E,
   const Eigen::MatrixBase<DerivedE> & E,
-  bool force_ascii
+  FileEncoding encoding
    );
    );
 
 
 template <
 template <

+ 10 - 10
include/igl/writeSTL.cpp

@@ -14,11 +14,11 @@ IGL_INLINE bool igl::writeSTL(
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedN> & N,
   const Eigen::MatrixBase<DerivedN> & N,
-  const bool ascii)
+  FileEncoding encoding)
 {
 {
   using namespace std;
   using namespace std;
   assert(N.rows() == 0 || F.rows() == N.rows());
   assert(N.rows() == 0 || F.rows() == N.rows());
-  if(ascii)
+  if(encoding == FileEncoding::Ascii)
   {
   {
     FILE * stl_file = fopen(filename.c_str(),"w");
     FILE * stl_file = fopen(filename.c_str(),"w");
     if(stl_file == NULL)
     if(stl_file == NULL)
@@ -103,21 +103,21 @@ IGL_INLINE bool igl::writeSTL(
   const std::string & filename,
   const std::string & filename,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedF> & F,
   const Eigen::MatrixBase<DerivedF> & F,
-  const bool ascii)
+  FileEncoding encoding)
 {
 {
-  return writeSTL(filename,V,F, Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, Eigen::Dynamic>(), ascii);
+  return writeSTL(filename,V,F, Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, Eigen::Dynamic>(), encoding);
 }
 }
 
 
 #ifdef IGL_STATIC_LIBRARY
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // Explicit template instantiation
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::writeSTL<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, bool);
+template bool igl::writeSTL<Eigen::Matrix<float, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, igl::FileEncoding);
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::writeSTL<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, bool);
+template bool igl::writeSTL<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, igl::FileEncoding);
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::writeSTL<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, bool);
+template bool igl::writeSTL<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, igl::FileEncoding);
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::writeSTL<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, bool);
-template bool igl::writeSTL<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, bool);
-template bool igl::writeSTL<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&, bool);
+template bool igl::writeSTL<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, igl::FileEncoding);
+template bool igl::writeSTL<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, igl::FileEncoding);
+template bool igl::writeSTL<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&, igl::FileEncoding);
 #endif
 #endif

+ 9 - 8
include/igl/writeSTL.h

@@ -1,13 +1,14 @@
 // This file is part of libigl, a simple c++ geometry processing library.
 // This file is part of libigl, a simple c++ geometry processing library.
-// 
+//
 // Copyright (C) 2013 Alec Jacobson <[email protected]>
 // Copyright (C) 2013 Alec Jacobson <[email protected]>
-// 
-// This Source Code Form is subject to the terms of the Mozilla Public License 
-// v. 2.0. If a copy of the MPL was not distributed with this file, You can 
+//
+// This Source Code Form is subject to the terms of the Mozilla Public License
+// v. 2.0. If a copy of the MPL was not distributed with this file, You can
 // obtain one at http://mozilla.org/MPL/2.0/.
 // obtain one at http://mozilla.org/MPL/2.0/.
 #ifndef IGL_WRITESTL_H
 #ifndef IGL_WRITESTL_H
 #define IGL_WRITESTL_H
 #define IGL_WRITESTL_H
 #include "igl_inline.h"
 #include "igl_inline.h"
+#include <igl/FileEncoding.h>
 
 
 #ifndef IGL_NO_EIGEN
 #ifndef IGL_NO_EIGEN
 #  include <Eigen/Core>
 #  include <Eigen/Core>
@@ -15,7 +16,7 @@
 #include <string>
 #include <string>
 #include <vector>
 #include <vector>
 
 
-namespace igl 
+namespace igl
 {
 {
   // Write a mesh to an stl file.
   // Write a mesh to an stl file.
   //
   //
@@ -27,7 +28,7 @@ namespace igl
   //   V  double matrix of vertex positions  #F*3 by 3
   //   V  double matrix of vertex positions  #F*3 by 3
   //   F  index matrix of triangle indices #F by 3
   //   F  index matrix of triangle indices #F by 3
   //   N  double matrix of vertex positions  #F by 3
   //   N  double matrix of vertex positions  #F by 3
-  //   asci  write ascii file {true}
+  //   encoding enum to set file encoding (ascii by default)
   // Returns true on success, false on errors
   // Returns true on success, false on errors
   //
   //
   template <typename DerivedV, typename DerivedF, typename DerivedN>
   template <typename DerivedV, typename DerivedF, typename DerivedN>
@@ -36,13 +37,13 @@ namespace igl
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedF> & F,
     const Eigen::MatrixBase<DerivedF> & F,
     const Eigen::MatrixBase<DerivedN> & N,
     const Eigen::MatrixBase<DerivedN> & N,
-    const bool ascii=true);
+    FileEncoding encoding=FileEncoding::Ascii);
   template <typename DerivedV, typename DerivedF>
   template <typename DerivedV, typename DerivedF>
   IGL_INLINE bool writeSTL(
   IGL_INLINE bool writeSTL(
     const std::string & filename,
     const std::string & filename,
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedF> & F,
     const Eigen::MatrixBase<DerivedF> & F,
-    const bool ascii=true);
+    FileEncoding encoding=FileEncoding::Ascii);
 }
 }
 
 
 #ifndef IGL_STATIC_LIBRARY
 #ifndef IGL_STATIC_LIBRARY

+ 8 - 8
include/igl/write_triangle_mesh.cpp

@@ -21,7 +21,7 @@ IGL_INLINE bool igl::write_triangle_mesh(
   const std::string str,
   const std::string str,
   const Eigen::MatrixBase<DerivedV>& V,
   const Eigen::MatrixBase<DerivedV>& V,
   const Eigen::MatrixBase<DerivedF>& F,
   const Eigen::MatrixBase<DerivedF>& F,
-  const bool force_ascii)
+  FileEncoding encoding)
 {
 {
   using namespace std;
   using namespace std;
   // dirname, basename, extension and filename
   // dirname, basename, extension and filename
@@ -41,10 +41,10 @@ IGL_INLINE bool igl::write_triangle_mesh(
     return writeOFF(str,V,F);
     return writeOFF(str,V,F);
   }else if(e == "ply")
   }else if(e == "ply")
   {
   {
-    return writePLY(str,V,F,force_ascii);
+    return writePLY(str,V,F,encoding);
   }else if(e == "stl")
   }else if(e == "stl")
   {
   {
-    return writeSTL(str,V,F,force_ascii);
+    return writeSTL(str,V,F,encoding);
   }else if(e == "wrl")
   }else if(e == "wrl")
   {
   {
     return writeWRL(str,V,F);
     return writeWRL(str,V,F);
@@ -59,12 +59,12 @@ IGL_INLINE bool igl::write_triangle_mesh(
 #ifdef IGL_STATIC_LIBRARY
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
 // Explicit template instantiation
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, bool);
+template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, igl::FileEncoding);
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::write_triangle_mesh<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, bool);
+template bool igl::write_triangle_mesh<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, igl::FileEncoding);
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, bool);
+template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, igl::FileEncoding);
 // generated by autoexplicit.sh
 // generated by autoexplicit.sh
-template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, const bool);
-template bool igl::write_triangle_mesh<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&, bool);
+template bool igl::write_triangle_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, igl::FileEncoding);
+template bool igl::write_triangle_mesh<Eigen::Matrix<double, 8, 3, 0, 8, 3>, Eigen::Matrix<int, 12, 3, 0, 12, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::MatrixBase<Eigen::Matrix<double, 8, 3, 0, 8, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, 12, 3, 0, 12, 3> > const&, igl::FileEncoding);
 #endif
 #endif

+ 3 - 2
include/igl/write_triangle_mesh.h

@@ -8,6 +8,7 @@
 #ifndef IGL_WRITE_TRIANGLE_MESH_H
 #ifndef IGL_WRITE_TRIANGLE_MESH_H
 #define IGL_WRITE_TRIANGLE_MESH_H
 #define IGL_WRITE_TRIANGLE_MESH_H
 #include "igl_inline.h"
 #include "igl_inline.h"
+#include <igl/FileEncoding.h>
 
 
 #include <Eigen/Core>
 #include <Eigen/Core>
 #include <string>
 #include <string>
@@ -25,14 +26,14 @@ namespace igl
   //   str  path to file
   //   str  path to file
   //   V  eigen double matrix #V by 3
   //   V  eigen double matrix #V by 3
   //   F  eigen int matrix #F by 3
   //   F  eigen int matrix #F by 3
-  //   force_ascii  force ascii format even if binary is available
+  //   encoding  set file encoding (ascii or binary) when both are available
   // Returns true iff success
   // Returns true iff success
   template <typename DerivedV, typename DerivedF>
   template <typename DerivedV, typename DerivedF>
   IGL_INLINE bool write_triangle_mesh(
   IGL_INLINE bool write_triangle_mesh(
     const std::string str,
     const std::string str,
     const Eigen::MatrixBase<DerivedV>& V,
     const Eigen::MatrixBase<DerivedV>& V,
     const Eigen::MatrixBase<DerivedF>& F,
     const Eigen::MatrixBase<DerivedF>& F,
-    const bool force_ascii = true);
+    FileEncoding encoding = FileEncoding::Ascii);
 }
 }
 
 
 #ifndef IGL_STATIC_LIBRARY
 #ifndef IGL_STATIC_LIBRARY

+ 6 - 6
tests/include/igl/writePLY.cpp

@@ -10,7 +10,7 @@ TEST_CASE("writePLY: bunny.ply", "[igl]")
     std::ifstream f(test_common::data_path("bunny.ply"));
     std::ifstream f(test_common::data_path("bunny.ply"));
     REQUIRE (f.good());
     REQUIRE (f.good());
     f.close();
     f.close();
-    
+
     Eigen::MatrixXd V1,N1,UV1,VD1,FD1,ED1;
     Eigen::MatrixXd V1,N1,UV1,VD1,FD1,ED1;
     std::vector<std::string> Vheader1,Fheader1,Eheader1,comments1;
     std::vector<std::string> Vheader1,Fheader1,Eheader1,comments1;
 
 
@@ -19,7 +19,7 @@ TEST_CASE("writePLY: bunny.ply", "[igl]")
     // load test data first
     // load test data first
     REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V1, F1, E1, N1, UV1, VD1,Vheader1, FD1,Fheader1, ED1,Eheader1,comments1));
     REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V1, F1, E1, N1, UV1, VD1,Vheader1, FD1,Fheader1, ED1,Eheader1,comments1));
 
 
-    // add more data 
+    // add more data
     Vheader1.push_back("dummy_data");
     Vheader1.push_back("dummy_data");
     Eigen::VectorXd dummy_data(V1.rows());
     Eigen::VectorXd dummy_data(V1.rows());
     for(size_t i=0;i<V1.rows();++i)
     for(size_t i=0;i<V1.rows();++i)
@@ -29,7 +29,7 @@ TEST_CASE("writePLY: bunny.ply", "[igl]")
 
 
 
 
     // test that saving preserves all the data, including new data column
     // test that saving preserves all the data, including new data column
-    REQUIRE (igl::writePLY("test_bunny.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD1,Fheader1, ED1, Eheader1, comments1, true));
+    REQUIRE (igl::writePLY("test_bunny.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD1,Fheader1, ED1, Eheader1, comments1, igl::FileEncoding::Binary));
 
 
     Eigen::MatrixXd V,N,UV,VD,FD,ED;
     Eigen::MatrixXd V,N,UV,VD,FD,ED;
     Eigen::MatrixXi F,E;
     Eigen::MatrixXi F,E;
@@ -85,7 +85,7 @@ TEST_CASE("writePLY: bunny.ply float", "[igl]")
     std::ifstream f(test_common::data_path("bunny.ply"));
     std::ifstream f(test_common::data_path("bunny.ply"));
     REQUIRE (f.good());
     REQUIRE (f.good());
     f.close();
     f.close();
-    
+
     Eigen::MatrixXf V1,N1,UV1,VD1,FD1,ED1;
     Eigen::MatrixXf V1,N1,UV1,VD1,FD1,ED1;
     std::vector<std::string> Vheader1,Fheader1,Eheader1,comments1;
     std::vector<std::string> Vheader1,Fheader1,Eheader1,comments1;
 
 
@@ -94,7 +94,7 @@ TEST_CASE("writePLY: bunny.ply float", "[igl]")
     // load test data first
     // load test data first
     REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V1, F1, E1, N1, UV1, VD1,Vheader1, FD1,Fheader1, ED1,Eheader1,comments1));
     REQUIRE (igl::readPLY(test_common::data_path("bunny.ply"), V1, F1, E1, N1, UV1, VD1,Vheader1, FD1,Fheader1, ED1,Eheader1,comments1));
 
 
-    // add more data 
+    // add more data
     Vheader1.push_back("dummy_data");
     Vheader1.push_back("dummy_data");
     Eigen::VectorXf dummy_data(V1.rows());
     Eigen::VectorXf dummy_data(V1.rows());
     for(size_t i=0;i<V1.rows();++i)
     for(size_t i=0;i<V1.rows();++i)
@@ -104,7 +104,7 @@ TEST_CASE("writePLY: bunny.ply float", "[igl]")
 
 
 
 
     // test that saving preserves all the data, including new data column
     // test that saving preserves all the data, including new data column
-    REQUIRE (igl::writePLY("test_bunny.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD1,Fheader1, ED1, Eheader1, comments1, true));
+    REQUIRE (igl::writePLY("test_bunny.ply", V1, F1, E1, N1, UV1, VD2, Vheader1, FD1,Fheader1, ED1, Eheader1, comments1, igl::FileEncoding::Binary));
 
 
     Eigen::MatrixXf V,N,UV,VD,FD,ED;
     Eigen::MatrixXf V,N,UV,VD,FD,ED;
     Eigen::MatrixXi F,E;
     Eigen::MatrixXi F,E;