Exemple #1
0
// Test loading of volume
TEST(MAIN, RangeBasic){
  Range one(V3f(0,0,0), V3f(1,1,1)); //start
  Range inside(V3f(0.1,0.1,0.1), V3f(0.9,0.9,0.9)); 
  Range intersecting(V3f(0.1,0.1,0.1), V3f(0.9,5,0.9)); 
  Range outside(V3f(1.1,-2,3), V3f(1.2,-1,3.8)); 

  EXPECT_TRUE(ContainsPoint(one, V3f(0.5, 0.5, 0.5)));  // Some common cases
  EXPECT_FALSE(ContainsPoint(one, V3f(1.1, 0.5, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(-0.1, 0.5, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 1.1, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, -0.1, 0.5)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 0.5, 1.1)));
  EXPECT_FALSE(ContainsPoint(one, V3f(0.5, 0.5, -0.1)));
  EXPECT_TRUE(ContainsRange(one, inside));
  EXPECT_TRUE(IntersectsRange(one, intersecting));
  EXPECT_FALSE(ContainsRange(one, intersecting));
  EXPECT_FALSE(ContainsRange(one, outside));
};
//TODO - implement texture source; dummy for now.
bool Textured::CheckTexture(Range & r){

  if(force_update){ //First time.
    force_update = false;
    return UpdateTextured( *this, r);
  };

  if((r.max.x - r.min.x) > SIZE ||
     (r.max.y - r.min.y) > SIZE ||
     (r.max.z - r.min.z) > SIZE)return false;
  if(ContainsRange(current_range, r)){
    return true;
  };
  
  return UpdateTextured( *this, r);
};
        // Obtain data from the cache.
        // If the cache does not contain the requested amout of data: read more from the ReadCallback.
        // returns the count of bytes that have been read or -1 on error
        int ReadData(void* p_Buffer, int s32_Pos, int s32_Count)
        {
#if _TraceCache
            CTrace::TraceW(L"  CMemBlock %s:  ReadData(Pos= %08d, Count= %05d)", mu16_Name, s32_Pos, s32_Count);
#endif

            if (!ms32_BlockSize)            throw "The CMemBlock cache is not intialized!";
            if (s32_Count > ms32_BlockSize) throw "Cache blocksize too small!";

            // If the cache does not contain the requested data -> fill with new data
            if (!ContainsRange(s32_Pos, 0))
            {
#if _TraceCache
                if (s32_Pos < ms32_StartPos) CTrace::TraceW(L"******* Warning Cache Callback reads a block twice! *******");
#endif

                ms32_StartPos = s32_Pos;
                ms32_Content  = mf_ReadCallback(mu8_Memory, s32_Pos, ms32_BlockSize);

#if _TraceCache
                CTrace::TraceW(L"  CMemBlock %s: *Callback(Pos= %08d, Count= %05d) --> %05d Bytes read", mu16_Name, s32_Pos, ms32_BlockSize, ms32_Content);
#endif

                if (ms32_Content < 0)
                    return -1; // Read Error
            }

            int s32_RelPos = s32_Pos - ms32_StartPos;
            s32_Count = min(s32_Count, ms32_Content - s32_RelPos);

#if _TraceCache
            CTrace::TraceW(L"  CMemBlock %s:  Copy Buf RelPos= %05d, Count= %05d", mu16_Name, s32_RelPos, s32_Count);
#endif

            memmove(p_Buffer, mu8_Memory + s32_RelPos, s32_Count);
            return s32_Count;
        }