27#include <vtkCellArray.h>
28#include <vtkCharArray.h>
29#include <vtkUnstructuredGrid.h>
30#include <vtkDataSetMapper.h>
31#include <vtkUnstructuredGridVolumeMapper.h>
32#include <vtkUnstructuredGridVolumeRayCastMapper.h>
33#include <vtkUnstructuredGridVolumeZSweepMapper.h>
34#include <vtkOpenGLProjectedTetrahedraMapper.h>
36#include <vtkColorTransferFunction.h>
37#include <vtkPiecewiseFunction.h>
38#include <vtkLookupTable.h>
39#include <vtkVolumeProperty.h>
45#include <vtkDataSetTriangleFilter.h>
46#include <vtkClipDataSet.h>
64 G4VVtkPipeline(nameIn,
"G4VtkUnstructuredPipeline", vcIn, false, vcIn.fViewer->renderer) {
70 pointColourValues->SetNumberOfComponents(4);
71 cellColourValues->SetNumberOfComponents(4);
75 pointColourIndices->SetNumberOfComponents(1);
76 cellColourIndices->SetNumberOfComponents(1);
79 colourLUT->DiscretizeOn();
82 unstructuredGrid->SetPoints(points);
83 unstructuredGrid->GetPointData()->SetScalars(pointColourValues);
84 unstructuredGrid->GetCellData()->SetScalars(cellColourValues);
89 clean->SetInputData(unstructuredGrid);
90 clean->ToleranceIsAbsoluteOff();
91 clean->SetTolerance(1e-6);
96 vtkNew<vtkPlane> plane;
97 clip->SetClipFunction(plane);
98 clip->SetInputData(unstructuredGrid);
102 tri->SetInputData(unstructuredGrid);
106 mapper->SetScalarModeToUseCellData();
107 mapper->SetColorModeToDirectScalars();
108 mapper->SetInputData(unstructuredGrid);
114 volumeMapper->SetScalarModeToUseCellData();
115 volumeMapper->SetInputConnection(tri->GetOutputPort());
119 volumeProp->SetColor(colourLUT);
123 actor->SetMapper(mapper);
124 actor->SetVisibility(1);
128 volume->SetMapper(volumeMapper);
130 volume->SetVisibility(1);
137void G4VtkUnstructuredGridPipeline::PseudoSceneForTetCells::AddSolid(
const G4VSolid& solid) {
141 const G4Tet& tet =
dynamic_cast<const G4Tet&
>(solid);
143 const auto& colour = pVisAtts->
GetColour();
148 G4int idx[4] = {-1, -1, -1, -1};
153 for (
G4int i = 0; i < 4; i++) {
157 fpPoints->InsertNextPoint(pts[i].x(), pts[i].y(), pts[i].z());
181 vtkNew<vtkTetra> tetra;
182 tetra->GetPointIds()->SetId(0, idx[0]);
183 tetra->GetPointIds()->SetId(1, idx[1]);
184 tetra->GetPointIds()->SetId(2, idx[2]);
185 tetra->GetPointIds()->SetId(3, idx[3]);
187 fpGrid->InsertNextCell(tetra->GetCellType(), tetra->GetPointIds());
190 unsigned short int iColour = 0;
194 double c[4] = {colour.GetRed(), colour.GetGreen(), colour.GetBlue(), colour.GetAlpha()};
201 fpCellColourValues->InsertNextTuple4(colour.GetRed(), colour.GetGreen(), colour.GetBlue(), colour.GetAlpha());
208 catch (
const std::bad_cast&) {
210 ed <<
"Called for a mesh that is not a tetrahedron mesh: " << solid.
GetName();
216void G4VtkUnstructuredGridPipeline::PseudoSceneForCubicalCells::AddSolid(
const G4Box& box) {
217 if (fpPVModel->GetCurrentDepth() == fDepth) {
219 const auto* pVisAtts = fpPVModel->GetCurrentLV()->GetVisAttributes();
220 const auto& colour = pVisAtts->GetColour();
233 vtkNew<vtkVoxel> voxel;
234 voxel->GetPointIds()->SetId(0, 8*iCell);
235 voxel->GetPointIds()->SetId(1, 8*iCell+1);
236 voxel->GetPointIds()->SetId(2, 8*iCell+2);
237 voxel->GetPointIds()->SetId(3, 8*iCell+3);
238 voxel->GetPointIds()->SetId(4, 8*iCell+4);
239 voxel->GetPointIds()->SetId(5, 8*iCell+5);
240 voxel->GetPointIds()->SetId(6, 8*iCell+6);
241 voxel->GetPointIds()->SetId(7, 8*iCell+7);
243 fpGrid->InsertNextCell(voxel->GetCellType(), voxel->GetPointIds());
245 double cols[] = {colour.GetRed(),
249 fpCellColourValues->InsertNextTuple(cols);
256 catch (
const std::bad_cast&) {
258 ed <<
"Called for a mesh that is not a cubical mesh: " << box.
GetName();
273 const G4bool useFullExtent =
true;
283 pointColourValues, cellColourValues,
284 pointColourIndices, cellColourIndices,
285 colourLUT, unstructuredGrid);
292 pointColourValues, cellColourValues,
293 pointColourIndices, cellColourIndices,
294 colourLUT, unstructuredGrid);
299 pointColourValues, cellColourValues,
300 pointColourIndices, cellColourIndices,
301 colourLUT, unstructuredGrid);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::size_t MakeHash(const G4ThreeVector &v)
G4double GetYHalfLength() const
G4double GetZHalfLength() const
G4double GetXHalfLength() const
const G4VisAttributes * GetVisAttributes() const
MeshType GetMeshType() const
G4VPhysicalVolume * GetContainerVolume() const
G4int GetMeshDepth() const
void SetCullingInvisible(G4bool)
void DescribeYourselfTo(G4VGraphicsScene &)
G4LogicalVolume * GetCurrentLV() const
G4int GetCurrentDepth() const
void GetVertices(G4ThreeVector &anchor, G4ThreeVector &p1, G4ThreeVector &p2, G4ThreeVector &p3) const
const G4Colour & GetColour() const
vtkSmartPointer< vtkDoubleArray > fpCellColourValues
vtkSmartPointer< vtkUnstructuredGrid > fpGrid
std::vector< G4ThreeVector > fpPointVector
vtkSmartPointer< vtkDiscretizableColorTransferFunction > fpColourLUT
vtkSmartPointer< vtkDoubleArray > fpCellColourIndices
G4PhysicalVolumeModel * fpPVModel
std::map< std::size_t, double > fpColourMap
std::map< std::size_t, std::size_t > fpPointMap
vtkSmartPointer< vtkPoints > fpPoints
void SetUnstructuredGridData(const G4Mesh &mesh)
G4VtkUnstructuredGridPipeline(G4String name, const G4VtkVisContext &vc)
vtkNew< vtkRenderer > renderer
const G4VtkViewer * fViewer