Beispiel #1
0
	int find_level_and_fract( float width, float& fract) const
	{
		if( width <= 1.0f)
		{
			fract = 0;
			return 0;
		}

		float scale = 1.0f;

		for( int i = 0, ie = num_levels() - 1; i < ie; ++i)
		{
			float next_scale = iscales_[i+1];

			if( width >= scale && width < next_scale)
			{
				fract = ( width -  scale) / ( float) ( next_scale - scale);
				return i;
			}

			scale = next_scale;
		}

		fract = 0;
		return num_levels() - 1;
	}
Beispiel #2
0
    pixel_t operator()( const vector2_t& p, const vector2_t& du, const vector2_t& dv) const
	{
		RAMEN_ASSERT( has_top_sampler_);

		int y = math::fast_float_floor( p.y);

		if( y < src_area().min.y || y > src_area().max.y)
	        return pixel_t( 0, 0, 0, 0);

		int x = math::fast_float_floor( p.x);

		if( x < src_area().min.x || x > src_area().max.x)
	        return pixel_t( 0, 0, 0, 0);

		float max_width = std::max( Imath::Math<float>::fabs( du.x),  std::max( Imath::Math<float>::fabs( du.y),
							std::max( Imath::Math<float>::fabs( dv.x), Imath::Math<float>::fabs( dv.y))));

		float width = 2.0f * max_width;

		float fract;
		int level = find_level_and_fract( width, fract);
		image::pixel_t result = sample_level( level, p);

		if( fract != 0.0f)
		{
			RAMEN_ASSERT( level < num_levels() - 1);

			image::pixel_t tmp = sample_level( level + 1, p);
			result = lerp_pixels( tmp, result, fract);
		}

		return result;
	}
Beispiel #3
0
int main() {
    test1();
#if 0

    const size_t num_bits = 1024 * 1024;
    const size_t ptsize = size_in_bits<uint64_t>();
    auto nl = num_levels(num_bits, size_in_bits<uint64_t>() );
    auto ull = used_on_last_level(num_bits, size_in_bits<uint64_t>() );
    std::cout << "nl: " << nl << " " << ull << "\n";

    size_t nbalx = 0;
    for( size_t i = 0; i < nl; ++i ) {
        size_t nbl = num_bits_on_level(i, num_bits, size_in_bits<uint64_t>());
        nbalx += std::max(nbl, ptsize);
        std::cout << "level: " << i << " " << num_bits_on_level(i, num_bits, size_in_bits<uint64_t>()) << "\n";
    }

    std::cout << "all levels: " << nbalx << " " << num_bits_on_all_levels(num_bits, ptsize) << "\n";
#endif
    typedef ml_bitmap<1024 * 1024 * 128> bitmap_type;
    std::unique_ptr<bitmap_type> mlb{std::make_unique<bitmap_type>()};

//    for( size_t i = 0; i < mlb.size(); ++i ) {
//        auto a = mlb.alloc();
//        std::cout << "alloc: " << a << "\n";
//    }
    size_t n = 0;
    while( mlb->allocate() != size_t(-1)) {
        ++n;
    }

    std::cout << "n: " << n << "\n";
}
inline void
MGSelector::clear()
{
    if(m_pGrid) {
        for(size_t i = 0; i < num_levels(); ++i)
            clear<TElem>(i);
    }
}
inline size_t
MGSelector::num() const
{
    size_t n = 0;
    for(size_t i = 0; i < num_levels(); ++i)
        n += num<TElem>((int)i);
    return n;
}
Beispiel #6
0
    Image_buffer<T>* get_level(uint32_t index)
    {
		if (index < num_levels())
        {
            return image_buffers_[index];
        }
        else
        {
            return nullptr;
        }
    }
Beispiel #7
0
	pixel_t sample_level( int level, const vector2_t& p) const
	{
		RAMEN_ASSERT( level >= 0 && level < num_levels());

		if( level == 0)
			return top_sampler_( p);

		float s = scales_[level];
		vector2_t q( p.x * s, p.y * s);
		return samplers_[level - 1]( q);
	}
inline size_t
MGSelector::num(int level) const
{
    const int sInd = get_section_index<TElem>();
    if(level < (int)num_levels()) {
        if(sInd < 0)
            return section_container<TElem>(level).num_elements();
        else
            return section_container<TElem>(level).num_elements(sInd);
    }
    return 0;
}
//	geometric-object-collection
GridObjectCollection MGSelector::get_grid_objects() const
{
	uint numLevels = num_levels();
	GridObjectCollection goc(numLevels);
	
	for(uint i = 0; i < numLevels; ++i)
	{
		goc.add_level(	&m_levels[i]->m_vertices,
						&m_levels[i]->m_edges,
						&m_levels[i]->m_faces,
						&m_levels[i]->m_volumes);
	}
	
	return goc;
}
bool 
Sol_MultigridPressure3DBase::initialize_base_storage(int nx_val, int ny_val, int nz_val, double hx_val, double hy_val, double hz_val)
{
  // pre-validate
  if (!check_float(hx_val) || !check_float(hy_val) || !check_float(hz_val)) {
    printf("[ERROR] Sol_MultigridPressure3DBase::initialize_storage - garbage hx,hy,hz value %f %f %f\n", hx_val, hy_val, hz_val);
    return false;
  }

  // do allocation and initialization
  _num_levels = num_levels(nx_val, ny_val, nz_val);

  _h = new double[_num_levels];
  _dim = new int3[_num_levels];
  _h[0] = min3(hx_val, hy_val, hz_val);
  _fx = (_h[0] * _h[0]) / (hx_val * hx_val);
  _fy = (_h[0] * _h[0]) / (hy_val * hy_val);
  _fz = (_h[0] * _h[0]) / (hz_val * hz_val);
  _omega = optimal_omega(_fx, _fy, _fz);
  _dim[0].x = nx_val;
  _dim[0].y = ny_val;
  _dim[0].z = nz_val;

  int level;
  for (level=1; level < _num_levels; level++) {
    int this_nx = nx(level-1)/2;
    int this_ny = ny(level-1)/2;
    int this_nz = nz(level-1)/2;

    _h[level] = get_h(level-1)*2;
    _dim[level].x = this_nx;
    _dim[level].y = this_ny;
    _dim[level].z = this_nz;
  }

  return true;
}
	StringId64 get_level_id(const PackageResource* pr, uint32_t i)
	{
		CE_ASSERT(i < num_levels(pr), "Index out of bounds");
		StringId64* begin = (StringId64*) ((char*)pr + pr->levels_offset);
		return begin[i];
	}