コード例 #1
0
ファイル: BitTag.cpp プロジェクト: chrismullins/moab
ErrorCode BitTag::clear_data( SequenceManager* seqman,
                              Error* error,
                              const EntityHandle* handles, 
                              size_t num_handles, 
                              const void* value_ptr,
                              int value_len )
{
  if (value_len)
    return MB_INVALID_SIZE;

  ErrorCode rval = seqman->check_valid_entities( error, handles, num_handles, true );
  if (MB_SUCCESS != rval)
    return rval;
    
  EntityType type;
  size_t page;
  int offset;
  const unsigned char value = *reinterpret_cast<const unsigned char*>(value_ptr);
  for (size_t i = 0; i < num_handles; ++i) {
    unpack( handles[i], type, page, offset );
    if (pageList[type].size() <= page)
      pageList[type].resize(page+1, 0);
    if (!pageList[type][page])
      pageList[type][page] = new BitPage( storedBitsPerEntity, default_val());
    pageList[type][page]->set_bits( offset, storedBitsPerEntity, value );
  }
  return MB_SUCCESS;
}
コード例 #2
0
void 
TestNearestNeighborSplat<T>::testPolicies()
{
    USING_NK_NS
    USING_NKHIVE_NS
    
    // construct volume
    T default_val(0); 
    T splat_val(1);
    
    // Test plus policy
    {
        typename Volume<T>::shared_ptr volume(new Volume<T>(2, 1, default_val));
        NearestNeighborSplat<T, std::plus> splatter(volume);
        splatter.splat(-0.2, -1.2, -0.8, splat_val);
        splatter.splat(-0.2, -1.2, -0.8, splat_val);

        TOL_CHECK(volume->get(-1, -2, -1), 2);
    }

    // Test set policy
    {
        typename Volume<T>::shared_ptr volume(new Volume<T>(2, 1, default_val));
        NearestNeighborSplat<T, set_op> splatter(volume);
        splatter.splat(-0.2, -1.2, -0.8, splat_val);
        splatter.splat(-0.2, -1.2, -0.8, splat_val);

        TOL_CHECK(volume->get(-1, -2, -1), 1);
    }
}
コード例 #3
0
ファイル: TestInterpolation.cpp プロジェクト: papaver/nkhive
void
TestInterpolation<T>::testGetIndexBounds()
{
    USING_NK_NS
    USING_NKHIVE_NS
  
    // construct volume 
    T default_val(1); 
    vec3d res(1.0);
    vec3d kernel_offset(0.5);
    typename Volume<T>::shared_ptr volume(
                        new Volume<T>(1, 2, default_val, res, kernel_offset));

    // create interpolator
    CubicInterpolation<T> cubic_interp(volume);

    // test interior point on a cell boundary
    vec3d voxel_coords(2.0,2.0,2.0);
    vec3i voxel_indices(2,2,2);

    vec3i min_indices, max_indices;
    cubic_interp.getIndexBounds(voxel_coords, voxel_indices, 
                               min_indices, max_indices);

    CPPUNIT_ASSERT(min_indices == vec3i(0,0,0));
    CPPUNIT_ASSERT(max_indices == vec3i(3,3,3));

    // test interior point
    voxel_coords = vec3d(2.15,2.2,2.1);
    voxel_indices = vec3i(2,2,2);

    cubic_interp.getIndexBounds(voxel_coords, voxel_indices, 
                               min_indices, max_indices);

    CPPUNIT_ASSERT(min_indices == vec3i(0,0,0));
    CPPUNIT_ASSERT(max_indices == vec3i(3,3,3));
    
    // test interior point rounded up
    voxel_coords = vec3d(2.75,2.8,2.9);
    voxel_indices = vec3i(2,2,2);

    cubic_interp.getIndexBounds(voxel_coords, voxel_indices, 
                               min_indices, max_indices);

    CPPUNIT_ASSERT(min_indices == vec3i(1,1,1));
    CPPUNIT_ASSERT(max_indices == vec3i(4,4,4));
    
    // test an arbitrary point
    voxel_coords = vec3d(1.9,1.2,3.2);
    voxel_indices = vec3i(1,1,3);

    cubic_interp.getIndexBounds(voxel_coords, voxel_indices, 
                               min_indices, max_indices);

    CPPUNIT_ASSERT(min_indices == vec3i(0,-1,1));
    CPPUNIT_ASSERT(max_indices == vec3i(3,2,4));
}
コード例 #4
0
ファイル: TestInterpolation.cpp プロジェクト: papaver/nkhive
void
TestInterpolation<T>::testCollectInterpolants()
{
    USING_NK_NS
    USING_NKHIVE_NS

    // construct volume 
    T default_val(1); 
    vec3d res(1.0);
    vec3d kernel_offset(0.5);
    typename Volume<T>::shared_ptr volume(
                        new Volume<T>(1, 2, default_val, res, kernel_offset));
    
    // easy to track values    
    i32 value=0; 
    for (i32 z=0; z<4; ++z) {
        for (i32 y=0; y<4; ++y) {
            for (i32 x=0; x<4; ++x) {
                volume->set(x,y,z,value++);
            }
        }
    }

    vec3i min_indices(0,0,0);
    vec3i max_indices(3,3,3);

    CubicInterpolation<T> cubic_interp(volume);

    // test interior
    typename CubicInterpolation<T>::calc_type interpolants[64];
    cubic_interp.collectInterpolants(min_indices, max_indices, interpolants);

    for (i32 i=0; i<64; ++i) {
        CPPUNIT_ASSERT(interpolants[i] == 
                                typename CubicInterpolation<T>::calc_type(i));
    }

    // test boundary
    min_indices = vec3i(0,0,1);
    max_indices = vec3i(3,3,4);
    cubic_interp.collectInterpolants(min_indices, max_indices, interpolants);

    for (i32 i=0; i<48; ++i) {
        CPPUNIT_ASSERT(interpolants[i] == 
                            typename CubicInterpolation<T>::calc_type(i + 16));
    }

    for (i32 i=0; i<16; ++i) {
        CPPUNIT_ASSERT(interpolants[i + 48] == 
                                 typename CubicInterpolation<T>::calc_type(1));
    }
}
コード例 #5
0
ファイル: TestLinearSplat.cpp プロジェクト: papaver/nkhive
void
TestLinearSplat<T>::testPolicies()
{
    USING_NK_NS
    USING_NKHIVE_NS

    // construct volume
    T default_val(0); 
    T splat_val(1);
    vec3d res(1.0);
    vec3d kernel_offset(0.5);

    // test std::plus
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T, std::plus> splatter(volume);
        splatter.splat(0, 0, 0, splat_val);
        splatter.splat(0, 0, 0, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 0.25);
        TOL_CHECK(volume->get(0, 0, -1), 0.25);
        TOL_CHECK(volume->get(0, -1, 0), 0.25);
        TOL_CHECK(volume->get(0, -1, -1), 0.25);
        TOL_CHECK(volume->get(-1, 0, 0), 0.25);
        TOL_CHECK(volume->get(-1, -1, 0), 0.25);
        TOL_CHECK(volume->get(-1, 0, -1), 0.25);
        TOL_CHECK(volume->get(-1, -1, -1), 0.25);
    }

    // test set
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T, set_op> splatter(volume);
        splatter.splat(0, 0, 0, splat_val);
        splatter.splat(0, 0, 0, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 0.125);
        TOL_CHECK(volume->get(0, 0, -1), 0.125);
        TOL_CHECK(volume->get(0, -1, 0), 0.125);
        TOL_CHECK(volume->get(0, -1, -1), 0.125);
        TOL_CHECK(volume->get(-1, 0, 0), 0.125);
        TOL_CHECK(volume->get(-1, -1, 0), 0.125);
        TOL_CHECK(volume->get(-1, 0, -1), 0.125);
        TOL_CHECK(volume->get(-1, -1, -1), 0.125);
    }
}
コード例 #6
0
ファイル: BitTag.cpp プロジェクト: chrismullins/moab
ErrorCode BitTag::remove_data( SequenceManager*,
                               Error*,
                               const EntityHandle* handles, 
                               size_t num_handles )
{
  EntityType type;
  size_t page;
  int offset;
  const unsigned char val = default_val();
  for (size_t i = 0; i < num_handles; ++i) {
    unpack( handles[i], type, page, offset );
    if (pageList[type].size() > page && pageList[type][page])
      pageList[type][page]->set_bits( offset, storedBitsPerEntity, val );
  }
  return MB_SUCCESS;
}
コード例 #7
0
ファイル: TestInterpolation.cpp プロジェクト: papaver/nkhive
void
TestInterpolation<T>::testInterpNegative()
{
    USING_NK_NS
    USING_NKHIVE_NS
  
    // construct volume 
    T default_val(1); 
    vec3d res(1.0);
    vec3d kernel_offset(0.5);
    typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));

    // set some cell values
    volume->set(-1, -2, -1, T(2));
    volume->set(-1, -2, -2, T(2));
    volume->set(-2, -2, -1, T(2));
    volume->set(-2, -2, -2, T(2));

    // create interpolation object
    LinearInterpolation<T> linear_interp(volume);
    
    // test interior point
    T result(0);
    linear_interp.interp(-1.0, -1.0, -1.0, result);
    CHECK_RESULT(1.5);

    // test boundary point
    linear_interp.interp(-1.0, 0.0, -1.0, result);
    CHECK_RESULT(1.0);

    // test boundary point
    linear_interp.interp(-1.0, -2.0, -1.0, result);
    CHECK_RESULT(1.5);

    // test interior point
    linear_interp.interp(-1.0, -0.75, -1.0, result);
    CHECK_RESULT(1.25);
  
    // test interior point
    linear_interp.interp(-1.0, -1.25, -1.0, result);
    CHECK_RESULT(1.75);
}
コード例 #8
0
ファイル: BitTag.cpp プロジェクト: chrismullins/moab
ErrorCode BitTag::get_data( const SequenceManager*,
                            Error*,
                            const EntityHandle* handles, 
                            size_t num_handles, 
                            void* gen_data ) const
{
  EntityType type;
  size_t page;
  int offset;
  unsigned char def = default_val();
  unsigned char* data = reinterpret_cast<unsigned char*>(gen_data);
  for (size_t i = 0; i < num_handles; ++i) {
    unpack( handles[i], type, page, offset );
    if (pageList[type].size() <= page || !pageList[type][page]) 
      data[i] = def;
    else
      data[i] = pageList[type][page]->get_bits( offset, storedBitsPerEntity );
  }
  return MB_SUCCESS;
}
コード例 #9
0
ファイル: BitTag.cpp プロジェクト: chrismullins/moab
ErrorCode BitTag::clear_data( SequenceManager* seqman,
                              Error* error,
                              const Range& handles, 
                              const void* value_ptr,
                              int value_len )
{
  if (value_len)
    return MB_INVALID_SIZE;

  ErrorCode rval = seqman->check_valid_entities( error, handles );
  if (MB_SUCCESS != rval)
    return rval;
    
  EntityType type;
  EntityID count;
  size_t page;
  int offset, per_page = ents_per_page();
  const unsigned char value = *reinterpret_cast<const unsigned char*>(value_ptr);
  Range::const_pair_iterator i;
  for (i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i) {
    unpack( i->first, type, page, offset );
    assert(TYPE_FROM_HANDLE(i->second) == type); // should be true because id of zero is never used
    count = i->second - i->first + 1;
    
    while (count) {
      if (page >= pageList[type].size())
        pageList[type].resize( page+1, 0 );
      if (!pageList[type][page])
        pageList[type][page] = new BitPage( storedBitsPerEntity, default_val() );

      size_t pcount = std::min( (EntityID)(per_page - offset), count );
      pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, value );
      count -= pcount; 
      offset = 0;
      ++page;
    }
  }
  return MB_SUCCESS;
}
コード例 #10
0
ファイル: BitTag.cpp プロジェクト: chrismullins/moab
ErrorCode BitTag::remove_data( SequenceManager*, Error*, const Range& handles )
{
  EntityType type;
  EntityID count;
  size_t page;
  int offset, per_page = ents_per_page();
  unsigned char val = default_val();
  Range::const_pair_iterator i;
  for (i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i) {
    unpack( i->first, type, page, offset );
    assert(TYPE_FROM_HANDLE(i->second) == type); // should be true because id of zero is never used
    count = i->second - i->first + 1;
    
    while (count) {
      size_t pcount = std::min( (EntityID)(per_page - offset), count );
      if (page < pageList[type].size() && pageList[type][page])
        pageList[type][page]->set_bits( offset, pcount, storedBitsPerEntity, val );
      count -= pcount; 
      offset = 0;
      ++page;
    }
  }
  return MB_SUCCESS;
}
コード例 #11
0
ファイル: BitTag.cpp プロジェクト: chrismullins/moab
ErrorCode BitTag::get_data( const SequenceManager*,
                            Error*,
                            const Range& handles, 
                            void* gen_data ) const
{
  EntityType type;
  EntityID count;
  size_t page;
  int offset, per_page = ents_per_page();
  unsigned char def = default_val();
  unsigned char* data = reinterpret_cast<unsigned char*>(gen_data);
  Range::const_pair_iterator i;
  for (i = handles.const_pair_begin(); i != handles.const_pair_end(); ++i) {
    unpack( i->first, type, page, offset );
    assert(TYPE_FROM_HANDLE(i->second) == type); // should be true because id of zero is never used
    count = i->second - i->first + 1;
    if (page >= pageList[type].size()) {
      memset( data, def, count );
      data += count;
      continue;
    }
    
    while (count) {
      size_t pcount = std::min( (EntityID)(per_page - offset), count );
      if (pageList[type][page])
        pageList[type][page]->get_bits( offset, pcount, storedBitsPerEntity, data );
      else
        memset( data, def, pcount );
      data += pcount;
      count -= pcount; 
      offset = 0;
      ++page;
    }
  }
  return MB_SUCCESS;
}
コード例 #12
0
ファイル: TestInterpolation.cpp プロジェクト: papaver/nkhive
void
TestInterpolation<T>::testInterp()
{
    USING_NK_NS
    USING_NKHIVE_NS

    // construct volume 
    T default_val(1); 
    vec3d res(1.0);
    vec3d kernel_offset(0.5);
    typename Volume<T>::shared_ptr volume(
                        new Volume<T>(1, 2, default_val, res, kernel_offset));

    // easy to track values    
    i32 value=0; 
    for (i32 z=0; z<4; ++z) {
        for (i32 y=0; y<4; ++y) {
            for (i32 x=0; x<4; ++x) {
                volume->set(x,y,z,value++);
            }
        }
    }

    // test an interior point
    typename CubicInterpolation<T>::calc_type coords[3];
    coords[0] = 1.75;
    coords[1] = 2.0;
    coords[2] = 2.25;

    CubicInterpolation<T> cubic_interp(volume);

    T result;
    cubic_interp.interp(coords[0], coords[1], coords[2], result);
    CHECK_RESULT(35.25);
    
    // test boundary points
    coords[0] = 1.5;
    coords[1] = 1.5;
    coords[2] = 1.5;
    cubic_interp.interp(coords[0], coords[1], coords[2], result);
    CHECK_RESULT(21.0);

    coords[0] = 1.5;
    coords[1] = 1.5;
    coords[2] = 2.5;
    cubic_interp.interp(coords[0], coords[1], coords[2], result);
    CHECK_RESULT(37.0);

    coords[0] = 2.5;
    coords[1] = 1.5;
    coords[2] = 2.5;
    cubic_interp.interp(coords[0], coords[1], coords[2], result);
    CHECK_RESULT(38.0);

    coords[0] = 2.5;
    coords[1] = 2.5;
    coords[2] = 2.5;
    cubic_interp.interp(coords[0], coords[1], coords[2], result);
    CHECK_RESULT(42.0);

}
コード例 #13
0
ファイル: TestInterpolation.cpp プロジェクト: papaver/nkhive
void
TestInterpolation<T>::testLinear()
{
    USING_NK_NS
    USING_NKHIVE_NS
  
    // construct volume 
    T default_val(1); 
    vec3d res(1.0);
    vec3d kernel_offset(0.5);
    typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));

    // set some cell values
    volume->set(0, 1, 0, T(2));
    volume->set(0, 1, 1, T(2));
    volume->set(1, 1, 0, T(2));
    volume->set(1, 1, 1, T(2));

    // create interpolation object
    LinearInterpolation<T> linear_interp(volume);
    
    // test interior point
    T result(0);
    linear_interp.interp(1.0, 1.0, 1.0, result);
    CHECK_RESULT(1.5);

    // test boundary point
    linear_interp.interp(1.0, 0.0, 1.0, result);
    CHECK_RESULT(1.0);

    // test boundary point
    linear_interp.interp(1.0, 2.0, 1.0, result);
    CHECK_RESULT(1.5);

    // test interior point
    linear_interp.interp(1.0, 0.75, 1.0, result);
    CHECK_RESULT(1.25);
  
    // test interior point
    linear_interp.interp(1.0, 1.25, 1.0, result);
    CHECK_RESULT(1.75);
    
    // test y axis 
    // destroy and create new one
    // clear would be nice here
    volume = typename Volume<T>::shared_ptr(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
   
    // set some cell values
    volume->set(1, 0, 0, T(2));
    volume->set(1, 0, 1, T(2));
    volume->set(1, 1, 0, T(2));
    volume->set(1, 1, 1, T(2));
    
    // create interpolation object
    LinearInterpolation<T> linear_interp2(volume);
    
    // test interior point
    linear_interp2.interp(1.0, 1.0, 1.0, result);
    CHECK_RESULT(1.5);

    // test boundary point
    linear_interp2.interp(0.0, 0.75, 1.0, result);
    CHECK_RESULT(1.0);

    // test boundary point
    linear_interp2.interp(2.0, 1.0, 1.0, result);
    CHECK_RESULT(1.5);
   
    // test z axis 
    // destroy and create new one
    // clear would be nice here
    volume = typename Volume<T>::shared_ptr(
                        new Volume<T>(2, 1, default_val, res, kernel_offset)); 
   
    // set some cell values
    volume->set(0, 0, 1, T(2));
    volume->set(1, 0, 1, T(2));
    volume->set(0, 1, 1, T(2));
    volume->set(1, 1, 1, T(2));
    
    // create interpolation object
    LinearInterpolation<T> linear_interp3(volume);
    
    // test interior point
    linear_interp3.interp(1.0, 1.0, 1.0, result);
    CHECK_RESULT(1.5);

    // test boundary point
    linear_interp3.interp(1.0, 1.9, 0.0, result);
    CHECK_RESULT(1.0);

    // test boundary point
    linear_interp3.interp(1.0, 1.0, 2.0, result);
    CHECK_RESULT(1.5);

    // test some more interior points
    volume = typename Volume<T>::shared_ptr(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));

    // set some cell values
    volume->set(0,0,0, T(1));
    volume->set(0,0,1, T(2));
    volume->set(0,1,0, T(3));
    volume->set(0,1,1, T(4));
    volume->set(1,0,0, T(5));
    volume->set(1,0,1, T(6));
    volume->set(1,1,0, T(7));
    volume->set(1,1,1, T(8));

    LinearInterpolation<T> linear_interp4(volume);
    linear_interp4.interp(0.75, 1.15, 0.9, result);
    CHECK_RESULT(3.7);
}
コード例 #14
0
ファイル: TestLinearSplat.cpp プロジェクト: papaver/nkhive
void
TestLinearSplat<T>::test()
{
    USING_NK_NS
    USING_NKHIVE_NS

    // construct volume
    T default_val(0); 
    T splat_val(1);
    vec3d res(1.0);
    vec3d kernel_offset(0.5);

    // splat value at the origin.
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T> splatter(volume);
        splatter.splat(0, 0, 0, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 0.125);
        TOL_CHECK(volume->get(0, 0, -1), 0.125);
        TOL_CHECK(volume->get(0, -1, 0), 0.125);
        TOL_CHECK(volume->get(0, -1, -1), 0.125);
        TOL_CHECK(volume->get(-1, 0, 0), 0.125);
        TOL_CHECK(volume->get(-1, -1, 0), 0.125);
        TOL_CHECK(volume->get(-1, 0, -1), 0.125);
        TOL_CHECK(volume->get(-1, -1, -1), 0.125);
    }

    // splat value at the center of a voxel.
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T> splatter(volume);
        splatter.splat(0.5, 0.5, 0.5, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 1);
        TOL_CHECK(volume->get(0, 0, -1), 0);
        TOL_CHECK(volume->get(0, -1, 0), 0);
        TOL_CHECK(volume->get(0, -1, -1), 0);
        TOL_CHECK(volume->get(-1, 0, 0), 0);
        TOL_CHECK(volume->get(-1, -1, 0), 0);
        TOL_CHECK(volume->get(-1, 0, -1), 0);
        TOL_CHECK(volume->get(-1, -1, -1), 0);
        TOL_CHECK(volume->get(0, 0, 1), 0);
        TOL_CHECK(volume->get(0, 1, 0), 0);
        TOL_CHECK(volume->get(0, 1, 1), 0);
        TOL_CHECK(volume->get(1, 0, 0), 0);
        TOL_CHECK(volume->get(1, 1, 0), 0);
        TOL_CHECK(volume->get(1, 0, 1), 0);
        TOL_CHECK(volume->get(1, 1, 1), 0);
    }

    // splat value off center closer to origin
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T> splatter(volume);
        splatter.splat(0.25, 0.25, 0.25, splat_val);

        TOL_CHECK(volume->get(0, 0, 0),    0.421875);
        TOL_CHECK(volume->get(0, 0, -1),   0.140625);
        TOL_CHECK(volume->get(0, -1, 0),   0.140625);
        TOL_CHECK(volume->get(0, -1, -1),  0.046875);
        TOL_CHECK(volume->get(-1, 0, 0),   0.140625);
        TOL_CHECK(volume->get(-1, -1, 0),  0.046875);
        TOL_CHECK(volume->get(-1, 0, -1),  0.046875);
        TOL_CHECK(volume->get(-1, -1, -1), 0.015625);
    }

    // splat value off center further from origin
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T> splatter(volume);
        splatter.splat(0.75, 0.75, 0.75, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 0.421875);
        TOL_CHECK(volume->get(0, 0, 1), 0.140625);
        TOL_CHECK(volume->get(0, 1, 0), 0.140625);
        TOL_CHECK(volume->get(0, 1, 1), 0.046875);
        TOL_CHECK(volume->get(1, 0, 0), 0.140625);
        TOL_CHECK(volume->get(1, 1, 0), 0.046875);
        TOL_CHECK(volume->get(1, 0, 1), 0.046875);
        TOL_CHECK(volume->get(1, 1, 1), 0.015625);
    }

    // splat value at negative voxel
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T> splatter(volume);
        splatter.splat(-0.75, -0.75, -0.75, splat_val);

        TOL_CHECK(volume->get(-1, -1, -1), 0.421875);
        TOL_CHECK(volume->get(-1, -1, -2), 0.140625);
        TOL_CHECK(volume->get(-1, -2, -1), 0.140625);
        TOL_CHECK(volume->get(-1, -2, -2), 0.046875);
        TOL_CHECK(volume->get(-2, -1, -1), 0.140625);
        TOL_CHECK(volume->get(-2, -2, -1), 0.046875);
        TOL_CHECK(volume->get(-2, -1, -2), 0.046875);
        TOL_CHECK(volume->get(-2, -2, -2), 0.015625);
    }

    // splat value at negative voxel closer to zero
    {
        typename Volume<T>::shared_ptr volume(
                        new Volume<T>(2, 1, default_val, res, kernel_offset));
        LinearSplat<T> splatter(volume);
        splatter.splat(-0.25, -0.25, -0.25, splat_val);

        TOL_CHECK(volume->get(-1, -1, -1), 0.421875);
        TOL_CHECK(volume->get(-1, -1,  0), 0.140625);
        TOL_CHECK(volume->get(-1,  0, -1), 0.140625);
        TOL_CHECK(volume->get(-1,  0,  0), 0.046875);
        TOL_CHECK(volume->get( 0, -1, -1), 0.140625);
        TOL_CHECK(volume->get( 0,  0, -1), 0.046875);
        TOL_CHECK(volume->get( 0, -1,  0), 0.046875);
        TOL_CHECK(volume->get( 0,  0,  0), 0.015625);
    }
}
コード例 #15
0
void
TestNearestNeighborSplat<T>::test()
{
    USING_NKHIVE_NS

    // construct volume
    T default_val(0); 
    T splat_val(1);

    // splat value at the origin.
    {
        typename Volume<T>::shared_ptr volume(new Volume<T>(2, 1, default_val));
        NearestNeighborSplat<T> splatter(volume);
        splatter.splat(0, 0, 0, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 1);
        TOL_CHECK(volume->get(0, 0, -1), 0);
        TOL_CHECK(volume->get(0, -1, 0), 0);
        TOL_CHECK(volume->get(0, -1, -1), 0);
        TOL_CHECK(volume->get(-1, 0, 0), 0);
        TOL_CHECK(volume->get(-1, -1, 0), 0);
        TOL_CHECK(volume->get(-1, 0, -1), 0);
        TOL_CHECK(volume->get(-1, -1, -1), 0);
    }

    // splat value at center
    {
        typename Volume<T>::shared_ptr volume(new Volume<T>(2, 1, default_val));
        NearestNeighborSplat<T> splatter(volume);
        splatter.splat(0.5, 0.5, 0.5, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 1);
        TOL_CHECK(volume->get(0, 0, -1), 0);
        TOL_CHECK(volume->get(0, -1, 0), 0);
        TOL_CHECK(volume->get(0, -1, -1), 0);
        TOL_CHECK(volume->get(-1, 0, 0), 0);
        TOL_CHECK(volume->get(-1, -1, 0), 0);
        TOL_CHECK(volume->get(-1, 0, -1), 0);
        TOL_CHECK(volume->get(-1, -1, -1), 0);
    }

    // splat value off center
    {
        typename Volume<T>::shared_ptr volume(new Volume<T>(2, 1, default_val));
        NearestNeighborSplat<T> splatter(volume);
        splatter.splat(0.1, 0.5, 0.8, splat_val);

        TOL_CHECK(volume->get(0, 0, 0), 1);
        TOL_CHECK(volume->get(0, 0, -1), 0);
        TOL_CHECK(volume->get(0, -1, 0), 0);
        TOL_CHECK(volume->get(0, -1, -1), 0);
        TOL_CHECK(volume->get(-1, 0, 0), 0);
        TOL_CHECK(volume->get(-1, -1, 0), 0);
        TOL_CHECK(volume->get(-1, 0, -1), 0);
        TOL_CHECK(volume->get(-1, -1, -1), 0);
    }

    // splat negative values.
    {
        typename Volume<T>::shared_ptr volume(new Volume<T>(2, 1, default_val));
        NearestNeighborSplat<T> splatter(volume);
        splatter.splat(-0.2, -1.2, -0.8, splat_val);

        TOL_CHECK(volume->get(-1, -2, -1), 1);
        TOL_CHECK(volume->get(0, 0, -2), 0);
        TOL_CHECK(volume->get(0, -2, 0), 0);
        TOL_CHECK(volume->get(0, -2, -2), 0);
        TOL_CHECK(volume->get(-2, 0, 0), 0);
        TOL_CHECK(volume->get(-2, -2, 0), 0);
        TOL_CHECK(volume->get(-2, 0, -2), 0);
        TOL_CHECK(volume->get(-2, -2, -2), 0);
        TOL_CHECK(volume->get(0, 0, 0), 0);
        TOL_CHECK(volume->get(1, 0, 0), 0);
        TOL_CHECK(volume->get(0, 1, 0), 0);
        TOL_CHECK(volume->get(0, 0, 1), 0);
        TOL_CHECK(volume->get(1, 0, 1), 0);
        TOL_CHECK(volume->get(1, 1, 0), 0);
        TOL_CHECK(volume->get(1, 1, 1), 0);
    }
}