Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/vtkpost/meshedge.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI meshedge *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
41
#include <QtGui>
42
#include <iostream>
43
#include "vtkpost.h"
44
#include "meshedge.h"
45
#include "preferences.h"
46
47
#include <vtkUnstructuredGrid.h>
48
#include <vtkExtractEdges.h>
49
#include <vtkDataSetMapper.h>
50
#include <vtkProperty.h>
51
#include <vtkActor.h>
52
#include <vtkTubeFilter.h>
53
#include <vtkClipPolyData.h>
54
#include <vtkPlane.h>
55
56
using namespace std;
57
58
MeshEdge::MeshEdge(QWidget *parent)
59
: QDialog(parent)
60
{
61
ui.setupUi(this);
62
63
setWindowTitle("Mesh edges");
64
setWindowIcon(QIcon(":/icons/Mesh3D.png"));
65
}
66
67
MeshEdge::~MeshEdge()
68
{
69
}
70
71
void MeshEdge::draw(VtkPost* vtkPost, Preferences* preferences)
72
{
73
bool useSurfaceGrid = preferences->ui.meshEdgesSurface->isChecked();
74
int lineWidth = preferences->ui.meshLineWidth->value();
75
bool useTubeFilter = preferences->ui.meshEdgeTubes->isChecked();
76
int quality = preferences->ui.meshEdgeTubeQuality->value();
77
int radius = preferences->ui.meshEdgeTubeRadius->value();
78
bool useClip = preferences->ui.meshEdgesClip->isChecked();
79
useClip |= vtkPost->GetClipAll();
80
QColor color = preferences->getMeshEdgeColor();
81
82
vtkUnstructuredGrid* grid = NULL;
83
84
if(useSurfaceGrid) {
85
grid = vtkPost->GetSurfaceGrid();
86
} else {
87
grid = vtkPost->GetVolumeGrid();
88
}
89
90
if(!grid) return;
91
92
if(grid->GetNumberOfCells() < 1) return;
93
94
vtkExtractEdges* edges = vtkExtractEdges::New();
95
#if VTK_MAJOR_VERSION <= 5
96
edges->SetInput(grid);
97
#else
98
edges->SetInputData(grid);
99
#endif
100
101
vtkTubeFilter* tubes = vtkTubeFilter::New();
102
if(useTubeFilter) {
103
double r = vtkPost->GetLength() * radius / 2000.0;
104
tubes->SetInputConnection(edges->GetOutputPort());
105
tubes->SetNumberOfSides(quality);
106
tubes->SetRadius(r);
107
}
108
109
vtkClipPolyData* clipper = vtkClipPolyData::New();
110
if(useClip) {
111
if(useTubeFilter) {
112
clipper->SetInputConnection(tubes->GetOutputPort());
113
} else {
114
clipper->SetInputConnection(edges->GetOutputPort());
115
}
116
clipper->SetClipFunction(vtkPost->GetClipPlane());
117
clipper->GenerateClippedOutputOn();
118
}
119
120
vtkDataSetMapper* mapper = vtkDataSetMapper::New();
121
if(useClip) {
122
mapper->SetInputConnection(clipper->GetOutputPort());
123
} else {
124
if(useTubeFilter) {
125
mapper->SetInputConnection(tubes->GetOutputPort());
126
} else {
127
mapper->SetInputConnection(edges->GetOutputPort());
128
}
129
}
130
mapper->ScalarVisibilityOff();
131
mapper->SetResolveCoincidentTopologyToPolygonOffset();
132
// mapper->ImmediateModeRenderingOn();
133
134
vtkPost->GetMeshEdgeActor()->GetProperty()->SetLineWidth(lineWidth);
135
vtkPost->GetMeshEdgeActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
136
vtkPost->GetMeshEdgeActor()->SetMapper(mapper);
137
138
mapper->Delete();
139
clipper->Delete();
140
tubes->Delete();
141
edges->Delete();
142
}
143
144