Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 // 28 // 29 // John Allison 5th April 2001 30 // A template for a simplest possible graphics driver. 31 //?? Lines or sections marked like this require specialisation for your driver. 32 33 #include "G4VtkSceneHandler.hh" 34 35 #include "G4Box.hh" 36 #include "G4Circle.hh" 37 #include "G4LogicalVolume.hh" 38 #include "G4LogicalVolumeModel.hh" 39 #include "G4Material.hh" 40 #include "G4Mesh.hh" 41 #include "G4PhysicalVolumeModel.hh" 42 #include "G4Polyhedron.hh" 43 #include "G4Polyline.hh" 44 #include "G4PseudoScene.hh" 45 #include "G4Square.hh" 46 #include "G4SystemOfUnits.hh" 47 #include "G4Text.hh" 48 #include "G4UnitsTable.hh" 49 #include "G4VNestedParameterisation.hh" 50 #include "G4VPhysicalVolume.hh" 51 #include "G4VtkStore.hh" 52 #include "G4VtkVisContext.hh" 53 54 #include <vtkColorTransferFunction.h> 55 #include <vtkContourValues.h> 56 #include <vtkPiecewiseFunction.h> 57 #include <vtkVolumeProperty.h> 58 59 #include <cstdlib> 60 61 G4int G4VtkSceneHandler::fSceneIdCount = 0; 62 // Counter for XXX scene handlers. 63 64 G4VtkSceneHandler::G4VtkSceneHandler(G4VGraphicsSystem& system, const G4String& name) 65 : G4VSceneHandler(system, fSceneIdCount++, name), polyhedronPipelineType(G4String("tensor")) 66 {} 67 68 void G4VtkSceneHandler::AddPrimitive(const G4Polyline& polyline) 69 { 70 #ifdef G4VTKDEBUG 71 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Polyline&)" << G4endl; 72 #endif 73 auto vc = MakeDefaultVisContext(); 74 75 if (fReadyForTransients) 76 transientStore.AddPrimitive(polyline, vc); 77 else 78 store.AddPrimitive(polyline, vc); 79 } 80 81 void G4VtkSceneHandler::AddPrimitive(const G4Text& text) 82 { 83 #ifdef G4VTKDEBUG 84 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Text& text)" << G4endl; 85 #endif 86 87 auto vc = MakeDefaultVisContext(); 88 89 if (fReadyForTransients) 90 transientStore.AddPrimitive(text, vc); 91 else 92 store.AddPrimitive(text, vc); 93 } 94 95 void G4VtkSceneHandler::AddPrimitive(const G4Circle& circle) 96 { 97 #ifdef G4VTKDEBUG 98 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Circle& circle)" << G4endl; 99 #endif 100 101 auto vc = MakeDefaultVisContext(); 102 G4VSceneHandler::MarkerSizeType sizeType; 103 vc.fSize = GetMarkerSize(circle, sizeType); 104 105 if (fReadyForTransients) 106 transientStore.AddPrimitive(circle, vc); 107 else 108 store.AddPrimitive(circle, vc); 109 } 110 111 void G4VtkSceneHandler::AddPrimitive(const G4Square& square) 112 { 113 #ifdef G4VTKDEBUG 114 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Square& square)" << G4endl; 115 #endif 116 117 auto vc = MakeDefaultVisContext(); 118 G4VSceneHandler::MarkerSizeType sizeType; 119 vc.fSize = GetMarkerSize(square, sizeType); 120 121 if (fReadyForTransients) 122 transientStore.AddPrimitive(square, vc); 123 else 124 store.AddPrimitive(square, vc); 125 } 126 127 void G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) 128 { 129 #ifdef G4VTKDEBUG 130 G4cout << "G4VtkSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron)" << G4endl; 131 #endif 132 133 auto vc = MakeDefaultVisContext(); 134 auto visAtt = vc.fViewer->GetApplicableVisAttributes(polyhedron.GetVisAttributes()); 135 auto colour = visAtt->GetColour(); 136 137 vc.fDrawingStyle = GetDrawingStyle(visAtt); 138 vc.alpha = colour.GetAlpha(); 139 vc.red = colour.GetRed(); 140 vc.green = colour.GetGreen(); 141 vc.blue = colour.GetBlue(); 142 143 auto pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 144 if (pPVModel != nullptr) { 145 vc.fDepth = pPVModel->GetCurrentDepth(); 146 vc.fDescription = pPVModel->GetCurrentDescription(); 147 } 148 149 if (fReadyForTransients) { 150 if (polyhedronPipelineType == "tensor") 151 transientStore.AddPrimitiveTensorGlyph(polyhedron, vc); 152 else if (polyhedronPipelineType == "append") 153 transientStore.AddPrimitiveAppend(polyhedron, vc); 154 else if (polyhedronPipelineType == "bake") 155 transientStore.AddPrimitiveTransformBake(polyhedron, vc); 156 else if (polyhedronPipelineType == "separate") 157 transientStore.AddPrimitiveSeparate(polyhedron, vc); 158 } 159 else { 160 if (polyhedronPipelineType == "tensor") 161 store.AddPrimitiveTensorGlyph(polyhedron, vc); 162 else if (polyhedronPipelineType == "append") 163 store.AddPrimitiveAppend(polyhedron, vc); 164 else if (polyhedronPipelineType == "bake") 165 store.AddPrimitiveTransformBake(polyhedron, vc); 166 else if (polyhedronPipelineType == "separate") 167 store.AddPrimitiveSeparate(polyhedron, vc); 168 } 169 } 170 171 void G4VtkSceneHandler::Modified() 172 { 173 #ifdef G4VTKDEBUG 174 G4cout << "G4VtkSceneHandler::Modified()" << G4endl; 175 #endif 176 177 store.Modified(); 178 transientStore.Modified(); 179 } 180 181 void G4VtkSceneHandler::ClearStore() 182 { 183 #ifdef G4VTKDEBUG 184 G4cout << "G4VtkSceneHandler::ClearStore()" << G4endl; 185 #endif 186 store.Clear(); 187 } 188 189 void G4VtkSceneHandler::ClearTransientStore() 190 { 191 #ifdef G4VTKDEBUG 192 G4cout << "G4VtkSceneHandler::ClearTransientStore()" << G4endl; 193 #endif 194 transientStore.Clear(); 195 } 196 197 G4VtkVisContext G4VtkSceneHandler::MakeDefaultVisContext() 198 { 199 auto vc = G4VtkVisContext(dynamic_cast<G4VtkViewer*>(fpViewer), fpVisAttribs, fProcessing2D, 200 fObjectTransformation); 201 202 if (fpVisAttribs != nullptr) { 203 G4Colour c = fpVisAttribs->GetColour(); 204 vc.red = c.GetRed(); 205 vc.green = c.GetGreen(); 206 vc.blue = c.GetBlue(); 207 vc.alpha = c.GetAlpha(); 208 vc.fDrawingStyle = fpViewer->GetViewParameters().GetDrawingStyle(); 209 } 210 211 return vc; 212 } 213 214 void G4VtkSceneHandler::AddSolid(const G4Box& box) 215 { 216 G4VSceneHandler::AddSolid(box); 217 218 return; 219 220 const G4VModel* pv_model = GetModel(); 221 if (pv_model == nullptr) { 222 return; 223 } 224 225 auto pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 226 if (pPVModel == nullptr) { 227 return; 228 } 229 230 //-- debug information 231 #ifdef G4VTKDEBUG 232 G4VPhysicalVolume* pv = pPVModel->GetCurrentPV(); 233 G4LogicalVolume* lv = pv->GetLogicalVolume(); 234 G4cout << "name=" << box.GetName() << " volumeType=" << pv->VolumeType() 235 << " pvName=" << pv->GetName() << " lvName=" << lv->GetName() 236 << " multiplicity=" << pv->GetMultiplicity() << " isparametrised=" << pv->IsParameterised() 237 << " isreplicated=" << pv->IsReplicated() 238 << " parametrisation=" << pv->GetParameterisation() 239 << G4endl 240 241 G4Material* mat = pPVModel->GetCurrentMaterial(); 242 G4String name = mat->GetName(); 243 G4double dens = mat->GetDensity() / (g / cm3); 244 G4int copyNo = pPVModel->GetCurrentPV()->GetCopyNo(); 245 G4int depth = pPVModel->GetCurrentDepth(); 246 G4cout << " name : " << box.GetName() << G4endl; 247 G4cout << " copy no.: " << copyNo << G4endl; 248 G4cout << " depth : " << depth << G4endl; 249 G4cout << " density : " << dens << " [g/cm3]" << G4endl; 250 G4cout << " location: " << pPVModel->GetCurrentPV()->GetObjectTranslation() << G4endl; 251 G4cout << " Multiplicity : " << pPVModel->GetCurrentPV()->GetMultiplicity() << G4endl; 252 G4cout << " Is replicated? : " << pPVModel->GetCurrentPV()->IsReplicated() << G4endl; 253 G4cout << " Is parameterised? : " << pPVModel->GetCurrentPV()->IsParameterised() << G4endl; 254 G4cout << " top phys. vol. name : " << pPVModel->GetTopPhysicalVolume()->GetName() << G4endl; 255 #endif 256 } 257 258 void G4VtkSceneHandler::AddCompound(const G4Mesh& mesh) 259 { 260 #ifdef G4VTKDEBUG 261 G4cout << "G4VtkSceneHandler::AddCompound> mesh type " << mesh.GetMeshType() << " " 262 << fpViewer->GetViewParameters().GetSpecialMeshRenderingOption() << G4endl; 263 #endif 264 265 if(fpViewer->GetViewParameters().GetSpecialMeshRenderingOption() == G4ViewParameters::meshAsDefault) 266 { 267 auto vc = MakeDefaultVisContext(); 268 269 if (fReadyForTransients) 270 transientStore.AddCompound(mesh, vc); 271 else 272 store.AddCompound(mesh, vc); 273 } 274 else { 275 StandardSpecialMeshRendering(mesh); 276 } 277 } 278 279 void G4VtkSceneHandler::Print() {} 280 281 void G4VtkSceneHandler::SetPolyhedronPipeline(const G4String& type) 282 { 283 polyhedronPipelineType = type; 284 } 285