Skip to content

Commit 3970e77

Browse files
author
Ayla Khan
authored
Merge pull request #188 from SCIInstitute/nrrd_headers
Nrrd headers
2 parents a0695c3 + abeccb6 commit 3970e77

7 files changed

Lines changed: 356 additions & 60 deletions

File tree

src/Application/LayerIO/NrrdLayerExporter.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,17 @@ bool NrrdLayerExporter::export_nrrd( const std::string& file_path )
7878
DataLayer* temp_handle = dynamic_cast< DataLayer* >(
7979
this->layers_[ 0 ].get() );
8080

81+
bool no_downgrade = PreferencesManager::Instance()->export_nrrd0005_state_->get();
82+
8183
Core::NrrdDataHandle nrrd = Core::NrrdDataHandle( new Core::NrrdData(
82-
temp_handle->get_data_volume()->get_data_block(), temp_handle->get_grid_transform() ) );
84+
temp_handle->get_data_volume()->get_data_block(), temp_handle->get_grid_transform(),
85+
no_downgrade ) );
8386

8487
bool compress = PreferencesManager::Instance()->compression_state_->get();
8588
int level = PreferencesManager::Instance()->compression_level_state_->get();
8689

8790
std::string error;
88-
if ( !( Core::NrrdData::SaveNrrd( file_path, nrrd, error, compress, level ) ) )
91+
if ( !( Core::NrrdData::SaveNrrd( file_path, nrrd, error, compress, level ) ) )
8992
{
9093
CORE_LOG_ERROR( error );
9194
return false;

src/Application/PreferencesManager/PreferencesManager.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ void PreferencesManager::initialize_states()
169169
this->add_state( "compression_level", this->compression_level_state_, 2, 0, 9, 1 );
170170
this->add_state( "slice_step_multiplier", this->slice_step_multiplier_state_, 8 );
171171
this->add_state( "add_dicom_headers", this->export_dicom_headers_state_, true );
172+
this->add_state( "use_nrrd0005_format", this->export_nrrd0005_state_, true );
172173

173174
this->add_state( "axis_labels_option", this->axis_labels_option_state_, "sca",
174175
"sca=Sagittal/Coronal/Axial|sct=Sagittal/Coronal/Transverse|"

src/Application/PreferencesManager/PreferencesManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class PreferencesManager : public Core::StateHandler
8787
Core::StateBoolHandle generate_osx_project_bundle_state_;
8888

8989
Core::StateBoolHandle export_dicom_headers_state_;
90+
Core::StateBoolHandle export_nrrd0005_state_;
9091

9192
//Viewers Preferences
9293
Core::StateOptionHandle default_viewer_mode_state_;

src/Core/DataBlock/NrrdData.cc

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ NrrdData::NrrdData( DataBlockHandle data_block ) :
8383
}
8484

8585

86-
NrrdData::NrrdData( DataBlockHandle data_block, GridTransform transform ) :
86+
NrrdData::NrrdData( DataBlockHandle data_block, GridTransform transform, bool no_downgrade ) :
8787
private_( new NrrdDataPrivate )
8888
{
8989
if ( !data_block )
@@ -102,7 +102,7 @@ NrrdData::NrrdData( DataBlockHandle data_block, GridTransform transform ) :
102102
data_block->get_nx(), data_block->get_ny(),
103103
data_block->get_nz() );
104104

105-
set_transform( transform );
105+
set_transform( transform, no_downgrade );
106106
}
107107
}
108108

@@ -264,7 +264,7 @@ GridTransform NrrdData::get_grid_transform() const
264264
return grid_transform;
265265
}
266266

267-
void NrrdData::set_transform( GridTransform& transform )
267+
void NrrdData::set_transform( GridTransform& transform, bool no_downgrade )
268268
{
269269
if ( !this->private_->nrrd_ ) return;
270270

@@ -319,32 +319,39 @@ void NrrdData::set_transform( GridTransform& transform )
319319
if ( nrrd->spaceDim > 0 && nrrd->spaceDim == nrrd->dim )
320320
{
321321
bool is_aligned_nrrd = true;
322-
for ( size_t j = 0; j < static_cast<size_t>( nrrd->spaceDim ); j++ )
322+
if ( no_downgrade )
323323
{
324-
for ( size_t i = 0; i < static_cast<size_t>( nrrd->dim ); i++ )
324+
is_aligned_nrrd = false;
325+
}
326+
else
327+
{
328+
for ( size_t j = 0; j < static_cast<size_t>( nrrd->spaceDim ); j++ )
325329
{
326-
if ( (i != j) &&
327-
( (nrrd->axis[ i ].spaceDirection[ j ] != 0.0) &&
328-
(! IsNan(nrrd->axis[ i ].spaceDirection[ j ])) ) )
330+
for ( size_t i = 0; i < static_cast<size_t>( nrrd->dim ); i++ )
329331
{
330-
is_aligned_nrrd = false;
332+
if ( (i != j) &&
333+
( (nrrd->axis[ i ].spaceDirection[ j ] != 0.0) &&
334+
(! IsNan(nrrd->axis[ i ].spaceDirection[ j ])) ) )
335+
{
336+
is_aligned_nrrd = false;
337+
}
331338
}
332339
}
333-
}
334340

335-
for ( size_t j = 0; j < static_cast<size_t>( nrrd->spaceDim ); j++ )
336-
{
337-
for ( size_t i = 0; i < static_cast<size_t>( nrrd->spaceDim ); i++ )
341+
for ( size_t j = 0; j < static_cast<size_t>( nrrd->spaceDim ); j++ )
338342
{
339-
if ( (i != j) &&
340-
( (nrrd->measurementFrame[ i ][ j ] != 0.0) &&
341-
(! IsNan( nrrd->measurementFrame[ i ][ j ])) ) )
343+
for ( size_t i = 0; i < static_cast<size_t>( nrrd->spaceDim ); i++ )
342344
{
343-
is_aligned_nrrd = false;
345+
if ( (i != j) &&
346+
( (nrrd->measurementFrame[ i ][ j ] != 0.0) &&
347+
(! IsNan( nrrd->measurementFrame[ i ][ j ])) ) )
348+
{
349+
is_aligned_nrrd = false;
350+
}
344351
}
345352
}
346353
}
347-
354+
348355
if ( is_aligned_nrrd )
349356
{
350357
// Down grade nrrd

src/Core/DataBlock/NrrdData.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ class NrrdData : boost::noncopyable
8080
/// Construct a NrrdData object from an existing DataBlock of data
8181
/// The datablock handle will be stored internally until the object is deleted
8282
/// and the memory with the data is shared between the object and the nrrd object.
83+
/// no_downgrade specifies whether the nrrd format will be downgraded to NRRD0001 when possible.
84+
/// when no_downgrade is true, nrrd format is always NRRD0005.
8385
NrrdData( DataBlockHandle data_block );
84-
NrrdData( DataBlockHandle data_block, GridTransform transform );
86+
NrrdData( DataBlockHandle data_block, GridTransform transform, bool no_downgrade = true );
8587

8688
virtual ~NrrdData();
8789

@@ -109,7 +111,7 @@ class NrrdData : boost::noncopyable
109111

110112
// SET_TRANSFORM:
111113
/// Set the transfrom in the nrrd data
112-
void set_transform( GridTransform& transform );
114+
void set_transform( GridTransform& transform, bool no_downgrade );
113115

114116
// GET_HISTOGRAM:
115117
/// Get the histogram from the nrrd

src/Interface/Application/PreferencesInterface.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ void PreferencesInterface::setup_general_prefs()
162162
PreferencesManager::Instance()->active_layer_navigation_state_ );
163163
QtUtils::QtBridge::Connect( this->private_->ui_.export_dicom_headers_,
164164
PreferencesManager::Instance()->export_dicom_headers_state_ );
165+
QtUtils::QtBridge::Connect( this->private_->ui_.export_nrrd0005_,
166+
PreferencesManager::Instance()->export_nrrd0005_state_ );
165167

166168
QtUtils::QtBridge::Connect( this->private_->ui_.enable_compression_checkbox_,
167169
PreferencesManager::Instance()->compression_state_ );

0 commit comments

Comments
 (0)