Exemplo n.º 1
0
struct buf *alloc_buffer(struct bufpool *pool, vfs_blkno_t blkno)
{
    struct buf *buf;

    // Try to get buffer from cache
    buf = lookup_buffer(pool, blkno);
    if (buf)
    {
        memset(buf->data, 0, pool->bufsize);
        return buf;
    }

    // Buffer not cached, get new buffer from buffer pool
    buf = get_new_buffer(pool);

    // Insert buffer into hash table
    buf->blkno = blkno;
    insert_into_hashtable(pool, buf);

    // Clear buffer
    memset(buf->data, 0, pool->bufsize);

    // Lock buffer
    buf->state = BUF_STATE_LOCKED;
    buf->locks++;

    return buf;
}
Exemplo n.º 2
0
void invalidate_buffer(struct bufpool *pool, vfs_blkno_t blkno)
{
    struct buf *buf;

    // If buffer is not in cache we are finished
    buf = lookup_buffer(pool, blkno);
    if (!buf) return;

    // Mark buffer as invalid and release it
    mark_buffer_invalid(buf);
    release_buffer(pool, buf);
}
Exemplo n.º 3
0
struct buf *get_buffer(struct bufpool *pool, vfs_blkno_t blkno)
{
    struct buf *buf;

    // Try to get buffer from cache
    buf = lookup_buffer(pool, blkno);
    if (buf) return buf;

    // Buffer not cached, get new buffer from buffer pool
    buf = get_new_buffer(pool);

    // Insert buffer into hash table
    buf->blkno = blkno;
    insert_into_hashtable(pool, buf);

    // Read block from device
    read_buffer(pool, buf);

    // Add lock on buffer
    buf->locks++;

    return buf;
}
Exemplo n.º 4
0
cv::viz::WMesh::WMesh(const Mesh &mesh)
{
    CV_Assert(mesh.cloud.rows == 1 && mesh.polygons.type() == CV_32SC1);

    vtkSmartPointer<vtkCloudMatSource> source = vtkSmartPointer<vtkCloudMatSource>::New();
    source->SetColorCloudNormalsTCoords(mesh.cloud, mesh.colors, mesh.normals, mesh.tcoords);
    source->Update();

    Mat lookup_buffer(1, (int)mesh.cloud.total(), CV_32SC1);
    int *lookup = lookup_buffer.ptr<int>();
    for(int y = 0, index = 0; y < mesh.cloud.rows; ++y)
    {
        int s_chs = mesh.cloud.channels();

        if (mesh.cloud.depth() == CV_32F)
        {
            const float* srow = mesh.cloud.ptr<float>(y);
            const float* send = srow + mesh.cloud.cols * s_chs;

            for (; srow != send; srow += s_chs, ++lookup)
                if (!isNan(srow[0]) && !isNan(srow[1]) && !isNan(srow[2]))
                    *lookup = index++;
        }

        if (mesh.cloud.depth() == CV_64F)
        {
            const double* srow = mesh.cloud.ptr<double>(y);
            const double* send = srow + mesh.cloud.cols * s_chs;

            for (; srow != send; srow += s_chs, ++lookup)
                if (!isNan(srow[0]) && !isNan(srow[1]) && !isNan(srow[2]))
                    *lookup = index++;
        }
    }
    lookup = lookup_buffer.ptr<int>();

    vtkSmartPointer<vtkPolyData> polydata = source->GetOutput();
    polydata->SetVerts(0);

    const int * polygons = mesh.polygons.ptr<int>();
    vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New();

    int idx = 0;
    size_t polygons_size = mesh.polygons.total();
    for (size_t i = 0; i < polygons_size; ++idx)
    {
        int n_points = polygons[i++];

        cell_array->InsertNextCell(n_points);
        for (int j = 0; j < n_points; ++j, ++idx)
            cell_array->InsertCellPoint(lookup[polygons[i++]]);
    }
    cell_array->GetData()->SetNumberOfValues(idx);
    cell_array->Squeeze();
    polydata->SetStrips(cell_array);

    vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetScalarModeToUsePointData();
#if VTK_MAJOR_VERSION < 8
    mapper->ImmediateModeRenderingOff();
#endif
    VtkUtils::SetInputData(mapper, polydata);

    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    //actor->SetNumberOfCloudPoints(std::max(1, polydata->GetNumberOfPoints() / 10));
    actor->GetProperty()->SetRepresentationToSurface();
    actor->GetProperty()->BackfaceCullingOff(); // Backface culling is off for higher efficiency
    actor->GetProperty()->SetInterpolationToFlat();
    actor->GetProperty()->EdgeVisibilityOff();
    actor->GetProperty()->ShadingOff();
    actor->SetMapper(mapper);

    if (!mesh.texture.empty())
    {
        vtkSmartPointer<vtkImageMatSource> image_source = vtkSmartPointer<vtkImageMatSource>::New();
        image_source->SetImage(mesh.texture);

        vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
        texture->SetInputConnection(image_source->GetOutputPort());
        actor->SetTexture(texture);
    }

    WidgetAccessor::setProp(*this, actor);
}