The Parametric Pseudo-Manifold (PPS) Library 1.0
|
00001 00026 #include <iostream> 00027 #include <iomanip> 00028 #include <cassert> 00029 00030 #include "writer.h" 00031 00032 00046 namespace offlib { 00047 00048 00056 Writer::Writer( const std::string& fn ) 00057 { 00058 assert( !fn.empty() ) ; 00059 00060 _fname = fn + std::string( ".off" ) ; 00061 00062 return ; 00063 } 00064 00065 00073 Writer::Writer( const Writer& w ) : _fname( w._fname ) 00074 {} 00075 00076 00088 void 00089 Writer::write( 00090 unsigned nv , 00091 double* vset , 00092 unsigned nf , 00093 unsigned* fset 00094 ) 00095 { 00096 _fs.open( _fname.c_str() , std::ios::out | std::ios::binary ) ; 00097 00098 assert( _fs != 0 ) ; 00099 00100 write_header( nv , nf ) ; 00101 00102 write_vertices( nv , vset ) ; 00103 00104 write_faces( nf , fset ) ; 00105 00106 _fs.close() ; 00107 00108 return ; 00109 } 00110 00111 00120 void 00121 Writer::write_header( 00122 unsigned nv , 00123 unsigned nf 00124 ) 00125 { 00126 // 00127 // Write first line 00128 // 00129 _fs << "OFF" << std::endl ; 00130 00131 // 00132 // Write the number of vertices, faces, and edges 00133 // 00134 _fs << nv 00135 << " " 00136 << nf 00137 << " 0" 00138 << std::endl ; 00139 } 00140 00141 00150 void 00151 Writer::write_vertices( 00152 unsigned nv , 00153 double* vset 00154 ) 00155 { 00156 _fs << std::fixed << std::setprecision( 18 ) ; 00157 00158 for ( unsigned i = 0 ; i < nv ; i++ ) { 00159 00160 const unsigned j = 3 * i ; 00161 00162 _fs << vset[ j ] 00163 << " " 00164 << vset[ j + 1 ] 00165 << " " 00166 << vset[ j + 2 ] 00167 << std::endl; 00168 } 00169 00170 return ; 00171 } 00172 00173 00182 void 00183 Writer::write_faces( 00184 unsigned nf , 00185 unsigned* fset 00186 ) 00187 { 00188 for ( unsigned i = 0 ; i < nf ; i++ ) { 00189 00190 const unsigned j = 3 * i; 00191 00192 _fs << "3 " 00193 << fset[ j ] 00194 << " " 00195 << fset[ j + 1 ] 00196 << " " 00197 << fset[ j + 2 ] 00198 << std::endl ; 00199 } 00200 00201 return ; 00202 } 00203 00204 } 00205 //end of group class.