cgse-coordinates 0.17.3__py3-none-any.whl → 0.17.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1251 +0,0 @@
1
- """
2
- The referenceFrames module provides the class :code:`ReferenceFrames` which defines the affine transformation
3
- for bringing one reference frame to another.
4
-
5
- .. todo:: The tests in methods like getPassiveTransformationTo using '==' should be looked at again and maybe
6
- changed into using the 'is' operator. This because we now have __eq__ implemented.
7
-
8
- @author: Pierre Royer
9
- """
10
-
11
- import logging
12
- import random
13
- import string
14
- import textwrap
15
-
16
- import numpy as np
17
- import transforms3d as t3
18
-
19
- import egse.coordinates.transform3d_addon as t3add
20
- from egse.coordinates.point import Point
21
- from egse.coordinates.rotationMatrix import RotationMatrix
22
- from egse.decorators import deprecate
23
- from egse.exceptions import InvalidOperationError
24
-
25
- LOGGER = logging.getLogger(__name__)
26
- DEBUG = False
27
-
28
-
29
- def transformationToString(transformation):
30
- """Helper function: prints out a transformation (numpy ndarray) in a condensed form on one line."""
31
-
32
- if isinstance(transformation, np.ndarray):
33
- if np.allclose(transformation, ReferenceFrame._I):
34
- return "Identity"
35
- msg = np.array2string(
36
- transformation,
37
- separator=",",
38
- suppress_small=True,
39
- formatter={"float_kind": lambda x: "%.2f" % x},
40
- ).replace("\n", "")
41
- return msg
42
-
43
- # We do not want to raise an Exception here since this is mainly used in logging messages
44
- # and doesn't really harm the execution of the program.
45
- return f"ERROR: expected transformation to be an ndarray, type={type(transformation)}"
46
-
47
-
48
- class ReferenceFrame(object):
49
- """
50
- A Reference Frame defined in reference frame "ref", i.e.
51
- defined by the affine transformation bringing the reference frame "ref" onto "self".
52
-
53
- By default, "ref" is the master refence frame, defined as the identity matrix.
54
-
55
- :param transformation: 4x4 affine transformation matrix defining this system in "ref" system
56
- :type transformation: numpy array
57
-
58
- :param ref: reference system in which this new reference frame is defined
59
- :type ref: ReferenceFrame
60
-
61
- :param name: name the reference frame so it can be referenced, set to 'master' when None
62
- :type name: str
63
-
64
- :param rot_config:
65
- * Is set when using creator ReferenceFrame.fromTranslationRotation()
66
- * In other cases, is set to a default "szyx"
67
- (rotations around static axes z, y and x in this order)
68
- In these other cases, it has no real direct influence,
69
- except for methods returning the rotation vector (e.g. getRotationVector)
70
- It is therefore always recommended to pass it to the constructor, even when
71
- constructing the ReferenceFrame directly from a transformation matrix
72
- :type rot_config: str
73
-
74
- Both the ``transformation`` and the ``ref`` parameters are mandatory.
75
-
76
- If the reference frame is None, the master reference frame is created.
77
-
78
- The master reference frame:
79
-
80
- * is defined by the identity transformation matrix
81
- * has itself as a reference
82
-
83
- For convenience we provide the following factory methods:
84
-
85
- createMaster()
86
- Create a Master Reference Frame
87
-
88
- createRotation(..)
89
- Create a new Reference Frame that is rotated with respect to the given reference frame
90
-
91
- createTranslation(..)
92
- Create a new Reference Frame that is a translation with respect to the given reference frame
93
- """
94
-
95
- _I = np.identity(4)
96
- _MASTER = None
97
- _ROT_CONFIG_DEFAULT = "sxyz"
98
- _names_used = [None, "Master"]
99
- _strict_naming = False
100
- _ACTIVE_DEFAULT = True
101
-
102
- def __new__(cls, transformation, ref, name=None, rot_config=_ROT_CONFIG_DEFAULT):
103
- """Create a new ReferenceFrame class."""
104
-
105
- DEBUG and LOGGER.debug(
106
- f"transformation={transformationToString(transformation)}, ref={ref!r}, name={name}, rot_config={rot_config}"
107
- )
108
-
109
- if ref is None:
110
- msg = (
111
- "No reference frame was given, if you planned to create a Master Reference Frame, "
112
- "use ReferenceFrame.createMaster(). "
113
- )
114
- LOGGER.error(msg)
115
- raise ValueError(msg, "REF_IS_NONE")
116
-
117
- if not isinstance(ref, cls):
118
- msg = f"The 'ref' keyword argument is not a ReferenceFrame object, but {type(ref)}"
119
- LOGGER.error(msg)
120
- raise ValueError(msg, "REF_IS_NOT_CLS")
121
-
122
- if name == "Master":
123
- msg = (
124
- "The 'name' argument cannot be 'Master' unless a Master instance should be created, "
125
- "in that case, use ReferenceFrame.createMaster()"
126
- )
127
- LOGGER.error(msg)
128
- raise ValueError(msg, "MASTER_NAME_USED")
129
-
130
- if transformation is None:
131
- msg = "The 'transformation' argument can not be None, please provide a proper transformation for this reference frame."
132
- LOGGER.error(msg)
133
- raise ValueError(msg, "TRANSFORMATION_IS_NONE")
134
-
135
- if not isinstance(transformation, np.ndarray):
136
- msg = f"The 'transformation' argument shall be a Numpy ndarray [not a {type(transformation)}], please provide a proper transformation for this reference frame."
137
- LOGGER.error(msg)
138
- raise ValueError(msg, "TRANSFORMATION_IS_NOT_NDARRAY")
139
-
140
- if rot_config is None:
141
- msg = "The 'rot_config' keyword argument can not be None, do not specify it when you want to use the default value."
142
- LOGGER.error(msg)
143
- raise ValueError(msg)
144
-
145
- _instance = super(ReferenceFrame, cls).__new__(cls)
146
-
147
- return _instance
148
-
149
- def __init__(self, transformation, ref, name=None, rot_config=_ROT_CONFIG_DEFAULT):
150
- """Initialize the ReferenceFrame object"""
151
-
152
- self.debug = False
153
-
154
- DEBUG and LOGGER.debug(
155
- f"transformation={transformationToString(transformation)}, ref={ref!r}, name={name}, rot_config={rot_config}"
156
- )
157
-
158
- # All argument testing is done in the __new__() method and we should be save here.
159
-
160
- self.ref = ref
161
- self.name = self.__createName(name)
162
- self.transformation = transformation
163
- self.rot_config = rot_config
164
-
165
- self.definition = [self.transformation, self.ref, self.name]
166
-
167
- self.x = self.getAxis("x")
168
- self.y = self.getAxis("y")
169
- self.z = self.getAxis("z")
170
-
171
- self.linkedTo = {}
172
- self.referenceFor = []
173
-
174
- ref.referenceFor.append(self)
175
-
176
- return
177
-
178
- def find_master(self):
179
- return self.findMaster()
180
-
181
- def findMaster(self):
182
- """
183
- Returns the Master frame for this reference frame. The Master frame is always at the end
184
- of the path following the references.
185
-
186
- Returns:
187
- The master frame.
188
- """
189
-
190
- frame = self
191
- while not frame.isMaster():
192
- frame = frame.ref
193
- return frame
194
-
195
- @classmethod
196
- def createMaster(cls):
197
- """
198
- Create a master reference frame.
199
-
200
- A master reference frame is defined with respect to itself and is initialised with the
201
- identity matrix.
202
-
203
- The master frame is automatically given the name "Master".
204
- """
205
- ref_master = super(ReferenceFrame, cls).__new__(cls)
206
- ref_master.name = "Master"
207
- ref_master.ref = ref_master
208
- ref_master.transformation = cls._I
209
- ref_master.rot_config = cls._ROT_CONFIG_DEFAULT
210
- ref_master.initialized = True
211
- ref_master.debug = False
212
- ref_master.linkedTo = {}
213
- ref_master.referenceFor = []
214
-
215
- DEBUG and LOGGER.debug(
216
- f"NEW MASTER CREATED: {id(ref_master)}, ref = {id(ref_master.ref)}, name = {ref_master.name}"
217
- )
218
-
219
- return ref_master
220
-
221
- @classmethod
222
- def __createName(cls, name: str = None):
223
- if name is None:
224
- while name in cls._names_used:
225
- name = "F" + "".join(random.choices(string.ascii_uppercase, k=3))
226
- return name
227
-
228
- if cls._strict_naming:
229
- # generate a unique name
230
-
231
- old_name = name
232
-
233
- while name in cls._names_used:
234
- name = "F" + "".join(random.choices(string.ascii_uppercase, k=3))
235
-
236
- LOGGER.warning(
237
- f"name ('{old_name}') is already defined, since strict naming is applied, "
238
- f"a new unique name was created: {name}"
239
- )
240
-
241
- else:
242
- if name in cls._names_used:
243
- DEBUG and LOGGER.warning(
244
- f"name ('{name}') is already defined, now you have more than one "
245
- f"ReferenceFrame with the same name.",
246
- )
247
-
248
- cls._names_used.append(name)
249
- return name
250
-
251
- @classmethod
252
- def fromTranslation(cls, transx, transy, transz, ref, name=None):
253
- """
254
- Create a ReferenceFrame from a translation with respect to the given reference frame.
255
-
256
- :param transx: translation along the x-axis
257
- :type transx: float
258
-
259
- :param transy: translation along the y-axis
260
- :type transy: float
261
-
262
- :param transz: translation along the z-axis
263
- :type transz: float
264
-
265
- :param ref: reference frame with respect to which the translation is performed. If no ref is given
266
- the rotation is with respect to the master reference frame
267
- :type ref: ReferenceFrame
268
-
269
- :param name: a simple convenient name to identify the reference frame. If no name is provided
270
- a random name of four characters starting with 'F' will be generated.
271
- :type name: str
272
-
273
- :return: a reference frame
274
- """
275
- adef = np.identity(4)
276
- adef[:3, 3] = [transx, transy, transz]
277
-
278
- if ref is None:
279
- raise ValueError("The ref argument can not be None, provide a master or another reference frame.")
280
-
281
- return cls(transformation=adef, ref=ref, name=name)
282
-
283
- @classmethod
284
- def fromRotation(
285
- cls,
286
- rotx,
287
- roty,
288
- rotz,
289
- ref,
290
- name=None,
291
- rot_config=_ROT_CONFIG_DEFAULT,
292
- active=_ACTIVE_DEFAULT,
293
- degrees=True,
294
- ):
295
- """
296
- Create a ReferenceFrame from a rotation with respect to the given reference frame.
297
-
298
- :param rotx: rotation around the x-axis
299
- :type rotx: float
300
-
301
- :param roty: rotation around the y-axis
302
- :type roty: float
303
-
304
- :param rotz: rotation around the z-axis
305
- :type rotz: float
306
-
307
- :param ref: reference frame with respect to which the rotation is performed. If no ref is given
308
- the rotation is with respect to the master reference frame
309
- :type ref: ReferenceFrame
310
-
311
- :param name: a simple convenient name to identify the reference frame. If no name is provided
312
- a random name of four characters starting with 'F' will be generated.
313
- :type name: str
314
-
315
- :return: a reference frame
316
- """
317
- # Convention (rotating axes, in order xyz)
318
-
319
- # rot_config = cls._ROT_CONFIG_DEFAULT
320
-
321
- # Rotation amplitude
322
-
323
- # Rotation
324
- if degrees:
325
- rotx = np.deg2rad(rotx)
326
- roty = np.deg2rad(roty)
327
- rotz = np.deg2rad(rotz)
328
-
329
- rotation = RotationMatrix(rotx, roty, rotz, rot_config, active=active)
330
-
331
- # Defaults for zoom & shear
332
-
333
- zdef = np.array([1, 1, 1])
334
- sdef = np.array([0, 0, 0])
335
-
336
- translation = [0, 0, 0]
337
-
338
- TT = t3.affines.compose(T=translation, R=rotation.R, Z=zdef, S=sdef)
339
-
340
- if ref is None:
341
- raise ValueError("The ref argument can not be None, provide a master or another reference frame.")
342
-
343
- return cls(transformation=TT, ref=ref, name=name, rot_config=rot_config)
344
-
345
- @staticmethod
346
- def fromPoints(points, plane="xy", name=None, usesvd=True, verbose=True):
347
- """
348
- fromPoints(points, plane="xy", name=None, usesvd=True,verbose=True)
349
-
350
- Finds the best fitting "plane" plane to all points in "points" and builds a ReferenceFrame
351
- considering the fitted plane as the 'xy' plane of the new system
352
-
353
- fitPlane must be in ['xy','yz','zx']
354
- """
355
- return points.bestFittingPlane(fitPlane=plane, usesvd=usesvd, verbose=verbose)
356
-
357
- @classmethod
358
- def fromTranslationRotation(
359
- cls,
360
- translation,
361
- rotation,
362
- ref,
363
- name=None,
364
- rot_config=_ROT_CONFIG_DEFAULT,
365
- active=_ACTIVE_DEFAULT,
366
- degrees=True,
367
- ):
368
- """fromTranslationRotation(cls,translation,rotation, ref=None,name=None, rot_config=_ROT_CONFIG_DEFAULT,active=_ACTIVE_DEFAULT, degrees=True)
369
-
370
- Construct a ReferenceFrame from a translation and a rotation (vectors!)
371
-
372
- translation : translation vector : 3 x 1 = tx, ty, tz
373
- rotation : rotation vector : 3 x 1 = rx, ry, rz
374
-
375
- rot_config : convention for the rotation, see rotationMatrix.__doc__
376
-
377
- degrees : if True, input values are assumed in degrees, otherwise radians
378
- """
379
- # Translation
380
- translation = np.array(translation)
381
- # Zoom - unit
382
- zdef = np.array([1, 1, 1])
383
- # Shear
384
- sdef = np.array([0, 0, 0])
385
- # Rotation
386
- if degrees:
387
- rotation = np.array([np.deg2rad(item) for item in rotation])
388
- rotx, roty, rotz = rotation
389
- #
390
- rmat = RotationMatrix(rotx, roty, rotz, rot_config=rot_config, active=active)
391
- #
392
- # transformation = t3.affines.compose(translation,rmat.R,Z=zdef,S=sdef)
393
-
394
- if ref is None:
395
- raise ValueError("The ref argument can not be None, provide a master or another reference frame.")
396
-
397
- return cls(
398
- transformation=t3.affines.compose(translation, rmat.R, Z=zdef, S=sdef),
399
- ref=ref,
400
- name=name,
401
- rot_config=rot_config,
402
- )
403
-
404
- def getTranslationVector(self):
405
- """
406
- getTranslationVector()
407
-
408
- Returns the translation defining this reference frame (from self.ref to self)
409
- """
410
- return self.transformation[:3, 3]
411
-
412
- def getRotationVector(self, degrees=True, active=_ACTIVE_DEFAULT):
413
- """
414
- getRotationVector()
415
-
416
- Returns the rotation (vector) defining this reference frame (from self.ref to self)
417
- degrees : if true, rotation angles are expressed in degrees
418
- """
419
- rotation = t3.euler.mat2euler(self.transformation, axes=self.rot_config)
420
- if degrees:
421
- rotation = np.array([np.rad2deg(item) for item in rotation])
422
- return rotation
423
-
424
- def getTranslationRotationVectors(self, degrees=True, active=_ACTIVE_DEFAULT):
425
- """getTranslationRotationVectors()
426
- Returns the translation and rotation (vectors) defining this reference frame (from self.ref to self)
427
- degrees : if true, rotation angles are expressed in degrees
428
- """
429
- translation = self.getTranslationVector()
430
- rotation = self.getRotationVector(degrees=degrees, active=active)
431
- return translation, rotation
432
-
433
- def getRotationMatrix(self):
434
- """
435
- getRotationMatrix()
436
-
437
- Returns the rotation (matrix) defining this reference frame (from self.ref to self)
438
- """
439
- result = self.transformation.copy()
440
- result[:3, 3] = [0.0, 0.0, 0.0]
441
- return result
442
-
443
- def __repr__(self):
444
- return f"ReferenceFrame(transformation={transformationToString(self.transformation)}, ref={self.ref.name}, name={self.name}, rot_config={self.rot_config})"
445
-
446
- def __str__(self):
447
- msg = textwrap.dedent(
448
- f"""\
449
- ReferenceFrame
450
- name : {self.name}
451
- reference : {self.ref.name}
452
- rot_config : {self.rot_config}
453
- links : {[key.name for key in self.linkedTo.keys()]}
454
- transformation:
455
- [{np.round(self.transformation[0], 3)}
456
- {np.round(self.transformation[1], 3)}
457
- {np.round(self.transformation[2], 3)}
458
- {np.round(self.transformation[3], 3)}]
459
- translation : {np.round(self.getTranslationVector(), 3)}
460
- rotation : {np.round(self.getRotationVector(), 3)}"""
461
- )
462
- return msg
463
-
464
- @deprecate(
465
- reason=(
466
- "I do not see the added value of changing the name and "
467
- "the current method has the side effect to change the name "
468
- "to a random string when the name argument is already used."
469
- ),
470
- alternative="the constructor argument to set the name already of the object.",
471
- )
472
- def setName(self, name=None):
473
- """
474
- Set or change the name of a reference frame.
475
-
476
- ..note: this method is deprecated
477
-
478
- :param str name: the new name for the reference frame, if None, a random name will be generated.
479
-
480
- :raises InvalidOperationError: when you try to change the name of the Master reference frame
481
- """
482
- if self.isMaster():
483
- raise InvalidOperationError(
484
- "You try to change the name of the Master reference frame, which is not allowed."
485
- )
486
- self.name = self.__createName(name)
487
-
488
- def addLink(self, ref, transformation=None, _stop=False):
489
- """
490
- adds a link between self and ref in self.linkedTo and ref.linkedTo
491
- """
492
-
493
- # DONE: set the inverse transformation in the ref to this
494
- # ref.linkedTo[self] = t3add.affine_inverse(transformation)
495
- # TODO:
496
- # remove the _stop keyword
497
-
498
- # TODO: deprecate transformation as an input variable
499
- # linkedTo can become a list of reference frames, with no transformation
500
- # associated to the link. The tfo associated to a link is already
501
- # checked in real time whenever the link is addressed
502
- if transformation is None:
503
- transformation = self.getActiveTransformationTo(ref)
504
- else:
505
- if DEBUG:
506
- LOGGER.info(
507
- "Deprecation warning: transformation will be automatically set to "
508
- "the current relation between {self.name} and {ref.name}"
509
- )
510
- LOGGER.debug("Requested:")
511
- LOGGER.debug(np.round(transformation, decimals=3))
512
- LOGGER.debug("Auto (enforced):")
513
-
514
- transformation = self.getActiveTransformationTo(ref)
515
-
516
- DEBUG and LOGGER.debug(np.round(transformation, decimals=3))
517
-
518
- self.linkedTo[ref] = transformation
519
-
520
- # TODO simplify this when transformation is deprecated
521
- # it becomes ref.linkedTo[self] = ref.getActiveTransformationTo(self)
522
- ref.linkedTo[self] = t3add.affine_inverse(transformation)
523
-
524
- def removeLink(self, ref):
525
- """
526
- Remove the link between self and ref, both ways.
527
- """
528
-
529
- # First remove the entry in ref to this
530
-
531
- if self in ref.linkedTo:
532
- del ref.linkedTo[self]
533
-
534
- # Then remove the entry in this to ref
535
-
536
- if ref in self.linkedTo:
537
- del self.linkedTo[ref]
538
-
539
- def getPassiveTransformationTo(self, targetFrame):
540
- """
541
- getPassiveTransformationTo(self,targetFrame)
542
- == getPointTransformationTo(self,targetFrame)
543
-
544
- returns the transformation to apply to a Point (defined in self) to express it in targetFrame
545
-
546
- Passive transformation : the point is static, we change the reference frame around it
547
- """
548
- DEBUG and LOGGER.debug("PASSIVE TO self {self.name} target {targetFrame.name}")
549
- if targetFrame is self:
550
- """
551
- Nothing to do here, we already have the right coordinates
552
- """
553
- DEBUG and LOGGER.debug("case 1")
554
- result = np.identity(4)
555
-
556
- elif targetFrame.ref is self:
557
- """
558
- The target frame is defined in self => the requested transformation is the targetFrame definition
559
- """
560
- DEBUG and LOGGER.debug("=== 2 start ===")
561
- result = t3add.affine_inverse(targetFrame.transformation)
562
- DEBUG and LOGGER.debug("=== 2 end ===")
563
- elif targetFrame.ref is self.ref:
564
- """
565
- targetFrame and self are defined wrt the same reference frame
566
- We want
567
- self --> targetFrame
568
- We know
569
- targetFrame.ref --> targetFrame (= targetFrame.transformation)
570
- self.ref --> self (= self.transformation)
571
- That is
572
- self --> self.ref is targetFrame.ref --> targetFrame
573
- inverse(definition) targetFrame definition
574
-
575
- """
576
- if DEBUG:
577
- LOGGER.debug("=== 3 start ===")
578
- LOGGER.debug(" ref \n{0}".format(self.ref))
579
- LOGGER.debug("===")
580
- LOGGER.debug("self \n{0}".format(self))
581
- LOGGER.debug("===")
582
- LOGGER.debug("targetFrame \n{0}".format(targetFrame))
583
- LOGGER.debug("===")
584
-
585
- selfToRef = self.transformation
586
- DEBUG and LOGGER.debug("selfToRef \n{0}".format(selfToRef))
587
-
588
- # refToRef = I
589
-
590
- refToTarget = t3add.affine_inverse(targetFrame.transformation)
591
- DEBUG and LOGGER.debug("refToTarget \n{0}".format(refToTarget))
592
-
593
- result = np.dot(refToTarget, selfToRef)
594
- DEBUG and LOGGER.debug("result \n{0}".format(result))
595
- DEBUG and LOGGER.debug("=== 3 end ===")
596
- else:
597
- """
598
- We are after the transformation from
599
- self --> targetFrame
600
- ==
601
- self --> self.ref --> targetFrame.ref --> targetFrame
602
-
603
- We know
604
- targetFrame.ref --> targetFrame (targetFrame.transformation)
605
- self.ref --> self (self.transformation)
606
- but
607
- targetFrame.ref != self.ref
608
- so we need
609
- self.ref --> targetFrame.ref
610
- then we can compose
611
- self --> self.ref --> targetFrame.ref --> targetFrame
612
-
613
- Note: the transformation self.ref --> targetFrame.ref is acquired recursively
614
- This relies on the underlying assumption that there exists
615
- one unique reference frame that source and self can be linked to
616
- (without constraints on the number of links necessary), i.e.
617
- that, from a frame to its reference or the opposite, there exists
618
- a path between self and targetFrame. That is equivalent to
619
- the assumption that the entire set of reference frames is connex,
620
- i.e. defined upon a unique master reference frame.
621
- """
622
- DEBUG and LOGGER.debug("=== 4 start ===")
623
- selfToRef = self.transformation
624
- selfRefToTargetRef = self.ref.getPassiveTransformationTo(targetFrame.ref)
625
- refToTarget = t3add.affine_inverse(targetFrame.transformation)
626
- result = np.dot(refToTarget, np.dot(selfRefToTargetRef, selfToRef))
627
- DEBUG and LOGGER.debug("=== 4 end ===")
628
-
629
- return result
630
-
631
- def getPassiveTranslationRotationVectorsTo(self, targetFrame, degrees=True): # , active=_ACTIVE_DEFAULT):
632
- """
633
- getPassiveTranslationRotationVectorsTo(self,ref,degrees=True)
634
-
635
- extracts rotation vector from the result of getPassiveTransformationTo(target)
636
- """
637
- transformation = self.getPassiveTransformationTo(targetFrame)
638
- rotation = t3.euler.mat2euler(transformation, axes=self.rot_config)
639
- if degrees:
640
- rotation = np.array([np.rad2deg(item) for item in rotation])
641
- translation = transformation[:3, 3]
642
- return translation, rotation
643
-
644
- def getPassiveTranslationVectorTo(self, targetFrame, degrees=True):
645
- """
646
- getPassiveTranslationRotationVectorsTo(self,ref,degrees=True)
647
-
648
- extracts translation vector from the result of getPassiveTransformationTo(target)
649
- """
650
- return self.getPassiveTranslationRotationVectorsTo(targetFrame, degrees=degrees)[0]
651
-
652
- def getPassiveRotationVectorTo(self, targetFrame, degrees=True):
653
- """
654
- getPassiveTranslationRotationVectorsTo(self,targetFrame,degrees=True)
655
-
656
- extracts rotation vector from the result of getPassiveTransformationTo(targetFrame)
657
- """
658
- return self.getPassiveTranslationRotationVectorsTo(targetFrame, degrees=degrees)[1]
659
-
660
- def getPassiveTransformationFrom(self, source):
661
- """
662
- getPassiveTransformationFrom(self,source)
663
- == getPointTransformationTo(self,source)
664
-
665
- INPUT
666
- source : is a ReferenceFrame object
667
-
668
- OUTPUT
669
- returns the transformation matrix that, applied to a point defined
670
- in source returns its coordinates in self
671
- """
672
- DEBUG and LOGGER.debug("PASSIVE FROM self {self.name} source {source.name}")
673
- return source.getPassiveTransformationTo(self)
674
-
675
- def getPassiveTranslationRotationVectorsFrom(self, source, degrees=True): # , active=_ACTIVE_DEFAULT):
676
- """
677
- getPassiveTranslationRotationVectorsFrom(self,source, degrees=True)
678
-
679
- extracts rotation vector from the result of getPassiveTransformationTo(target)
680
- """
681
- transformation = self.getPassiveTransformationFrom(source)
682
- rotation = t3.euler.mat2euler(transformation, axes=self.rot_config)
683
- if degrees:
684
- rotation = np.array([np.rad2deg(item) for item in rotation])
685
- translation = transformation[:3, 3]
686
- return translation, rotation
687
-
688
- def getPassiveTranslationVectorFrom(self, source, degrees=True):
689
- """
690
- getPassiveTranslationVectorFrom(self,source, degrees=True)
691
-
692
- extracts translation vector from the result of getPassiveTransformationFrom(source)
693
- """
694
- return self.getPassiveTranslationRotationVectorsFrom(source, degrees=degrees)[0]
695
-
696
- def getPassiveRotationVectorFrom(self, source, degrees=True):
697
- """
698
- getPassiveTranslationRotationVectorsFrom(self,source,degrees=True)
699
-
700
- extracts rotation vector from the result of getPassiveTransformationFrom(source)
701
- """
702
- return self.getPassiveTranslationRotationVectorsFrom(source, degrees=degrees)[1]
703
-
704
- def getActiveTransformationTo(self, target):
705
- """
706
- Return the transformation matrix from this reference frame (``self``) to
707
- the target reference frame.
708
-
709
- Applying this transformation to the ``self`` ReferenceFrame would render it
710
- identical to target.
711
-
712
- Applying this transformation to a point defined in ``self`` would move it to
713
- the same coordinates in target.
714
-
715
- :param target: is a ReferenceFrame object
716
-
717
- :return: the transformation matrix that defines the reference frame ``target``
718
- in ``self``, the current reference frame. The transformation from self
719
- to target
720
-
721
- """
722
- DEBUG and LOGGER.debug("ACTIVE TO self {self.name} target {target.name}")
723
- return target.getPassiveTransformationTo(self)
724
-
725
- def getActiveTranslationRotationVectorsTo(self, targetFrame, degrees=True): # ,active=_ACTIVE_DEFAULT):
726
- """
727
- getActiveTranslationRotationVectorsTo(self,ref,degrees=True)
728
-
729
- extracts rotation vector from the result of getActiveTransformationTo(target)
730
- """
731
- transformation = self.getActiveTransformationTo(targetFrame)
732
- rotation = t3.euler.mat2euler(transformation, axes=self.rot_config)
733
- if degrees:
734
- rotation = np.array([np.rad2deg(item) for item in rotation])
735
- translation = transformation[:3, 3]
736
- return translation, rotation
737
-
738
- def getActiveTranslationVectorTo(self, targetFrame, degrees=True):
739
- """
740
- getActiveTranslationRotationVectorsTo(self,ref,degrees=True)
741
-
742
- extracts translation vector from the result of getActiveTransformationTo(target)
743
- """
744
- return self.getActiveTranslationRotationVectorsTo(targetFrame, degrees=degrees)[0]
745
-
746
- def getActiveRotationVectorTo(self, targetFrame, degrees=True):
747
- """
748
- getActiveTranslationRotationVectorsTo(self,targetFrame,degrees=True)
749
-
750
- extracts rotation vector from the result of getActiveTransformationTo(targetFrame)
751
- """
752
- return self.getActiveTranslationRotationVectorsTo(targetFrame, degrees=degrees)[1]
753
-
754
- def getActiveTransformationFrom(self, source):
755
- """
756
- Applying this transformation to the ``source`` ReferenceFrame
757
- would render it identical to self.
758
-
759
- Applying this transformation to a point defined in source
760
- would move it to the same coordinates in self.
761
-
762
- :param source: is a ReferenceFrame object
763
-
764
- :return: the transformation matrix that defines this reference frame in ``source``,
765
- i.e. the transformation from ``source`` to ``self``
766
-
767
- """
768
- DEBUG and LOGGER.debug("ACTIVE FROM self {self.name} source {source.name}")
769
- return self.getPassiveTransformationTo(source)
770
-
771
- def getActiveTranslationRotationVectorsFrom(self, source, degrees=True): # ,active=_ACTIVE_DEFAULT):
772
- """
773
- getActiveTranslationRotationVectorsFrom(self,source, degrees=True)
774
-
775
- extracts rotation vector from the result of getActiveTransformationTo(target)
776
- """
777
- transformation = self.getActiveTransformationFrom(source)
778
- rotation = t3.euler.mat2euler(transformation, axes=self.rot_config)
779
- if degrees:
780
- rotation = np.array([np.rad2deg(item) for item in rotation])
781
- translation = transformation[:3, 3]
782
- return translation, rotation
783
-
784
- def getActiveTranslationVectorFrom(self, source, degrees=True):
785
- """
786
- getActiveTranslationVectorFrom(self,source, degrees=True)
787
-
788
- extracts translation vector from the result of getActiveTransformationFrom(source)
789
- """
790
- return self.getActiveTranslationRotationVectorsFrom(source, degrees=degrees)[0]
791
-
792
- def getActiveRotationVectorFrom(self, source, degrees=True):
793
- """
794
- getActiveTranslationRotationVectorsFrom(self,source,degrees=True)
795
-
796
- extracts rotation vector from the result of getActiveTransformationFrom(source)
797
- """
798
- return self.getActiveTranslationRotationVectorsFrom(source, degrees=degrees)[1]
799
-
800
- def _findEnds(self, frame, visited=[], ends=[], verbose=True, level=1):
801
- """
802
- PURPOSE
803
- Identify the 'linked_frames':
804
- frames that are linked, either directly or indirectly (via mult. links) to "frame"
805
- --> returned as visited
806
- Identify subset of 'linked_frames of which the reference does not belong to linked_frames
807
- --> returned as 'finalEnds'
808
- """
809
- DEBUG and LOGGER.debug(
810
- f"{level:-2d}{2 * level * ' '} Current: {frame.name} -- ends: {[f.name for f in ends]} -- visited {[f.name for f in visited]}"
811
- )
812
- # if verbose: print (f"{level:-2d}{2*level*' '} Current: {frame.name} -- ends: {[f.name for f in ends]} -- visited {[f.name for f in visited]}")
813
-
814
- # Establish the set of 'linked_frames' (variable 'visited')
815
- # The recursive process below keeps unwanted (non-endFrames), namely the
816
- # frames that are not directly, but well indirectly linked to their reference
817
- # This case is solved further down
818
- if frame not in visited:
819
- visited.append(frame)
820
- if verbose and level:
821
- level += 1
822
- if frame.ref not in frame.linkedTo:
823
- ends.append(frame)
824
- DEBUG and LOGGER.debug(f"{(10 + 2 * level) * ' '}{frame.name}: new end")
825
- # if verbose: LOGGER.info(f"{(10+2*level)*' '}{frame.name}: new end")
826
- for linkedFrame in frame.linkedTo:
827
- ends, visited = self._findEnds(linkedFrame, visited=visited, ends=ends, verbose=verbose, level=level)
828
-
829
- # If frame.ref was linked to frame via an indirect route, reject it
830
- finalEnds = []
831
- for aframe in ends:
832
- if aframe.ref not in ends:
833
- finalEnds.append(aframe)
834
- return finalEnds, visited
835
-
836
- def setTransformation(self, transformation, updated=None, preserveLinks=True, _relative=False, verbose=True):
837
- """
838
- setTransformation(self,transformation, updated=None, preserveLinks=True,_relative=False, verbose=True)
839
-
840
- Alter the definition of this coordinate system
841
-
842
- If other systems are linked to this one, their definition must be updated accordingly
843
- The link set between two ref. Frames A & B is the active transformation matrix from A to B
844
- A.addLink(B, matrix)
845
- A.getActiveTransformationTo(B) --> matrix
846
-
847
- The way to update the definition of the present system, and of those linked to it
848
- depends on the structure of those links.
849
-
850
- We define
851
- - the target frame as the one we want to move / redefine
852
- - 'linkedFrames' as those directly, or indirectly (i.e. via multiple links)
853
- linked to the target frame
854
- - endFrames as the subset of linkedFrames which are not linked to their reference (directly or indirectly)
855
- - sideFrames as the set of frames whose reference is a linkedFrame, but not themselves belonging to the linkedFrames
856
-
857
- We can demonstrate that updating the endFrames (Block A below) is sufficient to represent
858
- the movement of the target frame and all frames directly or indirectly linked to it.
859
-
860
- This may nevertheless have perverse effects for sideFrames. Indeed,
861
- their reference will (directly or implicitely) be redefined, but they shouldn't:
862
- they are not linked to their reference --> their location in space (e.g. wrt the master frame)
863
- should not be affected by the movement of the target frame. This is the aim of block B.
864
-
865
- For a completely robust solution, 2 steps must be taken
866
- BLOCK A. apply the rigt transformation to all "endFrames"
867
- BLOCK B. Check for frames
868
- using any of the "visited" frames as a reference
869
- not linked to its reference
870
- Correct its so that it doesn't move (it shouldn't be affected by the requested movement)
871
- This demands a "referenceFor" array property
872
-
873
- """
874
- # Ruthless, enforced redefinition of one system. Know what you do, or stay away.
875
- # Semi-unpredictible side effets if the impacted frame has links!
876
- if preserveLinks == False:
877
- self.transformation = transformation
878
- return
879
-
880
- if updated is None:
881
- updated = []
882
-
883
- # visitedFrames = all frames which can be reached from self via invariant links
884
- # endFrames = subset of visitedFrames that are at the end of a chain, and must be updated
885
- # in order to properly represent the requested movement
886
- endFrames, visitedFrames = self._findEnds(frame=self, visited=[], ends=[], verbose=verbose)
887
- if verbose:
888
- LOGGER.info(f"Visited sub-system {[f.name for f in visitedFrames]}")
889
- LOGGER.info(f"End-frames (movement necessary) {[f.name for f in endFrames]}")
890
-
891
- # All updates are done by relative movements
892
- # so we must first compute the relative movement corresponding to the requested absolute movement
893
- if _relative == False:
894
- ## virtual = what self should become after the (absolute) movement
895
- ## it allows to compute the relative transformation to be applied and work in relative further down
896
- virtual = ReferenceFrame(transformation, ref=self.ref, name="virtual", rot_config=self.rot_config)
897
- request = self.getActiveTransformationTo(virtual)
898
- del virtual
899
- else:
900
- # If this method is called by applyTransformation,
901
- # we are facing a request for a relative movement
902
- # In that case the input is directly what we want
903
- request = transformation
904
-
905
- # BLOCK B. Check for frames that were impacted but shouldn't have been and correct them
906
- # B1. List of frames demanding a correction
907
- # 'impacted' are frames having their reference inside the rigid structure moving, but not linked to it
908
- # If nothing is done, the movement will implicitely displace them, which is not intended
909
-
910
- ### Impacted shall not contain frames that are linked to self (== to any frame in visitedFrames) via any route...
911
- ### We check if the impacted frames are in visitedFrames:
912
- ### it is enough to know it's connected to the entire 'solid body' in which self belongs
913
- impacted = []
914
- for frame in visitedFrames:
915
- for child in frame.referenceFor:
916
- # Version 1 : too simple (restores too many frames)
917
- # if child not in frame.linkedTo:
918
-
919
- # Version 2 : overkill
920
- # child_ends, child_visited = child._findEnds(frame=child,visited=[],ends=[],verbose=verbose)
921
- # if frame not in child_visited:
922
-
923
- # Version 3 : just check if the child belongs to the rigid structure...
924
- if child not in visitedFrames:
925
- impacted.append(child)
926
-
927
- DEBUG and LOGGER.debug(f"Impacted (not moving, defined in moving) {[f.name for f in impacted]}")
928
-
929
- # B2. save the location of all impacted frames
930
- # tempReference has the only purpose of avoiding that every frame must know the master
931
- # It could be any frame without links and defined wrt the master, but the master isn't known here...
932
- # TODO : confirm that the master isn't known (e.g. via cls._MASTER)
933
- tempMaster = self.findMaster()
934
- toRestore = {}
935
- for frame in impacted:
936
- toRestore[frame] = ReferenceFrame(
937
- frame.getActiveTransformationFrom(tempMaster),
938
- ref=tempMaster,
939
- name=frame.name + "toRestore",
940
- rot_config=frame.rot_config,
941
- )
942
-
943
- # BLOCK A. apply the rigt transformation to all "endFrames"
944
- """
945
- ### Ensure that "Untouched" remains unaffected regardless of the update order of the endFrames
946
- selfUntouched = ReferenceFrame(
947
- transformation = self.getActiveTransformationFrom(tempMaster),
948
- ref=tempMaster,
949
- name=self.name + "_fixed",
950
- rot_config=self.rot_config,
951
- )
952
- """
953
-
954
- selfUntouched = ReferenceFrame(
955
- transformation=self.transformation,
956
- ref=self.ref,
957
- name=self.name + "_fixed",
958
- rot_config=self.rot_config,
959
- )
960
-
961
- for bottom in endFrames:
962
- up = bottom.getActiveTransformationTo(selfUntouched)
963
- down = selfUntouched.getActiveTransformationTo(bottom)
964
-
965
- relativeTransformation = up @ request @ down
966
-
967
- if DEBUG:
968
- LOGGER.debug(f"\nAdjusting {bottom.name} to {self.name}\nUpdated {[i.name for i in updated]}")
969
- LOGGER.debug(f"\ninput transformation \n{np.round(transformation, 3)}")
970
- LOGGER.debug(
971
- f"\nup \n{np.round(up, 3)}\ntransformation\n{np.round(request, 3)}\ndown\n{np.round(down, 3)}"
972
- )
973
- LOGGER.debug(f"\nrelativeTransformation \n{np.round(relativeTransformation, 3)}")
974
-
975
- bottom.transformation = bottom.transformation @ relativeTransformation
976
-
977
- updated.append(bottom)
978
-
979
- for frame in visitedFrames:
980
- if frame not in updated:
981
- updated.append(frame)
982
-
983
- # Block B
984
- # B3. Correction
985
- # we must set preserveLinks to False to prevent cascading impact from this update
986
- # if X1 is impacted with
987
- # X1.ref = E1 X1 --> X2 (simple link) E2.ref = X2
988
- # where X1 and X2 are "external frames" and E1 and E2 are "endFrames" that will hence move
989
- # X1 was impacted by the move of E1, but X2 wasn't
990
- # ==> wrt master, neither X1 nor X2 should have moved, but X1 did (via its ref)
991
- # and hence its link with X2 is now corrupt
992
- # We need to move X1 back to its original location wrt master
993
- # if we preserved the links while doing that,
994
- # we will move X2, which shouldn't move
995
- # (it didn't have to, it didn't and the goal is to restore the validity of the links)
996
- #
997
- # Direct restoration or the impacted frames at their original location
998
-
999
- for frame in toRestore:
1000
- frame.transformation = frame.ref.getActiveTransformationTo(toRestore[frame])
1001
-
1002
- del toRestore
1003
-
1004
- return
1005
-
1006
- def setTranslationRotation(
1007
- self,
1008
- translation,
1009
- rotation,
1010
- rot_config=_ROT_CONFIG_DEFAULT,
1011
- active=_ACTIVE_DEFAULT,
1012
- degrees=True,
1013
- preserveLinks=True,
1014
- ):
1015
- """
1016
- setTranslationRotation(self,translation,rotation,rot_config=_ROT_CONFIG_DEFAULT, active=_ACTIVE_DEFAULT, degrees=True, preserveLinks=True)
1017
-
1018
- Same as setTransformation, but input = translation and rotation vectors rather than affine transformation matrix
1019
- """
1020
- # Translation
1021
- translation = np.array(translation)
1022
- # Zoom - unit
1023
- zdef = np.array([1, 1, 1])
1024
- # Shear
1025
- sdef = np.array([0, 0, 0])
1026
- # Rotation
1027
- if degrees:
1028
- rotation = np.array([np.deg2rad(item) for item in rotation])
1029
-
1030
- rotx, roty, rotz = rotation
1031
-
1032
- rmat = RotationMatrix(rotx, roty, rotz, rot_config=rot_config, active=active)
1033
-
1034
- DEBUG and LOGGER.debug(t3.affines.compose(translation, rmat.R, Z=zdef, S=sdef))
1035
-
1036
- transformation = t3.affines.compose(translation, rmat.R, Z=zdef, S=sdef)
1037
-
1038
- self.setTransformation(transformation, preserveLinks=preserveLinks, _relative=False)
1039
- return
1040
-
1041
- def applyTransformation(self, transformation, updated=None, preserveLinks=True):
1042
- """
1043
- applyTransformation(self,transformation)
1044
-
1045
- Applies the transformation to the current reference frame's definition
1046
-
1047
- self.transformation := transformation @ self.transformation
1048
- """
1049
- if updated is None:
1050
- updated = []
1051
-
1052
- self.setTransformation(
1053
- transformation=transformation,
1054
- updated=updated,
1055
- preserveLinks=preserveLinks,
1056
- _relative=True,
1057
- )
1058
-
1059
- def applyTranslationRotation(
1060
- self,
1061
- translation,
1062
- rotation,
1063
- rot_config=None,
1064
- active=_ACTIVE_DEFAULT,
1065
- degrees=True,
1066
- preserveLinks=True,
1067
- ):
1068
- """
1069
- applyTranslationRotation(self,translation,rotation,rot_config=None,active=_ACTIVE_DEFAULT,degrees=True, preserveLinks=True)
1070
-
1071
- Builds transformation from input translation and rotation, then applies this transformation
1072
- """
1073
- if rot_config is None:
1074
- rot_config = self.rot_config
1075
-
1076
- # Translation
1077
- translation = np.array(translation)
1078
- # Zoom - unit
1079
- zdef = np.array([1, 1, 1])
1080
- # Shear
1081
- sdef = np.array([0, 0, 0])
1082
- # Rotation
1083
- if degrees:
1084
- rotation = np.array([np.deg2rad(item) for item in rotation])
1085
- rotx, roty, rotz = rotation
1086
- #
1087
- rmat = RotationMatrix(rotx, roty, rotz, rot_config=rot_config, active=active)
1088
- #
1089
- transformation = t3.affines.compose(translation, rmat.R, Z=zdef, S=sdef)
1090
- #
1091
- self.applyTransformation(transformation, preserveLinks=preserveLinks)
1092
- return
1093
-
1094
- def getAxis(self, axis, name=None):
1095
- """
1096
- INPUT
1097
- axis : in ['x','y','z']
1098
-
1099
- OUTPUT
1100
- Returns an object of class Point, corresponding to the vector defining
1101
- the axis of choice in self.
1102
- The output can be used with the Point methods to express that axis in any reference frame
1103
- """
1104
- haxis = {}
1105
- haxis["x"] = [1, 0, 0]
1106
- haxis["y"] = [0, 1, 0]
1107
- haxis["z"] = [0, 0, 1]
1108
- if name is None:
1109
- name = self.name + axis
1110
- return Point(haxis[axis], ref=self, name=name)
1111
-
1112
- def getNormal(self, name=None):
1113
- """
1114
- getNormal(self,name=None)
1115
-
1116
- Returns a unit vector normal to the X-Y plane (= [0,0,1] = getAxis('z'))
1117
- """
1118
- return Point([0, 0, 1], ref=self, name=name)
1119
-
1120
- def getOrigin(self, name=None):
1121
- """
1122
- OUTPUT
1123
- Returns an object of class Point, corresponding to the vector defining the origin in 'self', i.e. [0,0,0]
1124
- The output can be used with the Point methods to express that axis in any reference frame
1125
- """
1126
- return Point([0, 0, 0], ref=self, name=name)
1127
-
1128
- def is_master(self):
1129
- return self.isMaster()
1130
-
1131
- def isMaster(self):
1132
- """
1133
- A Master reference frame is a reference frame that refers to itself, and the
1134
- transformation is the Identity matrix.
1135
- """
1136
- tr = self.transformation
1137
-
1138
- if (self.name == self.ref.name) and (tr.shape[0] == tr.shape[1]) and np.allclose(tr, np.eye(tr.shape[0])):
1139
- return True
1140
- return False
1141
-
1142
- def isSame(self, other):
1143
- """
1144
- Returns True if the two reference frames are the same except for their name.
1145
-
1146
- Two Reference Frames are considered the same when:
1147
-
1148
- * their transformation matrices are equal
1149
- * the reference frame is equal
1150
- * the rot_config is equal
1151
- * the name may be different
1152
-
1153
- .. todo:: This needs further work and testing!
1154
- """
1155
-
1156
- if other is self:
1157
- DEBUG and LOGGER.debug(
1158
- "self and other are the same object (beware: this message might occur with recursion from self.ref != self.other)"
1159
- )
1160
- return True
1161
-
1162
- if isinstance(other, ReferenceFrame):
1163
- DEBUG and LOGGER.debug(f"comparing {self.name} and {other.name}")
1164
- if not np.array_equal(self.transformation, other.transformation):
1165
- DEBUG and LOGGER.debug("self.transformation not equals other.transformation")
1166
- return False
1167
- if self.rot_config != other.rot_config:
1168
- DEBUG and LOGGER.debug("self.rot_config not equals other.rot_config")
1169
- return False
1170
- # The following tests are here to prevent recursion to go infinite when self and other
1171
- # point to itself
1172
- if self.ref is self and other.ref is other:
1173
- DEBUG and LOGGER.debug("both self.ref and other.ref point to themselves")
1174
- pass
1175
- else:
1176
- DEBUG and LOGGER.debug("one of self.ref or other.ref doesn't points to itself")
1177
- if self.ref != other.ref:
1178
- DEBUG and LOGGER.debug("self.ref not equals other.ref")
1179
- return False
1180
- if self.name is not other.name:
1181
- DEBUG and LOGGER.debug(
1182
- f"When checking two reference frames for equality, only their names differ: '{self.name}' not equals '{other.name}'"
1183
- )
1184
- pass
1185
- return True
1186
- return NotImplemented
1187
-
1188
- def __eq__(self, other):
1189
- """
1190
- Overrides the default implementation, which basically checks for id(self) == id(other).
1191
-
1192
- Two Reference Frames are considered equal when:
1193
-
1194
- * their transformation matrices are equal
1195
- * the reference frame is equal
1196
- * the rot_config is equal
1197
- * do we want to insist on the name being equal?
1198
- YES - for strict testing
1199
- NO - this might need a new method like isSame(self, other) where the criteria are relaxed
1200
-
1201
-
1202
- .. todo:: This needs further work and testing!
1203
- """
1204
-
1205
- if other is self:
1206
- DEBUG and LOGGER.debug(
1207
- "self and other are the same object (beware: this message might occur with recursion from self.ref != self.other)"
1208
- )
1209
- return True
1210
-
1211
- if isinstance(other, ReferenceFrame):
1212
- DEBUG and LOGGER.debug(f"comparing {self.name} and {other.name}")
1213
- if not np.array_equal(self.transformation, other.transformation):
1214
- DEBUG and LOGGER.debug("self.transformation not equals other.transformation")
1215
- return False
1216
- if self.rot_config != other.rot_config:
1217
- DEBUG and LOGGER.debug("self.rot_config not equals other.rot_config")
1218
- return False
1219
- # The following tests are here to prevent recursion to go infinite when self and other
1220
- # point to itself
1221
- if self.ref is self and other.ref is other:
1222
- DEBUG and LOGGER.debug("both self.ref and other.ref point to themselves")
1223
- pass
1224
- else:
1225
- DEBUG and LOGGER.debug("one of self.ref or other.ref doesn't points to itself")
1226
- if self.ref != other.ref:
1227
- DEBUG and LOGGER.debug("self.ref not equals other.ref")
1228
- return False
1229
- if self.name is not other.name:
1230
- DEBUG and LOGGER.debug(
1231
- f"When checking two reference frames for equality, only their names differ: '{self.name}' not equals '{other.name}'"
1232
- )
1233
- return False
1234
- return True
1235
- return NotImplemented
1236
-
1237
- def __hash__(self):
1238
- """Overrides the default implementation"""
1239
- hash_number = (id(self.rot_config) + id(self.ref) + id(self.name)) // 16
1240
- return hash_number
1241
-
1242
- def __copy__(self):
1243
- DEBUG and LOGGER.debug(
1244
- f'Copying {self!r} unless {self.name} is "Master" in which case the Master itself is returned.'
1245
- )
1246
-
1247
- if self.isMaster():
1248
- DEBUG and LOGGER.debug(f"Returning Master itself instead of a copy.")
1249
- return self
1250
-
1251
- return ReferenceFrame(self.transformation, self.ref, self.name, self.rot_config)