VTK:按数组值为非结构化网格着色-有些面未正确着色?

时间:2018-08-15 17:20:53

标签: c++ vtk

我有以下代码,该代码应在具有点数据的XML VTK非结构化网格中读取并渲染由数组数据着色的网格。这应该是一个相对常见的任务,但是我终生无法在示例网站上找到一个很好的示例。

我遇到的问题是,尽管ParaView和VisIt都使用数据中正确的颜色渐变对面进行了着色,但我的面的其中一个面(网格的“背面”)是纯色的。我想不出发生这种情况的充分理由,但我怀疑我的映射器设置有问题。我从渲染此管道获得的输出在代码下方。

#include <vtkSmartPointer.h>
#include <vtkLookupTable.h>
#include <vtkColorSeries.h>
#include <vtkPointData.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLUnstructuredGridReader.h>
#include <vtkDataSetMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <iostream>

#define ARRAY   "Vec_0xb5ea60_1rho.0"

int main(int argc, char *argv[])
{
    if (argc < 2)
    {
        std::cout << "Usage: " << argv[0] << " grid.vtu" << std::endl;
        return EXIT_FAILURE;
    }

    vtkSmartPointer<vtkXMLUnstructuredGridReader> reader =
        vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
    reader->SetFileName(argv[1]);
    reader->Update();

    vtkSmartPointer<vtkLookupTable> lookup =
        vtkSmartPointer<vtkLookupTable>::New();
    vtkSmartPointer<vtkColorSeries> colors =
        vtkSmartPointer<vtkColorSeries>::New();
    colors->SetColorScheme(vtkColorSeries:: WILD_FLOWER);
    colors->BuildLookupTable(lookup, vtkColorSeries::ORDINAL);

    vtkSmartPointer<vtkDataSetMapper> mapper =
        vtkSmartPointer<vtkDataSetMapper>::New();
    mapper->SetInputConnection(reader->GetOutputPort());
    mapper->ScalarVisibilityOn();
    mapper->SetColorModeToMapScalars();
    mapper->SetLookupTable(lookup);
    mapper->SetScalarModeToUsePointFieldData();
    mapper->SelectColorArray(ARRAY);

    vtkPointData *pd = reader->GetOutput()->GetPointData();
    mapper->SetScalarRange(pd->GetArray(ARRAY)->GetRange());

    vtkSmartPointer<vtkActor> actor =
        vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);

    vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();

    vtkSmartPointer<vtkRenderWindow> window =
        vtkSmartPointer<vtkRenderWindow>::New();
    window->AddRenderer(renderer);

    vtkSmartPointer<vtkRenderWindowInteractor> interactor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow(window);

    renderer->AddActor(actor);
    window->SetSize(1280, 720);

    window->Render();
    interactor->Start();

    return EXIT_SUCCESS;
}

"Back" face of mesh is solid

0 个答案:

没有答案