EMAN2
vec3.h
Go to the documentation of this file.
1/*
2 * Author: Steven Ludtke, 04/10/2003 (sludtke@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31
32#ifndef eman__vec3_h__
33#define eman__vec3_h__ 1
34
35#include <vector>
36using std::vector;
37
38#include <cmath>
39
40#include <iostream>
41using std::cout;
42using std::endl;
43
44namespace EMAN
45{
46
64 template<typename Type>
65 class Vec4
66 {
67 public:
70 typedef Type type;
71
73 {
74 vec[0] = static_cast<Type>(0);
75 vec[1] = static_cast<Type>(0);
76 vec[2] = static_cast<Type>(0);
77 vec[3] = static_cast<Type>(0);
78 }
79
80 template<typename Type2, typename Type3, typename Type4, typename Type5>
81 Vec4(const Type2& a, const Type3& b, const Type4& c, const Type5& d)
82 {
83 vec[0] = static_cast<Type>(a);
84 vec[1] = static_cast<Type>(b);
85 vec[2] = static_cast<Type>(c);
86 vec[3] = static_cast<Type>(d);
87 }
88
93 template<typename Type2>
94 Vec4(const vector < Type2 > &v)
95 {
96 vec[0] = static_cast<Type>(v[0]);
97 vec[1] = static_cast<Type>(v[1]);
98 vec[2] = static_cast<Type>(v[2]);
99 vec[3] = static_cast<Type>(v[3]);
100 }
101
104 template<typename Type2>
106 {
107 vec[0] = v[0];
108 vec[1] = v[1];
109 vec[2] = v[2];
110 vec[2] = v[3];
111 }
112
115 ~Vec4() {}
116
121 float length() const
122 {
123 float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]);
124 return (float)sqrt(t);
125 }
126
131 float normalize()
132 {
133 // Warning - float precision
134 float len = length();
135 if (len != 0) {
136 vec[0] = static_cast<Type> (vec[0] / len);
137 vec[1] = static_cast<Type> (vec[1] / len);
138 vec[2] = static_cast<Type> (vec[2] / len);
139 vec[3] = static_cast<Type> (vec[3] / len);
140 }
141 else {
142 set_value(0, 0, 0, 0);
143 }
144 return len;
145 }
146
151 template<typename Type2>
152 void set_value(const vector < Type2 > &v)
153 {
154 vec[0] = static_cast<Type>(v[0]);
155 vec[1] = static_cast<Type>(v[1]);
156 vec[2] = static_cast<Type>(v[2]);
157 vec[3] = static_cast<Type>(v[3]);
158 }
159
164 template<typename Type2>
165 void set_value_at(int index, const Type2& value)
166 {
167 vec[index] = static_cast<Type>(value);
168 }
169
175 void set_value(const Type& a, const Type& b, const Type& c, const Type& d)
176 {
177 vec[0] = a;
178 vec[1] = b;
179 vec[2] = c;
180 vec[3] = d;
181 }
182
190 inline Type at(int i)
191 {
192 return vec[i];
193 }
194
200 {
201 return 4;
202 }
203
209 Type * begin()
210 {
211 return &vec[0];
212 }
213
219 Type * end()
220 {
221 return &vec[4];
222 }
223
231 inline Type operator[] (int i) const
232 {
233 return vec[i];
234 }
235
243 inline Type& operator[] (int i)
244 {
245 return vec[i];
246 }
247
248 private:
249 Type vec[4];
250 };
251
255
270 template<typename Type>
271 class Vec3
272 {
273 public:
276 typedef Type type;
277
280 Vec3() /*: vec[0](0),vec[1](0),vec[2](0)*/ {
281
282 vec[0] = static_cast<Type>(0);
283 vec[1] = static_cast<Type>(0);
284 vec[2] = static_cast<Type>(0);
285 }
286
293 template<typename Type2, typename Type3, typename Type4>
294 Vec3(const Type2& x, const Type3& y, const Type4& z = 0)
295 {
296 vec[0] = static_cast<Type>(x);
297 vec[1] = static_cast<Type>(y);
298 vec[2] = static_cast<Type>(z);
299 }
300
305 template<typename Type2>
306 Vec3(const vector < Type2 > &v)
307 {
308 vec[0] = static_cast<Type>(v[0]);
309 vec[1] = static_cast<Type>(v[1]);
310 vec[2] = static_cast<Type>(v[2]);
311 }
312
315 template<typename Type2>
317 {
318 vec[0] = v[0];
319 vec[1] = v[1];
320 vec[2] = v[2];
321 }
322
325 ~Vec3() {}
326
327
332 float normalize()
333 {
334 // Warning - float precision
335 float len = length();
336 if (len != 0) {
337 vec[0] = static_cast<Type> (vec[0] / len);
338 vec[1] = static_cast<Type> (vec[1] / len);
339 vec[2] = static_cast<Type> (vec[2] / len);
340 }
341 else {
342 set_value(0, 0, 0);
343 }
344 return len;
345 }
346
347
352 float length() const
353 {
354 float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
355 return (float)sqrt(t);
356 }
357
362 Type squared_length() const
363 {
364 return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] ;
365 }
366
372 template<typename Type2>
373 Type dot(const Vec3<Type2> & v) const
374 {
375 return static_cast<Type>((vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]));
376 }
377
383 template<typename Type2>
384 Vec3<Type> cross(const Vec3<Type2> & v) const
385 {
386 return Vec3<Type>((vec[1] * v[2] - vec[2] * v[1]),
387 (vec[2] * v[0] - vec[0] * v[2]),
388 (vec[0] * v[1] - vec[1] * v[0]));
389 }
390
394 vector<Type> as_list() const
395 {
396 vector < Type > v(3);
397 v[0] = vec[0];
398 v[1] = vec[1];
399 v[2] = vec[2];
400 return v;
401 }
402
407 template<typename Type2>
408 void set_value(const vector < Type2 > &v)
409 {
410 vec[0] = static_cast<Type>(v[0]);
411 vec[1] = static_cast<Type>(v[1]);
412 vec[2] = static_cast<Type>(v[2]);
413 }
414
419 template<typename Type2>
420 void set_value_at(int index, const Type2& value)
421 {
422 vec[index] = static_cast<Type>(value);
423 }
424
430 void set_value(const Type& x, const Type& y, const Type& z)
431 {
432 vec[0] = x;
433 vec[1] = y;
434 vec[2] = z;
435 }
436
444 inline Type operator[] (int i) const
445 {
446 return vec[i];
447 }
448
456 inline Type& operator[] (int i)
457 {
458 return vec[i];
459 }
460
468 inline Type at(int i)
469 {
470 return vec[i];
471 }
472
478 {
479 return 3;
480 }
481
487 Type * begin()
488 {
489 return &vec[0];
490 }
491
497 Type * end()
498 {
499 return &vec[3];
500 }
501
506 template<typename Type2>
508 vec[0] = static_cast<Type>(vec[0]+v[0]);
509 vec[1] = static_cast<Type>(vec[1]+v[1]);
510 vec[2] = static_cast<Type>(vec[2]+v[2]);
511 return *this;
512 }
513
518 template<typename Type2>
519 Vec3<Type> &operator +=(const Type2& d) {
520 vec[0] = static_cast<Type>(vec[0]+d);
521 vec[1] = static_cast<Type>(vec[1]+d);
522 vec[2] = static_cast<Type>(vec[2]+d);
523 return *this;
524 }
525
530 template<typename Type2>
532 vec[0] = static_cast<Type>(vec[0]-v[0]);
533 vec[1] = static_cast<Type>(vec[1]-v[1]);
534 vec[2] = static_cast<Type>(vec[2]-v[2]);
535 return *this;
536 }
537
542 template<typename Type2>
543 Vec3<Type>& operator -=(const Type2& d) {
544 vec[0] = static_cast<Type>(vec[0]-d);
545 vec[1] = static_cast<Type>(vec[1]-d);
546 vec[2] = static_cast<Type>(vec[2]-d);
547 return *this;
548 }
549
554 template<typename Type2>
555 Vec3<Type> &operator *=(const Type2& d) {
556 vec[0] = static_cast<Type>(vec[0]*d);
557 vec[1] = static_cast<Type>(vec[1]*d);
558 vec[2] = static_cast<Type>(vec[2]*d);
559 return *this;
560 }
561
566 template<typename Type2>
567 Vec3<Type> &operator /=(const Type2& d) {
568 vec[0] = static_cast<Type>(vec[0]/d);
569 vec[1] = static_cast<Type>(vec[1]/d);
570 vec[2] = static_cast<Type>(vec[2]/d);
571 return *this;
572 }
573
574 template<typename Type2>
575 operator vector<Type2>() const {
576 vector<Type2> v(vec,vec+3);
577 return v;
578 }
579
580
581 private:
582 Type vec[3];
583 };
584
585 template<typename Type,typename Type2>
586 inline Vec3<Type> operator +(const Vec3<Type> &v1, const Vec3<Type2> &v2)
587 {
588
589 return Vec3<Type>(static_cast<Type>(v1[0] + v2[0]), static_cast<Type>(v1[1] + v2[1]),static_cast<Type>(v1[2] + v2[2]));;
590 }
591
592 template<typename Type,typename Type2>
593 inline Vec3<Type> operator +(const Vec3<Type> &v, const Type2& n)
594 {
595 Vec3<Type> v1(v);
596 v1 += n;
597 return v1;
598 }
599
600// template<typename Type,typename Type2>
601// inline Vec3<Type> operator +(const Type2& n, const Vec3<Type> &v)
602// {
603// Vec3<Type> v1(v);
604// v1 += n;
605// return v1;
606// }
607
608 template<typename Type,typename Type2>
609 inline Vec3<Type> operator -(const Vec3<Type> &v1, const Vec3<Type2> &v2)
610 {
611 return Vec3<Type>(static_cast<Type>(v1[0] - v2[0]),
612 static_cast<Type>(v1[1] - v2[1]),
613 static_cast<Type>(v1[2] - v2[2]));
614 }
615
616 template<typename Type,typename Type2>
617 inline Vec3<Type> operator -(const Vec3<Type> &v, const Type2& n)
618 {
619 Vec3<Type> v1(v);
620 v1 -= n;
621 return v1;
622 }
623 template<typename Type>
625 {
626 return Vec3<Type>(-v[0],-v[1],-v[2]);
627 }
628
629// template<typename Type,typename Type2>
630// inline Vec3<Type> operator -(const Type2& n, const Vec3<Type> &v)
631// {
632// Vec3<Type> v1(v);
633// v1 -= n;
634// return v1;
635// }
636
637 template<typename Type,typename Type2>
638 inline Type operator *(const Vec3<Type> &v1, const Vec3<Type2> &v2)
639 {
640 return v1.dot(v2);
641 }
642
643 template<typename Type,typename Type2>
644 inline Vec3<Type2> operator *(const Type& d, const Vec3<Type2> & v)
645 {
646 // Preserve the vector type
647 Vec3<Type2> v1(v);
648 v1 *= d;
649 return v1;
650 }
651
652 template<typename Type,typename Type2>
653 inline Vec3<Type> operator *(const Vec3<Type> & v,const Type2& d) {
654 // Preserve the vector type
655 Vec3<Type> v1(v);
656 v1 *= d;
657 return v1;
658 }
659
660 template<typename Type,typename Type2>
661 inline Vec3<Type2> operator /(const Type& d, const Vec3<Type2> & v)
662 {
663 // Preserve the vector type
664 Vec3<Type2> v1(v);
665 v1 /= d;
666 return v1;
667 }
668
669 template<typename Type,typename Type2>
670 inline Vec3<Type> operator /(const Vec3<Type> & v,const Type2& d) {
671 // Preserve the vector type
672 Vec3<Type> v1(v);
673 v1 /= d;
674 return v1;
675 }
676
677 template<typename Type,typename Type2>
678 inline bool operator ==(const Vec3<Type> &v1, const Vec3<Type2> &v2) {
679 if (v1[0] == v2[0] && v1[1] == v2[1] && v1[2] == v2[2]) {
680 return true;
681 }
682 return false;
683 }
684
685 template<typename Type,typename Type2>
686 inline bool operator !=(const Vec3<Type> &v1, const Vec3<Type2> &v2) {
687 if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) {
688 return true;
689 }
690 return false;
691 }
692
696
697
708 template<typename Type>
709 class Vec2
710 {
711 public:
714 typedef Type type;
715
718 Vec2() /*: vec[0](0),vec[1](0),vec[2](0)*/ {
719 vec[0] = static_cast<Type>(0);
720 vec[1] = static_cast<Type>(0);
721 }
722
728 template<typename Type2, typename Type3>
729 Vec2(const Type2& x, const Type3& y)
730 {
731 vec[0] = static_cast<Type>(x);
732 vec[1] = static_cast<Type>(y);
733 }
734
739 template<typename Type2>
740 Vec2(const vector < Type2 > &v)
741 {
742 vec[0] = static_cast<Type>(v[0]);
743 vec[1] = static_cast<Type>(v[1]);
744 }
745
748 template<typename Type2>
750 {
751 vec[0] = static_cast<Type>(v[0]);
752 vec[1] = static_cast<Type>(v[1]);
753 }
754
757 ~Vec2() {}
758
759
764 float normalize()
765 {
766 // Warning - float precision
767 float len = length();
768 if (len != 0) {
769 vec[0] = static_cast<Type> (vec[0] / len);
770 vec[1] = static_cast<Type> (vec[1] / len);
771 }
772 else {
773 set_value(0, 0);
774 }
775 return len;
776 }
777
778
783 float length() const
784 {
785 float t = (float)(vec[0] * vec[0] + vec[1] * vec[1]);
786 return (float)sqrt(t);
787 }
788
793 Type squared_length() const
794 {
795 return vec[0] * vec[0] + vec[1] * vec[1] ;
796 }
797
803 template<typename Type2>
804 Type dot(const Vec2<Type2> & v) const
805 {
806 return static_cast<Type>((vec[0] * v[0] + vec[1] * v[1]));
807 }
808
812 vector<Type> as_list() const
813 {
814 vector < Type > v(2);
815 v[0] = vec[0];
816 v[1] = vec[1];
817 return v;
818 }
819
824 template<typename Type2>
825 void set_value(const vector < Type2 > &v)
826 {
827 vec[0] = static_cast<Type>(v[0]);
828 vec[1] = static_cast<Type>(v[1]);;
829 }
830
835 template<typename Type2>
836 void set_value_at(int index, const Type2& value)
837 {
838 vec[index] = static_cast<Type>(value);
839 }
840
845 void set_value(const Type& x, const Type& y)
846 {
847 vec[0] = x;
848 vec[1] = y;
849 }
850
858 inline Type operator[] (int i) const { return vec[i]; }
859
867 inline Type& operator[] (int i) { return vec[i]; }
868
876 inline Type at(int i) { return vec[i]; }
877
878
884 {
885 return 2;
886 }
887
893 Type * begin()
894 {
895 return &vec[0];
896 }
897
903 Type * end()
904 {
905 return &vec[2];
906 }
907
908
913 template<typename Type2>
915 vec[0] = static_cast<Type>(vec[0]+v[0]);
916 vec[1] = static_cast<Type>(vec[1]+v[1]);
917 return *this;
918 }
919
924 template<typename Type2>
925 Vec2<Type>& operator +=(const Type2& d) {
926 vec[0] = static_cast<Type>(vec[0]+d);
927 vec[1] = static_cast<Type>(vec[1]+d);
928 return *this;
929 }
930
935 template<typename Type2>
937 vec[0] = static_cast<Type>(vec[0]-v[0]);
938 vec[1] = static_cast<Type>(vec[1]-v[1]);
939 return *this;
940 }
941
946 template<typename Type2>
947 Vec2<Type>& operator -=(const Type2& d) {
948 vec[0] = static_cast<Type>(vec[0]-d);
949 vec[1] = static_cast<Type>(vec[1]-d);
950 return *this;
951 }
952
957 template<typename Type2>
958 Vec2<Type>& operator *=(const Type2& d) {
959 vec[0] = static_cast<Type>(vec[0]*d);
960 vec[1] = static_cast<Type>(vec[1]*d);
961 return *this;
962 }
963
968 template<typename Type2>
969 Vec2<Type>& operator /=(const Type2& d) {
970 vec[0] = static_cast<Type>(vec[0]/d);
971 vec[1] = static_cast<Type>(vec[1]/d);
972 return *this;
973 }
974
975
976 private:
977 Type vec[2];
978 };
979
980 template<typename Type,typename Type2>
981 inline Vec2<Type> operator +(const Vec2<Type> &v1, const Vec2<Type2> &v2)
982 {
983 return Vec2<Type>(static_cast<Type>(v1[0] + v2[0]), static_cast<Type>(v1[1] + v2[1]));;
984 }
985
986 template<typename Type,typename Type2>
987 inline Vec2<Type> operator +(const Vec2<Type> &v, const Type2& n)
988 {
989 Vec2<Type> v1(v);
990 v1 += n;
991 return v1;
992 }
993
994 template<typename Type,typename Type2>
995 inline Vec2<Type> operator -(const Vec2<Type> &v1, const Vec2<Type2> &v2)
996 {
997 return Vec2<Type>(static_cast<Type>(v1[0] - v2[0]), static_cast<Type>(v1[1] - v2[1]));
998 }
999
1000 template<typename Type,typename Type2>
1001 inline Vec2<Type> operator -(const Vec2<Type> &v, const Type2& n)
1002 {
1003 Vec2<Type> v1(v);
1004 v1 -= n;
1005 return v1;
1006 }
1007
1008 template<typename Type>
1010 {
1011 return Vec2<Type>(-v[0],-v[1]);
1012 }
1013
1014
1015 template<typename Type,typename Type2>
1016 inline Type operator *(const Vec2<Type> &v1, const Vec2<Type2> &v2)
1017 {
1018 return v1.dot(v2);
1019 }
1020
1021 template<typename Type,typename Type2>
1022 inline Vec2<Type2> operator *(const Type& d, const Vec2<Type2> & v)
1023 {
1024 // Preserve the vector type
1025 Vec2<Type2> v1(v);
1026 v1 *= d;
1027 return v1;
1028 }
1029
1030 template<typename Type,typename Type2>
1031 inline Vec2<Type> operator *(const Vec2<Type> & v,const Type2& d) {
1032 // Preserve the vector type
1033 Vec2<Type> v1(v);
1034 v1 *= d;
1035 return v1;
1036 }
1037
1038 template<typename Type,typename Type2>
1039 inline Vec2<Type2> operator /(const Type& d, const Vec2<Type2> & v)
1040 {
1041 // Preserve the vector type
1042 Vec2<Type2> v1(v);
1043 v1 /= d;
1044 return v1;
1045 }
1046
1047 template<typename Type,typename Type2>
1048 inline Vec2<Type> operator /(const Vec2<Type> & v,const Type2& d) {
1049 // Preserve the vector type
1050 Vec2<Type> v1(v);
1051 v1 /= d;
1052 return v1;
1053 }
1054
1055 template<typename Type,typename Type2>
1056 inline bool operator ==(const Vec2<Type> &v1, const Vec2<Type2> &v2) {
1057 if (v1[0] == v2[0] && v1[1] == v2[1] ) {
1058 return true;
1059 }
1060 return false;
1061 }
1062
1063 template<typename Type,typename Type2>
1064 inline bool operator !=(const Vec2<Type> &v1, const Vec2<Type2> &v2) {
1065 if (v1[0] != v2[0] || v1[1] != v2[1] ) {
1066 return true;
1067 }
1068 return false;
1069 }
1070
1074}
1075#endif
The Vec2 is precisely the same as Vec3 except it works exclusively in 2D Note there are convenient ty...
Definition: vec3.h:710
vector< Type > as_list() const
Return the values of this vector as a std::vector.
Definition: vec3.h:812
~Vec2()
Destructor.
Definition: vec3.h:757
Type squared_length() const
Calculate its squared length.
Definition: vec3.h:793
Type vec[2]
Definition: vec3.h:977
Vec2(const Vec2< Type2 > &v)
Copy constructor copies vector elements.
Definition: vec3.h:749
Type at(int i)
Get the ith item of the vector.
Definition: vec3.h:876
Type * begin()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Definition: vec3.h:893
Type type
One can always cast to the type of a Vec2 by accessing Vec2<Type>::type.
Definition: vec3.h:714
float length() const
Calculate its length.
Definition: vec3.h:783
Type * end()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Definition: vec3.h:903
Type dot(const Vec2< Type2 > &v) const
Calculate the dot product of 'this' vector with a second vector.
Definition: vec3.h:804
Vec2()
contruct a Vec2 object with all elements equal to 0.
Definition: vec3.h:718
float normalize()
Normalize the vector and return its length before the normalization.
Definition: vec3.h:764
int number_of_element()
For python len
Definition: vec3.h:883
Vec2< Type > & operator+=(const Vec2< Type2 > &v)
'this' += v; Add the 2 vectors by adding item by item.
Definition: vec3.h:914
void set_value(const Type &x, const Type &y)
Set new values to this vector object.
Definition: vec3.h:845
Type operator[](int i) const
Get the ith item of the vector.
Definition: vec3.h:858
Vec2< Type > & operator/=(const Type2 &d)
'this' /= d; Divide a number on each item of 'this' vector.
Definition: vec3.h:969
Vec2< Type > & operator*=(const Type2 &d)
'this' *= d; Multiply a number on each item of 'this' vector.
Definition: vec3.h:958
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Definition: vec3.h:825
Vec2(const Type2 &x, const Type3 &y)
contruct a Vec2 object given (x,y) or (x,y,z) values.
Definition: vec3.h:729
void set_value_at(int index, const Type2 &value)
Set values at a particular index.
Definition: vec3.h:836
Vec2< Type > & operator-=(const Vec2< Type2 > &v)
'this' -= v; Minus the 2 vectors item by item.
Definition: vec3.h:936
Vec2(const vector< Type2 > &v)
Construct a Vec2 object given a std::vector object.
Definition: vec3.h:740
The Vec3 object is a templated object, intended to instantiated with basic types such as int,...
Definition: vec3.h:272
Type * end()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Definition: vec3.h:497
Type type
One can always cast to the type of a Vec3 by accessing Vec3<Type>::type.
Definition: vec3.h:276
Vec3< Type > & operator*=(const Type2 &d)
'this' *= d; Multiply a number on each item of 'this' vector.
Definition: vec3.h:555
Vec3< Type > & operator-=(const Vec3< Type2 > &v)
'this' -= v; Minus the 2 vectors item by item.
Definition: vec3.h:531
Vec3< Type > cross(const Vec3< Type2 > &v) const
Calculate the cross product of 'this' vector with a second vector.
Definition: vec3.h:384
Vec3< Type > & operator/=(const Type2 &d)
'this' /= d; Divide a number on each item of 'this' vector.
Definition: vec3.h:567
Type vec[3]
Definition: vec3.h:582
vector< Type > as_list() const
Return the values of this vector as a std::vector.
Definition: vec3.h:394
Type * begin()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Definition: vec3.h:487
Vec3(const Vec3< Type2 > &v)
Copy constructor copies vector elements.
Definition: vec3.h:316
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Definition: vec3.h:408
Type squared_length() const
Calculate its squared length.
Definition: vec3.h:362
Type dot(const Vec3< Type2 > &v) const
Calculate the dot product of 'this' vector with a second vector.
Definition: vec3.h:373
Type operator[](int i) const
Get the ith item of the vector.
Definition: vec3.h:444
Type at(int i)
Get the ith item of the vector.
Definition: vec3.h:468
float normalize()
Normalize the vector and return its length before the normalization.
Definition: vec3.h:332
void set_value(const Type &x, const Type &y, const Type &z)
Set new values to this vector object.
Definition: vec3.h:430
float length() const
Calculate its length.
Definition: vec3.h:352
int number_of_element()
For python len
Definition: vec3.h:477
Vec3(const vector< Type2 > &v)
Construct a Vec3 object given a std::vector object.
Definition: vec3.h:306
Vec3(const Type2 &x, const Type3 &y, const Type4 &z=0)
contruct a Vec3 object given (x,y) or (x,y,z) values.
Definition: vec3.h:294
void set_value_at(int index, const Type2 &value)
Set values at a particular index.
Definition: vec3.h:420
~Vec3()
Destructor.
Definition: vec3.h:325
Vec3< Type > & operator+=(const Vec3< Type2 > &v)
'this' += v; Add the 2 vectors by adding item by item.
Definition: vec3.h:507
Vec3()
contruct a Vec3 object with all elements equal to 0.
Definition: vec3.h:280
The Vec4 object is a templated object, intended to instantiated with basic types such as int,...
Definition: vec3.h:66
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Definition: vec3.h:152
Vec4(const Vec4< Type2 > &v)
Copy constructor copies vector elements.
Definition: vec3.h:105
Type vec[4]
Definition: vec3.h:249
Type operator[](int i) const
Get the ith item of the vector.
Definition: vec3.h:231
void set_value(const Type &a, const Type &b, const Type &c, const Type &d)
Set new values to this vector object.
Definition: vec3.h:175
Type * begin()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Definition: vec3.h:209
Type * end()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Definition: vec3.h:219
float length() const
Calculate its length.
Definition: vec3.h:121
void set_value_at(int index, const Type2 &value)
Set values at a particular index.
Definition: vec3.h:165
float normalize()
Normalize the vector and return its length before the normalization.
Definition: vec3.h:131
~Vec4()
Destructor.
Definition: vec3.h:115
Type type
One can always cast to the type of a Vec4 by accessing Vec4<Type>::type.
Definition: vec3.h:70
Vec4()
Definition: vec3.h:72
Vec4(const vector< Type2 > &v)
Construct a Vec3 object given a std::vector object.
Definition: vec3.h:94
Type at(int i)
Get the ith item of the vector.
Definition: vec3.h:190
Vec4(const Type2 &a, const Type3 &b, const Type4 &c, const Type5 &d)
Definition: vec3.h:81
int number_of_element()
For python len
Definition: vec3.h:199
EMData * sqrt() const
return square root of current image
E2Exception class.
Definition: aligner.h:40
Vec4< float > Vec4f
Definition: vec3.h:252
EMData * operator+(const EMData &em, float n)
Definition: emdata.cpp:3187
Vec3< float > Vec3f
Definition: vec3.h:693
Vec4< int > Vec4i
Definition: vec3.h:253
Vec3< int > Vec3i
Definition: vec3.h:694
Vec2< double > Vec2d
Definition: vec3.h:1073
Vec2< float > Vec2f
Definition: vec3.h:1071
Vec3< double > Vec3d
Definition: vec3.h:695
Vec2< int > Vec2i
Definition: vec3.h:1072
Vec4< double > Vec4d
Definition: vec3.h:254
bool operator!=(const EMObject &e1, const EMObject &e2)
Definition: emobject.cpp:873
EMData * operator-(const EMData &em, float n)
Definition: emdata.cpp:3194
EMData * operator/(const EMData &em, float n)
Definition: emdata.cpp:3208
EMData * operator*(const EMData &em, float n)
Definition: emdata.cpp:3201
bool operator==(const EMObject &e1, const EMObject &e2)
Definition: emobject.cpp:770
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517