Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
SimplicialMeshActor.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_SimplicialMeshActor_cpp_
10#define model_SimplicialMeshActor_cpp_
11
12
13#include <vtkVersion.h>
14#include <vtkSmartPointer.h>
15#include <vtkPolyData.h>
16#include <vtkPolyDataMapper.h>
17#include <vtkActor.h>
18#include <vtkProperty.h>
19#include <vtkRenderer.h>
20#include <vtkTriangle.h>
21#include <vtkCellData.h>
22#include <vtkPlane.h>
23#include <vtkClipPolyData.h>
24#include <vtkRenderWindowInteractor.h>
25#include <vtkRenderWindow.h>
26#include <vtkRenderer.h>
27#include <vtkActor.h>
28#include <vtkCamera.h>
29#include <vtkPolyDataMapper.h>
30#include <vtkDataSetMapper.h>
31#include <vtkPolyData.h>
32#include <vtkStripper.h>
33#include <vtkFeatureEdges.h>
34#include <vtkActor.h>
35#include <vtkProperty.h>
36#include <vtkPolyDataMapper.h>
37#include <vtkClipPolyData.h>
38#include <vtkPlane.h>
39#include <vtkSphereSource.h>
40#include <vtkPlane.h>
41#include <vtkCommand.h>
42#include <vtkImplicitPlaneWidget2.h>
43#include <vtkImplicitPlaneRepresentation.h>
44#include <vtkNamedColors.h>
45#include <vtkLookupTable.h>
46#include <vtkUnsignedCharArray.h>
47#include <vtkPointData.h>
48#include <vtkNamedColors.h>
49#include <vtkTextProperty.h>
50#include <random>
51#include <algorithm>
52#include <vtkPolygon.h>
53#include <vtkTriangleFilter.h>
54
55#include <TextFileParser.h>
56
57#include <SimplicialMeshActor.h>
58
59#include <DDqtControls.h>
60
61namespace model
62{
63
64 SimplicialMeshActor::SimplicialMeshActor(vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow_in,vtkRenderer* const renderer_in, const SimplicialMesh<3>& mesh_in) :
65 /* init */ mainLayout(new QGridLayout(this))
66 /* init */,showMesh(new QCheckBox(this))
67 /* init */,showExternalFaceIDs(new QCheckBox(this))
68// /* init */,showMeshLabel(new QLabel("show mesh"))
69 /* init */,showFaceBoundaries(new QCheckBox(this))
70/* init */,showPeriodicFaces(new QCheckBox(this))
71// /* init */,showFaceBoundariesLabel(new QLabel("show face edges"))
72// /* init */,showGrainColors(new QCheckBox(this))
73// /* init */,showGrainColorsLabel(new QLabel("show grain colors"))
74 /* init */,showRegionBoundaries(new QCheckBox(this))
75 /* init */,sliderRegionBoundaries(new QSlider(this))
76 /* init */,showClipPlane(new QCheckBox(this))
77 /* init */,sliderClipPlane(new QSlider(this))
78 /* init */,showAxes(new QCheckBox(this))
79 /* init */,showPeriodicityVectors(new QCheckBox(this))
80 /* init */,labelPolyData(vtkSmartPointer<vtkPolyData>::New())
81 /* init */,labelMapper(vtkSmartPointer<vtkLabeledDataMapper>::New())
82 /* init */,labelActor(vtkSmartPointer<vtkActor2D>::New())
84// /* init */,showRegionBoundariesLabel(new QLabel("show grain boundaries"))
85 /* init */,renderWindow(renderWindow_in)
86 /* init */,renderer(renderer_in)
87 /* init */,mesh(mesh_in)
88 /* init */,dispCorr(1.0)
89 /* init */,pts(vtkSmartPointer<vtkPoints>::New())
90 /* init */,polydata(vtkSmartPointer<vtkPolyData>::New())
91 /* init */,mapper(vtkSmartPointer<vtkPolyDataMapper>::New())
92 /* init */,actor(vtkSmartPointer<vtkActor>::New())
93 /* init */,facePts(vtkSmartPointer<vtkPoints>::New())
94 /* init */,facePolydata(vtkSmartPointer<vtkPolyData>::New())
95 /* init */,faceMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
96 /* init */,faceActor(vtkSmartPointer<vtkActor>::New())
97 /* init */,gbColors(vtkSmartPointer<vtkUnsignedCharArray>::New())
98 /* init */,gbPoints(vtkSmartPointer<vtkPoints>::New())
99 /* init */,gbTriangles(vtkSmartPointer<vtkCellArray>::New())
100 /* init */,gbTrianglePolyData(vtkSmartPointer<vtkPolyData>::New())
101 /* init */,gbMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
102 /* init */,gbActor(vtkSmartPointer<vtkActor>::New())
103 /* init */,pfMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
104 /* init */,pfActor(vtkSmartPointer<vtkActor>::New())
105 /* init */,clipPlane(vtkSmartPointer<vtkPlane>::New())
106 /* init */,clipper(vtkSmartPointer<vtkClipPolyData>::New())
107 /* init */,clippedPolyData(vtkSmartPointer<vtkPolyData>::New())
108 /* init */,clipMapper(vtkSmartPointer<vtkDataSetMapper>::New())
109 /* init */,clipActor(vtkSmartPointer<vtkActor>::New())
110 /* init */,cubeAxesActor(vtkSmartPointer<vtkCubeAxesActor>::New())
111 /* init */,periodicityPolydata(vtkSmartPointer<vtkPolyData>::New())
112 /* init */,periodicityGlyphs(vtkSmartPointer<vtkGlyph3D>::New())
113 /* init */,periodicityMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
114 /* init */,periodicityActor(vtkSmartPointer<vtkActor>::New())
115
116// /* init */,axes(vtkSmartPointer<vtkAxesActor>::New())
117// /* init */,axesWidget(vtkSmartPointer<vtkOrientationMarkerWidget>::New())
118// /* init */,myCallback(vtkSmartPointer<FieldActorCallback>::New())
119// /* init */,rep(vtkSmartPointer<vtkImplicitPlaneRepresentation>::New())
120// /* init */,planeWidget(vtkSmartPointer<vtkImplicitPlaneWidget2>::New())
121 {
122
123 showFaceBoundaries->setChecked(true);
124 showFaceBoundaries->setText("Face Edges");
125 faceActor->SetVisibility(true);
126
127 showPeriodicFaces->setChecked(false);
128 showPeriodicFaces->setText("Periodic Faces");
129 pfActor->SetVisibility(false);
130
131
132 showMesh->setChecked(false);
133 showExternalFaceIDs->setText("External face IDs");
134 showExternalFaceIDs->setChecked(false);
135 labelActor->SetVisibility(false);
136
137 showMesh->setText("Mesh");
138 actor->SetVisibility(false);
139// showGrainColors->setChecked(false);
140// showGrainColors->setText("grain colors");
141// gbMapper->SetScalarVisibility(false);
142 showRegionBoundaries->setChecked(false);
143 showRegionBoundaries->setText("Grain Boundaries");
144 sliderRegionBoundaries->setEnabled(false);
145 gbActor->SetVisibility(false);
146
147 showClipPlane->setText("Clip Plane");
148 showClipPlane->setChecked(false);
149 sliderClipPlane->setEnabled(false);
150 clipActor->SetVisibility(false);
151
152 showAxes->setText("Axes");
153 showAxes->setChecked(false);
154 showAxes->setEnabled(true);
155 cubeAxesActor->SetVisibility(false);
156
157 showPeriodicityVectors->setText("Periodicity Vectors");
159 periodicityGlyphs->SetSourceConnection(vtkSmartPointer<vtkArrowSource>::New()->GetOutputPort());
160 periodicityGlyphs->ScalingOn();
161 periodicityGlyphs->SetScaleModeToScaleByVector();
162 periodicityGlyphs->OrientOn();
163 periodicityGlyphs->ClampingOff();
164 periodicityGlyphs->SetVectorModeToUseVector();
165 periodicityGlyphs->SetIndexModeToOff();
166 periodicityMapper->SetInputConnection(periodicityGlyphs->GetOutputPort());
167 periodicityMapper->ScalarVisibilityOff();
169 periodicityActor->GetProperty()->SetColor(1.0, 1.0, 0.0); //(R,G,B)
170 periodicityActor->SetVisibility(false);
171 renderer->AddActor(periodicityActor);
172
173 vtkSmartPointer<vtkPoints> periodicityPoints = vtkSmartPointer<vtkPoints>::New();
174 vtkSmartPointer<vtkDoubleArray> periodicityVectors(vtkSmartPointer<vtkDoubleArray>::New());
175 periodicityVectors->SetNumberOfComponents(3);
176 const auto periodicBasis(mesh.periodicBasis());
177 for(int cIdx=0; cIdx<periodicBasis.cols();++cIdx)
178 {
179 Eigen::Vector3d pShift(periodicBasis.col(cIdx));
180 periodicityPoints->InsertNextPoint(mesh.xMin().data());
181 periodicityVectors->InsertNextTuple(pShift.data());
182 }
183 periodicityPolydata->SetPoints(periodicityPoints);
184 periodicityPolydata->GetPointData()->SetVectors(periodicityVectors);
185 periodicityPolydata->Modified();
186
187
188// axesWidget->SetOrientationMarker( axes );
190// std::cout<<"Interactor"<<std::endl;
191// renderWindow->SetInteractor(renderWindow->MakeRenderWindowInteractor());
193// std::cout<<bool(renderWindow->GetInteractor())<<std::endl;
194// axesWidget->SetInteractor( renderWindow->GetInteractor());
195// renderer->AddActor(axes);
196//
198// axesWidget->SetEnabled( true );
199// axesWidget->InteractiveOn();
200
201 auto *meshBox = controls::box("Mesh", this, "Show or hide the simulation mesh.", showMesh);
202 mainLayout->addWidget(meshBox, 0, 0);
203 auto *faceIDsBox = controls::box("Face IDs", this, "Show IDs of exterior mesh faces.", showExternalFaceIDs);
204 mainLayout->addWidget(faceIDsBox, 1, 0);
205 auto *facesBox =
206 controls::box("Face boundaries", this, "Show the boundary edges of mesh faces.", showFaceBoundaries);
207 mainLayout->addWidget(facesBox, 2, 0);
208 auto *periodicFacesBox = controls::box(
209 "Periodic faces", this, "Highlight faces paired by periodic boundary conditions.", showPeriodicFaces);
210 mainLayout->addWidget(periodicFacesBox, 3, 0);
211 auto *regionsBox = controls::box("Grain boundaries", this, "Show or hide internal region boundaries.",
213 mainLayout->addWidget(regionsBox, 4, 0);
214 auto *clippedBox =
215 controls::box("Clipped boundaries", this, "Show the clipped grain-boundary surface.", showClipPlane);
216 mainLayout->addWidget(clippedBox, 5, 0);
217 auto *axesBox = controls::box("Axes", this, "Show or hide the coordinate axes.", showAxes);
218 mainLayout->addWidget(axesBox, 6, 0);
219 auto *periodicityBox =
220 controls::box("Periodicity vectors", this, "Show periodic translation vectors of the simulation cell.",
222 mainLayout->addWidget(periodicityBox, 7, 0);
223 controls::field(controls::grid(regionsBox), 0, "Opacity", sliderRegionBoundaries,
224 "Grain-boundary opacity: 0 is transparent, 10 is opaque.");
225 controls::field(controls::grid(clippedBox), 0, "Opacity", sliderClipPlane,
226 "Opacity of the clipped boundary surface: 0 is transparent, 10 is opaque.");
227 mainLayout->setRowStretch(8, 1);
228 sliderRegionBoundaries->setOrientation(Qt::Horizontal);
229 sliderRegionBoundaries->setMinimum(0);
230 sliderRegionBoundaries->setMaximum(10);
231 sliderRegionBoundaries->setValue(5);
232 sliderClipPlane->setOrientation(Qt::Horizontal);
233 sliderClipPlane->setMinimum(0);
234 sliderClipPlane->setMaximum(10);
235 sliderClipPlane->setValue(5);
236
237
238 // mainLayout->addWidget(showRegionBoundariesLabel,3,1,1,1);
239 mainLayout->setColumnStretch(0, 1);
240
241 this->setLayout(mainLayout);
242
243 connect(showMesh,SIGNAL(stateChanged(int)), this, SLOT(modify()));
244 connect(showFaceBoundaries,SIGNAL(stateChanged(int)), this, SLOT(modify()));
245// connect(showGrainColors,SIGNAL(stateChanged(int)), this, SLOT(modify()));
246 connect(showRegionBoundaries,SIGNAL(stateChanged(int)), this, SLOT(modify()));
247 connect(showClipPlane,SIGNAL(stateChanged(int)), this, SLOT(modify()));
248 connect(sliderRegionBoundaries,SIGNAL(valueChanged(int)), this, SLOT(modify()));
249 connect(sliderClipPlane,SIGNAL(valueChanged(int)), this, SLOT(modify()));
250 connect(showAxes,SIGNAL(stateChanged(int)), this, SLOT(modify()));
251 connect(showPeriodicityVectors,SIGNAL(stateChanged(int)), this, SLOT(modify()));
252 connect(showExternalFaceIDs,SIGNAL(stateChanged(int)), this, SLOT(modify()));
253 connect(showPeriodicFaces,SIGNAL(stateChanged(int)), this, SLOT(modify()));
254
255
256
257
258
259
260 const Eigen::Matrix<double,3,1> c(0.5*(mesh.xMax()+mesh.xMin()));
261 clipPlane->SetOrigin(c(0),c(1),c(2));
262 clipPlane->SetNormal(1.0, 0.0, 0.0);
263
264
265 polydata->Allocate();
266
267 size_t pointID(0);
268 for (const auto& node : mesh.simplexFactory<0>().liveSimplices())
269 {
270 if(node.second->isBoundarySimplex())
271 {
272 pts->InsertNextPoint(node.second->P0(0),
273 node.second->P0(1),
274 node.second->P0(2));
275
276 // pts->InsertNextPoint(edge.second->child(1).P0(0),
277 // edge.second->child(1).P0(1),
278 // edge.second->child(1).P0(2));
279 sIDtoVtkPointsMap.emplace(node.second->xID(0),std::make_pair(pointID,Eigen::Matrix<double,3,1>::Zero()));
280 pointID++;
281 }
282 }
283
284 // std::cout<<"done inserting points"<<std::endl;
285
286
287
288 // size_t connectivityID=0;
289 for (const auto& edge : mesh.simplexFactory<1>().liveSimplices())
290 {
291 if(edge.second->isBoundarySimplex())
292 {
293 const auto iter0(sIDtoVtkPointsMap.find(edge.second->child(0).xID(0)));
294 if(iter0!=sIDtoVtkPointsMap.end())
295 {
296 const auto iter1(sIDtoVtkPointsMap.find(edge.second->child(1).xID(0)));
297 if(iter1!=sIDtoVtkPointsMap.end())
298 {
299 vtkIdType connectivity[2];
300 connectivity[0] = iter0->second.first;
301 connectivity[1] = iter1->second.first;
302 polydata->InsertNextCell(VTK_LINE,2,connectivity); //Connects the first and fourth point we inserted into a line
303
304 }
305 else
306 {
307 throw std::runtime_error("child1 not found in sIDtoVtkPointsMap");
308 }
309 }
310 else
311 {
312 throw std::runtime_error("child0 not found in sIDtoVtkPointsMap");
313 }
314 }
315 }
316
317
318
319
320 polydata->SetPoints(pts);
321
322 mapper->SetInputData(polydata);
323
324 actor->SetMapper ( mapper );
325 // actor->GetProperty()->SetLineWidth(0.1);
326 actor->GetProperty()->SetLineWidth(0.5);
327
328 actor->GetProperty()->SetColor(0.5,0.5,0.5); // Give some color to the mesh. (1,1,1) is white
329 // actor->GetProperty()->SetColor(0.0,0.0,0.0); // Give some color to the mesh. (1,1,1) is white
330
331 // actor->GetProperty()->SetOpacity(0.15); //Make the mesh have some transparency.
332 actor->GetProperty()->SetOpacity(0.5); //Make the mesh have some transparency.
333
334 facePolydata->Allocate();
335 size_t faceConnectivityID=0;
336 for(auto region : mesh.regions())
337 {// Sum number of external faces for final check
338 for(auto& face : region.second->faces())
339 {
340 for(size_t k=0;k<face.second->convexHull().size();++k)
341 {
342 // const int k1(k<convexHull().size()-1? k+1 : 0);
343
344 facePts->InsertNextPoint(face.second->convexHull()[k]->P0(0),
345 face.second->convexHull()[k]->P0(1),
346 face.second->convexHull()[k]->P0(2));
347
348 vtkIdType connectivity[2];
349 connectivity[0] = faceConnectivityID;
350 connectivity[1] = k<face.second->convexHull().size()-1? faceConnectivityID+1 : faceConnectivityID+1-face.second->convexHull().size();//connectivityID+1;
351
352 facePolydata->InsertNextCell(VTK_LINE,2,connectivity); //Connects the first and fourth point we inserted into a line
353
354 faceConnectivityID+=1;
355 }
356 }
357 }
358 facePolydata->SetPoints(facePts);
359 faceMapper->SetInputData(facePolydata);
360 faceActor->SetMapper ( faceMapper );
361 faceActor->GetProperty()->SetLineWidth(5.0);
362 faceActor->GetProperty()->SetColor(0.0,0.0,0.0); // Give some color to the mesh. (1,1,1) is white
363 faceActor->GetProperty()->SetOpacity(0.5); //Make the mesh have some transparency.
364
365
366
367 gbColors->SetNumberOfComponents(3);
368 gbColors->SetName("Colors");
369
370 std::mt19937 generator;
371 std::uniform_int_distribution<> distribution(0,255);
372 std::map<int,Eigen::Matrix<int,1,3>> grainColors;
373 for(const auto& region : mesh.regions())
374 {
375 grainColors.emplace(region.first,Eigen::Matrix<int,1,3>::Random()*255);
376 // grainColors.emplace(region.first,Eigen::Matrix<int,1,3>::Constant(clr)*255);
377 }
378
379
380// if(showGrainColors)
381// {
382 const double faceOffset(1.0e-1);
383 size_t triPtID=0;
384
385 // A same-grain periodic seam is not a physical grain surface.
386 // Keep free surfaces and cross-grain periodic interfaces, together
387 // with the internal interfaces handled below.
388 std::set<const Simplex<3,2>*> sameGrainPeriodicTriangles;
389 for(const auto& region : mesh.regions())
390 {
391 for(const auto& entry : region.second->faces())
392 {
393 const auto& face=*entry.second;
394 const auto* partner=face.periodicFacePair.second;
395 if(face.isExternal() && partner && face.regionIDs==partner->regionIDs)
396 {
397 sameGrainPeriodicTriangles.insert(face.simplices().begin(),face.simplices().end());
398 }
399 }
400 }
401 for(const auto& meshTriangle : mesh.simplexFactory<2>().liveSimplices())
402 {// Color triangles the grain they belong to. TO DO: triangles can be replaced by mesh faces
403 if(sameGrainPeriodicTriangles.count(meshTriangle.second.get()))
404 {
405 continue;
406 }
407 if(meshTriangle.second->isBoundarySimplex())
408 {
409 const Eigen::Matrix<double,3,3> vM(meshTriangle.second->vertexPositionMatrix());
410 const int regionID=meshTriangle.second->parents().begin()->second->region->regionID;
411 const Eigen::Matrix<int,1,3>& regionClr(grainColors.at(regionID));
412
413 gbPoints->InsertNextPoint ( vM(0,0), vM(1,0), vM(2,0) );
414 gbPoints->InsertNextPoint ( vM(0,1), vM(1,1), vM(2,1) );
415 gbPoints->InsertNextPoint ( vM(0,2), vM(1,2), vM(2,2) );
416 vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
417 triangle->GetPointIds()->SetId (0,triPtID+0);
418 triangle->GetPointIds()->SetId (1,triPtID+1);
419 triangle->GetPointIds()->SetId (2,triPtID+2);
420 gbColors->InsertNextTuple3(regionClr(0),regionClr(1),regionClr(2)); // use this to assig color to each vertex
421 gbTriangles->InsertNextCell ( triangle );
422 triPtID+=3;
423 }
424 else if(meshTriangle.second->isRegionBoundarySimplex())
425 {
426 const Eigen::Matrix<double,3,3> vM(meshTriangle.second->vertexPositionMatrix());
427
428 const int regionID1=meshTriangle.second->parents().begin()->second->region->regionID;
429 const int regionID2=meshTriangle.second->parents().rbegin()->second->region->regionID;
430
431 const Eigen::Matrix<double,3,1> n1=-meshTriangle.second->outNormal(regionID1).normalized();
432 const Eigen::Matrix<double,3,1> n2=-meshTriangle.second->outNormal(regionID2).normalized();
433
434 const Eigen::Matrix<int,1,3>& regionClr1(grainColors.at(regionID1));
435 const Eigen::Matrix<int,1,3>& regionClr2(grainColors.at(regionID2));
436
437 // Triangle on first grain
438 gbPoints->InsertNextPoint ( vM(0,0)+faceOffset*n1(0), vM(1,0)+faceOffset*n1(1), vM(2,0)+faceOffset*n1(2) );
439 gbPoints->InsertNextPoint ( vM(0,1)+faceOffset*n1(0), vM(1,1)+faceOffset*n1(1), vM(2,1)+faceOffset*n1(2) );
440 gbPoints->InsertNextPoint ( vM(0,2)+faceOffset*n1(0), vM(1,2)+faceOffset*n1(1), vM(2,2)+faceOffset*n1(2) );
441 vtkSmartPointer<vtkTriangle> triangle1 = vtkSmartPointer<vtkTriangle>::New();
442 triangle1->GetPointIds()->SetId (0,triPtID+0);
443 triangle1->GetPointIds()->SetId (1,triPtID+1);
444 triangle1->GetPointIds()->SetId (2,triPtID+2);
445 gbTriangles->InsertNextCell ( triangle1 );
446 gbColors->InsertNextTuple3(regionClr1(0),regionClr1(1),regionClr1(2)); // use this to assig color to each vertex
447 triPtID+=3;
448
449 // Triangle on second grain
450 gbPoints->InsertNextPoint ( vM(0,0)+faceOffset*n2(0), vM(1,0)+faceOffset*n2(1), vM(2,0)+faceOffset*n2(2) );
451 gbPoints->InsertNextPoint ( vM(0,1)+faceOffset*n2(0), vM(1,1)+faceOffset*n2(1), vM(2,1)+faceOffset*n2(2) );
452 gbPoints->InsertNextPoint ( vM(0,2)+faceOffset*n2(0), vM(1,2)+faceOffset*n2(1), vM(2,2)+faceOffset*n2(2) );
453 vtkSmartPointer<vtkTriangle> triangle2 = vtkSmartPointer<vtkTriangle>::New();
454 triangle2->GetPointIds()->SetId (0,triPtID+0);
455 triangle2->GetPointIds()->SetId (1,triPtID+1);
456 triangle2->GetPointIds()->SetId (2,triPtID+2);
457 gbTriangles->InsertNextCell ( triangle2 );
458 gbColors->InsertNextTuple3(regionClr2(0),regionClr2(1),regionClr2(2)); // use this to assig color to each vertex
459 triPtID+=3;
460 }
461 }
462// }
463
464 gbTrianglePolyData->SetPoints ( gbPoints );
465 gbTrianglePolyData->SetPolys ( gbTriangles );
466 gbTrianglePolyData->GetCellData()->SetScalars(gbColors);
467 gbMapper->SetInputData(gbTrianglePolyData);
468 gbActor->SetMapper(gbMapper);
469 gbActor->GetProperty()->SetOpacity(0.2);
470 gbActor->GetProperty()->SetColor(0.0,0.5,0.5);
471
472
473 std::set<std::pair<const Polyhedron<3,3-1>*,const Polyhedron<3,3-1>*>> periodicFaceSet;
474 for(const auto& region : mesh.regions())
475 {
476 for(const auto& face : region.second->faces())
477 {
478 if(face.second->periodicFacePair.second)
479 {// a periodic face exists
480 if(face.second->sID<face.second->periodicFacePair.second->sID)
481 {
482 periodicFaceSet.emplace(face.second.get(),face.second->periodicFacePair.second);
483 }
484 else
485 {
486 periodicFaceSet.emplace(face.second->periodicFacePair.second,face.second.get());
487 }
488 }
489 }
490 }
491
492 vtkSmartPointer<vtkUnsignedCharArray> pfColors(vtkSmartPointer<vtkUnsignedCharArray>::New());
493 vtkSmartPointer<vtkPoints> pfPoints(vtkSmartPointer<vtkPoints>::New());
494 vtkSmartPointer<vtkCellArray> pfCells(vtkSmartPointer<vtkCellArray>::New());
495 vtkSmartPointer<vtkLookupTable> pfLut(vtkSmartPointer<vtkLookupTable>::New());
496 pfLut->SetTableRange(0, periodicFaceSet.size());
497 pfLut->Build();
498
499 size_t pfPointID(0);
500 size_t pfID(0);
501 for(const auto& facePair : periodicFaceSet)
502 {
503 double dclr[3];
504 pfLut->GetColor(pfID, dclr);
505 std::cout<<"dclr"<<std::endl;
506 std::cout<<dclr[0]<<","<<dclr[1]<<","<<dclr[2]<<std::endl;
507
508 vtkNew<vtkPolygon> polygon1;
509 for(const auto& pt : facePair.first->convexHull())
510 {
511 pfPoints->InsertNextPoint(pt->P0.data());
512 polygon1->GetPointIds()->InsertNextId(pfPointID);
513 pfPointID++;
514 }
515 pfCells->InsertNextCell(polygon1);
516 pfColors->InsertNextTuple3(int(dclr[0]*255.0),int(dclr[1]*255.0),int(dclr[2]*255.0)); // use this to assig color to each vertex
517
518 vtkNew<vtkPolygon> polygon2;
519 for(const auto& pt : facePair.second->convexHull())
520 {
521 pfPoints->InsertNextPoint(pt->P0.data());
522 polygon2->GetPointIds()->InsertNextId(pfPointID);
523 pfPointID++;
524 }
525 pfCells->InsertNextCell(polygon2);
526 pfColors->InsertNextTuple3(int(dclr[0]*255.0),int(dclr[1]*255.0),int(dclr[2]*255.0)); // use this to assig color to each vertex
527
528 pfID++;
529 }
530
531 std::cout<<"periodicFaceSet.size()="<<periodicFaceSet.size()<<std::endl;
532
533 vtkSmartPointer<vtkPolyData> pfPolyData(vtkSmartPointer<vtkPolyData>::New());
534// vtkSmartPointer<vtkPolyDataMapper> pfMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
535
536 pfPolyData->SetPoints(pfPoints);
537 pfPolyData->SetPolys(pfCells);
538// pfPolyData->GetCellData()->SetScalars(pfColors);
539 pfPolyData->GetCellData()->SetVectors(pfColors);
540
541 pfPolyData->Modified();
542 pfMapper->SetScalarModeToUseCellData();
543// vtkNew<vtkTriangleFilter> pfFilter;
544// pfFilter->SetInputData(pfPolyData);
545// pfFilter->Update();
546 pfMapper->SetInputData(pfPolyData);
547// pfMapper->SetInputData(pfFilter->GetOutput());
548 pfActor->SetMapper(pfMapper);
549 pfActor->GetProperty()->SetOpacity(0.5);
550
551
552// THIS IS NOT SHOWING, MAYBE STORE MAPPER?
553
554
555 clipper->SetInputData(gbTrianglePolyData);
556 clipper->SetClipFunction(clipPlane);
557 clipper->SetValue(0);
558 clipper->Update();
559 clipMapper->SetInputConnection(clipper->GetOutputPort());
560 clipActor->SetMapper(clipMapper);
561
562 vtkNew<vtkNamedColors> colors;
563 vtkColor3d axisColor=colors->GetColor3d("LightSkyBlue");
564 const int fontSize=12;
565
566
567// cubeAxesActor->GetTextActor()->SetTextScaleModeToNone();
568// cubeAxesActor->SetUseTextActor3D(1);
569// cubeAxesActor->SetUse2DMode(true);
570 //cubeAxesActor->SetUseTextActor3D(false);
571 cubeAxesActor->SetBounds(polydata->GetBounds());
572 cubeAxesActor->SetCamera(renderer->GetActiveCamera());
573// cubeAxesActor->SetTitleOffset(20+fontSize);
574// cubeAxesActor->GetAxisLabelTextProperty()->SetFontSize(fontsize);
575// cubeAxesActor->GetAxisTitleTextProperty()->SetFontSize(fontsize);
576
577 cubeAxesActor->GetTitleTextProperty(0)->SetColor(axisColor.GetData());
578 cubeAxesActor->GetTitleTextProperty(0)->SetFontSize(fontSize);
579 cubeAxesActor->GetLabelTextProperty(0)->SetColor(axisColor.GetData());
580 cubeAxesActor->GetLabelTextProperty(0)->SetFontSize(fontSize);
581 cubeAxesActor->XAxisTickVisibilityOn();
582 cubeAxesActor->GetXAxesLinesProperty()->SetColor(axisColor.GetData());
583 cubeAxesActor->GetXAxesLinesProperty()->SetLineWidth(4);
584 cubeAxesActor->DrawXGridlinesOn();
585 cubeAxesActor->GetXAxesGridlinesProperty()->SetColor(axisColor.GetData());
586 cubeAxesActor->SetXTitle("X");
587
588 cubeAxesActor->GetTitleTextProperty(1)->SetColor(axisColor.GetData());
589 cubeAxesActor->GetTitleTextProperty(1)->SetFontSize(fontSize);
590 cubeAxesActor->GetLabelTextProperty(1)->SetColor(axisColor.GetData());
591 cubeAxesActor->GetLabelTextProperty(1)->SetFontSize(fontSize);
592 cubeAxesActor->YAxisTickVisibilityOn();
593 cubeAxesActor->GetYAxesLinesProperty()->SetColor(axisColor.GetData());
594 cubeAxesActor->GetYAxesLinesProperty()->SetLineWidth(4);
595 cubeAxesActor->DrawYGridlinesOn();
596 cubeAxesActor->GetYAxesGridlinesProperty()->SetColor(axisColor.GetData());
597 cubeAxesActor->SetYTitle("Y");
598
599
600 cubeAxesActor->GetTitleTextProperty(2)->SetColor(axisColor.GetData());
601 cubeAxesActor->GetTitleTextProperty(2)->SetFontSize(fontSize);
602 cubeAxesActor->GetLabelTextProperty(2)->SetColor(axisColor.GetData());
603 cubeAxesActor->GetLabelTextProperty(2)->SetFontSize(fontSize);
604 cubeAxesActor->ZAxisTickVisibilityOn();
605 cubeAxesActor->GetZAxesLinesProperty()->SetColor(axisColor.GetData());
606 cubeAxesActor->GetZAxesLinesProperty()->SetLineWidth(4);
607 cubeAxesActor->DrawZGridlinesOn();
608 cubeAxesActor->GetZAxesGridlinesProperty()->SetColor(axisColor.GetData());
609 cubeAxesActor->SetZTitle("Z");
610
611
612 // cubeAxesActor->SetGridLineLocation(cubeAxesActor->VTK_GRID_LINES_FURTHEST);
613
614// cubeAxesActor->XAxisMinorTickVisibilityOff();
615// cubeAxesActor->YAxisMinorTickVisibilityOff();
616// cubeAxesActor->ZAxisMinorTickVisibilityOff();
617// cubeAxesActor->SetColor(0.0,0.0,0.0,0.0);
618
619 cubeAxesActor->SetFlyModeToStaticTriad();
620
621
622 vtkSmartPointer<vtkPoints> nodePoints(vtkSmartPointer<vtkPoints>::New());
623 vtkSmartPointer<vtkDoubleArray> nodeLabels(vtkSmartPointer<vtkDoubleArray>::New());
624 nodeLabels->SetNumberOfComponents(1);
625 nodeLabels->SetName("face IDs");
626
627 for(const auto& region : mesh.regions())
628 {
629 for(const auto& face : region.second->faces())
630 {
631 if(face.second->isExternal())
632 {
633 nodePoints->InsertNextPoint(face.second->center().data());
634 nodeLabels->InsertNextTuple1(face.second->sID);
635 }
636 }
637 }
638
639 labelPolyData->SetPoints(nodePoints);
640 labelPolyData->GetPointData()->SetScalars(nodeLabels);
641 labelPolyData->Modified();
642 labelMapper->SetInputData(labelPolyData);
643 labelMapper->SetLabelModeToLabelScalars();
644 labelMapper->SetLabelFormat("%1.0f");
645 labelMapper->GetLabelTextProperty()->SetFontSize(20);
646 labelActor->SetMapper(labelMapper);
647 labelActor->GetProperty()->SetColor(0.0, 0.0, 0.0); //(R,G,B)
648
649
650 renderer->AddActor(gbActor);
651 renderer->AddActor(pfActor);
652 renderer->AddActor(clipActor); // enable to clip grain boundaries
653 renderer->AddActor(cubeAxesActor);
654 renderer->AddActor(labelActor);
655
656
657 // Update
658 // update(0/*,0,0.0,Eigen::Matrix<float,3,1>::Zero()*/);
659 modifyPts();
660
661 // Render
662 renderer->AddActor(actor);
663 renderer->AddActor(faceActor);
664 renderer->ResetCamera();
665
666
667
668// myCallback->plane=clipPlane;
669// rep->SetPlaceFactor(1.0); // This must be set prior to placing the widget
670// rep->PlaceWidget(clipActor->GetBounds());
671// rep->SetNormal(clipPlane->GetNormal());
672// // planeWidget->SetInteractor(renderWindow->GetInteractor());
673// planeWidget->AddObserver(vtkCommand::InteractionEvent,myCallback);
674// planeWidget->SetRepresentation(rep);
675// planeWidget->setEnabled(true );
676
677// modify();
678 }
679
680
681
682
683
684 void SimplicialMeshActor::modify()
685 {
686 actor->SetVisibility(showMesh->isChecked());
687 faceActor->SetVisibility(showFaceBoundaries->isChecked());
688 gbActor->SetVisibility(showRegionBoundaries->isChecked());
689 sliderRegionBoundaries->setEnabled(showRegionBoundaries->isChecked());
690 gbActor->GetProperty()->SetOpacity(sliderRegionBoundaries->value()/10.0);
691 clipActor->SetVisibility(showClipPlane->isChecked());
692 pfActor->SetVisibility(showPeriodicFaces->isChecked());
693
694 sliderClipPlane->setEnabled(showClipPlane->isChecked());
695 clipActor->GetProperty()->SetOpacity(sliderClipPlane->value()/10.0);
696
697 cubeAxesActor->SetVisibility(showAxes->isChecked());
698
699 periodicityActor->SetVisibility(showPeriodicityVectors->isChecked());
700
701 labelActor->SetVisibility(showExternalFaceIDs->isChecked());
702
703 renderWindow->Render();
704 }
705
706
707 /**************************************************************************/
709 {
710 for (const auto& node : mesh.simplexFactory<0>().liveSimplices())
711 {
712 if(node.second->isBoundarySimplex())
713 {
714
715 const auto nodeIter(sIDtoVtkPointsMap.find(node.second->xID(0)));
716 if(nodeIter!=sIDtoVtkPointsMap.end())
717 {
718 Eigen::Matrix<double,3,1> newP(node.second->P0+dispCorr*nodeIter->second.second);
719 pts->SetPoint(nodeIter->second.first,newP(0),newP(1),newP(2));
720
721 }
722 else
723 {
724 throw std::runtime_error("node not found in sIDtoVtkPointsMap");
725 }
726
727 }
728 }
729 pts->Modified();
730 }
731
732} // namespace model
733
734 // namespace model
735#endif
736
737
738
739
740
741
742
c
Definition int_R.m:15
QGridLayout * grid(QGroupBox *group)
QGroupBox * box(const QString &title, QWidget *parent, const QString &description, QCheckBox *toggle=nullptr)
void field(QGridLayout *layout, int row, const QString &title, QWidget *input, const QString &description)
vtkSmartPointer< vtkPolyData > facePolydata
vtkSmartPointer< vtkActor2D > labelActor
vtkSmartPointer< vtkPoints > gbPoints
const SimplicialMesh< 3 > & mesh
vtkSmartPointer< vtkLabeledDataMapper > labelMapper
SimplicialMeshActor(vtkSmartPointer< vtkGenericOpenGLRenderWindow >, vtkRenderer *const renderer_in, const SimplicialMesh< 3 > &mesh_in)
vtkSmartPointer< vtkActor > actor
vtkSmartPointer< vtkPoints > pts
vtkSmartPointer< vtkActor > periodicityActor
vtkSmartPointer< vtkPolyDataMapper > gbMapper
vtkSmartPointer< vtkPoints > facePts
vtkSmartPointer< vtkPolyDataMapper > periodicityMapper
std::map< size_t, std::pair< size_t, Eigen::Matrix< double, 3, 1 > > > sIDtoVtkPointsMap
vtkSmartPointer< vtkGenericOpenGLRenderWindow > renderWindow
vtkSmartPointer< vtkPolyData > polydata
vtkSmartPointer< vtkPolyDataMapper > faceMapper
vtkSmartPointer< vtkPolyData > labelPolyData
vtkSmartPointer< vtkGlyph3D > periodicityGlyphs
vtkSmartPointer< vtkCellArray > gbTriangles
vtkSmartPointer< vtkPolyDataMapper > pfMapper
vtkSmartPointer< vtkCubeAxesActor > cubeAxesActor
vtkSmartPointer< vtkClipPolyData > clipper
vtkSmartPointer< vtkActor > clipActor
vtkSmartPointer< vtkDataSetMapper > clipMapper
vtkSmartPointer< vtkPolyData > periodicityPolydata
vtkSmartPointer< vtkPolyData > gbTrianglePolyData
vtkSmartPointer< vtkPlane > clipPlane
vtkSmartPointer< vtkUnsignedCharArray > gbColors
vtkSmartPointer< vtkActor > pfActor
vtkSmartPointer< vtkPolyDataMapper > mapper
vtkSmartPointer< vtkActor > faceActor
vtkSmartPointer< vtkActor > gbActor
vtkSmartPointer< vtkPolyData > clippedPolyData
REAL ** triangle
Definition triangle.cpp:508
int k