|
@@ -33,6 +33,47 @@ IGL_INLINE bool igl::writeOFF(
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+// write mesh and colors-by-vertex to an ascii off file
|
|
|
+template <typename DerivedV, typename DerivedF, typename DerivedC>
|
|
|
+IGL_INLINE bool igl::writeOFF(
|
|
|
+ const std::string fname,
|
|
|
+ const Eigen::PlainObjectBase<DerivedV>& V,
|
|
|
+ const Eigen::PlainObjectBase<DerivedF>& F,
|
|
|
+ const Eigen::PlainObjectBase<DerivedC>& C)
|
|
|
+{
|
|
|
+ using namespace std;
|
|
|
+ using namespace Eigen;
|
|
|
+ assert(V.cols() == 3 && "V should have 3 columns");
|
|
|
+ assert(C.cols() == 3 && "C should have 3 columns");
|
|
|
+
|
|
|
+ if(V.rows() != C.rows())
|
|
|
+ {
|
|
|
+ fprintf(stderr,"IOError: writeOFF() Only color per vertex supported. V and C should have same size.\n");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ ofstream s(fname);
|
|
|
+ if(!s.is_open())
|
|
|
+ {
|
|
|
+ fprintf(stderr,"IOError: writeOFF() could not open %s\n",fname.c_str());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ //Check if RGB values are in the range [0..1] or [0..255]
|
|
|
+ int rgbScale = (C.maxCoeff() <= 1.0)?255:1;
|
|
|
+ Eigen::MatrixXd RGB = rgbScale * C;
|
|
|
+
|
|
|
+ s<< "COFF\n"<<V.rows()<<" "<<F.rows()<<" 0\n";
|
|
|
+ for (unsigned i=0; i< V.rows(); i++)
|
|
|
+ {
|
|
|
+ s <<V.row(i).format(IOFormat(FullPrecision,DontAlignCols," "," ","","",""," "));
|
|
|
+ s << unsigned(RGB(i,0)) << " " << unsigned(RGB(i,1)) << " " << unsigned(RGB(i,2)) << " 255\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ s<<(F.array()).format(IOFormat(FullPrecision,DontAlignCols," ","\n","3 ","","","\n"));
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
|
// Explicit template specialization
|
|
|
// generated by autoexplicit.sh
|
|
@@ -44,4 +85,6 @@ template bool igl::writeOFF<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix
|
|
|
template bool igl::writeOFF<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::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
|
|
|
template bool igl::writeOFF<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 3, 0, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
|
|
|
template bool igl::writeOFF<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::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&);
|
|
|
+template bool igl::writeOFF<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<double, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&);
|
|
|
+template bool igl::writeOFF<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, 3, 1, -1, 3>, Eigen::Matrix<double, -1, 3, 1, -1, 3> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&);
|
|
|
#endif
|