VR-Forces 4.0.4 Class Documentation
include/vrvCore/DtIntersectorCacheKey.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 2010 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 /******************************************************************************
00006 ** $RCSfile: DtCachedIntersectorKey.h,v $ $Revision: 1.9 $ $State: Exp $
00007 ******************************************************************************/
00008 
00015 
00016 #pragma once
00017 
00018 #include <vrvCore/vrvCore.h>
00019 #include <vrvCore/DtIntersector.h>
00020 
00021 #include <string.h>
00022 
00023 namespace makVrv
00024 {
00027    class DtIntersectorCacheKey
00028    {
00029    public:
00031       DtIntersectorCacheKey(DtIntersector::IntersectProperties p, double x, double y, double z)
00032       {
00033          myVals[0] = x; myVals[1] = y; myVals[2] = z;
00034          myVals[3] = 99999999.99999999; myVals[4] = 99999999.99999999; myVals[5] = 99999999.99999999;
00035          myVals[6] = p;
00036          myHashValue = hash((const unsigned char*)&myVals[0], sizeof(myVals));
00037       }
00038       
00040       DtIntersectorCacheKey(DtIntersector::IntersectProperties p, double x, double y, double z,
00041          double end_x, double end_y, double end_z)
00042       {
00043          myVals[0] = x; myVals[1] = y; myVals[2] = z;
00044          myVals[3] = end_x; myVals[4] = end_y; myVals[5] = end_z;
00045          myVals[6] = p;
00046          myHashValue = hash((const unsigned char*)&myVals[0], sizeof(myVals));
00047       }
00048 
00050       DtIntersectorCacheKey(const DtIntersectorCacheKey& k)
00051       {
00052          memcpy(myVals, k.myVals, sizeof(myVals));
00053          myHashValue = k.myHashValue;
00054       }
00055 
00057       bool operator==(const DtIntersectorCacheKey& rhs) const
00058       {
00059          return (myHashValue == rhs.myHashValue);
00060       }
00061 
00062       bool operator!=(const DtIntersectorCacheKey& rhs) const
00063       {
00064          return !(*this == rhs);
00065       }
00066 
00068       std::size_t hash(const unsigned char *p, int n)
00069       {
00070           std::size_t h = 0;
00071           std::size_t g;
00072 
00073           while (n--) {
00074               h = (h << 4) + *p++;
00075               if ((g = (h & 0xf0000000)) != 0)
00076                   h ^= g >> 23;
00077               h &= ~g;
00078           }
00079           return h;
00080       }
00081 
00083       inline std::size_t hashValue() const
00084       {
00085          return myHashValue;
00086       }
00087 
00088       inline operator std::size_t() const
00089       {
00090          return myHashValue;
00091       }
00092 
00093    protected:
00094       double myVals[7];
00095       std::size_t myHashValue;
00096    };
00097 }

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)