MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / fromMrDistanceMap

Function fromMrDistanceMap

source/MRMesh/MRDistanceMapLoad.cpp:71–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69}
70
71Expected<DistanceMap> fromMrDistanceMap( const std::filesystem::path& path, const DistanceMapLoadSettings& settings )
72{
73 if ( path.empty() )
74 return unexpected( "Path is empty" );
75
76 auto ext = utf8string( path.extension() );
77 for ( auto& c : ext )
78 c = ( char )tolower( c );
79
80 if ( ext != ".mrdistancemap" )
81 {
82 std::stringstream ss;
83 ss << "Extension is not correct, expected \".mrdistancemap\" current \"" << ext << "\"" << std::endl;
84 return unexpected( ss.str() );
85 }
86
87 std::error_code ec;
88 if ( !std::filesystem::exists( path, ec ) )
89 return unexpected( "File " + utf8string( path ) + " does not exist" );
90
91 std::ifstream inFile( path, std::ios::binary );
92 const std::string readError = "Cannot read file: " + utf8string( path );
93 if ( !inFile )
94 return unexpected( readError );
95
96 auto params = settings.distanceMapToWorld;
97 if ( !params )
98 {
99 static DistanceMapToWorld defaultParams;
100 params = &defaultParams;
101 }
102 if ( !inFile.read( ( char* )params, sizeof( DistanceMapToWorld ) ) )
103 return unexpected( readError );
104
105 uint64_t resolution[2] = {};
106 if ( !inFile.read( ( char* )resolution, sizeof( resolution ) ) )
107 return unexpected( readError );
108
109 DistanceMap dmap( resolution[0], resolution[1] );
110 const size_t size = size_t( resolution[0] ) * size_t( resolution[1] );
111 std::vector<float> buffer( size );
112
113 if ( !readByBlocks( inFile, ( char* )buffer.data(), buffer.size() * sizeof( float ), settings.progress ) )
114 return unexpectedOperationCanceled();
115
116 if ( !inFile )
117 return unexpected( readError );
118
119 for ( size_t i = 0; i < size; ++i )
120 dmap.set( int( i ), buffer[i] );
121
122 return dmap;
123}
124
125#if !defined( __EMSCRIPTEN__ ) && !defined( MRMESH_NO_TIFF )
126Expected<DistanceMap> fromTiff( const std::filesystem::path& path, const DistanceMapLoadSettings& settings )

Calls 9

utf8stringFunction · 0.85
readByBlocksFunction · 0.85
unexpectedFunction · 0.70
emptyMethod · 0.45
readMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected