440{
442
443
444
446
447
448
449
450
451
452
453
454 std::vector<G4Point3D> vertices;
455 std::vector<G4Normal3D> normals;
456
457
458
459 typedef std::pair<G4Point3D,G4Point3D> Line;
460 std::vector<Line> lines;
461 auto insertIfNew = [&lines](const Line& newLine) {
462
463
464
465
466
467 lines.push_back(newLine);
468 };
469
470 G4bool isAuxilaryEdgeVisible =
fpViewer->GetViewParameters().IsAuxEdgeVisible();
472 do {
477 notLastFace = a_polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normal);
478 vertices.push_back(vertex[0]);
479 vertices.push_back(vertex[1]);
480 vertices.push_back(vertex[2]);
481 normals.push_back(normal[0]);
482 normals.push_back(normal[1]);
483 normals.push_back(normal[2]);
484 if(isAuxilaryEdgeVisible||edgeFlag[0]>0)insertIfNew(Line(vertex[0],vertex[1]));
485 if(isAuxilaryEdgeVisible||edgeFlag[1]>0)insertIfNew(Line(vertex[1],vertex[2]));
486 if (nEdges == 3) {
487
488
489 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[0]));
490 } else if (nEdges == 4) {
491
492
493 vertices.push_back(vertex[2]);
494 vertices.push_back(vertex[3]);
495 vertices.push_back(vertex[0]);
496 normals.push_back(normal[2]);
497 normals.push_back(normal[3]);
498 normals.push_back(normal[0]);
499 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[3]));
500 if(isAuxilaryEdgeVisible||edgeFlag[3]>0)insertIfNew(Line(vertex[3],vertex[0]));
501 } else {
503 << "G4ToolsSGSceneHandler::AddPrimitive(G4Polyhedron): WARNING:"
504 << "\n G4Polyhedron facet with unexpected number of edges (" << nEdges << ")."
506 return;
507 }
508 } while (notLastFace);
509
511 switch (drawing_style) {
513
514 break;
516 break;
518
519 break;
521 break;
523
524 return;
525 }
526
528 if (!currentNode) return;
529
530 tools::sg::separator* sep = new tools::sg::separator;
531 currentNode->add(sep);
532
533
534 {tools::sg::matrix* mtx = new tools::sg::matrix;
539 0, 0, 0, 1);
540 sep->add(mtx);}
541
542 {
const auto& colour =
GetColour(a_polyhedron);
543 tools::sg::rgba* mat = new tools::sg::rgba();
544 mat->color =
545 tools::colorf(float(colour.GetRed()),
546 float(colour.GetGreen()),
547 float(colour.GetBlue()),
548 float(colour.GetAlpha()));
549 sep->add(mat);}
550
554
555 {tools::sg::draw_style* ds = new tools::sg::draw_style;
556 ds->style = tools::sg::draw_filled;
557
558 sep->add(ds);}
559
560 tools::sg::atb_vertices* vtxs = new tools::sg::atb_vertices;
561 vtxs->mode = tools::gl::triangles();
562 sep->add(vtxs);
563
564 const auto nVerts = vertices.size();
565 for (size_t i = 0; i < nVerts; i++) {
566 vtxs->add(float(vertices[i].x()),float(vertices[i].y()),float(vertices[i].z()));
567 vtxs->add_normal(float(normals[i].x()),float(normals[i].y()),float(normals[i].z()));
568 }
569 }
570
574
575 {tools::sg::draw_style* ds = new tools::sg::draw_style;
576 ds->style = tools::sg::draw_lines;
579 sep->add(ds);}
580
581 tools::sg::vertices* vtxs = new tools::sg::vertices;
582 vtxs->mode = tools::gl::lines();
583 sep->add(vtxs);
584
585 for (const auto& line: lines) {
586 vtxs->add(float(line.first.x()),float(line.first.y()),float(line.first.z()));
587 vtxs->add(float(line.second.x()),float(line.second.y()),float(line.second.z()));
588 }
589
590 }
591}
HepGeom::Normal3D< G4double > G4Normal3D
HepGeom::Point3D< G4double > G4Point3D
G4GLOB_DLL std::ostream G4cerr
const G4Colour & GetColour()
G4Transform3D fObjectTransformation
G4VViewer * GetCurrentViewer() const
const G4VisAttributes * fpVisAttribs
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
G4double GetLineWidth(const G4VisAttributes *)
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
const G4VisAttributes * GetVisAttributes() const
G4int GetNoFacets() const
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=nullptr, G4Normal3D *normals=nullptr) const