Conversation
source/MRViewer/MRViewerIO.h
Outdated
| extern "C" { | ||
|
|
||
| MRVIEWER_API EMSCRIPTEN_KEEPALIVE int load_files( int count, const char** filenames ); | ||
|
|
||
| MRVIEWER_API EMSCRIPTEN_KEEPALIVE int save_file( const char* filename ); | ||
|
|
||
| MRVIEWER_API EMSCRIPTEN_KEEPALIVE int save_scene( const char* filename ); | ||
|
|
||
| } | ||
| #endif |
There was a problem hiding this comment.
this is not needed in header
source/MRMesh/MRProgressCallback.h
Outdated
| const ProgressCallback emptyProgressCallback = [] ( float ) | ||
| { | ||
| return true; | ||
| }; |
source/MRMesh/MRVoxelsSave.h
Outdated
| MRMESH_API tl::expected<void, std::string> saveRAW( const std::filesystem::path& path, const ObjectVoxels& voxelsObject, | ||
| ProgressCallback callback = emptyProgressCallback ); |
source/MRMesh/MRVoxelsSave.cpp
Outdated
| if ( !callback( 0.03f ) ) | ||
| return tl::make_unexpected( std::string( "Saving canceled" ) ); |
There was a problem hiding this comment.
please add callbacks also for actual saving
source/MRViewer/MRViewerIO.cpp
Outdated
| if ( !callback( 0.f ) ) | ||
| return "Saving canceled"; |
There was a problem hiding this comment.
if ( callback && !callback( 0.f ) )
| if ( callback && !callback( float( blockIndex * blockSize ) / dataSize ) ) | ||
| return false; |
There was a problem hiding this comment.
no need to check callback existance, we checked it in the beggining of this function
source/MRMesh/MRPointsSave.cpp
Outdated
| #include <fstream> | ||
| #include "MRMesh/MRProgressReadWrite.h" |
There was a problem hiding this comment.
better add new includes before std ones
source/MRMesh/MRPointsSave.cpp
Outdated
| saveData.callbackFn = [callback, &saveData] ( float progress ) | ||
| { | ||
| progress = ( saveData.sum + progress * saveData.blockSize ) / saveData.maxSize; | ||
| float newProgress = 0.f; | ||
| for ( int i = 0; i < 5; ++i ) | ||
| { | ||
| if ( progress < 0.2f ) | ||
| { | ||
| newProgress += progress / 0.2f * 0.7f * ( 1 - newProgress ); | ||
| break; | ||
| } | ||
| else | ||
| { | ||
| progress = ( progress - 0.2f ) / 0.8f; | ||
| newProgress += ( 1 - newProgress ) * 0.7f; | ||
| } | ||
| } | ||
| return callback( newProgress ); | ||
| }; |
There was a problem hiding this comment.
please add comments about this
source/MRMesh/MRMeshSave.cpp
Outdated
| struct SaveData | ||
| { | ||
| std::function<bool( float )> callbackFn{}; | ||
| std::ostream* stream; | ||
| size_t sum{ 0 }; | ||
| size_t blockSize{ 0 }; | ||
| size_t maxSize{ 0 }; | ||
| } saveData; | ||
| saveData.callbackFn = [callback, &saveData] ( float progress ) | ||
| { | ||
| progress = ( saveData.sum + progress * saveData.blockSize ) / saveData.maxSize; | ||
| float newProgress = 0.f; | ||
| for ( int i = 0; i < 5; ++i ) | ||
| { | ||
| if ( progress < 0.2f ) | ||
| { | ||
| newProgress += progress / 0.2f * 0.7f * ( 1 - newProgress ); | ||
| break; | ||
| } | ||
| else | ||
| { | ||
| progress = ( progress - 0.2f ) / 0.8f; | ||
| newProgress += ( 1 - newProgress ) * 0.7f; | ||
| } | ||
| } | ||
| return callback( newProgress ); | ||
| }; |
source/MRViewer/MRViewerIO.h
Outdated
| * \brief save visual object (mesh, lines, points or voxels) to file | ||
| * \param callback - callback function to set progress (for progress bar) | ||
| */ | ||
| MRVIEWER_API std::string saveObjectToFile( const std::shared_ptr<VisualObject>& obj, const std::filesystem::path& filename, |
There was a problem hiding this comment.
What is returned std::string?
source/MRViewer/MRViewerIO.h
Outdated
| * \brief save visual object (mesh, lines, points or voxels) to file | ||
| * \param callback - callback function to set progress (for progress bar) | ||
| */ | ||
| MRVIEWER_API std::string saveObjectToFile( const std::shared_ptr<VisualObject>& obj, const std::filesystem::path& filename, |
There was a problem hiding this comment.
Can we change the first parameter to const VisualObject & obj or even to const Object & obj?
source/MRMesh/MRProgressReadWrite.h
Outdated
|
|
||
| /** | ||
| * \brief write dataSize bytes from data to out stream by blocks blockSize bytes | ||
| * \details if progress callback not setted write all data by one block |
source/MRMesh/MRProgressReadWrite.h
Outdated
| /** | ||
| * \brief write dataSize bytes from data to out stream by blocks blockSize bytes | ||
| * \details if progress callback not setted write all data by one block | ||
| * \return false if process was canceled (callback setted and return false ) |
There was a problem hiding this comment.
and what is returned if write fails?
There was a problem hiding this comment.
this function does not handle errors
source/MRMesh/MRPointsSave.cpp
Outdated
| for ( auto v : points.validPoints ) | ||
| { | ||
| out << points.points[v] << "\n"; | ||
| if ( callback && !callback( float( pointIndex ) / pointsNum ) ) |
There was a problem hiding this comment.
It is too expensive to run callback for every point! It shall be done on every 1000 point, for example. Here and in other similar places.
source/MRMesh/MRPointsSave.cpp
Outdated
| if ( progress < 0.2f ) | ||
| { | ||
| newProgress += progress / 0.2f * 0.7f * ( 1 - newProgress ); | ||
| break; | ||
| } | ||
| else | ||
| { | ||
| progress = ( progress - 0.2f ) / 0.8f; | ||
| newProgress += ( 1 - newProgress ) * 0.7f; |
There was a problem hiding this comment.
Please introduce named constants (fewer - better) instead of 0.2, 0.7, 0.8
There was a problem hiding this comment.
removed magic numbers
source/MRMesh/MRPointsSave.cpp
Outdated
| // calculate full progress in partical-linear scale (we don't know compressed size and it less than real size) | ||
| progress = ( saveData.sum + progress * saveData.blockSize ) / saveData.maxSize; | ||
| float newProgress = 0.f; | ||
| for ( int i = 0; i < 5; ++i ) |
source/MRMesh/MRPointsSave.cpp
Outdated
| cVert.r = c.r; cVert.g = c.g; cVert.b = c.b; | ||
| out.write( (const char*) &cVert, 15 ); | ||
| out.write( ( const char* )&cVert, 15 ); | ||
| if ( callback && !callback( float( v ) / numVertices ) ) |
There was a problem hiding this comment.
again too expensive to invoke callback on every triangle
|
|
||
| const bool cancel = !MR::writeByBlocks( out, ( const char* )mesh.points.data(), mesh.points.size() * sizeof( Vector3f ), callback ); | ||
| if ( cancel ) | ||
| return tl::make_unexpected( std::string( "Saving canceled" ) ); |
There was a problem hiding this comment.
canceled. writeByBlocks return true only if process was canceled
source/MRViewer/MRViewerIO.h
Outdated
| * \param callback - callback function to set progress (for progress bar) | ||
| * \return empty string if no error or error text | ||
| */ | ||
| MRVIEWER_API std::string saveObjectToFile( const Object& obj, const std::filesystem::path& filename, |
There was a problem hiding this comment.
Let us better return tl::expected<void, std::string> as in MRMeshSave
source/MRMesh/MRPointsSave.cpp
Outdated
| { | ||
| out << points.points[v] << "\n"; | ||
| ++pointIndex; | ||
| if ( !( pointIndex % 1000 ) && callback && !callback( float( pointIndex ) / pointsNum ) ) |
There was a problem hiding this comment.
better
if ( callback && !( pointIndex % 1000 ) && !callback( float( pointIndex ) / pointsNum ) )
to avoid division when no callback, and in other similar places
No description provided.