fshake3d
0.0.1
FreeformDensity3DSurfaceEditor
|
00001 #ifndef PLX_MATH_HPP 00002 #define PLX_MATH_HPP 00003 00004 #include <gmtl/gmtl.h> 00005 00006 typedef gmtl::Rayd Ray; 00007 typedef gmtl::Matrix44d Matrix; 00008 00009 using namespace gmtl; 00010 00011 00012 template<typename T> inline T clamp(T x, T min, T max) { return (x<min) ? min : (x>max) ? max : x; } 00013 00014 // typedef float Scalar; 00015 00016 inline Vec3d spherical_coordinate_to_Vec3d(double azimuth, double polar) 00017 { 00018 return Vec3d( 00019 cos(Math::deg2Rad(azimuth)) * sin(Math::deg2Rad(polar) ) 00020 , sin(Math::deg2Rad(azimuth)) * sin(Math::deg2Rad(polar) ) 00021 , cos(Math::deg2Rad(polar)) 00022 ); 00023 } 00024 00025 template<typename IterT> 00026 unsigned char* new_colormap(int steps, IterT keys, int nkeys) 00027 { 00028 static const int CHANNELS = 3; 00029 00030 unsigned char* cmap = new unsigned char[steps*CHANNELS]; 00031 00032 unsigned char* out = cmap; 00033 double window = 1.0/nkeys; 00034 00035 for(int i = 0; i < steps ; ++i ) 00036 { 00037 // f is the global step interpolation fraction [ = 0..1 ] 00038 double f = ( double(i) / double(steps-1) ); 00039 00040 // alpha mix factor between two keys [ = 0..1 ] 00041 00042 double keyf = f * double(nkeys-1); 00043 double base; 00044 double alpha = modf( keyf, &base ); 00045 00046 int ia = int(base); 00047 if (ia >= nkeys) ia = nkeys-1; 00048 int ib = int(base) + 1; 00049 if (ib >= nkeys) ib = nkeys-1; 00050 00051 Vec3d col = keys[ia] * (1-alpha) + keys[ib] * alpha; 00052 00053 for(int j = 0; j < CHANNELS ; ++j ) 00054 { 00055 out[j] = static_cast<unsigned char>( col[j]*255 ); 00056 } 00057 out += CHANNELS; 00058 /* 00059 *out++ =unsigned char( col[0]*255 ); 00060 *out++ =unsigned char( col[1]*255 ); 00061 *out++ =unsigned char( col[2]*255 ); 00062 */ 00063 } 00064 return cmap; 00065 } 00066 00067 inline Point3d center(const AABoxd& aabox) 00068 { 00069 return ( aabox.getMin() + aabox.getMax() ) * 0.5; 00070 } 00071 00072 inline Vec3d size(const AABoxd& aabox) 00073 { 00074 return ( aabox.getMax() - aabox.getMin() ); 00075 } 00076 00077 #endif // PLX_MATH_HPP