102 std::string mode = ( _ascii ?
"ascii" :
"binar" );
103 std::ios::openmode omd = std::ios::out;
105 omd |= std::ios::binary;
106 std::ofstream os( fname.c_str(), omd );
112 std::unique_ptr< ItemWriter<T> > ir( _itemw->writer( mode,
false ) );
114 std::unique_ptr< ItemWriter<uint32_t> > sr( sr1.
writer( mode,
false ) );
116 std::unique_ptr< ItemWriter<Point3df> > pr( pr1.
writer( mode,
false ) );
118 std::unique_ptr< ItemWriter<AimsVector<uint,D> > > plr ( plr1.
writer( mode,
false ) );
122 os << ( _ascii ?
"ascii\n" :
"binar" );
125 std::string sep = ( _ascii ?
"\n" :
"" );
130 os.write( (
const char *) &magicNumber,
sizeof(uint32_t) );
132 size_t tmp = code.size();
133 uint32_t typeSize = (uint32_t)tmp;
134 sr->write( os, typeSize );
139 uint32_t dim = (uint32_t)D;
140 sr->write( os, dim );
143 uint32_t size = (uint32_t)thing.size();
144 sr->write( os, size );
155 uint32_t nvertex, nnormal, time, ntexture, npolygon;
158 for ( is=thing.begin(); is!=es; ++is )
161 const std::vector<Point3df> & vert = (*is).second.vertex();
162 const std::vector<Point3df> &
norm = (*is).second.normal();
163 const std::vector<T> & tex = (*is).second.texture();
164 const std::vector<AimsVector<uint,D> > & poly = (*is).second.polygon();
166 nvertex = (uint32_t)vert.size();
167 nnormal = (uint32_t)
norm.size();
168 ntexture = (uint32_t)tex.size();
169 npolygon = (uint32_t)poly.size();
172 sr->write( os, time );
176 sr->write( os, nvertex );
179 pr->write( os, &vert[0], nvertex );
183 sr->write( os, nnormal );
185 pr->write( os, &
norm[0], nnormal );
189 sr->write( os, ntexture );
191 ir->write( os, &tex[0], ntexture );
195 sr->write( os, npolygon );
197 plr->write( os, &poly[0], npolygon );
bool write(const T &obj, const std::string &filename, carto::Object options=carto::none(), const std::string *format=0)
Finds the correct format and writes the object, global version.