0

我加载了一个网格(带颜色)并希望将其写入 .ply 文件并存储 rgb 信息。我目前有下面的代码,它使用vtkPLYWriter类,但这只是保存顶点而不是 RGB 信息。有没有内置的方法来做到这一点?

代码

vtkSmartPointer<vtkTransformPolyDataFilter> rotate_and_save_mesh(vtkSmartPointer<vtkPLYReader> mesh_reader, double rotation_angle, double x, double y, double z, 
        std::string& out_name, bool should_write = true){
    vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
    transform->RotateWXYZ(rotation_angle, x, y, z);
    vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();

    transformFilter->SetTransform(transform);
    transformFilter->SetInputConnection(mesh_reader->GetOutputPort());
    transformFilter->Update();

    if(should_write){
        vtkSmartPointer<vtkPLYWriter> writer = vtkSmartPointer<vtkPLYWriter>::New();
        writer->SetInputConnection(transformFilter->GetOutputPort());
        writer->SetFileName(out_name.c_str());

        writer->Write();
    }
    return transformFilter;
}
4

1 回答 1

1

这很尴尬。与 vtkPolyDataXMLWriter 和大多数其他 VTK 编写器不同,您必须指定

plyWriter->SetArrayName("Colors");

您的颜色数组的创建/命名如下:

vtkSmartPointer<vtkUnsignedCharArray> colors =
  vtkSmartPointer<vtkUnsignedCharArray>::New();
colors->SetNumberOfComponents(3);
colors->SetName("Colors");
于 2013-10-22T18:49:49.427 回答