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