【问题标题】:Plot an array of spheres in VTK在 VTK 中绘制一个球体数组
【发布时间】:2013-01-08 06:56:08
【问题描述】:

我想在 C++ 中使用 VTK 并在 3D 中绘制一个分子。我有一个代表原子位置的向量和另一个代表每个原子大小的向量。我怎么能做到这一点?我是否需要为每个原子创建一个新的 sphere_source。

vector< vector <double> > Positions;
vector< double > Sizes;

【问题讨论】:

  • 我会说结构会是更好的选择?说struct Atom { double position; double size;}; ??
  • 当然,我的问题更多是关于VTK部分,如何制作对象数组;是否需要制作大量的vtk spheres源或者VTK内部有机制。

标签: c++ vtk


【解决方案1】:

看看 vtkGlyph3D,这个例子: http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/Glyph3D 但是,您需要为每个原子 SIZE 提供单独的球源,所有具有相同大小的原子都可以使用相同的球源...

【讨论】:

  • 谢谢,我确实按照你的建议解决了。
  • 嗨,这很完美!现在,关于如何在每个字形上添加标签的一些想法?我正在尝试使用 vtkLabeledDataMapper,但不知道,
【解决方案2】:
void VTK_Plotter::Add_Point(vector<double> Position, double Size)
{

    Size = floor((log10(Size) + 0.2) * 100.0) / 100.0;

    vtkSmartPointer<vtkSphereSource> Current_Sphere_Source;
    // Different atomi number have different set of points
    vtkSmartPointer<vtkPoints> Current_Point_Group;
    // If the point has a size not in the list create a new sphere source with different size
    if (Table_Size_Source.find(Size) == Table_Size_Source.end()) {
        // Create new source
        Current_Sphere_Source = vtkSmartPointer<vtkSphereSource>::New();
        Current_Sphere_Source->SetRadius(Size);
        Table_Size_Source[Size] = Current_Sphere_Source;
        // Create new points
        Current_Point_Group = vtkSmartPointer<vtkPoints>::New();
        Table_Points_VTK[Size] = Current_Point_Group;
    }
    else
    {
        Current_Sphere_Source = Table_Size_Source[Size];
        Current_Point_Group = Table_Points_VTK[Size];
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-14
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2017-04-04
    相关资源
    最近更新 更多