Skip to content

Commit 1165d69

Browse files
committed
Apply affine inplace when the underlying arraysequence of the streamlines is not a sliced view.
1 parent 9a400ba commit 1165d69

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

nibabel/streamlines/array_sequence.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ def __init__(self, iterable=None, buffer_size=4):
134134

135135
self.extend(iterable)
136136

137+
@property
138+
def is_sliced_view(self):
139+
return self._lengths.sum() != self._data.shape[0]
140+
137141
@property
138142
def is_array_sequence(self):
139143
return True

nibabel/streamlines/tractogram.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,12 @@ def apply_affine(self, affine, lazy=False):
429429
if np.all(affine == np.eye(4)):
430430
return self # No transformation.
431431

432-
for i in range(len(self.streamlines)):
433-
self.streamlines[i] = apply_affine(affine, self.streamlines[i])
432+
if self.streamlines.is_sliced_view:
433+
# Apply affine only on the selected streamlines.
434+
for i in range(len(self.streamlines)):
435+
self.streamlines[i] = apply_affine(affine, self.streamlines[i])
436+
else:
437+
self.streamlines._data = apply_affine(affine, self.streamlines._data, inplace=True)
434438

435439
if self.affine_to_rasmm is not None:
436440
# Update the affine that brings back the streamlines to RASmm.

0 commit comments

Comments
 (0)