Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DICOM load: convert lengths from meters to current UI units #3740

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions source/MRCommonPlugins/ViewerButtons/MRIOFilesMenuItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "MRViewer/MRMouseController.h"
#include "MRViewer/MRRecentFilesStore.h"
#include "MRViewer/MRViewport.h"
#include "MRViewer/MRUnitSettings.h"
#include "MRViewer/MRUnits.h"
#include "MRViewer/MROpenObjects.h"
#include "MRMesh/MRDirectory.h"
#include "MRMesh/MRIOFormatsRegistry.h"
Expand Down Expand Up @@ -333,11 +335,16 @@ void sOpenDICOMs( const std::filesystem::path & directory, const std::string & s
std::vector<std::shared_ptr<ObjectVoxels>> voxelObjects;
ProgressBar::setTaskCount( (int)loadRes.size() + 1 );
std::string errors;
// conversion factor from meters into current UI length units
float scaleFactor = 1;
if ( auto uiLengthUnit = UnitSettings::getUiLengthUnit() )
scaleFactor = getUnitInfo( LengthUnit::meters ).conversionFactor / getUnitInfo( *uiLengthUnit ).conversionFactor;
for ( auto & res : loadRes )
Comment on lines +339 to 342
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be applied in

auto loadRes = VoxelsLoad::loadDicomsFolderTreeAsVdb( directory, 4, ProgressBar::callBackSetProgress );
``
in 331 line?

{
if ( res.has_value() )
{
ProgressBar::nextTask( "Construct ObjectVoxels" );
res->vol.voxelSize *= scaleFactor;
auto expObj = createObjectVoxels( *res, ProgressBar::callBackSetProgress );
if ( ProgressBar::isCanceled() )
{
Expand Down Expand Up @@ -416,10 +423,10 @@ void OpenDirectoryMenuItem::openDirectory( const std::filesystem::path& director
#if !defined( MESHLIB_NO_VOXELS ) && !defined( MRVOXELS_NO_DICOM )
// check if the directory can be opened as a DICOM archive
if ( VoxelsLoad::isDicomFolder( directory ) )
{
sOpenDICOMs( directory, "Failed to open directory as DICOM:\n" + utf8string( directory ) );
return;
}
{
sOpenDICOMs( directory, "Failed to open directory as DICOM:\n" + utf8string( directory ) );
return;
}
#endif

bool isAnySupportedFiles = isSupportedFileInSubfolders( directory );
Expand Down
7 changes: 6 additions & 1 deletion source/MRViewer/MROpenObjects.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "MROpenObjects.h"
#include "MRUnitSettings.h"
#include <MRMesh/MRObject.h>
#include <MRMesh/MRTimer.h>
#include <MRMesh/MRStringConvert.h>
Expand Down Expand Up @@ -126,7 +127,11 @@ Expected<LoadedObject> makeObjectTreeFromFolder( const std::filesystem::path & f
{
loadTasks.emplace_back( std::async( std::launch::async, [folder = node.path, &loadingCanceled] ()
{
return VoxelsLoad::makeObjectVoxelsFromDicomFolder( folder, [&loadingCanceled]( float ){ return !loadingCanceled; } ).and_then(
float scaleFactor = 1;
if ( auto uiLengthUnit = UnitSettings::getUiLengthUnit() )
scaleFactor = getUnitInfo( LengthUnit::meters ).conversionFactor / getUnitInfo( *uiLengthUnit ).conversionFactor;
return VoxelsLoad::makeObjectVoxelsFromDicomFolder( folder, scaleFactor,
[&loadingCanceled]( float ){ return !loadingCanceled; } ).and_then(
[&]( LoadedObjectVoxels && ld ) -> loadObjResultType
{
return LoadedObjects{ .objs = { ld.obj } };
Expand Down
4 changes: 3 additions & 1 deletion source/MRVoxels/MRDicom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,12 +860,14 @@ Expected<std::shared_ptr<ObjectVoxels>> createObjectVoxels( const DicomVolumeAsV
return obj;
}

Expected<LoadedObjectVoxels> makeObjectVoxelsFromDicomFolder( const std::filesystem::path& folder, const ProgressCallback& callback )
Expected<LoadedObjectVoxels> makeObjectVoxelsFromDicomFolder( const std::filesystem::path& folder,
float scaleFactor, const ProgressCallback& callback )
{
MR_TIMER
return loadDicomFolder<VdbVolume>( folder, 4, subprogress( callback, 0.0f, 0.5f ) ).and_then(
[&]( DicomVolumeAsVdb && vdb )
{
vdb.vol.voxelSize *= scaleFactor;
return createObjectVoxels( vdb, subprogress( callback, 0.5f, 1.0f ) );
} ).and_then(
[&]( std::shared_ptr<ObjectVoxels> && objVoxels ) -> Expected<LoadedObjectVoxels>
Expand Down
4 changes: 3 additions & 1 deletion source/MRVoxels/MRDicom.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ MRVOXELS_API std::vector<Expected<DicomVolumeAsVdb>> loadDicomsFolderTreeAsVdb(
MRVOXELS_API Expected<std::shared_ptr<ObjectVoxels>> createObjectVoxels( const DicomVolumeAsVdb & dcm, const ProgressCallback & cb = {} );

/// Loads 3D volumetric data from dicom-files in given folder, and converts them into an ObjectVoxels
MRVOXELS_API Expected<LoadedObjectVoxels> makeObjectVoxelsFromDicomFolder( const std::filesystem::path& folder, const ProgressCallback& callback = {} );
/// \param scaleFactor multiplier for voxel size
MRVOXELS_API Expected<LoadedObjectVoxels> makeObjectVoxelsFromDicomFolder( const std::filesystem::path& folder,
float scaleFactor, const ProgressCallback& callback = {} );

/// Loads 3D volumetric data from a single DICOM file
template <typename T = SimpleVolumeMinMax>
Expand Down
Loading