#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include<vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleTrackballActor.h>
#include <vtkAutoInit.h>
#include <vtkLineSource.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)
using namespace std;
auto createball(float x, float y, float z, int r)
{
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(x, y, z);
sphereSource->SetRadius(r);
sphereSource->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
return actor;
}
auto createline(double x1, double y1, double z1, double x2, double y2, double z2)
{
vtkSmartPointer<vtkLineSource> lineSource =
vtkSmartPointer<vtkLineSource>::New();
lineSource->SetPoint1(x1, y1, z1);
lineSource->SetPoint2(x2, y2, z2);
lineSource->Update();
// Visualize
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(lineSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetLineWidth(4);
return actor;
}
int main()
{
//设置圆
auto actor11 = createball(-12.0, -10.0, 0.0, 2.0);
auto actor12 = createball(-15.0, -4.0, 0.0, 2.0);
auto actor13 = createball(-18.0, 3.0, 0.0, 2.0);
auto actor21 = createball(-6.0, -2.0, 0.0, 2.0);
auto actor22 = createball(-8.0, 10.0, 0.0, 2.0);
auto actor23 = createball(-10.0, 25.0, 0.0, 2.0);
auto actor31 = createball(0.0, 0.0, 0.0, 2.0);
auto actor32 = createball(0.0, 12.0, 0.0, 2.0);
auto actor33 = createball(0.0, 27.0, 0.0, 2.0);
auto actor41 = createball(5.0, -2.0, 0.0, 2.0);
auto actor42 = createball(7.0, 10.0, 0.0, 2.0);
auto actor43 = createball(9.0, 23.0, 0.0, 2.0);
auto actor51 = createball(10.0, -6.0, 0.0, 2.0);
auto actor52 = createball(12.0, 0.0, 0.0, 2.0);
auto actor53 = createball(14.0, 10.0, 0.0, 2.0);
auto actor_ori = createball(0.0, -18.0, 0.0, 2.0);
//设置线
auto line_actor10 = createline(-12.0, -10.0, 0.0, 0.0, -18.0, 0.0);
auto line_actor11 = createline(-12.0, -10.0, 0.0, -15.0, -4.0, 0.0);
auto line_actor12 = createline(-15.0, -4.0, 0.0, -18.0, 3.0, 0.0);
auto line_actor20 = createline(-6.0, -2.0, 0.0, 0.0, -18.0, 0.0);
auto line_actor21 = createline(-6.0, -2.0, 0.0, -8.0, 10.0, 0.0);
auto line_actor22 = createline(-8.0, 10.0, 0.0, -10.0, 25.0, 0.0);
auto line_actor30 = createline(0.0, 0.0, 0.0, 0.0, -18.0, 0.0);
auto line_actor31 = createline(0.0, 0.0, 0.0, 0.0, 12.0, 0.0);
auto line_actor32 = createline(0.0, 12.0, 0.0, 0.0, 27.0, 0.0);
auto line_actor40 = createline(5.0, -2.0, 0.0, 0.0, -18.0, 0.0);
auto line_actor41 = createline(5.0, -2.0, 0.0, 7.0, 10.0, 0.0);
auto line_actor42 = createline(7.0, 10.0, 0.0, 9.0, 23.0, 0.0);
auto line_actor50 = createline(10.0, -6.0, 0.0, 0.0, -18.0, 0.0);
auto line_actor51 = createline(10.0, -6.0, 0.0, 12.0, 0.0, 0.0);
auto line_actor52 = createline(12.0, 0.0, 0.0, 14.0, 10.0, 0.0);
// A renderer and render window
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// An interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actors to the scene
renderer->AddActor(actor11);
renderer->AddActor(actor12);
renderer->AddActor(actor13);
renderer->AddActor(actor21);
renderer->AddActor(actor22);
renderer->AddActor(actor23);
renderer->AddActor(actor31);
renderer->AddActor(actor32);
renderer->AddActor(actor33);
renderer->AddActor(actor41);
renderer->AddActor(actor42);
renderer->AddActor(actor43);
renderer->AddActor(actor51);
renderer->AddActor(actor52);
renderer->AddActor(actor53);
renderer->AddActor(actor_ori);
renderer->AddActor(line_actor10);
renderer->AddActor(line_actor11);
renderer->AddActor(line_actor12);
renderer->AddActor(line_actor20);
renderer->AddActor(line_actor21);
renderer->AddActor(line_actor22);
renderer->AddActor(line_actor30);
renderer->AddActor(line_actor31);
renderer->AddActor(line_actor32);
renderer->AddActor(line_actor40);
renderer->AddActor(line_actor41);
renderer->AddActor(line_actor42);
renderer->AddActor(line_actor50);
renderer->AddActor(line_actor51);
renderer->AddActor(line_actor52);
renderer->SetBackground(0, 0, 0); // Background color white
// Render an image (lights and cameras are created automatically)
renderWindow->Render();
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
renderWindowInteractor->SetInteractorStyle(style);
// Begin mouse interaction
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
vtk画个手的骨架
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 这周随便写写最近感受比较深的几件事,另外,我在公司内部换了个岗位~ 嘿~ 1 塞翁失马焉知非福 前段时间写了某种我...