#pragma once #include "Vect3usi.h" // =================================================================== // // Get 'i'th neighbor (in following i order): // // i z y x // // 0 -1 0 0 // 1 0 -1 0 // 2 0 0 -1 // 3 0 0 1 // 4 0 1 0 // 5 1 0 0 // 6 brings all ZYX back to original // // IMPORTANT NOTE, this function should be called in a loop from i = 0:5, AND ZYX SHOULD NOT BE CHANGED IN BETWEEN CALLS // -IF ZYX want to be returned to the original state at the end, call one more time with i = 6 // -IF you break in the middle of the i=0:5 iterations, ZYX should not be reused // // returns FALSE if result is negative or larger than max_vals // =================================================================== // inline bool get_zyx_neigh_6dir(char &i, unsigned short &z, unsigned short &y, unsigned short &x, unsigned short &mz, unsigned short &my, unsigned short &mx) { switch (i) { case 0: --z; if (z == 65535) return false; return true; case 1: ++z; --y; if (y == 65535) return false; return true; case 2: ++y; --x; if (x == 65535) return false; return true; case 3: x += 2; if (x >= mx) return false; return true; case 4: ++y; --x; if (y >= my) return false; return true; case 5: ++z; --y; if (z >= mz) return false; return true; case 6: --z; return false; default: return false; } } inline bool get_zyx_neigh_6dir(char &i, Vect3usi &xyz, Vect3usi &max_xyz) { return get_zyx_neigh_6dir(i, xyz.z, xyz.y, xyz.x, max_xyz.z, max_xyz.y, max_xyz.x ); }; // =================================================================== // // Finds an infinity value for data size // =================================================================== // template <class T> class FindUsefulTypeProperties { public: FindUsefulTypeProperties(); ~FindUsefulTypeProperties(); T getInfinity(); bool isSigned(); // Useful constants private: bool is_signed; T infinity; }; template <class T> FindUsefulTypeProperties<T>::FindUsefulTypeProperties( ) { // Determine if it 'T' is signed or not T sign_test = (T)-1; is_signed = ( sign_test >= 0 ) ? (false) : (true); // Calculate infinity, first set entire bit range to 1 infinity = 0xFF; for (int i = 1; i < sizeof(T); i++) { // Now shift in '1' for full data type size infinity = (infinity << 8) | 0xFF; } // If T is signed, set MSb of infinity to 0 if (is_signed) { infinity = infinity >> 1; } }; template <class T> FindUsefulTypeProperties<T>::~FindUsefulTypeProperties( ) { }; // ------- FUNCTION IMPLEMENTATIONS ------- // template <class T> T FindUsefulTypeProperties<T>::getInfinity() { return infinity; }; template <class T> bool FindUsefulTypeProperties<T>::isSigned() { return is_signed; };