@@ -212,7 +212,6 @@ def __init__(
212
212
rot_h = torch .cat ((rot , zeros ), dim = - 2 ).reshape (- 1 , 4 , 3 )
213
213
self ._matrix = torch .cat ((rot_h , self ._matrix [:, :, 3 ].reshape (- 1 , 4 , 1 )), dim = - 1 )
214
214
215
- self ._transforms = [] # store transforms to compose
216
215
self ._lu = None
217
216
self .device = device
218
217
self .dtype = self ._matrix .dtype
@@ -240,13 +239,12 @@ def compose(self, *others):
240
239
Returns:
241
240
A new Transform3d with the stored transforms
242
241
"""
243
- out = Transform3d ( device = self . device , dtype = self . dtype )
244
- out . _matrix = self ._matrix . clone ()
242
+
243
+ mat = self ._matrix
245
244
for other in others :
246
- if not isinstance (other , Transform3d ):
247
- msg = "Only possible to compose Transform3d objects; got %s"
248
- raise ValueError (msg % type (other ))
249
- out ._transforms = self ._transforms + list (others )
245
+ mat = _broadcast_bmm (mat , other .get_matrix ())
246
+
247
+ out = Transform3d (device = self .device , dtype = self .dtype , matrix = mat )
250
248
return out
251
249
252
250
def get_matrix (self ):
@@ -266,11 +264,7 @@ def get_matrix(self):
266
264
Returns:
267
265
A transformation matrix representing the composed inputs.
268
266
"""
269
- composed_matrix = self ._matrix
270
- for other in self ._transforms :
271
- other_matrix = other .get_matrix ()
272
- composed_matrix = _broadcast_bmm (composed_matrix , other_matrix )
273
- return composed_matrix
267
+ return self ._matrix
274
268
275
269
def _get_matrix_inverse (self ):
276
270
"""
@@ -311,40 +305,16 @@ def inverse(self, invert_composed: bool = False):
311
305
transformation.
312
306
"""
313
307
314
- tinv = Transform3d ( device = self .device )
308
+ i_matrix = self ._get_matrix_inverse ( )
315
309
316
- if invert_composed :
317
- # first compose then invert
318
- tinv ._matrix = self ._invert_transformation_matrix (self .get_matrix ())
319
- else :
320
- # self._get_matrix_inverse() implements efficient inverse
321
- # of self._matrix
322
- i_matrix = self ._get_matrix_inverse ()
323
-
324
- # 2 cases:
325
- if len (self ._transforms ) > 0 :
326
- # a) Either we have a non-empty list of transforms:
327
- # Here we take self._matrix and append its inverse at the
328
- # end of the reverted _transforms list. After composing
329
- # the transformations with get_matrix(), this correctly
330
- # right-multiplies by the inverse of self._matrix
331
- # at the end of the composition.
332
- tinv ._transforms = [t .inverse () for t in reversed (self ._transforms )]
333
- last = Transform3d (device = self .device )
334
- last ._matrix = i_matrix
335
- tinv ._transforms .append (last )
336
- else :
337
- # b) Or there are no stored transformations
338
- # we just set inverted matrix
339
- tinv ._matrix = i_matrix
310
+ tinv = Transform3d (matrix = i_matrix , device = self .device )
340
311
341
312
return tinv
342
313
343
314
def stack (self , * others ):
344
315
transforms = [self ] + list (others )
345
316
matrix = torch .cat ([t ._matrix for t in transforms ], dim = 0 )
346
- out = Transform3d ()
347
- out ._matrix = matrix
317
+ out = Transform3d (matrix = matrix , device = self .device , dtype = self .dtype )
348
318
return out
349
319
350
320
def transform_points (self , points , eps : Optional [float ] = None ):
@@ -478,7 +448,6 @@ def clone(self):
478
448
if self ._lu is not None :
479
449
other ._lu = [elem .clone () for elem in self ._lu ]
480
450
other ._matrix = self ._matrix .clone ()
481
- other ._transforms = [t .clone () for t in self ._transforms ]
482
451
return other
483
452
484
453
def to (self , device , copy : bool = False , dtype = None ):
@@ -504,7 +473,6 @@ def to(self, device, copy: bool = False, dtype=None):
504
473
other .device = device
505
474
other .dtype = dtype if dtype is not None else other .dtype
506
475
other ._matrix = self ._matrix .to (device = device , dtype = dtype )
507
- other ._transforms = [t .to (device , copy = copy , dtype = dtype ) for t in other ._transforms ]
508
476
return other
509
477
510
478
def cpu (self ):
0 commit comments