40 #include <geogram/basic/file_system.h> 61 const auto MAX_LINE_LEN =
62 static_cast< unsigned int >( std::pow( 2, 16 ) - 1 );
64 std::ifstream lFile( f1.c_str() );
65 std::ifstream rFile( f2.c_str() );
67 std::unique_ptr< char[] > lBuffer(
new char[MAX_LINE_LEN]() );
68 std::unique_ptr< char[] > rBuffer(
new char[MAX_LINE_LEN]() );
72 lFile.read( lBuffer.get(), MAX_LINE_LEN );
73 rFile.read( rBuffer.get(), MAX_LINE_LEN );
74 size_t numberOfRead =
static_cast< size_t >( lFile.gcount() );
76 if( std::memcmp( lBuffer.get(), rBuffer.get(), numberOfRead ) != 0 )
80 }
while( lFile.good() || rFile.good() );
86 GeoModelIOHandler2D::initialize();
87 GeoModelIOHandler3D::initialize();
93 template < index_t DIMENSION >
97 load( filename, geomodel );
99 "I/O",
" Loaded geomodel ", geomodel.
name(),
" from ", filename );
103 template < index_t DIMENSION >
107 save( geomodel, filename );
112 std::string ext = GEO::FileSystem::extension( filename );
113 if( GeoModelIOHandlerFactory2D::has_creator( ext ) )
115 return GeoModelIOHandler2D::get_handler( filename )
116 ->dimension( filename );
118 else if( GeoModelIOHandlerFactory3D::has_creator( ext ) )
120 return GeoModelIOHandler3D::get_handler( filename )
121 ->dimension( filename );
130 template < index_t DIMENSION >
134 if( !GEO::FileSystem::is_file( filename ) )
138 Logger::out(
"I/O",
"Loading file ", filename,
"..." );
140 std::unique_ptr< GeoModelIOHandler< DIMENSION > > handler(
142 return handler->load_geomodel( filename, geomodel );
145 template < index_t DIMENSION >
149 Logger::out(
"I/O",
"Saving file ", filename,
"..." );
151 std::unique_ptr< GeoModelIOHandler< DIMENSION > > handler(
153 handler->save_geomodel( geomodel, filename );
158 template < index_t DIMENSION >
159 std::unique_ptr< GeoModelIOHandler< DIMENSION > >
165 Logger::err(
"I/O",
"Currently supported file formats are: " );
166 for(
const std::string& name :
173 "I/O",
"Unsupported file format: ", format );
178 template < index_t DIMENSION >
179 std::unique_ptr< GeoModelIOHandler< DIMENSION > >
181 const std::string& filename )
183 return create( GEO::FileSystem::extension( filename ) );
189 template bool RINGMESH_API
geomodel_load( GeoModel2D&,
const std::string& );
191 const GeoModel2D&,
const std::string& );
193 template bool RINGMESH_API
geomodel_load( GeoModel3D&,
const std::string& );
195 const GeoModel3D&,
const std::string& );
void RINGMESH_API mesh_initialize()
static std::unique_ptr< BaseClass > create(const Key &key, const Args &... args)
void save_geomodel(const GeoModel< DIMENSION > &geomodel, const std::string &filename)
bool is_geomodel_valid(const GeoModel< DIMENSION > &geomodel, ValidityCheckMode validity_check_mode=ValidityCheckMode::ALL)
Check global geomodel validity.
static std::unique_ptr< GeoModelIOHandler< DIMENSION > > get_handler(const std::string &filename)
const std::string & name() const
Gets the name of the GeoModel.
bool geomodel_load(GeoModel< DIMENSION > &geomodel, const std::string &filename)
static void err(const std::string &feature, const Args &... args)
static void out(const std::string &feature, const Args &... args)
void geomodel_save(const GeoModel< DIMENSION > &geomodel, const std::string &filename)
index_t RINGMESH_API find_geomodel_dimension(const std::string &filename)
static std::unique_ptr< GeoModelIOHandler > create(const std::string &format)
bool RINGMESH_API compare_files(const std::string &f1, const std::string &f2)
Classes to build GeoModel from various inputs.
bool load_geomodel(const std::string &filename, GeoModel< DIMENSION > &geomodel)
#define ringmesh_assert_not_reached