• vtk数据集的整合与附加_vtkAppendFilter



    开发环境:

    1. Windows 11 家庭中文版
    2. Microsoft Visual Studio Community 2019
    3. VTK-9.3.0.rc0
    4. vtk-example
    5. 参考代码

    demo解决问题: 将一个或多个数据集附加到一个非结构网格中
    将一个或多个数据集追加到单个非结构化网格中

    vtkAppendFilter 是一个筛选器,用于将多个数据集之一追加到单个非结构化网格中。将提取并追加所有几何图形,但仅当所有数据集都具有可用的点属性时,才会提取和追加点属性(即标量、向量、法线、字段数据等)。(例如,如果一个数据集具有标量,而另一个数据集没有标量,则不会追加标量。

    注意数据结构vtkUnstructuredGrid的应用场景

    prj name: AppendFilter

    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    #include 
    
    namespace {
    
    /**
     * Convert points to glyphs.
     *
     * @param points - The points to glyph
     * @param scale - The scale, used to determine the size of the glyph
     * representing the point, expressed as a fraction of the largest side of the
     * bounding box surrounding the points. e.g. 0.05
     *
     * @return The actor.
     */
    vtkSmartPointer<vtkActor> PointToGlyph(vtkPoints* points, double const& scale);
    
    } // namespace
    
    int main(int, char*[])
    {
      // Create 5 points (vtkPolyData)
      vtkNew<vtkPointSource> pointSource;
      pointSource->SetNumberOfPoints(5);
      pointSource->Update();
    
      auto polydata = pointSource->GetOutput();
    
      std::cout << "There are " << polydata->GetNumberOfPoints()
                << " points in the polydata." << std::endl;
    
      // Create 2 points in a vtkUnstructuredGrid
    
      vtkNew<vtkPoints> points;
      points->InsertNextPoint(0, 0, 0);
      points->InsertNextPoint(0, 0, 1);
    
      vtkNew<vtkUnstructuredGrid> ug;
      ug->SetPoints(points);
    
      std::cout << "There are " << ug->GetNumberOfPoints()
                << " points in the unstructured grid." << std::endl;
    
      // Combine the two data sets
      vtkNew<vtkAppendFilter> appendFilter;
      appendFilter->AddInputData(polydata);
      appendFilter->AddInputData(ug);
      appendFilter->Update();
    
      auto combined = appendFilter->GetOutput();
      std::cout << "There are " << combined->GetNumberOfPoints()
                << " points combined." << std::endl;
    
      // Create a mapper and actor
      vtkNew<vtkNamedColors> colors;
    
      vtkNew<vtkDataSetMapper> mapper;
      mapper->SetInputConnection(appendFilter->GetOutputPort());
    
      vtkNew<vtkActor> actor;
      actor->SetMapper(mapper);
    
      // Map the points to spheres
      auto sphereActor = PointToGlyph(appendFilter->GetOutput()->GetPoints(), 0.05);
      sphereActor->GetProperty()->SetColor(colors->GetColor3d("Gold").GetData());
    
      // Create a renderer, render window, and interactor
      vtkNew<vtkRenderer> renderer;
      vtkNew<vtkRenderWindow> renderWindow;
      renderWindow->AddRenderer(renderer);
      vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
      renderWindowInteractor->SetRenderWindow(renderWindow);
    
      // Add the actor to the scene
      renderer->AddActor(actor);
      renderer->AddActor(sphereActor);
      renderer->SetBackground(colors->GetColor3d("RoyalBlue").GetData());
    
      // Render and interact
      renderWindow->SetWindowName("AppendFilter");
      renderWindow->Render();
      renderWindowInteractor->Start();
    
      return EXIT_SUCCESS;
    }
    
    namespace {
    
    vtkSmartPointer<vtkActor> PointToGlyph(vtkPoints* points, double const& scale)
    {
      auto bounds = points->GetBounds();
      double maxLen = 0;
      for (int i = 1; i < 3; ++i)
      {
        maxLen = std::max(bounds[i + 1] - bounds[i], maxLen);
      }
    
      vtkNew<vtkSphereSource> sphereSource;
      sphereSource->SetRadius(scale * maxLen);
    
      vtkNew<vtkPolyData> pd;
      pd->SetPoints(points);
    
      vtkNew<vtkGlyph3DMapper> mapper;
      mapper->SetInputData(pd);
      mapper->SetSourceConnection(sphereSource->GetOutputPort());
      mapper->ScalarVisibilityOff();
      mapper->ScalingOff();
    
      vtkNew<vtkActor> actor;
      actor->SetMapper(mapper);
    
      return actor;
    }
    
    } // namespace
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
  • 相关阅读:
    如何通过内网穿透实现公网远程连接Redis数据库
    「学习笔记」tarjan 求最近公共祖先
    自动化测试selenium(一)
    基于vue和nodejs的项目知识信息分享平台
    双软认证需要什么条件
    【Android Camera开发】Android Automotive介绍
    数据链路层和DNS之间的那些事~
    C++11的半同步半异步线程池
    Qt 5.12.12 静态编译(MinGW)
    负载均衡的在线OJ
  • 原文地址:https://blog.csdn.net/chengfenglee/article/details/134535220