81 ,
labelMapper(vtkSmartPointer<vtkLabeledDataMapper>::New())
82 ,
labelActor(vtkSmartPointer<vtkActor2D>::New())
89 ,
pts(vtkSmartPointer<vtkPoints>::New())
90 ,
polydata(vtkSmartPointer<vtkPolyData>::New())
91 ,
mapper(vtkSmartPointer<vtkPolyDataMapper>::New())
92 ,
actor(vtkSmartPointer<vtkActor>::New())
93 ,
facePts(vtkSmartPointer<vtkPoints>::New())
95 ,
faceMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
96 ,
faceActor(vtkSmartPointer<vtkActor>::New())
97 ,
gbColors(vtkSmartPointer<vtkUnsignedCharArray>::New())
98 ,
gbPoints(vtkSmartPointer<vtkPoints>::New())
101 ,
gbMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
102 ,
gbActor(vtkSmartPointer<vtkActor>::New())
103 ,
pfMapper(vtkSmartPointer<vtkPolyDataMapper>::New())
104 ,
pfActor(vtkSmartPointer<vtkActor>::New())
105 ,
clipPlane(vtkSmartPointer<vtkPlane>::New())
106 ,
clipper(vtkSmartPointer<vtkClipPolyData>::New())
108 ,
clipMapper(vtkSmartPointer<vtkDataSetMapper>::New())
109 ,
clipActor(vtkSmartPointer<vtkActor>::New())
138 actor->SetVisibility(
false);
159 periodicityGlyphs->SetSourceConnection(vtkSmartPointer<vtkArrowSource>::New()->GetOutputPort());
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)
179 Eigen::Vector3d pShift(periodicBasis.col(cIdx));
180 periodicityPoints->InsertNextPoint(
mesh.xMin().data());
181 periodicityVectors->InsertNextTuple(pShift.data());
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.",
219 auto *periodicityBox =
220 controls::box(
"Periodicity vectors",
this,
"Show periodic translation vectors of the simulation cell.",
224 "Grain-boundary opacity: 0 is transparent, 10 is opaque.");
226 "Opacity of the clipped boundary surface: 0 is transparent, 10 is opaque.");
243 connect(
showMesh,SIGNAL(stateChanged(
int)),
this, SLOT(modify()));
247 connect(
showClipPlane,SIGNAL(stateChanged(
int)),
this, SLOT(modify()));
249 connect(
sliderClipPlane,SIGNAL(valueChanged(
int)),
this, SLOT(modify()));
250 connect(
showAxes,SIGNAL(stateChanged(
int)),
this, SLOT(modify()));
260 const Eigen::Matrix<double,3,1>
c(0.5*(
mesh.xMax()+
mesh.xMin()));
268 for (
const auto& node :
mesh.simplexFactory<0>().liveSimplices())
270 if(node.second->isBoundarySimplex())
272 pts->InsertNextPoint(node.second->P0(0),
279 sIDtoVtkPointsMap.emplace(node.second->xID(0),std::make_pair(pointID,Eigen::Matrix<double,3,1>::Zero()));
289 for (
const auto& edge :
mesh.simplexFactory<1>().liveSimplices())
291 if(edge.second->isBoundarySimplex())
299 vtkIdType connectivity[2];
300 connectivity[0] = iter0->second.first;
301 connectivity[1] = iter1->second.first;
302 polydata->InsertNextCell(VTK_LINE,2,connectivity);
307 throw std::runtime_error(
"child1 not found in sIDtoVtkPointsMap");
312 throw std::runtime_error(
"child0 not found in sIDtoVtkPointsMap");
326 actor->GetProperty()->SetLineWidth(0.5);
328 actor->GetProperty()->SetColor(0.5,0.5,0.5);
332 actor->GetProperty()->SetOpacity(0.5);
335 size_t faceConnectivityID=0;
336 for(
auto region :
mesh.regions())
338 for(
auto& face : region.second->faces())
340 for(
size_t k=0;
k<face.second->convexHull().size();++
k)
344 facePts->InsertNextPoint(face.second->convexHull()[
k]->P0(0),
345 face.second->convexHull()[
k]->P0(1),
346 face.second->convexHull()[
k]->P0(2));
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();
354 faceConnectivityID+=1;
361 faceActor->GetProperty()->SetLineWidth(5.0);
362 faceActor->GetProperty()->SetColor(0.0,0.0,0.0);
363 faceActor->GetProperty()->SetOpacity(0.5);
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())
375 grainColors.emplace(region.first,Eigen::Matrix<int,1,3>::Random()*255);
382 const double faceOffset(1.0e-1);
388 std::set<const Simplex<3,2>*> sameGrainPeriodicTriangles;
389 for(
const auto& region :
mesh.regions())
391 for(
const auto& entry : region.second->faces())
393 const auto& face=*entry.second;
394 const auto* partner=face.periodicFacePair.second;
395 if(face.isExternal() && partner && face.regionIDs==partner->regionIDs)
397 sameGrainPeriodicTriangles.insert(face.simplices().begin(),face.simplices().end());
401 for(
const auto& meshTriangle :
mesh.simplexFactory<2>().liveSimplices())
403 if(sameGrainPeriodicTriangles.count(meshTriangle.second.get()))
407 if(meshTriangle.second->isBoundarySimplex())
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));
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));
424 else if(meshTriangle.second->isRegionBoundarySimplex())
426 const Eigen::Matrix<double,3,3> vM(meshTriangle.second->vertexPositionMatrix());
428 const int regionID1=meshTriangle.second->parents().begin()->second->region->regionID;
429 const int regionID2=meshTriangle.second->parents().rbegin()->second->region->regionID;
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();
434 const Eigen::Matrix<int,1,3>& regionClr1(grainColors.at(regionID1));
435 const Eigen::Matrix<int,1,3>& regionClr2(grainColors.at(regionID2));
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);
446 gbColors->InsertNextTuple3(regionClr1(0),regionClr1(1),regionClr1(2));
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);
458 gbColors->InsertNextTuple3(regionClr2(0),regionClr2(1),regionClr2(2));
469 gbActor->GetProperty()->SetOpacity(0.2);
470 gbActor->GetProperty()->SetColor(0.0,0.5,0.5);
474 for(
const auto& region :
mesh.regions())
476 for(
const auto& face : region.second->faces())
478 if(face.second->periodicFacePair.second)
480 if(face.second->sID<face.second->periodicFacePair.second->sID)
482 periodicFaceSet.emplace(face.second.get(),face.second->periodicFacePair.second);
486 periodicFaceSet.emplace(face.second->periodicFacePair.second,face.second.get());
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());
501 for(
const auto& facePair : periodicFaceSet)
504 pfLut->GetColor(pfID, dclr);
505 std::cout<<
"dclr"<<std::endl;
506 std::cout<<dclr[0]<<
","<<dclr[1]<<
","<<dclr[2]<<std::endl;
508 vtkNew<vtkPolygon> polygon1;
509 for(
const auto& pt : facePair.first->convexHull())
511 pfPoints->InsertNextPoint(pt->P0.data());
512 polygon1->GetPointIds()->InsertNextId(pfPointID);
515 pfCells->InsertNextCell(polygon1);
516 pfColors->InsertNextTuple3(
int(dclr[0]*255.0),
int(dclr[1]*255.0),
int(dclr[2]*255.0));
518 vtkNew<vtkPolygon> polygon2;
519 for(
const auto& pt : facePair.second->convexHull())
521 pfPoints->InsertNextPoint(pt->P0.data());
522 polygon2->GetPointIds()->InsertNextId(pfPointID);
525 pfCells->InsertNextCell(polygon2);
526 pfColors->InsertNextTuple3(
int(dclr[0]*255.0),
int(dclr[1]*255.0),
int(dclr[2]*255.0));
531 std::cout<<
"periodicFaceSet.size()="<<periodicFaceSet.size()<<std::endl;
533 vtkSmartPointer<vtkPolyData> pfPolyData(vtkSmartPointer<vtkPolyData>::New());
536 pfPolyData->SetPoints(pfPoints);
537 pfPolyData->SetPolys(pfCells);
539 pfPolyData->GetCellData()->SetVectors(pfColors);
541 pfPolyData->Modified();
542 pfMapper->SetScalarModeToUseCellData();
549 pfActor->GetProperty()->SetOpacity(0.5);
562 vtkNew<vtkNamedColors> colors;
563 vtkColor3d axisColor=colors->GetColor3d(
"LightSkyBlue");
564 const int fontSize=12;
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);
582 cubeAxesActor->GetXAxesLinesProperty()->SetColor(axisColor.GetData());
585 cubeAxesActor->GetXAxesGridlinesProperty()->SetColor(axisColor.GetData());
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);
593 cubeAxesActor->GetYAxesLinesProperty()->SetColor(axisColor.GetData());
596 cubeAxesActor->GetYAxesGridlinesProperty()->SetColor(axisColor.GetData());
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);
605 cubeAxesActor->GetZAxesLinesProperty()->SetColor(axisColor.GetData());
608 cubeAxesActor->GetZAxesGridlinesProperty()->SetColor(axisColor.GetData());
622 vtkSmartPointer<vtkPoints> nodePoints(vtkSmartPointer<vtkPoints>::New());
623 vtkSmartPointer<vtkDoubleArray> nodeLabels(vtkSmartPointer<vtkDoubleArray>::New());
624 nodeLabels->SetNumberOfComponents(1);
625 nodeLabels->SetName(
"face IDs");
627 for(
const auto& region :
mesh.regions())
629 for(
const auto& face : region.second->faces())
631 if(face.second->isExternal())
633 nodePoints->InsertNextPoint(face.second->center().data());
634 nodeLabels->InsertNextTuple1(face.second->sID);
645 labelMapper->GetLabelTextProperty()->SetFontSize(20);
647 labelActor->GetProperty()->SetColor(0.0, 0.0, 0.0);