284 "G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
289 if (polyline.size() == 0)
return;
293 static G4bool first =
true;
296 G4Exception(
"G4Qt3DSceneHandler::AddPrimitive(const G4Polyline&)",
298 "No available node!");
306 transform->setObjectName(
"transform");
308 auto polylineEntity =
new Qt3DCore::QEntity(currentNode);
309 polylineEntity->addComponent(transform);
311 const auto vertexByteSize = 3*
sizeof(
PRECISION);
313 const std::size_t nLines = polyline.size() - 1;
314 QByteArray polylineByteArray;
315 const auto polylineBufferByteSize = 2*nLines*vertexByteSize;
316 polylineByteArray.resize((
G4int)polylineBufferByteSize);
317 auto polylineBufferArray =
reinterpret_cast<PRECISION*
>(polylineByteArray.data());
319 for (std::size_t i = 0; i < nLines; ++i) {
320 polylineBufferArray[iLine++] = polyline[i].x();
321 polylineBufferArray[iLine++] = polyline[i].y();
322 polylineBufferArray[iLine++] = polyline[i].z();
323 polylineBufferArray[iLine++] = polyline[i+1].x();
324 polylineBufferArray[iLine++] = polyline[i+1].y();
325 polylineBufferArray[iLine++] = polyline[i+1].z();
327 auto polylineGeometry =
new G4Qt3DCompat::QGeometry();
328 polylineGeometry->setObjectName(
"polylineGeometry");
330 auto polylineBuffer =
new G4Qt3DCompat::QBuffer(polylineGeometry);
331 polylineBuffer->setObjectName(
"Polyline buffer");
332 polylineBuffer->setData(polylineByteArray);
334 auto polylineAtt =
new G4Qt3DCompat::QAttribute;
335 polylineAtt->setObjectName(
"Position attribute");
336 polylineAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
337 polylineAtt->setBuffer(polylineBuffer);
338 polylineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
339 polylineAtt->setVertexBaseType(
BASETYPE);
340 polylineAtt->setVertexSize(3);
341 polylineAtt->setCount((
G4int)nLines);
342 polylineAtt->setByteOffset(0);
343 polylineAtt->setByteStride(vertexByteSize);
345 auto dummyNormalLineAtt =
new G4Qt3DCompat::QAttribute;
346 dummyNormalLineAtt->setObjectName(
"Normal attribute");
347 dummyNormalLineAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName());
348 dummyNormalLineAtt->setBuffer(polylineBuffer);
349 dummyNormalLineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
350 dummyNormalLineAtt->setVertexBaseType(
BASETYPE);
351 dummyNormalLineAtt->setVertexSize(3);
352 dummyNormalLineAtt->setCount(0);
353 dummyNormalLineAtt->setByteOffset(0);
354 dummyNormalLineAtt->setByteStride(vertexByteSize);
358 polylineGeometry->addAttribute(polylineAtt);
359 polylineGeometry->addAttribute(dummyNormalLineAtt);
361 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
362 material->setObjectName(
"materialForPolyline");
364 material->setShininess(0.);
365 material->setSpecular(0.);
366 polylineEntity->addComponent(material);
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);
377 renderer->setObjectName(
"polylineRenderer");
378 renderer->setGeometry(polylineGeometry);
379 renderer->setVertexCount(2*(
G4int)nLines);
380 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
382 polylineEntity->addComponent(renderer);
387 if (polymarker.size() == 0)
return;
391 static G4bool first =
true;
394 G4Exception(
"G4Qt3DSceneHandler::AddPrimitive(const G4Polymarker&)",
396 "No available node!");
410 const std::size_t nDots = polymarker.size();
413 transform->setObjectName(
"transform");
415 auto polymarkerEntity =
new Qt3DCore::QEntity(currentNode);
416 polymarkerEntity->addComponent(transform);
418 const auto vertexByteSize = 3*
sizeof(
PRECISION);
420 QByteArray polymarkerByteArray;
421 const auto polymarkerBufferByteSize = nDots*vertexByteSize;
422 polymarkerByteArray.resize((
G4int)polymarkerBufferByteSize);
423 auto polymarkerBufferArray =
reinterpret_cast<PRECISION*
>(polymarkerByteArray.data());
425 for (std::size_t i = 0; i < polymarker.size(); ++i) {
426 polymarkerBufferArray[iMarker++] = polymarker[i].x();
427 polymarkerBufferArray[iMarker++] = polymarker[i].y();
428 polymarkerBufferArray[iMarker++] = polymarker[i].z();
430 auto polymarkerGeometry =
new G4Qt3DCompat::QGeometry();
431 polymarkerGeometry->setObjectName(
"polymarkerGeometry");
432 auto polymarkerBuffer =
new G4Qt3DCompat::QBuffer(polymarkerGeometry);
433 polymarkerBuffer->setObjectName(
"Polymarker buffer");
434 polymarkerBuffer->setData(polymarkerByteArray);
436 auto polymarkerAtt =
new G4Qt3DCompat::QAttribute;
437 polymarkerAtt->setObjectName(
"Position attribute");
438 polymarkerAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
439 polymarkerAtt->setBuffer(polymarkerBuffer);
440 polymarkerAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
441 polymarkerAtt->setVertexBaseType(
BASETYPE);
442 polymarkerAtt->setVertexSize(3);
443 polymarkerAtt->setCount((
G4int)nDots);
444 polymarkerAtt->setByteOffset(0);
445 polymarkerAtt->setByteStride(vertexByteSize);
449 polymarkerGeometry->addAttribute(polymarkerAtt);
451 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
452 material->setObjectName(
"materialForPolymarker");
454 material->setShininess(0.);
455 material->setSpecular(0.);
456 polymarkerEntity->addComponent(material);
458 auto renderer =
new Qt3DRender::QGeometryRenderer;
459 renderer->setObjectName(
"polymarkerWireframeRenderer");
460 renderer->setGeometry(polymarkerGeometry);
461 renderer->setVertexCount((
G4int)nDots);
462 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Points);
463 polymarkerEntity->addComponent(renderer);
471 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
472 material->setObjectName(
"materialForCircle");
474 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
476 auto sphereMesh =
new Qt3DExtras::QSphereMesh;
477 sphereMesh->setObjectName(
"sphereMesh");
484 sphereMesh->setRadius(radius);
488 for (std::size_t iPoint = 0; iPoint < polymarker.size(); ++iPoint) {
491 auto currentEntity =
new Qt3DCore::QEntity(currentNode);
492 currentEntity->addComponent(material);
493 currentEntity->addComponent(transform);
494 currentEntity->addComponent(sphereMesh);
503 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
504 material->setObjectName(
"materialForSquare");
506 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
508 auto boxMesh =
new Qt3DExtras::QCuboidMesh();
509 boxMesh->setObjectName(
"boxMesh");
516 boxMesh->setXExtent(side);
517 boxMesh->setYExtent(side);
518 boxMesh->setZExtent(side);
520 for (std::size_t iPoint = 0; iPoint < polymarker.size(); ++iPoint) {
523 auto currentEntity =
new Qt3DCore::QEntity(currentNode);
524 currentEntity->addComponent(material);
525 currentEntity->addComponent(transform);
526 currentEntity->addComponent(boxMesh);
744 static G4bool first =
true;
747 G4Exception(
"G4Qt3DSceneHandler::AddPrimitive(const G4Polyhedron&)",
749 "No available node!");
765 std::vector<G4Point3D> vertices;
766 std::vector<G4Normal3D> normals;
770 typedef std::pair<G4Point3D,G4Point3D> Line;
771 std::vector<Line> lines;
772 auto insertIfNew = [&lines](
const Line& newLine) {
781 lines.push_back(newLine);
791 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normal);
792 vertices.push_back(vertex[0]);
793 vertices.push_back(vertex[1]);
794 vertices.push_back(vertex[2]);
795 normals.push_back(normal[0]);
796 normals.push_back(normal[1]);
797 normals.push_back(normal[2]);
798 if(isAuxilaryEdgeVisible||edgeFlag[0]>0)insertIfNew(Line(vertex[0],vertex[1]));
799 if(isAuxilaryEdgeVisible||edgeFlag[1]>0)insertIfNew(Line(vertex[1],vertex[2]));
803 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[0]));
804 }
else if (nEdges == 4) {
807 vertices.push_back(vertex[2]);
808 vertices.push_back(vertex[3]);
809 vertices.push_back(vertex[0]);
810 normals.push_back(normal[2]);
811 normals.push_back(normal[3]);
812 normals.push_back(normal[0]);
813 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[3]));
814 if(isAuxilaryEdgeVisible||edgeFlag[3]>0)insertIfNew(Line(vertex[3],vertex[0]));
817 <<
"ERROR: polyhedron face with unexpected number of edges (" << nEdges <<
')'
822 }
while (notLastFace);
823 const auto nVerts = vertices.size();
824 const auto nLines = lines.size();
829 transform->setObjectName(
"transform");
831 Qt3DCore::QEntity* wireframeEntity =
nullptr;
832 Qt3DCore::QEntity* surfaceEntity =
nullptr;
833 static G4int errorCount = 0;
835 switch (drawing_style) {
837 wireframeEntity =
new Qt3DCore::QEntity(currentNode);
838 wireframeEntity->addComponent(transform);
841 wireframeEntity =
new Qt3DCore::QEntity(currentNode);
842 wireframeEntity->addComponent(transform);
843 surfaceEntity =
new Qt3DCore::QEntity(currentNode);
844 surfaceEntity->addComponent(transform);
847 surfaceEntity =
new Qt3DCore::QEntity(currentNode);
848 surfaceEntity->addComponent(transform);
851 wireframeEntity =
new Qt3DCore::QEntity(currentNode);
852 wireframeEntity->addComponent(transform);
853 surfaceEntity =
new Qt3DCore::QEntity(currentNode);
854 surfaceEntity->addComponent(transform);
858 if (errorCount == 0) {
860 G4warn <<
"WARNING: Qt3D: cloud drawing not implemented" <<
G4endl;
866 const auto vertexByteSize = 3*
sizeof(
PRECISION);
868 G4Qt3DCompat::QGeometry* vertexGeometry =
nullptr;
869 G4Qt3DCompat::QGeometry* lineGeometry =
nullptr;
871 G4Qt3DCompat::QAttribute* positionAtt =
nullptr;
872 G4Qt3DCompat::QAttribute* normalAtt =
nullptr;
873 G4Qt3DCompat::QAttribute* lineAtt =
nullptr;
874 G4Qt3DCompat::QAttribute* dummyNormalLineAtt =
nullptr;
876 G4Qt3DCompat::QBuffer* vertexBuffer =
nullptr;
883 QByteArray vertexByteArray;
884 const auto vertexBufferByteSize = 2*nVerts*vertexByteSize;
885 vertexByteArray.resize((
G4int)vertexBufferByteSize);
886 auto vertexBufferArray =
reinterpret_cast<PRECISION*
>(vertexByteArray.data());
888 for (std::size_t i = 0; i < nVerts; ++i) {
889 vertexBufferArray[i1++] = vertices[i].x();
890 vertexBufferArray[i1++] = vertices[i].y();
891 vertexBufferArray[i1++] = vertices[i].z();
892 vertexBufferArray[i1++] = normals[i].x();
893 vertexBufferArray[i1++] = normals[i].y();
894 vertexBufferArray[i1++] = normals[i].z();
897 vertexGeometry =
new G4Qt3DCompat::QGeometry();
898 vertexGeometry->setObjectName(
"vertexGeometry");
899 vertexBuffer =
new G4Qt3DCompat::QBuffer(vertexGeometry);
900 vertexBuffer->setObjectName(
"Vertex buffer");
901 vertexBuffer->setData(vertexByteArray);
904 positionAtt =
new G4Qt3DCompat::QAttribute;
905 positionAtt->setObjectName(
"Position attribute");
906 positionAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
907 positionAtt->setBuffer(vertexBuffer);
908 positionAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
909 positionAtt->setVertexBaseType(
BASETYPE);
910 positionAtt->setVertexSize(3);
911 positionAtt->setCount((
G4int)nVerts);
912 positionAtt->setByteOffset(0);
913 positionAtt->setByteStride(2*vertexByteSize);
916 normalAtt =
new G4Qt3DCompat::QAttribute;
917 normalAtt->setObjectName(
"Normal attribute");
918 normalAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName());
919 normalAtt->setBuffer(vertexBuffer);
920 normalAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
921 normalAtt->setVertexBaseType(
BASETYPE);
922 normalAtt->setVertexSize(3);
923 normalAtt->setCount((
G4int)nVerts);
924 normalAtt->setByteOffset(vertexByteSize);
925 normalAtt->setByteStride(2*vertexByteSize);
928 G4Qt3DCompat::QBuffer* lineBuffer =
nullptr;
934 QByteArray lineByteArray;
935 const auto lineBufferByteSize = 2*nLines*vertexByteSize;
936 lineByteArray.resize((
G4int)lineBufferByteSize);
937 auto lineBufferArray =
reinterpret_cast<PRECISION*
>(lineByteArray.data());
939 for (
const auto& line: lines) {
940 lineBufferArray[i2++] = line.first.x();
941 lineBufferArray[i2++] = line.first.y();
942 lineBufferArray[i2++] = line.first.z();
943 lineBufferArray[i2++] = line.second.x();
944 lineBufferArray[i2++] = line.second.y();
945 lineBufferArray[i2++] = line.second.z();
948 lineGeometry =
new G4Qt3DCompat::QGeometry();
949 lineGeometry->setObjectName(
"lineGeometry");
950 lineBuffer =
new G4Qt3DCompat::QBuffer(lineGeometry);
951 lineBuffer->setObjectName(
"Line buffer");
952 lineBuffer->setData(lineByteArray);
955 lineAtt =
new G4Qt3DCompat::QAttribute;
956 lineAtt->setObjectName(
"Position attribute");
957 lineAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
958 lineAtt->setBuffer(lineBuffer);
959 lineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
960 lineAtt->setVertexBaseType(
BASETYPE);
961 lineAtt->setVertexSize(3);
962 lineAtt->setCount((
G4int)nLines);
963 lineAtt->setByteOffset(0);
964 lineAtt->setByteStride(vertexByteSize);
966 dummyNormalLineAtt =
new G4Qt3DCompat::QAttribute;
967 dummyNormalLineAtt->setObjectName(
"Normal attribute");
968 dummyNormalLineAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName());
969 dummyNormalLineAtt->setBuffer(lineBuffer);
970 dummyNormalLineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
971 dummyNormalLineAtt->setVertexBaseType(
BASETYPE);
972 dummyNormalLineAtt->setVertexSize(3);
973 dummyNormalLineAtt->setCount(0);
974 dummyNormalLineAtt->setByteOffset(0);
975 dummyNormalLineAtt->setByteStride(vertexByteSize);
981 Qt3DExtras::QDiffuseSpecularMaterial* material;
982 Qt3DRender::QGeometryRenderer* renderer;
983 switch (drawing_style) {
987 lineGeometry->addAttribute(lineAtt);
988 lineGeometry->addAttribute(dummyNormalLineAtt);
990 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
991 material->setObjectName(
"materialForWireframe");
993 material->setShininess(0.);
994 material->setSpecular(0.);
995 wireframeEntity->addComponent(material);
997 renderer =
new Qt3DRender::QGeometryRenderer;
998 renderer->setObjectName(
"polyhedronWireframeRenderer");
999 renderer->setGeometry(lineGeometry);
1000 renderer->setVertexCount(2*(
G4int)nLines);
1001 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
1002 wireframeEntity->addComponent(renderer);
1010 vertexGeometry->addAttribute(positionAtt);
1011 vertexGeometry->addAttribute(normalAtt);
1013 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1014 material->setObjectName(
"materialForHiddenLines");
1015 material->setAmbient(Qt::white);
1016 material->setShininess(0.);
1017 material->setSpecular(0.);
1018 surfaceEntity->addComponent(material);
1020 renderer =
new Qt3DRender::QGeometryRenderer;
1021 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1022 renderer->setGeometry(vertexGeometry);
1023 renderer->setVertexCount((
G4int)nVerts);
1024 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
1025 surfaceEntity->addComponent(renderer);
1029 lineGeometry->addAttribute(lineAtt);
1030 lineGeometry->addAttribute(dummyNormalLineAtt);
1032 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1033 material->setObjectName(
"materialForWireFrame");
1035 material->setShininess(0.);
1036 material->setSpecular(0.);
1037 wireframeEntity->addComponent(material);
1039 renderer =
new Qt3DRender::QGeometryRenderer;
1040 renderer->setObjectName(
"polyhedronWireframeRenderer");
1041 renderer->setGeometry(lineGeometry);
1042 renderer->setVertexCount(2*(
G4int)nLines);
1043 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
1044 wireframeEntity->addComponent(renderer);
1050 vertexGeometry->addAttribute(positionAtt);
1051 vertexGeometry->addAttribute(normalAtt);
1053 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1054 material->setObjectName(
"materialForSurface");
1056 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
1057 surfaceEntity->addComponent(material);
1059 renderer =
new Qt3DRender::QGeometryRenderer;
1060 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1061 renderer->setGeometry(vertexGeometry);
1062 renderer->setVertexCount((
G4int)nVerts);
1063 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
1064 surfaceEntity->addComponent(renderer);
1072 vertexGeometry->addAttribute(positionAtt);
1073 vertexGeometry->addAttribute(normalAtt);
1075 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1076 material->setObjectName(
"materialForSurface");
1078 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
1079 surfaceEntity->addComponent(material);
1081 renderer =
new Qt3DRender::QGeometryRenderer;
1082 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1083 renderer->setGeometry(vertexGeometry);
1084 renderer->setVertexCount((
G4int)nVerts);
1085 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
1086 surfaceEntity->addComponent(renderer);
1090 lineGeometry->addAttribute(lineAtt);
1091 lineGeometry->addAttribute(dummyNormalLineAtt);
1093 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1094 material->setObjectName(
"materialForWireframe");
1096 material->setShininess(0.);
1097 material->setSpecular(0.);
1098 wireframeEntity->addComponent(material);
1100 renderer =
new Qt3DRender::QGeometryRenderer;
1101 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1102 renderer->setGeometry(lineGeometry);
1103 renderer->setVertexCount(2*(
G4int)nLines);
1104 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
1105 wireframeEntity->addComponent(renderer);