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 // John Allison 17th June 2019 26 // John Allison 17th June 2019 27 27 28 #include "G4Qt3DSceneHandler.hh" 28 #include "G4Qt3DSceneHandler.hh" 29 29 30 #include "G4PhysicalVolumeModel.hh" 30 #include "G4PhysicalVolumeModel.hh" 31 #include "G4LogicalVolumeModel.hh" 31 #include "G4LogicalVolumeModel.hh" 32 #include "G4VPhysicalVolume.hh" 32 #include "G4VPhysicalVolume.hh" 33 #include "G4LogicalVolume.hh" 33 #include "G4LogicalVolume.hh" 34 #include "G4TransportationManager.hh" 34 #include "G4TransportationManager.hh" 35 #include "G4Box.hh" 35 #include "G4Box.hh" 36 #include "G4Polyline.hh" 36 #include "G4Polyline.hh" 37 #include "G4Polymarker.hh" 37 #include "G4Polymarker.hh" 38 #include "G4Text.hh" 38 #include "G4Text.hh" 39 #include "G4Circle.hh" 39 #include "G4Circle.hh" 40 #include "G4Square.hh" 40 #include "G4Square.hh" 41 #include "G4Polyhedron.hh" 41 #include "G4Polyhedron.hh" 42 #include "G4Scene.hh" 42 #include "G4Scene.hh" 43 #include "G4Threading.hh" 43 #include "G4Threading.hh" 44 #include "G4Mesh.hh" 44 #include "G4Mesh.hh" 45 #include "G4PseudoScene.hh" 45 #include "G4PseudoScene.hh" 46 #include "G4VisManager.hh" 46 #include "G4VisManager.hh" 47 47 48 #include "G4Qt3DViewer.hh" 48 #include "G4Qt3DViewer.hh" 49 #include "G4Qt3DUtils.hh" 49 #include "G4Qt3DUtils.hh" 50 #include "G4Qt3DQEntity.hh" 50 #include "G4Qt3DQEntity.hh" 51 51 52 #include <Qt3DCore> 52 #include <Qt3DCore> 53 #include <Qt3DExtras> 53 #include <Qt3DExtras> 54 #include <Qt3DRender> 54 #include <Qt3DRender> 55 55 56 #include <utility> 56 #include <utility> 57 57 58 #define G4warn G4cout 58 #define G4warn G4cout 59 59 60 // Qt3D seems to offer a choice of type - floa 60 // Qt3D seems to offer a choice of type - float or double. It would be nice 61 // to use double since it offers the prospect 61 // to use double since it offers the prospect of higher precision, hopefully 62 // avoiding some issues that we see at high zo 62 // avoiding some issues that we see at high zoom. But it currently gives the 63 // following warning: 63 // following warning: 64 // Qt5: "findBoundingVolumeComputeData: Positi 64 // Qt5: "findBoundingVolumeComputeData: Position attribute not 65 // suited for bounding volume computation", 65 // suited for bounding volume computation", 66 // Qt6: "Failed to build graphics pipeline: Ge 66 // Qt6: "Failed to build graphics pipeline: Geometry doesn't match expected layout 67 // An attribute type is not supported "vertexP 67 // An attribute type is not supported "vertexPosition" Qt3DCore::QAttribute::Double" 68 // so for now we use float. 68 // so for now we use float. 69 #define PRECISION float 69 #define PRECISION float 70 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 70 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 71 #define BASETYPE Qt3DRender::QAttribute::Float 71 #define BASETYPE Qt3DRender::QAttribute::Float 72 #else 72 #else 73 #define BASETYPE Qt3DCore::QAttribute::Float 73 #define BASETYPE Qt3DCore::QAttribute::Float 74 #endif 74 #endif 75 75 76 // Qt3D types move between namespaces between 76 // Qt3D types move between namespaces between 5 and 6 77 namespace G4Qt3DCompat 77 namespace G4Qt3DCompat 78 { 78 { 79 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 79 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 80 using Qt3DRender::QAttribute; 80 using Qt3DRender::QAttribute; 81 using Qt3DRender::QBuffer; 81 using Qt3DRender::QBuffer; 82 using Qt3DRender::QGeometry; 82 using Qt3DRender::QGeometry; 83 #else 83 #else 84 using Qt3DCore::QAttribute; 84 using Qt3DCore::QAttribute; 85 using Qt3DCore::QBuffer; 85 using Qt3DCore::QBuffer; 86 using Qt3DCore::QGeometry; 86 using Qt3DCore::QGeometry; 87 #endif 87 #endif 88 } 88 } 89 89 90 G4int G4Qt3DSceneHandler::fSceneIdCount = 0; 90 G4int G4Qt3DSceneHandler::fSceneIdCount = 0; 91 91 92 G4Qt3DSceneHandler::G4Qt3DSceneHandler 92 G4Qt3DSceneHandler::G4Qt3DSceneHandler 93 (G4VGraphicsSystem& system, const G4String& n 93 (G4VGraphicsSystem& system, const G4String& name) 94 : G4VSceneHandler(system, fSceneIdCount++, nam 94 : G4VSceneHandler(system, fSceneIdCount++, name) 95 ,fpQt3DScene(nullptr) << 96 ,fpTransientObjects(nullptr) << 97 ,fpPersistentObjects(nullptr) << 98 { 95 { 99 #ifdef G4QT3DDEBUG 96 #ifdef G4QT3DDEBUG 100 G4cout << "G4Qt3DSceneHandler::G4Qt3DSceneHa 97 G4cout << "G4Qt3DSceneHandler::G4Qt3DSceneHandler called" << G4endl; 101 #endif 98 #endif 102 fpQt3DScene = new Qt3DCore::QEntity; 99 fpQt3DScene = new Qt3DCore::QEntity; 103 fpQt3DScene->setObjectName("G4Qt3DSceneRoot" 100 fpQt3DScene->setObjectName("G4Qt3DSceneRoot"); 104 EstablishG4Qt3DQEntities(); 101 EstablishG4Qt3DQEntities(); 105 } 102 } 106 103 107 G4Qt3DSceneHandler::~G4Qt3DSceneHandler() 104 G4Qt3DSceneHandler::~G4Qt3DSceneHandler() 108 { 105 { 109 if (fpQt3DScene) { << 106 // Doesn't like this - it gives BAD_ACCESS in delete_entity_recursively. 110 G4Qt3DUtils::delete_components_and_childre << 107 // Curiously the delete traceback shows three calls to this recursively: 111 delete fpQt3DScene; << 108 /*#1 0x0000000100411906 in (anonymous namespace)::delete_entity_recursively(Qt3DCore::QNode*) at /Users/johna/Geant4/geant4-dev/source/visualization/Qt3D/src/G4Qt3DSceneHandler.cc:60 112 } << 109 #2 0x0000000100411840 in G4Qt3DSceneHandler::~G4Qt3DSceneHandler() at /Users/johna/Geant4/geant4-dev/source/visualization/Qt3D/src/G4Qt3DSceneHandler.cc:169 >> 110 #3 0x0000000100411fc5 in G4Qt3DSceneHandler::~G4Qt3DSceneHandler() at /Users/johna/Geant4/geant4-dev/source/visualization/Qt3D/src/G4Qt3DSceneHandler.cc:168 >> 111 #4 0x0000000100411fe9 in G4Qt3DSceneHandler::~G4Qt3DSceneHandler() at /Users/johna/Geant4/geant4-dev/source/visualization/Qt3D/src/G4Qt3DSceneHandler.cc:168 >> 112 #5 0x0000000101032510 in G4VisManager::~G4VisManager() at /Users/johna/Geant4/geant4-dev/source/visualization/management/src/G4VisManager.cc:214 >> 113 #6 0x0000000100013885 in G4VisExecutive::~G4VisExecutive() at /Users/johna/Geant4/geant4-dev/source/visualization/management/include/G4VisExecutive.hh:119 >> 114 #7 0x00000001000119a5 in G4VisExecutive::~G4VisExecutive() at /Users/johna/Geant4/geant4-dev/source/visualization/management/include/G4VisExecutive.hh:119 >> 115 #8 0x00000001000119c9 in G4VisExecutive::~G4VisExecutive() at /Users/johna/Geant4/geant4-dev/source/visualization/management/include/G4VisExecutive.hh:119 >> 116 #9 0x00000001000117dd in main at /Users/johna/Geant4/geant4-dev/examples/basic/B1/exampleB1.cc:108 >> 117 */ >> 118 //if (fpQt3DScene) delete_entity_recursively(fpQt3DScene); 113 } 119 } 114 120 115 void G4Qt3DSceneHandler::EstablishG4Qt3DQEntit 121 void G4Qt3DSceneHandler::EstablishG4Qt3DQEntities() 116 { 122 { 117 fpTransientObjects = new G4Qt3DQEntity(fpQt 123 fpTransientObjects = new G4Qt3DQEntity(fpQt3DScene); // Hangs from root 118 fpTransientObjects ->setObjectName("G4Qt3DT 124 fpTransientObjects ->setObjectName("G4Qt3DTORoot"); 119 fpPersistentObjects = new G4Qt3DQEntity(fpQt 125 fpPersistentObjects = new G4Qt3DQEntity(fpQt3DScene); // Hangs from root 120 fpPersistentObjects ->setObjectName("G4Qt3DP 126 fpPersistentObjects ->setObjectName("G4Qt3DPORoot"); 121 127 122 // Physical volume objects hang from POs 128 // Physical volume objects hang from POs 123 fpPhysicalVolumeObjects.clear(); << 124 if (fpScene) { 129 if (fpScene) { 125 const auto& sceneModels = fpScene->GetRunD 130 const auto& sceneModels = fpScene->GetRunDurationModelList(); 126 for (const auto& sceneModel : sceneModels) 131 for (const auto& sceneModel : sceneModels) { 127 const auto& pvModel = dynamic_cast<G4Phy 132 const auto& pvModel = dynamic_cast<G4PhysicalVolumeModel*>(sceneModel.fpModel); 128 if (pvModel) { 133 if (pvModel) { 129 auto entity = new G4Qt3DQEntity(fpPers 134 auto entity = new G4Qt3DQEntity(fpPersistentObjects); 130 const auto& pv = pvModel->GetTopPhysic 135 const auto& pv = pvModel->GetTopPhysicalVolume(); 131 entity->setObjectName("G4Qt3DPORoot_"+ 136 entity->setObjectName("G4Qt3DPORoot_"+QString(pv->GetName())); 132 entity->SetPVNodeID(G4PhysicalVolumeMo 137 entity->SetPVNodeID(G4PhysicalVolumeModel::G4PhysicalVolumeNodeID(pv)); 133 fpPhysicalVolumeObjects.push_back(enti 138 fpPhysicalVolumeObjects.push_back(entity); 134 } 139 } 135 } 140 } 136 } 141 } 137 } 142 } 138 143 139 G4Qt3DQEntity* G4Qt3DSceneHandler::CreateNewNo 144 G4Qt3DQEntity* G4Qt3DSceneHandler::CreateNewNode() 140 { 145 { 141 // Create a G4Qt3DQEntity node suitable for 146 // Create a G4Qt3DQEntity node suitable for next solid or primitive 142 147 143 G4Qt3DQEntity* newNode = nullptr; 148 G4Qt3DQEntity* newNode = nullptr; 144 149 145 if (fReadyForTransients) { // All transient 150 if (fReadyForTransients) { // All transients hang from this node 146 newNode = new G4Qt3DQEntity(fpTransientObj 151 newNode = new G4Qt3DQEntity(fpTransientObjects); 147 G4String name = fpModel? fpModel->GetGloba << 152 G4String name = fpModel? fpModel->GetGlobalTag(): "User"; 148 newNode->setObjectName(name.c_str()); 153 newNode->setObjectName(name.c_str()); 149 return newNode; 154 return newNode; 150 } 155 } 151 156 152 G4PhysicalVolumeModel* pPVModel = 157 G4PhysicalVolumeModel* pPVModel = 153 dynamic_cast<G4PhysicalVolumeModel*>(fpMod 158 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); 154 159 155 if (!pPVModel) { // Persistent objects (e.g 160 if (!pPVModel) { // Persistent objects (e.g., axes) 156 newNode = new G4Qt3DQEntity(fpPersistentOb 161 newNode = new G4Qt3DQEntity(fpPersistentObjects); 157 newNode->setObjectName(fpModel->GetGlobalT 162 newNode->setObjectName(fpModel->GetGlobalTag().c_str()); 158 return newNode; 163 return newNode; 159 } 164 } 160 165 161 // So this is a G4PhysicalVolumeModel 166 // So this is a G4PhysicalVolumeModel 162 167 163 typedef G4PhysicalVolumeModel::G4PhysicalVol 168 typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID; 164 typedef std::vector<PVNodeID> PVPath; 169 typedef std::vector<PVNodeID> PVPath; 165 // const PVPath& drawnPVPath = pPVModel->GetD 170 // const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath(); 166 const PVPath& fullPVPath = pPVModel->GetFul 171 const PVPath& fullPVPath = pPVModel->GetFullPVPath(); 167 //G4int currentDepth = pPVModel->GetCurrentD 172 //G4int currentDepth = pPVModel->GetCurrentDepth(); 168 //G4VPhysicalVolume* pCurrentPV = pPVModel-> 173 //G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV(); 169 //G4LogicalVolume* pCurrentLV = pPVModel->Ge 174 //G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV(); 170 //G4Material* pCurrentMaterial = pPVModel->G 175 //G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial(); 171 // Note: pCurrentMaterial may be zero (paral 176 // Note: pCurrentMaterial may be zero (parallel world). 172 177 173 #ifdef G4QTDEBUG 178 #ifdef G4QTDEBUG 174 G4cout << "A: " << fullPVPath << G4endl; // 179 G4cout << "A: " << fullPVPath << G4endl; // DEBUG 175 #endif 180 #endif 176 181 177 // Find appropriate root 182 // Find appropriate root 178 const std::size_t nWorlds = fpPhysicalVolume 183 const std::size_t nWorlds = fpPhysicalVolumeObjects.size(); 179 std::size_t iWorld = 0; 184 std::size_t iWorld = 0; 180 for (; iWorld < nWorlds; ++iWorld) { 185 for (; iWorld < nWorlds; ++iWorld) { 181 if (fullPVPath[0].GetPhysicalVolume() == 186 if (fullPVPath[0].GetPhysicalVolume() == 182 fpPhysicalVolumeObjects[iWorld]->GetPV 187 fpPhysicalVolumeObjects[iWorld]->GetPVNodeID().GetPhysicalVolume()) break; 183 } 188 } 184 if (iWorld == nWorlds) { 189 if (iWorld == nWorlds) { 185 G4Exception("G4Qt3DSceneHandler::CreateNew 190 G4Exception("G4Qt3DSceneHandler::CreateNewNode", "qt3D-0000", FatalException, 186 "World mis-match - not possibl 191 "World mis-match - not possible(!?)"); 187 } 192 } 188 193 189 // (Re-)establish pv path of root entity 194 // (Re-)establish pv path of root entity 190 G4Qt3DQEntity* wrld = fpPhysicalVolumeObject 195 G4Qt3DQEntity* wrld = fpPhysicalVolumeObjects[iWorld]; 191 wrld->SetPVNodeID(fullPVPath[0]); 196 wrld->SetPVNodeID(fullPVPath[0]); 192 197 193 // Create nodes as required 198 // Create nodes as required 194 G4Qt3DQEntity* node = wrld; 199 G4Qt3DQEntity* node = wrld; 195 newNode = node; 200 newNode = node; 196 const std::size_t depth = fullPVPath.size(); 201 const std::size_t depth = fullPVPath.size(); 197 std::size_t iDepth = 1; 202 std::size_t iDepth = 1; 198 while (iDepth < depth) { 203 while (iDepth < depth) { 199 const auto& children = node->children(); 204 const auto& children = node->children(); 200 const G4int nChildren = (G4int)children.si 205 const G4int nChildren = (G4int)children.size(); 201 G4int iChild = 0; 206 G4int iChild = 0; 202 G4Qt3DQEntity* child = nullptr; 207 G4Qt3DQEntity* child = nullptr; 203 for (; iChild < nChildren; ++iChild) { 208 for (; iChild < nChildren; ++iChild) { 204 child = static_cast<G4Qt3DQEntity*>(chil 209 child = static_cast<G4Qt3DQEntity*>(children[iChild]); 205 if (child->GetPVNodeID() == fullPVPath[i 210 if (child->GetPVNodeID() == fullPVPath[iDepth]) break; 206 } 211 } 207 if (iChild != nChildren) { // Existing no 212 if (iChild != nChildren) { // Existing node found 208 node = child; // Must be the ancestor o 213 node = child; // Must be the ancestor of new node (subsequent iteration) 209 } else { 214 } else { 210 // Add a new node as child of node 215 // Add a new node as child of node 211 newNode = new G4Qt3DQEntity(node); 216 newNode = new G4Qt3DQEntity(node); 212 newNode->SetPVNodeID(fullPVPath[iDepth]) 217 newNode->SetPVNodeID(fullPVPath[iDepth]); 213 std::ostringstream oss; 218 std::ostringstream oss; 214 oss << newNode->GetPVNodeID().GetPhysica 219 oss << newNode->GetPVNodeID().GetPhysicalVolume()->GetName() 215 << ':' << newNode->GetPVNodeID().GetCopy 220 << ':' << newNode->GetPVNodeID().GetCopyNo(); 216 newNode->setObjectName(oss.str().c_str() 221 newNode->setObjectName(oss.str().c_str()); 217 node = newNode; 222 node = newNode; 218 } 223 } 219 ++iDepth; 224 ++iDepth; 220 } 225 } 221 226 222 return node; 227 return node; 223 } 228 } 224 229 225 void G4Qt3DSceneHandler::PreAddSolid 230 void G4Qt3DSceneHandler::PreAddSolid 226 (const G4Transform3D& objectTransformation, 231 (const G4Transform3D& objectTransformation, 227 const G4VisAttributes& visAttribs) 232 const G4VisAttributes& visAttribs) 228 { 233 { 229 G4VSceneHandler::PreAddSolid(objectTransform 234 G4VSceneHandler::PreAddSolid(objectTransformation, visAttribs); 230 } 235 } 231 236 232 void G4Qt3DSceneHandler::PostAddSolid() 237 void G4Qt3DSceneHandler::PostAddSolid() 233 { 238 { 234 G4VSceneHandler::PostAddSolid(); 239 G4VSceneHandler::PostAddSolid(); 235 } 240 } 236 241 237 void G4Qt3DSceneHandler::BeginPrimitives2D(con 242 void G4Qt3DSceneHandler::BeginPrimitives2D(const G4Transform3D& objectTransformation) 238 { 243 { 239 // The x,y coordinates of the primitives passe 244 // The x,y coordinates of the primitives passed to AddPrimitive are 240 // intrepreted as screen coordinates, -1 < x,y 245 // intrepreted as screen coordinates, -1 < x,y < 1. The 241 // z-coordinate is ignored. 246 // z-coordinate is ignored. 242 // IMPORTANT: invoke this from your polymorphi 247 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 243 // void MyXXXSceneHandler::BeginPrimitives2D 248 // void MyXXXSceneHandler::BeginPrimitives2D 244 // (const G4Transform3D& objectTransformation) 249 // (const G4Transform3D& objectTransformation) { 245 static G4bool first = true; 250 static G4bool first = true; 246 if (first) { 251 if (first) { 247 first = false; 252 first = false; 248 G4Exception("G4Qt3DSceneHandler::BeginPrim 253 G4Exception("G4Qt3DSceneHandler::BeginPrimitives2D", "qt3D-0001", 249 JustWarning, 254 JustWarning, 250 "2D drawing not yet implemente 255 "2D drawing not yet implemented"); 251 } 256 } 252 G4VSceneHandler::BeginPrimitives2D (objectT 257 G4VSceneHandler::BeginPrimitives2D (objectTransformation); 253 // ... 258 // ... 254 } 259 } 255 260 256 void G4Qt3DSceneHandler::EndPrimitives2D () 261 void G4Qt3DSceneHandler::EndPrimitives2D () 257 { 262 { 258 // IMPORTANT: invoke this from your polymorphi 263 // IMPORTANT: invoke this from your polymorphic versions, e.g.: 259 // void MyXXXSceneHandler::EndPrimitives2D () 264 // void MyXXXSceneHandler::EndPrimitives2D () { 260 // ... 265 // ... 261 G4VSceneHandler::EndPrimitives2D (); 266 G4VSceneHandler::EndPrimitives2D (); 262 } 267 } 263 268 264 void G4Qt3DSceneHandler::BeginPrimitives 269 void G4Qt3DSceneHandler::BeginPrimitives 265 (const G4Transform3D& objectTransformation) 270 (const G4Transform3D& objectTransformation) 266 { 271 { 267 G4VSceneHandler::BeginPrimitives(objectTrans 272 G4VSceneHandler::BeginPrimitives(objectTransformation); 268 } 273 } 269 274 270 void G4Qt3DSceneHandler::EndPrimitives () 275 void G4Qt3DSceneHandler::EndPrimitives () 271 { 276 { 272 G4VSceneHandler::EndPrimitives (); 277 G4VSceneHandler::EndPrimitives (); 273 } 278 } 274 279 275 void G4Qt3DSceneHandler::AddPrimitive(const G4 280 void G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline) 276 { 281 { 277 #ifdef G4QT3DDEBUG 282 #ifdef G4QT3DDEBUG 278 G4cout << 283 G4cout << 279 "G4Qt3DSceneHandler::AddPrimitive(const G4Po 284 "G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n" 280 << polyline 285 << polyline 281 << G4endl; 286 << G4endl; 282 #endif 287 #endif 283 288 284 if (polyline.size() == 0) return; 289 if (polyline.size() == 0) return; 285 290 286 auto currentNode = CreateNewNode(); 291 auto currentNode = CreateNewNode(); 287 if (!currentNode) { 292 if (!currentNode) { 288 static G4bool first = true; 293 static G4bool first = true; 289 if (first) { 294 if (first) { 290 first = false; 295 first = false; 291 G4Exception("G4Qt3DSceneHandler::AddPrim 296 G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Polyline&)", 292 "qt3d-0003", JustWarning, 297 "qt3d-0003", JustWarning, 293 "No available node!"); 298 "No available node!"); 294 } 299 } 295 return; 300 return; 296 } 301 } 297 302 298 fpVisAttribs = fpViewer->GetApplicableVisAtt 303 fpVisAttribs = fpViewer->GetApplicableVisAttributes(polyline.GetVisAttributes()); 299 304 300 auto transform = G4Qt3DUtils::CreateQTransfo 305 auto transform = G4Qt3DUtils::CreateQTransformFrom(fObjectTransformation); 301 transform->setObjectName("transform"); 306 transform->setObjectName("transform"); 302 307 303 auto polylineEntity = new Qt3DCore::QEntity( 308 auto polylineEntity = new Qt3DCore::QEntity(currentNode); 304 polylineEntity->addComponent(transform); 309 polylineEntity->addComponent(transform); 305 310 306 const auto vertexByteSize = 3*sizeof(PRECIS 311 const auto vertexByteSize = 3*sizeof(PRECISION); 307 312 308 const std::size_t nLines = polyline.size() - 313 const std::size_t nLines = polyline.size() - 1; 309 QByteArray polylineByteArray; 314 QByteArray polylineByteArray; 310 const auto polylineBufferByteSize = 2*nLines 315 const auto polylineBufferByteSize = 2*nLines*vertexByteSize; 311 polylineByteArray.resize((G4int)polylineBuff 316 polylineByteArray.resize((G4int)polylineBufferByteSize); 312 auto polylineBufferArray = reinterpret_cast< 317 auto polylineBufferArray = reinterpret_cast<PRECISION*>(polylineByteArray.data()); 313 G4int iLine = 0; 318 G4int iLine = 0; 314 for (std::size_t i = 0; i < nLines; ++i) { 319 for (std::size_t i = 0; i < nLines; ++i) { 315 polylineBufferArray[iLine++] = polyline[i] 320 polylineBufferArray[iLine++] = polyline[i].x(); 316 polylineBufferArray[iLine++] = polyline[i] 321 polylineBufferArray[iLine++] = polyline[i].y(); 317 polylineBufferArray[iLine++] = polyline[i] 322 polylineBufferArray[iLine++] = polyline[i].z(); 318 polylineBufferArray[iLine++] = polyline[i+ 323 polylineBufferArray[iLine++] = polyline[i+1].x(); 319 polylineBufferArray[iLine++] = polyline[i+ 324 polylineBufferArray[iLine++] = polyline[i+1].y(); 320 polylineBufferArray[iLine++] = polyline[i+ 325 polylineBufferArray[iLine++] = polyline[i+1].z(); 321 } 326 } 322 auto polylineGeometry = new G4Qt3DCompat::QG 327 auto polylineGeometry = new G4Qt3DCompat::QGeometry(); 323 polylineGeometry->setObjectName("polylineGeo 328 polylineGeometry->setObjectName("polylineGeometry"); 324 329 325 auto polylineBuffer = new G4Qt3DCompat::QBuf 330 auto polylineBuffer = new G4Qt3DCompat::QBuffer(polylineGeometry); 326 polylineBuffer->setObjectName("Polyline buff 331 polylineBuffer->setObjectName("Polyline buffer"); 327 polylineBuffer->setData(polylineByteArray); 332 polylineBuffer->setData(polylineByteArray); 328 333 329 auto polylineAtt = new G4Qt3DCompat::QAttrib 334 auto polylineAtt = new G4Qt3DCompat::QAttribute; 330 polylineAtt->setObjectName("Position attribu 335 polylineAtt->setObjectName("Position attribute"); 331 polylineAtt->setName(G4Qt3DCompat::QAttribut 336 polylineAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName()); 332 polylineAtt->setBuffer(polylineBuffer); 337 polylineAtt->setBuffer(polylineBuffer); 333 polylineAtt->setAttributeType(G4Qt3DCompat:: 338 polylineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute); 334 polylineAtt->setVertexBaseType(BASETYPE); 339 polylineAtt->setVertexBaseType(BASETYPE); 335 polylineAtt->setVertexSize(3); 340 polylineAtt->setVertexSize(3); 336 polylineAtt->setCount((G4int)nLines); 341 polylineAtt->setCount((G4int)nLines); 337 polylineAtt->setByteOffset(0); 342 polylineAtt->setByteOffset(0); 338 polylineAtt->setByteStride(vertexByteSize); 343 polylineAtt->setByteStride(vertexByteSize); 339 // Normal attribute (a dummy with count==0) 344 // Normal attribute (a dummy with count==0) (Qt6 seems to require) 340 auto dummyNormalLineAtt = new G4Qt3DCompat:: 345 auto dummyNormalLineAtt = new G4Qt3DCompat::QAttribute; 341 dummyNormalLineAtt->setObjectName("Normal at 346 dummyNormalLineAtt->setObjectName("Normal attribute"); 342 dummyNormalLineAtt->setName(G4Qt3DCompat::QA 347 dummyNormalLineAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName()); 343 dummyNormalLineAtt->setBuffer(polylineBuffer 348 dummyNormalLineAtt->setBuffer(polylineBuffer); 344 dummyNormalLineAtt->setAttributeType(G4Qt3DC 349 dummyNormalLineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute); 345 dummyNormalLineAtt->setVertexBaseType(BASETY 350 dummyNormalLineAtt->setVertexBaseType(BASETYPE); 346 dummyNormalLineAtt->setVertexSize(3); 351 dummyNormalLineAtt->setVertexSize(3); 347 dummyNormalLineAtt->setCount(0); 352 dummyNormalLineAtt->setCount(0); 348 dummyNormalLineAtt->setByteOffset(0); 353 dummyNormalLineAtt->setByteOffset(0); 349 dummyNormalLineAtt->setByteStride(vertexByte 354 dummyNormalLineAtt->setByteStride(vertexByteSize); 350 355 351 const auto& colour = fpVisAttribs->GetColour 356 const auto& colour = fpVisAttribs->GetColour(); 352 357 353 polylineGeometry->addAttribute(polylineAtt); 358 polylineGeometry->addAttribute(polylineAtt); 354 polylineGeometry->addAttribute(dummyNormalLi 359 polylineGeometry->addAttribute(dummyNormalLineAtt); 355 360 356 auto material = new Qt3DExtras::QDiffuseSpec 361 auto material = new Qt3DExtras::QDiffuseSpecularMaterial(); 357 material->setObjectName("materialForPolyline 362 material->setObjectName("materialForPolyline"); 358 material->setAmbient(G4Qt3DUtils::ConvertToQ 363 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 359 material->setShininess(0.); 364 material->setShininess(0.); 360 material->setSpecular(0.); 365 material->setSpecular(0.); 361 polylineEntity->addComponent(material); 366 polylineEntity->addComponent(material); 362 367 363 auto renderer = new Qt3DRender::QGeometryRen 368 auto renderer = new Qt3DRender::QGeometryRenderer; >> 369 #if QT_VERSION >= QT_VERSION_CHECK(6,0,0) >> 370 auto geometryView = new Qt3DCore::QGeometryView(polylineGeometry); >> 371 geometryView->setObjectName("polylineGeometryView"); >> 372 geometryView->setGeometry(polylineGeometry); >> 373 geometryView->setVertexCount((G4int)(2*nLines)); >> 374 geometryView->setPrimitiveType(Qt3DCore::QGeometryView::Lines); >> 375 renderer->setView(geometryView); >> 376 #else 364 renderer->setObjectName("polylineRenderer"); 377 renderer->setObjectName("polylineRenderer"); 365 renderer->setGeometry(polylineGeometry); 378 renderer->setGeometry(polylineGeometry); 366 renderer->setVertexCount(2*(G4int)nLines); 379 renderer->setVertexCount(2*(G4int)nLines); 367 renderer->setPrimitiveType(Qt3DRender::QGeom 380 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines); >> 381 #endif 368 polylineEntity->addComponent(renderer); 382 polylineEntity->addComponent(renderer); 369 } 383 } 370 384 371 void G4Qt3DSceneHandler::AddPrimitive (const G 385 void G4Qt3DSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 372 { 386 { 373 if (polymarker.size() == 0) return; 387 if (polymarker.size() == 0) return; 374 388 375 auto currentNode = CreateNewNode(); 389 auto currentNode = CreateNewNode(); 376 if (!currentNode) { 390 if (!currentNode) { 377 static G4bool first = true; 391 static G4bool first = true; 378 if (first) { 392 if (first) { 379 first = false; 393 first = false; 380 G4Exception("G4Qt3DSceneHandler::AddPrim 394 G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Polymarker&)", 381 "qt3d-0003", JustWarning, 395 "qt3d-0003", JustWarning, 382 "No available node!"); 396 "No available node!"); 383 } 397 } 384 return; 398 return; 385 } 399 } 386 400 387 fpVisAttribs = fpViewer->GetApplicableVisAtt 401 fpVisAttribs = fpViewer->GetApplicableVisAttributes(polymarker.GetVisAttributes()); 388 402 389 MarkerSizeType markerSizeType; 403 MarkerSizeType markerSizeType; 390 G4double markerSize = GetMarkerSize(polymark 404 G4double markerSize = GetMarkerSize(polymarker, markerSizeType); 391 405 392 switch (polymarker.GetMarkerType()) { 406 switch (polymarker.GetMarkerType()) { 393 default: 407 default: 394 case G4Polymarker::dots: 408 case G4Polymarker::dots: 395 { 409 { 396 const std::size_t nDots = polymarker.siz 410 const std::size_t nDots = polymarker.size(); 397 411 398 auto transform = G4Qt3DUtils::CreateQTra 412 auto transform = G4Qt3DUtils::CreateQTransformFrom(fObjectTransformation); 399 transform->setObjectName("transform"); 413 transform->setObjectName("transform"); 400 414 401 auto polymarkerEntity = new Qt3DCore::QE 415 auto polymarkerEntity = new Qt3DCore::QEntity(currentNode); 402 polymarkerEntity->addComponent(transform 416 polymarkerEntity->addComponent(transform); 403 417 404 const auto vertexByteSize = 3*sizeof(PR 418 const auto vertexByteSize = 3*sizeof(PRECISION); 405 419 406 QByteArray polymarkerByteArray; 420 QByteArray polymarkerByteArray; 407 const auto polymarkerBufferByteSize = nD 421 const auto polymarkerBufferByteSize = nDots*vertexByteSize; 408 polymarkerByteArray.resize((G4int)polyma 422 polymarkerByteArray.resize((G4int)polymarkerBufferByteSize); 409 auto polymarkerBufferArray = reinterpret 423 auto polymarkerBufferArray = reinterpret_cast<PRECISION*>(polymarkerByteArray.data()); 410 G4int iMarker = 0; 424 G4int iMarker = 0; 411 for (std::size_t i = 0; i < polymarker.s 425 for (std::size_t i = 0; i < polymarker.size(); ++i) { 412 polymarkerBufferArray[iMarker++] = pol 426 polymarkerBufferArray[iMarker++] = polymarker[i].x(); 413 polymarkerBufferArray[iMarker++] = pol 427 polymarkerBufferArray[iMarker++] = polymarker[i].y(); 414 polymarkerBufferArray[iMarker++] = pol 428 polymarkerBufferArray[iMarker++] = polymarker[i].z(); 415 } 429 } 416 auto polymarkerGeometry = new G4Qt3DComp 430 auto polymarkerGeometry = new G4Qt3DCompat::QGeometry(); 417 polymarkerGeometry->setObjectName("polym 431 polymarkerGeometry->setObjectName("polymarkerGeometry"); 418 auto polymarkerBuffer = new G4Qt3DCompat 432 auto polymarkerBuffer = new G4Qt3DCompat::QBuffer(polymarkerGeometry); 419 polymarkerBuffer->setObjectName("Polymar 433 polymarkerBuffer->setObjectName("Polymarker buffer"); 420 polymarkerBuffer->setData(polymarkerByte 434 polymarkerBuffer->setData(polymarkerByteArray); 421 435 422 auto polymarkerAtt = new G4Qt3DCompat::Q 436 auto polymarkerAtt = new G4Qt3DCompat::QAttribute; 423 polymarkerAtt->setObjectName("Position a 437 polymarkerAtt->setObjectName("Position attribute"); 424 polymarkerAtt->setName(G4Qt3DCompat::QAt 438 polymarkerAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName()); 425 polymarkerAtt->setBuffer(polymarkerBuffe 439 polymarkerAtt->setBuffer(polymarkerBuffer); 426 polymarkerAtt->setAttributeType(G4Qt3DCo 440 polymarkerAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute); 427 polymarkerAtt->setVertexBaseType(BASETYP 441 polymarkerAtt->setVertexBaseType(BASETYPE); 428 polymarkerAtt->setVertexSize(3); 442 polymarkerAtt->setVertexSize(3); 429 polymarkerAtt->setCount((G4int)nDots); 443 polymarkerAtt->setCount((G4int)nDots); 430 polymarkerAtt->setByteOffset(0); 444 polymarkerAtt->setByteOffset(0); 431 polymarkerAtt->setByteStride(vertexByteS 445 polymarkerAtt->setByteStride(vertexByteSize); 432 446 433 const auto& colour = fpVisAttribs->GetCo 447 const auto& colour = fpVisAttribs->GetColour(); 434 448 435 polymarkerGeometry->addAttribute(polymar 449 polymarkerGeometry->addAttribute(polymarkerAtt); 436 450 437 auto material = new Qt3DExtras::QDiffuse 451 auto material = new Qt3DExtras::QDiffuseSpecularMaterial(); 438 material->setObjectName("materialForPoly 452 material->setObjectName("materialForPolymarker"); 439 material->setAmbient(G4Qt3DUtils::Conver 453 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 440 material->setShininess(0.); 454 material->setShininess(0.); 441 material->setSpecular(0.); 455 material->setSpecular(0.); 442 polymarkerEntity->addComponent(material) 456 polymarkerEntity->addComponent(material); 443 457 444 auto renderer = new Qt3DRender::QGeometr 458 auto renderer = new Qt3DRender::QGeometryRenderer; 445 renderer->setObjectName("polymarkerWiref 459 renderer->setObjectName("polymarkerWireframeRenderer"); 446 renderer->setGeometry(polymarkerGeometry 460 renderer->setGeometry(polymarkerGeometry); 447 renderer->setVertexCount((G4int)nDots); 461 renderer->setVertexCount((G4int)nDots); 448 renderer->setPrimitiveType(Qt3DRender::Q 462 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Points); 449 polymarkerEntity->addComponent(renderer) 463 polymarkerEntity->addComponent(renderer); 450 } 464 } 451 break; 465 break; 452 case G4Polymarker::circles: 466 case G4Polymarker::circles: 453 { 467 { 454 G4Circle circle (polymarker); // Defaul 468 G4Circle circle (polymarker); // Default circle 455 469 456 const auto& colour = fpVisAttribs->GetCo 470 const auto& colour = fpVisAttribs->GetColour(); 457 auto material = new Qt3DExtras::QDiffuse 471 auto material = new Qt3DExtras::QDiffuseSpecularMaterial(); 458 material->setObjectName("materialForCirc 472 material->setObjectName("materialForCircle"); 459 material->setAmbient(G4Qt3DUtils::Conver 473 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 460 if (colour.GetAlpha() < 1.) material->se 474 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(true); 461 475 462 auto sphereMesh = new Qt3DExtras::QSpher 476 auto sphereMesh = new Qt3DExtras::QSphereMesh; 463 sphereMesh->setObjectName("sphereMesh"); 477 sphereMesh->setObjectName("sphereMesh"); 464 G4double radius = markerSize/2.; 478 G4double radius = markerSize/2.; 465 if (markerSizeType == G4VSceneHandler::s 479 if (markerSizeType == G4VSceneHandler::screen ) { 466 // Not figured out how to do screen-si 480 // Not figured out how to do screen-size, so use scene extent 467 const G4double scale = 200.; // Rough 481 const G4double scale = 200.; // Roughly pixels per scene 468 radius *= fpScene->GetExtent().GetExte 482 radius *= fpScene->GetExtent().GetExtentRadius()/scale; 469 } 483 } 470 sphereMesh->setRadius(radius); 484 sphereMesh->setRadius(radius); 471 // sphereMesh->setInstanceCount(polymarke 485 // sphereMesh->setInstanceCount(polymarker.size()); // Not undertood instancing yet 472 486 473 // auto currentEntity = new Qt3DCore::QEn 487 // auto currentEntity = new Qt3DCore::QEntity(currentNode); // Not undertood instancing yet 474 for (std::size_t iPoint = 0; iPoint < po 488 for (std::size_t iPoint = 0; iPoint < polymarker.size(); ++iPoint) { 475 auto position = fObjectTransformation* 489 auto position = fObjectTransformation*G4Translate3D(polymarker[iPoint]); 476 auto transform = G4Qt3DUtils::CreateQT 490 auto transform = G4Qt3DUtils::CreateQTransformFrom(position); 477 auto currentEntity = new Qt3DCore::QEntity(c 491 auto currentEntity = new Qt3DCore::QEntity(currentNode); // Not undertood instancing yet 478 currentEntity->addComponent(material); 492 currentEntity->addComponent(material); 479 currentEntity->addComponent(transform) 493 currentEntity->addComponent(transform); 480 currentEntity->addComponent(sphereMesh 494 currentEntity->addComponent(sphereMesh); 481 } 495 } 482 } 496 } 483 break; 497 break; 484 case G4Polymarker::squares: 498 case G4Polymarker::squares: 485 { 499 { 486 G4Square square (polymarker); // Defaul 500 G4Square square (polymarker); // Default square 487 501 488 const auto& colour = fpVisAttribs->GetCo 502 const auto& colour = fpVisAttribs->GetColour(); 489 auto material = new Qt3DExtras::QDiffuse 503 auto material = new Qt3DExtras::QDiffuseSpecularMaterial(); 490 material->setObjectName("materialForSqua 504 material->setObjectName("materialForSquare"); 491 material->setAmbient(G4Qt3DUtils::Conver 505 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 492 if (colour.GetAlpha() < 1.) material->se 506 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(true); 493 507 494 auto boxMesh = new Qt3DExtras::QCuboidMe 508 auto boxMesh = new Qt3DExtras::QCuboidMesh(); 495 boxMesh->setObjectName("boxMesh"); 509 boxMesh->setObjectName("boxMesh"); 496 G4double side = markerSize; 510 G4double side = markerSize; 497 if (markerSizeType == G4VSceneHandler::s 511 if (markerSizeType == G4VSceneHandler::screen ) { 498 // Not figured out how to do screen-si 512 // Not figured out how to do screen-size, so use scene extent 499 const G4double scale = 200.; // Rough 513 const G4double scale = 200.; // Roughly pixles per scene 500 side *= fpScene->GetExtent().GetExtent 514 side *= fpScene->GetExtent().GetExtentRadius()/scale; 501 } 515 } 502 boxMesh->setXExtent(side); 516 boxMesh->setXExtent(side); 503 boxMesh->setYExtent(side); 517 boxMesh->setYExtent(side); 504 boxMesh->setZExtent(side); 518 boxMesh->setZExtent(side); 505 519 506 for (std::size_t iPoint = 0; iPoint < po 520 for (std::size_t iPoint = 0; iPoint < polymarker.size(); ++iPoint) { 507 auto position = fObjectTransformation* 521 auto position = fObjectTransformation*G4Translate3D(polymarker[iPoint]); 508 auto transform = G4Qt3DUtils::CreateQT 522 auto transform = G4Qt3DUtils::CreateQTransformFrom(position); 509 auto currentEntity = new Qt3DCore::QEn 523 auto currentEntity = new Qt3DCore::QEntity(currentNode); 510 currentEntity->addComponent(material); 524 currentEntity->addComponent(material); 511 currentEntity->addComponent(transform) 525 currentEntity->addComponent(transform); 512 currentEntity->addComponent(boxMesh); 526 currentEntity->addComponent(boxMesh); 513 } 527 } 514 } 528 } 515 break; 529 break; 516 } 530 } 517 } 531 } 518 532 519 #ifdef G4QT3DDEBUG 533 #ifdef G4QT3DDEBUG 520 void G4Qt3DSceneHandler::AddPrimitive(const G4 534 void G4Qt3DSceneHandler::AddPrimitive(const G4Text& text) { 521 G4cout << 535 G4cout << 522 "G4Qt3DSceneHandler::AddPrimitive(const G4Te 536 "G4Qt3DSceneHandler::AddPrimitive(const G4Text& text) called.\n" 523 << text 537 << text 524 << G4endl; 538 << G4endl; 525 #else 539 #else 526 void G4Qt3DSceneHandler::AddPrimitive(const G4 540 void G4Qt3DSceneHandler::AddPrimitive(const G4Text& /*text*/) { 527 #endif 541 #endif 528 542 529 static G4bool first = true; 543 static G4bool first = true; 530 if (first) { 544 if (first) { 531 first = false; 545 first = false; 532 G4Exception("G4Qt3DSceneHandler::AddPrimit 546 G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Text&)", 533 "qt3D-0002", JustWarning, 547 "qt3D-0002", JustWarning, 534 "Text drawing doesn't work yet 548 "Text drawing doesn't work yet"); 535 } // OK. Not working, but let it execute, w 549 } // OK. Not working, but let it execute, which it does without error. 536 550 537 /* But it crashes after /vis/viewer/rebuild! 551 /* But it crashes after /vis/viewer/rebuild!!! 538 auto currentNode = CreateNewNode(); 552 auto currentNode = CreateNewNode(); 539 if (!currentNode) { 553 if (!currentNode) { 540 static G4bool first = true; 554 static G4bool first = true; 541 if (first) { 555 if (first) { 542 first = false; 556 first = false; 543 G4Exception("G4Qt3DSceneHandler::AddPrimiti 557 G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Text&)", 544 "qt3d-0003", JustWarning, 558 "qt3d-0003", JustWarning, 545 "No available node!"); 559 "No available node!"); 546 } 560 } 547 return; 561 return; 548 } 562 } 549 563 550 fpVisAttribs = fpViewer->GetApplicableVisAtt 564 fpVisAttribs = fpViewer->GetApplicableVisAttributes(text.GetVisAttributes()); 551 565 552 auto position = fObjectTransformation*G4Tran 566 auto position = fObjectTransformation*G4Translate3D(text.GetPosition()); 553 auto transform = G4Qt3DUtils::CreateQTransfo 567 auto transform = G4Qt3DUtils::CreateQTransformFrom(position); 554 // transform->setScale(10); 568 // transform->setScale(10); 555 transform->setScale(0.1); 569 transform->setScale(0.1); 556 570 557 // auto currentEntity = new Qt3DCore::QEntity 571 // auto currentEntity = new Qt3DCore::QEntity(currentNode); 558 572 559 // This simply does not work 573 // This simply does not work 560 auto qtext = new Qt3DExtras::QText2DEntity() 574 auto qtext = new Qt3DExtras::QText2DEntity(); 561 qtext->setParent(currentNode); 575 qtext->setParent(currentNode); 562 // qtext->setParent(currentEntity); // ?? D 576 // qtext->setParent(currentEntity); // ?? Doesn't help 563 qtext->setText(text.GetText().c_str()); 577 qtext->setText(text.GetText().c_str()); 564 // qtext->setHeight(100); 578 // qtext->setHeight(100); 565 // qtext->setWidth(1000); 579 // qtext->setWidth(1000); 566 qtext->setHeight(20); 580 qtext->setHeight(20); 567 qtext->setWidth(100); 581 qtext->setWidth(100); 568 qtext->setColor(Qt::green); 582 qtext->setColor(Qt::green); 569 qtext->setFont(QFont("Courier New", 10)); 583 qtext->setFont(QFont("Courier New", 10)); 570 qtext->addComponent(transform); 584 qtext->addComponent(transform); 571 585 572 // This produces text in 3D facing +z - not 586 // This produces text in 3D facing +z - not what we want 573 // const auto& colour = GetTextColour(text); 587 // const auto& colour = GetTextColour(text); 574 // auto material = new Qt3DExtras::QDiffuseSp 588 // auto material = new Qt3DExtras::QDiffuseSpecularMaterial(); 575 // material->setObjectName("materialForText") 589 // material->setObjectName("materialForText"); 576 // material->setAmbient(G4Qt3DUtils::ConvertT 590 // material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 577 // if (colour.GetAlpha() < 1.) material->setA 591 // if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(true); 578 // 592 // 579 // auto textMesh = new Qt3DExtras::QExtrudedT 593 // auto textMesh = new Qt3DExtras::QExtrudedTextMesh(); 580 // textMesh->setText(text.GetText().c_str()); 594 // textMesh->setText(text.GetText().c_str()); 581 // textMesh->setFont(QFont("Courier New", 10) 595 // textMesh->setFont(QFont("Courier New", 10)); 582 // textMesh->setDepth(.01f); 596 // textMesh->setDepth(.01f); 583 // 597 // 584 // currentNode->addComponent(material); 598 // currentNode->addComponent(material); 585 // currentNode->addComponent(transform); 599 // currentNode->addComponent(transform); 586 // currentNode->addComponent(textMesh); 600 // currentNode->addComponent(textMesh); 587 */ 601 */ 588 } 602 } 589 603 590 void G4Qt3DSceneHandler::AddPrimitive(const G4 604 void G4Qt3DSceneHandler::AddPrimitive(const G4Circle& circle) 591 { 605 { 592 #ifdef G4QT3DDEBUG 606 #ifdef G4QT3DDEBUG 593 G4cout << 607 G4cout << 594 "G4Qt3DSceneHandler::AddPrimitive(const G4Ci 608 "G4Qt3DSceneHandler::AddPrimitive(const G4Circle& circle) called.\n" 595 << circle 609 << circle 596 << G4endl; 610 << G4endl; 597 #endif 611 #endif 598 612 599 #ifdef G4QT3DDEBUG 613 #ifdef G4QT3DDEBUG 600 MarkerSizeType sizeType; 614 MarkerSizeType sizeType; 601 G4double size = GetMarkerSize (circle, sizeT 615 G4double size = GetMarkerSize (circle, sizeType); 602 switch (sizeType) { 616 switch (sizeType) { 603 default: 617 default: 604 case screen: 618 case screen: 605 // Draw in screen coordinates. 619 // Draw in screen coordinates. 606 G4cout << "screen"; 620 G4cout << "screen"; 607 break; 621 break; 608 case world: 622 case world: 609 // Draw in world coordinates. 623 // Draw in world coordinates. 610 G4cout << "world"; 624 G4cout << "world"; 611 break; 625 break; 612 } 626 } 613 G4cout << " size: " << size << G4endl; 627 G4cout << " size: " << size << G4endl; 614 #endif 628 #endif 615 629 616 auto currentNode = CreateNewNode(); 630 auto currentNode = CreateNewNode(); 617 if (!currentNode) { 631 if (!currentNode) { 618 static G4bool first = true; 632 static G4bool first = true; 619 if (first) { 633 if (first) { 620 first = false; 634 first = false; 621 G4Exception("G4Qt3DSceneHandler::AddPrim 635 G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Circle&)", 622 "qt3d-0003", JustWarning, 636 "qt3d-0003", JustWarning, 623 "No available node!"); 637 "No available node!"); 624 } 638 } 625 return; 639 return; 626 } 640 } 627 641 628 fpVisAttribs = fpViewer->GetApplicableVisAtt 642 fpVisAttribs = fpViewer->GetApplicableVisAttributes(circle.GetVisAttributes()); 629 643 630 auto position = fObjectTransformation*G4Tran 644 auto position = fObjectTransformation*G4Translate3D(circle.GetPosition()); 631 auto transform = G4Qt3DUtils::CreateQTransfo 645 auto transform = G4Qt3DUtils::CreateQTransformFrom(position); 632 646 633 const auto& colour = fpVisAttribs->GetColour 647 const auto& colour = fpVisAttribs->GetColour(); 634 auto material = new Qt3DExtras::QDiffuseSpec 648 auto material = new Qt3DExtras::QDiffuseSpecularMaterial(); 635 material->setObjectName("materialForCircle") 649 material->setObjectName("materialForCircle"); 636 material->setAmbient(G4Qt3DUtils::ConvertToQ 650 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 637 if (colour.GetAlpha() < 1.) material->setAlp 651 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(true); 638 652 639 auto sphereMesh = new Qt3DExtras::QSphereMes 653 auto sphereMesh = new Qt3DExtras::QSphereMesh; 640 sphereMesh->setObjectName("sphereMesh"); 654 sphereMesh->setObjectName("sphereMesh"); 641 G4double radius; 655 G4double radius; 642 if (circle.GetSizeType() == G4VMarker::world 656 if (circle.GetSizeType() == G4VMarker::world ) { 643 radius =circle.GetWorldRadius(); 657 radius =circle.GetWorldRadius(); 644 } else { // Screen-size or none 658 } else { // Screen-size or none 645 // Not figured out how to do screen-size, 659 // Not figured out how to do screen-size, so use scene extent 646 const G4double scale = 200.; // Roughly p 660 const G4double scale = 200.; // Roughly pixles per scene 647 radius = circle.GetScreenRadius()*fpScene- 661 radius = circle.GetScreenRadius()*fpScene->GetExtent().GetExtentRadius()/scale; 648 } 662 } 649 sphereMesh->setRadius(radius); 663 sphereMesh->setRadius(radius); 650 664 651 auto currentEntity = new Qt3DCore::QEntity(c 665 auto currentEntity = new Qt3DCore::QEntity(currentNode); 652 currentEntity->addComponent(material); 666 currentEntity->addComponent(material); 653 currentEntity->addComponent(transform); 667 currentEntity->addComponent(transform); 654 currentEntity->addComponent(sphereMesh); 668 currentEntity->addComponent(sphereMesh); 655 } 669 } 656 670 657 void G4Qt3DSceneHandler::AddPrimitive(const G4 671 void G4Qt3DSceneHandler::AddPrimitive(const G4Square& square) 658 { 672 { 659 #ifdef G4QT3DDEBUG 673 #ifdef G4QT3DDEBUG 660 G4cout << 674 G4cout << 661 "G4Qt3DSceneHandler::AddPrimitive(const G4Sq 675 "G4Qt3DSceneHandler::AddPrimitive(const G4Square& square) called.\n" 662 << square 676 << square 663 << G4endl; 677 << G4endl; 664 #endif 678 #endif 665 679 666 #ifdef G4QT3DDEBUG 680 #ifdef G4QT3DDEBUG 667 MarkerSizeType sizeType; 681 MarkerSizeType sizeType; 668 G4double size = GetMarkerSize (square, sizeT 682 G4double size = GetMarkerSize (square, sizeType); 669 switch (sizeType) { 683 switch (sizeType) { 670 default: 684 default: 671 case screen: 685 case screen: 672 // Draw in screen coordinates. 686 // Draw in screen coordinates. 673 G4cout << "screen"; 687 G4cout << "screen"; 674 break; 688 break; 675 case world: 689 case world: 676 // Draw in world coordinates. 690 // Draw in world coordinates. 677 G4cout << "world"; 691 G4cout << "world"; 678 break; 692 break; 679 } 693 } 680 G4cout << " size: " << size << G4endl; 694 G4cout << " size: " << size << G4endl; 681 #endif 695 #endif 682 696 683 auto currentNode = CreateNewNode(); 697 auto currentNode = CreateNewNode(); 684 if (!currentNode) { 698 if (!currentNode) { 685 static G4bool first = true; 699 static G4bool first = true; 686 if (first) { 700 if (first) { 687 first = false; 701 first = false; 688 G4Exception("G4Qt3DSceneHandler::AddPrim 702 G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Square&)", 689 "qt3d-0003", JustWarning, 703 "qt3d-0003", JustWarning, 690 "No available node!"); 704 "No available node!"); 691 } 705 } 692 return; 706 return; 693 } 707 } 694 708 695 fpVisAttribs = fpViewer->GetApplicableVisAtt 709 fpVisAttribs = fpViewer->GetApplicableVisAttributes(square.GetVisAttributes()); 696 710 697 auto position = fObjectTransformation*G4Tran 711 auto position = fObjectTransformation*G4Translate3D(square.GetPosition()); 698 auto transform = G4Qt3DUtils::CreateQTransfo 712 auto transform = G4Qt3DUtils::CreateQTransformFrom(position); 699 713 700 const auto& colour = fpVisAttribs->GetColour 714 const auto& colour = fpVisAttribs->GetColour(); 701 auto material = new Qt3DExtras::QDiffuseSpec 715 auto material = new Qt3DExtras::QDiffuseSpecularMaterial(); 702 material->setObjectName("materialForSquare") 716 material->setObjectName("materialForSquare"); 703 material->setAmbient(G4Qt3DUtils::ConvertToQ 717 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 704 if (colour.GetAlpha() < 1.) material->setAlp 718 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(true); 705 719 706 auto boxMesh = new Qt3DExtras::QCuboidMesh() 720 auto boxMesh = new Qt3DExtras::QCuboidMesh(); 707 boxMesh->setObjectName("boxMesh"); 721 boxMesh->setObjectName("boxMesh"); 708 G4double side; 722 G4double side; 709 if (square.GetSizeType() == G4VMarker::world 723 if (square.GetSizeType() == G4VMarker::world ) { 710 side = square.GetWorldDiameter(); 724 side = square.GetWorldDiameter(); 711 } else { // Screen-size or none 725 } else { // Screen-size or none 712 // Not figured out how to do screen-size, 726 // Not figured out how to do screen-size, so use scene extent 713 const G4double scale = 200.; // Roughly p 727 const G4double scale = 200.; // Roughly pixles per scene 714 side = square.GetScreenDiameter()*fpScene- 728 side = square.GetScreenDiameter()*fpScene->GetExtent().GetExtentRadius()/scale; 715 } 729 } 716 boxMesh->setXExtent(side); 730 boxMesh->setXExtent(side); 717 boxMesh->setYExtent(side); 731 boxMesh->setYExtent(side); 718 boxMesh->setZExtent(side); 732 boxMesh->setZExtent(side); 719 733 720 auto currentEntity = new Qt3DCore::QEntity(c 734 auto currentEntity = new Qt3DCore::QEntity(currentNode); 721 currentEntity->addComponent(material); 735 currentEntity->addComponent(material); 722 currentEntity->addComponent(transform); 736 currentEntity->addComponent(transform); 723 currentEntity->addComponent(boxMesh); 737 currentEntity->addComponent(boxMesh); 724 } 738 } 725 739 726 void G4Qt3DSceneHandler::AddPrimitive(const G4 740 void G4Qt3DSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron) 727 { 741 { 728 auto currentNode = CreateNewNode(); 742 auto currentNode = CreateNewNode(); 729 if (!currentNode) { 743 if (!currentNode) { 730 static G4bool first = true; 744 static G4bool first = true; 731 if (first) { 745 if (first) { 732 first = false; 746 first = false; 733 G4Exception("G4Qt3DSceneHandler::AddPrim 747 G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Polyhedron&)", 734 "qt3d-0003", JustWarning, 748 "qt3d-0003", JustWarning, 735 "No available node!"); 749 "No available node!"); 736 } 750 } 737 return; 751 return; 738 } 752 } 739 753 740 if (polyhedron.GetNoFacets() == 0) return; 754 if (polyhedron.GetNoFacets() == 0) return; 741 755 742 fpVisAttribs = fpViewer->GetApplicableVisAtt 756 fpVisAttribs = fpViewer->GetApplicableVisAttributes(polyhedron.GetVisAttributes()); 743 757 744 // Roll out vertices and normals for the fac 758 // Roll out vertices and normals for the faces. Note that this means vertices 745 // are duplicated. For example a box has 8 v 759 // are duplicated. For example a box has 8 vertices, but to define 6 faces 746 // you need 12 triangles and 36 vertices. If 760 // you need 12 triangles and 36 vertices. If it was just a matter of vertices 747 // we could restrict the number to 8 and use 761 // we could restrict the number to 8 and use the indices to define the 748 // triangles, but we also have to consider t 762 // triangles, but we also have to consider the normals. A vertex can be have 749 // more than one normal, depending on which 763 // more than one normal, depending on which face it is being used to define. 750 // So we roll out all the vertices and norma 764 // So we roll out all the vertices and normals for each triangle. 751 std::vector<G4Point3D> vertices; 765 std::vector<G4Point3D> vertices; 752 std::vector<G4Normal3D> normals; 766 std::vector<G4Normal3D> normals; 753 767 754 // Also roll out edges (as lines) for wirefr 768 // Also roll out edges (as lines) for wireframe. Avoid duplicate lines, 755 // including those that differ only in the o 769 // including those that differ only in the order of vertices. 756 typedef std::pair<G4Point3D,G4Point3D> Line; 770 typedef std::pair<G4Point3D,G4Point3D> Line; 757 std::vector<Line> lines; 771 std::vector<Line> lines; 758 auto insertIfNew = [&lines](const Line& newL 772 auto insertIfNew = [&lines](const Line& newLine) { 759 // For a large polyhedron, eliminating lin 773 // For a large polyhedron, eliminating lines like this is prohibitively 760 // expensive. Comment out for now, and may 774 // expensive. Comment out for now, and maybe unwind altogether in future. 761 // Allow the graphics-reps utilities to op 775 // Allow the graphics-reps utilities to optimise things like this. 762 // for (const auto& line: lines) { 776 // for (const auto& line: lines) { 763 // if ((newLine.first==line.first && newL 777 // if ((newLine.first==line.first && newLine.second==line.second) || 764 // (newLine.first==line.second && new 778 // (newLine.first==line.second && newLine.second==line.first)) 765 // return; 779 // return; 766 // } 780 // } 767 lines.push_back(newLine); 781 lines.push_back(newLine); 768 }; 782 }; 769 783 770 G4bool isAuxilaryEdgeVisible = fpViewer->Get 784 G4bool isAuxilaryEdgeVisible = fpViewer->GetViewParameters().IsAuxEdgeVisible(); 771 G4bool notLastFace; 785 G4bool notLastFace; 772 do { 786 do { 773 G4int nEdges; 787 G4int nEdges; 774 G4Point3D vertex [4]; 788 G4Point3D vertex [4]; 775 G4int edgeFlag[4]; 789 G4int edgeFlag[4]; 776 G4Normal3D normal [4]; 790 G4Normal3D normal [4]; 777 notLastFace = polyhedron.GetNextFacet(nEdg 791 notLastFace = polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normal); 778 vertices.push_back(vertex[0]); 792 vertices.push_back(vertex[0]); 779 vertices.push_back(vertex[1]); 793 vertices.push_back(vertex[1]); 780 vertices.push_back(vertex[2]); 794 vertices.push_back(vertex[2]); 781 normals.push_back(normal[0]); 795 normals.push_back(normal[0]); 782 normals.push_back(normal[1]); 796 normals.push_back(normal[1]); 783 normals.push_back(normal[2]); 797 normals.push_back(normal[2]); 784 if(isAuxilaryEdgeVisible||edgeFlag[0]>0)in 798 if(isAuxilaryEdgeVisible||edgeFlag[0]>0)insertIfNew(Line(vertex[0],vertex[1])); 785 if(isAuxilaryEdgeVisible||edgeFlag[1]>0)in 799 if(isAuxilaryEdgeVisible||edgeFlag[1]>0)insertIfNew(Line(vertex[1],vertex[2])); 786 if (nEdges == 3) { 800 if (nEdges == 3) { 787 // Face is a triangle 801 // Face is a triangle 788 // One more line for wireframe, triangle 802 // One more line for wireframe, triangles for surfaces are complete 789 if(isAuxilaryEdgeVisible||edgeFlag[2]>0) 803 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[0])); 790 } else if (nEdges == 4) { 804 } else if (nEdges == 4) { 791 // Face is a quadrilateral 805 // Face is a quadrilateral 792 // Create another triangle for surfaces, 806 // Create another triangle for surfaces, add two more lines for wireframe 793 vertices.push_back(vertex[2]); 807 vertices.push_back(vertex[2]); 794 vertices.push_back(vertex[3]); 808 vertices.push_back(vertex[3]); 795 vertices.push_back(vertex[0]); 809 vertices.push_back(vertex[0]); 796 normals.push_back(normal[2]); 810 normals.push_back(normal[2]); 797 normals.push_back(normal[3]); 811 normals.push_back(normal[3]); 798 normals.push_back(normal[0]); 812 normals.push_back(normal[0]); 799 if(isAuxilaryEdgeVisible||edgeFlag[2]>0) 813 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[3])); 800 if(isAuxilaryEdgeVisible||edgeFlag[3]>0) 814 if(isAuxilaryEdgeVisible||edgeFlag[3]>0)insertIfNew(Line(vertex[3],vertex[0])); 801 } else { 815 } else { 802 G4warn 816 G4warn 803 << "ERROR: polyhedron face with unexpect 817 << "ERROR: polyhedron face with unexpected number of edges (" << nEdges << ')' 804 << "\n Tag: " << fpModel->GetCurrentTag 818 << "\n Tag: " << fpModel->GetCurrentTag() 805 << G4endl; 819 << G4endl; 806 return; 820 return; 807 } 821 } 808 } while (notLastFace); 822 } while (notLastFace); 809 const auto nVerts = vertices.size(); 823 const auto nVerts = vertices.size(); 810 const auto nLines = lines.size(); 824 const auto nLines = lines.size(); 811 825 812 // Now put stuff into Qt objects 826 // Now put stuff into Qt objects 813 827 814 auto transform = G4Qt3DUtils::CreateQTransfo 828 auto transform = G4Qt3DUtils::CreateQTransformFrom(fObjectTransformation); 815 transform->setObjectName("transform"); 829 transform->setObjectName("transform"); 816 830 817 Qt3DCore::QEntity* wireframeEntity = nullptr 831 Qt3DCore::QEntity* wireframeEntity = nullptr; 818 Qt3DCore::QEntity* surfaceEntity = nullptr 832 Qt3DCore::QEntity* surfaceEntity = nullptr; 819 static G4int errorCount = 0; 833 static G4int errorCount = 0; 820 G4ViewParameters::DrawingStyle drawing_style 834 G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (fpVisAttribs); 821 switch (drawing_style) { 835 switch (drawing_style) { 822 case G4ViewParameters::wireframe: 836 case G4ViewParameters::wireframe: 823 wireframeEntity = new Qt3DCore::QEntity( 837 wireframeEntity = new Qt3DCore::QEntity(currentNode); 824 wireframeEntity->addComponent(transform) 838 wireframeEntity->addComponent(transform); 825 break; 839 break; 826 case G4ViewParameters::hlr: 840 case G4ViewParameters::hlr: 827 wireframeEntity = new Qt3DCore::QEntity( 841 wireframeEntity = new Qt3DCore::QEntity(currentNode); 828 wireframeEntity->addComponent(transform) 842 wireframeEntity->addComponent(transform); 829 surfaceEntity = new Qt3DCore::QEntity(cu 843 surfaceEntity = new Qt3DCore::QEntity(currentNode); 830 surfaceEntity->addComponent(transform); 844 surfaceEntity->addComponent(transform); 831 break; 845 break; 832 case G4ViewParameters::hsr: 846 case G4ViewParameters::hsr: 833 surfaceEntity = new Qt3DCore::QEntity(cu 847 surfaceEntity = new Qt3DCore::QEntity(currentNode); 834 surfaceEntity->addComponent(transform); 848 surfaceEntity->addComponent(transform); 835 break; 849 break; 836 case G4ViewParameters::hlhsr: 850 case G4ViewParameters::hlhsr: 837 wireframeEntity = new Qt3DCore::QEntity( 851 wireframeEntity = new Qt3DCore::QEntity(currentNode); 838 wireframeEntity->addComponent(transform) 852 wireframeEntity->addComponent(transform); 839 surfaceEntity = new Qt3DCore::QEntity(cu 853 surfaceEntity = new Qt3DCore::QEntity(currentNode); 840 surfaceEntity->addComponent(transform); 854 surfaceEntity->addComponent(transform); 841 break; 855 break; 842 case G4ViewParameters::cloud: 856 case G4ViewParameters::cloud: 843 // Shouldn't happen in this function (it 857 // Shouldn't happen in this function (it's a polyhedron!) 844 if (errorCount == 0) { 858 if (errorCount == 0) { 845 ++errorCount; 859 ++errorCount; 846 G4warn << "WARNING: Qt3D: cloud drawin 860 G4warn << "WARNING: Qt3D: cloud drawing not implemented" << G4endl; 847 } 861 } 848 return; 862 return; 849 break; 863 break; 850 } 864 } 851 865 852 const auto vertexByteSize = 3*sizeof(PRECIS 866 const auto vertexByteSize = 3*sizeof(PRECISION); 853 867 854 G4Qt3DCompat::QGeometry* vertexGeometry = nu 868 G4Qt3DCompat::QGeometry* vertexGeometry = nullptr; 855 G4Qt3DCompat::QGeometry* lineGeometry = nu 869 G4Qt3DCompat::QGeometry* lineGeometry = nullptr; 856 870 857 G4Qt3DCompat::QAttribute* positionAtt = null 871 G4Qt3DCompat::QAttribute* positionAtt = nullptr; 858 G4Qt3DCompat::QAttribute* normalAtt = null 872 G4Qt3DCompat::QAttribute* normalAtt = nullptr; 859 G4Qt3DCompat::QAttribute* lineAtt = null 873 G4Qt3DCompat::QAttribute* lineAtt = nullptr; 860 G4Qt3DCompat::QAttribute* dummyNormalLineAtt 874 G4Qt3DCompat::QAttribute* dummyNormalLineAtt = nullptr; 861 875 862 G4Qt3DCompat::QBuffer* vertexBuffer = nullpt 876 G4Qt3DCompat::QBuffer* vertexBuffer = nullptr; 863 if (drawing_style == G4ViewParameters::hlr | 877 if (drawing_style == G4ViewParameters::hlr || 864 drawing_style == G4ViewParameters::hsr | 878 drawing_style == G4ViewParameters::hsr || 865 drawing_style == G4ViewParameters::hlhsr 879 drawing_style == G4ViewParameters::hlhsr) { 866 880 867 // Put vertices, normals into QByteArray 881 // Put vertices, normals into QByteArray 868 // Accomodates both vertices and normals - 882 // Accomodates both vertices and normals - hence 2* 869 QByteArray vertexByteArray; 883 QByteArray vertexByteArray; 870 const auto vertexBufferByteSize = 2*nVerts 884 const auto vertexBufferByteSize = 2*nVerts*vertexByteSize; 871 vertexByteArray.resize((G4int)vertexBuffer 885 vertexByteArray.resize((G4int)vertexBufferByteSize); 872 auto vertexBufferArray = reinterpret_cast< 886 auto vertexBufferArray = reinterpret_cast<PRECISION*>(vertexByteArray.data()); 873 G4int i1 = 0; 887 G4int i1 = 0; 874 for (std::size_t i = 0; i < nVerts; ++i) { 888 for (std::size_t i = 0; i < nVerts; ++i) { 875 vertexBufferArray[i1++] = vertices[i].x( 889 vertexBufferArray[i1++] = vertices[i].x(); 876 vertexBufferArray[i1++] = vertices[i].y( 890 vertexBufferArray[i1++] = vertices[i].y(); 877 vertexBufferArray[i1++] = vertices[i].z( 891 vertexBufferArray[i1++] = vertices[i].z(); 878 vertexBufferArray[i1++] = normals[i].x() 892 vertexBufferArray[i1++] = normals[i].x(); 879 vertexBufferArray[i1++] = normals[i].y() 893 vertexBufferArray[i1++] = normals[i].y(); 880 vertexBufferArray[i1++] = normals[i].z() 894 vertexBufferArray[i1++] = normals[i].z(); 881 } 895 } 882 // Vertex buffer (vertices and normals) 896 // Vertex buffer (vertices and normals) 883 vertexGeometry = new G4Qt3DCompat::QGeomet 897 vertexGeometry = new G4Qt3DCompat::QGeometry(); 884 vertexGeometry->setObjectName("vertexGeome 898 vertexGeometry->setObjectName("vertexGeometry"); 885 vertexBuffer = new G4Qt3DCompat::QBuffer(v 899 vertexBuffer = new G4Qt3DCompat::QBuffer(vertexGeometry); 886 vertexBuffer->setObjectName("Vertex buffer 900 vertexBuffer->setObjectName("Vertex buffer"); 887 vertexBuffer->setData(vertexByteArray); 901 vertexBuffer->setData(vertexByteArray); 888 902 889 // Position attribute 903 // Position attribute 890 positionAtt = new G4Qt3DCompat::QAttribute 904 positionAtt = new G4Qt3DCompat::QAttribute; 891 positionAtt->setObjectName("Position attri 905 positionAtt->setObjectName("Position attribute"); 892 positionAtt->setName(G4Qt3DCompat::QAttrib 906 positionAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName()); 893 positionAtt->setBuffer(vertexBuffer); 907 positionAtt->setBuffer(vertexBuffer); 894 positionAtt->setAttributeType(G4Qt3DCompat 908 positionAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute); 895 positionAtt->setVertexBaseType(BASETYPE); 909 positionAtt->setVertexBaseType(BASETYPE); 896 positionAtt->setVertexSize(3); 910 positionAtt->setVertexSize(3); 897 positionAtt->setCount((G4int)nVerts); 911 positionAtt->setCount((G4int)nVerts); 898 positionAtt->setByteOffset(0); 912 positionAtt->setByteOffset(0); 899 positionAtt->setByteStride(2*vertexByteSiz 913 positionAtt->setByteStride(2*vertexByteSize); 900 914 901 // Normal attribute 915 // Normal attribute 902 normalAtt = new G4Qt3DCompat::QAttribute; 916 normalAtt = new G4Qt3DCompat::QAttribute; 903 normalAtt->setObjectName("Normal attribute 917 normalAtt->setObjectName("Normal attribute"); 904 normalAtt->setName(G4Qt3DCompat::QAttribut 918 normalAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName()); 905 normalAtt->setBuffer(vertexBuffer); 919 normalAtt->setBuffer(vertexBuffer); 906 normalAtt->setAttributeType(G4Qt3DCompat:: 920 normalAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute); 907 normalAtt->setVertexBaseType(BASETYPE); 921 normalAtt->setVertexBaseType(BASETYPE); 908 normalAtt->setVertexSize(3); 922 normalAtt->setVertexSize(3); 909 normalAtt->setCount((G4int)nVerts); 923 normalAtt->setCount((G4int)nVerts); 910 normalAtt->setByteOffset(vertexByteSize); 924 normalAtt->setByteOffset(vertexByteSize); 911 normalAtt->setByteStride(2*vertexByteSize) 925 normalAtt->setByteStride(2*vertexByteSize); 912 } 926 } 913 927 914 G4Qt3DCompat::QBuffer* lineBuffer = nullptr; 928 G4Qt3DCompat::QBuffer* lineBuffer = nullptr; 915 if (drawing_style == G4ViewParameters::wiref 929 if (drawing_style == G4ViewParameters::wireframe || 916 drawing_style == G4ViewParameters::hlr | 930 drawing_style == G4ViewParameters::hlr || 917 drawing_style == G4ViewParameters::hlhsr 931 drawing_style == G4ViewParameters::hlhsr) { 918 932 919 // Put lines into a QByteArray 933 // Put lines into a QByteArray 920 QByteArray lineByteArray; 934 QByteArray lineByteArray; 921 const auto lineBufferByteSize = 2*nLines*v 935 const auto lineBufferByteSize = 2*nLines*vertexByteSize; 922 lineByteArray.resize((G4int)lineBufferByte 936 lineByteArray.resize((G4int)lineBufferByteSize); 923 auto lineBufferArray = reinterpret_cast<PR 937 auto lineBufferArray = reinterpret_cast<PRECISION*>(lineByteArray.data()); 924 G4int i2 = 0; 938 G4int i2 = 0; 925 for (const auto& line: lines) { 939 for (const auto& line: lines) { 926 lineBufferArray[i2++] = line.first.x(); 940 lineBufferArray[i2++] = line.first.x(); 927 lineBufferArray[i2++] = line.first.y(); 941 lineBufferArray[i2++] = line.first.y(); 928 lineBufferArray[i2++] = line.first.z(); 942 lineBufferArray[i2++] = line.first.z(); 929 lineBufferArray[i2++] = line.second.x(); 943 lineBufferArray[i2++] = line.second.x(); 930 lineBufferArray[i2++] = line.second.y(); 944 lineBufferArray[i2++] = line.second.y(); 931 lineBufferArray[i2++] = line.second.z(); 945 lineBufferArray[i2++] = line.second.z(); 932 } 946 } 933 // Line loop buffer 947 // Line loop buffer 934 lineGeometry = new G4Qt3DCompat::QGeometry 948 lineGeometry = new G4Qt3DCompat::QGeometry(); 935 lineGeometry->setObjectName("lineGeometry" 949 lineGeometry->setObjectName("lineGeometry"); 936 lineBuffer = new G4Qt3DCompat::QBuffer(lin 950 lineBuffer = new G4Qt3DCompat::QBuffer(lineGeometry); 937 lineBuffer->setObjectName("Line buffer"); 951 lineBuffer->setObjectName("Line buffer"); 938 lineBuffer->setData(lineByteArray); 952 lineBuffer->setData(lineByteArray); 939 953 940 // Line attribute 954 // Line attribute 941 lineAtt = new G4Qt3DCompat::QAttribute; 955 lineAtt = new G4Qt3DCompat::QAttribute; 942 lineAtt->setObjectName("Position attribute 956 lineAtt->setObjectName("Position attribute"); 943 lineAtt->setName(G4Qt3DCompat::QAttribute: 957 lineAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName()); 944 lineAtt->setBuffer(lineBuffer); 958 lineAtt->setBuffer(lineBuffer); 945 lineAtt->setAttributeType(G4Qt3DCompat::QA 959 lineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute); 946 lineAtt->setVertexBaseType(BASETYPE); 960 lineAtt->setVertexBaseType(BASETYPE); 947 lineAtt->setVertexSize(3); 961 lineAtt->setVertexSize(3); 948 lineAtt->setCount((G4int)nLines); 962 lineAtt->setCount((G4int)nLines); 949 lineAtt->setByteOffset(0); 963 lineAtt->setByteOffset(0); 950 lineAtt->setByteStride(vertexByteSize); 964 lineAtt->setByteStride(vertexByteSize); 951 // Normal attribute (a dummy with count==0 965 // Normal attribute (a dummy with count==0) (Qt6 seems to require) 952 dummyNormalLineAtt = new G4Qt3DCompat::QAt 966 dummyNormalLineAtt = new G4Qt3DCompat::QAttribute; 953 dummyNormalLineAtt->setObjectName("Normal 967 dummyNormalLineAtt->setObjectName("Normal attribute"); 954 dummyNormalLineAtt->setName(G4Qt3DCompat:: 968 dummyNormalLineAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName()); 955 dummyNormalLineAtt->setBuffer(lineBuffer); 969 dummyNormalLineAtt->setBuffer(lineBuffer); 956 dummyNormalLineAtt->setAttributeType(G4Qt3 970 dummyNormalLineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute); 957 dummyNormalLineAtt->setVertexBaseType(BASE 971 dummyNormalLineAtt->setVertexBaseType(BASETYPE); 958 dummyNormalLineAtt->setVertexSize(3); 972 dummyNormalLineAtt->setVertexSize(3); 959 dummyNormalLineAtt->setCount(0); 973 dummyNormalLineAtt->setCount(0); 960 dummyNormalLineAtt->setByteOffset(0); 974 dummyNormalLineAtt->setByteOffset(0); 961 dummyNormalLineAtt->setByteStride(vertexBy 975 dummyNormalLineAtt->setByteStride(vertexByteSize); 962 } 976 } 963 977 964 // Create material and renderer(s)... 978 // Create material and renderer(s)... 965 979 966 const auto& colour = fpVisAttribs->GetColour 980 const auto& colour = fpVisAttribs->GetColour(); 967 Qt3DExtras::QDiffuseSpecularMaterial* materi 981 Qt3DExtras::QDiffuseSpecularMaterial* material; 968 Qt3DRender::QGeometryRenderer* renderer; 982 Qt3DRender::QGeometryRenderer* renderer; 969 switch (drawing_style) { 983 switch (drawing_style) { 970 984 971 case G4ViewParameters::wireframe: 985 case G4ViewParameters::wireframe: 972 986 973 lineGeometry->addAttribute(lineAtt); 987 lineGeometry->addAttribute(lineAtt); 974 lineGeometry->addAttribute(dummyNormalLi 988 lineGeometry->addAttribute(dummyNormalLineAtt); 975 989 976 material = new Qt3DExtras::QDiffuseSpecu 990 material = new Qt3DExtras::QDiffuseSpecularMaterial(); 977 material->setObjectName("materialForWire 991 material->setObjectName("materialForWireframe"); 978 material->setAmbient(G4Qt3DUtils::Conver 992 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 979 material->setShininess(0.); 993 material->setShininess(0.); 980 material->setSpecular(0.); 994 material->setSpecular(0.); 981 wireframeEntity->addComponent(material); 995 wireframeEntity->addComponent(material); 982 996 983 renderer = new Qt3DRender::QGeometryRend 997 renderer = new Qt3DRender::QGeometryRenderer; 984 renderer->setObjectName("polyhedronWiref 998 renderer->setObjectName("polyhedronWireframeRenderer"); 985 renderer->setGeometry(lineGeometry); 999 renderer->setGeometry(lineGeometry); 986 renderer->setVertexCount(2*(G4int)nLines 1000 renderer->setVertexCount(2*(G4int)nLines); 987 renderer->setPrimitiveType(Qt3DRender::Q 1001 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines); 988 wireframeEntity->addComponent(renderer); 1002 wireframeEntity->addComponent(renderer); 989 1003 990 break; 1004 break; 991 1005 992 case G4ViewParameters::hlr: 1006 case G4ViewParameters::hlr: 993 1007 994 // Surfaces with background colour to hi 1008 // Surfaces with background colour to hide the edges 995 1009 996 vertexGeometry->addAttribute(positionAtt 1010 vertexGeometry->addAttribute(positionAtt); 997 vertexGeometry->addAttribute(normalAtt); 1011 vertexGeometry->addAttribute(normalAtt); 998 1012 999 material = new Qt3DExtras::QDiffuseSpecu 1013 material = new Qt3DExtras::QDiffuseSpecularMaterial(); 1000 material->setObjectName("materialForHid 1014 material->setObjectName("materialForHiddenLines"); 1001 material->setAmbient(Qt::white); // Wh 1015 material->setAmbient(Qt::white); // White for now (should be from fVP) 1002 material->setShininess(0.); 1016 material->setShininess(0.); 1003 material->setSpecular(0.); 1017 material->setSpecular(0.); 1004 surfaceEntity->addComponent(material); 1018 surfaceEntity->addComponent(material); 1005 1019 1006 renderer = new Qt3DRender::QGeometryRen 1020 renderer = new Qt3DRender::QGeometryRenderer; 1007 renderer->setObjectName("polyhedronSurf 1021 renderer->setObjectName("polyhedronSurfaceRenderer"); 1008 renderer->setGeometry(vertexGeometry); 1022 renderer->setGeometry(vertexGeometry); 1009 renderer->setVertexCount((G4int)nVerts) 1023 renderer->setVertexCount((G4int)nVerts); 1010 renderer->setPrimitiveType(Qt3DRender:: 1024 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); 1011 surfaceEntity->addComponent(renderer); 1025 surfaceEntity->addComponent(renderer); 1012 1026 1013 // Edges 1027 // Edges 1014 1028 1015 lineGeometry->addAttribute(lineAtt); 1029 lineGeometry->addAttribute(lineAtt); 1016 lineGeometry->addAttribute(dummyNormalL 1030 lineGeometry->addAttribute(dummyNormalLineAtt); 1017 1031 1018 material = new Qt3DExtras::QDiffuseSpec 1032 material = new Qt3DExtras::QDiffuseSpecularMaterial(); 1019 material->setObjectName("materialForWir 1033 material->setObjectName("materialForWireFrame"); 1020 material->setAmbient(G4Qt3DUtils::Conve 1034 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 1021 material->setShininess(0.); 1035 material->setShininess(0.); 1022 material->setSpecular(0.); 1036 material->setSpecular(0.); 1023 wireframeEntity->addComponent(material) 1037 wireframeEntity->addComponent(material); 1024 1038 1025 renderer = new Qt3DRender::QGeometryRen 1039 renderer = new Qt3DRender::QGeometryRenderer; 1026 renderer->setObjectName("polyhedronWire 1040 renderer->setObjectName("polyhedronWireframeRenderer"); 1027 renderer->setGeometry(lineGeometry); 1041 renderer->setGeometry(lineGeometry); 1028 renderer->setVertexCount(2*(G4int)nLine 1042 renderer->setVertexCount(2*(G4int)nLines); 1029 renderer->setPrimitiveType(Qt3DRender:: 1043 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines); 1030 wireframeEntity->addComponent(renderer) 1044 wireframeEntity->addComponent(renderer); 1031 1045 1032 break; 1046 break; 1033 1047 1034 case G4ViewParameters::hsr: 1048 case G4ViewParameters::hsr: 1035 1049 1036 vertexGeometry->addAttribute(positionAt 1050 vertexGeometry->addAttribute(positionAtt); 1037 vertexGeometry->addAttribute(normalAtt) 1051 vertexGeometry->addAttribute(normalAtt); 1038 1052 1039 material = new Qt3DExtras::QDiffuseSpec 1053 material = new Qt3DExtras::QDiffuseSpecularMaterial(); 1040 material->setObjectName("materialForSur 1054 material->setObjectName("materialForSurface"); 1041 material->setAmbient(G4Qt3DUtils::Conve 1055 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 1042 if (colour.GetAlpha() < 1.) material->s 1056 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(true); 1043 surfaceEntity->addComponent(material); 1057 surfaceEntity->addComponent(material); 1044 1058 1045 renderer = new Qt3DRender::QGeometryRen 1059 renderer = new Qt3DRender::QGeometryRenderer; 1046 renderer->setObjectName("polyhedronSurf 1060 renderer->setObjectName("polyhedronSurfaceRenderer"); 1047 renderer->setGeometry(vertexGeometry); 1061 renderer->setGeometry(vertexGeometry); 1048 renderer->setVertexCount((G4int)nVerts) 1062 renderer->setVertexCount((G4int)nVerts); 1049 renderer->setPrimitiveType(Qt3DRender:: 1063 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); 1050 surfaceEntity->addComponent(renderer); 1064 surfaceEntity->addComponent(renderer); 1051 1065 1052 break; 1066 break; 1053 1067 1054 case G4ViewParameters::hlhsr: 1068 case G4ViewParameters::hlhsr: 1055 1069 1056 // Surfaces 1070 // Surfaces 1057 1071 1058 vertexGeometry->addAttribute(positionAt 1072 vertexGeometry->addAttribute(positionAtt); 1059 vertexGeometry->addAttribute(normalAtt) 1073 vertexGeometry->addAttribute(normalAtt); 1060 1074 1061 material = new Qt3DExtras::QDiffuseSpec 1075 material = new Qt3DExtras::QDiffuseSpecularMaterial(); 1062 material->setObjectName("materialForSur 1076 material->setObjectName("materialForSurface"); 1063 material->setAmbient(G4Qt3DUtils::Conve 1077 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 1064 if (colour.GetAlpha() < 1.) material->s 1078 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(true); 1065 surfaceEntity->addComponent(material); 1079 surfaceEntity->addComponent(material); 1066 1080 1067 renderer = new Qt3DRender::QGeometryRen 1081 renderer = new Qt3DRender::QGeometryRenderer; 1068 renderer->setObjectName("polyhedronSurf 1082 renderer->setObjectName("polyhedronSurfaceRenderer"); 1069 renderer->setGeometry(vertexGeometry); 1083 renderer->setGeometry(vertexGeometry); 1070 renderer->setVertexCount((G4int)nVerts) 1084 renderer->setVertexCount((G4int)nVerts); 1071 renderer->setPrimitiveType(Qt3DRender:: 1085 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); 1072 surfaceEntity->addComponent(renderer); 1086 surfaceEntity->addComponent(renderer); 1073 1087 1074 // Edges 1088 // Edges 1075 1089 1076 lineGeometry->addAttribute(lineAtt); 1090 lineGeometry->addAttribute(lineAtt); 1077 lineGeometry->addAttribute(dummyNormalL 1091 lineGeometry->addAttribute(dummyNormalLineAtt); 1078 1092 1079 material = new Qt3DExtras::QDiffuseSpec 1093 material = new Qt3DExtras::QDiffuseSpecularMaterial(); 1080 material->setObjectName("materialForWir 1094 material->setObjectName("materialForWireframe"); 1081 material->setAmbient(G4Qt3DUtils::Conve 1095 material->setAmbient(G4Qt3DUtils::ConvertToQColor(colour)); 1082 material->setShininess(0.); 1096 material->setShininess(0.); 1083 material->setSpecular(0.); 1097 material->setSpecular(0.); 1084 wireframeEntity->addComponent(material) 1098 wireframeEntity->addComponent(material); 1085 1099 1086 renderer = new Qt3DRender::QGeometryRen 1100 renderer = new Qt3DRender::QGeometryRenderer; 1087 renderer->setObjectName("polyhedronSurf 1101 renderer->setObjectName("polyhedronSurfaceRenderer"); 1088 renderer->setGeometry(lineGeometry); 1102 renderer->setGeometry(lineGeometry); 1089 renderer->setVertexCount(2*(G4int)nLine 1103 renderer->setVertexCount(2*(G4int)nLines); 1090 renderer->setPrimitiveType(Qt3DRender:: 1104 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines); 1091 wireframeEntity->addComponent(renderer) 1105 wireframeEntity->addComponent(renderer); 1092 1106 1093 break; 1107 break; 1094 1108 1095 case G4ViewParameters::cloud: 1109 case G4ViewParameters::cloud: 1096 // Case trapped at start of function, s 1110 // Case trapped at start of function, so no need to implement 1097 break; 1111 break; 1098 } 1112 } 1099 } 1113 } 1100 1114 1101 void G4Qt3DSceneHandler::AddCompound(const G4 1115 void G4Qt3DSceneHandler::AddCompound(const G4Mesh& mesh) 1102 { 1116 { 1103 StandardSpecialMeshRendering(mesh); 1117 StandardSpecialMeshRendering(mesh); 1104 } 1118 } 1105 1119 1106 void G4Qt3DSceneHandler::ClearStore () 1120 void G4Qt3DSceneHandler::ClearStore () 1107 { 1121 { 1108 G4Qt3DUtils::delete_components_and_children 1122 G4Qt3DUtils::delete_components_and_children_of_entity_recursively(fpQt3DScene); 1109 EstablishG4Qt3DQEntities(); 1123 EstablishG4Qt3DQEntities(); 1110 } 1124 } 1111 1125 1112 void G4Qt3DSceneHandler::ClearTransientStore 1126 void G4Qt3DSceneHandler::ClearTransientStore () 1113 { 1127 { 1114 G4Qt3DUtils::delete_components_and_children 1128 G4Qt3DUtils::delete_components_and_children_of_entity_recursively(fpTransientObjects); 1115 } 1129 } 1116 1130