421 {
422
423
424
425
427
428
431
432
433
434
435
436
437
439
440
441#ifdef G4VTKDEBUG
442 G4cout <<
"=================================" <<
G4endl;
443 G4cout <<
"G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called> " <<
G4endl;
444 G4cout <<
"G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called> colour:" << colour.
GetRed() <<
" " << colour.
GetBlue() <<
" " << colour.
GetGreen() <<
G4endl;
445 G4cout <<
"G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called> alpha:" << colour.
GetAlpha() <<
G4endl;
446 G4cout <<
"G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called> lineWidth:" << lineWidth <<
G4endl;
447 G4cout <<
"G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) called> lineStyle:" << lineStyle <<
G4endl;
448#endif
449
450
451
452 std::size_t vhash = 0;
454
455 std::size_t phash = std::hash<G4Polyhedron>{}(polyhedron);
456
457 std::size_t hash = 0;
460
462
463 vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
464 vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
465 vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
466
468 int iVert = 0;
469 do {
474 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normals);
475
476 vtkSmartPointer<vtkIdList> poly = vtkSmartPointer<vtkIdList>::New();
477
478 for (int i = 0; i < nEdges; i++) {
479 points->InsertNextPoint(vertex[i].x(), vertex[i].y(), vertex[i].z());
480 poly->InsertNextId(iVert);
481 iVert++;
482 }
483 polys->InsertNextCell(poly);
484
485 } while (notLastFace);
486
487 polydata->SetPoints(points);
488 polydata->SetPolys(polys);
489
490 polyhedronDataMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkPoints>>(hash, points));
491 polyhedronPolyMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkCellArray>>(hash, polys));
494
495 vtkSmartPointer<vtkPoints> instancePosition = vtkSmartPointer<vtkPoints>::New();
496 vtkSmartPointer<vtkDoubleArray> instanceRotation = vtkSmartPointer<vtkDoubleArray>::New();
497 vtkSmartPointer<vtkDoubleArray> instanceColors = vtkSmartPointer<vtkDoubleArray>::New();
498 vtkSmartPointer<vtkPolyDataMapper> instanceMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
499 vtkSmartPointer<vtkActor> instanceActor = vtkSmartPointer<vtkActor>::New();
500 instanceColors->SetName("colors");
501
502 instanceColors->SetNumberOfComponents(4);
503 instanceRotation->SetNumberOfComponents(9);
504
505 vtkSmartPointer<vtkPolyData> instancePolyData = vtkSmartPointer<vtkPolyData>::New();
506 instancePolyData->SetPoints(instancePosition);
507 instancePolyData->GetPointData()->SetTensors(instanceRotation);
508 instancePolyData->GetPointData()->SetVectors(instanceColors);
509 instancePolyData->GetPointData()->SetScalars(instanceColors);
510
511 vtkSmartPointer<vtkCleanPolyData> filterClean = vtkSmartPointer<vtkCleanPolyData>::New();
512 filterClean->PointMergingOn();
513 filterClean->AddInputData(polydata);
514
515 vtkSmartPointer<vtkTriangleFilter> filterTriangle = vtkSmartPointer<vtkTriangleFilter>::New();
516 filterTriangle->SetInputConnection(filterClean->GetOutputPort());
517
518 vtkSmartPointer<vtkPolyDataNormals> filterNormals = vtkSmartPointer<vtkPolyDataNormals>::New();
519 filterNormals->SetFeatureAngle(45);
520 filterNormals->SetInputConnection(filterTriangle->GetOutputPort());
521
522 vtkSmartPointer<vtkFeatureEdges> filterEdge = vtkSmartPointer<vtkFeatureEdges>::New();
523 filterEdge->SetFeatureEdges(1);
524 filterEdge->SetManifoldEdges(0);
525 filterEdge->SetBoundaryEdges(0);
526 filterEdge->SetFeatureAngle(45);
527 filterEdge->SetInputConnection(filterTriangle->GetOutputPort());
528
529 vtkSmartPointer<vtkTensorGlyphColor> tensorGlyph = vtkSmartPointer<vtkTensorGlyphColor>::New();
530 tensorGlyph->SetInputData(instancePolyData);
531 tensorGlyph->SetSourceConnection(filterNormals->GetOutputPort());
532 tensorGlyph->ColorGlyphsOn();
533 tensorGlyph->ScalingOff();
534 tensorGlyph->ThreeGlyphsOff();
535 tensorGlyph->ExtractEigenvaluesOff();
536 tensorGlyph->SetColorModeToScalars();
537 tensorGlyph->Update();
538
539 instanceMapper->SetInputData(tensorGlyph->GetOutput());
540 instanceMapper->SetColorModeToDirectScalars();
541
542 instanceActor->SetMapper(instanceMapper);
543
544 instanceActor->SetVisibility(1);
545
547
548 }
549
551 }
552
554 instanceActor->GetProperty()->SetRepresentationToWireframe();
555 }
556
558 pVtkViewer->
renderer->AddActor(instanceActor);
559
560 instancePositionMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkPoints>>(hash, instancePosition));
561 instanceRotationMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkDoubleArray>>(hash, instanceRotation));
562 instanceColoursMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkDoubleArray>>(hash, instanceColors));
563 instancePolyDataMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkPolyData>>(hash,instancePolyData));
564 instanceActorMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkActor>>(hash, instanceActor));
565 instanceTensorGlyphMap.insert(std::pair<std::size_t, vtkSmartPointer<vtkTensorGlyphColor>>(hash, tensorGlyph));
566 }
567
569
570 double red = colour.
GetRed();
572 double blue = colour.
GetBlue();
574
576
580
582
584 fInvObjTrans.
yx(), fInvObjTrans.
yy(),fInvObjTrans.
yz(),
585 fInvObjTrans.
zx(), fInvObjTrans.
zy(),fInvObjTrans.
zz());
586
587}
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
std::map< std::size_t, vtkSmartPointer< vtkPolyData > > instancePolyDataMap
std::map< std::size_t, vtkSmartPointer< vtkDoubleArray > > instanceColoursMap
std::map< std::size_t, vtkSmartPointer< vtkDoubleArray > > instanceRotationMap
std::map< std::size_t, vtkSmartPointer< vtkPoints > > instancePositionMap
std::map< std::size_t, vtkSmartPointer< vtkPolyData > > polyhedronPolyDataMap
std::map< std::size_t, std::size_t > polyhedronPolyDataCountMap
std::map< std::size_t, vtkSmartPointer< vtkActor > > instanceActorMap
std::map< std::size_t, vtkSmartPointer< vtkCellArray > > polyhedronPolyMap
std::map< std::size_t, vtkSmartPointer< vtkTensorGlyphColor > > instanceTensorGlyphMap
std::map< std::size_t, vtkSmartPointer< vtkPoints > > polyhedronDataMap
G4int GetNoFacets() const
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=nullptr, G4Normal3D *normals=nullptr) const
void hash_combine(std::size_t)