📄 omformat.hh
字号:
{ return static_cast<Chunk::Dim>( _hdr.dim_ ); } // calc minimum (power-of-2) number of bits needed Chunk::Integer_Size needed_bits( size_t s ); // Return the storage type (Chunk::Header::bits_) template <typename T> inline unsigned int bits(const T& val) { return is_integer(val) ? (static_cast<unsigned int>(integer_size(val))) : (static_cast<unsigned int>(float_size(val))); } // Convert size of type to Integer_Size template <typename T> Chunk::Integer_Size integer_size(const T& d) { assert( is_integer(d) ); switch( sizeof(T) ) { case 1: return OMFormat::Chunk::Integer_8; case 2: return OMFormat::Chunk::Integer_16; case 4: return OMFormat::Chunk::Integer_32; case 8: return OMFormat::Chunk::Integer_64; } return Chunk::Integer_Size(0); } // Convert size of type to FLoat_Size template <typename T> Chunk::Float_Size float_size(const T& d) { assert( is_float(d) ); switch( sizeof(T) ) { case 4: return OMFormat::Chunk::Float_32; case 8: return OMFormat::Chunk::Float_64; case 16: return OMFormat::Chunk::Float_128; } return Chunk::Float_Size(0); } // -------------------- create/read version inline uint8 mk_version(const uint16 major, const uint16 minor) { return (major & 0x07) << 5 | (minor & 0x1f); } inline uint16 major_version(const uint8 version) { return (version >> 5) & 0x07; } inline uint16 minor_version(const uint8 version) { return (version & 0x001f); } // ---------------------------------------- convenience functions const char *as_string(Chunk::Type t); const char *as_string(Chunk::Entity e); const char *as_string(Chunk::Dim d); const char *as_string(Chunk::Integer_Size d); const char *as_string(Chunk::Float_Size d); std::ostream& operator << ( std::ostream& _os, const Header& _h ); std::ostream& operator << ( std::ostream& _os, const Chunk::Header& _c );//@}} // namespace OMFormat // -------------------- (re-)store header template <> inline size_t store( std::ostream& _os, const OMFormat::Header& _hdr, bool _swap) { return _hdr.store( _os, _swap ); } template <> inline size_t restore( std::istream& _is, OMFormat::Header& _hdr, bool _swap ) { return _hdr.restore( _is, _swap ); } // -------------------- (re-)store chunk header template <> inline size_t store( std::ostream& _os, const OMFormat::Chunk::Header& _hdr, bool _swap) { OMFormat::uint16 val; val << _hdr; return binary<uint16_t>::store( _os, val, _swap ); } template <> inline size_t restore( std::istream& _is, OMFormat::Chunk::Header& _hdr, bool _swap ) { OMFormat::uint16 val; size_t bytes = binary<uint16_t>::restore( _is, val, _swap ); _hdr << val; return bytes; } // -------------------- (re-)store integer with wanted number of bits (bytes) typedef GenProg::True t_signed; typedef GenProg::False t_unsigned; // helper to store a an integer template< typename T > size_t store( std::ostream& _os, const T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_signed); // helper to store a an unsigned integer template< typename T > size_t store( std::ostream& _os, const T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_unsigned); /// Store an integer with a wanted number of bits template< typename T > inline size_t store( std::ostream& _os, const T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap) { assert( OMFormat::is_integer( _val ) ); if ( OMFormat::is_signed( _val ) ) return store( _os, _val, _b, _swap, t_signed() ); return store( _os, _val, _b, _swap, t_unsigned() ); } // helper to store a an integer template< typename T > inline size_t restore( std::istream& _is, T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_signed); // helper to store a an unsigned integer template< typename T > inline size_t restore( std::istream& _is, T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap, t_unsigned); /// Restore an integer with a wanted number of bits template< typename T > inline size_t restore( std::istream& _is, T& _val, OMFormat::Chunk::Integer_Size _b, bool _swap) { assert( OMFormat::is_integer( _val ) ); if ( OMFormat::is_signed( _val ) ) return restore( _is, _val, _b, _swap, t_signed() ); return restore( _is, _val, _b, _swap, t_unsigned() ); } // // ---------------------------------------- storing vectors template <typename VecT> inline size_t store( std::ostream& _os, const VecT& _vec, GenProg::Int2Type<1>, bool _swap ) { return store( _os, _vec[0], _swap ); } template <typename VecT> inline size_t store( std::ostream& _os, const VecT& _vec, GenProg::Int2Type<2>, bool _swap ) { size_t bytes = store( _os, _vec[0], _swap ); bytes += store( _os, _vec[1], _swap ); return bytes; } template <typename VecT> inline size_t store( std::ostream& _os, const VecT& _vec, GenProg::Int2Type<3>, bool _swap ) { size_t bytes = store( _os, _vec[0], _swap ); bytes += store( _os, _vec[1], _swap ); bytes += store( _os, _vec[2], _swap ); return bytes; } template <typename VecT> inline size_t store( std::ostream& _os, const VecT& _vec, GenProg::Int2Type<4>, bool _swap ) { size_t bytes = store( _os, _vec[0], _swap ); bytes += store( _os, _vec[1], _swap ); bytes += store( _os, _vec[2], _swap ); bytes += store( _os, _vec[3], _swap ); return bytes; } /// storing a vector type template <typename VecT> inline size_t vector_store( std::ostream& _os, const VecT& _vec, bool _swap ) { return store( _os, _vec, GenProg::Int2Type< vector_traits<VecT>::size_ >(), _swap ); } // ---------------------------------------- restoring vectors template <typename VecT> inline size_t restore( std::istream& _is, VecT& _vec, GenProg::Int2Type<1>, bool _swap ) { return restore( _is, _vec[0], _swap ); } template <typename VecT> inline size_t restore( std::istream& _is, VecT& _vec, GenProg::Int2Type<2>, bool _swap ) { size_t bytes = restore( _is, _vec[0], _swap ); bytes += restore( _is, _vec[1], _swap ); return bytes; } template <typename VecT> inline size_t restore( std::istream& _is, VecT& _vec, GenProg::Int2Type<3>, bool _swap ) { typedef typename vector_traits<VecT>::value_type scalar_type; size_t bytes; bytes = binary<scalar_type>::restore( _is, _vec[0], _swap ); bytes += binary<scalar_type>::restore( _is, _vec[1], _swap ); bytes += binary<scalar_type>::restore( _is, _vec[2], _swap ); return bytes; } template <typename VecT> inline size_t restore( std::istream& _is, VecT& _vec, GenProg::Int2Type<4>, bool _swap ) { typedef typename vector_traits<VecT>::value_type scalar_type; size_t bytes; bytes = binary<scalar_type>::restore( _is, _vec[0], _swap ); bytes += binary<scalar_type>::restore( _is, _vec[1], _swap ); bytes += binary<scalar_type>::restore( _is, _vec[2], _swap ); bytes += binary<scalar_type>::restore( _is, _vec[3], _swap ); return bytes; } /// Restoring a vector type template <typename VecT> inline size_t vector_restore( std::istream& _is, VecT& _vec, bool _swap ) { return restore( _is, _vec, GenProg::Int2Type< vector_traits<VecT>::size_ >(), _swap ); } // ---------------------------------------- storing property names template <> inline size_t store( std::ostream& _os, const OMFormat::Chunk::PropertyName& _pn, bool _swap ) { store( _os, _pn.size(), OMFormat::Chunk::Integer_8, _swap ); // 1 byte if ( _pn.size() ) _os.write( _pn.c_str(), _pn.size() ); // size bytes return _pn.size() + 1; } template <> inline size_t restore( std::istream& _is, OMFormat::Chunk::PropertyName& _pn, bool _swap ) { size_t size; restore( _is, size, OMFormat::Chunk::Integer_8, _swap); // 1 byte assert( OMFormat::Chunk::PropertyName::is_valid( size ) ); if ( size > 0 ) { char buf[256]; _is.read( buf, size ); // size bytes buf[size] = '\0'; _pn.resize(size); _pn = buf; } return size+1; }//=============================================================================} // namespace IO} // namespace OpenMesh#endif//=============================================================================#if defined(OM_MISSING_HEADER_LIMITS)# undef OM_MISSING_HEADER_LIMITS#endif//=============================================================================#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_IO_OMFORMAT_CC)# define OPENMESH_IO_OMFORMAT_TEMPLATES# include "OMFormat.cc"#endif//=============================================================================#endif//=============================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -