1///////////////////////////////////////////////////////////////////////////
2//
3// Copyright (c) 2004-2012, Industrial Light & Magic, a division of Lucas
4// Digital Ltd. LLC
5//
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are
10// met:
11// * Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// * Redistributions in binary form must reproduce the above
14// copyright notice, this list of conditions and the following disclaimer
15// in the documentation and/or other materials provided with the
16// distribution.
17// * Neither the name of Industrial Light & Magic nor the names of
18// its contributors may be used to endorse or promote products derived
19// from this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33///////////////////////////////////////////////////////////////////////////
34
35
36
37#ifndef INCLUDED_IMATHSHEAR_H
38#define INCLUDED_IMATHSHEAR_H
39
40//----------------------------------------------------
41//
42// Shear6 class template.
43//
44//----------------------------------------------------
45
46#include "ImathExc.h"
47#include "ImathLimits.h"
48#include "ImathMath.h"
49#include "ImathVec.h"
50#include "ImathNamespace.h"
51#include <iostream>
52
53
54IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
55
56template <class T> class Shear6
57{
58 public:
59
60 //-------------------
61 // Access to elements
62 //-------------------
63
64 T xy, xz, yz, yx, zx, zy;
65
66 T & operator [] (int i);
67 const T & operator [] (int i) const;
68
69
70 //-------------
71 // Constructors
72 //-------------
73
74 Shear6 (); // (0 0 0 0 0 0)
75 Shear6 (T XY, T XZ, T YZ); // (XY XZ YZ 0 0 0)
76 Shear6 (const Vec3<T> &v); // (v.x v.y v.z 0 0 0)
77 template <class S> // (v.x v.y v.z 0 0 0)
78 Shear6 (const Vec3<S> &v);
79 Shear6 (T XY, T XZ, T YZ, // (XY XZ YZ YX ZX ZY)
80 T YX, T ZX, T ZY);
81
82
83 //---------------------------------
84 // Copy constructors and assignment
85 //---------------------------------
86
87 Shear6 (const Shear6 &h);
88 template <class S> Shear6 (const Shear6<S> &h);
89
90 const Shear6 & operator = (const Shear6 &h);
91 template <class S>
92 const Shear6 & operator = (const Vec3<S> &v);
93
94 //------------
95 // Destructor
96 //------------
97
98 ~Shear6() = default;
99
100 //----------------------
101 // Compatibility with Sb
102 //----------------------
103
104 template <class S>
105 void setValue (S XY, S XZ, S YZ, S YX, S ZX, S ZY);
106
107 template <class S>
108 void setValue (const Shear6<S> &h);
109
110 template <class S>
111 void getValue (S &XY, S &XZ, S &YZ,
112 S &YX, S &ZX, S &ZY) const;
113
114 template <class S>
115 void getValue (Shear6<S> &h) const;
116
117 T * getValue();
118 const T * getValue() const;
119
120
121 //---------
122 // Equality
123 //---------
124
125 template <class S>
126 bool operator == (const Shear6<S> &h) const;
127
128 template <class S>
129 bool operator != (const Shear6<S> &h) const;
130
131 //-----------------------------------------------------------------------
132 // Compare two shears and test if they are "approximately equal":
133 //
134 // equalWithAbsError (h, e)
135 //
136 // Returns true if the coefficients of this and h are the same with
137 // an absolute error of no more than e, i.e., for all i
138 //
139 // abs (this[i] - h[i]) <= e
140 //
141 // equalWithRelError (h, e)
142 //
143 // Returns true if the coefficients of this and h are the same with
144 // a relative error of no more than e, i.e., for all i
145 //
146 // abs (this[i] - h[i]) <= e * abs (this[i])
147 //-----------------------------------------------------------------------
148
149 bool equalWithAbsError (const Shear6<T> &h, T e) const;
150 bool equalWithRelError (const Shear6<T> &h, T e) const;
151
152
153 //------------------------
154 // Component-wise addition
155 //------------------------
156
157 const Shear6 & operator += (const Shear6 &h);
158 Shear6 operator + (const Shear6 &h) const;
159
160
161 //---------------------------
162 // Component-wise subtraction
163 //---------------------------
164
165 const Shear6 & operator -= (const Shear6 &h);
166 Shear6 operator - (const Shear6 &h) const;
167
168
169 //------------------------------------
170 // Component-wise multiplication by -1
171 //------------------------------------
172
173 Shear6 operator - () const;
174 const Shear6 & negate ();
175
176
177 //------------------------------
178 // Component-wise multiplication
179 //------------------------------
180
181 const Shear6 & operator *= (const Shear6 &h);
182 const Shear6 & operator *= (T a);
183 Shear6 operator * (const Shear6 &h) const;
184 Shear6 operator * (T a) const;
185
186
187 //------------------------
188 // Component-wise division
189 //------------------------
190
191 const Shear6 & operator /= (const Shear6 &h);
192 const Shear6 & operator /= (T a);
193 Shear6 operator / (const Shear6 &h) const;
194 Shear6 operator / (T a) const;
195
196
197 //----------------------------------------------------------
198 // Number of dimensions, i.e. number of elements in a Shear6
199 //----------------------------------------------------------
200
201 static unsigned int dimensions() {return 6;}
202
203
204 //-------------------------------------------------
205 // Limitations of type T (see also class limits<T>)
206 //-------------------------------------------------
207
208 static T baseTypeMin() {return limits<T>::min();}
209 static T baseTypeMax() {return limits<T>::max();}
210 static T baseTypeSmallest() {return limits<T>::smallest();}
211 static T baseTypeEpsilon() {return limits<T>::epsilon();}
212
213
214 //--------------------------------------------------------------
215 // Base type -- in templates, which accept a parameter, V, which
216 // could be either a Vec2<T> or a Shear6<T>, you can refer to T as
217 // V::BaseType
218 //--------------------------------------------------------------
219
220 typedef T BaseType;
221};
222
223
224//--------------
225// Stream output
226//--------------
227
228template <class T>
229std::ostream & operator << (std::ostream &s, const Shear6<T> &h);
230
231
232//----------------------------------------------------
233// Reverse multiplication: scalar * Shear6<T>
234//----------------------------------------------------
235
236template <class S, class T> Shear6<T> operator * (S a, const Shear6<T> &h);
237
238
239//-------------------------
240// Typedefs for convenience
241//-------------------------
242
243typedef Vec3 <float> Shear3f;
244typedef Vec3 <double> Shear3d;
245typedef Shear6 <float> Shear6f;
246typedef Shear6 <double> Shear6d;
247
248
249
250
251//-----------------------
252// Implementation of Shear6
253//-----------------------
254
255template <class T>
256inline T &
257Shear6<T>::operator [] (int i)
258{
259 return (&xy)[i]; // NOSONAR - suppress SonarCloud bug report.
260}
261
262template <class T>
263inline const T &
264Shear6<T>::operator [] (int i) const
265{
266 return (&xy)[i]; // NOSONAR - suppress SonarCloud bug report.
267}
268
269template <class T>
270inline
271Shear6<T>::Shear6 ()
272{
273 xy = xz = yz = yx = zx = zy = 0;
274}
275
276template <class T>
277inline
278Shear6<T>::Shear6 (T XY, T XZ, T YZ)
279{
280 xy = XY;
281 xz = XZ;
282 yz = YZ;
283 yx = 0;
284 zx = 0;
285 zy = 0;
286}
287
288template <class T>
289inline
290Shear6<T>::Shear6 (const Vec3<T> &v)
291{
292 xy = v.x;
293 xz = v.y;
294 yz = v.z;
295 yx = 0;
296 zx = 0;
297 zy = 0;
298}
299
300template <class T>
301template <class S>
302inline
303Shear6<T>::Shear6 (const Vec3<S> &v)
304{
305 xy = T (v.x);
306 xz = T (v.y);
307 yz = T (v.z);
308 yx = 0;
309 zx = 0;
310 zy = 0;
311}
312
313template <class T>
314inline
315Shear6<T>::Shear6 (T XY, T XZ, T YZ, T YX, T ZX, T ZY)
316{
317 xy = XY;
318 xz = XZ;
319 yz = YZ;
320 yx = YX;
321 zx = ZX;
322 zy = ZY;
323}
324
325template <class T>
326inline
327Shear6<T>::Shear6 (const Shear6 &h)
328{
329 xy = h.xy;
330 xz = h.xz;
331 yz = h.yz;
332 yx = h.yx;
333 zx = h.zx;
334 zy = h.zy;
335}
336
337template <class T>
338template <class S>
339inline
340Shear6<T>::Shear6 (const Shear6<S> &h)
341{
342 xy = T (h.xy);
343 xz = T (h.xz);
344 yz = T (h.yz);
345 yx = T (h.yx);
346 zx = T (h.zx);
347 zy = T (h.zy);
348}
349
350template <class T>
351inline const Shear6<T> &
352Shear6<T>::operator = (const Shear6 &h)
353{
354 xy = h.xy;
355 xz = h.xz;
356 yz = h.yz;
357 yx = h.yx;
358 zx = h.zx;
359 zy = h.zy;
360 return *this;
361}
362
363template <class T>
364template <class S>
365inline const Shear6<T> &
366Shear6<T>::operator = (const Vec3<S> &v)
367{
368 xy = T (v.x);
369 xz = T (v.y);
370 yz = T (v.z);
371 yx = 0;
372 zx = 0;
373 zy = 0;
374 return *this;
375}
376
377template <class T>
378template <class S>
379inline void
380Shear6<T>::setValue (S XY, S XZ, S YZ, S YX, S ZX, S ZY)
381{
382 xy = T (XY);
383 xz = T (XZ);
384 yz = T (YZ);
385 yx = T (YX);
386 zx = T (ZX);
387 zy = T (ZY);
388}
389
390template <class T>
391template <class S>
392inline void
393Shear6<T>::setValue (const Shear6<S> &h)
394{
395 xy = T (h.xy);
396 xz = T (h.xz);
397 yz = T (h.yz);
398 yx = T (h.yx);
399 zx = T (h.zx);
400 zy = T (h.zy);
401}
402
403template <class T>
404template <class S>
405inline void
406Shear6<T>::getValue (S &XY, S &XZ, S &YZ, S &YX, S &ZX, S &ZY) const
407{
408 XY = S (xy);
409 XZ = S (xz);
410 YZ = S (yz);
411 YX = S (yx);
412 ZX = S (zx);
413 ZY = S (zy);
414}
415
416template <class T>
417template <class S>
418inline void
419Shear6<T>::getValue (Shear6<S> &h) const
420{
421 h.xy = S (xy);
422 h.xz = S (xz);
423 h.yz = S (yz);
424 h.yx = S (yx);
425 h.zx = S (zx);
426 h.zy = S (zy);
427}
428
429template <class T>
430inline T *
431Shear6<T>::getValue()
432{
433 return (T *) &xy;
434}
435
436template <class T>
437inline const T *
438Shear6<T>::getValue() const
439{
440 return (const T *) &xy;
441}
442
443template <class T>
444template <class S>
445inline bool
446Shear6<T>::operator == (const Shear6<S> &h) const
447{
448 return xy == h.xy && xz == h.xz && yz == h.yz &&
449 yx == h.yx && zx == h.zx && zy == h.zy;
450}
451
452template <class T>
453template <class S>
454inline bool
455Shear6<T>::operator != (const Shear6<S> &h) const
456{
457 return xy != h.xy || xz != h.xz || yz != h.yz ||
458 yx != h.yx || zx != h.zx || zy != h.zy;
459}
460
461template <class T>
462bool
463Shear6<T>::equalWithAbsError (const Shear6<T> &h, T e) const
464{
465 for (int i = 0; i < 6; i++)
466 if (!IMATH_INTERNAL_NAMESPACE::equalWithAbsError ((*this)[i], h[i], e))
467 return false;
468
469 return true;
470}
471
472template <class T>
473bool
474Shear6<T>::equalWithRelError (const Shear6<T> &h, T e) const
475{
476 for (int i = 0; i < 6; i++)
477 if (!IMATH_INTERNAL_NAMESPACE::equalWithRelError ((*this)[i], h[i], e))
478 return false;
479
480 return true;
481}
482
483
484template <class T>
485inline const Shear6<T> &
486Shear6<T>::operator += (const Shear6 &h)
487{
488 xy += h.xy;
489 xz += h.xz;
490 yz += h.yz;
491 yx += h.yx;
492 zx += h.zx;
493 zy += h.zy;
494 return *this;
495}
496
497template <class T>
498inline Shear6<T>
499Shear6<T>::operator + (const Shear6 &h) const
500{
501 return Shear6 (xy + h.xy, xz + h.xz, yz + h.yz,
502 yx + h.yx, zx + h.zx, zy + h.zy);
503}
504
505template <class T>
506inline const Shear6<T> &
507Shear6<T>::operator -= (const Shear6 &h)
508{
509 xy -= h.xy;
510 xz -= h.xz;
511 yz -= h.yz;
512 yx -= h.yx;
513 zx -= h.zx;
514 zy -= h.zy;
515 return *this;
516}
517
518template <class T>
519inline Shear6<T>
520Shear6<T>::operator - (const Shear6 &h) const
521{
522 return Shear6 (xy - h.xy, xz - h.xz, yz - h.yz,
523 yx - h.yx, zx - h.zx, zy - h.zy);
524}
525
526template <class T>
527inline Shear6<T>
528Shear6<T>::operator - () const
529{
530 return Shear6 (-xy, -xz, -yz, -yx, -zx, -zy);
531}
532
533template <class T>
534inline const Shear6<T> &
535Shear6<T>::negate ()
536{
537 xy = -xy;
538 xz = -xz;
539 yz = -yz;
540 yx = -yx;
541 zx = -zx;
542 zy = -zy;
543 return *this;
544}
545
546template <class T>
547inline const Shear6<T> &
548Shear6<T>::operator *= (const Shear6 &h)
549{
550 xy *= h.xy;
551 xz *= h.xz;
552 yz *= h.yz;
553 yx *= h.yx;
554 zx *= h.zx;
555 zy *= h.zy;
556 return *this;
557}
558
559template <class T>
560inline const Shear6<T> &
561Shear6<T>::operator *= (T a)
562{
563 xy *= a;
564 xz *= a;
565 yz *= a;
566 yx *= a;
567 zx *= a;
568 zy *= a;
569 return *this;
570}
571
572template <class T>
573inline Shear6<T>
574Shear6<T>::operator * (const Shear6 &h) const
575{
576 return Shear6 (xy * h.xy, xz * h.xz, yz * h.yz,
577 yx * h.yx, zx * h.zx, zy * h.zy);
578}
579
580template <class T>
581inline Shear6<T>
582Shear6<T>::operator * (T a) const
583{
584 return Shear6 (xy * a, xz * a, yz * a,
585 yx * a, zx * a, zy * a);
586}
587
588template <class T>
589inline const Shear6<T> &
590Shear6<T>::operator /= (const Shear6 &h)
591{
592 xy /= h.xy;
593 xz /= h.xz;
594 yz /= h.yz;
595 yx /= h.yx;
596 zx /= h.zx;
597 zy /= h.zy;
598 return *this;
599}
600
601template <class T>
602inline const Shear6<T> &
603Shear6<T>::operator /= (T a)
604{
605 xy /= a;
606 xz /= a;
607 yz /= a;
608 yx /= a;
609 zx /= a;
610 zy /= a;
611 return *this;
612}
613
614template <class T>
615inline Shear6<T>
616Shear6<T>::operator / (const Shear6 &h) const
617{
618 return Shear6 (xy / h.xy, xz / h.xz, yz / h.yz,
619 yx / h.yx, zx / h.zx, zy / h.zy);
620}
621
622template <class T>
623inline Shear6<T>
624Shear6<T>::operator / (T a) const
625{
626 return Shear6 (xy / a, xz / a, yz / a,
627 yx / a, zx / a, zy / a);
628}
629
630
631//-----------------------------
632// Stream output implementation
633//-----------------------------
634
635template <class T>
636std::ostream &
637operator << (std::ostream &s, const Shear6<T> &h)
638{
639 return s << '('
640 << h.xy << ' ' << h.xz << ' ' << h.yz
641 << h.yx << ' ' << h.zx << ' ' << h.zy
642 << ')';
643}
644
645
646//-----------------------------------------
647// Implementation of reverse multiplication
648//-----------------------------------------
649
650template <class S, class T>
651inline Shear6<T>
652operator * (S a, const Shear6<T> &h)
653{
654 return Shear6<T> (a * h.xy, a * h.xz, a * h.yz,
655 a * h.yx, a * h.zx, a * h.zy);
656}
657
658
659IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
660
661#endif // INCLUDED_IMATHSHEAR_H
662

source code of include/OpenEXR/ImathShear.h