VCRA-SZCZERBACKI-PointBasedRendering/ssDefs.cpp

00001 #include "ssDefs.hpp"
00002 
00003 #undef NDEBUG                                   // we need to get the real assertion routines...
00004 
00005 #include <cassert>
00006 #include <cstdio>
00007 
00008 using namespace SS;
00009 
00010 /*****************************************************************************
00011  *
00012  * Function:            SS::assertFail()
00013  *
00014  * Description:         Assertion failure function -- calls either user-defined
00015  *                                      error handler or native assert() function.
00016  *
00017  *****************************************************************************/
00018 
00019 void SS::assertFail (const char* expr, const char* file, int line, const char* /*message*/)
00020 {
00021         #if defined (SS_BUILD_ACC)
00022                 __assert((const char*)expr,(const char*)file,line);
00023         #elif defined (SS_BUILD_GCC) && defined (SS_OS_LINUX)
00024                 __assert_fail(expr,file,line,"unknown function");
00025         #elif defined (SS_BUILD_GCC) && defined (SS_OS_MAC)
00026                 __assert((const char*)expr,file,line);
00027         #elif defined (SS_BUILD_GCC)
00028                 __assert((const char*)expr,line,file);
00029         #elif defined (SS_BUILD_CW)
00030                 __assertion_failed((char*)expr,(const char*)file,line);
00031         #elif defined (SS_BUILD_BC)
00032                 _assert((const char*)expr,(const char*)file,line);
00033         #elif defined (SS_BUILD_IVA)
00034                 _assert(expr,file,line);
00035         #else
00036 //              _assert((void*)expr,(void*)file,line);
00037         #endif
00038 }
00039 
00040 
00041 /*****************************************************************************
00042  *
00043  * Function:            SS::intChop()
00044  *
00045  * Description:         
00046  *
00047  *****************************************************************************/
00048 
00049 int SS::intChop (const float& f) 
00050 { 
00051         INT32 a                 = *reinterpret_cast<const INT32*>(&f);                  // take bit pattern of float into a register
00052         INT32 sign              = (a>>31);                                                                              // sign = 0xFFFFFFFF if original value is negative, 0 if positive
00053         INT32 mantissa  = (a&((1<<23)-1))|(1<<23);                                              // extract mantissa and add the hidden bit
00054         INT32 exponent  = ((a&0x7fffffff)>>23)-127;                                             // extract the exponent
00055         INT32 r                 = ((UINT32)(mantissa)<<8)>>(31-exponent);               // ((1<<exponent)*mantissa)>>24 -- (we know that mantissa > (1<<24))
00056         return ((r ^ (sign)) - sign ) &~ (exponent>>31);                                // add original sign. If exponent was negative, make return value 0.
00057 }
00058 
00059 /*****************************************************************************
00060  *
00061  * Function:            SS::intFloor()
00062  *
00063  * Description:         
00064  *
00065  *****************************************************************************/
00066 
00067 int SS::intFloor (const float& f) 
00068 { 
00069         INT32 a                 = *reinterpret_cast<const INT32*>(&f);                                                                  // take bit pattern of float into a register
00070         INT32 sign              = (a>>31);                                                                                                                              // sign = 0xFFFFFFFF if original value is negative, 0 if positive
00071         a&=0x7fffffff;                                                                                                                                                  // we don't need the sign any more
00072         INT32 exponent  = (a>>23)-127;                                                                                                                  // extract the exponent
00073         INT32 expsign   = ~(exponent>>31);                                                                                                              // 0xFFFFFFFF if exponent is positive, 0 otherwise
00074         INT32 imask             = ( (1<<(31-(exponent))))-1;                                                                                    // mask for true integer values
00075         INT32 mantissa  = (a&((1<<23)-1));                                                                                                              // extract mantissa (without the hidden bit)
00076         INT32 r                 = ((UINT32)(mantissa|(1<<23))<<8)>>(31-exponent);                                               // ((1<<exponent)*(mantissa|hidden bit))>>24 -- (we know that mantissa > (1<<24))
00077         r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign);   // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; 
00078         return r;
00079 }
00080 
00081 /*****************************************************************************
00082  *
00083  * Function:            SS::intCeil()
00084  *
00085  * Description:         
00086  *
00087  *****************************************************************************/
00088 
00089 int SS::intCeil (const float& f) 
00090 { 
00091         INT32 a                 = *reinterpret_cast<const INT32*>(&f) ^ 0x80000000;                                             // take bit pattern of float into a register
00092         INT32 sign              = (a>>31);                                                                                                                              // sign = 0xFFFFFFFF if original value is negative, 0 if positive
00093         a&=0x7fffffff;                                                                                                                                                  // we don't need the sign any more
00094         INT32 exponent  = (a>>23)-127;                                                                                                                  // extract the exponent
00095         INT32 expsign   = ~(exponent>>31);                                                                                                              // 0xFFFFFFFF if exponent is positive, 0 otherwise
00096         INT32 imask             = ( (1<<(31-(exponent))))-1;                                                                                    // mask for true integer values
00097         INT32 mantissa  = (a&((1<<23)-1));                                                                                                              // extract mantissa (without the hidden bit)
00098         INT32 r                 = ((UINT32)(mantissa|(1<<23))<<8)>>(31-exponent);                                               // ((1<<exponent)*(mantissa|hidden bit))>>24 -- (we know that mantissa > (1<<24))
00099         r = ((r & expsign) ^ (sign)) + ((!((mantissa<<8)&imask)&(expsign^((a-1)>>31)))&sign);   // if (fabs(value)<1.0) value = 0; copy sign; if (value < 0 && value==(int)(value)) value++; 
00100         return -r;
00101 }
00102 
00103 //------------------------------------------------------------------------

Generated on Thu Feb 15 09:09:20 2007 for Surface Splating by  doxygen 1.5.1-p1