Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/vtkpost/meshpoint.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 meshpoint *
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 "meshpoint.h"
45
#include "preferences.h"
46
47
#include <vtkUnstructuredGrid.h>
48
#include <vtkSphereSource.h>
49
#include <vtkGlyph3D.h>
50
#include <vtkPolyDataMapper.h>
51
#include <vtkProperty.h>
52
#include <vtkActor.h>
53
#include <vtkClipPolyData.h>
54
#include <vtkPlane.h>
55
56
using namespace std;
57
58
MeshPoint::MeshPoint(QWidget *parent)
59
: QDialog(parent)
60
{
61
ui.setupUi(this);
62
63
setWindowTitle("Mesh points");
64
setWindowIcon(QIcon(":/icons/Mesh3D.png"));
65
}
66
67
MeshPoint::~MeshPoint()
68
{
69
}
70
71
void MeshPoint::draw(VtkPost* vtkPost, Preferences* preferences)
72
{
73
double length = vtkPost->GetLength();
74
int pointQuality = preferences->ui.pointQuality->value();
75
int pointSize = preferences->ui.pointSize->value();
76
bool useSurfaceGrid = preferences->ui.meshPointsSurface->isChecked();
77
bool useClip = preferences->ui.meshPointsClip->isChecked();
78
useClip |= vtkPost->GetClipAll();
79
QColor color = preferences->getMeshPointColor();
80
81
vtkSphereSource* sphere = vtkSphereSource::New();
82
sphere->SetRadius((double)pointSize * length / 2000.0);
83
sphere->SetThetaResolution(pointQuality);
84
sphere->SetPhiResolution(pointQuality);
85
86
vtkUnstructuredGrid* grid = NULL;
87
88
if(useSurfaceGrid) {
89
grid = vtkPost->GetSurfaceGrid();
90
} else {
91
grid = vtkPost->GetVolumeGrid();
92
}
93
94
if(!grid) return;
95
96
if(grid->GetNumberOfPoints() < 1) return;
97
98
vtkGlyph3D* glyph = vtkGlyph3D::New();
99
#if VTK_MAJOR_VERSION <= 5
100
glyph->SetInput(grid);
101
#else
102
glyph->SetInputData(grid);
103
#endif
104
glyph->SetSourceConnection(sphere->GetOutputPort());
105
106
vtkClipPolyData* clipper = vtkClipPolyData::New();
107
if(useClip) {
108
clipper->SetInputConnection(glyph->GetOutputPort());
109
clipper->SetClipFunction(vtkPost->GetClipPlane());
110
clipper->GenerateClippedOutputOn();
111
}
112
113
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
114
if(useClip) {
115
mapper->SetInputConnection(clipper->GetOutputPort());
116
} else {
117
mapper->SetInputConnection(glyph->GetOutputPort());
118
}
119
mapper->ScalarVisibilityOff();
120
121
vtkPost->GetMeshPointActor()->SetMapper(mapper);
122
vtkPost->GetMeshPointActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
123
124
mapper->Delete();
125
clipper->Delete();
126
glyph->Delete();
127
sphere->Delete();
128
}
129
130