279 "G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
284 if (polyline.size() == 0)
return;
288 static G4bool first =
true;
291 G4Exception(
"G4Qt3DSceneHandler::AddPrimitive(const G4Polyline&)",
293 "No available node!");
301 transform->setObjectName(
"transform");
303 auto polylineEntity =
new Qt3DCore::QEntity(currentNode);
304 polylineEntity->addComponent(transform);
306 const auto vertexByteSize = 3*
sizeof(
PRECISION);
308 const std::size_t nLines = polyline.size() - 1;
309 QByteArray polylineByteArray;
310 const auto polylineBufferByteSize = 2*nLines*vertexByteSize;
311 polylineByteArray.resize((
G4int)polylineBufferByteSize);
312 auto polylineBufferArray =
reinterpret_cast<PRECISION*
>(polylineByteArray.data());
314 for (std::size_t i = 0; i < nLines; ++i) {
315 polylineBufferArray[iLine++] = polyline[i].x();
316 polylineBufferArray[iLine++] = polyline[i].y();
317 polylineBufferArray[iLine++] = polyline[i].z();
318 polylineBufferArray[iLine++] = polyline[i+1].x();
319 polylineBufferArray[iLine++] = polyline[i+1].y();
320 polylineBufferArray[iLine++] = polyline[i+1].z();
322 auto polylineGeometry =
new G4Qt3DCompat::QGeometry();
323 polylineGeometry->setObjectName(
"polylineGeometry");
325 auto polylineBuffer =
new G4Qt3DCompat::QBuffer(polylineGeometry);
326 polylineBuffer->setObjectName(
"Polyline buffer");
327 polylineBuffer->setData(polylineByteArray);
329 auto polylineAtt =
new G4Qt3DCompat::QAttribute;
330 polylineAtt->setObjectName(
"Position attribute");
331 polylineAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
332 polylineAtt->setBuffer(polylineBuffer);
333 polylineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
334 polylineAtt->setVertexBaseType(
BASETYPE);
335 polylineAtt->setVertexSize(3);
336 polylineAtt->setCount((
G4int)nLines);
337 polylineAtt->setByteOffset(0);
338 polylineAtt->setByteStride(vertexByteSize);
340 auto dummyNormalLineAtt =
new G4Qt3DCompat::QAttribute;
341 dummyNormalLineAtt->setObjectName(
"Normal attribute");
342 dummyNormalLineAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName());
343 dummyNormalLineAtt->setBuffer(polylineBuffer);
344 dummyNormalLineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
345 dummyNormalLineAtt->setVertexBaseType(
BASETYPE);
346 dummyNormalLineAtt->setVertexSize(3);
347 dummyNormalLineAtt->setCount(0);
348 dummyNormalLineAtt->setByteOffset(0);
349 dummyNormalLineAtt->setByteStride(vertexByteSize);
353 polylineGeometry->addAttribute(polylineAtt);
354 polylineGeometry->addAttribute(dummyNormalLineAtt);
356 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
357 material->setObjectName(
"materialForPolyline");
359 material->setShininess(0.);
360 material->setSpecular(0.);
361 polylineEntity->addComponent(material);
363 auto renderer =
new Qt3DRender::QGeometryRenderer;
364 renderer->setObjectName(
"polylineRenderer");
365 renderer->setGeometry(polylineGeometry);
366 renderer->setVertexCount(2*(
G4int)nLines);
367 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
368 polylineEntity->addComponent(renderer);
373 if (polymarker.size() == 0)
return;
377 static G4bool first =
true;
380 G4Exception(
"G4Qt3DSceneHandler::AddPrimitive(const G4Polymarker&)",
382 "No available node!");
396 const std::size_t nDots = polymarker.size();
399 transform->setObjectName(
"transform");
401 auto polymarkerEntity =
new Qt3DCore::QEntity(currentNode);
402 polymarkerEntity->addComponent(transform);
404 const auto vertexByteSize = 3*
sizeof(
PRECISION);
406 QByteArray polymarkerByteArray;
407 const auto polymarkerBufferByteSize = nDots*vertexByteSize;
408 polymarkerByteArray.resize((
G4int)polymarkerBufferByteSize);
409 auto polymarkerBufferArray =
reinterpret_cast<PRECISION*
>(polymarkerByteArray.data());
411 for (std::size_t i = 0; i < polymarker.size(); ++i) {
412 polymarkerBufferArray[iMarker++] = polymarker[i].x();
413 polymarkerBufferArray[iMarker++] = polymarker[i].y();
414 polymarkerBufferArray[iMarker++] = polymarker[i].z();
416 auto polymarkerGeometry =
new G4Qt3DCompat::QGeometry();
417 polymarkerGeometry->setObjectName(
"polymarkerGeometry");
418 auto polymarkerBuffer =
new G4Qt3DCompat::QBuffer(polymarkerGeometry);
419 polymarkerBuffer->setObjectName(
"Polymarker buffer");
420 polymarkerBuffer->setData(polymarkerByteArray);
422 auto polymarkerAtt =
new G4Qt3DCompat::QAttribute;
423 polymarkerAtt->setObjectName(
"Position attribute");
424 polymarkerAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
425 polymarkerAtt->setBuffer(polymarkerBuffer);
426 polymarkerAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
427 polymarkerAtt->setVertexBaseType(
BASETYPE);
428 polymarkerAtt->setVertexSize(3);
429 polymarkerAtt->setCount((
G4int)nDots);
430 polymarkerAtt->setByteOffset(0);
431 polymarkerAtt->setByteStride(vertexByteSize);
435 polymarkerGeometry->addAttribute(polymarkerAtt);
437 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
438 material->setObjectName(
"materialForPolymarker");
440 material->setShininess(0.);
441 material->setSpecular(0.);
442 polymarkerEntity->addComponent(material);
444 auto renderer =
new Qt3DRender::QGeometryRenderer;
445 renderer->setObjectName(
"polymarkerWireframeRenderer");
446 renderer->setGeometry(polymarkerGeometry);
447 renderer->setVertexCount((
G4int)nDots);
448 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Points);
449 polymarkerEntity->addComponent(renderer);
457 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
458 material->setObjectName(
"materialForCircle");
460 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
462 auto sphereMesh =
new Qt3DExtras::QSphereMesh;
463 sphereMesh->setObjectName(
"sphereMesh");
468 radius *=
fpScene->GetExtent().GetExtentRadius()/scale;
470 sphereMesh->setRadius(radius);
474 for (std::size_t iPoint = 0; iPoint < polymarker.size(); ++iPoint) {
477 auto currentEntity =
new Qt3DCore::QEntity(currentNode);
478 currentEntity->addComponent(material);
479 currentEntity->addComponent(transform);
480 currentEntity->addComponent(sphereMesh);
489 auto material =
new Qt3DExtras::QDiffuseSpecularMaterial();
490 material->setObjectName(
"materialForSquare");
492 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
494 auto boxMesh =
new Qt3DExtras::QCuboidMesh();
495 boxMesh->setObjectName(
"boxMesh");
500 side *=
fpScene->GetExtent().GetExtentRadius()/scale;
502 boxMesh->setXExtent(side);
503 boxMesh->setYExtent(side);
504 boxMesh->setZExtent(side);
506 for (std::size_t iPoint = 0; iPoint < polymarker.size(); ++iPoint) {
509 auto currentEntity =
new Qt3DCore::QEntity(currentNode);
510 currentEntity->addComponent(material);
511 currentEntity->addComponent(transform);
512 currentEntity->addComponent(boxMesh);
730 static G4bool first =
true;
733 G4Exception(
"G4Qt3DSceneHandler::AddPrimitive(const G4Polyhedron&)",
735 "No available node!");
751 std::vector<G4Point3D> vertices;
752 std::vector<G4Normal3D> normals;
756 typedef std::pair<G4Point3D,G4Point3D> Line;
757 std::vector<Line> lines;
758 auto insertIfNew = [&lines](
const Line& newLine) {
767 lines.push_back(newLine);
770 G4bool isAuxilaryEdgeVisible =
fpViewer->GetViewParameters().IsAuxEdgeVisible();
777 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normal);
778 vertices.push_back(vertex[0]);
779 vertices.push_back(vertex[1]);
780 vertices.push_back(vertex[2]);
781 normals.push_back(normal[0]);
782 normals.push_back(normal[1]);
783 normals.push_back(normal[2]);
784 if(isAuxilaryEdgeVisible||edgeFlag[0]>0)insertIfNew(Line(vertex[0],vertex[1]));
785 if(isAuxilaryEdgeVisible||edgeFlag[1]>0)insertIfNew(Line(vertex[1],vertex[2]));
789 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[0]));
790 }
else if (nEdges == 4) {
793 vertices.push_back(vertex[2]);
794 vertices.push_back(vertex[3]);
795 vertices.push_back(vertex[0]);
796 normals.push_back(normal[2]);
797 normals.push_back(normal[3]);
798 normals.push_back(normal[0]);
799 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[3]));
800 if(isAuxilaryEdgeVisible||edgeFlag[3]>0)insertIfNew(Line(vertex[3],vertex[0]));
803 <<
"ERROR: polyhedron face with unexpected number of edges (" << nEdges <<
')'
804 <<
"\n Tag: " <<
fpModel->GetCurrentTag()
808 }
while (notLastFace);
809 const auto nVerts = vertices.size();
810 const auto nLines = lines.size();
815 transform->setObjectName(
"transform");
817 Qt3DCore::QEntity* wireframeEntity =
nullptr;
818 Qt3DCore::QEntity* surfaceEntity =
nullptr;
819 static G4int errorCount = 0;
821 switch (drawing_style) {
823 wireframeEntity =
new Qt3DCore::QEntity(currentNode);
824 wireframeEntity->addComponent(transform);
827 wireframeEntity =
new Qt3DCore::QEntity(currentNode);
828 wireframeEntity->addComponent(transform);
829 surfaceEntity =
new Qt3DCore::QEntity(currentNode);
830 surfaceEntity->addComponent(transform);
833 surfaceEntity =
new Qt3DCore::QEntity(currentNode);
834 surfaceEntity->addComponent(transform);
837 wireframeEntity =
new Qt3DCore::QEntity(currentNode);
838 wireframeEntity->addComponent(transform);
839 surfaceEntity =
new Qt3DCore::QEntity(currentNode);
840 surfaceEntity->addComponent(transform);
844 if (errorCount == 0) {
846 G4warn <<
"WARNING: Qt3D: cloud drawing not implemented" <<
G4endl;
852 const auto vertexByteSize = 3*
sizeof(
PRECISION);
854 G4Qt3DCompat::QGeometry* vertexGeometry =
nullptr;
855 G4Qt3DCompat::QGeometry* lineGeometry =
nullptr;
857 G4Qt3DCompat::QAttribute* positionAtt =
nullptr;
858 G4Qt3DCompat::QAttribute* normalAtt =
nullptr;
859 G4Qt3DCompat::QAttribute* lineAtt =
nullptr;
860 G4Qt3DCompat::QAttribute* dummyNormalLineAtt =
nullptr;
862 G4Qt3DCompat::QBuffer* vertexBuffer =
nullptr;
869 QByteArray vertexByteArray;
870 const auto vertexBufferByteSize = 2*nVerts*vertexByteSize;
871 vertexByteArray.resize((
G4int)vertexBufferByteSize);
872 auto vertexBufferArray =
reinterpret_cast<PRECISION*
>(vertexByteArray.data());
874 for (std::size_t i = 0; i < nVerts; ++i) {
875 vertexBufferArray[i1++] = vertices[i].x();
876 vertexBufferArray[i1++] = vertices[i].y();
877 vertexBufferArray[i1++] = vertices[i].z();
878 vertexBufferArray[i1++] = normals[i].x();
879 vertexBufferArray[i1++] = normals[i].y();
880 vertexBufferArray[i1++] = normals[i].z();
883 vertexGeometry =
new G4Qt3DCompat::QGeometry();
884 vertexGeometry->setObjectName(
"vertexGeometry");
885 vertexBuffer =
new G4Qt3DCompat::QBuffer(vertexGeometry);
886 vertexBuffer->setObjectName(
"Vertex buffer");
887 vertexBuffer->setData(vertexByteArray);
890 positionAtt =
new G4Qt3DCompat::QAttribute;
891 positionAtt->setObjectName(
"Position attribute");
892 positionAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
893 positionAtt->setBuffer(vertexBuffer);
894 positionAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
895 positionAtt->setVertexBaseType(
BASETYPE);
896 positionAtt->setVertexSize(3);
897 positionAtt->setCount((
G4int)nVerts);
898 positionAtt->setByteOffset(0);
899 positionAtt->setByteStride(2*vertexByteSize);
902 normalAtt =
new G4Qt3DCompat::QAttribute;
903 normalAtt->setObjectName(
"Normal attribute");
904 normalAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName());
905 normalAtt->setBuffer(vertexBuffer);
906 normalAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
907 normalAtt->setVertexBaseType(
BASETYPE);
908 normalAtt->setVertexSize(3);
909 normalAtt->setCount((
G4int)nVerts);
910 normalAtt->setByteOffset(vertexByteSize);
911 normalAtt->setByteStride(2*vertexByteSize);
914 G4Qt3DCompat::QBuffer* lineBuffer =
nullptr;
920 QByteArray lineByteArray;
921 const auto lineBufferByteSize = 2*nLines*vertexByteSize;
922 lineByteArray.resize((
G4int)lineBufferByteSize);
923 auto lineBufferArray =
reinterpret_cast<PRECISION*
>(lineByteArray.data());
925 for (
const auto& line: lines) {
926 lineBufferArray[i2++] = line.first.x();
927 lineBufferArray[i2++] = line.first.y();
928 lineBufferArray[i2++] = line.first.z();
929 lineBufferArray[i2++] = line.second.x();
930 lineBufferArray[i2++] = line.second.y();
931 lineBufferArray[i2++] = line.second.z();
934 lineGeometry =
new G4Qt3DCompat::QGeometry();
935 lineGeometry->setObjectName(
"lineGeometry");
936 lineBuffer =
new G4Qt3DCompat::QBuffer(lineGeometry);
937 lineBuffer->setObjectName(
"Line buffer");
938 lineBuffer->setData(lineByteArray);
941 lineAtt =
new G4Qt3DCompat::QAttribute;
942 lineAtt->setObjectName(
"Position attribute");
943 lineAtt->setName(G4Qt3DCompat::QAttribute::defaultPositionAttributeName());
944 lineAtt->setBuffer(lineBuffer);
945 lineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
946 lineAtt->setVertexBaseType(
BASETYPE);
947 lineAtt->setVertexSize(3);
948 lineAtt->setCount((
G4int)nLines);
949 lineAtt->setByteOffset(0);
950 lineAtt->setByteStride(vertexByteSize);
952 dummyNormalLineAtt =
new G4Qt3DCompat::QAttribute;
953 dummyNormalLineAtt->setObjectName(
"Normal attribute");
954 dummyNormalLineAtt->setName(G4Qt3DCompat::QAttribute::defaultNormalAttributeName());
955 dummyNormalLineAtt->setBuffer(lineBuffer);
956 dummyNormalLineAtt->setAttributeType(G4Qt3DCompat::QAttribute::VertexAttribute);
957 dummyNormalLineAtt->setVertexBaseType(
BASETYPE);
958 dummyNormalLineAtt->setVertexSize(3);
959 dummyNormalLineAtt->setCount(0);
960 dummyNormalLineAtt->setByteOffset(0);
961 dummyNormalLineAtt->setByteStride(vertexByteSize);
967 Qt3DExtras::QDiffuseSpecularMaterial* material;
968 Qt3DRender::QGeometryRenderer* renderer;
969 switch (drawing_style) {
973 lineGeometry->addAttribute(lineAtt);
974 lineGeometry->addAttribute(dummyNormalLineAtt);
976 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
977 material->setObjectName(
"materialForWireframe");
979 material->setShininess(0.);
980 material->setSpecular(0.);
981 wireframeEntity->addComponent(material);
983 renderer =
new Qt3DRender::QGeometryRenderer;
984 renderer->setObjectName(
"polyhedronWireframeRenderer");
985 renderer->setGeometry(lineGeometry);
986 renderer->setVertexCount(2*(
G4int)nLines);
987 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
988 wireframeEntity->addComponent(renderer);
996 vertexGeometry->addAttribute(positionAtt);
997 vertexGeometry->addAttribute(normalAtt);
999 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1000 material->setObjectName(
"materialForHiddenLines");
1001 material->setAmbient(Qt::white);
1002 material->setShininess(0.);
1003 material->setSpecular(0.);
1004 surfaceEntity->addComponent(material);
1006 renderer =
new Qt3DRender::QGeometryRenderer;
1007 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1008 renderer->setGeometry(vertexGeometry);
1009 renderer->setVertexCount((
G4int)nVerts);
1010 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
1011 surfaceEntity->addComponent(renderer);
1015 lineGeometry->addAttribute(lineAtt);
1016 lineGeometry->addAttribute(dummyNormalLineAtt);
1018 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1019 material->setObjectName(
"materialForWireFrame");
1021 material->setShininess(0.);
1022 material->setSpecular(0.);
1023 wireframeEntity->addComponent(material);
1025 renderer =
new Qt3DRender::QGeometryRenderer;
1026 renderer->setObjectName(
"polyhedronWireframeRenderer");
1027 renderer->setGeometry(lineGeometry);
1028 renderer->setVertexCount(2*(
G4int)nLines);
1029 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
1030 wireframeEntity->addComponent(renderer);
1036 vertexGeometry->addAttribute(positionAtt);
1037 vertexGeometry->addAttribute(normalAtt);
1039 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1040 material->setObjectName(
"materialForSurface");
1042 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
1043 surfaceEntity->addComponent(material);
1045 renderer =
new Qt3DRender::QGeometryRenderer;
1046 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1047 renderer->setGeometry(vertexGeometry);
1048 renderer->setVertexCount((
G4int)nVerts);
1049 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
1050 surfaceEntity->addComponent(renderer);
1058 vertexGeometry->addAttribute(positionAtt);
1059 vertexGeometry->addAttribute(normalAtt);
1061 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1062 material->setObjectName(
"materialForSurface");
1064 if (colour.GetAlpha() < 1.) material->setAlphaBlendingEnabled(
true);
1065 surfaceEntity->addComponent(material);
1067 renderer =
new Qt3DRender::QGeometryRenderer;
1068 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1069 renderer->setGeometry(vertexGeometry);
1070 renderer->setVertexCount((
G4int)nVerts);
1071 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);
1072 surfaceEntity->addComponent(renderer);
1076 lineGeometry->addAttribute(lineAtt);
1077 lineGeometry->addAttribute(dummyNormalLineAtt);
1079 material =
new Qt3DExtras::QDiffuseSpecularMaterial();
1080 material->setObjectName(
"materialForWireframe");
1082 material->setShininess(0.);
1083 material->setSpecular(0.);
1084 wireframeEntity->addComponent(material);
1086 renderer =
new Qt3DRender::QGeometryRenderer;
1087 renderer->setObjectName(
"polyhedronSurfaceRenderer");
1088 renderer->setGeometry(lineGeometry);
1089 renderer->setVertexCount(2*(
G4int)nLines);
1090 renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
1091 wireframeEntity->addComponent(renderer);