Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenInventorQtExaminerViewer Class Reference

#include <G4OpenInventorQtExaminerViewer.hh>

+ Inheritance diagram for G4OpenInventorQtExaminerViewer:

Classes

struct  elementForSorting
 
struct  sceneElement
 
struct  viewPtData
 

Public Member Functions

 G4OpenInventorQtExaminerViewer (QWidget *parent=NULL, const char *name=NULL, SbBool embed=TRUE, SoQtFullViewer::BuildFlag flag=BUILD_ALL, SoQtViewer::Type type=BROWSER)
 
 ~G4OpenInventorQtExaminerViewer ()
 
G4UIQtGetUIQt ()
 
template<class T >
void parseString (T &t, const std::string &s, bool &error)
 
void setOrigWindowSize (int w, int h)
 
QMenuBar * getMenubar ()
 
QMenu * getFileMenu ()
 
QMenu * getEtcMenu ()
 
QFont * getFont ()
 
void setExternalQtApp ()
 
void addEscapeCallback (void(*cb)())
 

Public Attributes

std::string saveScenegraphFileName
 
std::string saveRefCoordsFileName
 
bool abbrOutputFlag
 
bool pickRefPathFlag
 
bool viewingBeforePickRef
 

Protected Types

enum  CameraType { PERSPECTIVE , ORTHOGRAPHIC }
 
enum  State {
  GENERAL , BEAMLINE , VIEWPOINT , ANIMATION ,
  REVERSED_ANIMATION , PAUSED_ANIMATION , ROTATING
}
 

Protected Member Functions

void construct (const SbBool build)
 
void buildWidget (QWidget *parent)
 
virtual void afterRealizeHook ()
 
SbBool processSoEvent (const SoEvent *const event)
 
void saveViewPt (char *name)
 
bool loadViewPts ()
 
void addViewPoints ()
 
void setViewPt ()
 
void writeViewPtIdx ()
 
void cleanUpAfterPrevFile ()
 
void deleteViewPt (char *vpName=NULL)
 
void renameViewPt (char *vpName)
 
void sortViewPts (std::vector< std::string >)
 
void zoom (const float)
 
void moveCamera (float dist=0, bool lookdown=false)
 
void rotateCamera ()
 
void updateViewParams (SoKeyboardEvent::Key)
 
void animateRefParticle ()
 
void saveCurCamera ()
 
void restoreCamera ()
 
void incSpeed ()
 
void decSpeed ()
 
void setReferencePath (SoLineSet *, SoCoordinate3 *, bool append=false)
 
void setReferencePathZPos ()
 
void findAndSetRefPath ()
 
SoCoordinate3 * getCoordsNode (SoFullPath *path)
 
void getSceneElements ()
 
float sqrlen (const SbVec3f &)
 
void distanceToTrajectory (const SbVec3f &, float &, SbVec3f &, int &)
 
void sortElements ()
 
void createElementsList ()
 
void evenOutRefParticlePts ()
 
void gotoRefPathStart ()
 
void invertRefPath ()
 
void setStartingPtForAnimation ()
 
std::string viewPtAutoName ()
 
SoNode * getSuperimpositionNode (SoNode *, const char *name)
 
void superimpositionEvent (SoAction *action)
 
virtual void actualRedraw (void)
 
void updateSpeedIndicator (void)
 

Static Protected Member Functions

static void sceneChangeCB (void *, SoSensor *)
 
static void mouseoverCB (void *aThis, SoEventCallback *eventCB)
 
static void pickingCB (void *aThis, SoEventCallback *eventCB)
 
static void animateRefParticleCB ()
 
static void animateSensorCB (void *, SoSensor *)
 
static void animateSensorRotationCB (void *, SoSensor *)
 
static void superimpositionCB (void *closure, SoAction *action)
 

Protected Attributes

HookEventProcStatehookBeamOn
 
bool newEvents
 
std::string curEltName
 
SbVec3f camUpVec
 
SbVec3f camDir
 
double animateBtwPtsPeriod
 
double speedStep
 
SoTimerSensor * animateSensor
 
SoTimerSensor * animateSensorRotation
 
SoNodeSensor * sceneChangeSensor
 
SbVec3f camStartPos
 
SbVec3f camEndPos
 
SbRotation camStartOrient
 
SbRotation camEndOrient
 
bool zcoordSetFlag
 
std::vector< sceneElementsceneElements
 
std::vector< viewPtDataviewPtList
 
std::string fileName
 
std::ifstream fileIn
 
std::ofstream fileOut
 
int viewPtIdx
 
int MAX_VP_IDX
 
int MAX_VP_NAME
 
std::vector< SbVec3f > refParticleTrajectory
 
std::vector< float > refZPositions
 
int refParticleIdx
 
int prevRefIdx
 
float distance
 
State currentState
 
State prevState
 
State beforePausing
 
char * curViewPtName
 
int step
 
SbVec3f prevPt
 
SbVec3f prevParticleDir
 
void * prevColorField
 
viewPtData camB4Animation
 
bool returnToSaveVP
 
bool returnToAnim
 
SoCamera * myCam
 
float left_right
 
float up_down
 
SbVec3f rotAxis
 
int rotCnt
 
SoSearchAction * searcher
 
SoNode * superimposition
 
SoCoordinate3 * sgeometry
 
SoScale * sscale
 
SoTranslation * stranslation
 
SoTranslation * curInfoTrans
 
SoTranslation * mouseOverTransSolid
 
SoTranslation * mouseOverTransMaterial
 
SoTranslation * mouseOverTransLogName
 
SoTranslation * mouseOverTransZPos
 
SoText2 * curInfoText
 
SoText2 * mouseOverTextSolid
 
SoText2 * mouseOverTextMaterial
 
SoText2 * mouseOverTextLogName
 
SoText2 * mouseOverTextZPos
 
SoFont * curInfoFont
 
SoFont * mouseOverFontSolid
 
SoFont * mouseOverFontMaterial
 
SoFont * mouseOverFontLogName
 
SoFont * mouseOverFontZPos
 
SoSwitch * axisSwitch
 
SoSwitch * animSpeedOutlineSwitch
 
SoSwitch * animSpeedSwitch
 
SoSwitch * curInfoSwitch
 
float maxSpeed
 
float defaultHeight
 
float defaultHeightAngle
 
G4int pathLookahead
 
SbVec3f upVector
 
SbVec3f offsetFromCenter
 
SbVec3f center
 
bool rotUpVec
 
SoSeparator * newSceneGraph
 

Friends

class G4OpenInventorQtViewer
 
class HookEventProcState
 

Detailed Description

Definition at line 87 of file G4OpenInventorQtExaminerViewer.hh.

Member Enumeration Documentation

◆ CameraType

◆ State

Constructor & Destructor Documentation

◆ G4OpenInventorQtExaminerViewer()

G4OpenInventorQtExaminerViewer::G4OpenInventorQtExaminerViewer ( QWidget * parent = NULL,
const char * name = NULL,
SbBool embed = TRUE,
SoQtFullViewer::BuildFlag flag = BUILD_ALL,
SoQtViewer::Type type = BROWSER )

Definition at line 118 of file G4OpenInventorQtExaminerViewer.cc.

122 : SoQtExaminerViewer(parent, name, embed, flag, type),
123 externalQtApp(0), processSoEventCount(0)
124{
125 // FWJ DEBUG
126 // G4cout << "G4OpenInventorQtExaminerViewer CONSTRUCTOR CALLED" << G4endl;
127 // G4cout << "G4OpenInventorQtExaminerViewer parent=" << parent << G4endl;
128
129 // FWJ THIS DOESN'T WORK APPARENTLY NO MAINWINDOW
130 // QMenuBar* menubar = ((QMainWindow*)parent)->menuBar();
131
132 fName = new QString(name);
133 viewer = this;
135}
#define TRUE
Definition globals.hh:41

◆ ~G4OpenInventorQtExaminerViewer()

G4OpenInventorQtExaminerViewer::~G4OpenInventorQtExaminerViewer ( )

Definition at line 138 of file G4OpenInventorQtExaminerViewer.cc.

139{
140 // if (superimposition != NULL) {
141 // removeSuperimposition(superimposition);
142 // superimposition->unref();
143 // superimposition = NULL;
144 // }
145 // if (animateSensor->isScheduled())
146 // animateSensor->unschedule();
147 // delete animateSensor;
148 // delete sceneChangeSensor;
149 // delete[] curViewPtName;
150 // delete searcher;
151
152 viewer = 0;
153}

Member Function Documentation

◆ actualRedraw()

void G4OpenInventorQtExaminerViewer::actualRedraw ( void )
protectedvirtual

Definition at line 1529 of file G4OpenInventorQtExaminerViewer.cc.

1529 {
1530 switch (currentState) {
1531 case ANIMATION:
1532 case REVERSED_ANIMATION:
1533 case PAUSED_ANIMATION:
1535 SoQtExaminerViewer::actualRedraw();
1536 break;
1537 default:
1538 SoQtExaminerViewer::actualRedraw();
1539 break;
1540 }
1541}

◆ addEscapeCallback()

void G4OpenInventorQtExaminerViewer::addEscapeCallback ( void(* cb )())

Definition at line 2578 of file G4OpenInventorQtExaminerViewer.cc.

2579{
2580 escapeCallback = callback;
2581}

◆ addViewPoints()

void G4OpenInventorQtExaminerViewer::addViewPoints ( )
protected

Definition at line 2603 of file G4OpenInventorQtExaminerViewer.cc.

2604{
2605 std::size_t size = viewPtList.size();
2606 if (!size) return;
2607
2608 for (std::size_t i = 0; i < size; ++i) {
2609 new QListWidgetItem(viewPtList[i].viewPtName,
2610 AuxWindowDialog->listWidget);
2611 }
2612}
QListWidget * listWidget

Referenced by afterRealizeHook().

◆ afterRealizeHook()

void G4OpenInventorQtExaminerViewer::afterRealizeHook ( )
protectedvirtual

Definition at line 666 of file G4OpenInventorQtExaminerViewer.cc.

667{
668 SoQtExaminerViewer::afterRealizeHook();
669
670 // Default height is used when selecting and viewing scene elements
671 // FWJ Added defaultHeight for Ortho camera
672 SoCamera *cam = getCamera();
673 if (cam) {
674 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
676 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
677 toggleCameraType();
679 ((SoOrthographicCamera *) cam)->height.getValue();
680 toggleCameraType();
681 } else {
683 ((SoOrthographicCamera *) cam)->height.getValue();
684 toggleCameraType();
685 cam = getCamera();
686 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId()))
688 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
689 toggleCameraType();
690 }
691 }
692
693 // Open the default bookmark file
694 fileIn.open(fileName.c_str());
695 if (!fileIn.fail()) {
696 if (!loadViewPts()) {
697 QMessageBox msgbox;
698 msgbox.setFont(*font);
699 QString messagetxt = "Error reading bookmark file ";
700 messagetxt.append(QString(fileName.c_str()));
701 msgbox.setText(messagetxt);
702 msgbox.exec();
703 } else {
704 // Opens a file without erasing it
705 fileOut.open(fileName.c_str(), std::ios::in);
706 fileOut.seekp(0, std::ios::end); // For appending new data to the end
707 // FWJ DEBUG
708 // G4cout << "afterRealizeHook: opened EXISTING bookmark file"
709 // << G4endl;
710 if (viewPtList.size()) {
711 // FWJ disabled auto-selection of first viewpoint.
712 // Initial view should be user-controllable & not forced
713 // setViewPt();
715 }
716 }
717 fileIn.close();
718 } else {
719 // Creates a new default bookmark file
720 fileOut.open(fileName.c_str());
721 // FWJ DEBUG
722 // G4cout << "afterRealizeHook: Opened a NEW bookmark file" << G4endl;
723 }
724
725 fileIn.clear();
726
727 SoSeparator* root = (SoSeparator*) (getSceneManager()->getSceneGraph());
728 if (root == NULL)
729 SoDebugError::post("G4OpenInventorQtExaminerViewer::afterRealizeHook", "Root is null.");
730 else {
731 root->addChild(myCam); // For position/orientation calculation during animation
732 }
733
734 sceneChangeSensor = new SoNodeSensor;
735 sceneChangeSensor->setFunction(sceneChangeCB);
736 sceneChangeSensor->attach(root);
737 sceneChangeSensor->setData(this);
738
739 ///////////////////////////// MOUSEOVER & PICK /////////////////////
740
741 // Monitor mouseover events for displaying the name of scene elements
742 // An SoEventCallback is needed instead of using the default processSoEvent
743 // because that last one does not provide us with an SoPath to the object
744 // that was picked
745 SoEventCallback *moCB = new SoEventCallback;
746 moCB->addEventCallback(
747 SoLocation2Event::getClassTypeId(),
748 mouseoverCB, static_cast<void *>(this));
749 root->addChild(moCB);
750
751 // Override the default picking mechanism present in G4OpenInventorViewer
752 // because we want abbreviated output when picking a trajectory
753 SoEventCallback *pickCB = new SoEventCallback;
754 pickCB->addEventCallback(
755 SoMouseButtonEvent::getClassTypeId(),
756 pickingCB, static_cast<void *>(this));
757 root->addChild(pickCB);
758
759 ///////////////////////////// MOUSEOVER & PICK /////////////////////
760
761 AuxWindow->show();
762 AuxWindow->raise();
763 AuxWindow->activateWindow();
764
765 auto UI = G4UImanager::GetUIpointer();
766 uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWindow());
767 // This explicitly sets the TabWidget as parent before addTab():
768 if (uiQt) {
769 viewerParent = getParentWidget();
770 viewerParent2 = viewerParent->parentWidget();
771 uiQt->AddTabWidget(getParentWidget(), *fName);
772 uiQtTabIndex = uiQt->GetViewerTabWidget()->currentIndex();
773 // attached = TRUE;
774 addAppPushButton(detachButton);
775 }
776}
static void mouseoverCB(void *aThis, SoEventCallback *eventCB)
static void pickingCB(void *aThis, SoEventCallback *eventCB)
static void sceneChangeCB(void *, SoSensor *)
G4bool AddTabWidget(QWidget *, QString)
Definition G4UIQt.cc:2283
QTabWidget * GetViewerTabWidget()
Definition G4UIQt.hh:171
static G4UImanager * GetUIpointer()

◆ animateRefParticle()

void G4OpenInventorQtExaminerViewer::animateRefParticle ( )
protected

Definition at line 2555 of file G4OpenInventorQtExaminerViewer.cc.

2556{
2557 SoCamera *cam = getCamera();
2558
2559 camStartPos = cam->position.getValue();
2560 camStartOrient = cam->orientation.getValue();
2561
2562 if (currentState != BEAMLINE)
2564
2565 camEndPos = myCam->position.getValue();
2566 camEndOrient = myCam->orientation.getValue();
2567
2568 if (animateSensor->isScheduled())
2569 animateSensor->unschedule();
2570
2571 animateSensor->setBaseTime(SbTime::getTimeOfDay());
2572 animateSensor->setInterval(SbTime(0.02));
2573
2574 animateSensor->schedule();
2575}

Referenced by animateSensorCB(), incSpeed(), and processSoEvent().

◆ animateRefParticleCB()

static void G4OpenInventorQtExaminerViewer::animateRefParticleCB ( )
staticprotected

◆ animateSensorCB()

void G4OpenInventorQtExaminerViewer::animateSensorCB ( void * data,
SoSensor * sensor )
staticprotected

Definition at line 2381 of file G4OpenInventorQtExaminerViewer.cc.

2383{
2384 SbTime curTime = SbTime::getTimeOfDay();
2386 SoCamera *cam = This->getCamera();
2387 SoTimerSensor* s = (SoTimerSensor*) sensor;
2388
2389 float t = float((curTime - s->getBaseTime()).getValue())
2390 / This->animateBtwPtsPeriod;
2391
2392 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2393 t = 1.0f;
2394 SbBool end = (t == 1.0f);
2395
2396 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
2397 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
2398
2399 if (end) {
2400 This->animateSensor->unschedule();
2401
2402 if (This->currentState == ANIMATION) {
2403 if (This->refParticleIdx < (int) (This->refParticleTrajectory.size() - 1))
2404 This->animateRefParticle();
2405 else {
2407 This->speedStep = START_STEP;
2408 }
2409 }
2410 if (This->currentState == REVERSED_ANIMATION) {
2411 if (This->refParticleIdx >= 1)
2412 This->animateRefParticle();
2413 else {
2415 This->speedStep = START_STEP;
2416 }
2417 }
2418 }
2419}

Referenced by construct().

◆ animateSensorRotationCB()

void G4OpenInventorQtExaminerViewer::animateSensorRotationCB ( void * data,
SoSensor * sensor )
staticprotected

Definition at line 2348 of file G4OpenInventorQtExaminerViewer.cc.

2350{
2351 SbTime curTime = SbTime::getTimeOfDay();
2353
2354 SoTimerSensor* s = (SoTimerSensor*) sensor;
2355
2356 float t = float((curTime - s->getBaseTime()).getValue())
2357 / This->animateBtwPtsPeriod;
2358
2359 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2360 t = 1.0f;
2361 SbBool end = (t == 1.0f);
2362
2363 if (end) {
2364 This->animateSensorRotation->unschedule();
2365 if(This->rotCnt) {
2366 // rotations left
2367 This->rotateCamera();
2368 }
2369 else {
2370 // rotation over
2371 This->currentState = This->prevState;
2372 return;
2373 }
2374 }
2375
2376}

Referenced by construct().

◆ buildWidget()

void G4OpenInventorQtExaminerViewer::buildWidget ( QWidget * parent)
protected

Definition at line 431 of file G4OpenInventorQtExaminerViewer.cc.

432{
433 if (!parent)
434 SoDebugError::post("G4OpenInventorQtExaminerViewer::buildWidget",
435 "Error: Parent is null.");
436
437 // Common font for (almost) all widgets
438 font = new QFont;
439 font->setPointSize(12);
440 // This font setting does not propagate to added child widgets - Why?
441 parent->setFont(*font);
442 // This propagates everywhere but would affect UIQt!
443 // QApplication::setFont(*font);
444
445// MENU BAR
446
447 menubar = new QMenuBar(getRenderAreaWidget());
448 // FWJ DEBUG
449 // G4cout << "G4OpenInventorQtExaminerViewer: GOT A menubar=" <<
450 // menubar << G4endl;
451
452 filemenu = new QMenu("File");
453 menubar->addMenu(filemenu);
454
455 FileOpenBookmark = new QAction("Open Bookmark File", this);
456 FileOpenBookmark->setFont(*font);
457 connect(FileOpenBookmark, SIGNAL(triggered()), this,
458 SLOT(FileOpenBookmarkCB()));
459 filemenu->addAction(FileOpenBookmark);
460
461 FileNewBookmark = new QAction("New Bookmark File", this);
462 FileNewBookmark->setFont(*font);
463 connect(FileNewBookmark, SIGNAL(triggered()), this,
464 SLOT(FileNewBookmarkCB()));
465 filemenu->addAction(FileNewBookmark);
466
467 FileLoadRefPath = new QAction("Load Reference Path", this);
468 FileLoadRefPath->setFont(*font);
469 connect(FileLoadRefPath, SIGNAL(triggered()), this,
470 SLOT(FileLoadRefPathCB()));
471 filemenu->addAction(FileLoadRefPath);
472
473 FileSaveRefPath = new QAction("Save Reference Path", this);
474 FileSaveRefPath->setFont(*font);
475 connect(FileSaveRefPath, SIGNAL(triggered()), this,
476 SLOT(FileSaveRefPathCB()));
477 filemenu->addAction(FileSaveRefPath);
478
479 FileLoadSceneGraph = new QAction("Load scene graph", this);
480 FileLoadSceneGraph->setFont(*font);
481 connect(FileLoadSceneGraph, SIGNAL(triggered()), this,
482 SLOT(FileLoadSceneGraphCB()));
483 filemenu->addAction(FileLoadSceneGraph);
484
485 FileSaveSceneGraph = new QAction("Save scene graph", this);
486 FileSaveSceneGraph->setFont(*font);
487 connect(FileSaveSceneGraph, SIGNAL(triggered()), this,
488 SLOT(FileSaveSceneGraphCB()));
489 filemenu->addAction(FileSaveSceneGraph);
490
491 // Rest of File menu is done in G4OpenInventorQtViewer
492
493 toolsmenu = new QMenu("Tools");
494 menubar->addMenu(toolsmenu);
495
496 ToolsAnimateRefParticle = new QAction("Fly on Ref Path", this);
497 ToolsAnimateRefParticle->setFont(*font);
498 connect(ToolsAnimateRefParticle, SIGNAL(triggered()), this,
499 SLOT(ToolsAnimateRefParticleCB()));
500 toolsmenu->addAction(ToolsAnimateRefParticle);
501
502 ToolsRefPathStart = new QAction("Go to start of Ref Path", this);
503 ToolsRefPathStart->setFont(*font);
504 connect(ToolsRefPathStart, SIGNAL(triggered()), this,
505 SLOT(ToolsRefPathStartCB()));
506 toolsmenu->addAction(ToolsRefPathStart);
507
508 ToolsRefPathInvert = new QAction("Invert Ref Path", this);
509 ToolsRefPathInvert->setFont(*font);
510 connect(ToolsRefPathInvert, SIGNAL(triggered()), this,
511 SLOT(ToolsRefPathInvertCB()));
512 toolsmenu->addAction(ToolsRefPathInvert);
513
514 etcmenu = new QMenu("Etc");
515 menubar->addMenu(etcmenu);
516
517 // All Etc menu items are done in G4OpenInventorQtViewer
518
519 helpmenu = new QMenu("Help");
520 menubar->addMenu(helpmenu);
521
522 HelpControls = new QAction("Controls", this);
523 HelpControls->setFont(*font);
524 connect(HelpControls, SIGNAL(triggered()), this, SLOT(HelpControlsCB()));
525 helpmenu->addAction(HelpControls);
526
527 menubar->show();
528
529 // SoQtExaminerViewer::buildWidget(parent);
530
531 // APP VIEWER BUTTONS have their own box on upper left
532 // The built in viewer button list is PRIVATE
533
534 saveViewPtButton = new QPushButton;
535 saveViewPtButton->setIcon(QPixmap((const char **)saveViewPt_xpm));
536 saveViewPtButton->setIconSize(QSize(24,24));
537 saveViewPtButton->setToolTip("Bookmark this view");
538 connect(saveViewPtButton, SIGNAL(clicked()), this,
539 SLOT(SaveViewPtCB()));
540 addAppPushButton(saveViewPtButton);
541
542 nextViewPtButton = new QPushButton;
543 nextViewPtButton->setIconSize(QSize(24,24));
544 QCommonStyle style;
545 nextViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowRight));
546 nextViewPtButton->setToolTip("Next bookmark");
547 connect(nextViewPtButton, SIGNAL(clicked()), this,
548 SLOT(NextViewPtCB()));
549 addAppPushButton(nextViewPtButton);
550
551 prevViewPtButton = new QPushButton;
552 prevViewPtButton->setIconSize(QSize(24,24));
553 prevViewPtButton->setIcon(style.standardIcon(QStyle::SP_ArrowLeft));
554 prevViewPtButton->setToolTip("Previous bookmark");
555 connect(prevViewPtButton, SIGNAL(clicked()), this,
556 SLOT(PrevViewPtCB()));
557 addAppPushButton(prevViewPtButton);
558
559 abbrOutputButton = new QPushButton;
560 abbrOutputButton->setCheckable(true);
561 abbrOutputButton->setIconSize(QSize(24,24));
562 abbrOutputButton->setIcon(QPixmap((const char **)pickext_xpm));
563 abbrOutputButton->setToolTip("Extended picking & readout");
564 connect(abbrOutputButton, SIGNAL(toggled(bool)), this,
565 SLOT(AbbrOutputCB(bool)));
566 addAppPushButton(abbrOutputButton);
567
568 pickRefPathButton = new QPushButton;
569 pickRefPathButton->setIconSize(QSize(24,24));
570 pickRefPathButton->setIcon(QPixmap((const char **)pickref_xpm));
571 pickRefPathButton->setToolTip("Pick ref trajectory");
572 connect(pickRefPathButton, SIGNAL(clicked()), this,
573 SLOT(PickRefPathCB()));
574 addAppPushButton(pickRefPathButton);
575
576 switchWireFrameButton = new QPushButton;
577 switchWireFrameButton->setCheckable(true);
578 switchWireFrameButton->setIconSize(QSize(24,24));
579 switchWireFrameButton->setIcon(QPixmap((const char **)wireframe_xpm));
580 switchWireFrameButton->setToolTip("Switch wireframe/solid");
581 connect(switchWireFrameButton, SIGNAL(toggled(bool)), this,
582 SLOT(SwitchWireFrameCB(bool)));
583 addAppPushButton(switchWireFrameButton);
584
585 switchAxesButton = new QPushButton;
586 switchAxesButton->setCheckable(true);
587 switchAxesButton->setText(QString("A"));
588 switchAxesButton->setToolTip("Axes on/off");
589 connect(switchAxesButton, SIGNAL(toggled(bool)), this,
590 SLOT(SwitchAxesCB(bool)));
591 addAppPushButton(switchAxesButton);
592
593 detachButton = new QPushButton;
594 detachButton->setIconSize(QSize(24,24));
595 detachButton->setIcon(style.standardIcon(QStyle::SP_CommandLink));
596 detachButton->setToolTip("Detach viewer window");
597 connect(detachButton, SIGNAL(clicked()), this,
598 SLOT(DetachCB()));
599 // Used for UIQt only so check and add later
600 // addAppPushButton(detachButton);
601
602 // HELP WINDOW
603
604 helpmsgbox = new QMessageBox(getParentWidget());
605 helpmsgbox->setWindowTitle("OIQt Controls");
606 helpmsgbox->setFont(*font);
607 QString messagetxt =
608"\nVIEWING mode (Hand cursor):\n\n\
609 Left-button + pointer move: rotate\n\
610 Shift+Left-button + pointer move: pan\n\
611 Middle-button + pointer move: pan\n\
612 Ctrl+Shift+Left-button + pointer move: zoom\n\
613 Mouse wheel: zoom\n\
614 Right-button: popup menu\n\n\
615PICKING mode (Arrow cursor):\n\n\
616 Click on a volume: geometry readout\n\
617 Click on a trajectory: particle & trajectory readout\n\
618 Ctrl + click on a volume: see daughters.\n\
619 Shift + click on a volume: see mother.\n\n\
620EXTENDED PICKING mode (Arrow+ viewer button):\n\n\
621 Hover the mouse over a volume or trajectory for\n\
622 overlayed readout.\n\n\
623ELEMENT NAVIGATION (requires Reference Path):\n\n\
624 Click on element in list: centers view on element\n\
625 Arrow keys: rotate in 90 degree steps around element \n\
626 Shift + Right Arrow: move to next element\n\
627 Shift + Left Arrow: move to previous element\n\n\
628FLY mode (requires Reference Path):\n\n\
629 Page Up: Increase speed\n\
630 Page Down: Decrease speed (& reverse if wanted)\n\
631 Up Arrow: raise camera above path\n\
632 Down Arror: lower camera below path\n\
633 Escape: Exit fly mode";
634 helpmsgbox->setText(messagetxt);
635 helpmsgbox->setModal(false);
636 // helpmsgbox->setWindowModality(Qt::NonModal);
637
638 // AUXILIARY LISTS WINDOW
639
640 // Bypass the namespace in order to make a persistent object
641 AuxWindowDialog = new Ui_Dialog;
642 AuxWindow = new QDialog(parent);
643 AuxWindowDialog->setupUi(AuxWindow);
644
645 // SIGNALS
646 connect(AuxWindowDialog->listWidget, SIGNAL(itemClicked(QListWidgetItem*)),
647 this, SLOT(LoadBookmarkCB(QListWidgetItem*)));
648 connect(AuxWindowDialog->listWidget1, SIGNAL(itemClicked(QListWidgetItem*)),
649 this, SLOT(LookAtSceneElementCB(QListWidgetItem*)));
650 connect(AuxWindowDialog->pushButton_2, SIGNAL(clicked()),
651 this, SLOT(DeleteBookmarkCB()));
652 connect(AuxWindowDialog->pushButton_3, SIGNAL(clicked()),
653 this, SLOT(RenameBookmarkCB()));
654 connect(AuxWindowDialog->pushButton, SIGNAL(clicked()),
655 this, SLOT(SortBookmarksCB()));
656
657 // FWJ Better to do this after viewer window is realized
658 // AuxWindow->show();
659 // AuxWindow->raise();
660 // AuxWindow->activateWindow();
661}
QPushButton * pushButton_2
QPushButton * pushButton_3
void setupUi(QDialog *Dialog)
QListWidget * listWidget1
QPushButton * pushButton

Referenced by construct().

◆ cleanUpAfterPrevFile()

void G4OpenInventorQtExaminerViewer::cleanUpAfterPrevFile ( )
protected

Definition at line 2682 of file G4OpenInventorQtExaminerViewer.cc.

2683{
2684 viewPtIdx = -1;
2685 viewPtList.clear();
2686 // setSuperimpositionEnabled(superimposition, FALSE);
2687 // scheduleRedraw();
2689 if (fileOut.is_open()) fileOut.close();
2690
2691 AuxWindowDialog->listWidget->clear();
2692 AuxWindowDialog->lineEdit->setText(QString(""));
2693}
QLineEdit * lineEdit

◆ construct()

void G4OpenInventorQtExaminerViewer::construct ( const SbBool build)
protected

Definition at line 156 of file G4OpenInventorQtExaminerViewer.cc.

157{
158 setFeedbackSize(40);
159
160 hookBeamOn = new HookEventProcState(this);
161 newEvents = false;
162
163 buildWidget(getParentWidget());
164
165 fileName = "bookmarkFile"; // Default viewpoint file name
166 viewPtIdx = -1; // index of the most recent viewpoint in viewPtList vector
167
168 animateSensor = new SoTimerSensor(animateSensorCB, this);
169 animateSensorRotation = new SoTimerSensor(animateSensorRotationCB, this);
171
173 myCam = new SoPerspectiveCamera;
174 MAX_VP_IDX = 3;
175 MAX_VP_NAME = 35; // Max length of a viewpoint name, padded with spaces
176 curViewPtName = new char[MAX_VP_NAME + 1];
177 left_right = up_down = 0; // For movements around the beam during animation
178 speedStep = START_STEP; // For smoother animation speed increase/decrease
179 rotUpVec = false; // Used during scene element rotations
180 step = 1; //By default
181 // Used for moving along the beam with the
182 // mouse instead of rotating the view
183 lshiftdown = rshiftdown = false;
184 // Used for rotating the view with the camera
185 // staying in place
186 lctrldown = rctrldown = false;
187 // Used to send abbreviated output to the console when
188 abbrOutputFlag = false;
189 pickRefPathFlag = false;
190 prevColorField = NULL;
191 // warningFlag = false; // We come from the warning dialog
192 // myElementList = NULL;
193 // FWJ default path look-ahead
194 pathLookahead = 5;
195
196 newSceneGraph = NULL;
197 zcoordSetFlag = false;
198
199 //////////////////////////SUPERIMPOSED SCENE//////////////////////////
200 searcher = NULL;
201 // Used in animation; progressively scaled for gradual speed change
202 maxSpeed = 0.0f;
203
204 static const char * superimposed[] = {
205 "#Inventor V2.1 ascii", "",
206 "Separator ",
207 "{",
208 " MaterialBinding ",
209 " {",
210 " value OVERALL",
211 " }",
212 " OrthographicCamera ",
213 " {",
214 " height 1",
215 " nearDistance 0",
216 " farDistance 1",
217 " }",
218 " DEF soxt->callback Callback { }",
219 " Separator ",
220 " {",
221 " DEF soxt->translation Translation ",
222 " {",
223 " translation 0 0 0",
224 " }",
225 " DEF soxt->scale Scale ",
226 " {",
227 " scaleFactor 1 1 1",
228 " }",
229 " DEF soxt->geometry Coordinate3 ",
230 " {",
231 " point ",
232 " [",
233 " -0.81 -0.04 0, -0.81 0 0,",
234 " -0.81 0.04 0, 0 -0.04 0,",
235 " 0 0 0, 0 0.04 0,",
236 " 0.81 -0.04 0, 0.81 0 0,",
237 " 0.81 0.04 0,",
238 " 0 0.02 0,", // idx 9
239 " 0.81 0.02 0, 0.81 -0.02 0,",
240 " 0 -0.02 0,",
241 " 0 0.01 0,", // idx 13
242 " 0.4 0.01 0, 0.4 -0.01 0,",
243 " 0 -0.01 0",
244 " ]",
245 " }",
246 // current speed indicator (outline)
247 " DEF soxt->animSpeedOutlineSwitch Switch ",
248 " {",
249 " whichChild -3",
250 " Material ",
251 " {",
252 " emissiveColor 0 0 0",
253 " }",
254 " IndexedFaceSet ",
255 " {",
256 " coordIndex ",
257 " [",
258 " 12, 11, 10, 9, -1",
259 " ]",
260 " }",
261 " }",
262 // the coordinate system
263 " DEF soxt->axisSwitch Switch ",
264 " {",
265 " whichChild -3",
266 " BaseColor ",
267 " {",
268 " rgb 1 1 1",
269 " }",
270 " IndexedLineSet ",
271 " {",
272 " coordIndex ",
273 " [",
274 " 0, 2, -1,",
275 " 3, 5, -1,",
276 " 6, 8, -1,",
277 " 1, 7, -1",
278 " ]",
279 " }",
280 " }",
281 // current speed indicator
282 " DEF soxt->animSpeedSwitch Switch ",
283 " {",
284 " whichChild -3",
285 " Material ",
286 " {",
287 " emissiveColor 0 1 0",
288 " }",
289 " IndexedFaceSet ",
290 " {",
291 " coordIndex ",
292 " [",
293 " 16, 15, 14, 13, -1",
294 " ]",
295 " }",
296 " }",
297 " }",
298 // For displaying either z position (during animation) or current viewpoint name
299 " DEF soxt->curInfoSwitch Switch ",
300 " {",
301 " whichChild -3",
302 " DEF soxt->curInfoTrans Translation ",
303 " {",
304 " translation 0 0 0 ",
305 // " translation 10 20 30 ",
306 " }",
307 " DEF soxt->curInfoFont Font ",
308 " {",
309 " name defaultFont:Bold",
310 " size 16",
311 " }",
312 " DEF soxt->curInfoText Text2 ",
313 " {",
314 " string Hello",
315 " }",
316 " }",
317 // Need to use different fields for mouseover
318 // because newlines are ignored when the scene is rendered
319 " Separator ",
320 " {",
321 " DEF soxt->mouseOverTransLogName Translation ",
322 " {",
323 " translation 0 0 0 ",
324 " }",
325 " DEF soxt->mouseOverFontLogName Font ",
326 " {",
327 " name defaultFont:Bold",
328 " size 16",
329 " }",
330 " DEF soxt->mouseOverTextLogName Text2 { } ",
331 " }",
332 " Separator ",
333 " {",
334 " DEF soxt->mouseOverTransSolid Translation ",
335 " {",
336 " translation 0 0 0 ",
337 " }",
338 " DEF soxt->mouseOverFontSolid Font ",
339 " {",
340 " name defaultFont:Bold",
341 " size 16",
342 " }",
343 " DEF soxt->mouseOverTextSolid Text2 { } ",
344 " }",
345 " Separator ",
346 " {",
347 " DEF soxt->mouseOverTransMaterial Translation ",
348 " {",
349 " translation 0 0 0 ",
350 " }",
351 " DEF soxt->mouseOverFontMaterial Font ",
352 " {",
353 " name defaultFont:Bold",
354 " size 16",
355 " }",
356 " DEF soxt->mouseOverTextMaterial Text2 { } ",
357 " }",
358 " Separator ",
359 " {",
360 " DEF soxt->mouseOverTransZPos Translation ",
361 " {",
362 " translation 0 0 0 ",
363 " }",
364 " DEF soxt->mouseOverFontZPos Font ",
365 " {",
366 " name defaultFont:Bold",
367 " size 16",
368 " }",
369 " DEF soxt->mouseOverTextZPos Text2 { } ",
370 " }",
371 "}", NULL
372 };
373
374 int i, bufsize;
375 for (i = bufsize = 0; superimposed[i]; i++)
376 bufsize += strlen(superimposed[i]) + 1;
377 char * buf = new char[bufsize + 1];
378 for (i = bufsize = 0; superimposed[i]; i++) {
379 strcpy(buf + bufsize, superimposed[i]);
380 bufsize += strlen(superimposed[i]);
381 buf[bufsize] = '\n';
382 bufsize++;
383 }
384 SoInput * input = new SoInput;
385 input->setBuffer(buf, bufsize);
386 SbBool ok = SoDB::read(input, superimposition);
387 (void)ok; // FWJ added to avoid compiler warning
388 assert(ok);
389 delete input;
390 delete[] buf;
391 superimposition->ref();
392
393 sscale = (SoScale *) getSuperimpositionNode(superimposition, "soxt->scale");
394 stranslation = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->translation");
395 sgeometry = (SoCoordinate3 *) getSuperimpositionNode(superimposition, "soxt->geometry");
396 axisSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->axisSwitch");
397 animSpeedOutlineSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->animSpeedOutlineSwitch");
398 animSpeedSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->animSpeedSwitch");
399 curInfoSwitch = (SoSwitch *) getSuperimpositionNode(superimposition, "soxt->curInfoSwitch");
400 curInfoTrans = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->curInfoTrans");
401 curInfoFont = (SoFont *) getSuperimpositionNode(superimposition, "soxt->curInfoFont");
402 curInfoText = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->curInfoText");
403 mouseOverTransLogName = (SoTranslation*)getSuperimpositionNode(superimposition, "soxt->mouseOverTransLogName");
404 mouseOverFontLogName = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontLogName");
405 mouseOverTextLogName = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextLogName");
406 mouseOverTransSolid = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->mouseOverTransSolid");
407 mouseOverFontSolid = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontSolid");
408 mouseOverTextSolid = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextSolid");
409 mouseOverTransMaterial = (SoTranslation*)getSuperimpositionNode(superimposition, "soxt->mouseOverTransMaterial");
410 mouseOverFontMaterial = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontMaterial");
411 mouseOverTextMaterial = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextMaterial");
412 mouseOverTransZPos = (SoTranslation *) getSuperimpositionNode(superimposition, "soxt->mouseOverTransZPos");
413 mouseOverFontZPos = (SoFont *) getSuperimpositionNode(superimposition, "soxt->mouseOverFontZPos");
414 mouseOverTextZPos = (SoText2 *) getSuperimpositionNode(superimposition, "soxt->mouseOverTextZPos");
415
416 SoCallback * cb = (SoCallback *) getSuperimpositionNode(superimposition, "soxt->callback");
417 cb->setCallback(superimpositionCB, this);
418
419 addSuperimposition(superimposition);
420 setSuperimpositionEnabled(superimposition, FALSE);
421 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
422 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
423 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
424
425 /////////////////////\SUPERIMPOSED SCENE///////////////////////////////////
426
427}
static void superimpositionCB(void *closure, SoAction *action)
static void animateSensorRotationCB(void *, SoSensor *)
SoNode * getSuperimpositionNode(SoNode *, const char *name)
static void animateSensorCB(void *, SoSensor *)
#define FALSE
Definition globals.hh:38

Referenced by G4OpenInventorQtExaminerViewer().

◆ createElementsList()

void G4OpenInventorQtExaminerViewer::createElementsList ( )
protected

Definition at line 1982 of file G4OpenInventorQtExaminerViewer.cc.

1983{
1984 // FWJ DEBUG
1985 // G4cout << "Populating ELEMENT LIST..." << G4endl;
1986
1987 AuxWindowDialog->listWidget1->clear();
1988 // int size = sceneElements.size();
1989
1990 std::vector<sceneElement>::const_iterator it;
1991 std::stringstream ss;
1992
1993 for(it=sceneElements.begin(); it!=sceneElements.end(); ++it) {
1994 ss << it->name;
1995 if(zcoordSetFlag)
1996 ss << " [" << it->closestPointZCoord << "]";
1997
1998 new QListWidgetItem(ss.str().c_str(), AuxWindowDialog->listWidget1);
1999 ss.str("");
2000 }
2001}

Referenced by sortElements().

◆ decSpeed()

void G4OpenInventorQtExaminerViewer::decSpeed ( )
protected

Definition at line 1487 of file G4OpenInventorQtExaminerViewer.cc.

1487 {
1490 if (std::floor(animateBtwPtsPeriod * 100) == 12) { // Errors in double representation
1491 speedStep = 0.08;
1492 } else if (animateBtwPtsPeriod > 0.12)
1493 speedStep += 0.02;
1494 } else {
1497 maxSpeed = 0.0f;
1498 if (animateSensor->isScheduled())
1499 animateSensor->unschedule();
1500 }
1501}

Referenced by processSoEvent().

◆ deleteViewPt()

void G4OpenInventorQtExaminerViewer::deleteViewPt ( char * vpName = NULL)
protected

Definition at line 3164 of file G4OpenInventorQtExaminerViewer.cc.

3165{
3166 std::string line;
3167 std::size_t end;
3168 fileIn.open(fileName.c_str());
3169 std::ofstream out("temporaryFile.txt");
3170
3171 if (!vpName)
3172 vpName = viewPtList[viewPtIdx].viewPtName;
3173
3174 getline(fileIn, line); // Printing the viewpoint idx
3175 out << line << "\n";
3176
3177 while (getline(fileIn, line)) {
3178 end = line.find_last_not_of(' ');
3179 line = line.substr(0, end + 1);
3180 if (!strcmp(line.c_str(), vpName)) { // Equal
3181 while (line.size()) {
3182 getline(fileIn, line);
3183 }
3184
3185 while (getline(fileIn, line))
3186 out << line << "\n";
3187 } else {
3188 while (line.size()) {
3189 out << line << "\n";
3190 getline(fileIn, line);
3191 }
3192 out << "\n";
3193 }
3194 }
3195
3196 std::size_t idx = 0; // Remove viewpoint from the vector
3197 std::size_t size = viewPtList.size();
3198 while (idx < size) {
3199 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3200 viewPtList.erase(viewPtList.begin() + idx);
3201 break;
3202 }
3203 idx++;
3204 }
3205
3206 out.close();
3207 fileOut.close();
3208 fileIn.clear();
3209 fileIn.close();
3210
3211 // FWJ check return status: error popups needed here
3212 int istat = remove(fileName.c_str());
3213 if (istat == -1) {
3214 QMessageBox msgbox;
3215 msgbox.setFont(*font);
3216 QString messagetxt = "Error removing bookmarks file";
3217 // messagetxt.append(filenamein);
3218 msgbox.setText(messagetxt);
3219 msgbox.exec();
3220 // G4cout << "Error removing bookmarks file" << G4endl;
3221 }
3222 istat = rename("temporaryFile.txt", fileName.c_str());
3223 if (istat == -1) {
3224 QMessageBox msgbox;
3225 msgbox.setFont(*font);
3226 QString messagetxt = "Error renaming bookmarks file";
3227 // messagetxt.append(filenamein);
3228 msgbox.setText(messagetxt);
3229 msgbox.exec();
3230 // G4cout << "Error renaming bookmarks file" << G4endl;
3231 }
3232 fileOut.open(fileName.c_str(), std::ios::in);
3233 fileOut.seekp(0, std::ios::end);
3234
3235 if (!viewPtList.size()) { // viewPtList is empty
3236 curViewPtName = (char *) empty.c_str();
3237 scheduleRedraw();
3238 } else {
3239 if (viewPtIdx >= (int) viewPtList.size())
3240 viewPtIdx--;
3242 setViewPt();
3243 }
3244}

◆ distanceToTrajectory()

void G4OpenInventorQtExaminerViewer::distanceToTrajectory ( const SbVec3f & q,
float & dist,
SbVec3f & closestPoint,
int & index )
protected

Definition at line 1817 of file G4OpenInventorQtExaminerViewer.cc.

1821{
1822 // a : Previous point on trajectory
1823 // b : Next point on trajectory
1824 // q : the point in space
1825 // dab, daq, dbq: distance between a & b, a & q, b & q
1826 //
1827 // Theory: A point p on a line ab is defined as:
1828 //
1829 // p(t) = a+t?(b?a)
1830 //
1831 // note: All are vectors except the parameter t
1832 //
1833 // When t is between 0 and 1 the point p is situated between a and b on ab.
1834 // The point p is defined in terms of the parameter t, subsequently so does
1835 // the distance from the query point q to the point p. To find the minimum
1836 // of that distance we differentiate it and set equal to zero:
1837 //
1838 // diff(Norm(p(t)- q)) = 0
1839 //
1840 // note: diff means taking the derivative with regard to t
1841 //
1842 // The resulting t is given in the code below. The square of the distance
1843 // between p and q is given by:
1844 //
1845 // d^2 = (Norm(p(t)-q))^2
1846 //
1847 // The expression found is given in the code below (current_dist)
1848 //
1849 // Ref: http://programmizm.sourceforge.net/blog/2012/
1850 // distance-from-a-point-to-a-polyline
1851 //
1852 // --PLG
1853
1854 const std::size_t count = refParticleTrajectory.size();
1855 assert(count>0);
1856
1857 SbVec3f b = refParticleTrajectory[0];
1858 SbVec3f dbq = b - q;
1859 float sqrDist = sqrlen(dbq);
1860 closestPoint = b;
1861 index = 0;
1862 for (std::size_t i = 1; i < count; ++i) {
1863 const SbVec3f a = b;
1864 const SbVec3f daq = dbq;
1865 b = refParticleTrajectory[i];
1866 dbq = b - q;
1867 const SbVec3f dab = a - b;
1868
1869 float dab_x, dab_y, dab_z;
1870 dab.getValue(dab_x,dab_y,dab_z);
1871 float daq_x, daq_y, daq_z;
1872 daq.getValue(daq_x, daq_y, daq_z);
1873 float dbq_x, dbq_y, dbq_z;
1874 dbq.getValue(dbq_x, dbq_y, dbq_z);
1875
1876 const float inv_sqrlen = 1./sqrlen(dab);
1877 const float t = (dab_x*daq_x + dab_y*daq_y + dab_z*daq_z)*inv_sqrlen;
1878
1879 if (t<0.) {
1880 // The trajectory point occurs before point a
1881 // Go to the next point
1882 continue;
1883 }
1884 float current_dist;
1885 if (t<=1.) {
1886 // The trajectory point occurs between a and b.
1887 // Compute the distance to that point
1888 current_dist = daq_x*daq_x + daq_y*daq_y + daq_z*daq_z
1889 - t*(daq_x*dab_x + daq_y*dab_y + daq_z*dab_z)
1890 + t*t*(dab_x*dab_x + dab_y*dab_y + dab_z*dab_z);
1891 }
1892 else { //t>1.
1893 // The trajectory point occurs after b.
1894 // Get the distance to point b
1895 current_dist = sqrlen(dbq);
1896 }
1897
1898 if (current_dist < sqrDist) {
1899 sqrDist = current_dist;
1900 closestPoint = a + t*(b-a);
1901 index = (int) i;
1902 }
1903 }
1904
1905 dist = std::sqrt(sqrDist);
1906}

Referenced by sortElements().

◆ evenOutRefParticlePts()

void G4OpenInventorQtExaminerViewer::evenOutRefParticlePts ( )
protected

Definition at line 2235 of file G4OpenInventorQtExaminerViewer.cc.

2236{
2237 if(refParticleTrajectory.empty())
2238 return;
2239
2240 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
2241 float avgDistBtwPts = 0;
2242 float totalDistBtwPts = 0;
2243 std::vector<SbVec3f> newRefParticleTrajectory;
2244 SbVec3f refPoint;
2245 std::size_t size = refParticleTrajectory.size() - 1;
2246 int numOfPts = 0;
2247 for (std::size_t i = 0; i < size; ++i) {
2248 p1 = refParticleTrajectory[i];
2249 p2 = refParticleTrajectory[i + 1];
2250 if (p1 == p2)
2251 continue;
2252 numOfPts++;
2253 totalDistBtwPts += (p2 - p1).length();
2254 }
2255 // Nothing useful to do (and fix Coverity)
2256 if (numOfPts <= 2) return;
2257
2258 avgDistBtwPts = totalDistBtwPts / numOfPts;
2259 float minDistAllowed = 0.75 * avgDistBtwPts;
2260 // float maxDistAllowed = 1.25 * avgDistBtwPts; // Pts tend to be close not far
2261
2262 float x, y, z;
2263 std::size_t i = 0, j = 0;
2264 while (i < size) {
2265 p1 = refParticleTrajectory[i];
2266 p2 = refParticleTrajectory[i + 1];
2267
2268 refPoint = p1;
2269 p1.getValue(x, y, z);
2270
2271 newRefParticleTrajectory.push_back(refPoint);
2272
2273 j = i;
2274 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
2275 j++;
2276
2277 p1 = refParticleTrajectory[j];
2278 p2 = refParticleTrajectory[j + 1];
2279 }
2280 if (j != i)
2281 i = j + 1;
2282 else
2283 i++;
2284 }
2285
2286 refParticleTrajectory.clear();
2287 refParticleTrajectory = newRefParticleTrajectory;
2288}

Referenced by setReferencePath().

◆ findAndSetRefPath()

void G4OpenInventorQtExaminerViewer::findAndSetRefPath ( )
protected

Definition at line 1588 of file G4OpenInventorQtExaminerViewer.cc.

1589{
1590 SoSearchAction action;
1591 action.setType(SoLineSet::getClassTypeId(),false);
1592 action.setInterest(SoSearchAction::ALL);
1593 action.apply(getSceneGraph());
1594
1595 SoPathList &pathList = action.getPaths();
1596
1597 if(pathList.getLength() != 0) {
1598
1599 SoCoordinate3 * coords = NULL;
1600 std::vector<SoCoordinate3 *> coordvec;
1601 std::vector<SoLineSet *> linevec;
1602
1603 bool refPathFound = false;
1604 for(int i = 0; i < pathList.getLength(); ++i) {
1605 SoFullPath *path = (SoFullPath *)pathList[i];
1606
1607 G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(path->getTail());
1608 if(attHolder != nullptr)
1609 {
1610 for (std::size_t j = 0; j < attHolder->GetAttDefs().size(); ++j) {
1611 std::ostringstream oss;
1612 oss << G4AttCheck(attHolder->GetAttValues()[j],
1613 attHolder->GetAttDefs()[j]);
1614
1615 std::string findStr = "Type of trajectory (Type): ";
1616 std::string compareValue = "REFERENCE";
1617 std::size_t idx = oss.str().find(findStr);
1618
1619 if(idx != std::string::npos) {
1620 if(oss.str().substr(idx + findStr.size(),
1621 compareValue.size()) == compareValue) {
1622 coords = getCoordsNode(path);
1623 if(coords != NULL) {
1624 refPathFound = true;
1625 coordvec.push_back(coords);
1626 linevec.push_back((SoLineSet *)path->getTail());
1627 }
1628 break;
1629 }
1630 }
1631
1632 findStr = "Track ID (ID): ";
1633 idx = oss.str().find(findStr);
1634 if(idx != std::string::npos) {
1635 //index all primary tracks
1636 std::string tmpstr = oss.str().substr(idx + findStr.size(),1);
1637 std::istringstream buffer(tmpstr);
1638 int num;
1639 buffer >> num;
1640 if(num == 1) {
1641
1642 // Check if next character is a number,
1643 // in which case we don't have Track ID 1
1644 // FWJ attempt to fix Coverity issue.
1645 char nextChar = oss.str().at(idx+findStr.size()+1);
1646 // const char * nextChar =
1647 // oss.str().substr(idx + findStr.size() + 1,1).c_str();
1648 if(std::isdigit(nextChar))
1649 break; //Not a primary track, continue with next track
1650
1651 coords = getCoordsNode(path);
1652 if(coords != NULL) {
1653 coordvec.push_back(coords);
1654 linevec.push_back((SoLineSet *)path->getTail());
1655 break; //Found coords node, continue with next track
1656 }
1657 }
1658 else
1659 break; //Not a primary track, continue with next track
1660 }
1661 else{
1662 //Not a Track ID attribute, fall through
1663 }
1664 }
1665 }
1666
1667 if(refPathFound)
1668 break;
1669 }
1670
1671 if(coordvec.empty())
1672 return; //No track with a Coordinate3 node found
1673
1674 if(refPathFound) {
1675 //set ref path to last traj, coord in the vecs
1676 setReferencePath(linevec.back(), coordvec.back());
1677 return;
1678 }
1679 //else
1680
1681 int longestIdx = 0;
1682 float longestLength = 0.0;
1683 // For all paths
1684 for(unsigned int i=0;i < linevec.size(); ++i) {
1685
1686 //First generate a vector with all the points in this lineset
1687 std::vector<SbVec3f> trajectory;
1688 // For all lines in the i path
1689 for(int j=0; j < linevec[i]->numVertices.getNum(); ++j) {
1690 // For all points in line j
1691 for(int k=0; k < linevec[i]->numVertices[j]; ++k) {
1692 trajectory.push_back(coordvec[i]->point[k]);
1693 }
1694 }
1695
1696 // Then calculate the total length
1697 float tmpLength=0.0;
1698 for(unsigned int j=0; j < trajectory.size() - 1; ++j) {
1699 tmpLength += (trajectory[j] - trajectory[j + 1]).length();
1700 }
1701
1702 if(tmpLength > longestLength) {
1703 longestIdx = i;
1704 longestLength = tmpLength;
1705 }
1706 }
1707
1708 // Set the longest path as the reference path
1709 setReferencePath(linevec[longestIdx], coordvec[longestIdx]);
1710 }
1711}
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
SoCoordinate3 * getCoordsNode(SoFullPath *path)
void setReferencePath(SoLineSet *, SoCoordinate3 *, bool append=false)

Referenced by sceneChangeCB().

◆ getCoordsNode()

SoCoordinate3 * G4OpenInventorQtExaminerViewer::getCoordsNode ( SoFullPath * path)
protected

Definition at line 1714 of file G4OpenInventorQtExaminerViewer.cc.

1715{
1716 SoLineSet *trajectory = (SoLineSet *)path->getTail();
1717 SoSeparator * grpNode = (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1718 int nodeIndex = grpNode->findChild(trajectory);
1719 SoNode * tmpNode;
1720
1721 // We allow only 100 iterations, in case the node isn't found
1722 // (should take only a few iterations)
1723 for (int i = 0; i < 100; ++i) {
1724 --nodeIndex;
1725
1726 tmpNode = grpNode->getChild(nodeIndex);
1727 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1728 //node found
1729 return (SoCoordinate3 *)tmpNode;
1730 }
1731 }
1732 return NULL; //coords node not found
1733}

Referenced by findAndSetRefPath().

◆ getEtcMenu()

QMenu * G4OpenInventorQtExaminerViewer::getEtcMenu ( )
inline

Definition at line 208 of file G4OpenInventorQtExaminerViewer.hh.

208{ return etcmenu; }

Referenced by G4OpenInventorQtViewer::Initialise().

◆ getFileMenu()

QMenu * G4OpenInventorQtExaminerViewer::getFileMenu ( )
inline

Definition at line 207 of file G4OpenInventorQtExaminerViewer.hh.

207{ return filemenu; }

Referenced by G4OpenInventorQtViewer::Initialise().

◆ getFont()

QFont * G4OpenInventorQtExaminerViewer::getFont ( )
inline

Definition at line 209 of file G4OpenInventorQtExaminerViewer.hh.

209{ return font; };

Referenced by G4OpenInventorQtViewer::Initialise().

◆ getMenubar()

QMenuBar * G4OpenInventorQtExaminerViewer::getMenubar ( )
inline

Definition at line 206 of file G4OpenInventorQtExaminerViewer.hh.

206{ return menubar; }

◆ getSceneElements()

void G4OpenInventorQtExaminerViewer::getSceneElements ( )
protected

Definition at line 1738 of file G4OpenInventorQtExaminerViewer.cc.

1739{
1740 std::string field, eltName;
1741
1742 std::map<std::string, int> duplicates;
1743 std::map<std::string, int> sceneElts;
1744 SoSearchAction search;
1745 Geant4_SoPolyhedron *node;
1746 SoGroup *root = (SoGroup *)getSceneManager()->getSceneGraph();
1747
1748 SoBaseKit::setSearchingChildren(TRUE);
1749
1750 search.reset();
1751 search.setSearchingAll(TRUE);
1752 search.setInterest(SoSearchAction::ALL);
1753 search.setType(Geant4_SoPolyhedron::getClassTypeId(), 0);
1754
1755 // FWJ DEBUG
1756 // G4cout << "Searching for elements....." << G4endl;
1757 search.apply(root);
1758
1759 SoPathList &pl = search.getPaths();
1760
1761
1762 // First find which names occur more than once so we can append a counter to them
1763 for (int i = 0; i < pl.getLength(); i++) {
1764 SoFullPath *path = (SoFullPath *)pl[i];
1765 node = (Geant4_SoPolyhedron *)path->getTail();
1766 eltName = node->getName();
1767 // G4cout << " FOUND " << i << " " << eltName << G4endl;
1768 if(duplicates.count(eltName))
1769 duplicates[eltName]++;
1770 else
1771 duplicates[eltName] = 1;
1772 }
1773
1774 for(int i = 0; i < pl.getLength(); i++) {
1775 float x,y,z;
1776 std::stringstream ssCount;
1777 SoFullPath *path = (SoFullPath *)pl[i];
1778 node = (Geant4_SoPolyhedron *)path->getTail();
1779 eltName = node->getName();
1780 field = eltName;
1781 if(duplicates[eltName] == 1)
1782 ssCount << "";//duplicates[field]
1783 else {
1784 if(sceneElts.count(eltName))
1785 sceneElts[eltName]++;
1786 else
1787 sceneElts[eltName] = 1;
1788
1789 ssCount << sceneElts[eltName];
1790 field += "_";
1791 }
1792
1793 field += ssCount.str();
1794
1795 SoGetBoundingBoxAction bAction(getViewportRegion());
1796 bAction.apply(path);
1797 SbBox3f bBox = bAction.getBoundingBox();
1798
1799 SbVec3f centr = bBox.getCenter();
1800 centr.getValue(x,y,z);
1801
1802 path->ref();
1803 sceneElement el = { field, path, centr, 0.0 };
1804 sceneElements.push_back(el);
1805 }
1806}

Referenced by setReferencePath().

◆ getSuperimpositionNode()

SoNode * G4OpenInventorQtExaminerViewer::getSuperimpositionNode ( SoNode * root,
const char * name )
protected

Definition at line 782 of file G4OpenInventorQtExaminerViewer.cc.

784{
785 if (!searcher)
786 searcher = new SoSearchAction;
787 searcher->reset();
788 searcher->setName(SbName(name));
789 searcher->setInterest(SoSearchAction::FIRST);
790 searcher->setSearchingAll(TRUE);
791 searcher->apply(root);
792 assert(searcher->getPath());
793 return searcher->getPath()->getTail();
794}

Referenced by construct().

◆ GetUIQt()

G4UIQt * G4OpenInventorQtExaminerViewer::GetUIQt ( )
inline

Definition at line 197 of file G4OpenInventorQtExaminerViewer.hh.

197{return uiQt;}

◆ gotoRefPathStart()

void G4OpenInventorQtExaminerViewer::gotoRefPathStart ( )
protected

Definition at line 2477 of file G4OpenInventorQtExaminerViewer.cc.

2478{
2479 G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB();
2480}

◆ incSpeed()

void G4OpenInventorQtExaminerViewer::incSpeed ( )
protected

Definition at line 1469 of file G4OpenInventorQtExaminerViewer.cc.

1469 {
1470 if (std::ceil(animateBtwPtsPeriod * 100) >= 4) {
1471 if (speedStep > 0.08)
1472 speedStep -= 0.02;
1473 else
1474 speedStep = 0.02;
1476 } else
1477 animateBtwPtsPeriod = 0.0;
1478
1480 int lastIdx = (int) refParticleTrajectory.size() - 1;
1483 }
1484}

Referenced by processSoEvent().

◆ invertRefPath()

void G4OpenInventorQtExaminerViewer::invertRefPath ( )
protected

◆ loadViewPts()

bool G4OpenInventorQtExaminerViewer::loadViewPts ( )
protected

Definition at line 910 of file G4OpenInventorQtExaminerViewer.cc.

911{
912 bool error = false;
913 viewPtData tmp;
914 std::string token;
915 SbVec3f axis;
916 SbRotation orient;
917 float x{0.0}, y{0.0}, z{0.0}, angle{0.0};
918
919 // Gets the last view point accessed, stored in the first line of the data file.
920 fileIn >> token;
921 parseString<int>(viewPtIdx, token, error);
922 getline(fileIn, token); // Remove "\n"
923 // Converts data from string type into necessary types
924 while (getline(fileIn, token)) {
925
926 std::size_t end = token.find_last_not_of(' '); // Remove padded spaces
927 token = token.substr(0, end + 1);
928
929 char *vpName = new char[token.size() + 1];
930 strcpy(vpName, token.c_str());
931 tmp.viewPtName = vpName;
932 fileIn >> token;
933
934 parseString<float>(x, token, error);
935 fileIn >> token;
936 parseString<float>(y, token, error);
937 fileIn >> token;
938 parseString<float>(z, token, error);
939 fileIn >> token;
940 tmp.position = axis.setValue(x, y, z);
941
942 parseString<float>(x, token, error);
943 fileIn >> token;
944 parseString<float>(y, token, error);
945 fileIn >> token;
946 parseString<float>(z, token, error);
947 fileIn >> token;
948 parseString<float>(angle, token, error);
949 fileIn >> token;
950 orient.setValue(axis.setValue(x, y, z), angle);
951 tmp.orientation = orient.getValue();
952
953 int camType{0};
954 parseString<int>(camType, token, error);
955 fileIn >> token;
956 tmp.camType = (CameraType) camType;
957
958 parseString<float>(tmp.height, token, error);
959 fileIn >> token;
960 parseString<float>(tmp.focalDistance, token, error);
961 fileIn >> token;
962 parseString<float>(tmp.nearDistance, token, error);
963 fileIn >> token;
964 parseString<float>(tmp.farDistance, token, error);
965 fileIn >> token;
966 parseString<int>(tmp.viewportMapping, token, error);
967 fileIn >> token;
968 parseString<float>(tmp.aspectRatio, token, error);
969
970 getline(fileIn, token); // To remove "\n" characters
971 getline(fileIn, token);
972
973 if (error) {
974 viewPtIdx = 0;
975 viewPtList.clear();
976 return false;
977 }
978 viewPtList.push_back(tmp);
979 }
980
981 return true;
982}
void parseString(T &t, const std::string &s, bool &error)

Referenced by afterRealizeHook().

◆ mouseoverCB()

void G4OpenInventorQtExaminerViewer::mouseoverCB ( void * aThis,
SoEventCallback * eventCB )
staticprotected

Definition at line 1267 of file G4OpenInventorQtExaminerViewer.cc.

1268{
1269 SoHandleEventAction* action = eventCB->getAction();
1270 const SoPickedPoint* pp = action->getPickedPoint();
1272
1273 if(!This->abbrOutputFlag)
1274 return;
1275
1276 if(pp != NULL) {
1277
1278 const SbViewportRegion & viewportRegion = action->getViewportRegion();
1279
1280 std::string sLogName;
1281 float x,y,z;
1282 std::stringstream ssZPos;
1283 std::stringstream ssSolids;
1284 std::stringstream ssMaterials;
1285 SoPath * path = pp->getPath();
1286 SoNode* node = ((SoFullPath*)path)->getTail();
1287
1288 if(node->getTypeId() == Geant4_SoPolyhedron::getClassTypeId()) {
1289
1290 sLogName = "Logical Volume: ";
1291 sLogName += ((Geant4_SoPolyhedron *)node)->getName().getString();
1292
1293 SoGetBoundingBoxAction bAction(viewportRegion);
1294 bAction.apply((SoFullPath*)path);
1295 SbBox3f bBox = bAction.getBoundingBox();
1296 SbVec3f centr = bBox.getCenter();
1297 centr.getValue(x,y,z);
1298 ssZPos << "Pos: " << x << " " << y << " " << z;
1299
1300 G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1301 if(attHolder && attHolder->GetAttDefs().size()) {
1302
1303 std::vector<const std::map<G4String,G4AttDef>*> vecDefs =
1304 attHolder->GetAttDefs();
1305 std::vector<const std::vector<G4AttValue>*> vecVals =
1306 attHolder->GetAttValues();
1307 for (std::size_t i = 0; i < vecDefs.size(); ++i) {
1308 const std::vector<G4AttValue> * vals = vecVals[i];
1309
1310 std::vector<G4AttValue>::const_iterator iValue;
1311
1312 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1313 const G4String& valueName = iValue->GetName();
1314 const G4String& value = iValue->GetValue();
1315
1316 if(valueName == "Solid") {
1317 if(ssSolids.str() == "")
1318 ssSolids << "Solid Name: " << value;
1319 else
1320 ssSolids << ", " << value;
1321 }
1322
1323 if(valueName == "Material") {
1324 if(ssMaterials.str() == "")
1325 ssMaterials << "Material Name: " << value;
1326 else
1327 ssMaterials << ", " << value;
1328 }
1329 }
1330 }
1331 }
1332 }
1333 // FWJ Mouseover for trajectories
1334 else if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1335 // G4cout << "Trajectory!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << G4endl;
1336 G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1337 if(attHolder && attHolder->GetAttDefs().size()) {
1338 std::string strTrajPoint = "G4TrajectoryPoint:";
1339 std::ostringstream oss;
1340 G4String t1, t1Ch, t2, t3, t4;
1341 for (std::size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
1342 // G4cout << "Getting index " << i << " from attHolder" << G4endl;
1343 // No, returns a vector!
1344 // G4AttValue* attValue = attHolder->GetAttValues()[i];
1345 const std::vector<G4AttValue>* vals = attHolder->GetAttValues()[i];
1346 std::vector<G4AttValue>::const_iterator iValue;
1347 for (iValue = vals->begin(); iValue != vals->end(); ++iValue) {
1348 const G4String& valueName = iValue->GetName();
1349 const G4String& value = iValue->GetValue();
1350 // G4cout << " valueName = " << valueName << G4endl;
1351 // G4cout << " value = " << value << G4endl;
1352 // LINE 1
1353 if (valueName == "PN") t1 = value;
1354 if (valueName == "Ch") {
1355 if (atof(value.c_str()) > 0)
1356 t1Ch = " +";
1357 else
1358 t1Ch = " ";
1359 t1Ch += value;
1360 }
1361 if (valueName == "PDG") {
1362 t1 += " ";
1363 t1 += value;
1364 t1 += t1Ch;
1365 This->mouseOverTextLogName->string.setValue(t1);
1366 }
1367 // G4cout << " t1 = " << t1 << G4endl;
1368 // LINE 2
1369 if (valueName == "EventID") t2 = "Evt " + value;
1370 if (valueName == "ID") t2 += " Trk " + value;
1371 if (valueName == "PID") {
1372 t2 += " Prt " + value;
1373 This->mouseOverTextSolid->string.setValue(t2);
1374 }
1375 // LINE 3
1376 if (valueName == "IKE") t3 = "KE " + value;
1377 if (valueName == "IMom") {
1378 // Remove units
1379 std::size_t ipos = value.rfind(" ");
1380 G4String value1 = value;
1381 value1.erase(ipos);
1382 t3 += " P (" + value1 + ")";
1383 }
1384 if (valueName == "IMag") {
1385 t3 += " " + value + "/c";
1386 // t3 += " " + value;
1387 This->mouseOverTextMaterial->string.setValue(t3);
1388 }
1389 // LINE 4
1390 if (valueName == "NTP") {
1391 std::ostringstream t4oss;
1392 t4oss << "TrjPts " << value;
1393 t4oss << " Pos " << pp->getPoint()[0] << " " << pp->getPoint()[1] <<
1394 " " << pp->getPoint()[2];
1395 This->mouseOverTextZPos->string.setValue(SbString(t4oss.str().c_str()));
1396 }
1397 }
1398// G4cout << " NOW CALLING G4AttCheck" << G4endl;
1399// G4cout << G4AttCheck(attHolder->GetAttValues()[i],
1400// attHolder->GetAttDefs()[i]);
1401// oss << G4AttCheck(attHolder->GetAttValues()[i],
1402// attHolder->GetAttDefs()[i]);
1403// if(oss.str().find(strTrajPoint) != std::string::npos) {
1404// // Last attribute displayed was a trajectory point. Since we
1405// // want abbreviated output, display the last one and exit
1406// // (unless we're already at the last (and only) trajectory point)
1407// if(i != attHolder->GetAttDefs().size()-1) {
1408// G4cout << G4AttCheck(
1409// attHolder->GetAttValues()[attHolder->GetAttDefs().size()-1],
1410// attHolder->GetAttDefs()[attHolder->GetAttDefs().size()-1]);
1411// }
1412// break;
1413// }
1414 }
1415 }
1416 This->setSuperimpositionEnabled(This->superimposition, TRUE);
1417 This->scheduleRedraw();
1418 eventCB->setHandled();
1419 return;
1420 }
1421
1422 bool redraw = false;
1423 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != sLogName) {
1424 This->mouseOverTextLogName->string.setValue(SbString(sLogName.c_str()));
1425 redraw = true;
1426 }
1427 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != ssSolids.str()) {
1428 This->mouseOverTextSolid->string.setValue(SbString(ssSolids.str().c_str()));
1429 redraw = true;
1430 }
1431 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != ssMaterials.str()) {
1432 This->mouseOverTextMaterial->string.setValue(SbString(ssMaterials.str().c_str()));
1433 redraw = true;
1434 }
1435 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != ssZPos.str()) {
1436 This->mouseOverTextZPos->string.setValue(SbString(ssZPos.str().c_str()));
1437 redraw = true;
1438 }
1439
1440 if(redraw) {
1441 This->setSuperimpositionEnabled(This->superimposition, TRUE);
1442 This->scheduleRedraw();
1443 }
1444
1445 eventCB->setHandled();
1446 }
1447 else {
1448 if(std::string(This->mouseOverTextLogName->string.getValues(0)->getString()) != "") {
1449 This->mouseOverTextLogName->string.setValue(SbString(""));
1450 This->scheduleRedraw();
1451 }
1452 if(std::string(This->mouseOverTextSolid->string.getValues(0)->getString()) != "") {
1453 This->mouseOverTextSolid->string.setValue(SbString(""));
1454 This->scheduleRedraw();
1455 }
1456 if(std::string(This->mouseOverTextMaterial->string.getValues(0)->getString()) != "") {
1457 This->mouseOverTextMaterial->string.setValue(SbString(""));
1458 This->scheduleRedraw();
1459 }
1460 if(std::string(This->mouseOverTextZPos->string.getValues(0)->getString()) != "") {
1461 This->mouseOverTextZPos->string.setValue(SbString(""));
1462 This->scheduleRedraw();
1463 }
1464 }
1465}

Referenced by afterRealizeHook().

◆ moveCamera()

void G4OpenInventorQtExaminerViewer::moveCamera ( float dist = 0,
bool lookdown = false )
protected

Definition at line 1014 of file G4OpenInventorQtExaminerViewer.cc.

1015{
1016
1017 SoCamera *cam = getCamera();
1018 SbVec3f p1, p2; // The particle moves from p1 to p2
1019 SbVec3f particleDir; // Direction vector from p1 to p2
1020 SbVec3f camPosNew{0.0f, 0.0f, 0.0f}; // New position of the camera
1021
1022 if(refParticleTrajectory.size() == 0) {
1023 //refParticleTrajectory hasn't been set yet
1024 if(dist)
1025 distance = dist;
1026 else
1027 distance = (cam->position.getValue() - center).length();
1028
1029 cam->position.setValue(center + offsetFromCenter*distance);
1030 cam->focalDistance = (cam->position.getValue() - center).length();
1031 cam->pointAt(center, upVector);
1032 }
1033 else {
1034
1035 // If we move forward past the last trajectory point,
1036 // go back to the beginning
1037 if (refParticleIdx >= (int) refParticleTrajectory.size() - 1) {
1039 dist = (prevPt - cam->position.getValue()).length();
1040 refParticleIdx = 0;
1041 }
1042 // If we move backward past the beginning,
1043 // go to the last trajectory point
1044 if (refParticleIdx < 0) {
1046 dist = (prevPt - cam->position.getValue()).length();
1047 refParticleIdx = (int) refParticleTrajectory.size() - 2;
1048 }
1049
1050 // Set start and end points
1053
1054 // Get the direction from p1 to p2
1055 particleDir = p2 - p1;
1056 particleDir.normalize();
1057
1058 if(prevParticleDir == SbVec3f(0,0,0)) {
1059 // First time entering BEAMLINE mode, look at
1060 // the element from the front, with camera upright
1061 if(lookdown)
1062 camDir = SbVec3f(0,0,1);
1063 else
1064 camDir = SbVec3f(1,0,0);
1065 camUpVec = SbVec3f(0,1,0);
1066
1067 // In case the start of the goes in a
1068 // direction other than +z, rotate the camera accordingly
1069 SbRotation rot(SbVec3f(0,0,1), particleDir);
1070 rot.multVec(camDir, camDir);
1071 rot.multVec(camUpVec, camUpVec);
1072
1073 }
1074 else if(particleDir != prevParticleDir) {
1075 // The beamline has changed direction
1076
1077 SbRotation rot(prevParticleDir, particleDir);
1078 rot.multVec(camDir, camDir);
1079 rot.multVec(camUpVec, camUpVec);
1080
1081 }
1082
1083 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1084 if (!dist)
1085 distance = (prevPt - cam->position.getValue()).length();
1086 else
1087 distance = dist;
1088 }
1089
1090 // FWJ distance not relevant -- use focalDistance
1091 // if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1092 // if (!dist)
1093 // distance = (prevPt - cam->position.getValue()).length();
1094 // else
1095 // distance = dist;
1096 // }
1097
1098
1099 float x,y,z;
1100 prevPt.getValue(x,y,z);
1101
1102
1103 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
1104 camPosNew = p2 - (camDir*distance);
1105 }
1106 if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
1107 // FWJ maintain focal distance
1108 camPosNew = p2 - (camDir*cam->focalDistance.getValue());
1109 // camPosNew = p2 - (camDir);
1110 }
1111
1112 cam->position = camPosNew;
1113 cam->pointAt(p2, camUpVec);
1114 cam->focalDistance = (p2 - camPosNew).length();
1115
1116 p2.getValue(x,y,z);
1117 camPosNew.getValue(x,y,z);
1118
1119 prevParticleDir = particleDir;
1120 prevPt = p1; // For accurate distance calculation
1121
1122 }
1123
1124}

Referenced by processSoEvent().

◆ parseString()

template<class T >
void G4OpenInventorQtExaminerViewer::parseString ( T & t,
const std::string & s,
bool & error )

Definition at line 2618 of file G4OpenInventorQtExaminerViewer.cc.

2620{
2621 std::istringstream str(s);
2622 if ((str >> t).fail())
2623 error = true;
2624}

Referenced by loadViewPts().

◆ pickingCB()

void G4OpenInventorQtExaminerViewer::pickingCB ( void * aThis,
SoEventCallback * eventCB )
staticprotected

Definition at line 1127 of file G4OpenInventorQtExaminerViewer.cc.

1129{
1130 SoHandleEventAction* action = eventCB->getAction();
1131 const SoPickedPoint *pp = action->getPickedPoint();
1133
1134 if(pp != NULL) {
1135
1136 SoPath* path = pp->getPath();
1137 SoNode* node = ((SoFullPath*)path)->getTail();
1138
1139 if(node->getTypeId() == SoLineSet::getClassTypeId()) {
1140
1141 if(This->pickRefPathFlag) {
1142 This->pickRefPathFlag = false;
1143 if(This->viewingBeforePickRef != This->isViewing())
1144 This->setViewing(This->viewingBeforePickRef);
1145 else
1146 This->setComponentCursor(SoQtCursor(SoQtCursor::DEFAULT));
1147
1148 // The trajectory is a set of lines stored in a LineSet
1149 SoLineSet * trajectory = (SoLineSet *)node;
1150 // FWJ DEBUG
1151 // G4cout << "FOUND trajectory LineSet" << trajectory << G4endl;
1152
1153 // The set of all trajectories is stored in a Seperator group node
1154 // one level above the LineSet that was picked. The nodes under that
1155 // seperator are as follows (in this order): Material, LightModel,
1156 // ResetTransform, MatrixTransform, Coordinate3, DrawStyle, LineSet
1157 SoSeparator * grpNode =
1158 (SoSeparator*)(((SoFullPath*)path)->getNodeFromTail(1));
1159
1160 // The node that contains the coordinates for the trajectory is a
1161 // Coordinate3 node which occurs before the LineSet node. We iterate
1162 // back through the nodes in the group until we find the Coordinate3 node
1163 int nodeIndex = grpNode->findChild(trajectory);
1164 SoNode * tmpNode;
1165 // FWJ needs initialization
1166 SoCoordinate3 * coords = 0;
1167 // SoCoordinate3 * coords;
1168 // We allow only 100 iterations, in case the node isn't found
1169 // (should take only a few iterations)
1170 for(int i = 0; i < 100; ++i) {
1171 --nodeIndex;
1172
1173 tmpNode = grpNode->getChild(nodeIndex);
1174 if(tmpNode->getTypeId() == SoCoordinate3::getClassTypeId()) {
1175 //node found
1176 coords = (SoCoordinate3 *)tmpNode;
1177 break;
1178 }
1179 }
1180
1181 if(coords == NULL) {
1182 G4warn << "Could not find the coordinates node"
1183 " for the picked trajectory." << G4endl;
1184 G4warn << " Reference trajectory not set" << G4endl;
1185 return;
1186 }
1187 // FWJ DEBUG
1188 // G4cout << "FOUND SoCoordinate3 node " << coords << G4endl;
1189
1190
1191 if ((This->lshiftdown) || (This->rshiftdown))
1192 This->setReferencePath(trajectory, coords, true); //APPENDING
1193 else
1194 This->setReferencePath(trajectory, coords, false);
1195
1196 return;
1197
1198 }
1199 else if(This->abbrOutputFlag) {
1200
1201 G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1202 if(attHolder && attHolder->GetAttDefs().size()) {
1203
1204 std::string strTrajPoint = "G4TrajectoryPoint:";
1205 std::ostringstream oss;
1206 for (std::size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
1207 G4cout << G4AttCheck(attHolder->GetAttValues()[i],
1208 attHolder->GetAttDefs()[i]);
1209 oss << G4AttCheck(attHolder->GetAttValues()[i],
1210 attHolder->GetAttDefs()[i]);
1211 if(oss.str().find(strTrajPoint) != std::string::npos) {
1212
1213 // Last attribute displayed was a trajectory point. Since we
1214 // want abbreviated output, display the last one and exit
1215 // (unless we're already at the last (and only) trajectory point)
1216 if(i != attHolder->GetAttDefs().size()-1) {
1217 G4cout << G4AttCheck(
1218 attHolder->GetAttValues()[attHolder->GetAttDefs().size()-1],
1219 attHolder->GetAttDefs()[attHolder->GetAttDefs().size()-1]);
1220 }
1221 break;
1222 }
1223 }
1224 } else {
1225 G4String name((char*)node->getName().getString());
1226 G4String cls((char*)node->getTypeId().getName().getString());
1227 G4warn << "SoNode : " << node
1228 << " SoType : " << cls
1229 << " name : " << name
1230 << G4endl;
1231 G4warn << "No attributes attached." << G4endl;
1232 }
1233
1234 return;
1235 }
1236 else{
1237 //Go to default behavior
1238 }
1239 }
1240 else {
1241 //Go to default behavior
1242 }
1243
1244 // Default behavior in G4OpenInventorViewer::SelectionCB
1245 G4AttHolder* attHolder = dynamic_cast<G4AttHolder*>(node);
1246 if(attHolder && attHolder->GetAttDefs().size()) {
1247 for (std::size_t i = 0; i < attHolder->GetAttDefs().size(); ++i) {
1248 G4cout << G4AttCheck(attHolder->GetAttValues()[i],
1249 attHolder->GetAttDefs()[i]);
1250 }
1251 } else {
1252 G4String name((char*)node->getName().getString());
1253 G4String cls((char*)node->getTypeId().getName().getString());
1254 G4warn << "SoNode : " << node
1255 << " SoType : " << cls
1256 << " name : " << name
1257 << G4endl;
1258 G4warn << "No attributes attached." << G4endl;
1259 }
1260
1261 //Suppress other event handlers
1262 eventCB->setHandled();
1263 }
1264}
#define G4warn
Definition G4Scene.cc:41
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
const char * name(G4int ptype)

Referenced by afterRealizeHook().

◆ processSoEvent()

SbBool G4OpenInventorQtExaminerViewer::processSoEvent ( const SoEvent *const event)
protected

Definition at line 3456 of file G4OpenInventorQtExaminerViewer.cc.

3457{
3458
3459 // FWJ DEBUG
3460 // G4cout << "processSoEvent ############" << ++processSoEventCount << G4endl;
3461
3462 SoCamera *cam = getCamera();
3463 const SoType type(ev->getTypeId());
3464
3465// Needed to implement mouse wheel zoom direction change.
3466// Does not work with MacOS trackpad: use Coin3d default handler.
3467#ifndef __APPLE__
3468 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
3469 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
3470
3471 // if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
3472 // || currentState == PAUSED_ANIMATION) {
3473
3474 switch (me->getButton()) {
3475
3476 case SoMouseButtonEvent::BUTTON4: // Scroll wheel up
3477 if (me->getState() == SoButtonEvent::DOWN) {
3478 // G4cout << "SCROLL WHEEL UP" << G4endl;
3479 zoom(-0.1f);
3480 return TRUE;
3481 }
3482 break;
3483
3484 case SoMouseButtonEvent::BUTTON5: // Scroll wheel down
3485 if (me->getState() == SoButtonEvent::DOWN) {
3486 // G4cout << "SCROLL WHEEL DOWN" << G4endl;
3487 zoom(0.1f);
3488 return TRUE;
3489 }
3490 break;
3491
3492 default:
3493 break;
3494 }
3495 // }
3496 if (currentState == GENERAL) {
3497
3498 }
3499 }
3500#endif
3501
3502 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
3503 SoKeyboardEvent* ke = (SoKeyboardEvent*)ev;
3504
3505 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
3506 switch (ke->getKey()) {
3507 case SoKeyboardEvent::E:
3508 if (externalQtApp) {
3509 // G4cout << "E KEY PRESSED" << G4endl;
3510 return TRUE;
3511 } else {
3512 G4cout <<
3513 "E KEY PRESSED, EXITING OIQT VIEWER SECONDARY LOOP" <<
3514 G4endl;
3515 SoQt::exitMainLoop();
3516 // escapeCallback();
3517 return TRUE;
3518 }
3519 case SoKeyboardEvent::LEFT_SHIFT:
3520 this->lshiftdown = true;
3521 return TRUE;
3522 case SoKeyboardEvent::RIGHT_SHIFT:
3523 this->rshiftdown = true;
3524 return TRUE;
3525 case SoKeyboardEvent::LEFT_CONTROL:
3526 this->lctrldown = true;
3527 return TRUE;
3528 case SoKeyboardEvent::RIGHT_CONTROL:
3529 this->rctrldown = true;
3530 return TRUE;
3531 case SoKeyboardEvent::SPACE:
3532 if (currentState == ANIMATION
3536 if (animateSensor->isScheduled())
3537 animateSensor->unschedule();
3538 return TRUE;
3539 } else if (currentState == PAUSED_ANIMATION) {
3540 if (maxSpeed) {
3541 if ((beforePausing == ANIMATION
3543 < (int) refParticleTrajectory.size() - 1)
3545 && refParticleIdx > 0)) {
3548 }
3549 }
3550 return TRUE;
3551 }
3552 break;
3553 case SoKeyboardEvent::ESCAPE:
3554 if (currentState == ANIMATION
3557
3558 if (animateSensor->isScheduled())
3559 animateSensor->unschedule();
3562 setSuperimpositionEnabled(superimposition, FALSE);
3563 maxSpeed = 0.0f;
3564 step = 1;
3565
3566 scheduleRedraw();
3567 if (currentState == VIEWPOINT) {
3568 setSuperimpositionEnabled(superimposition, TRUE);
3569 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3570 animSpeedOutlineSwitch->whichChild.setValue(
3571 SO_SWITCH_NONE);
3572 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3573
3574 scheduleRedraw();
3575 }
3576 restoreCamera();
3577 return TRUE;
3578 }
3579 break;
3580 case SoKeyboardEvent::DELETE:
3581 if (viewPtList.size()
3582 && (currentState != ANIMATION
3585 // FWJ IMPLEMENT LATER
3586 // String dialogName = (char *) "Delete Viewpoint";
3587 // std::string msg = "Are you sure you want to delete current viewpoint?";
3588 // warningMsgDialog(msg, dialogName, deleteViewPtCB);
3589 return TRUE;
3590 }
3591 break;
3592 case SoKeyboardEvent::LEFT_ARROW:
3593 switch (currentState) {
3594 case BEAMLINE:
3595 if ((this->lshiftdown) || (this->rshiftdown)) {
3597 moveCamera();
3598 }
3599 else if ((this->lctrldown) || (this->rctrldown)) {
3600 if (SoQtExaminerViewer::isAnimating())
3601 stopAnimating();
3604 animateBtwPtsPeriod = 0.08f;
3605
3606 SbVec3f tmp = camDir;
3607 tmp.negate();
3608 rotAxis = tmp;
3609
3610 rotCnt = ROT_CNT;
3611 moveCamera(); // To make sure camera is perpendicular to the beamline
3612 rotateCamera();
3613 }
3614 else {
3615 if (SoQtExaminerViewer::isAnimating())
3616 stopAnimating();
3619 animateBtwPtsPeriod = 0.08f;
3620
3621 SbVec3f tmp = camUpVec;
3622 tmp.negate();
3623 rotAxis = tmp;
3624
3625 rotCnt = ROT_CNT;
3626 moveCamera(); // To make sure camera is perpendicular to the beamline
3627 rotateCamera();
3628
3629 }
3630 return TRUE;
3631
3632 case ANIMATION:
3633 case REVERSED_ANIMATION:
3634 left_right -= 1.5f;
3635 return TRUE;
3636 case PAUSED_ANIMATION:
3637 left_right -= 1.5f;
3639 cam->position = myCam->position;
3640 return TRUE;
3641 case GENERAL:
3642 case VIEWPOINT:
3643 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3644 // Using this allows us to look around without
3645 // changing the camera parameters (camDir, camUpVec)
3646 this->bottomWheelMotion(
3647 this->getBottomWheelValue() + 0.1f);
3648
3649 return TRUE;
3650 }
3651 break;
3652 case ROTATING:
3653 // For this state, let the keyboard event
3654 // be handled by superclass
3655 break;
3656 default:
3657 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3658 "Unhandled viewer state");
3659 break;
3660 }
3661 break;
3662
3663 case SoKeyboardEvent::RIGHT_ARROW:
3664 switch(currentState) {
3665 case BEAMLINE:
3666 if ((this->lshiftdown) || (this->rshiftdown)) {
3668 moveCamera();
3669 }
3670 else if ((this->lctrldown) || (this->rctrldown)) {
3671 if (SoQtExaminerViewer::isAnimating())
3672 stopAnimating();
3675 animateBtwPtsPeriod = 0.08f;
3676
3677 rotAxis = camDir;
3678
3679 rotCnt = ROT_CNT;
3680 moveCamera(); // To make sure camera is perpendicular to the beamline
3681 rotateCamera();
3682 }
3683 else{
3684 if (SoQtExaminerViewer::isAnimating())
3685 stopAnimating();
3688 animateBtwPtsPeriod = 0.08f;
3689
3690 rotAxis = camUpVec;
3691
3692 rotCnt = ROT_CNT;
3693 moveCamera(); // To make sure camera is perpendicular to the beamline
3694 rotateCamera();
3695 }
3696 return TRUE;
3697
3698 case ANIMATION:
3699 case REVERSED_ANIMATION:
3700 left_right += 1.5f;
3701 return TRUE;
3702 case PAUSED_ANIMATION:
3703 left_right += 1.5f;
3705 cam->position = myCam->position;
3706 return TRUE;
3707 case GENERAL:
3708 case VIEWPOINT:
3709 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3710 // Using this allows us to look around without
3711 // changing the camera parameters (camDir, camUpVec)
3712 this->bottomWheelMotion(
3713 this->getBottomWheelValue() - 0.1f);
3714 return TRUE;
3715 }
3716 break;
3717 case ROTATING:
3718 // For this state, let the keyboard event
3719 // be handled by superclass
3720 break;
3721 default:
3722 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3723 "Unhandled viewer state");
3724 break;
3725 }
3726 break;
3727
3728 case SoKeyboardEvent::DOWN_ARROW:
3729 switch(currentState) {
3730 case BEAMLINE:
3731
3732 if ((this->lshiftdown) || (this->rshiftdown)) {
3734 moveCamera();
3735 }
3736 else{
3737 if (SoQtExaminerViewer::isAnimating())
3738 stopAnimating();
3741 animateBtwPtsPeriod = 0.08f;
3742
3743 rotAxis = camDir.cross(camUpVec);
3744
3745 rotCnt = ROT_CNT;
3746 moveCamera(); // To make sure camera is perpendicular to the beamline
3747 rotateCamera();
3748
3749 }
3750 return TRUE;
3751
3752 case ANIMATION:
3753 case REVERSED_ANIMATION:
3754 up_down -= 1.5f;
3755 return TRUE;
3756 case PAUSED_ANIMATION:
3757 up_down -= 1.5f;
3759 cam->position = myCam->position;
3760 return TRUE;
3761 case GENERAL:
3762 case VIEWPOINT:
3763 // Using this allows us to look around without
3764 // changing the camera parameters (camDir, camUpVec)
3765 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3766 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
3767 return TRUE;
3768 }
3769 break;
3770 case ROTATING:
3771 // For this state, let the keyboard event
3772 // be handled by superclass
3773 break;
3774 default:
3775 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3776 "Unhandled viewer state");
3777 break;
3778 }
3779 break;
3780
3781 case SoKeyboardEvent::UP_ARROW:
3782 switch(currentState) {
3783 case BEAMLINE:
3784 if ((this->lshiftdown) || (this->rshiftdown)) {
3786 moveCamera();
3787 }
3788 else{
3789 if (SoQtExaminerViewer::isAnimating())
3790 stopAnimating();
3793 animateBtwPtsPeriod = 0.08f;
3794
3795 rotAxis = camUpVec.cross(camDir);
3796
3797 rotCnt = ROT_CNT;
3798 moveCamera();
3799
3800 rotateCamera();
3801
3802
3803 }
3804 return TRUE;
3805 case ANIMATION:
3806 case REVERSED_ANIMATION:
3807 up_down += 1.5f;
3808 return TRUE;
3809 case PAUSED_ANIMATION:
3810 up_down += 1.5f;
3812 cam->position = myCam->position;
3813 return TRUE;
3814 case GENERAL:
3815 case VIEWPOINT:
3816 // Using this allows us to look around without
3817 // changing the camera parameters (camDir, camUpVec)
3818 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3819 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
3820 return TRUE;
3821 }
3822 break;
3823 case ROTATING:
3824 // For this state, let the keyboard event
3825 // be handled by superclass
3826 break;
3827 default:
3828 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3829 "Unhandled viewer state");
3830 break;
3831 }
3832 break;
3833
3834 case SoKeyboardEvent::PAGE_UP:
3835 switch(currentState) {
3836 case BEAMLINE:
3837 if (step < (int) refParticleTrajectory.size() / 5) // Magic number
3838 step++;
3839 return TRUE;
3840 case ANIMATION:
3841 incSpeed();
3843 if (maxSpeed > 0.8)
3845 scheduleRedraw();
3846
3847 return TRUE;
3848 case REVERSED_ANIMATION:
3849 if(!animateSensor->isScheduled()) {
3851 if (refParticleIdx
3852 < (int) refParticleTrajectory.size() - 1) {
3855 scheduleRedraw();
3857 }
3858 }
3859 else{
3861 decSpeed();
3862 scheduleRedraw();
3863 }
3864 return TRUE;
3865 case PAUSED_ANIMATION:
3867 if (maxSpeed > 0.8)
3869
3870 if (beforePausing == ANIMATION) {
3871 incSpeed();
3872 } else {
3873 decSpeed();
3876 }
3877
3878 scheduleRedraw();
3879 return TRUE;
3880 default: //fall through
3881 break;
3882 }
3883 break;
3884
3885 case SoKeyboardEvent::PAGE_DOWN:
3886 switch(currentState) {
3887 case BEAMLINE:
3888 if (step > 1)
3889 step--;
3890 return TRUE;
3891 case ANIMATION:
3892 if(!animateSensor->isScheduled()) {
3894 if (refParticleIdx > 1) {
3897 scheduleRedraw();
3899 }
3900 }
3901 else{
3903 decSpeed();
3904 scheduleRedraw();
3905 }
3906 return TRUE;
3907 case REVERSED_ANIMATION:
3908 incSpeed();
3910 if (maxSpeed < -0.8)
3912 scheduleRedraw();
3913 return TRUE;
3914 case PAUSED_ANIMATION:
3916 if (maxSpeed < -0.8)
3919 incSpeed();
3920 } else {
3921 decSpeed();
3924 }
3925 scheduleRedraw();
3926 return TRUE;
3927 default:
3928 //fall through
3929 break;
3930 }
3931 break;
3932
3933 // FROM XT VIEWER
3934 // case SoKeyboardEvent::E:
3935 // this->escapeCallback(this->examinerObject);
3936 // break;
3937
3938 default:
3939 break; // To get rid of compiler warnings
3940 }
3941 }
3942 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
3943 switch (ke->getKey()) {
3944 case SoKeyboardEvent::LEFT_SHIFT:
3945 this->lshiftdown = false;
3946 return TRUE;
3947 case SoKeyboardEvent::RIGHT_SHIFT:
3948 this->rshiftdown = false;
3949 return TRUE;
3950 case SoKeyboardEvent::LEFT_CONTROL:
3951 this->lctrldown = false;
3952 return TRUE;
3953 case SoKeyboardEvent::RIGHT_CONTROL:
3954 this->rctrldown = false;
3955 return TRUE;
3956 default:
3957 break;
3958 }
3959 }
3960 }
3961
3962 // Pass the event on to the viewer
3963 // Need some checks here as in Xt viewer?
3964
3966 || currentState == ROTATING)
3967 return FALSE;
3968 else
3969 return SoQtExaminerViewer::processSoEvent(ev);
3970}
#define MAX_SPEED_INDICATOR
#define SPEED_INDICATOR_STEP
void moveCamera(float dist=0, bool lookdown=false)

◆ renameViewPt()

void G4OpenInventorQtExaminerViewer::renameViewPt ( char * vpName)
protected

Definition at line 3294 of file G4OpenInventorQtExaminerViewer.cc.

3295{
3296 std::size_t idx = 0, end, pos;
3297 std::size_t size = viewPtList.size();
3298 std::string line, newName;
3299 fileIn.open(fileName.c_str());
3300
3301 newName = vpName;
3302 while ((int) newName.size() < MAX_VP_NAME)
3303 newName += " ";
3304
3305 getline(fileIn, line);
3306 pos = fileIn.tellg();
3307 while (getline(fileIn, line)) {
3308 end = line.find_last_not_of(' ');
3309 line = line.substr(0, end + 1);
3310 if (!strcmp(line.c_str(), curViewPtName)) {
3311 fileOut.seekp(pos);
3312 fileOut << newName;
3313 fileOut.seekp(0, std::ios::end); // Set the file pointer to the end of the file
3314 break;
3315 }
3316 while (line.size())
3317 getline(fileIn, line);
3318 pos = fileIn.tellg();
3319 }
3320
3321 fileIn.close();
3322 fileIn.clear();
3323
3324 while (idx < size) {
3325 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3326 strcpy(viewPtList[idx].viewPtName, vpName);
3327 break;
3328 }
3329 idx++;
3330 }
3331}

◆ restoreCamera()

void G4OpenInventorQtExaminerViewer::restoreCamera ( )
protected

Definition at line 2314 of file G4OpenInventorQtExaminerViewer.cc.

2315{
2316 SoCamera *cam = getCamera();
2317
2318 cam->viewportMapping = camB4Animation.viewportMapping;
2319 cam->position = camB4Animation.position;
2320 cam->orientation = camB4Animation.orientation;
2321 cam->aspectRatio = camB4Animation.aspectRatio;
2322 cam->nearDistance = camB4Animation.nearDistance;
2323 cam->farDistance = camB4Animation.farDistance;
2324 cam->focalDistance = camB4Animation.focalDistance;
2325
2326 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2328 toggleCameraType();
2329 cam = getCamera();
2330 ((SoOrthographicCamera *) cam)->height.setValue(
2332 } else
2333 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2335 } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2337 toggleCameraType();
2338 cam = getCamera();
2339 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2341 } else
2342 ((SoOrthographicCamera *) cam)->height.setValue(
2344 }
2345}

Referenced by processSoEvent().

◆ rotateCamera()

void G4OpenInventorQtExaminerViewer::rotateCamera ( )
protected

Definition at line 987 of file G4OpenInventorQtExaminerViewer.cc.

988{
989 SoCamera *cam = getCamera();
990
991 SbRotation rot(rotAxis, M_PI / (2 * ROT_CNT));
992 rot.multVec(camDir, camDir);
993 rot.multVec(camUpVec, camUpVec);
994
995 SbVec3f camPosNew = prevPt - (camDir*distance);
996 cam->position = camPosNew;
997 cam->pointAt(prevPt, camUpVec);
998 cam->focalDistance = (prevPt - camPosNew).length();
999
1000 rotCnt--;
1001
1002 if (animateSensorRotation->isScheduled()) {
1003 animateSensorRotation->unschedule();
1004 }
1005
1006 animateSensorRotation->setBaseTime(SbTime::getTimeOfDay());
1007 animateSensorRotation->setInterval(SbTime(0.02));
1008 animateSensorRotation->schedule();
1009
1010}
#define M_PI
Definition SbMath.h:33

Referenced by animateSensorRotationCB(), and processSoEvent().

◆ saveCurCamera()

void G4OpenInventorQtExaminerViewer::saveCurCamera ( )
protected

Definition at line 2291 of file G4OpenInventorQtExaminerViewer.cc.

2292{
2293 SoCamera *cam = getCamera();
2294 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
2295 camB4Animation.position = cam->position.getValue();
2296 camB4Animation.orientation = cam->orientation.getValue();
2297 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
2298 camB4Animation.nearDistance = cam->nearDistance.getValue();
2299 camB4Animation.farDistance = cam->farDistance.getValue();
2300 camB4Animation.focalDistance = cam->focalDistance.getValue();
2301
2302 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2304 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
2306 } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2308 ((SoOrthographicCamera *) cam)->height.getValue();
2310 }
2311}

◆ saveViewPt()

void G4OpenInventorQtExaminerViewer::saveViewPt ( char * name)
protected

Definition at line 2842 of file G4OpenInventorQtExaminerViewer.cc.

2843{
2844 SbVec3f axis;
2845 viewPtData tmp;
2846 float x, y, z, angle;
2847 SoCamera* camera = getCamera();
2848
2849 // NOTE: Xt VSN increments this at end of procedure
2850 // viewPtIdx++;
2851
2852 // FWJ DEBUG
2853 // G4cout << "saveViewPt: saving bookmark " << viewPtIdx << " " << name
2854 // << G4endl;
2855
2856 if (viewPtList.size() == 0) {
2858 }
2859
2860 tmp.viewPtName = name;
2861 tmp.viewportMapping = camera->viewportMapping.getValue();
2862 tmp.position = camera->position.getValue();
2863 tmp.orientation = camera->orientation.getValue();
2864 tmp.aspectRatio = camera->aspectRatio.getValue();
2865 tmp.nearDistance = camera->nearDistance.getValue();
2866 tmp.farDistance = camera->farDistance.getValue();
2867 tmp.focalDistance = camera->focalDistance.getValue();
2868
2869 // Save camera height (changed by zooming)
2870 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2871 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
2872 tmp.camType = PERSPECTIVE;
2873 } else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2874 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
2875 tmp.camType = ORTHOGRAPHIC;
2876 } else {
2877 SoDebugError::post("G4OpenInventorQtExaminerViewer::saveViewPtCB",
2878 "Only Perspective and Orthographic cameras are supported.");
2879 return;
2880 }
2881
2882 viewPtList.push_back(tmp);
2883
2884 // Now save the view point to a .txt file
2885 // FWJ DEBUG
2886 // G4cout << "saveViewPt: writing to Bookmark file " << fileName << G4endl;
2887
2888 std::string vpName = name;
2889
2890 while ((int) vpName.size() <= MAX_VP_NAME)
2891 vpName += " ";
2892
2893 fileOut << vpName << std::endl;
2894 tmp.position.getValue(x, y, z);
2895 fileOut << x << " " << y << " " << z << std::endl;
2896
2897 // Reusing x, y and z for storing the axis
2898 tmp.orientation.getValue(axis, angle);
2899 axis.getValue(x, y, z);
2900 fileOut << x << " " << y << " " << z << " " << angle << std::endl;
2901
2902 fileOut << tmp.camType << " " << tmp.height << std::endl;
2903 fileOut << tmp.focalDistance << " ";
2904 fileOut << tmp.nearDistance << " ";
2905 fileOut << tmp.farDistance << std::endl;
2906 fileOut << tmp.viewportMapping << " ";
2907 fileOut << tmp.aspectRatio << "\n" << std::endl;
2908 fileOut.flush();
2909
2910 viewPtIdx++;
2911
2912 // FWJ DEBUG
2913 // G4cout << "saveViewPt: finished writing to file" << G4endl <<
2914 // " Next viewPtIdx is " << viewPtIdx << G4endl;
2915}

◆ sceneChangeCB()

void G4OpenInventorQtExaminerViewer::sceneChangeCB ( void * userData,
SoSensor *  )
staticprotected

Definition at line 2584 of file G4OpenInventorQtExaminerViewer.cc.

2585{
2586 // FWJ DEBUG
2587 // G4cout << "SCENE CHANGE callback" << G4endl;
2588 // NOTE: could/should be disabled during animation
2589
2592 if(This->newEvents) {
2593 This->findAndSetRefPath();
2594 This->newEvents = false;
2595 }
2596}

Referenced by afterRealizeHook().

◆ setExternalQtApp()

void G4OpenInventorQtExaminerViewer::setExternalQtApp ( )
inline

Definition at line 211 of file G4OpenInventorQtExaminerViewer.hh.

211{ externalQtApp = TRUE; }

Referenced by G4OpenInventorQtViewer::Initialise().

◆ setOrigWindowSize()

void G4OpenInventorQtExaminerViewer::setOrigWindowSize ( int w,
int h )
inline

Definition at line 202 of file G4OpenInventorQtExaminerViewer.hh.

202{ OWwidth = w; OWheight = h; }

Referenced by G4OpenInventorQtViewer::Initialise().

◆ setReferencePath()

void G4OpenInventorQtExaminerViewer::setReferencePath ( SoLineSet * lineset,
SoCoordinate3 * coords,
bool append = false )
protected

Definition at line 1544 of file G4OpenInventorQtExaminerViewer.cc.

1546{
1547 // TODO: Color the reference path
1548 // Disable the color stuff for now: changes all trajectories
1549 // FWJ See G4OpenInventorXtExaminerViewer.cc for test code
1550
1551 // The trajectory is composed of all the polyline segments in the
1552 // multiple value field (SoMFInt32) numVertices.
1553 // For each of the numVertices.getNum()* polyline segments,
1554 // retrieve the points from the SoCoordinate3 node
1555
1556 SbVec3f refParticlePt;
1557
1558 if(!append)
1559 refParticleTrajectory.clear();
1560
1561 for(int i = 0; i < lineset->numVertices.getNum(); ++i) {
1562 for(int j = 0; j < lineset->numVertices[i]; ++j) {
1563 refParticlePt = coords->point[j];
1564 refParticleTrajectory.push_back(refParticlePt);
1565 }
1566 }
1567 // Remove points that are too close to each other
1571 sortElements();
1572}

Referenced by findAndSetRefPath(), and pickingCB().

◆ setReferencePathZPos()

void G4OpenInventorQtExaminerViewer::setReferencePathZPos ( )
protected

Definition at line 1575 of file G4OpenInventorQtExaminerViewer.cc.

1576{
1577 refZPositions.clear();
1578 refZPositions.push_back(0);
1579 float dist;
1580 for(unsigned int i=0; i < refParticleTrajectory.size() - 1; ++i) {
1581 dist = (refParticleTrajectory[i] -
1582 refParticleTrajectory[i + 1]).length();
1583 refZPositions.push_back(refZPositions[i] + dist);
1584 }
1585}

Referenced by invertRefPath(), and setReferencePath().

◆ setStartingPtForAnimation()

void G4OpenInventorQtExaminerViewer::setStartingPtForAnimation ( )
protected

Definition at line 2422 of file G4OpenInventorQtExaminerViewer.cc.

2423{
2424 if (SoQtExaminerViewer::isAnimating())
2425 stopAnimating();
2426
2427 SbRotation rot;
2428 SbVec3f p1{0.0, 0.0, 0.0}, p2{0.0, 0.0, 0.0}, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
2429 float x1, y1, z1, x2, y2, z2;
2430
2431 if (currentState == ANIMATION) {
2434 } else if (currentState == REVERSED_ANIMATION) {
2437 } else if (currentState == PAUSED_ANIMATION) {
2438 if (refParticleIdx < (int) refParticleTrajectory.size()) {
2441 } else {
2444 }
2445 }
2446 p1.getValue(x1, y1, z1);
2447 p2.getValue(x2, y2, z2);
2448
2449 camD = p2 - p1;
2450 camD.normalize();
2451
2452 p2_tmp.setValue(x2, y1, z2);
2453 camD_tmp = p2_tmp - p1;
2454 camD_tmp.normalize();
2455
2456 camUpV.setValue(0, 1, 0);
2457 rot.setValue(camD_tmp, camD);
2458 rot.multVec(camUpV, camUpV);
2459
2460 leftRightAxis = camD.cross(camUpV);
2461
2462 myCam->position = p1;
2463 myCam->pointAt(p2, camUpV);
2464
2465 // Update camera position
2466 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
2467 myCam->position = p1;
2468 // FWJ Try look-ahead here
2469 int idx = refParticleIdx + pathLookahead;
2470 idx = std::min(idx, (int)refParticleTrajectory.size() - 1);
2471 myCam->pointAt(refParticleTrajectory[idx], camUpV);
2472 // myCam->pointAt(refParticleTrajectory[idx], camUpVec);
2473 myCam->focalDistance = 0.1f;
2474}

Referenced by animateRefParticle(), and processSoEvent().

◆ setViewPt()

void G4OpenInventorQtExaminerViewer::setViewPt ( )
protected

Definition at line 2964 of file G4OpenInventorQtExaminerViewer.cc.

2965{
2967 || currentState == ROTATING) {
2968 if (animateSensor->isScheduled()) animateSensor->unschedule();
2969 setSuperimpositionEnabled(superimposition, FALSE);
2970 maxSpeed = 0.0f;
2971 scheduleRedraw();
2972 }
2973
2974 SoCamera * camera = getCamera();
2975 if (camera == NULL) {
2976 G4warn << "setViewPt: Camera is null. Unable to set the viewpoint." <<
2977 G4endl;
2978 // String dialogName = (char *) "Missing Camera Node";
2979 // std::string msg = "Camera is null. Unable to set the viewpoint.";
2980 // warningMsgDialog(msg, dialogName, NULL);
2981 return;
2982 }
2983
2984 if (!viewPtList.size()) {
2985 G4warn << "setViewPt: There are no viewpoints to load." << G4endl;
2986 // String dialogName = (char *) "Missing Viewpoints";
2987 // std::string msg = "There are no viewpoints to load.";
2988 // warningMsgDialog(msg, dialogName, NULL);
2989 return;
2990 }
2991
2992 if (SoQtExaminerViewer::isAnimating()) stopAnimating();
2993
2994 if (currentState != VIEWPOINT) {
2996 //////////////////////////////////////////////////////////////
2997 setSuperimpositionEnabled(superimposition, TRUE);
2998 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
2999 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
3000 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3001 scheduleRedraw();
3002 ///////////////////////////////////////////////////////////////
3003 }
3004
3005 curViewPtName = viewPtList[viewPtIdx].viewPtName;
3006 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
3007 camera->position = viewPtList[viewPtIdx].position;
3008 camera->orientation = viewPtList[viewPtIdx].orientation;
3009 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
3010 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
3011 camera->farDistance = viewPtList[viewPtIdx].farDistance;
3012 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
3013
3014 // Restore camera height (changed by zooming)
3015 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3016 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
3017 toggleCameraType();
3018 camera = getCamera();
3019 ((SoOrthographicCamera *) camera)->height.setValue(
3020 viewPtList[viewPtIdx].height);
3021 } else
3022 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3023 viewPtList[viewPtIdx].height);
3024 } else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3025 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
3026 toggleCameraType();
3027 camera = getCamera();
3028 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3029 viewPtList[viewPtIdx].height);
3030 } else
3031 ((SoOrthographicCamera *) camera)->height.setValue(
3032 viewPtList[viewPtIdx].height);
3033 } else {
3034 SoDebugError::post("G4OpenInventorQtExaminerViewer::setViewPt",
3035 "Only Perspective and Orthographic cameras are supported.");
3036 return;
3037 }
3038
3039}

Referenced by deleteViewPt().

◆ sortElements()

void G4OpenInventorQtExaminerViewer::sortElements ( )
protected

Definition at line 1909 of file G4OpenInventorQtExaminerViewer.cc.

1910{
1911 if(refParticleTrajectory.empty())
1912 return;
1913
1914 float * trajLength = new float[refParticleTrajectory.size()];
1915 typedef std::map<elementForSorting, sceneElement> sortedMap;
1916 sortedMap sorted;
1917
1918 // For every point on the reference trajectory, compute
1919 // the total length from the start
1920 SbVec3f prevPoint;
1921 std::vector<SbVec3f>::iterator itRef = refParticleTrajectory.begin();
1922 int trajIndex = 0;
1923 prevPoint = *itRef;
1924 trajLength[trajIndex] = 0.0;
1925 ++itRef;
1926 ++trajIndex;
1927 for(; itRef != refParticleTrajectory.end(); ++itRef, ++trajIndex) {
1928 trajLength[trajIndex] = trajLength[trajIndex-1] + (*itRef - prevPoint).length();
1929 prevPoint = *itRef;
1930 }
1931
1932 // Compute the smallest distance between the element
1933 // and the reference trajectory (find the closest point),
1934 // then map the element to the trajectory length of that
1935 // point (calculated above)
1936 SoGetBoundingBoxAction bAction(getViewportRegion());
1937 SbVec3f elementCoord;
1938 std::vector<sceneElement>::iterator itEl;
1939 int elementIndex;
1940 elementForSorting el;
1941 for(itEl = sceneElements.begin(), elementIndex = 0;
1942 itEl != sceneElements.end(); ++itEl, ++elementIndex) {
1943 bAction.apply(itEl->path);
1944
1945 // FWJ sceneElement already has a center
1946 elementCoord = itEl->center;
1947 // ... and this sometimes returns an empty box!
1948 // elementCoord = bAction.getBoundingBox().getCenter();
1949 // if (bAction.getBoundingBox().isEmpty()) {
1950 // G4cout << "sortElements: Box is empty!" << G4endl;
1951 // G4cout << " element name=" << itEl->name << G4endl;
1952 // }
1953
1954 int index;
1955 distanceToTrajectory(elementCoord, el.smallestDistance, el.closestPoint, index);
1956 itEl->closestPointZCoord = el.closestPointZCoord = trajLength[index];
1957 el.distanceToBeamlineStart = (itEl->center - refParticleTrajectory[0]).length();
1958
1959 // This map of the scene elements (or their coordinates rather)
1960 // is automatically sorted by trajectory length (Z coord), then
1961 // by the distance between the element and the point in case the Z coord
1962 // is the same as another element. This is done by using as a key
1963 // an element structure which implements the operator for weak ordering
1964 sorted.insert(std::make_pair(el,*itEl));
1965 }
1966
1967 // store the sorted elements into the vector field
1968 sceneElements.clear();
1969
1970 sortedMap::iterator itSorted = sorted.begin();
1971 for(; itSorted != sorted.end(); itSorted++)
1972 sceneElements.push_back(itSorted->second);
1973
1974 zcoordSetFlag = true;
1975
1977
1978 delete[] trajLength;
1979}
void distanceToTrajectory(const SbVec3f &, float &, SbVec3f &, int &)

Referenced by invertRefPath(), and setReferencePath().

◆ sortViewPts()

void G4OpenInventorQtExaminerViewer::sortViewPts ( std::vector< std::string > sortedViewPts)
protected

Definition at line 3376 of file G4OpenInventorQtExaminerViewer.cc.

3377{
3378 SbVec3f axis;
3379 float x, y, z, angle;
3380 std::size_t sortIdx = 0, unsortIdx = 0;
3381
3382 if (fileOut.is_open())
3383 fileOut.close();
3384
3385 fileOut.open(fileName.c_str()); // Erase current viewpoint file
3386
3388
3389 std::size_t size = sortedViewPts.size();
3390 while (sortIdx < size) {
3391 while (strcmp(sortedViewPts[sortIdx].c_str(),
3392 viewPtList[unsortIdx].viewPtName))
3393 unsortIdx++;
3394
3395 std::string vpName = viewPtList[unsortIdx].viewPtName;
3396
3397 while ((int) vpName.size() < MAX_VP_NAME)
3398 vpName += " ";
3399 fileOut << vpName << std::endl;
3400 viewPtList[unsortIdx].position.getValue(x, y, z);
3401 fileOut << x << " " << y << " " << z << std::endl;
3402
3403 // Reusing x, y and z for storing the axis
3404 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3405 axis.getValue(x, y, z);
3406 fileOut << x << " " << y << " " << z << " " << angle << std::endl;
3407
3408 fileOut << viewPtList[unsortIdx].camType << " "
3409 << viewPtList[unsortIdx].height << std::endl;
3410 fileOut << viewPtList[unsortIdx].focalDistance << " ";
3411
3412 fileOut << viewPtList[unsortIdx].nearDistance << " ";
3413
3414 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3415
3416 fileOut << viewPtList[unsortIdx].viewportMapping << " ";
3417 fileOut << viewPtList[unsortIdx].aspectRatio << "\n" << std::endl;
3418 fileOut.flush();
3419
3420 unsortIdx = 0;
3421 sortIdx++;
3422 }
3423}

◆ sqrlen()

float G4OpenInventorQtExaminerViewer::sqrlen ( const SbVec3f & a)
protected

Definition at line 1809 of file G4OpenInventorQtExaminerViewer.cc.

1810{
1811 float x,y,z;
1812 a.getValue(x,y,z);
1813 return x*x + y*y + z*z;
1814}

Referenced by distanceToTrajectory().

◆ superimpositionCB()

void G4OpenInventorQtExaminerViewer::superimpositionCB ( void * closure,
SoAction * action )
staticprotected

Definition at line 799 of file G4OpenInventorQtExaminerViewer.cc.

801{
802 if (closure)
803 ((G4OpenInventorQtExaminerViewer*)closure)->superimpositionEvent(action);
804}

Referenced by construct().

◆ superimpositionEvent()

void G4OpenInventorQtExaminerViewer::superimpositionEvent ( SoAction * action)
protected

Definition at line 809 of file G4OpenInventorQtExaminerViewer.cc.

810{
811
812 if (!action->isOfType(SoGLRenderAction::getClassTypeId()))
813 return;
814 SbViewportRegion vpRegion =
815 ((SoGLRenderAction*)action)->getViewportRegion();
816 SbVec2s viewportSize = vpRegion.getViewportSizePixels();
817
818 // Aspect is WIDTH/HEIGHT
819 float aspect = float(viewportSize[0]) / float(viewportSize[1]);
820
821 // FWJ DEBUG
822 // G4cout << "SPEVENT X0 Y0 DX DY aspect: " << vpRegion.getViewportOrigin()[0] <<
823 // " " << vpRegion.getViewportOrigin()[1] <<
824 // " " << viewportSize[0] <<
825 // " " << viewportSize()[1] <<
826 // " " << aspect << G4endl;
827
828 // Translation and scale factor for animation speed indicator...
829
830 float factorx = 1.0f / float(viewportSize[1]) * 220.0f;
831 float factory = factorx;
832
833 if (aspect > 1.0f) {
834 stranslation->translation.setValue(SbVec3f(0.0f, -0.4f, 0.0f));
835 } else {
836 stranslation->translation.setValue(SbVec3f(0.0f, -0.4f / aspect, 0.0f));
837 factorx /= aspect;
838 factory /= aspect;
839 }
840 if (viewportSize[0] > 500)
841 factorx *= 500.0f / 400.0f;
842 else
843 factorx *= float(viewportSize[0]) / 400.0f;
844
845 sscale->scaleFactor.setValue(SbVec3f(factorx, factory, 1.0f));
846
847 // TEXT OVERLAY...
848
849 // FWJ Simplified and rewrote the following section to ease problems
850 // with the overlayed text after a viewer window resize.
851 // Result is now readable but needs further refinement of the scaling.
852
853 float xInfo, yInfo, xLogName, yLogName, xSolid, ySolid,
854 xMaterial, yMaterial, xZPos, yZPos;
855
856 // Base point for navigation distance or viewpoint name
857 // Origin is at center of render area.
858 xInfo = -.475;
859 yInfo = .475;
860 // Menu bar height in same coordinates:
861 float mbgap = 0.03;
862 if (aspect > 1.) xInfo = xInfo*aspect;
863 if (aspect < 1.) yInfo = yInfo/aspect;
864 yInfo = yInfo - mbgap*aspect;
865
866 // Following are relative to above base point
867 xLogName = 0.0;
868 yLogName = -.88 + mbgap*aspect;
869 xSolid = 0.0;
870 ySolid = -.91 + mbgap*aspect;
871 xMaterial = 0.0;
872 yMaterial = -.94 + mbgap*aspect;
873 xZPos = 0.0;
874 yZPos = -.97 + mbgap*aspect;
875
876 // Top line
877 curInfoTrans->translation.setValue(SbVec3f(xInfo, yInfo, 0.0));
878
879 // Bottom lines
880 mouseOverTransLogName->translation.setValue(SbVec3f(xLogName, yLogName, 0.0));
881 mouseOverTransSolid->translation.setValue(SbVec3f(xSolid, ySolid, 0.0));
882 mouseOverTransMaterial->translation.setValue(SbVec3f(xMaterial, yMaterial, 0.0));
883 mouseOverTransZPos->translation.setValue(SbVec3f(xZPos, yZPos, 0.0));
884
885 if (currentState == VIEWPOINT) { // Displaying viewpoint name
886 curInfoFont->size.setValue(15);
887 curInfoFont->name.setValue("defaultFont:Italic");
888 curInfoText->string.setValue(SbString(curViewPtName));
889 }
890 else if(currentState == GENERAL) { // Displaying longitudinal distance
891 curInfoFont->size.setValue(16);
892 curInfoFont->name.setValue("defaultFont:Bold");
893 curInfoText->string.setValue(SbString(""));
894 }
895 else {
896 if (refParticleIdx < (int) refParticleTrajectory.size() - 1) {
897 curInfoFont->size.setValue(16);
898 curInfoFont->name.setValue("defaultFont:Bold");
899 char zPos[20];
900 // FWJ need a better format here
901 snprintf(zPos, sizeof zPos, "%-7.2f [m]", refZPositions[refParticleIdx] / 1000);
902 curInfoText->string.setValue(SbString(zPos));
903 }
904 }
905}

◆ updateSpeedIndicator()

void G4OpenInventorQtExaminerViewer::updateSpeedIndicator ( void )
protected

Definition at line 1506 of file G4OpenInventorQtExaminerViewer.cc.

1507{
1508 assert(this->sgeometry != NULL);
1509
1510 SbVec3f * points = this->sgeometry->point.startEditing();
1511
1512 if (points[10][0] == 0.0f)
1513 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_ALL);
1514 if (points[14][0] == 0.0f)
1515 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_ALL);
1516 points[10][0] = this->maxSpeed;
1517 points[11][0] = this->maxSpeed;
1518 points[14][0] = this->maxSpeed;
1519 points[15][0] = this->maxSpeed;
1520 this->sgeometry->point.finishEditing();
1521
1522 if (this->maxSpeed == 0.0f) {
1523 this->animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
1524 this->animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
1525 }
1526}

Referenced by actualRedraw().

◆ updateViewParams()

void G4OpenInventorQtExaminerViewer::updateViewParams ( SoKeyboardEvent::Key )
protected

◆ viewPtAutoName()

std::string G4OpenInventorQtExaminerViewer::viewPtAutoName ( )
protected

◆ writeViewPtIdx()

void G4OpenInventorQtExaminerViewer::writeViewPtIdx ( )
protected

Definition at line 2920 of file G4OpenInventorQtExaminerViewer.cc.

2921{
2922 std::string idxStr;
2923 std::stringstream out;
2924
2925 out << viewPtIdx;
2926 idxStr = out.str();
2927 fileOut.seekp(0, std::ios::beg);
2928
2929 while ((int) idxStr.length() < MAX_VP_IDX) {
2930 idxStr += " ";
2931 }
2932
2933 // FWJ DEBUG
2934 // G4cout << "writeViewPtIdx: " << viewPtIdx << G4endl;
2935 fileOut << idxStr << "\n";
2936 fileOut.flush();
2937 fileOut.seekp(0, std::ios::end);
2938}

Referenced by deleteViewPt(), saveViewPt(), and sortViewPts().

◆ zoom()

void G4OpenInventorQtExaminerViewer::zoom ( const float diffvalue)
protected

Definition at line 3430 of file G4OpenInventorQtExaminerViewer.cc.

3431{
3432 float multiplicator = float(std::exp(diffvalue));
3433 SoCamera *cam = getCamera();
3434
3435 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3436 const float oldfocaldist = cam->focalDistance.getValue();
3437 const float newfocaldist = oldfocaldist * multiplicator;
3438
3439 SbVec3f direction;
3440 cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
3441
3442 const SbVec3f oldpos = cam->position.getValue();
3443 const SbVec3f newpos = oldpos + (newfocaldist - oldfocaldist) * -direction;
3444 cam->position = newpos;
3445 cam->focalDistance = newfocaldist;
3446 } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
3447 SoOrthographicCamera * oc = (SoOrthographicCamera *)cam;
3448 oc->height = oc->height.getValue() * multiplicator;
3449 }
3450}

Referenced by processSoEvent().

Friends And Related Symbol Documentation

◆ G4OpenInventorQtViewer

friend class G4OpenInventorQtViewer
friend

Definition at line 94 of file G4OpenInventorQtExaminerViewer.hh.

◆ HookEventProcState

friend class HookEventProcState
friend

Definition at line 240 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

Member Data Documentation

◆ abbrOutputFlag

bool G4OpenInventorQtExaminerViewer::abbrOutputFlag

Definition at line 219 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), mouseoverCB(), and pickingCB().

◆ animateBtwPtsPeriod

double G4OpenInventorQtExaminerViewer::animateBtwPtsPeriod
protected

◆ animateSensor

SoTimerSensor* G4OpenInventorQtExaminerViewer::animateSensor
protected

◆ animateSensorRotation

SoTimerSensor* G4OpenInventorQtExaminerViewer::animateSensorRotation
protected

◆ animSpeedOutlineSwitch

SoSwitch* G4OpenInventorQtExaminerViewer::animSpeedOutlineSwitch
protected

◆ animSpeedSwitch

SoSwitch* G4OpenInventorQtExaminerViewer::animSpeedSwitch
protected

◆ axisSwitch

SoSwitch* G4OpenInventorQtExaminerViewer::axisSwitch
protected

Definition at line 437 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), processSoEvent(), and setViewPt().

◆ beforePausing

State G4OpenInventorQtExaminerViewer::beforePausing
protected

Definition at line 387 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by processSoEvent().

◆ camB4Animation

viewPtData G4OpenInventorQtExaminerViewer::camB4Animation
protected

Definition at line 395 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by restoreCamera(), and saveCurCamera().

◆ camDir

SbVec3f G4OpenInventorQtExaminerViewer::camDir
protected

Definition at line 261 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera(), processSoEvent(), and rotateCamera().

◆ camEndOrient

SbRotation G4OpenInventorQtExaminerViewer::camEndOrient
protected

Definition at line 284 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camEndPos

SbVec3f G4OpenInventorQtExaminerViewer::camEndPos
protected

Definition at line 283 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camStartOrient

SbRotation G4OpenInventorQtExaminerViewer::camStartOrient
protected

Definition at line 284 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camStartPos

SbVec3f G4OpenInventorQtExaminerViewer::camStartPos
protected

Definition at line 283 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camUpVec

SbVec3f G4OpenInventorQtExaminerViewer::camUpVec
protected

Definition at line 260 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera(), processSoEvent(), and rotateCamera().

◆ center

SbVec3f G4OpenInventorQtExaminerViewer::center
protected

Definition at line 462 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ curEltName

std::string G4OpenInventorQtExaminerViewer::curEltName
protected

Definition at line 259 of file G4OpenInventorQtExaminerViewer.hh.

◆ curInfoFont

SoFont* G4OpenInventorQtExaminerViewer::curInfoFont
protected

Definition at line 432 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ curInfoSwitch

SoSwitch* G4OpenInventorQtExaminerViewer::curInfoSwitch
protected

Definition at line 440 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ curInfoText

SoText2* G4OpenInventorQtExaminerViewer::curInfoText
protected

Definition at line 423 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ curInfoTrans

SoTranslation* G4OpenInventorQtExaminerViewer::curInfoTrans
protected

Definition at line 415 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ currentState

◆ curViewPtName

char* G4OpenInventorQtExaminerViewer::curViewPtName
protected

◆ defaultHeight

float G4OpenInventorQtExaminerViewer::defaultHeight
protected

Definition at line 456 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by afterRealizeHook().

◆ defaultHeightAngle

float G4OpenInventorQtExaminerViewer::defaultHeightAngle
protected

Definition at line 457 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by afterRealizeHook().

◆ distance

float G4OpenInventorQtExaminerViewer::distance
protected

Definition at line 386 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera(), and rotateCamera().

◆ fileIn

std::ifstream G4OpenInventorQtExaminerViewer::fileIn
protected

◆ fileName

std::string G4OpenInventorQtExaminerViewer::fileName
protected

◆ fileOut

std::ofstream G4OpenInventorQtExaminerViewer::fileOut
protected

◆ hookBeamOn

HookEventProcState* G4OpenInventorQtExaminerViewer::hookBeamOn
protected

Definition at line 239 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ left_right

float G4OpenInventorQtExaminerViewer::left_right
protected

◆ MAX_VP_IDX

int G4OpenInventorQtExaminerViewer::MAX_VP_IDX
protected

Definition at line 376 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and writeViewPtIdx().

◆ MAX_VP_NAME

int G4OpenInventorQtExaminerViewer::MAX_VP_NAME
protected

◆ maxSpeed

float G4OpenInventorQtExaminerViewer::maxSpeed
protected

◆ mouseOverFontLogName

SoFont* G4OpenInventorQtExaminerViewer::mouseOverFontLogName
protected

Definition at line 435 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverFontMaterial

SoFont* G4OpenInventorQtExaminerViewer::mouseOverFontMaterial
protected

Definition at line 434 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverFontSolid

SoFont* G4OpenInventorQtExaminerViewer::mouseOverFontSolid
protected

Definition at line 433 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverFontZPos

SoFont* G4OpenInventorQtExaminerViewer::mouseOverFontZPos
protected

Definition at line 436 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverTextLogName

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextLogName
protected

Definition at line 429 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTextMaterial

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextMaterial
protected

Definition at line 428 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTextSolid

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextSolid
protected

Definition at line 427 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTextZPos

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextZPos
protected

Definition at line 430 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTransLogName

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransLogName
protected

Definition at line 418 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ mouseOverTransMaterial

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransMaterial
protected

Definition at line 417 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ mouseOverTransSolid

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransSolid
protected

Definition at line 416 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ mouseOverTransZPos

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransZPos
protected

Definition at line 419 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ myCam

SoCamera* G4OpenInventorQtExaminerViewer::myCam
protected

◆ newEvents

bool G4OpenInventorQtExaminerViewer::newEvents
protected

◆ newSceneGraph

SoSeparator* G4OpenInventorQtExaminerViewer::newSceneGraph
protected

Definition at line 465 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ offsetFromCenter

SbVec3f G4OpenInventorQtExaminerViewer::offsetFromCenter
protected

Definition at line 462 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ pathLookahead

G4int G4OpenInventorQtExaminerViewer::pathLookahead
protected

Definition at line 459 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and setStartingPtForAnimation().

◆ pickRefPathFlag

bool G4OpenInventorQtExaminerViewer::pickRefPathFlag

Definition at line 220 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and pickingCB().

◆ prevColorField

void* G4OpenInventorQtExaminerViewer::prevColorField
protected

Definition at line 393 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ prevParticleDir

SbVec3f G4OpenInventorQtExaminerViewer::prevParticleDir
protected

Definition at line 392 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ prevPt

SbVec3f G4OpenInventorQtExaminerViewer::prevPt
protected

Definition at line 391 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera(), and rotateCamera().

◆ prevRefIdx

int G4OpenInventorQtExaminerViewer::prevRefIdx
protected

Definition at line 385 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by processSoEvent().

◆ prevState

State G4OpenInventorQtExaminerViewer::prevState
protected

Definition at line 387 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateSensorRotationCB(), and processSoEvent().

◆ refParticleIdx

int G4OpenInventorQtExaminerViewer::refParticleIdx
protected

◆ refParticleTrajectory

◆ refZPositions

std::vector<float> G4OpenInventorQtExaminerViewer::refZPositions
protected

◆ returnToAnim

bool G4OpenInventorQtExaminerViewer::returnToAnim
protected

Definition at line 397 of file G4OpenInventorQtExaminerViewer.hh.

◆ returnToSaveVP

bool G4OpenInventorQtExaminerViewer::returnToSaveVP
protected

Definition at line 396 of file G4OpenInventorQtExaminerViewer.hh.

◆ rotAxis

SbVec3f G4OpenInventorQtExaminerViewer::rotAxis
protected

Definition at line 401 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by processSoEvent(), and rotateCamera().

◆ rotCnt

int G4OpenInventorQtExaminerViewer::rotCnt
protected

◆ rotUpVec

bool G4OpenInventorQtExaminerViewer::rotUpVec
protected

Definition at line 463 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ saveRefCoordsFileName

std::string G4OpenInventorQtExaminerViewer::saveRefCoordsFileName

Definition at line 215 of file G4OpenInventorQtExaminerViewer.hh.

◆ saveScenegraphFileName

std::string G4OpenInventorQtExaminerViewer::saveScenegraphFileName

Definition at line 214 of file G4OpenInventorQtExaminerViewer.hh.

◆ sceneChangeSensor

SoNodeSensor* G4OpenInventorQtExaminerViewer::sceneChangeSensor
protected

Definition at line 282 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by afterRealizeHook().

◆ sceneElements

std::vector<sceneElement> G4OpenInventorQtExaminerViewer::sceneElements
protected

◆ searcher

SoSearchAction* G4OpenInventorQtExaminerViewer::searcher
protected

Definition at line 408 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and getSuperimpositionNode().

◆ sgeometry

SoCoordinate3* G4OpenInventorQtExaminerViewer::sgeometry
protected

Definition at line 411 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and updateSpeedIndicator().

◆ speedStep

double G4OpenInventorQtExaminerViewer::speedStep
protected

Definition at line 276 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateSensorCB(), construct(), decSpeed(), and incSpeed().

◆ sscale

SoScale* G4OpenInventorQtExaminerViewer::sscale
protected

Definition at line 412 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ step

int G4OpenInventorQtExaminerViewer::step
protected

Definition at line 390 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), moveCamera(), and processSoEvent().

◆ stranslation

SoTranslation* G4OpenInventorQtExaminerViewer::stranslation
protected

Definition at line 414 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ superimposition

SoNode* G4OpenInventorQtExaminerViewer::superimposition
protected

◆ up_down

float G4OpenInventorQtExaminerViewer::up_down
protected

◆ upVector

SbVec3f G4OpenInventorQtExaminerViewer::upVector
protected

Definition at line 462 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ viewingBeforePickRef

bool G4OpenInventorQtExaminerViewer::viewingBeforePickRef

Definition at line 221 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by pickingCB().

◆ viewPtIdx

int G4OpenInventorQtExaminerViewer::viewPtIdx
protected

◆ viewPtList

std::vector<viewPtData> G4OpenInventorQtExaminerViewer::viewPtList
protected

◆ zcoordSetFlag

bool G4OpenInventorQtExaminerViewer::zcoordSetFlag
protected

Definition at line 368 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), createElementsList(), and sortElements().


The documentation for this class was generated from the following files: