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

Function makeObjectTreeFromFolder

source/MRViewer/MROpenObjects.cpp:22–266  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21
22Expected<LoadedObject> makeObjectTreeFromFolder( const std::filesystem::path & folder, bool dicomOnly, const ProgressCallback& callback )
23{
24 MR_TIMER;
25
26 if ( callback && !callback( 0.f ) )
27 return unexpected( getCancelMessage( folder ) );
28
29 ParallelProgressReporter cb( callback );
30
31 struct FilePathNode
32 {
33 std::filesystem::path path;
34 std::vector<FilePathNode> subfolders;
35 std::vector<FilePathNode> files;
36 bool dicomFolder = false;
37 #if !defined( MESHLIB_NO_VOXELS ) && !defined( MRVOXELS_NO_DICOM )
38 VoxelsLoad::DicomStatus dicomStatus = VoxelsLoad::DicomStatusEnum::Invalid;
39 #endif
40
41 bool empty() const
42 {
43 return files.empty() && subfolders.empty() && !dicomFolder;
44 }
45 };
46
47 std::function<FilePathNode( const std::filesystem::path& )> getFilePathNode;
48 getFilePathNode = [&getFilePathNode, filters = getAllFilters()] ( const std::filesystem::path& folder )
49 {
50 FilePathNode node{ .path = folder };
51 std::error_code ec;
52 for ( auto entry : Directory{ folder, ec } )
53 {
54 auto path = entry.path();
55 if ( entry.is_directory( ec ) )
56 {
57 node.subfolders.push_back( getFilePathNode( path ) );
58 }
59 else if ( !node.dicomFolder && ( entry.is_regular_file( ec ) || entry.is_symlink( ec ) ) )
60 {
61 auto ext = utf8string( path.extension() );
62 for ( auto& c : ext )
63 c = ( char )tolower( c );
64
65 #if !defined( MESHLIB_NO_VOXELS ) && !defined( MRVOXELS_NO_DICOM )
66 if ( auto dicomStatus = VoxelsLoad::isDicomFile( path ); dicomStatus != VoxelsLoad::DicomStatusEnum::Invalid ) // unsupported will be reported later
67 {
68 node.dicomStatus = dicomStatus;
69 node.dicomFolder = true;
70 node.files.clear();
71 }
72 else
73 #endif
74 if ( findFilter( filters, ext ) )
75 node.files.push_back( { .path = path } );
76 }
77 }
78 return node;
79 };

Callers 4

sOpenDICOMsFunction · 0.85
openDirectoryMethod · 0.85
makeObjectTreeFromZipFunction · 0.85
loadFilesMethod · 0.85

Calls 15

getCancelMessageFunction · 0.85
getAllFiltersFunction · 0.85
utf8stringFunction · 0.85
isDicomFileFunction · 0.85
findFilterFunction · 0.85
getActualModelLengthUnitFunction · 0.85
loadObjectFromFileFunction · 0.85
push_backMethod · 0.80
eraseMethod · 0.80
addChildMethod · 0.80
newTaskMethod · 0.80

Tested by

no test coverage detected