Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
QuadratureActor.cpp
Go to the documentation of this file.
1/* This file is part of MODEL, the Mechanics Of Defect Evolution Library.
2 *
3 * Copyright (C) 2011 by Giacomo Po <gpo@ucla.edu>.
4 *
5 * model is distributed without any warranty under the
6 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
7 */
8
9#ifndef model_QuadratureActor_cpp_
10#define model_QuadratureActor_cpp_
11
12#include <vtkLine.h>
13#include <vtkStructuredGrid.h>
14#include <vtkLookupTable.h>
15#include <vtkStructuredGridAppend.h>
16
17#include <QuadratureActor.h>
18
19#include <DDqtControls.h>
20
21namespace model
22{
23
24 QuadratureActor::QuadratureActor(vtkGenericOpenGLRenderWindow* const renWin,vtkRenderer* const ren,const Polycrystal<3>&,const DefectiveCrystalTraitsIO&) :
25 /* init */ renderWindow(renWin)
26 /* init */,renderer(ren)
27 /* init */,mainLayout(new QGridLayout(this))
28 /* init */,pkBox(new controls::GroupBox(tr("&PK forces")))
29 /* init */,pkScaleEdit(new QLineEdit("10000"))
30 /* init */,sfBox(new controls::GroupBox(tr("&stacking fault forces")))
31 /* init */,sfScaleEdit(new QLineEdit("10000"))
32 /* init */,ltBox(new controls::GroupBox(tr("&line tension forces")))
33 /* init */,ltScaleEdit(new QLineEdit("10000"))
34 /* init */,velocityBox(new controls::GroupBox(tr("&velocities")))
35 /* init */,velocityScaleEdit(new QLineEdit("100"))
36 /* init */,pkPolydata(vtkSmartPointer<vtkPolyData>::New())
37 /* init */,pkGlyphs(vtkSmartPointer<vtkGlyph3D>::New())
38 /* init */,pkMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
39 /* init */,pkActor(vtkSmartPointer<vtkActor>::New())
40 /* init */,sfPolydata(vtkSmartPointer<vtkPolyData>::New())
41 /* init */,sfGlyphs(vtkSmartPointer<vtkGlyph3D>::New())
42 /* init */,sfMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
43 /* init */,sfActor(vtkSmartPointer<vtkActor>::New())
44 /* init */,ltPolydata(vtkSmartPointer<vtkPolyData>::New())
45 /* init */,ltGlyphs(vtkSmartPointer<vtkGlyph3D>::New())
46 /* init */,ltMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
47 /* init */,ltActor(vtkSmartPointer<vtkActor>::New())
48 /* init */,velocityPolydata(vtkSmartPointer<vtkPolyData>::New())
49 /* init */,velocityGlyphs(vtkSmartPointer<vtkGlyph3D>::New())
50 /* init */,velocityMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
51 /* init */,velocityActor(vtkSmartPointer<vtkActor>::New())
52{
53
54 pkBox->setCheckable(true);
55 pkBox->setChecked(false);
56 pkActor->SetVisibility(false);
57 QGridLayout *pkLayout = new QGridLayout();
59 pkLayout, 0, "Scale", pkScaleEdit,
60 "Display multiplier for Peach-Koehler force arrows at quadrature points. Press Enter to apply.");
61 pkBox->setToolTip("Show or hide Peach-Koehler force arrows at quadrature points.");
62 pkBox->setLayout(pkLayout);
63
64 sfBox->setCheckable(true);
65 sfBox->setChecked(false);
66 sfActor->SetVisibility(false);
67 QGridLayout *sfLayout = new QGridLayout();
69 sfLayout, 0, "Scale", sfScaleEdit,
70 "Display multiplier for stacking-fault force arrows at quadrature points. Press Enter to apply.");
71 sfBox->setToolTip("Show or hide stacking-fault force arrows at quadrature points.");
72 sfBox->setLayout(sfLayout);
73
74 ltBox->setCheckable(true);
75 ltBox->setChecked(false);
76 ltActor->SetVisibility(false);
77 QGridLayout *ltLayout = new QGridLayout();
78 controls::field(ltLayout, 0, "Scale", ltScaleEdit,
79 "Display multiplier for line-tension force arrows at quadrature points. Press Enter to apply.");
80 ltBox->setToolTip("Show or hide line-tension force arrows at quadrature points.");
81 ltBox->setLayout(ltLayout);
82
83
84 velocityBox->setCheckable(true);
85 velocityBox->setChecked(false);
86 velocityActor->SetVisibility(false);
87 QGridLayout *velocityLayout = new QGridLayout();
88 controls::field(velocityLayout, 0, "Scale", velocityScaleEdit,
89 "Display multiplier for velocity arrows at quadrature points. Press Enter to apply.");
90 velocityBox->setToolTip("Show or hide velocity arrows at quadrature points.");
91 velocityBox->setLayout(velocityLayout);
92
93
94 mainLayout->addWidget(pkBox,0,0,1,1);
95 mainLayout->addWidget(sfBox,1,0,1,1);
96 mainLayout->addWidget(ltBox,2,0,1,1);
97 mainLayout->addWidget(velocityBox,3,0,1,1);
98 mainLayout->setRowStretch(4, 1);
99
100 this->setLayout(mainLayout);
101
102 connect(pkBox,SIGNAL(toggled(bool)), this, SLOT(modify()));
103 connect(pkScaleEdit,SIGNAL(returnPressed()), this, SLOT(modify()));
104 connect(sfBox,SIGNAL(toggled(bool)), this, SLOT(modify()));
105 connect(sfScaleEdit,SIGNAL(returnPressed()), this, SLOT(modify()));
106 connect(ltBox,SIGNAL(toggled(bool)), this, SLOT(modify()));
107 connect(ltScaleEdit,SIGNAL(returnPressed()), this, SLOT(modify()));
108 connect(velocityBox,SIGNAL(toggled(bool)), this, SLOT(modify()));
109 connect(velocityScaleEdit,SIGNAL(returnPressed()), this, SLOT(modify()));
110
111
112 pkGlyphs->SetInputData(pkPolydata);
113 pkGlyphs->SetSourceConnection(vtkSmartPointer<vtkArrowSource>::New()->GetOutputPort());
114 pkGlyphs->ScalingOn();
115 pkGlyphs->SetScaleModeToScaleByVector();
116 pkGlyphs->OrientOn();
117 pkGlyphs->ClampingOff();
118 pkGlyphs->SetVectorModeToUseVector();
119 pkGlyphs->SetIndexModeToOff();
120 pkMapper->SetInputConnection(pkGlyphs->GetOutputPort());
121 pkMapper->ScalarVisibilityOff();
122 pkActor->SetMapper(pkMapper);
123 pkActor->GetProperty()->SetColor(0.0, 0.0, 1.0); //(R,G,B)
124 renderer->AddActor(pkActor);
125
126 sfGlyphs->SetInputData(sfPolydata);
127 sfGlyphs->SetSourceConnection(vtkSmartPointer<vtkArrowSource>::New()->GetOutputPort());
128 sfGlyphs->ScalingOn();
129 sfGlyphs->SetScaleModeToScaleByVector();
130 sfGlyphs->OrientOn();
131 sfGlyphs->ClampingOff();
132 sfGlyphs->SetVectorModeToUseVector();
133 sfGlyphs->SetIndexModeToOff();
134 sfMapper->SetInputConnection(sfGlyphs->GetOutputPort());
135 sfMapper->ScalarVisibilityOff();
136 sfActor->SetMapper(sfMapper);
137 sfActor->GetProperty()->SetColor(0.0, 1.0, 0.0); //(R,G,B)
138 renderer->AddActor(sfActor);
139
140 ltGlyphs->SetInputData(ltPolydata);
141 ltGlyphs->SetSourceConnection(vtkSmartPointer<vtkArrowSource>::New()->GetOutputPort());
142 ltGlyphs->ScalingOn();
143 ltGlyphs->SetScaleModeToScaleByVector();
144 ltGlyphs->OrientOn();
145 ltGlyphs->ClampingOff();
146 ltGlyphs->SetVectorModeToUseVector();
147 ltGlyphs->SetIndexModeToOff();
148 ltMapper->SetInputConnection(ltGlyphs->GetOutputPort());
149 ltMapper->ScalarVisibilityOff();
150 ltActor->SetMapper(ltMapper);
151 ltActor->GetProperty()->SetColor(1.0, 0.0, 0.0); //(R,G,B)
152 renderer->AddActor(ltActor);
153
154
155
156 velocityGlyphs->SetInputData(velocityPolydata);
157 velocityGlyphs->SetSourceConnection(vtkSmartPointer<vtkArrowSource>::New()->GetOutputPort());
158 velocityGlyphs->ScalingOn();
159 velocityGlyphs->SetScaleModeToScaleByVector();
160 velocityGlyphs->OrientOn();
161 velocityGlyphs->ClampingOff();
162 velocityGlyphs->SetVectorModeToUseVector();
163 velocityGlyphs->SetIndexModeToOff();
164 velocityMapper->SetInputConnection(velocityGlyphs->GetOutputPort());
165 velocityMapper->ScalarVisibilityOff();
166 velocityActor->SetMapper(velocityMapper);
167 velocityActor->GetProperty()->SetColor(0.0, 1.0, 0.0); //(R,G,B)
168 renderer->AddActor(velocityActor);
169
170 }
171
173 {
174
175 std::cout<<"Updating QuadraturePoints..."<<std::flush;
176 const auto t0= std::chrono::system_clock::now();
177
178 vtkSmartPointer<vtkPoints> nodePoints = vtkSmartPointer<vtkPoints>::New();
179
180 vtkSmartPointer<vtkDoubleArray> pkForces(vtkSmartPointer<vtkDoubleArray>::New());
181 pkForces->SetNumberOfComponents(3);
182
183 vtkSmartPointer<vtkDoubleArray> sfForces(vtkSmartPointer<vtkDoubleArray>::New());
184 sfForces->SetNumberOfComponents(3);
185
186 vtkSmartPointer<vtkDoubleArray> ltForces(vtkSmartPointer<vtkDoubleArray>::New());
187 ltForces->SetNumberOfComponents(3);
188
189
190 vtkSmartPointer<vtkDoubleArray> velocities(vtkSmartPointer<vtkDoubleArray>::New());
191 velocities->SetNumberOfComponents(3);
192
193 for(const auto& qp : auxIO.quadraturePoints())
194 {
195 nodePoints->InsertNextPoint(qp.r.data());
196 pkForces->InsertNextTuple(qp.pkForce.data()); // arrow vector
197 sfForces->InsertNextTuple(qp.stackingFaultForce.data()); // arrow vector
198 ltForces->InsertNextTuple(qp.lineTensionForce.data()); // arrow vector
199 velocities->InsertNextTuple(qp.velocity.data()); // arrow vector
200 }
201
202 pkPolydata->SetPoints(nodePoints);
203 pkPolydata->GetPointData()->SetVectors(pkForces);
204 pkPolydata->Modified();
205
206 sfPolydata->SetPoints(nodePoints);
207 sfPolydata->GetPointData()->SetVectors(sfForces);
208 sfPolydata->Modified();
209
210 ltPolydata->SetPoints(nodePoints);
211 ltPolydata->GetPointData()->SetVectors(ltForces);
212 ltPolydata->Modified();
213
214
215 velocityPolydata->SetPoints(nodePoints);
216 velocityPolydata->GetPointData()->SetVectors(velocities);
217 velocityPolydata->Modified();
218
219 std::cout<<magentaColor<<" ["<<(std::chrono::duration<double>(std::chrono::system_clock::now()-t0)).count()<<" sec]"<<defaultColor<<std::endl;
220 }
221
222 void QuadratureActor::modify()
223 {
224 pkActor->SetVisibility(pkBox->isChecked());
225 const double pkScaling(std::atof(pkScaleEdit->text() .toStdString().c_str()));
226 pkGlyphs->SetScaleFactor(pkScaling);
227
228 sfActor->SetVisibility(sfBox->isChecked());
229 const double sfScaling(std::atof(sfScaleEdit->text() .toStdString().c_str()));
230 sfGlyphs->SetScaleFactor(sfScaling);
231
232 ltActor->SetVisibility(ltBox->isChecked());
233 const double ltScaling(std::atof(ltScaleEdit->text() .toStdString().c_str()));
234 ltGlyphs->SetScaleFactor(ltScaling);
235
236 velocityActor->SetVisibility(velocityBox->isChecked());
237 const double velocityScaling(std::atof(velocityScaleEdit->text() .toStdString().c_str()));
238 velocityGlyphs->SetScaleFactor(velocityScaling);
239
240
241 renderWindow->Render();
242 }
243
244
245} // namespace model
246#endif
void field(QGridLayout *layout, int row, const QString &title, QWidget *input, const QString &description)
size_t InstanceCount< Derived >::count
static std::string magentaColor
static std::string defaultColor
const std::vector< DislocationQuadraturePointIO< dim > > & quadraturePoints() const
void updateConfiguration(const DefectiveCrystalAuxIO< 3 > &auxIO)
QuadratureActor(vtkGenericOpenGLRenderWindow *const, vtkRenderer *const, const Polycrystal< 3 > &poly, const DefectiveCrystalTraitsIO &traitsIO)
REAL t0