Beispiel #1
0
std::pair<int,int> TextureAtlas::index_to_units(int index) {
    if (super_atlas) {
        return index_to_units(offset_index(index));
    } else {
        return std::make_pair(index % unit_columns,
                              index / unit_columns);
    }
}
int GridSampleHolder::GetNeighbors(const Sample & query, const float radius, vector<const Sample *> & neighbors) const
{
    neighbors.clear();

    const int dimension = Dimension();

    vector<int> cell_index(dimension);
    if(! LocateCell(query, cell_index))
    {
        // outside the grid
        return 0;
    }

    const float radius_in_cells = (radius/_domain_spec.cell_size + 1);

    NBallSliceCounter counter(dimension, radius_in_cells*radius_in_cells);

    vector<int> offset_index(dimension);
    vector<int> current_index(dimension);
    vector<int> corrected_index(dimension);
    
    counter.Reset();
    do
    {
        counter.Get(offset_index);

        for(unsigned int i = 0; i < current_index.size(); i++)
        {
            current_index[i] = cell_index[i] + offset_index[i];

            if(_domain.Boundary() == Domain::BOUNDARY_TOROIDAL)
            {
                corrected_index[i] = (((current_index[i]%_cells.Size(i))+_cells.Size(i))%_cells.Size(i));
            }
            else
            {
                corrected_index[i] = current_index[i];
            }
        }

        Cell current_cell;
        if(_cells.Get(corrected_index, current_cell))
        {
            for(unsigned int j = 0; j < current_cell.samples.size(); j++)
            {
                neighbors.push_back(current_cell.samples[j]);
            }
        }
    }
    while(counter.Next());

    // done
    return 1;
}
Beispiel #3
0
std::tuple<float,float,float,float> TextureAtlas::index_to_coords(int index) {
    if (super_atlas) {
        return super_atlas->index_to_coords(offset_index(index));
    } else {
        std::pair<int,int> units = index_to_units(index);
        return std::make_tuple<float,float,float,float>
            (
             float((units.first    ) * unit_w) / float(gl_image.store_width),
             float((units.first + 1) * unit_w) / float(gl_image.store_width),
             float(gl_image.height - (units.second + 1) * unit_h) / float(gl_image.store_height),
             float(gl_image.height - (units.second    ) * unit_h) / float(gl_image.store_height)
             );
    }
}