OGS
VtkCompositePointToGlyphFilter.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4// ** INCLUDES **
6
7#include <vtkDataSetAlgorithm.h>
8#include <vtkGlyph3D.h>
9#include <vtkPointData.h>
10#include <vtkSphereSource.h>
11
13 vtkAlgorithm* inputAlgorithm)
14 : VtkCompositeFilter(inputAlgorithm), _glyphSource(nullptr)
15{
16 this->init();
17}
18
23
25{
26 this->_inputDataObjectType = VTK_DATA_SET;
27 this->_outputDataObjectType = VTK_POLY_DATA;
28
29 std::size_t nPoints = static_cast<vtkDataSetAlgorithm*>(_inputAlgorithm)
30 ->GetOutput()
31 ->GetPointData()
32 ->GetNumberOfTuples();
33 int phi(10 - static_cast<std::size_t>(nPoints / 2000.0));
34 int theta(phi);
35 if (phi < 4)
36 {
37 phi = 4;
38 theta =
39 4; // for theta 3 would be possible, too, but 4 looks much better
40 }
41
42 double default_radius(GetInitialRadius());
43 _glyphSource = vtkSphereSource::New();
44 _glyphSource->SetRadius(default_radius);
45 _glyphSource->SetPhiResolution(phi);
46 _glyphSource->SetThetaResolution(theta);
47 (*_algorithmUserProperties)["Radius"] = default_radius;
48
49 (*_algorithmUserProperties)["PhiResolution"] = phi;
50 (*_algorithmUserProperties)["ThetaResolution"] = theta;
51
52 vtkGlyph3D* glyphFilter = vtkGlyph3D::New();
53 glyphFilter
54 ->ScalingOn(); // KR important to scale glyphs with double precision
55 // (e.g. 0.1 of their size for small datasets)
56 // glyphFilter->SetScaleModeToScaleByScalar(); // KR can easily obscure
57 // view when scalar values have large differences (this is also the default
58 // scaling method)
59 glyphFilter->SetScaleModeToDataScalingOff(); // KR scaling is possible but
60 // scalar values are ignored
61 glyphFilter->SetScaleFactor(1.0);
62 glyphFilter->SetSourceConnection(_glyphSource->GetOutputPort());
63 glyphFilter->SetInputConnection(_inputAlgorithm->GetOutputPort());
64 //(*_algorithmUserProperties)["ScaleMode"] = 0;
65 //(*_algorithmUserProperties)["ScaleFactor"] = 1.0;
66 //(*_algorithmUserProperties)["ColorMode"] = glyphFilter->GetColorMode();
67 //(*_algorithmUserProperties)["VectorMode"] = glyphFilter->GetVectorMode();
68 //(*_algorithmUserProperties)["Orient"] = glyphFilter->GetOrient();
69
70 _outputAlgorithm = glyphFilter;
71}
72
74 QVariant value)
75{
77
78 if (name.compare("Radius") == 0)
79 {
80 _glyphSource->SetRadius(value.toDouble());
81 }
82 else if (name.compare("PhiResolution") == 0)
83 {
84 _glyphSource->SetPhiResolution(value.toInt());
85 }
86 else if (name.compare("ThetaResolution") == 0)
87 {
88 _glyphSource->SetThetaResolution(value.toInt());
89 }
90 else if (name.compare("ScaleMode") == 0)
91 {
92 static_cast<vtkGlyph3D*>(_outputAlgorithm)->SetScaleMode(value.toInt());
93 }
94 else if (name.compare("ScaleFactor") == 0)
95 {
96 static_cast<vtkGlyph3D*>(_outputAlgorithm)
97 ->SetScaleFactor(value.toDouble());
98 }
99 else if (name.compare("ColorMode") == 0)
100 {
101 static_cast<vtkGlyph3D*>(_outputAlgorithm)->SetColorMode(value.toInt());
102 }
103 else if (name.compare("VectorMode") == 0)
104 {
105 static_cast<vtkGlyph3D*>(_outputAlgorithm)
106 ->SetVectorMode(value.toInt());
107 }
108 else if (name.compare("Orient") == 0)
109 {
110 static_cast<vtkGlyph3D*>(_outputAlgorithm)->SetOrient(value.toBool());
111 }
112}
virtual void SetUserProperty(QString name, QVariant value)
Sets a user property. This should be implemented by subclasses.
vtkAlgorithm * _outputAlgorithm
VtkCompositeFilter(vtkAlgorithm *inputAlgorithm)
Constructor.
double GetInitialRadius() const
Calculates a 1/200th of the largest extension of the bounding box (this is used as default radius for...
vtkAlgorithm * _inputAlgorithm
void SetUserProperty(QString name, QVariant value) override
Sets a user property. This should be implemented by subclasses.
VtkCompositePointToGlyphFilter(vtkAlgorithm *inputAlgorithm)