纹理贴图

vtkNew<vtkPoints> points;
        points->SetNumberOfPoints(4);
        points->SetPoint(0, 0, 0, 0);
        points->SetPoint(1, 1, 0, 0);
        points->SetPoint(2, 1, 1, 0);
        points->SetPoint(3, 0, 1, 0);

        vtkNew<vtkCellArray> polygons;
        polygons->InsertNextCell(4);
        polygons->InsertCellPoint(0);
        polygons->InsertCellPoint(1);
        polygons->InsertCellPoint(2);
        polygons->InsertCellPoint(3);

        vtkNew<vtkFloatArray> texcoord;
        texcoord->SetNumberOfComponents(3);
        double t0[] = {0, 0, 0};
        double t1[] = {1, 0, 0};
        double t2[] = {1, 1, 0};
        double t3[] = {0, 1, 0};

        texcoord->InsertNextTuple(t0);
        texcoord->InsertNextTuple(t1);
        texcoord->InsertNextTuple(t2);
        texcoord->InsertNextTuple(t3);

        vtkNew<vtkPolyData> polydata;
        polydata->SetPoints(points.GetPointer());
        polydata->SetPolys(polygons.GetPointer());
        polydata->GetPointData()->SetTCoords(texcoord.GetPointer());

        vtkNew<vtkPolyDataMapper> mapper;
        mapper->SetInputData(polydata.GetPointer());

        vtkNew<vtkPNGReader> png;
        png->SetFileName("/home/cc/1.png");

        vtkNew<vtkTexture> texture;
        texture->SetInputConnection(png->GetOutputPort());

        vtkNew<vtkActor> actor;
        actor->RotateX(90);

        actor->SetMapper(mapper.GetPointer());
        actor->SetTexture(texture.GetPointer());

 

posted @ 2016-06-17 15:42  20118281131  阅读(374)  评论(0编辑  收藏  举报