Qt&Vtk-022-LabeledMesh
【摘要】
这个我也不知道是啥东西。
文章目录
1 官方示例展示2 代码搬运2.1 labeledmesh.h2.2 labeledmesh.cpp
3运行效果★ 源码 ★
1 官方示例展...
这个我也不知道是啥东西。
1 官方示例展示
哎呀,这英语才是第一生产力,英语不好,是真的很烦人那。今天我们么接着搬运代码,官方示例如下
2 代码搬运
2.1 labeledmesh.h
#ifndef LABELEDMESH_H
#define LABELEDMESH_H
#include <QWidget>
#include "QVTKOpenGLWidget.h" //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkSmartPointer.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkActor2D.h"
#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkIdFilter.h"
#include "vtkRenderer.h"
#include "vtkSelectVisiblePoints.h"
#include "vtkLabeledDataMapper.h"
#include "vtkCellCenters.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTextProperty.h"
static int xLength;
static int yLength;
static vtkSmartPointer<vtkSelectVisiblePoints> visPts;
static vtkSmartPointer<vtkSelectVisiblePoints> visCells;
static vtkSmartPointer<vtkPoints> pts;
static vtkSmartPointer<vtkRenderWindow>renwin;
namespace Ui {
class LabeledMesh;
}
class LabeledMesh : public QWidget
{
Q_OBJECT
public:
explicit LabeledMesh(QWidget *parent = 0);
~LabeledMesh();
void PlaceWindow(int xmin, int ymin);
void MoveWindow();
private:
Ui::LabeledMesh *ui;
};
#endif // LABELEDMESH_H
- 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
2.2 labeledmesh.cpp
#include "labeledmesh.h"
#include "ui_labeledmesh.h"
LabeledMesh::LabeledMesh(QWidget *parent) :
QWidget(parent),
ui(new Ui::LabeledMesh)
{
ui->setupUi(this);
int xmin = 200;
xLength = 100;
int xmax = xmin + xLength;
int ymin = 200;
yLength = 100;
int ymax = xmin+yLength;
pts = vtkSmartPointer<vtkPoints>::New();
pts->InsertPoint(0,xmin,ymin,0);
pts->InsertPoint(1,xmax,ymin,0);
pts->InsertPoint(2,xmax,ymax,0);
pts->InsertPoint(3,xmin,ymax,0);
vtkSmartPointer<vtkCellArray> rect = vtkSmartPointer<vtkCellArray>::New();
rect->InsertNextCell(5);
rect->InsertCellPoint(0);
rect->InsertCellPoint(1);
rect->InsertCellPoint(2);
rect->InsertCellPoint(3);
rect->InsertCellPoint(0);
vtkSmartPointer<vtkPolyData> selectRect = vtkSmartPointer<vtkPolyData>::New();
selectRect->SetPoints(pts);
selectRect->SetLines(rect);
vtkSmartPointer<vtkPolyDataMapper2D> rectMapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
rectMapper->SetInputData(selectRect);
vtkSmartPointer<vtkActor2D> rectActor = vtkSmartPointer<vtkActor2D>::New();
rectActor->SetMapper(rectMapper);
vtkSmartPointer<vtkSphereSource> sphere = vtkSmartPointer<vtkSphereSource>::New();
vtkSmartPointer<vtkPolyDataMapper> sphereMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
sphereMapper->SetInputConnection(sphere->GetOutputPort());
vtkSmartPointer<vtkActor> sphereActor = vtkSmartPointer<vtkActor>::New();
sphereActor->SetMapper(sphereMapper);
vtkSmartPointer<vtkIdFilter> ids = vtkSmartPointer<vtkIdFilter>::New();
ids->SetInputConnection(sphere->GetOutputPort());
ids->PointIdsOn();
ids->CellIdsOn();
ids->FieldDataOn();
vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
visPts = vtkSmartPointer<vtkSelectVisiblePoints>::New();
visPts->SetInputConnection(ids->GetOutputPort());
visPts->SetRenderer(ren1);
visPts->SelectionWindowOn();
visPts->SetSelection(xmin,xmin+xLength,ymin,ymin+yLength);
vtkSmartPointer<vtkLabeledDataMapper> ldm = vtkSmartPointer<vtkLabeledDataMapper>::New();
ldm->SetInputConnection(visPts->GetOutputPort());
ldm->SetLabelModeToLabelFieldData();
vtkSmartPointer<vtkActor2D> pointLabels = vtkSmartPointer<vtkActor2D>::New();
pointLabels->SetMapper(ldm);
vtkSmartPointer<vtkCellCenters> cc = vtkSmartPointer<vtkCellCenters>::New();
cc->SetInputConnection(ids->GetOutputPort());
visCells = vtkSmartPointer<vtkSelectVisiblePoints>::New();
visCells->SetInputConnection(cc->GetOutputPort());
visCells->SetRenderer(ren1);
visCells->SelectionWindowOn();
visCells->SetSelection(xmin,xmin+xLength,ymin,ymin+ yLength);
vtkSmartPointer<vtkLabeledDataMapper> cellmapper = vtkSmartPointer<vtkLabeledDataMapper>::New();
cellmapper->SetInputConnection(visCells->GetOutputPort());
cellmapper->SetLabelModeToLabelFieldData();
cellmapper->GetLabelTextProperty()->SetColor(0,1,0);
vtkSmartPointer<vtkActor2D> cellLabels = vtkSmartPointer<vtkActor2D>::New();
cellLabels->SetMapper(cellmapper);
ui->widget->GetRenderWindow()->AddRenderer(ren1);
ren1->AddActor(sphereActor);
ren1->AddActor2D(rectActor);
ren1->AddActor2D(pointLabels);
ren1->AddActor2D(cellLabels);
// MoveWindow();
// PlaceWindow(xmin,ymin);
}
LabeledMesh::~LabeledMesh()
{
delete ui;
}
void LabeledMesh::PlaceWindow(int xmin, int ymin)
{
int xmax = xmin + xLength;
int ymax = ymin + yLength;
visPts->SetSelection(xmin,xmax,ymin,ymax);
visCells->SetSelection(xmin,xmax,ymin,ymax);
pts->InsertPoint(0,xmin,ymin,0);
pts->InsertPoint(1,xmin,ymin,0);
pts->InsertPoint(2,xmin,ymin,0);
pts->InsertPoint(3,xmin,ymin,0);
pts->Modified();
renwin->Render();
}
void LabeledMesh::MoveWindow()
{
for(int y = 100;y<300;y+=25)
for(int x = 100;x<300;x+=25)
PlaceWindow(x,y);
}
- 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
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
3运行效果
在我这里,调用movewindow是有问题的,后面再解决吧,这几天撸代码有点多,现在有点撸不动的感觉。
★ 源码 ★
源码分享一时爽,一直分享一直爽, 链接如下:
文章来源: dreamlife.blog.csdn.net,作者:DreamLife.,版权归原作者所有,如需转载,请联系作者。
原文链接:dreamlife.blog.csdn.net/article/details/119633239
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)