|
@@ -7,6 +7,7 @@
|
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
#include "writeOFF.h"
|
|
|
#include <cstdio>
|
|
|
+#include <fstream>
|
|
|
|
|
|
// write mesh to an ascii off file
|
|
|
template <typename DerivedV, typename DerivedF>
|
|
@@ -15,39 +16,23 @@ IGL_INLINE bool igl::writeOFF(
|
|
|
const Eigen::PlainObjectBase<DerivedV>& V,
|
|
|
const Eigen::PlainObjectBase<DerivedF>& F)
|
|
|
{
|
|
|
- FILE *fp = fopen (fname.c_str(), "w");
|
|
|
-
|
|
|
-
|
|
|
- if (!fp)
|
|
|
+ using namespace std;
|
|
|
+ using namespace Eigen;
|
|
|
+ assert(V.cols() == 3 && "V should have 3 columns");
|
|
|
+ ofstream s(fname);
|
|
|
+ if(!s.is_open())
|
|
|
{
|
|
|
- fprintf (stderr, "writeOFF(): could not open file %s", fname.c_str());
|
|
|
+ fprintf(stderr,"IOError: writeOFF() could not open %s\n",fname.c_str());
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- fprintf (fp, "OFF\n%d %d 0\n", (int) V.rows(), (int) F.rows());
|
|
|
-
|
|
|
- for (int i = 0; i < V.rows(); i++)
|
|
|
- {
|
|
|
- fprintf(
|
|
|
- fp,
|
|
|
- "%0.17g %0.17g %0.17g\n",
|
|
|
- (double)V(i,0),
|
|
|
- (double)V(i,1),
|
|
|
- (double)V(i,2));
|
|
|
- }
|
|
|
-
|
|
|
-// for (int i = 0; i < F.rows(); i++)
|
|
|
-// fprintf (fp, "3 %d %d %d\n", F(i,0), F(i,1), F(i,2));
|
|
|
- for (int i = 0; i < (int)F.rows(); i++)
|
|
|
- {
|
|
|
- fprintf (fp, "%d", (int)F.cols());
|
|
|
- for (int j = 0; j < (int)F.cols(); j++)
|
|
|
- fprintf (fp, " %d", (int)F(i,j));
|
|
|
- fprintf (fp, "\n");
|
|
|
- }
|
|
|
- fclose (fp);
|
|
|
+ s<<
|
|
|
+ "OFF\n"<<V.rows()<<" "<<F.rows()<<" 0\n"<<
|
|
|
+ V.format(IOFormat(FullPrecision,DontAlignCols," ","\n","","","","\n"))<<
|
|
|
+ (F.array()).format(IOFormat(FullPrecision,DontAlignCols," ","\n","3 ","","","\n"));
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
|
// Explicit template specialization
|
|
|
// generated by autoexplicit.sh
|