@@ -30,7 +30,10 @@ public VolumeDataset Import(string filePath)
30
30
31
31
// Create dataset
32
32
VolumeDataset volumeDataset = ScriptableObject . CreateInstance < VolumeDataset > ( ) ;
33
- ImportInternal ( volumeDataset , niftiFile , filePath ) ;
33
+ bool succeeded = ImportInternal ( volumeDataset , niftiFile , filePath ) ;
34
+
35
+ if ( ! succeeded )
36
+ volumeDataset = null ;
34
37
35
38
return volumeDataset ;
36
39
}
@@ -55,17 +58,26 @@ public async Task<VolumeDataset> ImportAsync(string filePath)
55
58
return null ;
56
59
}
57
60
58
- await Task . Run ( ( ) => ImportInternal ( volumeDataset , niftiFile , filePath ) ) ;
61
+ bool succeeded = await Task . Run ( ( ) => ImportInternal ( volumeDataset , niftiFile , filePath ) ) ;
62
+
63
+ if ( ! succeeded )
64
+ volumeDataset = null ;
59
65
60
66
return volumeDataset ;
61
67
}
62
- private void ImportInternal ( VolumeDataset volumeDataset , Nifti . NET . Nifti niftiFile , string filePath )
68
+ private bool ImportInternal ( VolumeDataset volumeDataset , Nifti . NET . Nifti niftiFile , string filePath )
63
69
{
64
70
int dimX = niftiFile . Header . dim [ 1 ] ;
65
71
int dimY = niftiFile . Header . dim [ 2 ] ;
66
72
int dimZ = niftiFile . Header . dim [ 3 ] ;
67
73
float [ ] pixelData = niftiFile . ToSingleArray ( ) ;
68
74
75
+ if ( pixelData == null )
76
+ {
77
+ Debug . LogError ( $ "Failed to read data, of type: { niftiFile . Data ? . GetType ( ) } ") ;
78
+ return false ;
79
+ }
80
+
69
81
Vector3 pixdim = new Vector3 ( niftiFile . Header . pixdim [ 1 ] , niftiFile . Header . pixdim [ 2 ] , niftiFile . Header . pixdim [ 3 ] ) ;
70
82
Vector3 size = new Vector3 ( dimX * pixdim . x , dimY * pixdim . y , dimZ * pixdim . z ) ;
71
83
@@ -80,6 +92,8 @@ private void ImportInternal(VolumeDataset volumeDataset,Nifti.NET.Nifti niftiFil
80
92
81
93
volumeDataset . FixDimensions ( ) ;
82
94
volumeDataset . rotation = Quaternion . Euler ( 90.0f , 0.0f , 0.0f ) ;
95
+
96
+ return true ;
83
97
}
84
98
}
85
99
}
0 commit comments