34 #ifndef AIMS_IO_MESHW_H
35 #define AIMS_IO_MESHW_H
52 template<
int D,
class T=Vo
id>
56 MeshWriter(
const std::string & name,
bool ascii =
false,
58 : _name( name ), _ascii( ascii ), _itemw( ir ) { }
64 inline std::string removeExtension(
const std::string& name)
const;
66 {
delete _itemw; _itemw = ir; }
75 template <
int D,
class T>
80 writer.
write( thing );
85 template <
int D,
class T>
inline
88 std::string res = name;
90 if( res.length() > 5 )
91 ext = res.substr(
int(res.length() - 5), 5 );
93 res = res.substr( 0, res.length() - 5 );
98 template <
int D,
class T>
inline
101 std::string fname = removeExtension( _name ) +
".mesh";
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 );
The template class to manage a mesh with time if needed.
const aims::PythonHeader & header() const
Get the header.
std::map< int, AimsSurface< D, T > >::const_iterator const_iterator
const std::vector< Point3df > & vertex() const
Get a const reference to the vector of verteces of the surface of index 0.
Default low-levels writers.
virtual ItemWriter< T > * writer(const std::string &openmode="binar", bool bswap=false) const
Low-level "small item" writer, used by higher-level file readers.
Mesh format writer for mesh objects.
void setItemWriter(ItemWriter< T > *ir)
std::string removeExtension(const std::string &name) const
Return a name without .mesh extension.
MeshWriter(const std::string &name, bool ascii=false, ItemWriter< T > *ir=0)
void write(const AimsTimeSurface< D, T > &thing)
virtual bool removeProperty(const std::string &)
virtual bool hasProperty(const std::string &) const
#define AIMS_MAGIC_NUMBER
The class for EcatSino data write operation.
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.
MotionWriter & operator<<(MotionWriter &writer, const AffineTransformation3d &thing) __attribute__((__deprecated__("OBSOLETE")))
— OBSOLETE —
AIMSDATA_API float norm(const Tensor &thing)