GCGlib  0.04.228
GCG Graphics Engine
gcg.h
Go to the documentation of this file.
1 
314 #ifndef _GCG_H_
315 
316 #ifdef __cplusplus
317  extern "C++" { // All names have C++ style
318 #else
319  #error "GCC library must be compiled with C++ compilers"
320 #endif
321 
322 #if !defined(_COUNTER_GCG_)
323  #define _COUNTER_GCG_ 1
324 #endif
325 
326 // Next definitions will be included once
327 #if _COUNTER_GCG_ == 1
328 
329 #if defined(GCG_WINDOWS32) || defined(GCG_WINDOWS64)
330  #ifndef VAPIWIN_API
331  // GCGlib is deployed as a Dynamic Linked Library for Windows
332  #define GCG_API_FUNCTION extern __declspec(dllexport)
333  #define GCG_API_DATA extern __declspec(dllexport)
334  #define GCG_API_CLASS __declspec(dllexport)
335  #define GCG_API_TEMPLATE __declspec(dllexport)
336  #else
337  // VAPIWIN is a Dynamic Linked Library for use with non-Visual C++ compilers for video input
338  #define GCG_API_FUNCTION extern
339  #define GCG_API_DATA extern
340  #define GCG_API_CLASS
341  #define GCG_API_TEMPLATE
342  #endif
343 #else
344  #ifdef WIN32
345  // GCGlib names need special modifiers in Windows
346  #define GCG_API_FUNCTION extern __declspec(dllimport)
347  #define GCG_API_DATA extern __declspec(dllimport)
348  #define GCG_API_CLASS
349  #define GCG_API_TEMPLATE
350  #else
351  // GCGlib names defined as C and C++ standards
352  #define GCG_API_FUNCTION extern
353  #define GCG_API_DATA extern
354  #define GCG_API_CLASS
355  #define GCG_API_TEMPLATE
356  #endif
357 #endif
358 
359 #include <stdio.h>
360 #include <math.h>
361 #include <new>
362 
363 #if defined(__GNUC__) || defined(MINGW)
364  #include <stdint.h>
365 #endif
366 
367 // MSVC compatible 64 bits integer
368 #ifdef _MSC_VER
369  typedef __int64 int64_t;
370  typedef unsigned __int64 uint64_t;
371 #endif
372 
380 
384 
387 GCG_API_DATA const char *GCG_VERSION;
390 GCG_API_DATA const char *GCG_BUILD_DATE;
393 GCG_API_DATA const int GCG_VERSION_MAJOR;
396 GCG_API_DATA const int GCG_VERSION_MINOR;
399 GCG_API_DATA const int GCG_VERSION_BUILD;
400 
401 
403 
404 
405 /*******************************************************************
406  GENERAL MACROS AND INLINE FUNCTIONS
407 ********************************************************************/
408 
413 
418 
419 #ifndef SQR
420 static inline int SQR(int x) { return x * x; }
425 
430 static inline short SQR(short x) { return x * x; }
431 
436 static inline long SQR(long x) { return x * x; }
437 
442 static inline float SQR(float x) { return x * x; }
443 
448 static inline double SQR(double x) { return x * x; }
449 #endif
450 
454 
455 #ifndef MIN
456 #define MIN(a, b) ((a > b) ? (b) : (a))
457 #endif
458 
462 
463 #ifndef MAX
464 #define MAX(a, b) ((a < b) ? (b) : (a))
465 #endif
466 
470 
471 #ifndef ABS
472 #define ABS(a) (((a) < 0) ? -(a) : (a))
473 #endif
474 
475 
479 
480 #ifndef SWAP
481 #define SWAP(a, b) {(a) ^= (b); (b) ^= (a); (a) ^= (b);}
482 #endif
483 
487 
488 #ifndef DEG2RAD
489 #define DEG2RAD(a) (((a) * M_PI) / 180.0)
490 #endif
491 
495 
496 #ifndef RAD2DEG
497 #define RAD2DEG(a) (((a) * 180) / M_PI)
498 #endif
499 
503 
504 #ifndef TRUE
505 #define TRUE 1
506 #endif
507 
508 
512 
513 #ifndef FALSE
514 #define FALSE 0
515 #endif
516 
520 
521 #ifndef EPSILON
522 #define EPSILON 0.0000077
523 #endif
524 
528 
529 #ifndef INF
530 #define INF 1.0e+16
531 #endif
532 
536 
537 #ifndef FEQUAL
538 #define FEQUAL(a, b) (fabs((a)-(b)) < EPSILON)
539 #endif
540 
544 
545 #ifndef M_PI
546 #define M_PI 3.14159265358979323846
547 #endif
548 
552 
553 #ifndef NULL
554 #define NULL 0
555 #endif
556 
560 
561 #ifndef ISPOWEROF2
562 #define ISPOWEROF2(n) (!(n & (n-1)))
563 #endif
564 
566 
574 
575 
603 
622 GCG_API_FUNCTION bool gcgReport(int code, const char *format = NULL, ...);
623 
636 GCG_API_FUNCTION int gcgGetReport(int sizestring = 0, char *extrastring = NULL);
637 
647 GCG_API_FUNCTION const char *gcgGetReportString(char **typestr = NULL, char **domainstr = NULL);
648 
664 GCG_API_FUNCTION bool gcgEnableReportLog(int code, bool enable);
665 
667 
668 
676 
682 GCG_API_FUNCTION FILE *gcgGetLogStream();
683 
691 GCG_API_FUNCTION FILE *gcgSetLogStream(FILE *logstream);
692 
699 GCG_API_FUNCTION void gcgOutputLog(const char *format, ...);
701 
702 
703 
709 
712 #define GCG_REPORT_CODE(t, d, m) (((((int) d) & (int) 0xff) << 3) | ((((int) m) & (int) 0x3ff) << 11) | ((((int) t) & (int) 0x07) << 0))
713 
716 #define GCG_REPORT_TYPE(c) ((((int) c) >> 0) & (int) 0x07) // 3 bits
717 
720 #define GCG_REPORT_DOMAIN(c) ((((int) c) >> 3) & (int) 0xff) // 8 bits
721 
724 #define GCG_REPORT_MESSAGE(c) ((((int) c) >> 11) & (int) 0x3ff) // 10 bits
725 
727 
728 
737 
741 #define GCG_SUCCESS 0 // Must be zero
742 #define GCG_ERROR 1
744 #define GCG_WARNING 2
746 #define GCG_INFORMATION 3 // Must be the greatest code
748 
760 
762 #define GCG_DOMAIN_MEMORY 8 // Must be the smallest code
763 #define GCG_DOMAIN_NETWORK 9
765 #define GCG_DOMAIN_FILE 10
767 #define GCG_DOMAIN_IMAGE 11
769 #define GCG_DOMAIN_CAMERA 12
771 #define GCG_DOMAIN_VIDEO 13
773 #define GCG_DOMAIN_THREAD 14
775 #define GCG_DOMAIN_GRAPHICS 15
777 #define GCG_DOMAIN_GEOMETRY 16
779 #define GCG_DOMAIN_ALGEBRA 17
781 #define GCG_DOMAIN_CONFIG 18
783 #define GCG_DOMAIN_DATASTRUCTURE 19
785 #define GCG_DOMAIN_SIGNAL 20
787 
789 #define GCG_DOMAIN_USER 21 // Must be the greatest code
790 
795 #define GCG_REPORT_ALL -1
796 
798 
799 
803 
805 #define GCG_NONE 0 // Must be the smallest code
806 #define GCG_ALLOCATIONERROR 1
808 #define GCG_INVALIDOBJECT 2
810 #define GCG_BADPARAMETERS 3
812 #define GCG_INITERROR 4
814 #define GCG_INTERNALERROR 5
816 #define GCG_TIMEOUT 6
818 #define GCG_IOERROR 7
820 #define GCG_FORMATMISMATCH 8
822 #define GCG_UNRECOGNIZEDFORMAT 9
824 #define GCG_UNSUPPORTEDFORMAT 10
826 #define GCG_UNSUPPORTEDOPERATION 11
828 #define GCG_INFORMATIONPROBLEM 12
830 #define GCG_READERROR 13
832 #define GCG_WRITEERROR 14
834 #define GCG_NOTCONNECTED 15
836 #define GCG_SOCKETERROR 16
838 #define GCG_SELECTERROR 17
840 #define GCG_CONNECTIONCLOSED 18
842 #define GCG_HOSTNOTFOUND 19
844 #define GCG_CONNECTERROR 20
846 #define GCG_SETSOCKETOPTERROR 21
848 #define GCG_BINDERROR 22
850 #define GCG_LISTENERROR 23
852 #define GCG_ACCEPTERROR 24
854 #define GCG_EXCEPTION 25
856 #define GCG_ACCEPTBADADDRESS 26
858 #define GCG_CONNECTIONREFUSED 27
860 #define GCG_CONNECTIONABORTED 28
862 #define GCG_WRITEBADADDRESS 29
864 #define GCG_READBADADDRESS 30
866 #define GCG_SENDSHUTDOWN 31
868 #define GCG_RECEIVESHUTDOWN 32
870 #define GCG_INVALIDSOCKET 33
872 #define GCG_STREAMCONTROLERROR 34
874 #define GCG_ALREADYRUNNING 35
876 #define GCG_CREATIONFAILED 36
878 #define GCG_MUTEXFAILURE 37
880 #define GCG_SEMAPHOREFAILURE 38
882 #define GCG_NOBUFFER 39
884 #define GCG_JOBNOTEXECUTED 40
886 #define GCG_INTERRUPTED 41
888 #define GCG_DISCONNECTED 42
890 #define GCG_STOPERROR 43
892 #define GCG_NOTRUNNING 44
894 #define GCG_EXITFAILURE 45
896 #define GCG_RELEASEERROR 46
898 #define GCG_LOCKERROR 47
900 #define GCG_OWNERSHIPERROR 48
902 #define GCG_REMOVALERROR 49
904 #define GCG_STOREFAILURE 50
906 #define GCG_OPENERROR 51
908 #define GCG_DECODEERROR 52
910 #define GCG_FUNCTIONCALLFAILED 53
912 #define GCG_GRAPHICSERROR 54
914 #define GCG_INCOMPATIBILITYERROR 55
916 #define GCG_CONFIGERROR 56
918 #define GCG_UNAVAILABLERESOURCE 57
920 #define GCG_STARTERROR 58
922 #define GCG_OUTOFBOUNDS 59
924 #define GCG_ENDOFSTREAM 60
926 #define GCG_OPERATIONFAILED 61
928 #define GCG_MEMORYLEAK 62
930 #define GCG_INSERTIONFAILED 63
932 #define GCG_ADAPTING 64
934 
936 #define GCG_UNDEFINED 65 // Must be the greatest code
937 
939 
947 
956 
957 class GCG_API_CLASS gcgCLASS {
958  public:
966  void *operator new(size_t size);
967 
975  void *operator new(size_t size, const std::nothrow_t&) throw();
976 
983  void *operator new[](size_t size);
984 
992  void *operator new[](size_t size, const std::nothrow_t&) throw();
993 
999  void operator delete(void *p);
1000 
1006  void operator delete(void *p, const std::nothrow_t&) throw();
1007 
1013  void operator delete[](void *p);
1014 
1020  void operator delete[](void *p, const std::nothrow_t&) throw();
1021 };
1022 
1023 
1027 GCG_API_FUNCTION uintptr_t getAllocatedMemoryCounter();
1028 
1029 
1030 
1038 
1040 // GCG primitive types.
1042 
1043 typedef float VECTOR2[2];
1044 typedef float VECTOR3[3];
1045 typedef float VECTOR4[4];
1046 
1047 typedef float MATRIX2[4];
1048 typedef float MATRIX3[9];
1049 typedef float MATRIX34[12];
1050 typedef float MATRIX4[16];
1051 
1052 typedef double VECTOR2d[2];
1053 typedef double VECTOR3d[3];
1054 typedef double VECTOR4d[4];
1055 
1056 typedef double MATRIX2d[4];
1057 typedef double MATRIX3d[9];
1058 typedef double MATRIX34d[12];
1059 typedef double MATRIX4d[16];
1060 
1061 
1063 // GCG algebra macros. More efficient than functions. But implies in a larger code.
1065 
1066 // Expressions ///////////////////////////////////////////////
1067 #define gcgDOTVECTOR2(v1, v2) ((v1)[0] * (v2)[0] + (v1)[1] * (v2)[1])
1068 #define gcgDOTIMEDVECTOR2(u, a, b) ((u)[0] * (a) + (u)[1] * (b)}
1069 #define gcgLENGTHVECTOR2(v) (sqrt(gcgDOTVECTOR2((v),(v))))
1070 
1071 #define gcgDOTVECTOR3(v1, v2) ((v1)[0] * (v2)[0] + (v1)[1] * (v2)[1] + (v1)[2] * (v2)[2])
1072 #define gcgDOTIMEDVECTOR3(u, a, b, c) ((u)[0] * (a) + (u)[1] * (b) + (u)[2] * (c))
1073 #define gcgLENGTHVECTOR3(v) (sqrt(gcgDOTVECTOR3((v),(v))))
1074 
1075 #define gcgDOTVECTOR4(v1, v2) ((v1)[0] * (v2)[0] + (v1)[1] * (v2)[1] + (v1)[2] * (v2)[2] + (v1)[3] * (v2)[3])
1076 #define gcgDOTIMEDVECTOR4(u, a, b, c, d) ((u)[0] * (a) + (u)[1] * (b) + (u)[2] * (c) + (u)[3] * (d))
1077 #define gcgLENGTHVECTOR4(v) (sqrt(gcgDOTVECTOR4((v),(v))))
1078 
1079 #define gcgISEQUALVECTOR2(v1, v2) (fabs(v1[0] - v2[0]) > EPSILON && fabs((v1)[1] - (v2)[1]) > EPSILON)
1080 #define gcgISEQUALVECTOR3(v1, v2) (fabs(v1[0] - v2[0]) > EPSILON && fabs((v1)[1] - (v2)[1]) > EPSILON && fabs((v1)[2] - (v2)[2]) > EPSILON)
1081 #define gcgISEQUALVECTOR4(v1, v2) (fabs(v1[0] - v2[0]) > EPSILON && fabs((v1)[1] - (v2)[1]) > EPSILON && fabs((v1)[2] - (v2)[2]) > EPSILON && fabs((v1)[3] - (v2)[3]) > EPSILON)
1082 
1083 // Computes the determinant of matrices
1084 #define gcgDETERMINANT3x3_(m0, m1, m2, m3, m4, m5, m6, m7, m8) ((m0)*((m8)*(m4)-(m7)*(m5)) - (m3)*((m8)*(m1)-(m7)*(m2)) + (m6)*((m5)*(m1)-(m4)*(m2)))
1085 #define gcgDETERMINANT4x4_(m, det0, det4, det8, det12) \
1086 ( (m)[0] * (det0 = gcgDETERMINANT3x3_((m)[5], (m)[6], (m)[7], (m)[9], (m)[10], (m)[11], (m)[13], (m)[14], (m)[15])) \
1087  -(m)[4] * (det4 = gcgDETERMINANT3x3_((m)[1], (m)[2], (m)[3], (m)[9], (m)[10], (m)[11], (m)[13], (m)[14], (m)[15])) \
1088  +(m)[8] * (det8 = gcgDETERMINANT3x3_((m)[1], (m)[2], (m)[3], (m)[5], (m)[6], (m)[7], (m)[13], (m)[14], (m)[15])) \
1089  -(m)[12] * (det12= gcgDETERMINANT3x3_((m)[1], (m)[2], (m)[3], (m)[5], (m)[6], (m)[7], (m)[9], (m)[10], (m)[11])) )
1090 
1091 #define gcgDETERMINANTMATRIX3(m) (gcgDETERMINANT3x3_((m)[0], (m)[1], (m)[2], (m)[3], (m)[4], (m)[5], (m)[6], (m)[7], (m)[8]))
1092 #define gcgDETERMINANTMATRIX4(m) \
1093 ( (m)[0] * gcgDETERMINANT3x3_((m)[5], (m)[6], (m)[7], (m)[9], (m)[10], (m)[11], (m)[13], (m)[14], (m)[15]) \
1094  -(m)[4] * gcgDETERMINANT3x3_((m)[1], (m)[2], (m)[3], (m)[9], (m)[10], (m)[11], (m)[13], (m)[14], (m)[15]) \
1095  +(m)[8] * gcgDETERMINANT3x3_((m)[1], (m)[2], (m)[3], (m)[5], (m)[6], (m)[7], (m)[13], (m)[14], (m)[15]) \
1096  -(m)[12] * gcgDETERMINANT3x3_((m)[1], (m)[2], (m)[3], (m)[5], (m)[6], (m)[7], (m)[9], (m)[10], (m)[11]) )
1097 
1098 
1099 // Commands ///////////////////////////////////////////////
1100 #define gcgZEROVECTOR2(v) { (v)[0] = (v)[1] = 0.0; }
1101 #define gcgZEROVECTOR3(v) { (v)[0] = (v)[1] = (v)[2] = 0.0; }
1102 #define gcgZEROVECTOR4(v) { (v)[0] = (v)[1] = (v)[2] = (v)[3] = 0.0; }
1103 
1104 #define gcgSETVECTOR2(dest, a, b) {(dest)[0] = a; (dest)[1] = b; }
1105 #define gcgSETVECTOR3(dest, a, b, c) {(dest)[0] = a; (dest)[1] = b; (dest)[2] = c; }
1106 #define gcgSETVECTOR4(dest, a, b, c, d) {(dest)[0] = a; (dest)[1] = b; (dest)[2] = c; (dest)[3]=d; }
1107 
1108 static inline void gcgCOPYVECTOR2(VECTOR2 dest, VECTOR2 src) {dest[0] = src[0]; dest[1] = src[1]; }
1109 static inline void gcgCOPYVECTOR2(VECTOR2d dest, VECTOR2d src) {dest[0] = src[0]; dest[1] = src[1]; }
1110 static inline void gcgCOPYVECTOR2(VECTOR2 dest, VECTOR2d src) {dest[0] = (float) src[0]; dest[1] = (float) src[1]; }
1111 static inline void gcgCOPYVECTOR2(VECTOR2d dest, VECTOR2 src) {dest[0] = src[0]; dest[1] = src[1]; }
1112 static inline void gcgCOPYVECTOR3(VECTOR3 dest, VECTOR3 src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; }
1113 static inline void gcgCOPYVECTOR3(VECTOR3 dest, VECTOR3d src) { dest[0] = (float) src[0]; dest[1] = (float) src[1]; dest[2] = (float) src[2]; }
1114 static inline void gcgCOPYVECTOR3(VECTOR3d dest, VECTOR3 src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; }
1115 static inline void gcgCOPYVECTOR3(VECTOR3d dest, VECTOR3d src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; }
1116 static inline void gcgCOPYVECTOR4(VECTOR4 dest, VECTOR4 src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; dest[3] = src[3];}
1117 static inline void gcgCOPYVECTOR4(VECTOR4 dest, VECTOR4d src) { dest[0] = (float) src[0]; dest[1] = (float) src[1]; dest[2] = (float) src[2]; dest[3] = (float) src[3];}
1118 static inline void gcgCOPYVECTOR4(VECTOR4d dest, VECTOR4 src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; dest[3] = src[3];}
1119 static inline void gcgCOPYVECTOR4(VECTOR4d dest, VECTOR4d src) { dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2]; dest[3] = src[3];}
1120 
1121 static inline void gcgSCALEVECTOR2(VECTOR2 dest, VECTOR2 v, float factor) { dest[0]=factor*v[0]; (dest)[1]=factor*v[1]; }
1122 static inline void gcgSCALEVECTOR2(VECTOR2d dest, VECTOR2d v, double factor) { dest[0]=factor*v[0]; (dest)[1]=factor*v[1]; }
1123 static inline void gcgSCALEVECTOR3(VECTOR3 dest, VECTOR3 v, float factor) {dest[0]=factor*v[0]; dest[1]=factor*v[1]; dest[2]=factor*v[2];}
1124 static inline void gcgSCALEVECTOR3(VECTOR3d dest, VECTOR3d v, double factor) {dest[0]=factor*v[0]; dest[1]=factor*v[1]; dest[2]=factor*v[2];}
1125 static inline void gcgSCALEVECTOR4(VECTOR4 dest, VECTOR4 v, float factor) {dest[0]=factor*v[0]; dest[1]=factor*v[1]; dest[2]=factor*v[2]; dest[3]=factor*v[3];}
1126 static inline void gcgSCALEVECTOR4(VECTOR4d dest, VECTOR4d v, double factor) {dest[0]=factor*v[0]; dest[1]=factor*v[1]; dest[2]=factor*v[2]; dest[3]=factor*v[3];}
1127 
1128 #define gcgADDVECTOR2(dest,v1,v2) {(dest)[0]=(v1)[0]+(v2)[0]; (dest)[1]=(v1)[1]+(v2)[1]; }
1129 #define gcgADDVECTOR3(dest,v1,v2) {(dest)[0]=(v1)[0]+(v2)[0]; (dest)[1]=(v1)[1]+(v2)[1]; (dest)[2]=(v1)[2]+(v2)[2];}
1130 #define gcgADDVECTOR4(dest,v1,v2) {(dest)[0]=(v1)[0]+(v2)[0]; (dest)[1]=(v1)[1]+(v2)[1]; (dest)[2]=(v1)[2]+(v2)[2]; (dest)[3]=(v1)[3]+(v2)[3];}
1131 
1132 #define gcgSUBVECTOR2(dest, v1, v2) {(dest)[0]=(v1)[0]-(v2)[0]; (dest)[1]=(v1)[1]-(v2)[1]; }
1133 #define gcgSUBVECTOR3(dest, v1, v2) {(dest)[0]=(v1)[0]-(v2)[0]; (dest)[1]=(v1)[1]-(v2)[1]; (dest)[2]=(v1)[2]-(v2)[2];}
1134 #define gcgSUBVECTOR4(dest, v1, v2) {(dest)[0]=(v1)[0]-(v2)[0]; (dest)[1]=(v1)[1]-(v2)[1]; (dest)[2]=(v1)[2]-(v2)[2]; (dest)[3]=(v1)[3]-(v2)[3];}
1135 
1136 // Normalize VECTOR2
1137 static inline void gcgNORMALIZEVECTOR2(VECTOR2 dest, VECTOR2 v) {
1138  register float factor = (float) (1.0 / gcgLENGTHVECTOR2((v)));
1139  gcgSCALEVECTOR2((dest), (v), factor);
1140 }
1141 
1142 static inline void gcgNORMALIZEVECTOR2(VECTOR2d dest, VECTOR2d v) {
1143  register double factor = 1.0 / gcgLENGTHVECTOR2((v));
1144  gcgSCALEVECTOR2((dest), (v), factor);
1145 }
1146 
1147 // Normalize VECTOR3
1148 static inline void gcgNORMALIZEVECTOR3(VECTOR3 dest, VECTOR3 v) {
1149  register float factor = (float) (1.0 / gcgLENGTHVECTOR3((v)));
1150  gcgSCALEVECTOR3((dest), (v), factor);
1151 }
1152 
1153 static inline void gcgNORMALIZEVECTOR3(VECTOR3d dest, VECTOR3d v) {
1154  register double factor = 1.0 / gcgLENGTHVECTOR3((v));
1155  gcgSCALEVECTOR3((dest), (v), factor);
1156 }
1157 
1158 // Normalize VECTOR4
1159 static inline void gcgNORMALIZEVECTOR4(VECTOR4 dest, VECTOR4 v) {
1160  register float factor = (float) (1.0 / gcgLENGTHVECTOR4((v)));
1161  gcgSCALEVECTOR4((dest), (v), factor);
1162 }
1163 
1164 static inline void gcgNORMALIZEVECTOR4(VECTOR4d dest, VECTOR4d v) {
1165  register double factor = 1.0 / gcgLENGTHVECTOR4((v));
1166  gcgSCALEVECTOR4((dest), (v), factor);
1167 }
1168 
1169 
1170 #define gcgCROSSVECTOR3(dest, v1, v2) { \
1171  (dest)[0] = (v1)[1] * (v2)[2] - (v1)[2] * (v2)[1]; \
1172  (dest)[1] = (v1)[2] * (v2)[0] - (v1)[0] * (v2)[2]; \
1173  (dest)[2] = (v1)[0] * (v2)[1] - (v1)[1] * (v2)[0];}
1174 
1175 // Creates a tensor from two vectors: T = v1 * transpose(v2)
1176 #define gcgVECTOR3TOTENSOR(t, v1, v2) { \
1177  (t)[0] = (v1)[0]*(v2)[0]; (t)[1] = (v1)[0]*(v2)[1]; (t)[2] = (v1)[0]*(v2)[2]; \
1178  (t)[3] = (v1)[1]*(v2)[0]; (t)[4] = (v1)[1]*(v2)[1]; (t)[5] = (v1)[1]*(v2)[2]; \
1179  (t)[6] = (v1)[2]*(v2)[0]; (t)[7] = (v1)[2]*(v2)[1]; (t)[8] = (v1)[2]*(v2)[2]; }
1180 
1181 
1183 // MATRIX COMMANDS MACROS
1184 
1185 #define gcgSETMATRIX2(dest, a, b, c, d) { \
1186  (dest)[ 0] = a; (dest)[ 1] = b; (dest)[ 2] = c; (dest)[ 3] = d; }
1187 
1188 #define gcgSETMATRIX3(dest, a, b, c, d, e, f, g, h, i) { \
1189  (dest)[ 0] = a; (dest)[ 1] = b; (dest)[ 2] = c; \
1190  (dest)[ 3] = d; (dest)[ 4] = e; (dest)[ 5] = f; \
1191  (dest)[ 6] = g; (dest)[ 7] = h; (dest)[ 8] = i; }
1192 
1193 #define gcgSETMATRIX4(dest, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) { \
1194  (dest)[ 0] = a; (dest)[ 1] = b; (dest)[ 2] = c; (dest)[ 3] = d; \
1195  (dest)[ 4] = e; (dest)[ 5] = f; (dest)[ 6] = g; (dest)[ 7] = h; \
1196  (dest)[ 8] = i; (dest)[ 9] = j; (dest)[10] = k; (dest)[11] = l; \
1197  (dest)[12] = m; (dest)[13] = n; (dest)[14] = o; (dest)[15] = p; }
1198 
1199 static inline void gcgCOPYMATRIX2(MATRIX2 dest, MATRIX2 m) {
1200  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2]; dest[ 3] = m[ 3];
1201 }
1202 
1203 static inline void gcgCOPYMATRIX2(MATRIX2d dest, MATRIX2d m) {
1204  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2]; dest[ 3] = m[ 3];
1205 }
1206 
1207 static inline void gcgCOPYMATRIX2(MATRIX2d dest, MATRIX2 m) {
1208  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2]; dest[ 3] = m[ 3];
1209 }
1210 
1211 static inline void gcgCOPYMATRIX2(MATRIX2 dest, MATRIX2d m) {
1212  dest[ 0] = (float) m[ 0]; dest[ 1] = (float) m[ 1]; dest[ 2] = (float) m[ 2]; dest[ 3] = (float) m[ 3];
1213 }
1214 
1215 static inline void gcgCOPYMATRIX3(MATRIX3 dest, MATRIX3 m) {
1216  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2];
1217  dest[ 3] = m[ 3]; dest[ 4] = m[ 4]; dest[ 5] = m[ 5];
1218  dest[ 6] = m[ 6]; dest[ 7] = m[ 7]; dest[ 8] = m[ 8];
1219 }
1220 
1221 static inline void gcgCOPYMATRIX3(MATRIX3d dest, MATRIX3d m) {
1222  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2];
1223  dest[ 3] = m[ 3]; dest[ 4] = m[ 4]; dest[ 5] = m[ 5];
1224  dest[ 6] = m[ 6]; dest[ 7] = m[ 7]; dest[ 8] = m[ 8];
1225 }
1226 
1227 static inline void gcgCOPYMATRIX3(MATRIX3d dest, MATRIX3 m) {
1228  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2];
1229  dest[ 3] = m[ 3]; dest[ 4] = m[ 4]; dest[ 5] = m[ 5];
1230  dest[ 6] = m[ 6]; dest[ 7] = m[ 7]; dest[ 8] = m[ 8];
1231 }
1232 
1233 static inline void gcgCOPYMATRIX3(MATRIX3 dest, MATRIX3d m) {
1234  dest[ 0] = (float) m[ 0]; dest[ 1] = (float) m[ 1]; dest[ 2] = (float) m[ 2];
1235  dest[ 3] = (float) m[ 3]; dest[ 4] = (float) m[ 4]; dest[ 5] = (float) m[ 5];
1236  dest[ 6] = (float) m[ 6]; dest[ 7] = (float) m[ 7]; dest[ 8] = (float) m[ 8];
1237 }
1238 
1239 
1240 static inline void gcgCOPYMATRIX4(MATRIX4 dest, MATRIX4 m) {
1241  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2]; dest[ 3] = m[ 3];
1242  dest[ 4] = m[ 4]; dest[ 5] = m[ 5]; dest[ 6] = m[ 6]; dest[ 7] = m[ 7];
1243  dest[ 8] = m[ 8]; dest[ 9] = m[ 9]; dest[10] = m[10]; dest[11] = m[11];
1244  dest[12] = m[12]; dest[13] = m[13]; dest[14] = m[14]; dest[15] = m[15];
1245 }
1246 
1247 static inline void gcgCOPYMATRIX4(MATRIX4d dest, MATRIX4 m) {
1248  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2]; dest[ 3] = m[ 3];
1249  dest[ 4] = m[ 4]; dest[ 5] = m[ 5]; dest[ 6] = m[ 6]; dest[ 7] = m[ 7];
1250  dest[ 8] = m[ 8]; dest[ 9] = m[ 9]; dest[10] = m[10]; dest[11] = m[11];
1251  dest[12] = m[12]; dest[13] = m[13]; dest[14] = m[14]; dest[15] = m[15];
1252 }
1253 
1254 static inline void gcgCOPYMATRIX4(MATRIX4d dest, MATRIX4d m) {
1255  dest[ 0] = m[ 0]; dest[ 1] = m[ 1]; dest[ 2] = m[ 2]; dest[ 3] = m[ 3];
1256  dest[ 4] = m[ 4]; dest[ 5] = m[ 5]; dest[ 6] = m[ 6]; dest[ 7] = m[ 7];
1257  dest[ 8] = m[ 8]; dest[ 9] = m[ 9]; dest[10] = m[10]; dest[11] = m[11];
1258  dest[12] = m[12]; dest[13] = m[13]; dest[14] = m[14]; dest[15] = m[15];
1259 }
1260 
1261 static inline void gcgCOPYMATRIX4(MATRIX4 dest, MATRIX4d m) {
1262  dest[ 0] = (float) m[ 0]; dest[ 1] = (float) m[ 1]; dest[ 2] = (float) m[ 2]; dest[ 3] = (float) m[ 3];
1263  dest[ 4] = (float) m[ 4]; dest[ 5] = (float) m[ 5]; dest[ 6] = (float) m[ 6]; dest[ 7] = (float) m[ 7];
1264  dest[ 8] = (float) m[ 8]; dest[ 9] = (float) m[ 9]; dest[10] = (float) m[10]; dest[11] = (float) m[11];
1265  dest[12] = (float) m[12]; dest[13] = (float) m[13]; dest[14] = (float) m[14]; dest[15] = (float) m[15];
1266 }
1267 
1268 #define gcgIDENTITYMATRIX2(matriz) { \
1269  (matriz)[0] = (matriz)[3] = 1.f; \
1270  (matriz)[1] = (matriz)[2] = 0.0f; }
1271 
1272 #define gcgIDENTITYMATRIX3(matriz) { \
1273  (matriz)[0] = (matriz)[4] = (matriz)[8] = 1.f; \
1274  (matriz)[1] = (matriz)[2] = (matriz)[3] = (matriz)[5] = (matriz)[6] = (matriz)[7] = 0.0f; }
1275 
1276 #define gcgIDENTITYMATRIX4(matriz) { \
1277  (matriz)[0] = (matriz)[5] = (matriz)[10] = (matriz)[15] = 1.f; \
1278  (matriz)[1] = (matriz)[2] = (matriz)[3] = (matriz)[4] = (matriz)[6] = (matriz)[7] = \
1279  (matriz)[8] = (matriz)[9] = (matriz)[11] = (matriz)[12] = (matriz)[13] = (matriz)[14] = 0.f; }
1280 
1281 //Transpose matrix 3x3
1282 #define gcgTRANSPOSEMATRIX3(tm, m) { \
1283  (tm)[ 0] = (m)[0]; (tm)[1] = (m)[3]; (tm)[2] = (m)[6]; \
1284  (tm)[ 3] = (m)[1]; (tm)[4] = (m)[4]; (tm)[5] = (m)[7]; \
1285  (tm)[ 6] = (m)[2]; (tm)[7] = (m)[5]; (tm)[8] = (m)[8]; }
1286 
1287 //Transpose matrix 4x4
1288 #define gcgTRANSPOSEMATRIX4(tm, m) { \
1289  (tm)[ 0] = (m)[ 0]; (tm)[ 1] = (m)[ 4]; (tm)[ 2] = (m)[ 8]; (tm)[ 3] = (m)[12]; \
1290  (tm)[ 4] = (m)[ 1]; (tm)[ 5] = (m)[ 5]; (tm)[ 6] = (m)[ 9]; (tm)[ 7] = (m)[13]; \
1291  (tm)[ 8] = (m)[ 2]; (tm)[ 9] = (m)[ 6]; (tm)[10] = (m)[10]; (tm)[11] = (m)[14]; \
1292  (tm)[12] = (m)[ 3]; (tm)[13] = (m)[ 7]; (tm)[14] = (m)[11]; (tm)[15] = (m)[15]; }
1293 
1294 // Scale matrix 2x2
1295 #define gcgSCALEMATRIX2(dest, m, s) \
1296  {(dest)[0] = (m)[0] * (s); (dest)[1] = (m)[1] * (s); (dest)[2] = (m)[2] * (s); (dest)[3] = (m)[3] * (s); }
1297 
1298 // Scale matrix 3x3
1299 #define gcgSCALEMATRIX3(dest, m, s) { \
1300  (dest)[0] = (m)[0] * (s); (dest)[1] = (m)[1] * (s); (dest)[2] = (m)[2] * (s); \
1301  (dest)[3] = (m)[3] * (s); (dest)[4] = (m)[4] * (s); (dest)[5] = (m)[5] * (s); \
1302  (dest)[6] = (m)[6] * (s); (dest)[7] = (m)[7] * (s); (dest)[8] = (m)[8] * (s); }
1303 
1304 // Scale matrix 4x4
1305 #define gcgSCALEMATRIX4(dest, m, s) { \
1306  (dest)[ 0] = (m)[ 0] * (s); (dest)[ 1] = (m)[ 1] * (s); (dest)[ 2] = (m)[ 2] * (s); (dest)[ 3] = (m)[ 3] * (s); \
1307  (dest)[ 4] = (m)[ 4] * (s); (dest)[ 5] = (m)[ 5] * (s); (dest)[ 6] = (m)[ 6] * (s); (dest)[ 7] = (m)[ 7] * (s); \
1308  (dest)[ 8] = (m)[ 8] * (s); (dest)[ 9] = (m)[ 9] * (s); (dest)[10] = (m)[10] * (s); (dest)[11] = (m)[11] * (s); \
1309  (dest)[12] = (m)[12] * (s); (dest)[13] = (m)[13] * (s); (dest)[14] = (m)[14] * (s); (dest)[15] = (m)[15] * (s); }
1310 
1311 // Additions and subtractions
1312 #define gcgADDMATRIX2(dest, m1, m2) { \
1313  (dest)[ 0] = (m1)[ 0] + (m2)[ 0]; (dest)[ 1] = (m1)[ 1] + (m2)[ 1]; \
1314  (dest)[ 2] = (m1)[ 2] + (m2)[ 2]; (dest)[ 3] = (m1)[ 3] + (m2)[ 3]; }
1315 
1316 #define gcgADDMATRIX3(dest, m1, m2) { \
1317  (dest)[ 0] = (m1)[ 0] + (m2)[ 0]; (dest)[ 1] = (m1)[ 1] + (m2)[ 1]; (dest)[ 2] = (m1)[ 2] + (m2)[ 2]; \
1318  (dest)[ 3] = (m1)[ 3] + (m2)[ 3]; (dest)[ 4] = (m1)[ 4] + (m2)[ 4]; (dest)[ 5] = (m1)[ 5] + (m2)[ 5]; \
1319  (dest)[ 6] = (m1)[ 6] + (m2)[ 6]; (dest)[ 7] = (m1)[ 7] + (m2)[ 7]; (dest)[ 8] = (m1)[ 8] + (m2)[ 8]; }
1320 
1321 #define gcgADDMATRIX4(dest, m1, m2) { \
1322  (dest)[ 0] = (m1)[ 0] + (m2)[ 0]; (dest)[ 1] = (m1)[ 1] + (m2)[ 1]; (dest)[ 2] = (m1)[ 2] + (m2)[ 2]; (dest)[ 3] = (m1)[ 3] + (m2)[ 3]; \
1323  (dest)[ 4] = (m1)[ 4] + (m2)[ 4]; (dest)[ 5] = (m1)[ 5] + (m2)[ 5]; (dest)[ 6] = (m1)[ 6] + (m2)[ 6]; (dest)[ 7] = (m1)[ 7] + (m2)[ 7]; \
1324  (dest)[ 8] = (m1)[ 8] + (m2)[ 8]; (dest)[ 9] = (m1)[ 9] + (m2)[ 9]; (dest)[10] = (m1)[10] + (m2)[10]; (dest)[11] = (m1)[11] + (m2)[11]; \
1325  (dest)[12] = (m1)[12] + (m2)[12]; (dest)[13] = (m1)[13] + (m2)[13]; (dest)[14] = (m1)[14] + (m2)[14]; (dest)[15] = (m1)[15] + (m2)[15]; }
1326 
1327 #define gcgSUBMATRIX2(dest, m1, m2) { \
1328  (dest)[ 0] = (m1)[ 0] - (m2)[ 0]; (dest)[ 1] = (m1)[ 1] - (m2)[ 1]; \
1329  (dest)[ 2] = (m1)[ 2] - (m2)[ 2]; (dest)[ 3] = (m1)[ 3] - (m2)[ 3]; }
1330 
1331 #define gcgSUBMATRIX3(dest, m1, m2) { \
1332  (dest)[ 0] = (m1)[ 0] - (m2)[ 0]; (dest)[ 1] = (m1)[ 1] - (m2)[ 1]; (dest)[ 2] = (m1)[ 2] - (m2)[ 2]; \
1333  (dest)[ 3] = (m1)[ 3] - (m2)[ 3]; (dest)[ 4] = (m1)[ 4] - (m2)[ 4]; (dest)[ 5] = (m1)[ 5] - (m2)[ 5]; \
1334  (dest)[ 6] = (m1)[ 6] - (m2)[ 6]; (dest)[ 7] = (m1)[ 7] - (m2)[ 7]; (dest)[ 8] = (m1)[ 8] - (m2)[ 8]; }
1335 
1336 #define gcgSUBMATRIX4(dest, m1, m2) { \
1337  (dest)[ 0] = (m1)[ 0] - (m2)[ 0]; (dest)[ 1] = (m1)[ 1] - (m2)[ 1]; (dest)[ 2] = (m1)[ 2] - (m2)[ 2]; (dest)[ 3] = (m1)[ 3] - (m2)[ 3]; \
1338  (dest)[ 4] = (m1)[ 4] - (m2)[ 4]; (dest)[ 5] = (m1)[ 5] - (m2)[ 5]; (dest)[ 6] = (m1)[ 6] - (m2)[ 6]; (dest)[ 7] = (m1)[ 7] - (m2)[ 7]; \
1339  (dest)[ 8] = (m1)[ 8] - (m2)[ 8]; (dest)[ 9] = (m1)[ 9] - (m2)[ 9]; (dest)[10] = (m1)[10] - (m2)[10]; (dest)[11] = (m1)[11] - (m2)[11]; \
1340  (dest)[12] = (m1)[12] - (m2)[12]; (dest)[13] = (m1)[13] - (m2)[13]; (dest)[14] = (m1)[14] - (m2)[14]; (dest)[15] = (m1)[15] - (m2)[15]; }
1341 
1342 //Multiply matrix 3x3
1343 #define gcgMULTMATRIX3(result, m1, m2) { \
1344  (result)[ 0] = (m1)[ 0] * (m2)[ 0] + (m1)[ 1] * (m2)[ 3] + (m1)[ 2] * (m2)[ 6]; \
1345  (result)[ 1] = (m1)[ 0] * (m2)[ 1] + (m1)[ 1] * (m2)[ 4] + (m1)[ 2] * (m2)[ 7]; \
1346  (result)[ 2] = (m1)[ 0] * (m2)[ 2] + (m1)[ 1] * (m2)[ 5] + (m1)[ 2] * (m2)[ 8]; \
1347  (result)[ 3] = (m1)[ 3] * (m2)[ 0] + (m1)[ 4] * (m2)[ 3] + (m1)[ 5] * (m2)[ 6]; \
1348  (result)[ 4] = (m1)[ 3] * (m2)[ 1] + (m1)[ 4] * (m2)[ 4] + (m1)[ 5] * (m2)[ 7]; \
1349  (result)[ 5] = (m1)[ 3] * (m2)[ 2] + (m1)[ 4] * (m2)[ 5] + (m1)[ 5] * (m2)[ 8]; \
1350  (result)[ 6] = (m1)[ 6] * (m2)[ 0] + (m1)[ 7] * (m2)[ 3] + (m1)[ 8] * (m2)[ 6]; \
1351  (result)[ 7] = (m1)[ 6] * (m2)[ 1] + (m1)[ 7] * (m2)[ 4] + (m1)[ 8] * (m2)[ 7]; \
1352  (result)[ 8] = (m1)[ 6] * (m2)[ 2] + (m1)[ 7] * (m2)[ 5] + (m1)[ 8] * (m2)[ 8]; }
1353 
1354 // Multiplica as matrizes 4x4 m1 e m2 sem utilizar laco
1355 #define gcgMULTMATRIX4(result, m1, m2) { \
1356  (result)[ 0] = (m1)[ 0] * (m2)[ 0] + (m1)[ 1] * (m2)[ 4] + (m1)[ 2] * (m2)[ 8] + (m1)[ 3] * (m2)[12]; \
1357  (result)[ 1] = (m1)[ 0] * (m2)[ 1] + (m1)[ 1] * (m2)[ 5] + (m1)[ 2] * (m2)[ 9] + (m1)[ 3] * (m2)[13]; \
1358  (result)[ 2] = (m1)[ 0] * (m2)[ 2] + (m1)[ 1] * (m2)[ 6] + (m1)[ 2] * (m2)[10] + (m1)[ 3] * (m2)[14]; \
1359  (result)[ 3] = (m1)[ 0] * (m2)[ 3] + (m1)[ 1] * (m2)[ 7] + (m1)[ 2] * (m2)[11] + (m1)[ 3] * (m2)[15]; \
1360  (result)[ 4] = (m1)[ 4] * (m2)[ 0] + (m1)[ 5] * (m2)[ 4] + (m1)[ 6] * (m2)[ 8] + (m1)[ 7] * (m2)[12]; \
1361  (result)[ 5] = (m1)[ 4] * (m2)[ 1] + (m1)[ 5] * (m2)[ 5] + (m1)[ 6] * (m2)[ 9] + (m1)[ 7] * (m2)[13]; \
1362  (result)[ 6] = (m1)[ 4] * (m2)[ 2] + (m1)[ 5] * (m2)[ 6] + (m1)[ 6] * (m2)[10] + (m1)[ 7] * (m2)[14]; \
1363  (result)[ 7] = (m1)[ 4] * (m2)[ 3] + (m1)[ 5] * (m2)[ 7] + (m1)[ 6] * (m2)[11] + (m1)[ 7] * (m2)[15]; \
1364  (result)[ 8] = (m1)[ 8] * (m2)[ 0] + (m1)[ 9] * (m2)[ 4] + (m1)[10] * (m2)[ 8] + (m1)[11] * (m2)[12]; \
1365  (result)[ 9] = (m1)[ 8] * (m2)[ 1] + (m1)[ 9] * (m2)[ 5] + (m1)[10] * (m2)[ 9] + (m1)[11] * (m2)[13]; \
1366  (result)[10] = (m1)[ 8] * (m2)[ 2] + (m1)[ 9] * (m2)[ 6] + (m1)[10] * (m2)[10] + (m1)[11] * (m2)[14]; \
1367  (result)[11] = (m1)[ 8] * (m2)[ 3] + (m1)[ 9] * (m2)[ 7] + (m1)[10] * (m2)[11] + (m1)[11] * (m2)[15]; \
1368  (result)[12] = (m1)[12] * (m2)[ 0] + (m1)[13] * (m2)[ 4] + (m1)[14] * (m2)[ 8] + (m1)[15] * (m2)[12]; \
1369  (result)[13] = (m1)[12] * (m2)[ 1] + (m1)[13] * (m2)[ 5] + (m1)[14] * (m2)[ 9] + (m1)[15] * (m2)[13]; \
1370  (result)[14] = (m1)[12] * (m2)[ 2] + (m1)[13] * (m2)[ 6] + (m1)[14] * (m2)[10] + (m1)[15] * (m2)[14]; \
1371  (result)[15] = (m1)[12] * (m2)[ 3] + (m1)[13] * (m2)[ 7] + (m1)[14] * (m2)[11] + (m1)[15] * (m2)[15]; }
1372 
1373 // Multiply the 3x4 affine matrices m1 e m2.
1374 #define gcgMULTMATRIX34(result, m1, m2) { \
1375  (result)[0] = (m1)[0] * (m2)[0] + (m1)[1] * (m2)[4] + (m1)[2] * (m2)[8]; \
1376  (result)[1] = (m1)[0] * (m2)[1] + (m1)[1] * (m2)[5] + (m1)[2] * (m2)[9]; \
1377  (result)[2] = (m1)[0] * (m2)[2] + (m1)[1] * (m2)[6] + (m1)[2] * (m2)[10]; \
1378  (result)[3] = (m1)[0] * (m2)[3] + (m1)[1] * (m2)[7] + (m1)[2] * (m2)[11] + (m1)[3]; \
1379  (result)[4] = (m1)[4] * (m2)[0] + (m1)[5] * (m2)[4] + (m1)[6] * (m2)[8]; \
1380  (result)[5] = (m1)[4] * (m2)[1] + (m1)[5] * (m2)[5] + (m1)[6] * (m2)[9]; \
1381  (result)[6] = (m1)[4] * (m2)[2] + (m1)[5] * (m2)[6] + (m1)[6] * (m2)[10]; \
1382  (result)[7] = (m1)[4] * (m2)[3] + (m1)[5] * (m2)[7] + (m1)[6] * (m2)[11] + (m1)[7]; \
1383  (result)[8] = (m1)[8] * (m2)[0] + (m1)[9] * (m2)[4] + (m1)[10] * (m2)[8]; \
1384  (result)[9] = (m1)[8] * (m2)[1] + (m1)[9] * (m2)[5] + (m1)[10] * (m2)[9]; \
1385  (result)[10] = (m1)[8] * (m2)[2] + (m1)[9] * (m2)[6] + (m1)[10] * (m2)[10]; \
1386  (result)[11] = (m1)[8] * (m2)[3] + (m1)[9] * (m2)[7] + (m1)[10] * (m2)[11] + (m1)[11]; }
1387 
1388 
1389 //Multiply a 3x1 vector by a 1x3 vector resulting in a 3x3 matrix
1390 #define gcgMATRIX3VECTOR3VECTOR3(result, v1, v2) { \
1391  (result)[0] = (v1)[0] * (v2)[0]; (result)[1] = (v1)[0] * (v2)[1]; (result)[2] = (v1)[0] * (v2)[2]; \
1392  (result)[3] = (v1)[1] * (v2)[0]; (result)[4] = (v1)[1] * (v2)[1]; (result)[5] = (v1)[1] * (v2)[2]; \
1393  (result)[6] = (v1)[2] * (v2)[0]; (result)[7] = (v1)[2] * (v2)[1]; (result)[8] = (v1)[2] * (v2)[2]; }
1394 
1395 
1396 #define gcgAPPLYMATRIX3VECTOR3(r, t, vetor) { \
1397  (r)[0] = (vetor)[0] * (t)[0] + (vetor)[1] * (t)[1] + (vetor)[2] * (t)[2]; \
1398  (r)[1] = (vetor)[0] * (t)[3] + (vetor)[1] * (t)[4] + (vetor)[2] * (t)[5]; \
1399  (r)[2] = (vetor)[0] * (t)[6] + (vetor)[1] * (t)[7] + (vetor)[2] * (t)[8]; }
1400 
1401 
1402 #define gcgAPPLYMATRIX4VECTOR4(r, t, vetor) { \
1403  (r)[0] = (vetor)[0] * (t)[0] + (vetor)[1] * (t)[1] + (vetor)[2] * (t)[2] + (vetor)[3] * (t)[3]; \
1404  (r)[1] = (vetor)[0] * (t)[4] + (vetor)[1] * (t)[5] + (vetor)[2] * (t)[6] + (vetor)[3] * (t)[7]; \
1405  (r)[2] = (vetor)[0] * (t)[8] + (vetor)[1] * (t)[9] + (vetor)[2] * (t)[10] + (vetor)[3] * (t)[11]; \
1406  (r)[3] = (vetor)[0] * (t)[12] + (vetor)[1] * (t)[13] + (vetor)[2] * (t)[14] + (vetor)[3] * (t)[15]; }
1407 
1408 #define gcgAPPLYMATRIX34VECTOR3(r, t, vetor) { \
1409  (r)[0] = (vetor)[0] * (t)[0] + (vetor)[1] * (t)[1] + (vetor)[2] * (t)[2] + (t)[3]; \
1410  (r)[1] = (vetor)[0] * (t)[4] + (vetor)[1] * (t)[5] + (vetor)[2] * (t)[6] + (t)[7]; \
1411  (r)[2] = (vetor)[0] * (t)[8] + (vetor)[1] * (t)[9] + (vetor)[2] * (t)[10] + (t)[11]; }
1412 
1413 #define gcgLINEARMATRIX4VECTOR3(r, t, vetor) { \
1414  (r)[0] = (vetor)[0] * (t)[0] + (vetor)[1] * (t)[1] + (vetor)[2] * (t)[2]; \
1415  (r)[1] = (vetor)[0] * (t)[4] + (vetor)[1] * (t)[5] + (vetor)[2] * (t)[6]; \
1416  (r)[2] = (vetor)[0] * (t)[8] + (vetor)[1] * (t)[9] + (vetor)[2] * (t)[10]; }
1417 
1418 // QUATERNION ALGEBRA ///////////////////////////////////////////////
1419 
1420 // Expressions //////////////////////////////////////////////////////
1421 // Commands /////////////////////////////////////////////////////////
1422 
1423 // Makes an unit quaternion
1424 #define gcgNORMALIZEQUATERNION(qf, q) { \
1425  register double mag = 1.0/(q[0]*q[0] + q[1]*q[1] + q[2]*q[2] + q[3]*q[3]); \
1426  gcgSCALEVECTOR3(qf, q, mag); }
1427 
1428 // Quaternion conjugate
1429 #define gcgCONJUGATEQUATERNION(qi, q) { \
1430  (qi)[0] = -(q)[0]; \
1431  (qi)[1] = -(q)[1]; \
1432  (qi)[2] = -(q)[2]; \
1433  (qi)[3] = (q)[3]; }
1434 
1435 
1436 // Multiply two quaternions (Graham's product)
1437 static inline void gcgMULTQUATERNION(VECTOR4 dest, VECTOR4 q2, VECTOR4 q1) {
1438  VECTOR4 t1;
1439  t1[3] = (q1)[3]*(q2)[3] - (q1)[0]*(q2)[0] - (q1)[1]*(q2)[1] - (q1)[2]*(q2)[2];
1440  t1[0] = (q1)[3]*(q2)[0] + (q1)[0]*(q2)[3] + (q1)[1]*(q2)[2] - (q1)[2]*(q2)[1];
1441  t1[1] = (q1)[3]*(q2)[1] + (q1)[1]*(q2)[3] + (q1)[2]*(q2)[0] - (q1)[0]*(q2)[2];
1442  t1[2] = (q1)[3]*(q2)[2] + (q1)[2]*(q2)[3] + (q1)[0]*(q2)[1] - (q1)[1]*(q2)[0];
1443  gcgCOPYVECTOR4(dest, t1);
1444 }
1445 
1446 static inline void gcgMULTQUATERNION(VECTOR4d dest, VECTOR4d q2, VECTOR4d q1) {
1447  VECTOR4d t1;
1448  t1[3] = (q1)[3]*(q2)[3] - (q1)[0]*(q2)[0] - (q1)[1]*(q2)[1] - (q1)[2]*(q2)[2];
1449  t1[0] = (q1)[3]*(q2)[0] + (q1)[0]*(q2)[3] + (q1)[1]*(q2)[2] - (q1)[2]*(q2)[1];
1450  t1[1] = (q1)[3]*(q2)[1] + (q1)[1]*(q2)[3] + (q1)[2]*(q2)[0] - (q1)[0]*(q2)[2];
1451  t1[2] = (q1)[3]*(q2)[2] + (q1)[2]*(q2)[3] + (q1)[0]*(q2)[1] - (q1)[1]*(q2)[0];
1452  gcgCOPYVECTOR4(dest, t1);
1453 }
1454 
1455 // Build a 4x4 rotation matrix from a quaternion
1456 static inline void gcgQUATERNIONTOMATRIX4(MATRIX4 m, VECTOR4 q) {
1457  register double xx = (q)[0] * (q)[0], yy = (q)[1] * (q)[1], zz = (q)[2] * (q)[2];
1458  register double xy = (q)[0] * (q)[1], xz = (q)[0] * (q)[2], yz = (q)[1] * (q)[2];
1459  register double xw = (q)[0] * (q)[3], yw = (q)[1] * (q)[3], zw = (q)[2] * (q)[3];
1460  m[0] = (float) (1.0 - (yy + yy + zz + zz));
1461  m[1] = (float) (xy + xy - zw - zw);
1462  m[2] = (float) (xz + xz + yw + yw);
1463  m[3] = 0.0f;
1464  m[4] = (float) (xy + xy + zw + zw);
1465  m[5] = (float) (1.0 - (zz + zz + xx + xx));
1466  m[6] = (float) (yz + yz - xw - xw);
1467  m[7] = 0.0f;
1468  m[8] = (float) (xz + xz - yw - yw);
1469  m[9] = (float) (yz + yz + xw + xw);
1470  m[10] = (float) (1.0 - (yy + yy + xx + xx));
1471  m[11] = m[12] = m[13] = m[14] = 0.0f;
1472  m[15] = 1.0f;
1473 }
1474 
1475 // Build a 4x4 rotation matrix from a quaternion
1476 static inline void gcgQUATERNIONTOMATRIX4(MATRIX4d m, VECTOR4d q) {
1477  register double xx = (q)[0] * (q)[0], yy = (q)[1] * (q)[1], zz = (q)[2] * (q)[2];
1478  register double xy = (q)[0] * (q)[1], xz = (q)[0] * (q)[2], yz = (q)[1] * (q)[2];
1479  register double xw = (q)[0] * (q)[3], yw = (q)[1] * (q)[3], zw = (q)[2] * (q)[3];
1480  m[0] = (1.0 - (yy + yy + zz + zz));
1481  m[1] = (xy + xy - zw - zw);
1482  m[2] = (xz + xz + yw + yw);
1483  m[3] = 0.0;
1484  m[4] = (xy + xy + zw + zw);
1485  m[5] = (1.0 - (zz + zz + xx + xx));
1486  m[6] = (yz + yz - xw - xw);
1487  m[7] = 0.0;
1488  m[8] = (xz + xz - yw - yw);
1489  m[9] = (yz + yz + xw + xw);
1490  m[10] = (1.0 - (yy + yy + xx + xx));
1491  m[11] = m[12] = m[13] = m[14] = 0.0f;
1492  m[15] = 1.0f;
1493 }
1494 
1495 // Build a quaternion that forms a rotation around an axis
1496 static inline void gcgAXISTOQUATERNION(VECTOR4 q, float phi, VECTOR3 a) {
1497  gcgSCALEVECTOR3(q, a, sinf(phi * 0.5f));
1498  q[3] = cosf(phi * 0.5f);
1499 }
1500 
1501 static inline void gcgAXISTOQUATERNION(VECTOR4d q, double phi, VECTOR3d a) {
1502  register double factor = sin(phi * 0.5);
1503  gcgSCALEVECTOR3(q, a, factor);
1504  q[3] = cos(phi * 0.5);
1505 }
1506 
1507 
1508 // Obtains the angle and rotation axis from a quaternion
1509 #define gcgQUATERNIONTOAXIS(angle, a, q) { \
1510  register double cos_a = q[3]; \
1511  angle = acos(cos_a) * 2; \
1512  register double sin_a = sqrt(1.0 - cos_a * cos_a ); \
1513  if(fabs(sin_a) < 0.0005) sin_a = 1.0; \
1514  gcgSETVECTOR3(a, q[0] / sin_a, q[1] / sin_a, q[2] / sin_a); }
1515 
1516 
1517 
1518 // Build a 3x3 rotation matrix from a quaternion
1519 #define gcgQUATERNIONTOMATRIX3(m, q) { \
1520  register double xx = (q)[0] * (q)[0], yy = (q)[1] * (q)[1], zz = (q)[2] * (q)[2];\
1521  register double xy = (q)[0] * (q)[1], xz = (q)[0] * (q)[2], yz = (q)[1] * (q)[2];\
1522  register double xw = (q)[0] * (q)[3], yw = (q)[1] * (q)[3], zw = (q)[2] * (q)[3];\
1523  m[0] = (1.0 - 2.0 * ( yy + zz)); \
1524  m[1] = (2.0 * (xy - zw)); \
1525  m[2] = (2.0 * (xz + yw)); \
1526  m[3] = (2.0 * (xy + zw)); \
1527  m[4] = (1.0 - 2.0 * (zz + xx)); \
1528  m[5] = (2.0 * (yz - xw)); \
1529  m[6] = (2.0 * (xz - yw)); \
1530  m[7] = (2.0 * (yz + xw)); \
1531  m[8] = (1.0 - 2.0 * (yy + xx)); }
1532 
1533 // Build a 3x4 rotation matrix from a quaternion
1534 #define gcgQUATERNIONTOMATRIX34(m, q) { \
1535  register double xx = (q)[0] * (q)[0], yy = (q)[1] * (q)[1], zz = (q)[2] * (q)[2];\
1536  register double xy = (q)[0] * (q)[1], xz = (q)[0] * (q)[2], yz = (q)[1] * (q)[2];\
1537  register double xw = (q)[0] * (q)[3], yw = (q)[1] * (q)[3], zw = (q)[2] * (q)[3];\
1538  m[0] = (1.0 - 2.0 * ( yy + zz)); \
1539  m[1] = (2.0 * (xy - zw)); \
1540  m[2] = (2.0 * (xz + yw)); \
1541  m[3] = 0.0; \
1542  m[4] = (2.0 * (xy + zw)); \
1543  m[5] = (1.0 - 2.0 * (zz + xx)); \
1544  m[6] = (2.0 * (yz - xw)); \
1545  m[7] = 0.0; \
1546  m[8] = (2.0 * (xz - yw)); \
1547  m[9] = (2.0 * (yz + xw)); \
1548  m[10] = (1.0 - 2.0 * (yy + xx)); \
1549  m[11] = 0.0; }
1550 
1551 
1552 // Build a quaternion from a 4x4 rotation matrix
1553 #define gcgMATRIX4TOQUATERNION(q, mat) { \
1554  register double trace = 1.0 + (mat)[0] + (mat)[5] + (mat)[10]; \
1555  if(trace > EPSILON) { \
1556  double S = sqrt(trace) * 2.0; \
1557  (q)[0] = ((mat)[9] - (mat)[6]) / S; \
1558  (q)[1] = ((mat)[2] - (mat)[8]) / S; \
1559  (q)[2] = ((mat)[4] - (mat)[1]) / S; \
1560  (q)[3] = 0.25 * S; \
1561  } else \
1562  if((mat)[0] > (mat)[5] && (mat)[0] > (mat)[10]) { \
1563  double S = sqrt(1.0 + (mat)[0] - (mat)[5] - (mat)[10]) * 2.0; \
1564  (q)[0] = 0.25 * S; \
1565  (q)[1] = ((mat)[4] + (mat)[1] ) / S; \
1566  (q)[2] = ((mat)[2] + (mat)[8] ) / S; \
1567  (q)[3] = ((mat)[9] - (mat)[6] ) / S; \
1568  } else if((mat)[5] > (mat)[10]) { \
1569  double S = sqrt(1.0 + (mat)[5] - (mat)[0] - (mat)[10] ) * 2.0; \
1570  (q)[0] = ((mat)[4] + (mat)[1] ) / S; \
1571  (q)[1] = 0.25 * S; \
1572  (q)[2] = ((mat)[9] + (mat)[6] ) / S; \
1573  (q)[3] = ((mat)[2] - (mat)[8] ) / S; \
1574  } else { \
1575  double S = sqrt(1.0 + (mat)[10] - (mat)[0] - (mat)[5] ) * 2.0; \
1576  (q)[0] = ((mat)[2] + (mat)[8] ) / S; \
1577  (q)[1] = ((mat)[9] + (mat)[6] ) / S; \
1578  (q)[2] = 0.25 * S; \
1579  (q)[3] = ((mat)[4] - (mat)[1] ) / S; \
1580  } \
1581  gcgNORMALIZEQUATERNION(q, q); }
1582 
1583 
1584 //Diadic tensor product of two 3D vectors
1585 #define gcgTENSORPRODUCT3(result, v1, v2) { \
1586  (result)[ 0] = (v1)[ 0] * (v2)[ 0]; \
1587  (result)[ 1] = (v1)[ 0] * (v2)[ 1]; \
1588  (result)[ 2] = (v1)[ 0] * (v2)[ 2]; \
1589  (result)[ 3] = (v1)[ 1] * (v2)[ 0]; \
1590  (result)[ 4] = (v1)[ 1] * (v2)[ 1]; \
1591  (result)[ 5] = (v1)[ 1] * (v2)[ 2]; \
1592  (result)[ 6] = (v1)[ 2] * (v2)[ 0]; \
1593  (result)[ 7] = (v1)[ 2] * (v2)[ 1]; \
1594  (result)[ 8] = (v1)[ 2] * (v2)[ 2]; }
1595 
1596 
1597 
1598 // Build a quaternion from Euler angles
1599 static inline void gcgEULERTOQUATERNION(VECTOR4 q, float pitch, float yaw, float roll) {
1600  VECTOR4 qx = {sinf(pitch * -0.5f), 0.0f, 0.0f, cosf(pitch * -0.5f)};
1601  VECTOR4 qy = {0.0f, sinf(yaw * -0.5f), 0.0f, cosf(yaw * -0.5f)};
1602  VECTOR4 qz = {0.0f, 0.0f, sinf(roll * -0.5f), cosf(roll * -0.5f)};
1603  gcgMULTQUATERNION(qy, qy, qx);
1604  gcgMULTQUATERNION(q, qz, qy);
1605 }
1606 
1607 static inline void gcgEULERTOQUATERNION(VECTOR4d q, double pitch, double yaw, double roll) {
1608  VECTOR4d qx = {sin(pitch * -0.5), 0, 0, cos(pitch * -0.5)};
1609  VECTOR4d qy = {0, sin(yaw * -0.5), 0, cos(yaw * -0.5)};
1610  VECTOR4d qz = {0, 0, sin(roll * -0.5), cos(roll * -0.5)};
1611  gcgMULTQUATERNION(qy, qy, qx);
1612  gcgMULTQUATERNION(q, qz, qy);
1613 }
1614 
1615 
1616 // Vector rotation by quaternion application: vi = qr * v * qr-1
1617 static inline void gcgAPPLYQUATERNIONVECTOR3(VECTOR4 vi, VECTOR4 qr, VECTOR3 va) {
1618  VECTOR4 qi, kr;
1619  gcgCONJUGATEQUATERNION(qi, qr);
1620  gcgCOPYVECTOR3((float*) kr, va);
1621  (kr)[3] = 0.0;
1622  gcgMULTQUATERNION(kr, qr, kr);
1623  gcgMULTQUATERNION(kr, kr, qi);
1624  gcgCOPYVECTOR3(vi, kr);
1625 }
1626 
1627 static inline void gcgAPPLYQUATERNIONVECTOR3(VECTOR4d vi, VECTOR4d qr, VECTOR3d va) {
1628  VECTOR4d qi, kr;
1629  gcgCONJUGATEQUATERNION(qi, qr);
1630  gcgCOPYVECTOR3((double*) kr, va);
1631  (kr)[3] = 0.0;
1632  gcgMULTQUATERNION(kr, qr, kr);
1633  gcgMULTQUATERNION(kr, kr, qi);
1634  gcgCOPYVECTOR3(vi, kr);
1635 }
1636 
1638 // FUNCTION PROTOTYPES
1640 
1641 
1645 
1647 
1648 
1659 GCG_API_FUNCTION bool gcgInverseMatrix2(MATRIX2 inverse, MATRIX2 matrix);
1660 
1670 GCG_API_FUNCTION bool gcgInverseMatrix3(MATRIX3 inverse, MATRIX3 matrix);
1671 
1682 GCG_API_FUNCTION bool gcgInverseMatrix4(MATRIX4 inverse, MATRIX4 matrix);
1683 
1694 GCG_API_FUNCTION bool gcgInverseMatrix2(MATRIX2d inverse, MATRIX2d matrix);
1695 
1705 GCG_API_FUNCTION bool gcgInverseMatrix3(MATRIX3d inverse, MATRIX3d matrix);
1706 
1717 GCG_API_FUNCTION bool gcgInverseMatrix4(MATRIX4d inverse, MATRIX4d matrix);
1718 
1733 GCG_API_FUNCTION bool gcgEigenSymmetric(int norder, float matrix[], float eigenvectors[], float eigenvalues[]);
1734 
1749 GCG_API_FUNCTION bool gcgEigenSymmetric(int norder, double matrix[], double eigenvectors[], double eigenvalues[]);
1750 
1751 
1765 GCG_API_FUNCTION bool gcgEigenSymmetricMatrix3(MATRIX3 matrix, MATRIX3 eigenvectors, VECTOR3 eigenvalues);
1766 
1780 GCG_API_FUNCTION bool gcgEigenSymmetricMatrix3(MATRIX3d matrix, MATRIX3d eigenvectors, VECTOR3d eigenvalues);
1781 
1782 
1788 
1789 template<class NUMTYPE> class GCG_API_CLASS gcgMATRIX;
1790 
1792 
1793 
1801 
1806 
1811 
1817 GCG_API_FUNCTION bool gcgDrawLogo(float scale = 0.67);
1818 
1824 GCG_API_FUNCTION bool gcgDrawAABox(VECTOR3 bbmin, VECTOR3 bbmax);
1825 
1831 GCG_API_FUNCTION bool gcgDrawAABox(VECTOR3d bbmin, VECTOR3d bbmax);
1832 
1841 GCG_API_FUNCTION bool gcgDrawOBox(VECTOR3 obbangles, VECTOR3 obbcenter, VECTOR3 obbsize);
1842 
1851 GCG_API_FUNCTION bool gcgDrawOBox(VECTOR3d obbangles, VECTOR3d obbcenter, VECTOR3d obbsize);
1852 
1865 GCG_API_FUNCTION bool gcgDrawVectorPyramid(float x, float y, float z, VECTOR3 vector, float scale);
1866 
1879 GCG_API_FUNCTION bool gcgDrawVectorPyramid(float x, float y, float z, VECTOR3d vector, float scale);
1880 
1893 GCG_API_FUNCTION bool gcgDrawVectorPyramidClosed(float x, float y, float z, VECTOR3 vector, float scale);
1894 
1907 GCG_API_FUNCTION bool gcgDrawVectorPyramidClosed(float x, float y, float z, VECTOR3d vector, float scale);
1908 
1921 GCG_API_FUNCTION bool gcgDrawVectorThetrahedron(float x, float y, float z, VECTOR3 vector, float scale);
1922 
1935 GCG_API_FUNCTION bool gcgDrawVectorThetrahedron(float x, float y, float z, VECTOR3d vector, float scale);
1936 
1949 GCG_API_FUNCTION bool gcgDrawVectorThetrahedronClosed(float x, float y, float z, VECTOR3 vector, float scale);
1950 
1963 GCG_API_FUNCTION bool gcgDrawVectorThetrahedronClosed(float x, float y, float z, VECTOR3d vector, float scale);
1964 
1965 
1967 
1972 
1976 GCG_API_FUNCTION float gcgBlinkingAlpha();
1977 
1985 GCG_API_FUNCTION bool gcgHeatColor(float normheat, VECTOR3 color);
1986 
1994 GCG_API_FUNCTION bool gcgHeatColor(double normheat, VECTOR3d color);
1995 
1997 
2005 
2006 // GCGFONT Versions
2007 #define GCG_FONT_VERSION 0xf010
2008 
2009 // Compression modes
2010 #define GCG_FONT_UNCOMPRESSED 0
2011 #define GCG_FONT_COMPRESSED_RLE 1
2012 
2013 #pragma pack(push, 1) // Must have 1 byte alignment
2014 
2015 // Structure for the GCG font file format .gff version 1.0.
2016 typedef struct _GCGFONTDATA {
2017  // Header
2018  unsigned short version; // First two bytes indicate version: 1.0 = 0xf010
2019  unsigned int fontdatasize; // Font data size: header + information + maps
2020  unsigned char compression; // Font image compression mode
2021 
2022  // Font information dependent on version number
2023  unsigned int width; // Font image width
2024  unsigned int height; // Font image height
2025  unsigned int cellwidth; // Character cell width
2026  unsigned int cellheight; // Character cell height
2027  unsigned char firstASCII; // ASCII value of the first character in the font map
2028 
2029  // Information about the chars inside the cell
2030  unsigned int xoffset; // Offset in x for all characters in pixels
2031  unsigned int yoffset; // Offset in y for all characters in pixels
2032  unsigned int charheight; // Height of all characters in font
2033 
2035  // Font data maps as a sequence of chars.
2036  // nchars = ((unsigned int) width / cellwidth) * ((unsigned int) height / cellheight);
2038  // unsigned char charwidths[nchars]; // Width of each character texture in pixels
2039  // unsigned char basewidths[nchars]; // Character bases in pixels
2040  // unsigned char fontmap[remainingbytes]; // Font image
2041 } GCGFONTDATA;
2042 
2043 // Class for internal font handling
2044 class GCG_API_CLASS gcgFONT : public gcgCLASS {
2045  public:
2046  unsigned int textureID; // The font texture ID for OpenGL
2047  unsigned int nchars; // Number of characters in this font
2048  unsigned char firstASCII; // ASCII code of the first character in this font
2049  int font_base; // Character OpenGL list base.
2050 
2051  unsigned int charheight; // Character height in pixels
2052  unsigned char *basewidths; // Character widths in pixels.
2053 
2054  public:
2055  gcgFONT();
2056  virtual ~gcgFONT();
2057 
2058  // Object initiation
2059  bool loadGFF(char *fontname); // Loads a font from a .gff file
2060  bool createFromData(GCGFONTDATA *font);
2061  void releaseFont(); // Free all font resources
2062 
2063  // Functions to retrieve string information for rendering
2064  void textLength(unsigned int *strwidth, unsigned int *strheight, char *str, int strlength); // Computes the box spanned by this string
2065  int charsThatFit(float width, char *str, int strlength); // Computes how many chars fit to the width.
2066 };
2067 
2068 
2069 // Utilities for font creation
2070 GCG_API_FUNCTION bool gcgSaveGFF(char *name, GCGFONTDATA *gcgfont);
2071 GCG_API_FUNCTION GCGFONTDATA *gcgImportBFF(char *name); // Imports a .bff font file
2072 
2073 #pragma pack(pop)
2074 
2082 
2083 // Number of fonts internally implemented
2084 #define GCG_SYSTEM_FONTS 12
2085 
2086 // Registered system fonts
2087 #define GCG_FONT_SANSSERIF_11_NORMAL 0
2088 #define GCG_FONT_TAHOMA_12_NORMAL 1
2089 #define GCG_FONT_TAHOMA_12_BOLD 2
2090 #define GCG_FONT_TAHOMA_13_NORMAL 3
2091 #define GCG_FONT_COURIERNEW_15_NORMAL 4
2092 #define GCG_FONT_COURIERNEW_15_BOLD 5
2093 #define GCG_FONT_COURIERNEW_15_ITALIC 6
2094 #define GCG_FONT_COURIERNEW_15_BOLDITALIC 7
2095 #define GCG_FONT_TAHOMA_17_NORMAL 8
2096 #define GCG_FONT_TAHOMA_17_BOLD 9
2097 #define GCG_FONT_TAHOMA_17_ITALIC 10
2098 #define GCG_FONT_TAHOMA_17_BOLDITALIC 11
2099 
2100 // Class definition
2101 class GCG_API_CLASS gcgTEXT : public gcgCLASS {
2102  private:
2103  float x, y, z; // Next print position
2104  gcgFONT *currentfont; // Selected font object
2105  float scalex, scaley; // Font scale.
2106  float textangle; // Text orientation
2107  int borderpixels[2]; // Border pixels separation
2108 
2109  int viewport[4]; // OpenGL viewport
2110  float textbox[4]; // Output text box
2111 
2112  int wrap; // Wrap text to box?
2113  bool noTextBox; // Text box enabled?
2114 
2115  public:
2116  // Construction
2117  gcgTEXT();
2118  virtual ~gcgTEXT();
2119 
2120  // Font parameters
2121  bool setFont(gcgFONT *font);
2122  bool setSystemFont(int fontindex);
2123  void fontScale(float scalex, float scaley);
2124  float setBestFitSystemFont(char *str, float width); // Selects the best normal system font and scaling that fits to the width passed.
2125  gcgFONT* getCurrentFont();
2126 
2127  // Text box functions. Use screen-space coordinates (pixels).
2128  void enableTextBox(float x, float y, float width, float height); // Restricts the output area to this box.
2129  void enableTextBoxAt3DPos(float xpos, float ypos, float zpos, float width, float height);
2130  void adjustTextBox(float xoffset, float yoffset, float widthoffset, float heightoffset);
2131  void setBorder(int npixelsX, int npixelsY); // Number of pixels for text separation
2132  void disableTextBox(); // The output area is the entire viewport.
2133  void drawTextBox(float boxR, float boxG, float boxB, float boxA, float frameR, float frameG, float frameB, float frameA, float linewidth);
2134 
2135  // Text output functions. Use screen-space coordinates (pixels).
2136  void wrapText(bool wraptobox); // Text is wrapped to the box if wraptobox is TRUE.
2137  void textPosition(float x, float y); // Position inside the text box.
2138  void textOrientation(float angle); // Position inside the text box and orientation.
2139  void gcgprintf(const char *format, ...);
2140 
2141  // Information
2142 
2143  private:
2144  void initTextOutput(); // Initialization for al text output functions
2145  void finishTextOutput(); // Finishing the text output for all functions
2146  void outputText(int length, char *str); // Prints text to the output area. Implements the wrap functionality.
2147 };
2148 
2149 
2150 // Generates C code for internal registration as system font
2151 bool gcgGenerateSystemFontCode(char *name, GCGFONTDATA *gcgfont);
2152 
2153 
2161 
2163 // GCG geometry macros. More efficient than functions. But results in a larger code.
2165 
2166 // Add a point to a Axis Aligned Box min/max vectors
2167 #define gcgADDPPOINTAABox(bbmin, bbmax, p) { \
2168  if((bbmin)[0] > (p)[0]) (bbmin)[0] = (p)[0]; \
2169  if((bbmin)[1] > (p)[1]) (bbmin)[1] = (p)[1]; \
2170  if((bbmin)[2] > (p)[2]) (bbmin)[2] = (p)[2]; \
2171  if((bbmax)[0] < (p)[0]) (bbmax)[0] = (p)[0]; \
2172  if((bbmax)[1] < (p)[1]) (bbmax)[1] = (p)[1]; \
2173  if((bbmax)[2] < (p)[2]) (bbmax)[2] = (p)[2]; }
2174 
2175 
2177 // GCG geometry prototypes.
2179 
2180 // Functions for quaternions
2181 GCG_API_FUNCTION void gcgQuaternionSlerp(VECTOR4 dest, VECTOR4 p, VECTOR4 q, float t);
2182 
2183 // Functions for alignment tranformations
2184 // Computes the rotation matrix that aligns the z-axis with the direction specified by vector dir.
2185 GCG_API_FUNCTION bool gcgComputeAlignMatrix(MATRIX4 matrix, VECTOR3 dir);
2186 
2187 // Trackball simulation
2188 GCG_API_FUNCTION void gcgTrackball(VECTOR4 q, float p1x, float p1y, float p2x, float p2y);
2189 
2190 // Functions for bounding boxes
2191 GCG_API_FUNCTION void gcgAABoxFromOBox(VECTOR3 aabbmin, VECTOR3 aabbmax, VECTOR3 obbangles, VECTOR3 obbposition, VECTOR3 obbmin, VECTOR3 obbmax);
2192 
2193 // Functions for computing intersections
2194 GCG_API_FUNCTION int gcgIntersectTriangleTriangle(VECTOR3 V0, VECTOR3 V1, VECTOR3 V2, VECTOR3 U0, VECTOR3 U1, VECTOR3 U2);
2195 GCG_API_FUNCTION int gcgIntersectTriangleTriangleLine(VECTOR3 V0, VECTOR3 V1, VECTOR3 V2, VECTOR3 U0, VECTOR3 U1, VECTOR3 U2, int *coplanar, VECTOR3 isectpt1, VECTOR3 isectpt2);
2196 GCG_API_FUNCTION int gcgIntersectLineLine(VECTOR3 p1, VECTOR3 p2, VECTOR3 p3, VECTOR3 p4, VECTOR3 pa, VECTOR3 pb, double *mua, double *mub);
2197 GCG_API_FUNCTION int gcgIntersectPointLine(VECTOR3 point, VECTOR3 edgeA, VECTOR3 edgeB);
2198 GCG_API_FUNCTION int gcgIntersectPointTriangle(VECTOR3 p, VECTOR3 A, VECTOR3 B, VECTOR3 C);
2199 GCG_API_FUNCTION bool gcgIntersectLineBox2D(VECTOR2 p1, VECTOR2 p2, VECTOR2 box2dMin, VECTOR2 box2dMax);
2200 
2201 // Functions for triangles
2202 
2210 GCG_API_FUNCTION float gcgTriangleArea(VECTOR3 v0, VECTOR3 v1, VECTOR3 v2);
2211 
2222 GCG_API_FUNCTION void gcgTriangleGradient(VECTOR3 grad_u, VECTOR3 v0, VECTOR3 v1, VECTOR3 v2, float u0, float u1, float u2);
2223 
2233 GCG_API_FUNCTION float gcgSphericalDistance(float latitude1, float longitude1, float latitude2, float longitude2);
2234 
2235 
2236 //************* Double precision versions *************
2237 GCG_API_FUNCTION void gcgQuaternionSlerp(VECTOR4d dest, VECTOR4d p, VECTOR4d q, double t);
2238 GCG_API_FUNCTION bool gcgComputeAlignMatrix(MATRIX4d matrix, VECTOR3d dir);
2239 GCG_API_FUNCTION void gcgTrackball(VECTOR4d q, double p1x, double p1y, double p2x, double p2y);
2240 GCG_API_FUNCTION void gcgAABoxFromOBox(VECTOR3d aabbmin, VECTOR3d aabbmax, VECTOR3d obbangles, VECTOR3d obbposition, VECTOR3d obbmin, VECTOR3d obbmax);
2241 GCG_API_FUNCTION int gcgIntersectTriangleTriangle(VECTOR3d V0, VECTOR3d V1, VECTOR3d V2, VECTOR3d U0, VECTOR3d U1, VECTOR3d U2);
2242 GCG_API_FUNCTION int gcgIntersectTriangleTriangleLine(VECTOR3d V0, VECTOR3d V1, VECTOR3d V2, VECTOR3d U0, VECTOR3d U1, VECTOR3d U2, int *coplanar, VECTOR3d isectpt1, VECTOR3d isectpt2);
2243 GCG_API_FUNCTION int gcgIntersectLineLine(VECTOR3d p1, VECTOR3d p2, VECTOR3d p3, VECTOR3d p4, VECTOR3d pa, VECTOR3d pb, double *mua, double *mub);
2244 GCG_API_FUNCTION int gcgIntersectPointLine(VECTOR3d point, VECTOR3d edgeA, VECTOR3d edgeB);
2245 GCG_API_FUNCTION int gcgIntersectPointTriangle(VECTOR3d p, VECTOR3d A, VECTOR3d B, VECTOR3d C);
2246 GCG_API_FUNCTION bool gcgIntersectLineBox2D(VECTOR2d p1, VECTOR2d p2, VECTOR2d box2dMin, VECTOR2d box2dMax);
2247 GCG_API_FUNCTION double gcgTriangleArea(VECTOR3d v0, VECTOR3d v1, VECTOR3d v2);
2248 GCG_API_FUNCTION void gcgTriangleGradient(VECTOR3d grad_u, VECTOR3d v0, VECTOR3d v1, VECTOR3d v2, double u0, double u1, double u2);
2249 GCG_API_FUNCTION double gcgSphericalDistance(double latitude1, double longitude1, double latitude2, double longitude2);
2250 
2258 
2260 // Internal structures for mesh representation.
2262 
2264 // Class gcgPOLYGONVERTEX: main abstract class for vertex handling.
2266 class gcgPOLYGONVERTEX : public gcgCLASS {
2267  public:
2268  // Internal use in gcgPOLYGON class. Do not modify.
2269  unsigned int nhalf_edges; // Number of half-edges containing this vertex
2270  unsigned int maxhalf_edges; // Capacity of the half_edges array
2271  struct _GCGHALFEDGE **half_edges; // Array of half-edges containing this vertex
2272  gcgPOLYGONVERTEX *prevVertex; // Previous vertex of a mesh
2273  gcgPOLYGONVERTEX *nextVertex; // Next vertex of a mesh
2274 
2275  public:
2276  virtual ~gcgPOLYGONVERTEX() {}
2277 
2278  // Returns true if this vextex is equal to vertex2
2279  virtual bool isEqual(gcgPOLYGONVERTEX *vertex2);
2280 
2281  // Copies the contents of vertex2 to vertex
2282  virtual void copy(gcgPOLYGONVERTEX *vertex2);
2283 };
2284 
2286 // Class gcgVERTEX3: main abstract template class for
2287 // 3D vertex handling.
2288 // - use:
2289 // gcgVERTEX3<float> for VECTOR3
2290 // gcgVERTEX3<double> for VECTOR3d
2292 template <typename T>
2293 class gcgVERTEX3 : public gcgPOLYGONVERTEX {
2294  public:
2295  T position[3];
2296 
2297  public:
2298  virtual bool isEqual(T vertex2[3]) {
2299  return FEQUAL(this->position[0], vertex2[0]) &&
2300  FEQUAL(this->position[1], vertex2[1]) &&
2301  FEQUAL(this->position[2], vertex2[2]);
2302  };
2303 
2304  virtual void copy(T vertex2[3]) {
2305  this->position[0] = vertex2[0];
2306  this->position[1] = vertex2[1];
2307  this->position[2] = vertex2[2];
2308  };
2309 };
2310 
2311 
2312 // Internal polygon information
2313 class GCG_API_CLASS gcgPOLYGON : public gcgCLASS {
2314  public:
2315  unsigned int nvertices; // Number of vertices of this polygon
2316  struct _GCGHALFEDGE *half_edge; // Half-edges forming this polygon. One per vertex.
2317  gcgPOLYGON *prevPolygon; // Previous polygon of a mesh
2318  gcgPOLYGON *nextPolygon; // Next polygon of a mesh
2319 };
2320 
2321 
2322 // Internal Half-Edge information
2323 typedef struct _GCGHALFEDGE {
2324  gcgPOLYGONVERTEX *srcVertex; // Vertex to which this half-edge belongs
2325  gcgPOLYGON *face; // Face to which this half-edge belongs
2326  struct _GCGHALFEDGE *nextHalfEdge; // Next half-edge of this face
2327  struct _GCGHALFEDGE *prevHalfEdge; // Previous half-edge of this face
2328  struct _GCGHALFEDGE *nextBrotherHalfEdge; // Next face half-edge
2329  struct _GCGHALFEDGE *prevBrotherHalfEdge; // Previous face half-edge
2330 } GCGHALFEDGE;
2331 
2332 
2334 // Class gcgPOLYGONMESH: container for polygons and vertices.
2336 class GCG_API_CLASS gcgPOLYGONMESH : public gcgCLASS {
2337  public:
2338  // Polygon information
2339  unsigned int npolygons; // Number of polygons of this object
2340  gcgPOLYGON *polygons; // Linked list of polygons
2341 
2342  // Vertex information
2343  unsigned int nvertices; // Number of vertices of this object
2344  gcgPOLYGONVERTEX *vertices; // Linked list of vertices
2345 
2346  // Acess information
2347  GCGHALFEDGE* last_half_edge;
2348  GCGHALFEDGE* first_half_edge_brother;
2349  GCGHALFEDGE* last_half_edge_brother;
2350 
2351  public:
2352  // Constructors and destructors
2353  gcgPOLYGONMESH();
2354  virtual ~gcgPOLYGONMESH();
2355 
2356  // Resources handling.
2357  void destroyPolygon();
2358 
2359  // Object data access and initialization
2360  bool addPolygon(gcgPOLYGON *polygon);
2361  bool addVertex(gcgPOLYGONVERTEX *vertex);
2362  gcgPOLYGONVERTEX* findSimilarVertex(gcgPOLYGONVERTEX *vertex);
2363 
2364  // Functions to attach vertices to polygons and edges
2365  bool addPolygonVertex(gcgPOLYGON *ipolygon, gcgPOLYGONVERTEX *vertex, unsigned int newvertexIndex = 0);
2366 
2367  // Functions to retrieve information
2368  gcgPOLYGONVERTEX* getPolygonVertex(gcgPOLYGON *polygon, unsigned int vertexIndex);
2369  gcgPOLYGONVERTEX* getPolygonNextVertex(); // Gets the next edge in the last polygon acessed by getPolygonVertex.
2370  gcgPOLYGON* getPolygonFromEdge(gcgPOLYGONVERTEX *vertexID1, gcgPOLYGONVERTEX *vertexID2);
2371  gcgPOLYGON* getNextPolygonFromEdge();
2372 
2373  // Methods to remove objects. Keep remaining polygons and edges.
2374  bool removeVertex(gcgPOLYGONVERTEX *vertex);
2375  bool removeEdge(gcgPOLYGONVERTEX *vertex1, gcgPOLYGONVERTEX *vertex2);
2376  bool removePolygon(gcgPOLYGON *ipolygon);
2377  bool removeHalfEdge(GCGHALFEDGE* ihalf_edge);
2378  unsigned int removeIsolatedVertices();
2379 
2380  // Stellar Operations
2381  bool edgeCollapse(gcgPOLYGONVERTEX *vertexID1, gcgPOLYGONVERTEX *vertex2);
2382  bool halfEdgeCollapse(gcgPOLYGONVERTEX *vertexID1, gcgPOLYGONVERTEX *vertex2, gcgPOLYGONVERTEX *newvertex);
2383  bool edgeFlip(gcgPOLYGONVERTEX *vertex1, gcgPOLYGONVERTEX *vertex2);
2384  bool edgeWeld(gcgPOLYGONVERTEX *vertex);
2385  bool edgeSplit(gcgPOLYGONVERTEX *vertex1, gcgPOLYGONVERTEX *vertex2, gcgPOLYGONVERTEX *newvertex);
2386  bool polygonSplit(gcgPOLYGON *ipolygon, unsigned int vertexIndex, gcgPOLYGONVERTEX *newvertex);
2387 
2388  // Test link condition for edge collapse operation
2389  bool testLinkCondition(gcgPOLYGONVERTEX *vertex1, gcgPOLYGONVERTEX *vertex2);
2390 
2391  // Return the valence of ivertex
2392  unsigned int getValence(gcgPOLYGONVERTEX *vertexID);
2393  // Get the star of a vertex
2394  // starVertices - Returns a list of vertices
2395  // starPolygons - Returns a list of the faces
2396  bool getVertexStar(gcgPOLYGONVERTEX *vertex, gcgPOLYGONVERTEX **starVertexVertices, unsigned int* numVertices, gcgPOLYGON **starVertexPolygons, unsigned int* numPolygons);
2397  unsigned int getVerticesVertexStar(gcgPOLYGONVERTEX *vertexIndex, gcgPOLYGONVERTEX **starVertexVertices, unsigned int* numVertices);
2398  unsigned int getPolygonsVertexStar(gcgPOLYGONVERTEX *vertexID, gcgPOLYGON **starVertexPolygons, unsigned int* numPolygons);
2399  // Get the star of an edge
2400  unsigned int getEdgeStar(gcgPOLYGONVERTEX *vertex1, gcgPOLYGONVERTEX *vertex2, gcgPOLYGONVERTEX **starEdgeVertices, unsigned int* numVertices, gcgPOLYGON **starEdgePolygons, unsigned int* numPolygons);
2401  // Return the intersection between star1 and star2
2402  bool getStarIntersection(gcgPOLYGONVERTEX** starVertexVertices1, gcgPOLYGON** starVertexPolygons1, gcgPOLYGONVERTEX** starVertexVertices2, gcgPOLYGON** starVertexPolygons2, gcgPOLYGONVERTEX** starIntersectionVertices, gcgPOLYGON** starIntersectionPolygons, unsigned int numVertices1, unsigned int numPolygons1, unsigned int numVertices2, unsigned int numPolygons2, unsigned int* numVerticesIntersection, unsigned int* numPolygonsIntersection);
2403  // Compare two stars
2404  bool starComparison(gcgPOLYGONVERTEX** starVertices1, gcgPOLYGON** starPolygons1, gcgPOLYGONVERTEX** starVertices2, gcgPOLYGON** starPolygons2, unsigned int numVertices1, unsigned int numPolygons1, unsigned int numVertices2, unsigned int numPolygons2);
2405 
2406  private:// Check functions
2407  void testVertex();
2408  void testVertex(unsigned int vertexIndex);
2409  void testHalfEdgeBrother(GCGHALFEDGE* ihalf_edge);
2410  void testPolygons();
2411  void testStar(unsigned int *starVertex[2], unsigned int numVertices, unsigned int numPolygons);
2412  void testStarVertices(gcgPOLYGONVERTEX** starVertexVertices, unsigned int numVertices);
2413  void testStarVerticesRemove(gcgPOLYGONVERTEX** starVertexVertices, unsigned int numVertices);
2414  void testStarPolygons(gcgPOLYGON** starVertexPolygons, unsigned int numPolygons);
2415  void testStarPolygonsRemove(gcgPOLYGON** starVertexPolygons, unsigned int numPolygons);
2416  void testHalfEdgeBrother2();
2417  void testHalfEdgeBrother3();
2418 };
2419 
2420 
2428 
2429 // Vertex indices
2430 #define GCG_VAPEX 0
2431 #define GCG_VESQ 1
2432 #define GCG_VDIR 2
2433 
2435 // Sides for connections on level 2:
2436 // Defining the base of a side (NORTH,WEST) as the base of the opposite side,
2437 // (SOUTH, EAST) we force the subdivisions of the first be propagated to the
2438 // other.
2439 // As such, we can change the topology of the generated mesh as follows:
2440 //
2441 // Plane: no forced connection
2442 // Cylinder: WEST is connected to EAST
2443 // Torus: WEST is connected to EAST and NORTH is connected to SOUTH
2445 //
2446 // NORTH
2447 // p3------p2
2448 // | \ / |
2449 // WEST | \/ | EAST
2450 // | /\ |
2451 // | / \ |
2452 // p0------p1
2453 // SOUTH
2454 //
2455 #define GCG_TOPOLOGY_PLANE 0 // Default topology
2456 #define GCG_TOPOLOGY_CYLINDER 1
2457 #define GCG_TOPOLOGY_TORUS 2
2458 
2460 // Flags for composing mask actions for vertex indexes of an adaptive object.
2461 // - GCG_REFINE: this triangle is too coarse and should be refined.
2462 // - GCG_SIMPLIFY: this triangle is too detailed and should be simplified.
2463 // - GCG_MAXIMUMLOD: this triangle reached its maximum level of detail.
2464 // Avoid refining the sons of this node. Note that these
2465 // may be refined to keep the mesh consistent.
2466 // - GCG_MINIMUMLOD: this triangle reached its minimum level of detail.
2467 // Avoid simplifying the parents of this node. Note
2468 // that these may be simplified to keep the mesh consistent.
2469 // - GCG_INVISIBLE: informs that this triangle is completely invisible
2470 // - GCG_TOTALLYVISIBLE: informs that this triangle is completely visible
2471 //
2472 
2473 #define GCG_REFINE ((unsigned char) 0x01)
2474 #define GCG_SIMPLIFY ((unsigned char) 0x02)
2475 #define GCG_MAXIMUMLOD ((unsigned char) 0x04)
2476 #define GCG_MINIMUMLOD ((unsigned char) 0x08)
2477 #define GCG_INVISIBLE ((unsigned char) 0x10)
2478 #define GCG_TOTALLYVISIBLE ((unsigned char) 0x20)
2479 #define GCG_SELECT0 ((unsigned char) 0x40)
2480 #define GCG_SELECT1 ((unsigned char) 0x80)
2481 
2482 
2484 
2486 // gcgADAPTIVE: abstract interface to support refinable meshes
2487 // - informs the geometry of a refinable object
2488 // - must allocate all vertices.
2489 // - all methods are abstract
2491 class GCG_API_CLASS gcgADAPTIVE : public gcgCLASS {
2492  public:
2493 
2495  // beginTesselation() is called in the beginning of a tesselation to
2496  // obtain the domain for subdivision in the form of four vertices. Its call
2497  // indicates that the previous tesselation was discarded and all vertices
2498  // may be freed.
2499  // - For the semi-regular A48 mesh, the 4 vertices form a losangle
2500  // as follows:
2501  // d3-----d2
2502  // | / |
2503  // | / |
2504  // | / |
2505  // d0-----d1
2506  //
2507  // - For every tesselation, this method must allocate the vertices as
2508  // described above.
2509  virtual void beginTesselation() = 0;
2510 
2512  // action() is called to query if the triangle formed by counterclockwise
2513  // indexes iVertices[VAPEX], iVertices[VESQ], iVertices[DIR], should be
2514  // REFINED or SIMPLIFIED. It must return a byte mask with bits composed by
2515  // any combination of the flags:
2516  // - GCG_REFINE: this triangle is too coarse and should be refined.
2517  // - GCG_SIMPLIFY: this triangle is too detailed and should be simplified.
2518  // - GCG_MAXIMUMLOD: this triangle reached its maximum level of detail.
2519  // Avoid refining the sons of this node. Note that these
2520  // may be refined to keep the mesh consistent.
2521  // - GCG_MINIMUMLOD: this triangle reached its minimum level of detail.
2522  // Avoid simplifying the parents of this node. Note
2523  // that these may be simplified to keep the mesh consistent.
2524  // - GCG_INVISIBLE: informs that this triangle is completely invisible
2525  // - GCG_TOTALLYVISIBLE: informs that this triangle is completely visible
2526  //
2527  // It must return 0 if no action should be applied.
2528  virtual unsigned char action(unsigned char nivel, int *iVertices, unsigned char oldmask) = 0;
2529 
2531  // sample() must compute a NEW POINT for triangle subdivision
2532  // (splitting), and return its integer index. If the parameter apex2 is
2533  // positive, then it's the index of the apex of the triangle that forms
2534  // a losangle (diamond) with the triangle vertices pointed by iVertices.
2535  //
2536  // iVertices[VAPEX] +------+ iVertices[VDIR]
2537  // | / |
2538  // | / | - VAPEX = 0
2539  // | / | - VESQ = 1
2540  // | / | - VDIR = 2
2541  // iVertices[VESQ] +------+ apex2 (if positive)
2542  //
2543  // - apex2 may be negative. In this case only one triangle is used in the
2544  // subdivision.
2545  //
2546  // - it must return the interpolated point using the four points, case apex2 >= 0,
2547  // or using the triangle vertices, otherwise. This index will be used for
2548  // further subdivision queries or sampling.
2549  //
2550  virtual int sample(int *iVertices, int apex2) = 0;
2551 
2553  // endTesselation() is called when a tesselation has finished. Can be used
2554  // to adequate the object status.
2555  //
2556  virtual void endTesselation() = 0;
2557 };
2558 
2559 
2561 // Class gcgSEMIREGULAR48: restricted unbalanced binary trees
2562 // - forms a semi-regular A48 mesh.
2563 // - controls the top-down subdivision of the mesh
2564 // - define the mesh topology
2566 class GCG_API_CLASS gcgSEMIREGULAR48 : public gcgCLASS {
2567  private:
2568  // Para formar a estrutura básica da árvore
2569  typedef struct __nodo {
2570  // Most used fields first
2571  int iInfo; // Index for front info, if this node
2572  // is at tree front then iInfo >= 0
2573 
2574  unsigned char nivel; // Nivel (detalhe) desse nodo na árvore
2575  //unsigned int indice; // Índice único (estrutural) que
2576  // identifica esse triangulo
2577 
2578  // Controle da estrutura de subdivisao
2579  int filhoesq; // Filho esquerdo do nodo
2580  // Filho direito do nodo = filhoesq + 1 sempre
2581 
2582  int vizesq,
2583  vizdir, vizbase; // Indices para os vizinhos do nodo
2584  } NODO;
2585 
2586  // Information for front nodes
2587  typedef struct __frontinfo {
2588  unsigned char lastmask; // Last flags returned by an action call
2589  } FRONTINFO;
2590 
2591  // Connection control for topology
2592  unsigned char topology;
2593 
2594  gcgADAPTIVE *geometria; // Objeto corrente que fornece a geometria
2595 
2596  int nnodos; // Quantidade de nodos atual
2597  NODO *nodos; // Buffer dinamico para controle dos nodos
2598  int maxnodos; // Capacidade do buffer de nodos
2599 
2600  int ntriangulos; // Quantidade de triangulos atual
2601  int maxtriang; // Capacidade do buffer de triangulos
2602  FRONTINFO *front; // Front information: one for each triangle
2603  int *vertices; // Buffer dinamico para controle dos vertices dos triangulos
2604 
2605  int *stack; // Stack of integers for depth search
2606  int top; // Top of the stack = next node to be expanded
2607  int maxstack; // Stack capacity
2608 
2609  // For triangle selection
2610  unsigned char hidemask; // Front triangle selection: if a logical AND of
2611  // this mask with the lastmask is non-zero,
2612  // then it's not returned in a getIndexArray call.
2613  unsigned char showmask; // A logical AND with this mask and the lastmask,
2614  // determines those triangles that must be shown.
2615  // Only used if hidemask is non-zero.
2616  int nhidden; // Number of hidden elements in a getIndexArray call.
2617 
2618  // Metodos privados /////////////////////////////////////////////////////////
2619  private:
2620  void divide_node(int inodo);
2621  void triangle_bissection(int inodo, int novovertice, int ifilhoesq);
2622  int initTesselation(gcgADAPTIVE *geo);
2623 
2624 
2625  // Metodos públicos ////////////////////////////////////////////////////////
2626  public:
2627  // Creates a semiregular 4-8 mesh which domain and geometry is
2628  // defined by a gcgADAPTIVE object
2629  gcgSEMIREGULAR48();
2630  virtual ~gcgSEMIREGULAR48();
2631 
2632  void setTopology(int topologycode);
2633 
2634  // Generates a mesh WITH a restriction on the number of triangles using
2635  // a breath-first search.
2636  // - uses the gcgADAPTIVE interface to build the mesh.
2637  // - Returns the number of generated triangles.
2638  //
2639  int tesselate(int maxtriang, gcgADAPTIVE *geometry);
2640 
2641  // Generates a mesh WITHOUT a restriction on the number of triangles using
2642  // a depth-first search. It is faster than the other version, but the stop
2643  // criteria are exclusively implemented by the refinable object.
2644  //
2645  // - uses the gcgADAPTIVE interface to build the mesh.
2646  // - Returns the number of generated triangles.
2647  //
2648  int tesselate(gcgADAPTIVE *geometry);
2649 
2650  // Returns the vertex array of last tesselation. Stores the number of
2651  // triangles (vextex triplets) in the 'ntriang' parameter if it is non-null.
2652  int* getIndexArray(int *ntriang);
2653 
2654  // Selects the triangles that will be delivered by getIndexArray.
2655  int hideTriangles(unsigned char hidemask, unsigned char mustshowmask);
2656 };
2657 
2658 
2666 
2671 
2672 template<class NUMTYPE> class GCG_API_CLASS gcgDISCRETE1D;
2673 template<class NUMTYPE> class GCG_API_CLASS gcgDISCRETE2D;
2674 
2676 
2680 
2683 #define GCG_BORDER_EXTENSION_ZERO 1
2684 
2687 #define GCG_BORDER_EXTENSION_CLAMP 2
2688 
2691 #define GCG_BORDER_EXTENSION_PERIODIC 3
2692 
2695 #define GCG_BORDER_EXTENSION_SYMMETRIC_NOREPEAT 4
2696 
2699 #define GCG_BORDER_EXTENSION_SYMMETRIC_REPEAT 5
2700 
2702 
2703 
2711 
2720 template<class NUMTYPE> GCG_API_FUNCTION bool gcgLinearSolver(gcgDISCRETE2D<NUMTYPE> *A, gcgDISCRETE1D<NUMTYPE> *b, gcgDISCRETE1D<NUMTYPE> *x);
2721 
2729 
2730 template <class NUMTYPE = float> class GCG_API_CLASS gcgSEQUENCEDERIVATIVE2D;
2731 template <class NUMTYPE = float> class GCG_API_CLASS gcgFILTERMASK1D;
2732 
2734 // Signal comparison: error computation.
2736 
2737 template<class NUMTYPE> GCG_API_FUNCTION double computeMSEwith(gcgDISCRETE1D<NUMTYPE> *src1, gcgDISCRETE1D<NUMTYPE> *src2); // Computes the Mean Squared Error.
2738 template<class NUMTYPE> GCG_API_FUNCTION double computePSNRwith(gcgDISCRETE1D<NUMTYPE> *src1, gcgDISCRETE1D<NUMTYPE> *src2);// Computes the Peak Signal-to-Noise Ratio in dB.
2739 template<class NUMTYPE> GCG_API_FUNCTION double computeMAEwith(gcgDISCRETE1D<NUMTYPE> *src1, gcgDISCRETE1D<NUMTYPE> *src2); // Computes the Mean Absolute Error.
2740 
2741 template<class NUMTYPE> GCG_API_FUNCTION double computeMSEwith(gcgDISCRETE2D<NUMTYPE> *src1, gcgDISCRETE2D<NUMTYPE> *src2); // Computes the Mean Squared Error.
2742 template<class NUMTYPE> GCG_API_FUNCTION double computePSNRwith(gcgDISCRETE2D<NUMTYPE> *src1, gcgDISCRETE2D<NUMTYPE> *src2);// Computes the Peak Signal-to-Noise Ratio in dB.
2743 template<class NUMTYPE> GCG_API_FUNCTION double computeMAEwith(gcgDISCRETE2D<NUMTYPE> *src1, gcgDISCRETE2D<NUMTYPE> *src2); // Computes the Mean Absolute Error.
2744 
2745 
2747 // Signal analysis.
2749 
2750 // Computes the gradient of 1D signal src. The derivative is computed using well-known Sobel operator and
2751 // the result is stored in dx.
2752 template<class NUMTYPE> GCG_API_FUNCTION bool gcgFirstDerivativeSobel1D(gcgDISCRETE1D<NUMTYPE> *src, gcgDISCRETE1D<NUMTYPE> *dx);
2753 
2754 // Computes the gradient of 2D signal src. The partial derivatives are computed using well-known Sobel
2755 // operator and the components are stored in dx and dy. The pointer for dx or dy may be NULL.
2756 template<class NUMTYPE> GCG_API_FUNCTION bool gcgGradientSobel2D(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE2D<NUMTYPE> *dx, gcgDISCRETE2D<NUMTYPE> *dy);
2757 
2758 // Computes the (optical) flow given the partial derivatives in X, Y and time of up to three channels.
2759 // Uses the Augereau method (Bertrand Augereau, Benoît Tremblais, Christine Fernandez-Maloigne,
2760 // "Vectorial computation of the optical flow in colorimage sequences", CIC05).
2761 template<class NUMTYPE> GCG_API_FUNCTION bool gcgOpticalFlowAugereau2D(gcgDISCRETE2D<NUMTYPE> *dx1, gcgDISCRETE2D<NUMTYPE> *dy1, gcgDISCRETE2D<NUMTYPE> *dt1,
2762  gcgDISCRETE2D<NUMTYPE> *dx2, gcgDISCRETE2D<NUMTYPE> *dy2, gcgDISCRETE2D<NUMTYPE> *dt2,
2763  gcgDISCRETE2D<NUMTYPE> *dx3, gcgDISCRETE2D<NUMTYPE> *dy3, gcgDISCRETE2D<NUMTYPE> *dt3,
2764  gcgDISCRETE2D<float> *outflowX, gcgDISCRETE2D<float> *outflowY);
2765 template<class NUMTYPE> GCG_API_FUNCTION bool gcgOpticalFlowAugereau2D(gcgDISCRETE2D<NUMTYPE> *dx1, gcgDISCRETE2D<NUMTYPE> *dy1, gcgDISCRETE2D<NUMTYPE> *dt1,
2766  gcgDISCRETE2D<NUMTYPE> *dx2, gcgDISCRETE2D<NUMTYPE> *dy2, gcgDISCRETE2D<NUMTYPE> *dt2,
2767  gcgDISCRETE2D<NUMTYPE> *dx3, gcgDISCRETE2D<NUMTYPE> *dy3, gcgDISCRETE2D<NUMTYPE> *dt3,
2768  gcgDISCRETE2D<double> *outflowX, gcgDISCRETE2D<double> *outflowY);
2769 
2770 
2778 
2782 
2786 template <class NUMTYPE = float>
2787 class GCG_API_CLASS gcgBASIS1D : public gcgCLASS {
2789  virtual unsigned int getNumberOfCoefficients() = 0;
2790 
2795  virtual bool setNumberOfSamples(unsigned int nsamples) = 0;
2796 
2810  virtual bool projectSignal(int atX, gcgDISCRETE1D<float> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2811  virtual bool projectSignal(int atX, gcgDISCRETE1D<double> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2812  virtual bool projectSignal(int atX, gcgDISCRETE1D<short> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2813  virtual bool projectSignal(int atX, gcgDISCRETE1D<int> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2814  virtual bool projectSignal(int atX, gcgDISCRETE1D<long> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2815 
2827  virtual bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<float> *outputvector) = 0;
2828  virtual bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<double> *outputvector) = 0;
2829  virtual bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<short> *outputvector) = 0;
2830  virtual bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<int> *outputvector) = 0;
2831  virtual bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<long> *outputvector) = 0;
2832 };
2833 
2837 template <class NUMTYPE = float>
2838 class GCG_API_CLASS gcgBASIS2D : public gcgCLASS {
2840  virtual unsigned int getNumberOfCoefficients() = 0;
2841 
2853  virtual bool projectSignal(int atX, int atY, gcgDISCRETE2D<float> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2854  virtual bool projectSignal(int atX, int atY, gcgDISCRETE2D<double> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2855  virtual bool projectSignal(int atX, int atY, gcgDISCRETE2D<short> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2856  virtual bool projectSignal(int atX, int atY, gcgDISCRETE2D<int> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2857  virtual bool projectSignal(int atX, int atY, gcgDISCRETE2D<long> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef) = 0;
2858 
2871  virtual bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<float> *outputvector) = 0;
2872  virtual bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<double> *outputvector) = 0;
2873  virtual bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<short> *outputvector) = 0;
2874  virtual bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<int> *outputvector) = 0;
2875  virtual bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<long> *outputvector) = 0;
2876 };
2877 
2878 template<class NUMTYPE> class GCG_API_CLASS gcgLEGENDREBASIS1D;
2879 template<class NUMTYPE> class GCG_API_CLASS gcgLEGENDREBASIS2D;
2880 template<class NUMTYPE> class GCG_API_CLASS gcgDWTBASIS1D;
2881 
2883 
2884 
2892 
2897 
2898 
2921 
2922 class GCG_API_CLASS gcgIMAGE : public gcgCLASS {
2923  public:
2924  unsigned char *data;
2925  unsigned int width;
2926  unsigned int height;
2927  unsigned int bpp;
2928  unsigned int rowsize;
2929 
2930  unsigned int palettecolors;
2931  unsigned char *palette;
2932 
2934  unsigned int colormasks[4];
2935  unsigned int max[4];
2936 
2937  private:
2938  unsigned int rightshift[4];
2939  unsigned int nbits[4];
2940 
2941  public:
2944  gcgIMAGE();
2945 
2949  virtual ~gcgIMAGE();
2950 
2974  bool createImage(unsigned int width, unsigned int height, unsigned int bpp, bool usealpha = false);
2975 
2976 
2990  bool createSimilar(gcgIMAGE *source);
2991 
2999  bool destroyImage();
3000 
3009  bool isCompatibleWith(gcgIMAGE *source);
3010 
3020  bool isValid();
3021 
3035  bool duplicateImage(gcgIMAGE *source);
3036 
3054  bool duplicateSubimage(gcgIMAGE *source, int left, int top, unsigned int width, unsigned int height);
3055 
3068  bool copyImage(gcgIMAGE *source);
3069 
3078  bool loadImage(const char *filename);
3079 
3087  bool loadJPG(const char *filename);
3088 
3096  bool loadBMP(const char *filename);
3097 
3105  bool loadPCX(const char *filename);
3106 
3114  bool loadTGA(const char *filename);
3115 
3122  bool saveBMP(const char *filename);
3123 
3134  bool saveJPG(const char *filename , int quality);
3135 
3149  bool getPixelColor(unsigned int i, unsigned int j, VECTOR4 color);
3150 
3164  bool setPixelColor(unsigned int i, unsigned int j, VECTOR4 color);
3165 
3173  int getPixelIndex(unsigned int i, unsigned int j);
3174 
3183  bool setPixelIndex(unsigned int i, unsigned int j, int newindex);
3184 
3194  bool getPaletteColor(int index, VECTOR4 color);
3195 
3205  bool setPaletteColor(int index, VECTOR4 color);
3206 
3226  bool convolutionX(gcgIMAGE *source, gcgDISCRETE1D<float> *mask, float addthis = 0);
3227 
3247  bool convolutionY(gcgIMAGE *source, gcgDISCRETE1D<float> *mask, float addthis = 0);
3248 
3270  bool convolutionXY(gcgIMAGE *source, gcgDISCRETE2D<float> *mask, float addthis = 0);
3271 
3294  bool templateMatching(unsigned int imgleft, unsigned int imgbottom, unsigned int imgwidth, unsigned int imgheight, gcgDISCRETE2D<float> *mask, VECTOR2 position);
3295 
3308  bool transformColorSpace(gcgIMAGE *source, MATRIX4 matrix);
3309 
3323  bool convertBits(gcgIMAGE *source, unsigned int newbpp);
3324 
3337  bool convertGrayScale(gcgIMAGE *source);
3338 
3350  bool convertGrayScale8bits(gcgIMAGE *source);
3351 
3362  bool isGrayScale();
3363 
3374  bool forceLinearPalette();
3375 
3394  bool scale(float weight, gcgIMAGE *source, float addthis = 0.0);
3395 
3419  bool combineAdd(gcgIMAGE *source1, gcgIMAGE *source2, float weight1 = 1.0, float weight2 = 1.0, float addthis = 0.0);
3420 
3445  bool combineMult(gcgIMAGE *source1, gcgIMAGE *source2, float add1 = 0.0, float add2 = 0.0, float addthis = 0.0);
3446 
3463  bool splitChannels(gcgIMAGE *red, gcgIMAGE *green, gcgIMAGE *blue, gcgIMAGE *alpha = NULL);
3464 
3488  bool mergeChannels(gcgIMAGE *red, gcgIMAGE *green, gcgIMAGE *blue, gcgIMAGE *alpha = NULL);
3489 
3505  bool exportChannels(gcgDISCRETE2D<float> *red, gcgDISCRETE2D<float> *green, gcgDISCRETE2D<float> *blue, gcgDISCRETE2D<float> *alpha);
3506 
3522  bool exportChannels(gcgDISCRETE2D<double> *red, gcgDISCRETE2D<double> *green, gcgDISCRETE2D<double> *blue, gcgDISCRETE2D<double> *alpha);
3523 
3541  bool exportChannels(gcgDISCRETE2D<short> *red, gcgDISCRETE2D<short> *green, gcgDISCRETE2D<short> *blue, gcgDISCRETE2D<short> *alpha);
3542 
3560  bool exportChannels(gcgDISCRETE2D<int> *red, gcgDISCRETE2D<int> *green, gcgDISCRETE2D<int> *blue, gcgDISCRETE2D<int> *alpha);
3561 
3579  bool exportChannels(gcgDISCRETE2D<long> *red, gcgDISCRETE2D<long> *green, gcgDISCRETE2D<long> *blue, gcgDISCRETE2D<long> *alpha);
3580 
3599  bool importChannels(gcgDISCRETE2D<float> *red, gcgDISCRETE2D<float> *green, gcgDISCRETE2D<float> *blue, gcgDISCRETE2D<float> *alpha);
3600 
3619  bool importChannels(gcgDISCRETE2D<double> *red, gcgDISCRETE2D<double> *green, gcgDISCRETE2D<double> *blue, gcgDISCRETE2D<double> *alpha);
3620 
3642  bool importChannels(gcgDISCRETE2D<short> *red, gcgDISCRETE2D<short> *green, gcgDISCRETE2D<short> *blue, gcgDISCRETE2D<short> *alpha);
3643 
3665  bool importChannels(gcgDISCRETE2D<int> *red, gcgDISCRETE2D<int> *green, gcgDISCRETE2D<int> *blue, gcgDISCRETE2D<int> *alpha);
3666 
3688  bool importChannels(gcgDISCRETE2D<long> *red, gcgDISCRETE2D<long> *green, gcgDISCRETE2D<long> *blue, gcgDISCRETE2D<long> *alpha);
3689 
3691  // Histogram processing.
3692  // The srcimage can be the destination (this).
3694  bool histogramRGBA(unsigned int hvectorR[256], unsigned int hvectorG[256], unsigned int hvectorB[256], unsigned int hvectorA[256]); // Computes the histogram for each 8bit channel.
3695  bool histogramGray(unsigned int hvector[256]); // Computes the grayscale histogram (but does not convert the image to grayscale).
3696  int histogramIndex(unsigned int vectorsize, unsigned int *hvector); // Paletted images only. Returns the number of bins or zero if image is invalid.
3697  bool equalizeHistogram(gcgIMAGE *source);
3698 
3699 
3701  // Binarization.
3702  // The srcimage can be the destination (this).
3704  bool binarizeRGBA(gcgIMAGE *srcimage, int threR, int threG, int threB, int threA); // Binarize RGBA channels independently. Negative values indicate that the channel should not be binarized.
3705  bool binarizeGray(gcgIMAGE *srcimage, int threshold); // Binarize this image using the RGB average.
3706  bool binarizeIndex(gcgIMAGE *srcimage, int threshold); // Binarize the index values. For paletted images only.
3707 
3709  // Image bidimensional support processing functions.
3710  // The srcimage can be the destination (this).
3712  bool verticalFlip(); // Mirrors the image in the vertical direction.
3713 
3715  // Utilities
3717  bool unpackBMP(void *bmpHeader, unsigned char *bmpdata, unsigned int npalcolors, unsigned char *pal);
3718 
3719  private:
3720  // Load specific formats
3721  bool loadUncompressed8BitTGA(FILE *file);
3722  bool loadUncompressedTrueColorTGA(FILE *file);
3723  bool loadCompressedTrueColorTGA(FILE *file);
3724 
3725  // Unpacking BITMAP
3726  bool unpackPalettedBMP(void *bmpHeader, unsigned char *bmpdata, unsigned int npalcolors, unsigned char *pal);
3727  bool unpack16BitBMP(void *bmpHeader, unsigned char *bmpdata, unsigned int npalcolors, unsigned char *pal);
3728  bool unpack24BitBMP(void *bmpHeader, unsigned char *bmpdata);
3729  bool unpack32BitBMP(void *bmpHeader, unsigned char *bmpdata, unsigned int npalcolors, unsigned char *pal);
3730 
3731  // Specific converters
3732  bool convertPalettedto8Bits(gcgIMAGE *srcimage);
3733  bool convertPalettedto24Bits(gcgIMAGE *srcimage);
3734  bool convert16Bitsto24Bits(gcgIMAGE *srcimage);
3735  bool convert32Bitsto24Bits(gcgIMAGE *srcimage);
3736  bool convert16Bitsto32Bits(gcgIMAGE *srcimage);
3737 };
3738 
3740 
3748 
3753 
3759 
3770 GCG_API_FUNCTION unsigned int gcgPackRLE8(unsigned int fullsize, unsigned char *srcdata, unsigned char *RLEdata);
3771 
3780 GCG_API_FUNCTION unsigned int gcgUnpackRLE8(unsigned char *RLEdata, unsigned char *dstdata);
3781 
3792 GCG_API_FUNCTION unsigned int gcgPackRLE32(unsigned int fullsize, unsigned char *srcdata, unsigned char *RLEdata);
3793 
3802 GCG_API_FUNCTION unsigned int gcgUnpackRLE32(unsigned char *RLEdata, unsigned char *dstdata);
3804 
3809 
3821 GCG_API_FUNCTION unsigned int gcgCompressImageRLE8(unsigned int width, unsigned int height, unsigned char *srcdata, unsigned char *RLEdata);
3822 
3835 GCG_API_FUNCTION unsigned int gcgDecompressImageRLE8(unsigned int width, unsigned int height, unsigned char *RLEdata, unsigned char *dstdata);
3836 
3846 GCG_API_FUNCTION unsigned int gcgDecompressImageRLE4(unsigned int width, unsigned int height, unsigned char *RLEdata, unsigned char *dstdata);
3847 
3849 
3855 
3863 GCG_API_FUNCTION bool gcgSaveBytesAsText(unsigned int size, unsigned char *data, char *outputname);
3864 
3872 GCG_API_FUNCTION bool gcgSaveFloatsAsText(unsigned int size, float *data, char *outputname);
3873 
3880 GCG_API_FUNCTION bool gcgSaveBMPcode(char *inputname, char *outputname);
3881 
3883 
3884 
3892 
3893 // Macros for plotting graphs
3894 #define GCG_PLOT_MAX_LINES 16 // In any implementation, supremum is 255 lines
3895 #define GCG_PLOT_MAX_AXIS 3 // Prepared for 3D plots
3896 
3897 // Macros for range definition
3898 #define GCG_PLOT_X 0
3899 #define GCG_PLOT_Y 1
3900 #define GCG_PLOT_Z 2
3901 
3902 #define GCG_PLOT_RANGE_INI 0
3903 #define GCG_PLOT_RANGE_END 1
3904 
3905 class GCG_API_CLASS gcgPLOT : public gcgCLASS {
3906  private:
3907  // Basic struct for independent lines
3908  typedef struct __line {
3909  char *linename; // Name to identify this line
3910  float r, g, b, a; // Color for plotting this line
3911  float linewidth; // Line width
3912  unsigned short bitpattern; // Pattern for lines
3913 
3914  VECTOR3 *data; // Pointer to point data buffer
3915  unsigned int maxdata; // Data buffer capacity
3916  unsigned int ndata; // Number of points in buffer
3917  } LINE;
3918 
3919  // Basic struct for axis
3920  typedef struct __axis {
3921  char *title; // Title to identify this axis
3922  float r, g, b, a; // Color for plotting this title
3923  float linewidth; // Axis width
3924  unsigned short bitpattern; // Pattern for lines
3925  float ini; // Range start
3926  float end; // Range end
3927  } AXIS;
3928 
3929  // Lines buffer
3930  LINE lines[GCG_PLOT_MAX_LINES];
3931  unsigned int nlines; // Current number of lines
3932 
3933  // Plot axis
3934  AXIS axis[GCG_PLOT_MAX_AXIS]; // For each axis, information and a real interval.
3935 
3936  // Plot info
3937  float framebox[4]; // Output frame box
3938  float linewidth; // Frame line width
3939  float frameR, frameG, frameB, frameA; // Frame color
3940  float plotR, plotG, plotB, plotA; // Plot rectangle color
3941 
3942  unsigned int gridpixelsX; // Interval in pixels between two consecutive X values
3943  unsigned int gridpixelsY; // Interval in pixels between two consecutive Y values
3944  float gridR, gridG, gridB, gridA; // Grid color
3945 
3946  // Text output
3947  gcgTEXT textoutput; // Text output object
3948  unsigned int textWidthX, textHeightX; // Text extent in X
3949  unsigned int textWidthY, textHeightY; // Text extent in Y
3950  float factorX; // Text factor for X extents
3951 
3952  public:
3953  // Constructor
3954  gcgPLOT();
3955  virtual ~gcgPLOT();
3956 
3958  // INPUT DATA SPECIFICATION
3959  int newLine(); // Adds a new line to this plot
3960  bool addPoint2D(unsigned int lineindex, float x, float y);
3961  void setAxisRange(unsigned int axis, float ini, float end);
3962  void clipOutOfRange(unsigned int lineindex, unsigned int iaxis);
3963  void rangeFromData(unsigned int iaxis);
3964  void clearData(unsigned int lineindex);
3965  void clearAllData();
3966 
3968  // DRAW PARAMETERS SPECIFICATION
3969  void setFrame(float x, float y, float width, float height, float linewidth);
3970  void adjustFrame(float xoffset, float yoffset, float widthoffset, float heightoffset);
3971  void setFrameColor(float r, float g, float b, float a);
3972 
3973  void setPlotColor(float r, float g, float b, float a);
3974  void setGrid(unsigned int pixelsx, unsigned int pixelsy);
3975  void setGridColor(float r, float g, float b, float a);
3976 
3977  void setAxis(unsigned int axis, char *title, float r, float g, float b, float a, float linewidth, unsigned short bitpattern);
3978  void setLine(unsigned char lineindex, char *linename, float r, float g, float b, float a, float linewidth, unsigned short bitpattern);
3979 
3981  // DRAW FUNCTIONS
3982  void draw();
3983 };
3984 
3985 
3986 
3994 
3996 // Generate random numbers uniformly distributed with period (2^19937) - 1
3997 //
3998 // M. Matsumoto & T. Nishimura, "Mersenne Twister: A 623-Dimensionally
3999 // Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions
4000 // on Modeling and Computer Simulation, vol. 8, no. 1, 1998, pp. 3-30.
4002 class GCG_API_CLASS gcgRANDOM : public gcgCLASS {
4003  #define GCG_MERSENNE_N 624
4004  #define GCG_MERSENNE_MATRIX_A 0x9908b0df // Constant vector a
4005 
4006  private:
4007  unsigned long mt[GCG_MERSENNE_N]; // The array for the state vector
4008  unsigned long mag01[2]; // mag01[x] = x * MATRIX_A for x=0,1
4009  int mti; // Index for Mersenne Twisted state vector
4010  unsigned int lastInterval; // Last interval length for intRandom
4011  unsigned int RLimit; // Rejection limit used by intRandom
4012 
4013  public:
4014  // Constructor
4015  gcgRANDOM(); // Use C conventional rand() to define seed
4016  gcgRANDOM(unsigned int seed);
4017  virtual ~gcgRANDOM();
4018 
4019  // SERIES SPECIFICATION
4020  void setSeed(unsigned int seed);
4021 
4022  // Random number generation
4023  unsigned int bitRandom(); // Generate 32 random bits
4024  double random(); // Output random float in U[0, 1)
4025 
4026  // Random number generation in an interval
4027  int intRandom(int min, int max); // Output random integer in U[min, max]
4028  float floatRandom(float min, float max); // Output random float in U[min, max]
4029  double doubleRandom(double min, double max); // Output random double in U[min, max]
4030 };
4031 
4032 
4033 
4035 // Generate random numbers with Gaussian distribution with 0 mean and 1.0 as
4036 // standard-deviation N(0, 1).
4038 class GCG_API_CLASS gcgRANDOMGAUSSIAN : public gcgCLASS {
4039  private:
4040  gcgRANDOM ngen1; // Independent random generators
4041  gcgRANDOM ngen2;
4042  bool hasValue; // Flags the existence of a second value.
4043  double secondValue; // Keeps the second value
4044 
4045  public:
4046  // Constructor
4047  gcgRANDOMGAUSSIAN(); // Use C conventional rand() to define seed
4048  gcgRANDOMGAUSSIAN(unsigned int seed1, unsigned int seed2); // seed1 must be different than seed2.
4049  virtual ~gcgRANDOMGAUSSIAN();
4050 
4051  // SERIES SPECIFICATION: seed1 must be different than seed2.
4052  void setSeed(unsigned int seed1, unsigned int seed2);
4053 
4054  // RANDOM NUMBER GENERATION
4055  double random(); // Output random float in N(0, 1)
4056 };
4057 
4059 // Class to generate vectors with isotropic distribution.
4061 class GCG_API_CLASS gcgRANDOMVECTOR : public gcgCLASS {
4062  private:
4063  gcgRANDOM ngen1; // Independent random generators
4064  gcgRANDOM ngen2;
4065 
4066  public:
4067  // Constructor
4068  gcgRANDOMVECTOR(); // Use C conventional rand() to define seed
4069  gcgRANDOMVECTOR(unsigned int seed1, unsigned int seed2); // seed1 must be different than seed2.
4070  virtual ~gcgRANDOMVECTOR();
4071 
4072  // SERIES SPECIFICATION: seed1 must be different than seed2.
4073  void setSeed(unsigned int seed1, unsigned int seed2);
4074 
4075  // RANDOM VECTOR GENERATION
4076  void random(VECTOR3 v); // Output isotropic float vector in S^2.
4077  void random(VECTOR3d v); // Output isotropic double vector in S^2.
4078 };
4079 
4080 
4083 class GCG_API_CLASS gcgEVENTSPERSECOND : public gcgCLASS {
4084  private:
4085  void *handle;
4086 
4087  public:
4090 
4092  virtual ~gcgEVENTSPERSECOND();
4093 
4099  void startingEvents();
4100 
4107  float finishedEvents(int nevents = 1);
4108 
4109 
4114  float getEventsPerSecond(); // Retorna o ultimo EPS
4115 };
4116 
4117 
4119 // FUNCTION PROTOTYPES
4121 
4122 // Compute the Probability Distribution Function from a histogram.
4123 GCG_API_FUNCTION int gcgPDFfromHistogram(float *pdf, unsigned int *histogram, unsigned int Nbins);
4124 
4125 
4126 // Find the optimal threshold using Otsu's method.
4127 // Nobuyuki Otsu, "A threshold selection method from gray level histograms",
4128 // IEEE Transactions on Systems, Man and Cybernetics, vol.9, n.1, pp.62-66, jan/1979.
4129 GCG_API_FUNCTION unsigned int gcgOptimalThresholdOtsu(float *pdf, unsigned int left, unsigned int right);
4130 
4131 
4132 //************* Double precision versions *************
4133 GCG_API_FUNCTION int gcgPDFfromHistogram(double *pdf, unsigned int *histogram, unsigned int Nbins);
4134 GCG_API_FUNCTION unsigned int gcgOptimalThresholdOtsu(double *pdf, unsigned int left, unsigned int right);
4135 
4136 
4144 
4145 
4146 #define GCG_FRUSTUM_PARTIAL -1
4147 #define GCG_FRUSTUM_OUTSIDE 0
4148 #define GCG_FRUSTUM_INSIDE 1
4149 
4150 
4151 class GCG_API_CLASS gcgFRUSTUM : public gcgCLASS {
4152  public: // But read-only
4153  // CAMERA POSITION AND ORIENTATION: in world coordinates
4154  float x, y, z; // Observer's position
4155 
4156  VECTOR3 view; // Viewing direction: given by the quaternion
4157  VECTOR3 up; // Head up direction: given by the quaternion
4158  VECTOR3 right; // Right side direction: given by the quaternion
4159 
4160  private:
4161  // CAMERA PARAMETERS (always updated by changes in frustum)
4162  VECTOR4d orientation; // QUATERNION reflecting the viewers orientation.
4163  MATRIX4d view_matrix;
4164 
4165  // PARAMETROS DA PROJECAO
4166  MATRIX4d proj_matrix;
4167 
4168  // Equacoes dos planos do FRUSTUM corrente (redundante pois é calculado toda hora)
4169  // Coeficientes do plano superior do frustum
4170  float topA, topB, topC, topD;
4171 
4172  // Coeficientes do plano inferior do frustum
4173  float bottomA, bottomB, bottomC, bottomD;
4174 
4175  // Coeficientes do plano posterior do frustum
4176  float farA, farB, farC, farD;
4177 
4178  // Coeficientes do plano anterior do frustum
4179  float nearA, nearB, nearC, nearD;
4180 
4181  // Coeficientes do plano direito do frustum
4182  float rightA, rightB, rightC, rightD;
4183 
4184  // Coeficientes do plano esquerdo do frustum
4185  float leftA, leftB, leftC, leftD;
4186 
4187  public:
4188  //metodos construtores
4189  gcgFRUSTUM();
4190  virtual ~gcgFRUSTUM();
4191 
4193  // FREE VIEWER
4194 
4195  // Posicao do observador
4196  void setPosition(float x, float y, float z); // Posicao do observador
4197  void setPosition(double x, double y, double z); // Posicao do observador
4198  void setPosition(VECTOR3 pos); // Posicao do observador
4199  void setPosition(VECTOR3d pos); // Posicao do observador
4200 
4201  void movePosition(float dx, float dy, float dz); // Move o observador, dado um vetor
4202  void movePosition(double dx, double dy, double dz); // Move o observador, dado um vetor
4203  void movePosition(VECTOR3 pos); // Posicao do observador
4204  void movePosition(VECTOR3d pos); // Posicao do observador
4205 
4206  void advancePosition(float forward, float upward, float rightward); // Avanca usando as direcoes de visualizacao
4207  void advancePosition(double forward, double upward, double rightward); // Avanca usando as direcoes de visualizacao
4208 
4209  // Direcoes de observacao
4210  void resetOrientation(); // Loads the canonical reference system
4211 
4212  void setViewVector(float dirX, float dirY, float dirZ); // Configura vetor de direcao
4213  void setViewVector(double dirX, double dirY, double dirZ); // Configura vetor de direcao
4214  void setViewVector(VECTOR3 dir); // Configura vetor de direcao
4215  void setViewVector(VECTOR3d dir); // Configura vetor de direcao
4216 
4217  void setViewVectorSpherical(float latit, float longit); // latit em [-90, 90] longit em [-180, 180]
4218  void setViewVectorSpherical(double latit, double longit); // latit em [-90, 90] longit em [-180, 180]
4219 
4220  void setUpVector(float cimaX, float cimaY, float cimaZ); // Configura vetor acima
4221  void setUpVector(double cimaX, double cimaY, double cimaZ); // Configura vetor acima
4222  void setUpVector(VECTOR3 cima); // Configura vetor acima
4223  void setUpVector(VECTOR3d cima); // Configura vetor acima
4224 
4225  void setTarget(float alvoX, float alvoY, float alvoZ); // Ajusta as direcoes para visualizar o alvo.
4226  void setTarget(double alvoX, double alvoY, double alvoZ); // Ajusta as direcoes para visualizar o alvo.
4227  void setTarget(VECTOR3 alvo); // Ajusta as direcoes para visualizar o alvo.
4228  void setTarget(VECTOR3d alvo); // Ajusta as direcoes para visualizar o alvo.
4229 
4231  // OBSERVER IN THE CENTER OF AN UNITARY SPHERE (planetarium)
4232 
4233  // Rotates the unit ball where the observer is centered (planetarium)
4234  // - all functions use the local viewing system to apply rotations
4235  void rotateOrientationTrackball(double x1, double y1, double x2, double y2); // Trackball: p1,p2 em [-1,1]x[-1,1] plano no qual a bola é projetada. rotacao livre.
4236  void rotateOrientationSpherical(double dlat, double dlong); // Free rotation of the planetarium using spherical angles
4237  void rotateOrientationEuler(double pitch, double yaw, double row); // Rotation of the planetarium using Euler angles but keeping main axis aligned with Y e X
4238  void rotateOrientationAxis(double ang, double axisX, double axisY, double axisZ); // Rotation of the planetarium around a given axis.
4239 
4240  void alignAxis(); // Aligns up vector with Y, and right vector with X
4241 
4243  // OBSERVER IS FREE ROTATING AROUND AN ARBITRARY SPHERE (orbital)
4244 
4245  // Rotation of the observer's system around a sphere
4246  // - all functions align the local viewing system to the canonical system,
4247  // apply rotations and then align the canonical system back to the local system
4248  void rotateOrbitTrackball(double centroX, double centroY, double centroZ, double x1, double y1, double x2, double y2); // Trackball: p1,p2 em [-1,1]x[-1,1] plano no qual a esfera é projetada. rotacao livre.
4249  void rotateOrbitSpherical(double centroX, double centroY, double centroZ, double dlat, double dlong); // Spherical coordinates
4250  void rotateOrbitEuler(double centroX, double centroY, double centroZ, double pitch, double yaw, double roll); // Euler angles
4251 
4253  // OBSERVER IS FREE ROTATING AROUND ARBITRARY AXIS
4254 
4255  // Rotation of the observer's system around an axis
4256  void rotateAxis(double ang, double ox, double oy, double oz, double dirX, double dirY, double dirZ);
4257 
4258 
4260  // VISIBILITY TESTS
4261 
4262  int isPointVisible(float x, float y, float z);
4263  int isSphereVisible(float x, float y, float z, float raio);
4264  int isBoxVisible(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax);
4265 
4267  // GEOMETRIC PROJECTIONS
4268  void setPerspective(float fovh, float aspect, float prox, float dist);
4269  void setOrthographic(float left, float right, float top, float bottom, float near, float far);
4270 
4272  // GP Interfaces
4273 
4274  // Loads the projection and modelview matrix to OpenGL
4275  void exportOpenGL();
4276 
4278  // CAMERA INFORMATION RETRIEVAL
4279 
4280  void getViewMatrix(MATRIX4 matrot);
4281  void getViewMatrix(MATRIX4d matrot);
4282 
4283  void getProjectionMatrix(MATRIX4 matproj);
4284  void getProjectionMatrix(MATRIX4d matproj);
4285 
4286  private:
4287  // Calcula as direcoes do observador
4288  void computeParameters();
4289 };
4290 
4291 
4292 
4306 
4307 class gcgINTERNAL_VIDEO; // Internal class depends on platform
4308 
4319 class GCG_API_CLASS gcgVIDEO : public gcgCLASS {
4320  public:
4321  unsigned int width; //< Frame width in pixels. Read-only.
4322  unsigned int height; //< Frame height in pixels. Read-only.
4323  unsigned char bpp; //< Bits per pixel. Read-only.
4324  float fps; //< Frames per second. Read-only.
4325  unsigned int bitrate; //< Bits per second. Read-only.
4326 
4327  gcgINTERNAL_VIDEO *handle; //< Handle for internal video object or platform specific API. Read-only.
4328 
4329  public:
4330 
4333  gcgVIDEO();
4334 
4337  virtual ~gcgVIDEO();
4338 };
4339 
4352 
4353 class GCG_API_CLASS gcgVIDEOCAPTURE : public gcgVIDEO {
4354  unsigned int id; //< Current camera device identifier. Read-only.
4355 
4356  public:
4362  gcgVIDEOCAPTURE();
4363 
4367  virtual ~gcgVIDEOCAPTURE();
4368 
4374  virtual bool destroyVideo();
4375 
4380  virtual int getNumberOfCameras();
4381 
4390  virtual bool getCameraName(unsigned int id, char* pCameraName, unsigned int maxName);
4391 
4405  virtual bool openCamera(unsigned int id, unsigned int width, unsigned int height, unsigned char bpp, float fps);
4406 
4415  virtual bool start();
4416 
4425  virtual bool stop();
4426 
4434  virtual bool resume();
4435 
4443  virtual bool pause();
4444 
4450  virtual bool isCapturing();
4451 
4465  virtual bool setCallBackFunction(void (*callback) (gcgVIDEOCAPTURE*));
4466 
4476  virtual double copyFrameTo(gcgIMAGE *dstimg);
4477 };
4478 
4490 
4491 class GCG_API_CLASS gcgVIDEOFILE : public gcgVIDEO {
4492  public:
4497  gcgVIDEOFILE();
4498 
4502  virtual ~gcgVIDEOFILE();
4503 
4509  virtual bool destroyVideo();
4510 
4519  virtual bool openVideoFile(const char *filename);
4520 
4529  virtual long getFrameCount();
4530 
4540  virtual long getCurrentPosition();
4541 
4550  virtual bool setCurrentPosition(long newposition);
4551 
4562  virtual bool copyFrame(gcgIMAGE *dstimg);
4563 };
4564 
4565 
4566 
4580 
4581 
4589 class GCG_API_CLASS gcgDATA : public gcgCLASS {
4590  public:
4591  virtual ~gcgDATA(){};
4592 };
4593 
4594 
4595 
4609 class GCG_API_CLASS gcgITERATOR : public gcgCLASS {
4610  public:
4615  virtual ~gcgITERATOR();
4616 
4625  virtual gcgDATA *next() = 0;
4626 };
4627 
4628 
4637 class GCG_API_CLASS gcgDATASTRUCTURE : public gcgCLASS {
4640  virtual uintptr_t getCounter() = 0;
4641 
4647  virtual bool deleteAll() = 0;
4648 
4664  virtual gcgITERATOR *getIterator(int traversemode = 0) = 0;
4665 
4685  virtual gcgITERATOR *detach(int traversemode = 0) = 0;
4686 };
4687 
4697 class GCG_API_CLASS gcgLINK : public gcgDATA {
4698  public:
4699  union {
4702  };
4703 };
4704 
4716 class GCG_API_CLASS gcgDOUBLELINK : public gcgLINK {
4717  public:
4718  union {
4721  };
4722 };
4723 
4724 
4735 class GCG_API_CLASS gcgLISTSTRUCTURE : public gcgDATASTRUCTURE {
4736  public:
4743  virtual bool insertFirst(gcgLINK *newnode) = 0;
4744 
4751  virtual bool insertLast(gcgLINK *newnode) = 0;
4752 
4765  virtual bool insertAfter(gcgLINK *newnode, gcgLINK *node) = 0;
4766 
4779  virtual bool insertBefore(gcgLINK *newnode, gcgLINK *node) = 0;
4780 
4793  virtual bool moveToFirst(gcgLINK *node) = 0;
4794 
4806  virtual bool moveToLast(gcgLINK *node) = 0;
4807 
4817  virtual bool switchNodes(gcgLINK *node1, gcgLINK *node2) = 0;
4818 
4826  virtual bool remove(gcgLINK *node) = 0;
4827 };
4828 
4829 
4830 
4836 
4837 
4838 
4853 class GCG_API_CLASS gcgLINKEDLIST : public gcgLISTSTRUCTURE {
4854  public:
4857  uintptr_t counter;
4858 
4859  public:
4865  gcgLINKEDLIST();
4866 
4875  virtual ~gcgLINKEDLIST();
4876 
4877  // gcgLINKEDLIST specific methods
4878 
4889  gcgLINK *dequeueFirst();
4890 
4891 
4903  gcgLINK *dequeueLast();
4904 
4905  // gcgDATASTRUCTURE interface
4906 
4909  uintptr_t getCounter();
4910 
4915  bool deleteAll();
4916 
4930  gcgITERATOR *getIterator(int traversemode = 0);
4931 
4949  gcgITERATOR *detach(int traversemode = 0);
4950 
4951  // gcgLISTSTRUCTURE interface
4952 
4964  bool insertFirst(gcgLINK *node);
4965 
4977  bool insertLast(gcgLINK *node);
4978 
4993  bool insertAfter(gcgLINK *newnode, gcgLINK *node);
4994 
5009  bool insertBefore(gcgLINK *newnode, gcgLINK *node);
5010 
5024  bool moveToFirst(gcgLINK *node);
5025 
5039  bool moveToLast(gcgLINK *node);
5040 
5050  bool switchNodes(gcgLINK *node1, gcgLINK *node2);
5051 
5064  bool remove(gcgLINK *node);
5065 };
5066 
5067 
5068 
5069 
5084 class GCG_API_CLASS gcgDOUBLELINKEDLIST : public gcgLISTSTRUCTURE {
5085  public:
5088  uintptr_t counter;
5089 
5090  public:
5097 
5106  virtual ~gcgDOUBLELINKEDLIST();
5107 
5108  // gcgDOUBLELINKEDLIST specific methods
5109 
5120  gcgLINK *dequeueFirst();
5121 
5122 
5133  gcgLINK *dequeueLast();
5134 
5135  // gcgDATASTRUCTURE interface
5136 
5139  uintptr_t getCounter();
5140 
5145  bool deleteAll();
5146 
5161  gcgITERATOR *getIterator(int traversemode = 0);
5162 
5180  gcgITERATOR *detach(int traversemode = 0);
5181 
5182 
5183  // gcgLISTSTRUCTURE interface
5184 
5197  bool insertFirst(gcgLINK *node);
5198 
5211  bool insertLast(gcgLINK *node);
5212 
5227  bool insertAfter(gcgLINK *newnode, gcgLINK *node);
5228 
5243  bool insertBefore(gcgLINK *newnode, gcgLINK *node);
5244 
5258  bool moveToFirst(gcgLINK *node);
5259 
5273  bool moveToLast(gcgLINK *node);
5274 
5284  bool switchNodes(gcgLINK *node1, gcgLINK *node2);
5285 
5297  bool remove(gcgLINK *node);
5298 };
5299 
5300 
5301 
5302 
5303 
5304 
5305 
5319 
5320 
5321 
5334 class GCG_API_CLASS gcgORDEREDNODE : public gcgDOUBLELINK {
5335  public:
5336  union {
5337  signed char status;
5338  signed char balance;
5339  };
5340 };
5341 
5342 
5354 class GCG_API_CLASS gcgORDEREDSTRUCTURE : public gcgDATASTRUCTURE {
5355  public:
5374  virtual gcgORDEREDNODE *insert(gcgORDEREDNODE *newnode) = 0;
5375 
5394  virtual gcgORDEREDNODE *search(gcgORDEREDNODE *key) = 0;
5395 
5415  virtual gcgORDEREDNODE *remove(gcgORDEREDNODE *key) = 0;
5416 
5433  virtual int compare(gcgORDEREDNODE *refnode1, gcgORDEREDNODE *refnode2) = 0;
5434 };
5435 
5436 
5437 
5456 class GCG_API_CLASS gcgAVLTREE : public gcgDATASTRUCTURE {
5457  public:
5459  uintptr_t counter;
5460 
5461  private:
5462  struct _AVL_LEVEL_PATH *path;
5463  int levels;
5464  int maxlevels;
5465 
5466  public:
5469  gcgAVLTREE();
5470 
5473  virtual ~gcgAVLTREE();
5474 
5475  // gcgORDEREDSTRUCTURE interface
5476 
5493  gcgORDEREDNODE *insert(gcgORDEREDNODE *newnode);
5494 
5511  gcgORDEREDNODE *search(gcgORDEREDNODE *key);
5512 
5531  gcgORDEREDNODE *remove(gcgORDEREDNODE *key);
5532 
5533  // gcgDATASTRUCTURE interface
5534 
5539  uintptr_t getCounter();
5540 
5545  virtual bool deleteAll();
5546 
5561  gcgITERATOR *getIterator(int traversemode = 0);
5562 
5580  gcgITERATOR *detach(int traversemode = 0);
5581 
5597  virtual int compare(gcgORDEREDNODE *refnode1, gcgORDEREDNODE *refnode2) = 0;
5598 };
5599 
5600 
5623 class GCG_API_CLASS gcgHASHTABLE : public gcgORDEREDSTRUCTURE {
5624  public:
5625  uintptr_t counter;
5626  uintptr_t capacity;
5627  float minimumload;
5628  float maximumload;
5630 
5631  public:
5648  gcgHASHTABLE(uintptr_t capacity = 0, float minload = 0.8, float maxload = 16.0);
5649 
5652  virtual ~gcgHASHTABLE();
5653 
5654  // gcgHASHTABLE specific methods
5655 
5669  bool setCapacity(uintptr_t capacity);
5670 
5689  bool setLoadLimits(float minload, float maxload);
5690 
5691  // gcgDATASTRUCTURE interface
5692 
5697  uintptr_t getCounter();
5698 
5704  bool deleteAll();
5705 
5720  gcgITERATOR *getIterator(int traversemode = 0);
5721 
5739  gcgITERATOR *detach(int traversemode = 0);
5740 
5741  // gcgORDEREDSTRUCTURE interface
5742 
5762  gcgORDEREDNODE *insert(gcgORDEREDNODE *newnode);
5763 
5778  gcgORDEREDNODE *search(gcgORDEREDNODE *key);
5779 
5799  gcgORDEREDNODE *remove(gcgORDEREDNODE *key);
5800 
5816  virtual int compare(gcgORDEREDNODE *refnode1, gcgORDEREDNODE *refnode2) = 0;
5817 
5832  virtual long hash(gcgORDEREDNODE *node) = 0;
5833 };
5834 
5835 
5836 
5850 
5879 typedef union _GCGDIGITALKEY {
5880  void *pkey;
5881  intptr_t intkey;
5882  long lkey;
5883  int ikey;
5884  short skey;
5885  char ckey;
5886 
5887  // Constructors for implicit initialization
5888  _GCGDIGITALKEY() : pkey(NULL) {}
5889  _GCGDIGITALKEY(int64_t l) : intkey((intptr_t) l) {}
5890  _GCGDIGITALKEY(int l) : intkey((intptr_t) l) {}
5891  _GCGDIGITALKEY(short l) : intkey((intptr_t) l) {}
5892  _GCGDIGITALKEY(char l) : intkey((intptr_t) l) {}
5893  _GCGDIGITALKEY(uint64_t l) : intkey((intptr_t) l) {}
5894  _GCGDIGITALKEY(unsigned int l) : intkey((intptr_t) l) {}
5895  _GCGDIGITALKEY(unsigned short l) : intkey((intptr_t) l) {}
5896  _GCGDIGITALKEY(unsigned char l) : intkey((intptr_t) l) {}
5897  _GCGDIGITALKEY(void *p) : pkey(p) {}
5898  _GCGDIGITALKEY(char *p) : pkey((void*) p) {}
5899  _GCGDIGITALKEY(const char *p) : pkey((void*) p) {}
5900 } GCGDIGITALKEY;
5901 
5902 
5930 
5931 class GCG_API_CLASS gcgDATAMAP : public gcgDATASTRUCTURE {
5932  public:
5933 
5958  virtual gcgDATA *insert(GCGDIGITALKEY key, gcgDATA *value) = 0;
5959 
5981  virtual gcgDATA *search(GCGDIGITALKEY key) = 0;
5982 
6004  virtual gcgDATA *remove(GCGDIGITALKEY key) = 0;
6005 };
6006 
6007 
6008 
6009 
6015 
6016 
6049 
6050 class GCG_API_CLASS gcgPATRICIAMAP : public gcgDATAMAP {
6051  public:
6052  uintptr_t counter;
6053  unsigned int keysize;
6054 
6055  private:
6056  struct _GCG_PATRICIA_NODE *root;
6057  gcgDATA *insertByValue(GCGDIGITALKEY key, gcgDATA *value); // Optimization: faster insertion for keys with size fixed up to sizeof(intptr_t)
6058  gcgDATA *removeByValue(GCGDIGITALKEY key); // Optimization: faster removals for keys with size fixed up to sizeof(intptr_t)
6059 
6060  public:
6073  gcgPATRICIAMAP(unsigned int keysize);
6074 
6078  virtual ~gcgPATRICIAMAP();
6079 
6096  bool setKeySize(unsigned int keysize);
6097 
6131  gcgITERATOR *suffixIterator(GCGDIGITALKEY prefixkey, unsigned int prefixsize = 0, int traversemode = 0);
6132 
6133 
6134  // gcgDATASTRUCTURE interface
6135 
6140  uintptr_t getCounter();
6141 
6149  bool deleteAll();
6150 
6167  gcgITERATOR *getIterator(int traversemode = 0);
6168 
6189  gcgITERATOR *detach(int traversemode = 0);
6190 
6191  // gcgORDEREDSTRUCTURE interface
6192 
6217  virtual gcgDATA *insert(GCGDIGITALKEY key, gcgDATA *value);
6218 
6240  virtual gcgDATA *search(GCGDIGITALKEY key);
6241 
6264  virtual gcgDATA *remove(GCGDIGITALKEY key);
6265 };
6266 
6267 
6268 
6282 
6287 
6296 GCG_API_FUNCTION unsigned int gcgGetNumberOfProcessors();
6297 
6322 class GCG_API_CLASS gcgTHREAD : public gcgCLASS {
6323  public:
6324  void *handle;
6325 
6326  public:
6329  gcgTHREAD();
6330 
6337  virtual ~gcgTHREAD();
6338 
6345  bool startThread();
6346 
6361  bool abortThread();
6362 
6370  bool waitThread();
6371 
6375  bool isRunning();
6376 
6377  public:
6384  virtual void run() = 0;
6385 };
6386 
6421 class GCG_API_CLASS gcgLOCK : public gcgCLASS {
6422  public:
6423  void *handle;
6424 
6428  gcgLOCK();
6429 
6435  virtual ~gcgLOCK();
6436 
6451  bool lock(long timeoutUsec = -1);
6452 
6459  bool unlock();
6460 
6483  bool wait(long timeoutUsec = -1);
6484 
6496  bool wakeUp(int numberOfThreads = -1);
6497 };
6498 
6507 class GCG_API_CLASS gcgQUEUE : public gcgCLASS {
6508  private:
6509  void *handle;
6510 
6511  public:
6518  gcgQUEUE();
6519 
6528  virtual ~gcgQUEUE();
6529 
6544  bool enqueueTail(gcgLINK *node);
6545 
6559  bool enqueueHead(gcgLINK *node);
6560 
6571  gcgLINK *dequeue();
6572 
6591  gcgLINK *waitDequeue(long timeoutUsec = -1);
6592 
6600  bool isEmpty();
6601 
6609  uintptr_t getCounter();
6610 
6620  bool deleteAll();
6621 
6641  gcgLOCK *wakeUpWhenEnqueued(gcgLOCK *notifyme, int wakeupNumThreads);
6642 
6643 
6665  gcgLOCK *wakeUpWhenDequeued(gcgLOCK *notifyme, int wakeupNumThreads);
6666 };
6667 
6668 
6696 class GCG_API_CLASS gcgCACHE : public gcgCLASS {
6697  public:
6698  unsigned long totalcost;
6699  unsigned long capacity;
6700  unsigned int keysize;
6701 
6702  private:
6703  void *handle;
6704 
6705  public:
6716  gcgCACHE(unsigned int keysizebytes, unsigned long cachecapacity);
6717 
6721  virtual ~gcgCACHE();
6722 
6724  // Application interface: retrieving data from the cache
6725 
6746  void *get(void *key);
6747 
6758  bool flush(void *key);
6759 
6774  bool setCapacity(unsigned long maximumtotalcost);
6775 
6785  bool setKeySize(unsigned int keysizebytes);
6786 
6788  // Data interface: managing data creation, removal and persistence.
6789 
6804  virtual void *retrieveData(void *key, unsigned long *datacost) = 0;
6805 
6817  virtual void discardData(void *key, void *data, unsigned long datacost) = 0;
6818 };
6819 
6820 
6821 
6832 class GCG_API_CLASS gcgJOB : public gcgORDEREDNODE {
6833  public:
6837  gcgJOB() {}
6838 
6842  virtual ~gcgJOB() {}
6843 
6847  virtual void run() = 0;
6848 };
6849 
6850 
6872 class GCG_API_CLASS gcgTHREADPOOL : public gcgCLASS {
6873  public:
6874  void *handle;
6875 
6883  gcgTHREADPOOL(unsigned int numThreads = gcgGetNumberOfProcessors());
6884 
6895  virtual ~gcgTHREADPOOL();
6896 
6916  bool setNumberOfThreads(unsigned int numThreads = gcgGetNumberOfProcessors());
6917 
6925  unsigned int getNumberOfThreads();
6926 
6941  bool assignJob(gcgJOB *job);
6942 
6943 
6949  uintptr_t getNumberOfPendingJobs();
6950 
6962  bool wait();
6963 
6978  bool waitAndDestroy();
6979 
6999  bool destroyPool();
7000 
7021  bool setOutputQueue(gcgQUEUE *executed, gcgQUEUE *discarded = NULL);
7022 
7034  bool getOutputQueue(gcgQUEUE **pexecuted, gcgQUEUE **pdiscarded);
7035 
7042  bool isRunning();
7043 };
7044 
7045 
7046 
7065 class GCG_API_CLASS gcgPRODUCERCONSUMER : public gcgCLASS {
7066  private:
7067  void *handle;
7068 
7069  public:
7075  gcgPRODUCERCONSUMER(unsigned int bufferlength = 4);
7076 
7078  virtual ~gcgPRODUCERCONSUMER();
7079 
7085  bool setBufferSize(unsigned int bufferlength);
7086 
7090  bool destroyProducerConsumer();
7091 
7104  bool put(void *val);
7105 
7118  void *get();
7119 
7122  uintptr_t getCounter();
7123 
7141  void setTimeout(long timeoutprod, long timeoutcons);
7142 
7155  void enable(bool enabled);
7156 };
7157 
7159 
7167 
7173 class GCG_API_CLASS gcgTEXTURE2D : public gcgCLASS {
7174  public:
7175  unsigned int width;
7176  unsigned int height;
7177 
7178  unsigned int actualwidth;
7179  unsigned int actualheight;
7180 
7181  unsigned int idOpengl;
7182 
7184  int format;
7185  int type;
7186 
7187  public:
7191  gcgTEXTURE2D();
7192 
7196  virtual ~gcgTEXTURE2D();
7197 
7201  bool destroyTexture();
7202 
7226  bool createTexture(unsigned int width, unsigned int height, unsigned char bpp, bool usealpha, bool mipmapped = false);
7227 
7249  bool uploadImage(gcgIMAGE *srcimage, int destposX = 0, int destposY = 0, unsigned int level = 0, bool mipmapped = false);
7250 
7260  bool isCompatibleWith(gcgIMAGE *srcimage);
7261 
7270  bool bind();
7271 
7278  bool unbind();
7279 };
7280 
7281 
7282 
7290 
7295 
7300 
7301 // Event codes for waitEvent() of gcgINETPEER
7302 
7305 #define GCG_EVENT_NOTREADYORDISCONNECTED 0x0
7306 
7308 #define GCG_EVENT_RECEIVEREADY 0x1
7309 
7312 #define GCG_EVENT_SENDREADY 0x2
7313 
7315 #define GCG_EVENT_RECEIVESENDREADY (GCG_EVENT_RECEIVEREADY | GCG_EVENT_SENDREADY) // 3
7316 
7317 // Extra event codes for eventHandler() of gcgINETSERVICE
7318 
7320 #define GCG_EVENT_INSERTED 0x4
7321 
7323 #define GCG_EVENT_REMOVED 0x8
7324 
7326 #define GCG_EVENT_VISIT 0x10
7327 
7329 #define GCG_EVENT_NEWCONNECTION 0x20
7330 
7335 
7349 class GCG_API_CLASS gcgINETPEER : public gcgCLASS {
7350  public:
7351  int local_ip[4];
7354 
7355  int remote_ip[4];
7357 
7358  void *handle;
7359 
7360  public:
7362  gcgINETPEER();
7363 
7365  virtual ~gcgINETPEER(); // Safely disconnects the peer
7366 
7374  bool connectToHost(const char *host, int port);
7375 
7390  bool send(void *buffer, unsigned int nbytes);
7391 
7407  int receive(void *buffer, unsigned int nbytes);
7408 
7419  bool getConnectionFrom(gcgINETPEER *oldpeerobject);
7420 
7430  bool shutdownSend();
7431 
7441  bool shutdownReceive();
7442 
7450  bool disconnect();
7451 
7478  int waitEvent(bool checkReceive = true, bool checkSend = false, int timeoutUsec = -1);
7479 };
7480 
7481 
7510 class GCG_API_CLASS gcgINETSERVICE : public gcgCLASS {
7511  public:
7513  void *handle;
7514 
7515  public:
7517  gcgINETSERVICE();
7518 
7522  virtual ~gcgINETSERVICE();
7523 
7533  bool listenPort(int port);
7534 
7541  bool stopListening();
7542 
7562  bool insertPeer(gcgINETPEER *peer);
7563 
7572  int getPeerCount();
7573 
7599  bool flagEvents(gcgINETPEER *peer, bool checkReceive, bool checkSend);
7600 
7613  bool postRemove(gcgINETPEER *peer);
7614 
7625  bool postRemoveAll();
7626 
7637  bool postVisit(gcgINETPEER *peer);
7638 
7647  bool postVisitAll();
7648 
7657  bool postExit();
7658 
7696  bool processEvents(unsigned int numThreads = gcgGetNumberOfProcessors());
7697 
7706  bool setTimeout(int timeoutUsec);
7707 
7721  virtual void eventHandler(int events, gcgINETPEER *peer) = 0;
7722 };
7723 
7725 
7726 // End of definitions included once
7727 #endif // #if _COUNTER_GCG_ == 1
7728 
7740 
7741 
7742 // Next definitions are inserted more than once
7743 
7744 // Define the type
7745 #undef NUMTYPE
7746 #undef COERSIONFLOAT
7747 #undef COERSIONDOUBLE
7748 #undef COERSIONSHORT
7749 #undef COERSIONINT
7750 #undef COERSIONLONG
7751 #if _COUNTER_GCG_ == 1
7752  #define NUMTYPE float
7753  #define COERSIONFLOAT float
7754  #define COERSIONDOUBLE double
7755  #define COERSIONSHORT float
7756  #define COERSIONINT float
7757  #define COERSIONLONG float
7758 #elif _COUNTER_GCG_ == 2
7759  #define NUMTYPE double
7760  #define COERSIONFLOAT double
7761  #define COERSIONDOUBLE double
7762  #define COERSIONSHORT double
7763  #define COERSIONINT double
7764  #define COERSIONLONG double
7765 #elif _COUNTER_GCG_ == 3
7766  #define NUMTYPE short
7767  #define COERSIONFLOAT float
7768  #define COERSIONDOUBLE double
7769  #define COERSIONSHORT short
7770  #define COERSIONINT int
7771  #define COERSIONLONG long
7772 #elif _COUNTER_GCG_ == 4
7773  #define NUMTYPE int
7774  #define COERSIONFLOAT float
7775  #define COERSIONDOUBLE double
7776  #define COERSIONSHORT int
7777  #define COERSIONINT int
7778  #define COERSIONLONG long
7779 #elif _COUNTER_GCG_ == 5
7780  #define NUMTYPE long
7781  #define COERSIONFLOAT float
7782  #define COERSIONDOUBLE double
7783  #define COERSIONSHORT long
7784  #define COERSIONINT long
7785  #define COERSIONLONG long
7786 #endif
7787 
7793 
7794 
7802 template <>
7803 class GCG_API_CLASS gcgDISCRETE1D<NUMTYPE> : public gcgCLASS {
7804  public:
7805  NUMTYPE *data;
7806  unsigned int length;
7808 
7809  int origin;
7811 
7812  public:
7815  gcgDISCRETE1D();
7816 
7830  gcgDISCRETE1D(unsigned int length, int origin, NUMTYPE *sampledata = NULL, bool isstaticdata = false, int borderextension = GCG_BORDER_EXTENSION_CLAMP);
7831 
7834  virtual ~gcgDISCRETE1D();
7835 
7852  bool createSignal(unsigned int length, int origin, NUMTYPE *sampledata = NULL, bool isstaticdata = false, int borderextension = GCG_BORDER_EXTENSION_CLAMP);
7853 
7858  bool destroySignal();
7859 
7872  bool createSimilar(gcgDISCRETE1D<float> *source);
7873 
7886  bool createSimilar(gcgDISCRETE1D<double> *source);
7887 
7900  bool createSimilar(gcgDISCRETE1D<short> *source);
7901 
7914  bool createSimilar(gcgDISCRETE1D<int> *source);
7915 
7928  bool createSimilar(gcgDISCRETE1D<long> *source);
7929 
7930  bool isCompatibleWith(gcgDISCRETE1D<float> *source); // Checks if both signals are compatible: same dimensions, same origin.
7931  bool isCompatibleWith(gcgDISCRETE1D<double> *source);
7932  bool isCompatibleWith(gcgDISCRETE1D<short> *source);
7933  bool isCompatibleWith(gcgDISCRETE1D<int> *source);
7934  bool isCompatibleWith(gcgDISCRETE1D<long> *source);
7935  bool duplicateSignal(gcgDISCRETE1D<float> *source); // Makes an independent copy of the source signal.
7936  bool duplicateSignal(gcgDISCRETE1D<double> *source);
7937  bool duplicateSignal(gcgDISCRETE1D<short> *source);
7938  bool duplicateSignal(gcgDISCRETE1D<int> *source);
7939  bool duplicateSignal(gcgDISCRETE1D<long> *source);
7940  bool duplicateSubsignal(gcgDISCRETE1D<float> *source, int left, unsigned int width); // Makes an independent copy of the source subsignal.
7941  bool duplicateSubsignal(gcgDISCRETE1D<double> *source, int left, unsigned int width);
7942  bool duplicateSubsignal(gcgDISCRETE1D<short> *source, int left, unsigned int width);
7943  bool duplicateSubsignal(gcgDISCRETE1D<int> *source, int left, unsigned int width);
7944  bool duplicateSubsignal(gcgDISCRETE1D<long> *source, int left, unsigned int width);
7945 
7947  // Data access and modification. Not recommended for high
7948  // performance processes. Uses the origin and border extension.
7950  NUMTYPE getDataSample(int i);
7951  bool setDataSample(int i, NUMTYPE value);
7952 
7954  // Signal processing functions
7955  // The src can be the destination (this).
7957  bool normalize(gcgDISCRETE1D<float> *src, float floor = 0, float ceil = 1);
7958  bool normalize(gcgDISCRETE1D<double> *src, double floor = 0, double ceil = 1);
7959  bool normalize(gcgDISCRETE1D<short> *src, short floor = 0, short ceil = 1);
7960  bool normalize(gcgDISCRETE1D<int> *src, int floor = 0, int ceil = 1);
7961  bool normalize(gcgDISCRETE1D<long> *src, long floor = 0, long ceil = 1);
7962  bool convolution(gcgDISCRETE1D<NUMTYPE> *src, gcgDISCRETE1D<float> *mask);
7963  bool convolution(gcgDISCRETE1D<NUMTYPE> *src, gcgDISCRETE1D<double> *mask);
7964  bool convolution(gcgDISCRETE1D<NUMTYPE> *src, gcgDISCRETE1D<short> *mask);
7965  bool convolution(gcgDISCRETE1D<NUMTYPE> *src, gcgDISCRETE1D<int> *mask);
7966  bool convolution(gcgDISCRETE1D<NUMTYPE> *src, gcgDISCRETE1D<long> *mask);
7967  bool templateMatching(unsigned int imgleft, unsigned int imgwidth, gcgDISCRETE1D<float> *mask, int *position);
7968  bool templateMatching(unsigned int imgleft, unsigned int imgwidth, gcgDISCRETE1D<double> *mask, int *position);
7969  bool templateMatching(unsigned int imgleft, unsigned int imgwidth, gcgDISCRETE1D<short> *mask, int *position);
7970  bool templateMatching(unsigned int imgleft, unsigned int imgwidth, gcgDISCRETE1D<int> *mask, int *position);
7971  bool templateMatching(unsigned int imgleft, unsigned int imgwidth, gcgDISCRETE1D<long> *mask, int *position);
7972 
7973  // Computes the scalar product of two signals. At least one of the signals must have extension
7974  // GCG_BORDER_EXTENSION_ZERO. Aligns the origin of srcsignal2 with the sample of this object
7975  // with coordinate atX.
7976  COERSIONFLOAT scalarProduct(int atX, gcgDISCRETE1D<float> *srcsignal2);
7977  COERSIONDOUBLE scalarProduct(int atX, gcgDISCRETE1D<double> *srcsignal2);
7978  COERSIONSHORT scalarProduct(int atX, gcgDISCRETE1D<short> *srcsignal2);
7979  COERSIONINT scalarProduct(int atX, gcgDISCRETE1D<int> *srcsignal2);
7980  COERSIONLONG scalarProduct(int atX, gcgDISCRETE1D<long> *srcsignal2);
7981 
7982  // Produces a binary signal. The samples are mapped to: lessvalue, if sample is below the threshold; greaterequalvalue,
7983  // if the sample is greater or equal the threshold. The src can be the destination (this).
7984  bool binarize(gcgDISCRETE1D<float> *src, float threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
7985  bool binarize(gcgDISCRETE1D<double> *src, double threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
7986  bool binarize(gcgDISCRETE1D<short> *src, short threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
7987  bool binarize(gcgDISCRETE1D<int> *src, int threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
7988  bool binarize(gcgDISCRETE1D<long> *src, long threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
7989 
7991  // Signal composition. Source signals must be compatible.
7992  // The destination can be one of the sources.
7994  bool scale(gcgDISCRETE1D<float> *srcsignal1, COERSIONFLOAT weight, COERSIONFLOAT addthis = 0); // Scales a signal: I = w * I1 + at
7995  bool scale(gcgDISCRETE1D<double> *srcsignal1, COERSIONDOUBLE weight, COERSIONDOUBLE addthis = 0);
7996  bool scale(gcgDISCRETE1D<short> *srcsignal1, COERSIONSHORT weight, COERSIONSHORT addthis = 0);
7997  bool scale(gcgDISCRETE1D<int> *srcsignal1, COERSIONINT weight, COERSIONINT addthis = 0);
7998  bool scale(gcgDISCRETE1D<long> *srcsignal1, COERSIONLONG weight, COERSIONLONG addthis = 0);
7999  bool power(gcgDISCRETE1D<float> *srcsignal1, COERSIONFLOAT power); // Powers a signal: I = I1^power
8000  bool power(gcgDISCRETE1D<double> *srcsignal1, COERSIONDOUBLE power);
8001  bool power(gcgDISCRETE1D<short> *srcsignal1, COERSIONSHORT power);
8002  bool power(gcgDISCRETE1D<int> *srcsignal1, COERSIONINT power);
8003  bool power(gcgDISCRETE1D<long> *srcsignal1, COERSIONLONG power);
8004  bool combineAdd(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<float> *srcsignal2, COERSIONFLOAT weight1 = 1, COERSIONFLOAT weight2 = 1); // Combine two signals by addition: I = w1 * I1 + w2 * I2
8005  bool combineAdd(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<double> *srcsignal2, COERSIONDOUBLE weight1 = 1, COERSIONDOUBLE weight2 = 1);
8006  bool combineAdd(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<short> *srcsignal2, COERSIONSHORT weight1 = 1, COERSIONSHORT weight2 = 1);
8007  bool combineAdd(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<int> *srcsignal2, COERSIONINT weight1 = 1, COERSIONINT weight2 = 1);
8008  bool combineAdd(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<long> *srcsignal2, COERSIONLONG weight1 = 1, COERSIONLONG weight2 = 1);
8009  bool combineMult(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<float> *srcsignal2, COERSIONFLOAT add1 = 0, COERSIONFLOAT add2 = 0); // Combine two signals by multiplication: I = (a1 + I1) * (a2 + I2)
8010  bool combineMult(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<double> *srcsignal2, COERSIONDOUBLE add1 = 0, COERSIONDOUBLE add2 = 0);
8011  bool combineMult(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<short> *srcsignal2, COERSIONSHORT add1 = 0, COERSIONSHORT add2 = 0);
8012  bool combineMult(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<int> *srcsignal2, COERSIONINT add1 = 0, COERSIONINT add2 = 0);
8013  bool combineMult(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<long> *srcsignal2, COERSIONLONG add1 = 0, COERSIONLONG add2 = 0);
8014  bool combineNorm(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<float> *srcsignal2); // Combine two signals by the L2 norm: I = sqrt(I1^2 + I2^2)
8015  bool combineNorm(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<double> *srcsignal2);
8016  bool combineNorm(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<short> *srcsignal2);
8017  bool combineNorm(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<int> *srcsignal2);
8018  bool combineNorm(gcgDISCRETE1D<NUMTYPE> *srcsignal1, gcgDISCRETE1D<long> *srcsignal2);
8019 
8021  // Interfaces for gcgIMAGE
8023  bool exportGrayScaleImage(gcgIMAGE *outimage, bool normalize);
8024 };
8025 
8026 
8032 
8033 template <>
8034 class GCG_API_CLASS gcgDISCRETE2D<NUMTYPE> : public gcgCLASS {
8035  public:
8036  // Signal info and data
8037  NUMTYPE *data;
8038  unsigned int width;
8039  unsigned int height;
8040  bool isstaticdata;
8041 
8042  // Origin coordinate: indicates the position of the origin (x = 0, y = 0) of the signal.
8043  int originX;
8044  int originY;
8045 
8046  int extensionX;
8047  int extensionY;
8048 
8049  int errorcode;
8050 
8051  public:
8053  // Discrete signal construction
8055  gcgDISCRETE2D();
8056  gcgDISCRETE2D(unsigned int width, unsigned int length, int originX, int originY, NUMTYPE *sampledata = NULL,
8057  bool isstaticdata = false, int borderextX = GCG_BORDER_EXTENSION_CLAMP, int borderextY = GCG_BORDER_EXTENSION_CLAMP);
8058  virtual ~gcgDISCRETE2D();
8059 
8061  // Empty discrete signal creation and destruction
8063  bool createSignal(unsigned int width, unsigned int height, int originX, int originY, NUMTYPE *sampledata = NULL,
8064  bool isstaticdata = false, int borderextX = GCG_BORDER_EXTENSION_CLAMP, int borderextY = GCG_BORDER_EXTENSION_CLAMP);
8065  void destroySignal(); // Release all resources used by this discrete signal.
8066 
8068  // Discrete signal copying, duplication and conversion.
8070  bool createSimilar(gcgDISCRETE2D<float> *source); // Creates a signal similar as the source. The data is not copied.
8071  bool createSimilar(gcgDISCRETE2D<double> *source);
8072  bool createSimilar(gcgDISCRETE2D<short> *source);
8073  bool createSimilar(gcgDISCRETE2D<int> *source);
8074  bool createSimilar(gcgDISCRETE2D<long> *source);
8075  bool isCompatibleWith(gcgDISCRETE2D<float> *source); // Checks if both signals are compatible: same dimensions, same origin.
8076  bool isCompatibleWith(gcgDISCRETE2D<double> *source);
8077  bool isCompatibleWith(gcgDISCRETE2D<short> *source);
8078  bool isCompatibleWith(gcgDISCRETE2D<int> *source);
8079  bool isCompatibleWith(gcgDISCRETE2D<long> *source);
8080  bool duplicateSignal(gcgDISCRETE2D<float> *source); // Makes an independent copy of the source signal.
8081  bool duplicateSignal(gcgDISCRETE2D<double> *source);
8082  bool duplicateSignal(gcgDISCRETE2D<short> *source);
8083  bool duplicateSignal(gcgDISCRETE2D<int> *source);
8084  bool duplicateSignal(gcgDISCRETE2D<long> *source);
8085  bool duplicateSubsignal(gcgDISCRETE2D<float> *source, int left, int top, unsigned int width, unsigned int height); // Makes an independent copy of the source subsignal.
8086  bool duplicateSubsignal(gcgDISCRETE2D<double> *source, int left, int top, unsigned int width, unsigned int height);
8087  bool duplicateSubsignal(gcgDISCRETE2D<short> *source, int left, int top, unsigned int width, unsigned int height);
8088  bool duplicateSubsignal(gcgDISCRETE2D<int> *source, int left, int top, unsigned int width, unsigned int height);
8089  bool duplicateSubsignal(gcgDISCRETE2D<long> *source, int left, int top, unsigned int width, unsigned int height);
8090 
8092  // Data access and modification. Not recommended for high
8093  // performance processes. Uses the origin and border extension.
8095  NUMTYPE getDataSample(int i, int j);
8096  bool setDataSample(int i, int j, NUMTYPE value);
8097 
8099  // Signal processing functions
8100  // The src can be the destination (this).
8102  bool normalize(gcgDISCRETE2D<float> *src, float floor = 0, float ceil = 1);
8103  bool normalize(gcgDISCRETE2D<double> *src, double floor = 0, double ceil = 1);
8104  bool normalize(gcgDISCRETE2D<short> *src, short floor = 0, short ceil = 1);
8105  bool normalize(gcgDISCRETE2D<int> *src, int floor = 0, int ceil = 1);
8106  bool normalize(gcgDISCRETE2D<long> *src, long floor = 0, long ceil = 1);
8107  bool convolutionX(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<float> *mask);
8108  bool convolutionX(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<double> *mask);
8109  bool convolutionX(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<short> *mask);
8110  bool convolutionX(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<int> *mask);
8111  bool convolutionX(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<long> *mask);
8112  bool convolutionY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<float> *mask);
8113  bool convolutionY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<double> *mask);
8114  bool convolutionY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<short> *mask);
8115  bool convolutionY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<int> *mask);
8116  bool convolutionY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE1D<long> *mask);
8117  bool convolutionXY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE2D<float> *mask);
8118  bool convolutionXY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE2D<double> *mask);
8119  bool convolutionXY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE2D<short> *mask);
8120  bool convolutionXY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE2D<int> *mask);
8121  bool convolutionXY(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE2D<long> *mask);
8122  bool templateMatching(unsigned int imgleft, unsigned int imgbottom, unsigned int imgwidth, unsigned int imgheight, gcgDISCRETE2D<float> *mask, int *positionX, int *positionY);
8123  bool templateMatching(unsigned int imgleft, unsigned int imgbottom, unsigned int imgwidth, unsigned int imgheight, gcgDISCRETE2D<double> *mask, int *positionX, int *positionY);
8124  bool templateMatching(unsigned int imgleft, unsigned int imgbottom, unsigned int imgwidth, unsigned int imgheight, gcgDISCRETE2D<short> *mask, int *positionX, int *positionY);
8125  bool templateMatching(unsigned int imgleft, unsigned int imgbottom, unsigned int imgwidth, unsigned int imgheight, gcgDISCRETE2D<int> *mask, int *positionX, int *positionY);
8126  bool templateMatching(unsigned int imgleft, unsigned int imgbottom, unsigned int imgwidth, unsigned int imgheight, gcgDISCRETE2D<long> *mask, int *positionX, int *positionY);
8127 
8128  // Computes the scalar product of two signals. At least one of the signals must have extension
8129  // GCG_BORDER_EXTENSION_ZERO for X, and at least one of the signals must have extension
8130  // GCG_BORDER_EXTENSION_ZERO for Y. Aligns the origin of srcsignal2 with the sample of this object
8131  // with relative coordinates (atX, atY).
8132  COERSIONFLOAT scalarProduct(int atX, int atY, gcgDISCRETE2D<float> *srcsignal2);
8133  COERSIONDOUBLE scalarProduct(int atX, int atY, gcgDISCRETE2D<double> *srcsignal2);
8134  COERSIONSHORT scalarProduct(int atX, int atY, gcgDISCRETE2D<short> *srcsignal2);
8135  COERSIONINT scalarProduct(int atX, int atY, gcgDISCRETE2D<int> *srcsignal2);
8136  COERSIONLONG scalarProduct(int atX, int atY, gcgDISCRETE2D<long> *srcsignal2);
8137 
8138  // Produces a binary signal. The samples are mapped to: lessvalue, if sample is below the threshold; greaterequalvalue,
8139  // if the sample is greater or equal the threshold. The src can be the destination (this).
8140  bool binarize(gcgDISCRETE2D<float> *src, float threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
8141  bool binarize(gcgDISCRETE2D<double> *src, double threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
8142  bool binarize(gcgDISCRETE2D<short> *src, short threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
8143  bool binarize(gcgDISCRETE2D<int> *src, int threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
8144  bool binarize(gcgDISCRETE2D<long> *src, long threshold, NUMTYPE lessvalue = 0, NUMTYPE greaterequalvalue = 1);
8145 
8147  // Signal composition. Source signals must be compatible.
8148  // The destination can be one of the sources.
8150  bool scale(gcgDISCRETE2D<float> *srcsignal1, COERSIONFLOAT weight, COERSIONFLOAT addthis = 0); // Scales a signal: I = w * I1 + at
8151  bool scale(gcgDISCRETE2D<double> *srcsignal1, COERSIONDOUBLE weight, COERSIONDOUBLE addthis = 0);
8152  bool scale(gcgDISCRETE2D<short> *srcsignal1, COERSIONSHORT weight, COERSIONSHORT addthis = 0);
8153  bool scale(gcgDISCRETE2D<int> *srcsignal1, COERSIONINT weight, COERSIONINT addthis = 0);
8154  bool scale(gcgDISCRETE2D<long> *srcsignal1, COERSIONLONG weight, COERSIONLONG addthis = 0);
8155  bool power(gcgDISCRETE2D<float> *srcsignal1, COERSIONFLOAT power); // Powers a signal: I = I1^power
8156  bool power(gcgDISCRETE2D<double> *srcsignal1, COERSIONDOUBLE power);
8157  bool power(gcgDISCRETE2D<short> *srcsignal1, COERSIONSHORT power);
8158  bool power(gcgDISCRETE2D<int> *srcsignal1, COERSIONINT power);
8159  bool power(gcgDISCRETE2D<long> *srcsignal1, COERSIONLONG power);
8160  bool combineAdd(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<float> *srcsignal2, COERSIONFLOAT weight1 = 1, COERSIONFLOAT weight2 = 1); // Combine two signals by addition: I = w1 * I1 + w2 * I2
8161  bool combineAdd(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<double> *srcsignal2, COERSIONDOUBLE weight1 = 1, COERSIONDOUBLE weight2 = 1);
8162  bool combineAdd(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<short> *srcsignal2, COERSIONSHORT weight1 = 1, COERSIONSHORT weight2 = 1);
8163  bool combineAdd(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<int> *srcsignal2, COERSIONINT weight1 = 1, COERSIONINT weight2 = 1);
8164  bool combineAdd(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<long> *srcsignal2, COERSIONLONG weight1 = 1, COERSIONLONG weight2 = 1);
8165  bool combineMult(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<float> *srcsignal2, COERSIONFLOAT add1 = 0, COERSIONFLOAT add2 = 0); // Combine two signals by multiplication: I = (a1 + I1) * (a2 + I2)
8166  bool combineMult(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<double> *srcsignal2, COERSIONDOUBLE add1 = 0, COERSIONDOUBLE add2 = 0);
8167  bool combineMult(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<short> *srcsignal2, COERSIONSHORT add1 = 0, COERSIONSHORT add2 = 0);
8168  bool combineMult(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<int> *srcsignal2, COERSIONINT add1 = 0, COERSIONINT add2 = 0);
8169  bool combineMult(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<long> *srcsignal2, COERSIONLONG add1 = 0, COERSIONLONG add2 = 0);
8170  bool combineNorm(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<float> *srcsignal2); // Combine two signals by the L2 norm: I = sqrt(I1^2 + I2^2)
8171  bool combineNorm(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<double> *srcsignal2);
8172  bool combineNorm(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<short> *srcsignal2);
8173  bool combineNorm(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<int> *srcsignal2);
8174  bool combineNorm(gcgDISCRETE2D<NUMTYPE> *srcsignal1, gcgDISCRETE2D<long> *srcsignal2);
8175 
8177  // Domain processing (2D support)
8179  bool verticalFlip(); // Mirrors the signal in the vertical direction.
8180 
8182  // Interfaces for gcgIMAGE
8184  bool exportGrayScaleImage(gcgIMAGE *outimage, bool normalize);
8185 };
8186 
8187 
8188 
8189 // Next section are included only for floating point types
8190 #if _COUNTER_GCG_ < 3
8191 
8192 
8202 
8203 template <>
8204 class GCG_API_CLASS gcgMATRIX<NUMTYPE> : public gcgCLASS {
8205  public:
8206  // Matrix info and data
8207  NUMTYPE *data;
8208  unsigned int rows;
8209  unsigned int columns;
8211 
8212  public:
8214  // Matrix construction
8216  gcgMATRIX();
8217  gcgMATRIX(unsigned int rows, unsigned int columns, NUMTYPE *sampledata = NULL, bool isstaticdata = false);
8218  virtual ~gcgMATRIX();
8219 
8221  // Empty matrix creation and destruction
8223  bool createMatrix(unsigned int rows, unsigned int columns, NUMTYPE *sampledata = NULL, bool isstaticdata = false);
8224  void destroyMatrix(); // Release all resources used by this matrix
8225 
8227  // Matrix copying, duplication and conversion.
8229  bool createSimilar(gcgMATRIX<float> *source); // Creates a matrix similar as the source. The data is not copied.
8230  bool createSimilar(gcgMATRIX<double> *source);
8231  bool isCompatibleWith(gcgMATRIX<float> *source); // Checks if both matrices are compatible: same dimensions
8232  bool isCompatibleWith(gcgMATRIX<double> *source);
8233  bool duplicateMatrix(gcgMATRIX<float> *source); // Makes an independent copy of the source matrix.
8234  bool duplicateMatrix(gcgMATRIX<double> *source);
8235  bool duplicateSubMatrix(gcgMATRIX<float> *source, int firstrow, int firstcolumn, unsigned int rows, unsigned int columns); // Makes an independent copy of the source submatrix.
8236  bool duplicateSubMatrix(gcgMATRIX<double> *source, int firstrow, int firstcolumn, unsigned int rows, unsigned int columns);
8237 
8239  // Matrix access and modification. Not recommended for high performance operations.
8241  NUMTYPE getDataSample(int row, int column);
8242  bool setDataSample(int row, int column, NUMTYPE value);
8243 
8245  // Matrix composition. Source matrices must be compatible.
8246  // The destination can be one of the sources.
8248  bool scale(gcgMATRIX<float> *srcmatrix1, COERSIONFLOAT weight, COERSIONFLOAT addthis = 0); // Scales a matrix: M = w * M1 + at
8249  bool scale(gcgMATRIX<double> *srcmatrix1, COERSIONDOUBLE weight, COERSIONDOUBLE addthis = 0);
8250  bool power(gcgMATRIX<float> *srcmatrix1, COERSIONFLOAT power); // Powers the elements of the matrix: M = M1^power
8251  bool power(gcgMATRIX<double> *srcmatrix1, COERSIONDOUBLE power);
8252  bool combineAdd(gcgMATRIX<NUMTYPE> *srcmatrix1, gcgMATRIX<float> *srcmatrix2, COERSIONFLOAT weight1 = 1, COERSIONFLOAT weight2 = 1); // Combine two signals by addition: M = w1 * M1 + w2 * M2
8253  bool combineAdd(gcgMATRIX<NUMTYPE> *srcmatrix1, gcgMATRIX<double> *srcmatrix2, COERSIONDOUBLE weight1 = 1, COERSIONDOUBLE weight2 = 1);
8254  bool combineMult(gcgMATRIX<NUMTYPE> *srcmatrix1, gcgMATRIX<float> *srcmatrix2, COERSIONFLOAT add1 = 0, COERSIONFLOAT add2 = 0); // Combine two signals by multiplication: M = (a1 + M1) * (a2 + M2)
8255  bool combineMult(gcgMATRIX<NUMTYPE> *srcmatrix1, gcgMATRIX<double> *srcmatrix2, COERSIONDOUBLE add1 = 0, COERSIONDOUBLE add2 = 0);
8256  bool combineNorm(gcgMATRIX<NUMTYPE> *srcmatrix1, gcgMATRIX<float> *srcmatrix2); // Combine two signals by the L2 norm: M = sqrt(M1^2 + M2^2)
8257  bool combineNorm(gcgMATRIX<NUMTYPE> *srcmatrix1, gcgMATRIX<double> *srcmatrix2);
8258 };
8259 
8260 
8261 
8267 
8279 
8280 template <>
8281 class GCG_API_CLASS gcgLEGENDREBASIS1D<NUMTYPE> : public gcgBASIS1D<NUMTYPE> {
8282  public:
8283  unsigned int degree;
8284  unsigned int nsamples;
8285 
8286  private:
8287  double *coefficients; // Coefficients of polynomials. Double precision reduces numerical problems.
8288  unsigned int npolynomials; // number of polynomials = maximum degree of the polynomial basis + 1
8289 
8290  NUMTYPE *discretepolynomials; // Discrete version of polynomials
8291 
8292  public:
8293  gcgLEGENDREBASIS1D();
8294  virtual ~gcgLEGENDREBASIS1D();
8295 
8299  bool setBasisDegree(unsigned int degree);
8300 
8310  bool setNumberOfSamples(unsigned int nsamples);
8311 
8314  unsigned int getNumberOfCoefficients();
8315 
8322  NUMTYPE getPointValue(unsigned int idegree, NUMTYPE x);
8323 
8329  NUMTYPE getIntegralValue(unsigned int idegree, NUMTYPE a, NUMTYPE b);
8330 
8339  NUMTYPE getDiscreteValue(unsigned int idegree, unsigned int i);
8340 
8353  bool projectSignal(int atX, gcgDISCRETE1D<float> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8354  bool projectSignal(int atX, gcgDISCRETE1D<double> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8355  bool projectSignal(int atX, gcgDISCRETE1D<short> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8356  bool projectSignal(int atX, gcgDISCRETE1D<int> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8357  bool projectSignal(int atX, gcgDISCRETE1D<long> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8358 
8370  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<float> *outputvector);
8371  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<double> *outputvector);
8372  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<short> *outputvector);
8373  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<int> *outputvector);
8374  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<long> *outputvector);
8375 
8382  bool basisInformation(const char *filename);
8383 };
8384 
8385 
8391 
8392 
8404 
8405 template <>
8406 class GCG_API_CLASS gcgLEGENDREBASIS2D<NUMTYPE> : public gcgBASIS2D<NUMTYPE> {
8407  public:
8408  unsigned int degree;
8409  unsigned int nsamplesX;
8410  unsigned int nsamplesY;
8411 
8412  private:
8413  double *coefficients; // Coefficients of 2D polynomials. Double precision reduces numerical problems.
8414  unsigned int npolynomials; // number of polynomials for x and y = ((degree-2)*(degree-1))/2
8415 
8416  NUMTYPE *discretepolynomials; // Discrete version of polynomials
8417 
8418  public:
8419  gcgLEGENDREBASIS2D();
8420  virtual ~gcgLEGENDREBASIS2D();
8421 
8425  bool setBasisDegree(unsigned int degree);
8426 
8439  bool setNumberOfSamples(unsigned int nsamplesX, unsigned int nsamplesY);
8440 
8443  unsigned int getNumberOfCoefficients();
8444 
8455  bool synchBasisWithFile(const char *filename, unsigned int nsamplesX, unsigned int nsamplesY);
8456 
8466  NUMTYPE getPointValue(unsigned int i, unsigned int j, NUMTYPE x, NUMTYPE y);
8467 
8476  NUMTYPE getIntegralValue(unsigned int i, unsigned int j, NUMTYPE xmin, NUMTYPE xmax, NUMTYPE ymin, NUMTYPE ymax);
8477 
8493  NUMTYPE getDiscreteValue(unsigned int i, unsigned int j, unsigned int ix, unsigned int iy);
8494 
8508  bool projectSignal(int atX, int atY, gcgDISCRETE2D<float> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8509  bool projectSignal(int atX, int atY, gcgDISCRETE2D<double> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8510  bool projectSignal(int atX, int atY, gcgDISCRETE2D<short> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8511  bool projectSignal(int atX, int atY, gcgDISCRETE2D<int> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8512  bool projectSignal(int atX, int atY, gcgDISCRETE2D<long> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8513 
8514 
8528  bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<float> *outputvector);
8529  bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<double> *outputvector);
8530  bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<short> *outputvector);
8531  bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<int> *outputvector);
8532  bool reconstructSignal(int atX, int atY, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE2D<long> *outputvector);
8533 
8541  bool basisInformation(const char *filename, bool checkorthogonality, bool savefunctionsasimages);
8542 };
8543 
8544 
8550 
8561 
8562 template <>
8563 class GCG_API_CLASS gcgDWTBASIS1D<NUMTYPE> : public gcgBASIS1D<NUMTYPE> {
8564  public:
8569 
8570  unsigned int nsamples;
8571  unsigned int ncoefficients;
8572 
8573  private:
8574  void *buffer;
8575 
8576  public:
8577  gcgDWTBASIS1D();
8578  virtual ~gcgDWTBASIS1D();
8579 
8590 
8598  bool setNumberOfSamples(unsigned int nsamples);
8599 
8608  unsigned int getNumberOfCoefficients();
8609 
8622  bool projectSignal(int atX, gcgDISCRETE1D<float> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8623  bool projectSignal(int atX, gcgDISCRETE1D<double> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8624  bool projectSignal(int atX, gcgDISCRETE1D<short> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8625  bool projectSignal(int atX, gcgDISCRETE1D<int> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8626  bool projectSignal(int atX, gcgDISCRETE1D<long> *vector, gcgDISCRETE1D<NUMTYPE> *outputcoef);
8627 
8639  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<float> *outputvector);
8640  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<double> *outputvector);
8641  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<short> *outputvector);
8642  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<int> *outputvector);
8643  bool reconstructSignal(int atX, gcgDISCRETE1D<NUMTYPE> *inputcoef, gcgDISCRETE1D<long> *outputvector);
8644 
8651  bool basisInformation(const char *filename);
8652 };
8653 
8654 
8655 #endif
8656 
8657 
8663 
8666 // Class for computing the partial derivative of a 2D signal Icurrent (given
8667 // the sequence of signals {Iprevious, Icurrent, Inext} consecutively defined
8668 // in a axis t, perpendicular to the signals) in respect to axis t. The axis
8669 // t is frequently defined as time, over which the 2D signal vary.
8670 //
8671 // In each call of sequenceDerivative(), the parameters are compared with
8672 // those from previous invocation, and already computed information is reused.
8673 //
8675 
8676 template <>
8677 class GCG_API_CLASS gcgSEQUENCEDERIVATIVE2D<NUMTYPE> : public gcgCLASS {
8678  private:
8679  gcgDISCRETE2D<NUMTYPE> *current;
8680  gcgDISCRETE2D<NUMTYPE> *next;
8681  gcgDISCRETE2D<NUMTYPE> *lowcurrent;
8682  gcgDISCRETE2D<NUMTYPE> *lownext;
8683  gcgDISCRETE2D<NUMTYPE> temp;
8684 
8685  public:
8686  // Constructors and destructors
8689 
8690  // Computes a new partial derivative.
8691  virtual bool sequenceDerivative(gcgDISCRETE2D<NUMTYPE> *current, gcgDISCRETE2D<NUMTYPE> *next, gcgDISCRETE2D<NUMTYPE> *outputDt);
8692 };
8693 
8694 
8700 
8702 // Class for generating filter masks.
8704 //
8705 // Use gcgFILTERMASK<float> or gcgFILTERMASK<> for single precision.
8706 // Use gcgFILTERMASK<double> for double precision. Methods for projection
8707 // and reconstruction are avalaible. The performance of the numeric methods can be
8708 // analysed by using the basisInformation() method.
8709 //
8711 
8712 template<>
8713 class GCG_API_CLASS gcgFILTERMASK1D<NUMTYPE> : public gcgDISCRETE1D<NUMTYPE> {
8714  public:
8715  gcgFILTERMASK1D();
8716  virtual ~gcgFILTERMASK1D();
8717 
8718  // Box filter construction
8719  bool createBoxFilter(unsigned int nsamples);
8720 
8721  // Triangle filter construction
8722  bool createTriangleFilter(unsigned int nsamples);
8723 };
8724 
8725 
8731 
8733 // Signal comparison: error computation.
8735 
8736 template<> GCG_API_TEMPLATE double computeMSEwith<NUMTYPE>(gcgDISCRETE1D<NUMTYPE> *src1, gcgDISCRETE1D<NUMTYPE> *src2); // Computes the Mean Squared Error.
8737 template<> GCG_API_TEMPLATE double computePSNRwith<NUMTYPE>(gcgDISCRETE1D<NUMTYPE> *src1, gcgDISCRETE1D<NUMTYPE> *src2);// Computes the Peak Signal-to-Noise Ratio in dB.
8738 template<> GCG_API_TEMPLATE double computeMAEwith<NUMTYPE>(gcgDISCRETE1D<NUMTYPE> *src1, gcgDISCRETE1D<NUMTYPE> *src2); // Computes the Mean Absolute Error.
8739 
8740 template<> GCG_API_TEMPLATE double computeMSEwith<NUMTYPE>(gcgDISCRETE2D<NUMTYPE> *src1, gcgDISCRETE2D<NUMTYPE> *src2); // Computes the Mean Squared Error.
8741 template<> GCG_API_TEMPLATE double computePSNRwith<NUMTYPE>(gcgDISCRETE2D<NUMTYPE> *src1, gcgDISCRETE2D<NUMTYPE> *src2);// Computes the Peak Signal-to-Noise Ratio in dB.
8742 template<> GCG_API_TEMPLATE double computeMAEwith<NUMTYPE>(gcgDISCRETE2D<NUMTYPE> *src1, gcgDISCRETE2D<NUMTYPE> *src2); // Computes the Mean Absolute Error.
8743 
8744 
8746 // Signal analysis.
8748 
8749 // Computes the gradient of 1D signal src. The derivative is computed using well-known Sobel operator and
8750 // the result is stored in dx.
8751 template<> GCG_API_TEMPLATE bool gcgFirstDerivativeSobel1D<NUMTYPE>(gcgDISCRETE1D<NUMTYPE> *src, gcgDISCRETE1D<NUMTYPE> *dx);
8752 
8753 // Computes the gradient of 2D signal src. The partial derivatives are computed using well-known Sobel
8754 // operator and the components are stored in dx and dy. The pointer for dx or dy may be NULL.
8755 template<> GCG_API_TEMPLATE bool gcgGradientSobel2D<NUMTYPE>(gcgDISCRETE2D<NUMTYPE> *src, gcgDISCRETE2D<NUMTYPE> *dx, gcgDISCRETE2D<NUMTYPE> *dy);
8756 
8757 // Computes the (optical) flow given the partial derivatives in X, Y and time of up to three channels.
8758 // Uses the Augereau method (Bertrand Augereau, Benoît Tremblais, Christine Fernandez-Maloigne,
8759 // "Vectorial computation of the optical flow in colorimage sequences", CIC05).
8760 template<> GCG_API_TEMPLATE bool gcgOpticalFlowAugereau2D<NUMTYPE>(gcgDISCRETE2D<NUMTYPE> *dx1, gcgDISCRETE2D<NUMTYPE> *dy1, gcgDISCRETE2D<NUMTYPE> *dt1,
8761  gcgDISCRETE2D<NUMTYPE> *dx2, gcgDISCRETE2D<NUMTYPE> *dy2, gcgDISCRETE2D<NUMTYPE> *dt2,
8762  gcgDISCRETE2D<NUMTYPE> *dx3, gcgDISCRETE2D<NUMTYPE> *dy3, gcgDISCRETE2D<NUMTYPE> *dt3,
8763  gcgDISCRETE2D<float> *outflowX, gcgDISCRETE2D<float> *outflowY);
8764 
8765 template<> GCG_API_TEMPLATE bool gcgOpticalFlowAugereau2D<NUMTYPE>(gcgDISCRETE2D<NUMTYPE> *dx1, gcgDISCRETE2D<NUMTYPE> *dy1, gcgDISCRETE2D<NUMTYPE> *dt1,
8766  gcgDISCRETE2D<NUMTYPE> *dx2, gcgDISCRETE2D<NUMTYPE> *dy2, gcgDISCRETE2D<NUMTYPE> *dt2,
8767  gcgDISCRETE2D<NUMTYPE> *dx3, gcgDISCRETE2D<NUMTYPE> *dy3, gcgDISCRETE2D<NUMTYPE> *dt3,
8768  gcgDISCRETE2D<double> *outflowX, gcgDISCRETE2D<double> *outflowY);
8769 
8770 
8776 
8777 template<> GCG_API_TEMPLATE bool gcgLinearSolver(gcgDISCRETE2D<NUMTYPE> *A, gcgDISCRETE1D<NUMTYPE> *b, gcgDISCRETE1D<NUMTYPE> *x);
8778 
8779 /*
8781 // Tsai method
8783 
8785 #define NONE 0
8786 #define THREE_PARAM 1
8787 #define FULL 2
8788 
8789 class gcgCalibrator {
8790  public:
8791  double r1, r2, r3, r4, r5, r6, r7, r8, r9; //elementos da matriz de rotação
8792  double Tx, Ty, Tz; //elementos do vetor de translação
8793  double f; //distância focal
8794  double k1; //coeficiente de distorção
8795 };
8796 
8797 class gcgCameraCalibration: public gcgCalibrator{
8798  public:
8799 
8800  int n; //número de pontos para a calibração
8801  double Cx, Cy; //coordenadas da projeção do centro óptico
8802  double Rx, Ry, Rz; //ângulos da rotação
8803 
8804  VECTOR2d *worldPoints; //vetor de pontos do mundo
8805  VECTOR2d *imagePoints; //vetor de pontos da imagem
8806  VECTOR2d *distortedPoints; //vetor de pontos com distorção
8807 
8808  gcgCameraCalibration(int n, VECTOR2d *worldPoints, VECTOR2d *imagePoints, double Cx, double Cy);
8809 
8810  void rotationAngles();
8811 
8812  void rotationMatrix();
8813 
8814  int TsaiMethodCoplanar(int otimizationType);
8815 
8816  void otimization();
8817 
8818  void otimizationFull();
8819 };
8820 
8821 class gcgProjectorCalibration: public gcgCameraCalibration{
8822  public:
8823 
8824  double Rc[9], Tc[3], fc; //parâmetros da câmera calibrada
8825 
8826  gcgProjectorCalibration(int n, VECTOR2d *worldPoints, VECTOR2d *imagePoints, double Cx, double Cy,
8827  double rc1, double rc2, double rc3, double rc4, double rc5, double rc6, double rc7, double rc8, double rc9,
8828  double Tcx, double Tcy, double Tcz, double fc);
8829 
8830  gcgProjectorCalibration(int n, VECTOR2d *worldPoints, VECTOR2d *imagePoints, double Cx, double Cy, double Rc[9], double Tc[3], double fc);
8831 
8832  gcgProjectorCalibration(int n, VECTOR2d *worldPoints, VECTOR2d *imagePoints, double Cx, double Cy, gcgCameraCalibration *camera);
8833 
8834  int projectorCalibration(int otimizationType);
8835 };
8836 
8837 class gcgCameraProjectorCalibration: public gcgCameraCalibration{
8838  public:
8839 
8840  gcgProjectorCalibration *projector;
8841 
8842  gcgCameraProjectorCalibration(int nc, VECTOR2d *worldPointsCamera, VECTOR2d *imagePointsCamera, double CxCamera, double CyCamera,
8843  int np, VECTOR2d *worldPointsProjetor, VECTOR2d *imagePointsProjetor, double CxProjetor, double CyProjetor);
8844 
8845  int cameraProjectorCalibration(int otimizationType);
8846 };
8847 
8848 
8850 // Levenberg-Marquadt method
8852 class gcgLevMarq{
8853  public:
8854 
8855  int numPt; //número de pontos da função
8856  int numPar; //número de parâmetros a serem otimizados
8857  gcgDISCRETE1D<double> *p; //vetor que armazena os parâmetros
8858  gcgDISCRETE1D<double> *x; //vetor de tamanho >= numPt para armazenar a saída da função
8859 
8860  double epsilon1;
8861  double epsilon2;
8862  double epsilon3;
8863  double tau;
8864  int kmax;
8865  double jacobianInterval;
8866 
8867  gcgLevMarq();
8868 
8869  virtual void f(int numPt, int numPar, gcgDISCRETE1D<double> *p, gcgDISCRETE1D<double> *residuos) = 0;
8870 
8871  void multTransposeXMatrix(gcgDISCRETE2D<double> *matriz, gcgDISCRETE2D<double> *resultado);
8872 
8873  void multTransposeXMatrix(gcgDISCRETE2D<double> *matriz, gcgDISCRETE1D<double> *vetor, gcgDISCRETE1D<double> *resultado);
8874 
8875  double infinityNorm(gcgDISCRETE1D<double> *vetor);
8876 
8877  double euclidianNorm(gcgDISCRETE1D<double> *vetor);
8878 
8879  double multVectorTXVector(gcgDISCRETE1D<double> *vetor1, gcgDISCRETE1D<double> *vetor2);
8880 
8881  void jacobianCalculate(gcgDISCRETE1D<double> *p, double intervalo, gcgDISCRETE2D<double> *jacobiana);
8882 
8883  void otimization();
8884 };
8885 
8886 */
8887 
8888 
8889 // Update counter
8890 #if _COUNTER_GCG_ == 1
8891  #undef _COUNTER_GCG_
8892  #define _COUNTER_GCG_ 2
8893 #elif _COUNTER_GCG_ == 2
8894  #undef _COUNTER_GCG_
8895  #define _COUNTER_GCG_ 3
8896 #elif _COUNTER_GCG_ == 3
8897  #undef _COUNTER_GCG_
8898  #define _COUNTER_GCG_ 4
8899 #elif _COUNTER_GCG_ == 4
8900  #undef _COUNTER_GCG_
8901  #define _COUNTER_GCG_ 5
8902 #else
8903  #define _GCG_H_ // Stop loading
8904 #endif
8905 
8907 // Loads several times to automatically include classes with distinct types
8908 #if !defined(_GCG_H_)
8909  #include "gcg.h"
8910 #endif
8911 
8912 #ifdef __cplusplus
8913 } // extern "C++"
8914 #endif
8915 
8916 #endif // #ifndef _GCG_H_
Base abstract class for defining a hierarchical data structure in GCGlib for ordered nodes...
Definition: gcg.h:5354
bool gcgInverseMatrix4(MATRIX4 inverse, MATRIX4 matrix)
Computes the inverse of a 4x4 matrix by the direct method. It is suitable for fast inverse computatio...
union _GCGDIGITALKEY GCGDIGITALKEY
Union type for defining digital keys for data map classes. The data maps might use fixed or variable ...
unsigned int bpp
Bits per pixel that can assume the values: 1, 2, 4, 8, 16, 24, 32.
Definition: gcg.h:2927
FILE * gcgGetLogStream()
Returns the current log stream. The default log stream is stderr.
gcgLINK * first
Points to the first gcgLINK node in the list. Read-only.
Definition: gcg.h:4855
const int GCG_VERSION_BUILD
Points to the integer build version value.
Definition: gcg.h:399
int gcgGetReport(int sizestring=0, char *extrastring=NULL)
Returns the code of the last report. Use GCG_REPORT_TYPE(), GCG_REPORT_DOMAIN(), and GCG_REPORT_MESSA...
bool gcgDrawVectorPyramid(float x, float y, float z, VECTOR3 vector, float scale)
Draws an oriented pyramid (its base is not drawn) which can be used to represent vectors: 4 triangles...
bool gcgEigenSymmetricMatrix3(MATRIX3 matrix, MATRIX3 eigenvectors, VECTOR3 eigenvalues)
Computes the eigensystem decomposition of a symmetric 3 x 3 matrix matrix. The resulted eigenvectors ...
char ckey
The key as a char: guaranteed to have at least CHAR_BIT bits in C. It has 8 bits in x86-64 machines...
Definition: gcg.h:5885
Controls a pool of threads for executing multiple jobs concurrently.
Definition: gcg.h:6872
Class for capturing video from camera devices.
Definition: gcg.h:4353
Defines a queue with synchronized access. This is a standard data structure that may be used with Fir...
Definition: gcg.h:6507
Class to estimate the number of events per second.
Definition: gcg.h:4083
signed char status
Sequence of bits used to keep ordered node information. It depends on the underlying data structure...
Definition: gcg.h:5337
unsigned int nsamples
Number of samples for projection/reconstruction processes. Read-only. See setNumberOfSamples().
Definition: gcg.h:8570
gcgDISCRETE1D< NUMTYPE > H
Low pass decomposition filter. Read-only.
Definition: gcg.h:8565
int internalformat
OpenGL internal format: GL_LUMINANCE4, GL_LUMINANCE8, GL_RGB5, GL_RGB5_A1, GL_RGBA8, GL_RGB8 or GL_RGB4, depending on the texture creation parameters.
Definition: gcg.h:7183
void * handle
Internal handle of this object.
Definition: gcg.h:6509
void * handle
Internal handle of this service.
Definition: gcg.h:7513
Concrete class that implements a PATRICIA tree for key/value mappings. Insertion or search for a rand...
Definition: gcg.h:6050
uintptr_t getAllocatedMemoryCounter()
Function to retrieve how much memory was dynamically allocated by using GCGlib.
unsigned int gcgPackRLE8(unsigned int fullsize, unsigned char *srcdata, unsigned char *RLEdata)
Packs a 8 bit sequence as a Run-Lenght Encoded block.
#define GCG_BORDER_EXTENSION_CLAMP
Defines the border extension as: the first/last value s[0] s[0] s[0] s[0] s[1] s[2] s[2] s[2] s[2]...
Definition: gcg.h:2687
signed char balance
Name addressed by AVL trees. Internal use only.
Definition: gcg.h:5338
Class for 1D signal definition and processing.
Definition: gcg.h:7803
Generic abstract class for defining a linkable node for use in single linked lists and linear data st...
Definition: gcg.h:4697
bool gcgSaveFloatsAsText(unsigned int size, float *data, char *outputname)
Saves a float array as C code for software embedding.
void * handle
Internal handle of this peer.
Definition: gcg.h:7358
Class to transparently deal with 3D textures. Allocates the texture directly from graphics system and...
Definition: gcg.h:7173
Generic abstract class for defining classes to be used in the GCGlib data structures. In fact, a specialization of a correct and data structure dependent class is mandatory for using the data structures.
Definition: gcg.h:4589
float minimumload
Minimum load of this table. The table capacity will be adjusted to this minimum counter/capacity rati...
Definition: gcg.h:5627
Generic abstract class for defining a job/task for using with GCGlib. It inherits gcgORDEREDNODE in o...
Definition: gcg.h:6832
Base class for video processing.
Definition: gcg.h:4319
const char * GCG_BUILD_DATE
Points to the build date string.
Definition: gcg.h:390
bool gcgEnableReportLog(int code, bool enable)
Enables or disables the logging of messages of a specific type or domain. When a type or domain is en...
unsigned int height
Height effectively used by the texture. It must be <= actualheight.
Definition: gcg.h:7176
int type
OpenGL format: GL_UNSIGNED_BYTE, GL_BITMAP, GL_UNSIGNED_BYTE_4, GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_UNSIGNED_SHORT_5_6_5, or GL_UNSIGNED_SHORT_4_4_4_4_REV, depending on the texture creation parameters.
Definition: gcg.h:7185
const int GCG_VERSION_MAJOR
Points to the integer major version value.
Definition: gcg.h:393
bool gcgDrawLogo(float scale=0.67)
Draws the GCG logo on the top right conner of the viewport.
const char * gcgGetReportString(char **typestr=NULL, char **domainstr=NULL)
Gets the strings of the last report.
gcgDISCRETE1D< NUMTYPE > rH
Low pass reconstruction filter. Read-only.
Definition: gcg.h:8567
unsigned int gcgDecompressImageRLE8(unsigned int width, unsigned int height, unsigned char *RLEdata, unsigned char *dstdata)
Decompress a bit Run-Length Encoded 8 bits bitmap image. It receives a compressed block of a Windows ...
Class for handling matrices with arbitrary dimension. It is used in general functions for linear alge...
Definition: gcg.h:8204
Generic abstract class for defining a linkable node for use in double linked lists and linear data st...
Definition: gcg.h:4716
unsigned int idOpengl
OpenGL texture internal identification.
Definition: gcg.h:7181
Class with methods to listen a specific port and, as additionnal functionality, manage multiple peers...
Definition: gcg.h:7510
unsigned long capacity
Maximum sum of data costs this cache supports. Read-Only. See setMaximumCost().
Definition: gcg.h:6699
Base abstract class for defining data structures in GCGlib. It indicates the minimum methods that all...
Definition: gcg.h:4637
void * handle
Internal handle of this object.
Definition: gcg.h:7067
void * handle
Internal handle of this object.
Definition: gcg.h:6703
void * pkey
Points to the actual key (null terminated strings or fixed integer keys with size greater than sizeof...
Definition: gcg.h:5880
virtual ~gcgJOB()
Destructs the job. It is intended to be implemented by specialized classes. The object is deleted by ...
Definition: gcg.h:6842
unsigned int gcgDecompressImageRLE4(unsigned int width, unsigned int height, unsigned char *RLEdata, unsigned char *dstdata)
Decompress a bit Run-Length Encoded 4 bits bitmap image. It receives a compressed block of a Windows ...
bool gcgReport(int code, const char *format=NULL,...)
Reports an error. To avoid serialization, it is NEVER called for successful operations inside GCGlib...
bool gcgDrawAABox(VECTOR3 bbmin, VECTOR3 bbmax)
Draws an axis aligned box. Normals are sent and can be used for lighting. All parameters are float va...
unsigned int width
Image size in number of pixels.
Definition: gcg.h:2925
bool gcgDrawVectorPyramidClosed(float x, float y, float z, VECTOR3 vector, float scale)
Draws an oriented pyramid (its base is also drawn) which can be used to represent vectors: 6 triangle...
static int SQR(int x)
Inline function for squaring integers.
Definition: gcg.h:424
uintptr_t counter
Number of elements in this tree. Read-only.
Definition: gcg.h:5459
uintptr_t capacity
Capacity of this table or maximum number of elements of the table without collisions. Read-only.
Definition: gcg.h:5626
bool gcgHeatColor(float normheat, VECTOR3 color)
Returns a color given a normalized "heat" value between 0 and 1. Uses a palette that partitions the u...
int format
OpenGL format: GL_LUMINANCE, GL_BGRA, GL_RGB or GL_RGBA, depending on the texture creation parameters...
Definition: gcg.h:7184
FILE * gcgSetLogStream(FILE *logstream)
Sets a new stream for logging. The default log stream is stderr. Returns the previous log stream...
gcgLINK * left
Points to the left/previous gcgLINK node in a list. Same pointer as previous. Read-only.
Definition: gcg.h:4720
bool gcgInverseMatrix3(MATRIX3 inverse, MATRIX3 matrix)
Computes the inverse of a 3x3 matrix by the direct method. It is suitable for fast inverse computatio...
int extension
Defines the way the borders have to be extended.
Definition: gcg.h:7810
unsigned int rowsize
Stride in bytes between one row and the next. The last image row appears first in the data buffer...
Definition: gcg.h:2928
unsigned char * palette
Definition: gcg.h:2931
float maximumload
Maximum load of this table. The table capacity will be adjusted to this maximum counter/capacity rati...
Definition: gcg.h:5628
unsigned int degree
Degree of the polynomials = number of polynomials - 1. Read-only. See setBasisDegree().
Definition: gcg.h:8283
bool isListening
True if the service is listening a port.
Definition: gcg.h:7512
void * handle
Internal handle of this object.
Definition: gcg.h:6874
It is a concrete class that defines a fast double linked list. This is a standard data structure that...
Definition: gcg.h:5084
Abstract class for 2D basis projection/reconstruction interfaces.
Definition: gcg.h:2838
void gcgOutputLog(const char *format,...)
Reports a new message to the log stream.
short skey
The key as a short integer: guaranteed to have at least 16 bits in C. It has 16 bits in x86-64 machin...
Definition: gcg.h:5884
unsigned int height
Image height in number of pixels.
Definition: gcg.h:2926
uintptr_t counter
Number of elements in this list. Read-only.
Definition: gcg.h:5088
gcgLINK * last
Points to the last gcgLINK node in the list. Read-only.
Definition: gcg.h:5087
void * handle
Internal handle of this object.
Definition: gcg.h:6423
float gcgSphericalDistance(float latitude1, float longitude1, float latitude2, float longitude2)
Computes the distance between two points on the unit sphere using the method of R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159): http://www.movable-type.co.uk/scripts/gis-faq-5.1.htmlComputes.
uintptr_t counter
Number of elements in this tree. Read-only.
Definition: gcg.h:6052
gcgORDEREDNODE * root
Root node of the AVL tree. Read-only.
Definition: gcg.h:5458
bool gcgLinearSolver(gcgDISCRETE2D< NUMTYPE > *A, gcgDISCRETE1D< NUMTYPE > *b, gcgDISCRETE1D< NUMTYPE > *x)
Computes the solution of a linear system. If A is a square matrix (number of equations = number of un...
bool gcgDrawOBox(VECTOR3 obbangles, VECTOR3 obbcenter, VECTOR3 obbsize)
Draws an oriented box. Normals are sent and can be used for lighting. All parameters are float values...
bool isstaticdata
True if the data pointer data must not be deleted by this object.
Definition: gcg.h:8210
int ikey
The key as an integer: guaranteed to have at least 16 bits in C. It has 32 bits in x86-64 machines...
Definition: gcg.h:5883
const int GCG_VERSION_MINOR
Points to the integer minor version value.
Definition: gcg.h:396
unsigned int degree
Degree of the polynomials. Read-only. See setBasisDegree().
Definition: gcg.h:8408
float gcgBlinkingAlpha()
Computes a value between 0 and 1 in function of time that can be used as opacity value to simulate bl...
Generic abstract class to manage a hash table. A hash table is a data structure that organizes the no...
Definition: gcg.h:5623
unsigned int ncoefficients
Number of detail coefficients. Read-only. See setNumberOfSamples().
Definition: gcg.h:8571
int local_port
Local Port.
Definition: gcg.h:7352
unsigned int width
Width effectively used by the texture. It must be <= actualwidth.
Definition: gcg.h:7175
unsigned int nsamplesY
Current samples in Y direction. Read-only. See setNumberOfSamples().
Definition: gcg.h:8410
void * handle
Internal handle of this object.
Definition: gcg.h:4085
bool gcgSaveBytesAsText(unsigned int size, unsigned char *data, char *outputname)
Saves a byte array as C code for software embedding.
unsigned int palettecolors
Actual number of colors in the palette. It might be less than the maximum number of colors of a given...
Definition: gcg.h:2930
unsigned int actualheight
Real Height of the texture inside the graphics system: must be a power of 2.
Definition: gcg.h:7179
unsigned int keysize
Key size in bytes. If zero, the keys are null terminated string. Read-only.
Definition: gcg.h:6053
unsigned int gcgPackRLE32(unsigned int fullsize, unsigned char *srcdata, unsigned char *RLEdata)
Packs a 32 bit sequence as a Run-Lenght Encoded block. The parameter srcdata MUST be 4 aligned <=> fu...
gcgLINK * previous
Points to the left/previous gcgLINK node in a list. Same pointer as left. Read-only.
Definition: gcg.h:4719
gcgLINK * right
Points to the right/next gcgLINK node in a list. Same pointer as next. Read-only. ...
Definition: gcg.h:4701
unsigned int keysize
Size of each key in bytes. If zero, the key is a null terminated string. Maximum value is 255...
Definition: gcg.h:6700
Defines a lock for easy critical section control. Provides timed lock, which tries to lock an interna...
Definition: gcg.h:6421
unsigned int length
Signal length = number of samples.
Definition: gcg.h:7806
uintptr_t counter
Number of elements in this table. Read-only.
Definition: gcg.h:5625
Base abstract class for defining a hierarchical data structure in GCGlib for key/value mappings...
Definition: gcg.h:5931
bool isstaticdata
True if the data pointer data must not be deleted by this object.
Definition: gcg.h:7807
void gcgTriangleGradient(VECTOR3 grad_u, VECTOR3 v0, VECTOR3 v1, VECTOR3 v2, float u0, float u1, float u2)
Computes the gradient of a scalar u over a 3D triangle with edges (v0,v1), (v1, v2), (v2, v0).
#define NULL
Defines the null pointer.
Definition: gcg.h:554
unsigned int gcgUnpackRLE8(unsigned char *RLEdata, unsigned char *dstdata)
Decompress a 8 bit Run-Length Encoded data coded with gcgPackRLE8().
float gcgTriangleArea(VECTOR3 v0, VECTOR3 v1, VECTOR3 v2)
Computes the area of a triangle with edges (v0,v1), (v1, v2), (v2, v0). See Graphics Gems II - Pag...
bool gcgDrawVectorThetrahedron(float x, float y, float z, VECTOR3 vector, float scale)
Draws an oriented thetahedron (its base is not drawn) which can be used to represent vectors: 3 trian...
#define FEQUAL(a, b)
A macro for real numbers equality comparisons.
Definition: gcg.h:538
void * handle
Internal handle of this object.
Definition: gcg.h:6324
unsigned int actualwidth
Real width of the texture inside the graphics system: must be a power of 2.
Definition: gcg.h:7178
intptr_t intkey
Maximum integer key: guaranteed to be the same number of bits of a pointer.
Definition: gcg.h:5881
unsigned int nsamples
Current number of samples of each discretized polynomial. Read-only. See setNumberOfSamples().
Definition: gcg.h:8284
unsigned int columns
Number of columns.
Definition: gcg.h:8209
bool isConnected
True if this peer is connected.
Definition: gcg.h:7353
gcgCLASS ** table
Table of data structures. Internal use only.
Definition: gcg.h:5629
int origin
Origin coordinate: indicates the sample position of the origin (x = 0) of the signal.
Definition: gcg.h:7809
Controls and synchronizes multiple producers and consumers accessing a shared and limited buffer...
Definition: gcg.h:7065
Class for decode frames from a video file.
Definition: gcg.h:4491
bool gcgSaveBMPcode(char *inputname, char *outputname)
Saves a windows bitmap image as C code for software embedding.
It is a concrete class that defines a fast single linked list. This is a standard data structure that...
Definition: gcg.h:4853
Abstract class for 1D basis projection/reconstruction interfaces.
Definition: gcg.h:2787
Defines a synchronized and thread safe memory cache. This is an abstract data structure that may be u...
Definition: gcg.h:6696
bool gcgDrawVectorThetrahedronClosed(float x, float y, float z, VECTOR3 vector, float scale)
Draws an oriented thetrahedron (its base is also drawn) which can be used to represent vectors: 4 tri...
unsigned int rows
Number of rows.
Definition: gcg.h:8208
void * buffer
Buffer used in projection/reconstruction.
Definition: gcg.h:8574
unsigned int gcgUnpackRLE32(unsigned char *RLEdata, unsigned char *dstdata)
Decompress a 32 bit Run-Length Encoded data coded with gcgPackRLE32().
unsigned int gcgGetNumberOfProcessors()
Gets the number of processors installed in the system.
unsigned char * data
Image data where each pixel may be an index (1, 2, 4 and 8 bpp) or the actual color.
Definition: gcg.h:2924
struct _GCG_PATRICIA_NODE * root
Root node of the PATRICIA tree: internal only.
Definition: gcg.h:6056
int remote_port
Remote port.
Definition: gcg.h:7356
uintptr_t counter
Number of elements in this list. Read-only.
Definition: gcg.h:4857
gcgDISCRETE1D< NUMTYPE > rG
High pass reconstruction filter. Read-only.
Definition: gcg.h:8568
bool gcgEigenSymmetric(int norder, float matrix[], float eigenvectors[], float eigenvalues[])
Computes the eigensystem decomposition of a symmetric matrix matrix with arbitraty order...
long lkey
The key as a long integer: guaranteed to have at least 32 bits in C. It has 32 bits in x86-64 machine...
Definition: gcg.h:5882
unsigned long totalcost
Sum of the cost of all key/value pairs. Read-Only.
Definition: gcg.h:6698
gcgLINK * first
Points to the first gcgLINK node in the list. Read-only.
Definition: gcg.h:5086
const char * GCG_VERSION
Points to the full version string on the form: major.minor.build.
Definition: gcg.h:387
Generic abstract class to manage a AVL tree. AVL tree is a self balancing data structure that keeps a...
Definition: gcg.h:5456
Class for handling images with up to 32 bits per pixel and up to 4 channels.
Definition: gcg.h:2922
Implements methods for peer-to-peer communication using TCP/IP protocol.
Definition: gcg.h:7349
Generic abstract class to allow iterations over the several GCGlib data structures. The gcgITERATOR::next() returns the next object until it is NULL. The returned object type depends on the data structure and commonly is a specialization of gcgORDEREDNODE, gcgDOUBLELINK or gcgLINK classes. While iteration is being done, the original data structure must not be changed by insertions, removals or moves. Iterators copies all needed information to iterate over the nodes and are not allowed to change its associated data structure. A data structure can have several gcgITERATOR instances working at a time. The gcgITERATOR object must be deleted after use.
Definition: gcg.h:4609
Generic abstract class for defining an extended node for use in ordered data structures like gcgORDER...
Definition: gcg.h:5334
gcgDISCRETE1D< NUMTYPE > G
High pass decomposition filter. Read-only.
Definition: gcg.h:8566
unsigned int nsamplesX
Current samples in X direction. Read-only. See setNumberOfSamples().
Definition: gcg.h:8409
Base abstract class for defining a sequential data structure in GCGlib for lists. It indicates the mi...
Definition: gcg.h:4735
gcgJOB()
Constructs a valid and empty job. It is intended to be implemented by specialized classes...
Definition: gcg.h:6837
GCG - Group for Computer Graphics, Image and Vision library.
gcgLINK * next
Points to the right/next gcgLINK node in a list. Same pointer as right. Read-only.
Definition: gcg.h:4700
bool gcgInverseMatrix2(MATRIX2 inverse, MATRIX2 matrix)
Computes the inverse of a 2x2 matrix by the direct method. It is suitable for fast inverse computatio...
gcgLINK * last
Points to the last gcgLINK node in the list. Read-only.
Definition: gcg.h:4856
Generic abstract class for defining a thread.
Definition: gcg.h:6322
unsigned int gcgCompressImageRLE8(unsigned int width, unsigned int height, unsigned char *srcdata, unsigned char *RLEdata)
Compress a 8 bit bitmap image as a Run-Lenght Encoded block.
Base class for all GCGlib classes. It is used for better control of object instantiation, memory allocation, and object reuse. Some systems (like DLL versions in Windows) might demand special tasks in order to be stable. All GCGlib classes must be inherited from gcgCLASS.
Definition: gcg.h:957
Union type for defining digital keys for data map classes. The data maps might use fixed or variable ...
Definition: gcg.h:5879