我是 vtk 和 Qt 的新手。我在搅拌机中创建了一个具有 3 个红色面和 1 个绿色面的立方体,并导出为 cube.ply 以保留颜色信息:
ply
format ascii 1.0
comment Created by Blender 2.69 (sub 0) - www.blender.org, source file: ''
element vertex 24
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 6
property list uchar uint vertex_indices
end_header
1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000
1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000
-1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000
-1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000
1.000000 0.999999 1.000000 0.000000 -0.000000 1.000000
-1.000000 1.000000 1.000000 0.000000 -0.000000 1.000000
-1.000000 -1.000000 1.000000 0.000000 -0.000000 1.000000
0.999999 -1.000001 1.000000 0.000000 -0.000000 1.000000
1.000000 1.000000 -1.000000 1.000000 -0.000000 0.000000
1.000000 0.999999 1.000000 1.000000 -0.000000 0.000000
0.999999 -1.000001 1.000000 1.000000 -0.000000 0.000000
1.000000 -1.000000 -1.000000 1.000000 -0.000000 0.000000
1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000
0.999999 -1.000001 1.000000 -0.000000 -1.000000 -0.000000
-1.000000 -1.000000 1.000000 -0.000000 -1.000000 -0.000000
-1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000
-1.000000 -1.000000 -1.000000 -1.000000 0.000000 -0.000000
-1.000000 -1.000000 1.000000 -1.000000 0.000000 -0.000000
-1.000000 1.000000 1.000000 -1.000000 0.000000 -0.000000
-1.000000 1.000000 -1.000000 -1.000000 0.000000 -0.000000
1.000000 0.999999 1.000000 0.000000 1.000000 0.000000
1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000
-1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000
-1.000000 1.000000 1.000000 0.000000 1.000000 0.000000
4 0 1 2 3
4 4 5 6 7
4 8 9 10 11
4 12 13 14 15
4 16 17 18 19
4 20 21 22 23
我在 Qt Creator 中创建了一个 QVTK 小部件,我的代码将立方体绘制为灰色。以下是我的 mainwindow.cpp 文件(经过各种修改以显示颜色):
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QVTKInteractor.h"
#include <vtkSTLReader.h>
#include <vtkPLYReader.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkProperty.h>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renwin = vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<QVTKInteractor> interactor= vtkSmartPointer<QVTKInteractor>::New();
vtkSmartPointer<vtkPLYReader> reader = vtkSmartPointer<vtkPLYReader>::New();
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
reader->SetFileName("../vtk2/media/cube.ply");
reader->Update();
mapper->SetColorModeToMapScalars();
mapper->SetInputConnection(reader->GetOutputPort());
mapper->ScalarVisibilityOn();
actor->SetMapper(mapper);
renderer->AddActor(actor);
ui->qvtkWidget->SetRenderWindow(renwin);
ui->qvtkWidget->GetRenderWindow()->AddRenderer(renderer);
renderer->SetBackground(.3,.6,.3);
actor->GetProperty()->SetFrontfaceCulling(true);
QVTKInteractor* inter=ui->qvtkWidget->GetInteractor();
}
MainWindow::~MainWindow()
{
delete ui;
}
它不显示任何颜色。尝试了各种 VTK 示例后,我没有找到一个显示如何从导入的 3d 文件映射颜色的示例。我确定我错过了一段代码。
附带问题,多维数据集加载在 QVTKWidget 中看起来不对称。我想知道这是否是 QVTK 的问题。我附上一张图片..