Geant4 11.1.1
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 ()
 
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 2593 of file G4OpenInventorQtExaminerViewer.cc.

2594{
2595 escapeCallback = callback;
2596}

◆ addViewPoints()

void G4OpenInventorQtExaminerViewer::addViewPoints ( )
protected

Definition at line 2618 of file G4OpenInventorQtExaminerViewer.cc.

2619{
2620 std::size_t size = viewPtList.size();
2621 if (!size) return;
2622
2623 for (std::size_t i = 0; i < size; ++i) {
2624 new QListWidgetItem(viewPtList[i].viewPtName,
2625 AuxWindowDialog->listWidget);
2626 }
2627}
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:1860
QTabWidget * GetViewerTabWidget()
Definition: G4UIQt.hh:167
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77

◆ animateRefParticle()

void G4OpenInventorQtExaminerViewer::animateRefParticle ( )
protected

Definition at line 2570 of file G4OpenInventorQtExaminerViewer.cc.

2571{
2572 SoCamera *cam = getCamera();
2573
2574 camStartPos = cam->position.getValue();
2575 camStartOrient = cam->orientation.getValue();
2576
2577 if (currentState != BEAMLINE)
2579
2580 camEndPos = myCam->position.getValue();
2581 camEndOrient = myCam->orientation.getValue();
2582
2583 if (animateSensor->isScheduled())
2584 animateSensor->unschedule();
2585
2586 animateSensor->setBaseTime(SbTime::getTimeOfDay());
2587 animateSensor->setInterval(SbTime(0.02));
2588
2589 animateSensor->schedule();
2590}

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

◆ animateRefParticleCB()

static void G4OpenInventorQtExaminerViewer::animateRefParticleCB ( )
staticprotected

◆ animateSensorCB()

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

Definition at line 2396 of file G4OpenInventorQtExaminerViewer.cc.

2398{
2399 SbTime curTime = SbTime::getTimeOfDay();
2401 SoCamera *cam = This->getCamera();
2402 SoTimerSensor* s = (SoTimerSensor*) sensor;
2403
2404 float t = float((curTime - s->getBaseTime()).getValue())
2405 / This->animateBtwPtsPeriod;
2406
2407 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2408 t = 1.0f;
2409 SbBool end = (t == 1.0f);
2410
2411 cam->orientation = SbRotation::slerp(This->camStartOrient, This->camEndOrient, t);
2412 cam->position = This->camStartPos + (This->camEndPos - This->camStartPos) * t;
2413
2414 if (end) {
2415 This->animateSensor->unschedule();
2416
2417 if (This->currentState == ANIMATION) {
2418 if (This->refParticleIdx < (int) (This->refParticleTrajectory.size() - 1))
2419 This->animateRefParticle();
2420 else {
2422 This->speedStep = START_STEP;
2423 }
2424 }
2425 if (This->currentState == REVERSED_ANIMATION) {
2426 if (This->refParticleIdx >= 1)
2427 This->animateRefParticle();
2428 else {
2430 This->speedStep = START_STEP;
2431 }
2432 }
2433 }
2434}

Referenced by construct().

◆ animateSensorRotationCB()

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

Definition at line 2363 of file G4OpenInventorQtExaminerViewer.cc.

2365{
2366 SbTime curTime = SbTime::getTimeOfDay();
2368
2369 SoTimerSensor* s = (SoTimerSensor*) sensor;
2370
2371 float t = float((curTime - s->getBaseTime()).getValue())
2372 / This->animateBtwPtsPeriod;
2373
2374 if ((t > 1.0f) || (t + s->getInterval().getValue() > 1.0f))
2375 t = 1.0f;
2376 SbBool end = (t == 1.0f);
2377
2378 if (end) {
2379 This->animateSensorRotation->unschedule();
2380 if(This->rotCnt) {
2381 // rotations left
2382 This->rotateCamera();
2383 }
2384 else {
2385 // rotation over
2386 This->currentState = This->prevState;
2387 return;
2388 }
2389 }
2390
2391}

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 2701 of file G4OpenInventorQtExaminerViewer.cc.

2702{
2703 viewPtIdx = -1;
2704 viewPtList.clear();
2705 // setSuperimpositionEnabled(superimposition, FALSE);
2706 // scheduleRedraw();
2708 if (fileOut.is_open()) fileOut.close();
2709
2710 AuxWindowDialog->listWidget->clear();
2711 AuxWindowDialog->lineEdit->setText(QString(""));
2712}
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 1979 of file G4OpenInventorQtExaminerViewer.cc.

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

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 3199 of file G4OpenInventorQtExaminerViewer.cc.

3200{
3201 std::string line;
3202 std::size_t end;
3203 fileIn.open(fileName.c_str());
3204 std::ofstream out("temporaryFile.txt");
3205
3206 if (!vpName)
3207 vpName = viewPtList[viewPtIdx].viewPtName;
3208
3209 getline(fileIn, line); // Printing the viewpoint idx
3210 out << line << "\n";
3211
3212 while (getline(fileIn, line)) {
3213 end = line.find_last_not_of(' ');
3214 line = line.substr(0, end + 1);
3215 if (!strcmp(line.c_str(), vpName)) { // Equal
3216 while (line.size()) {
3217 getline(fileIn, line);
3218 }
3219
3220 while (getline(fileIn, line))
3221 out << line << "\n";
3222 } else {
3223 while (line.size()) {
3224 out << line << "\n";
3225 getline(fileIn, line);
3226 }
3227 out << "\n";
3228 }
3229 }
3230
3231 std::size_t idx = 0; // Remove viewpoint from the vector
3232 std::size_t size = viewPtList.size();
3233 while (idx < size) {
3234 if (!strcmp(viewPtList[idx].viewPtName, vpName)) {
3235 viewPtList.erase(viewPtList.begin() + idx);
3236 break;
3237 }
3238 idx++;
3239 }
3240
3241 out.close();
3242 fileOut.close();
3243 fileIn.clear();
3244 fileIn.close();
3245
3246 // FWJ check return status: error popups needed here
3247 int istat = remove(fileName.c_str());
3248 if (istat == -1) {
3249 QMessageBox msgbox;
3250 msgbox.setFont(*font);
3251 QString messagetxt = "Error removing bookmarks file";
3252 // messagetxt.append(filenamein);
3253 msgbox.setText(messagetxt);
3254 msgbox.exec();
3255 // G4cout << "Error removing bookmarks file" << G4endl;
3256 }
3257 istat = rename("temporaryFile.txt", fileName.c_str());
3258 if (istat == -1) {
3259 QMessageBox msgbox;
3260 msgbox.setFont(*font);
3261 QString messagetxt = "Error renaming bookmarks file";
3262 // messagetxt.append(filenamein);
3263 msgbox.setText(messagetxt);
3264 msgbox.exec();
3265 // G4cout << "Error renaming bookmarks file" << G4endl;
3266 }
3267 fileOut.open(fileName.c_str(), std::ios::in);
3268 fileOut.seekp(0, std::ios::end);
3269
3270 if (!viewPtList.size()) { // viewPtList is empty
3271 curViewPtName = (char *) empty.c_str();
3272 scheduleRedraw();
3273 } else {
3274 if (viewPtIdx >= (int) viewPtList.size())
3275 viewPtIdx--;
3277 setViewPt();
3278 }
3279}

◆ distanceToTrajectory()

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

Definition at line 1814 of file G4OpenInventorQtExaminerViewer.cc.

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

Referenced by sortElements().

◆ evenOutRefParticlePts()

void G4OpenInventorQtExaminerViewer::evenOutRefParticlePts ( )
protected

Definition at line 2250 of file G4OpenInventorQtExaminerViewer.cc.

2251{
2252 if(refParticleTrajectory.empty())
2253 return;
2254
2255 SbVec3f p1, p2, p3, dirNow, dirNxt, dir, p2_tmp, p_start, p_corner, p_nxt;
2256 float avgDistBtwPts = 0;
2257 float totalDistBtwPts = 0;
2258 std::vector<SbVec3f> newRefParticleTrajectory;
2259 SbVec3f refPoint;
2260 std::size_t size = refParticleTrajectory.size() - 1;
2261 int numOfPts = 0;
2262 for (std::size_t i = 0; i < size; ++i) {
2263 p1 = refParticleTrajectory[i];
2264 p2 = refParticleTrajectory[i + 1];
2265 if (p1 == p2)
2266 continue;
2267 numOfPts++;
2268 totalDistBtwPts += (p2 - p1).length();
2269 }
2270 // Nothing useful to do (and fix Coverity)
2271 if (numOfPts <= 2) return;
2272
2273 avgDistBtwPts = totalDistBtwPts / numOfPts;
2274 float minDistAllowed = 0.75 * avgDistBtwPts;
2275 // float maxDistAllowed = 1.25 * avgDistBtwPts; // Pts tend to be close not far
2276
2277 float x, y, z;
2278 std::size_t i = 0, j = 0;
2279 while (i < size) {
2280 p1 = refParticleTrajectory[i];
2281 p2 = refParticleTrajectory[i + 1];
2282
2283 refPoint = p1;
2284 p1.getValue(x, y, z);
2285
2286 newRefParticleTrajectory.push_back(refPoint);
2287
2288 j = i;
2289 while ((p2 - p1).length() < minDistAllowed && j < (size - 1)) {
2290 j++;
2291
2292 p1 = refParticleTrajectory[j];
2293 p2 = refParticleTrajectory[j + 1];
2294 }
2295 if (j != i)
2296 i = j + 1;
2297 else
2298 i++;
2299 }
2300
2301 refParticleTrajectory.clear();
2302 refParticleTrajectory = newRefParticleTrajectory;
2303}

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

Referenced by sceneChangeCB().

◆ getCoordsNode()

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

Definition at line 1711 of file G4OpenInventorQtExaminerViewer.cc.

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

Referenced by findAndSetRefPath().

◆ getEtcMenu()

QMenu * G4OpenInventorQtExaminerViewer::getEtcMenu ( )
inline

Definition at line 206 of file G4OpenInventorQtExaminerViewer.hh.

206{ return etcmenu; }

Referenced by G4OpenInventorQtViewer::Initialise().

◆ getFileMenu()

QMenu * G4OpenInventorQtExaminerViewer::getFileMenu ( )
inline

Definition at line 205 of file G4OpenInventorQtExaminerViewer.hh.

205{ return filemenu; }

Referenced by G4OpenInventorQtViewer::Initialise().

◆ getFont()

QFont * G4OpenInventorQtExaminerViewer::getFont ( )
inline

Definition at line 207 of file G4OpenInventorQtExaminerViewer.hh.

207{ return font; };

Referenced by G4OpenInventorQtViewer::Initialise().

◆ getMenubar()

QMenuBar * G4OpenInventorQtExaminerViewer::getMenubar ( )
inline

Definition at line 204 of file G4OpenInventorQtExaminerViewer.hh.

204{ return menubar; }

◆ getSceneElements()

void G4OpenInventorQtExaminerViewer::getSceneElements ( )
protected

Definition at line 1735 of file G4OpenInventorQtExaminerViewer.cc.

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

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().

◆ gotoRefPathStart()

void G4OpenInventorQtExaminerViewer::gotoRefPathStart ( )
protected

Definition at line 2492 of file G4OpenInventorQtExaminerViewer.cc.

2493{
2494 G4OpenInventorQtExaminerViewer::ToolsRefPathStartCB();
2495}

◆ 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;
1481 if (refParticleIdx < lastIdx && !animateSensor->isScheduled())
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, y, z, angle;
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;
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}

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; // 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 2633 of file G4OpenInventorQtExaminerViewer.cc.

2635{
2636 std::istringstream str(s);
2637 if ((str >> t).fail())
2638 error = true;
2639}

◆ 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:57
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 3497 of file G4OpenInventorQtExaminerViewer.cc.

3498{
3499
3500 // FWJ DEBUG
3501 // G4cout << "processSoEvent ############" << ++processSoEventCount << G4endl;
3502
3503 SoCamera *cam = getCamera();
3504 const SoType type(ev->getTypeId());
3505
3506// Needed to implement mouse wheel zoom direction change.
3507// Does not work with MacOS trackpad: use Coin3d default handler.
3508#ifndef __APPLE__
3509 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId())) {
3510 SoMouseButtonEvent * me = (SoMouseButtonEvent *) ev;
3511
3512 // if (currentState == ANIMATION || currentState == REVERSED_ANIMATION
3513 // || currentState == PAUSED_ANIMATION) {
3514
3515 switch (me->getButton()) {
3516
3517 case SoMouseButtonEvent::BUTTON4: // Scroll wheel up
3518 if (me->getState() == SoButtonEvent::DOWN) {
3519 // G4cout << "SCROLL WHEEL UP" << G4endl;
3520 zoom(-0.1f);
3521 return TRUE;
3522 }
3523 break;
3524
3525 case SoMouseButtonEvent::BUTTON5: // Scroll wheel down
3526 if (me->getState() == SoButtonEvent::DOWN) {
3527 // G4cout << "SCROLL WHEEL DOWN" << G4endl;
3528 zoom(0.1f);
3529 return TRUE;
3530 }
3531 break;
3532
3533 default:
3534 break;
3535 }
3536 // }
3537 if (currentState == GENERAL) {
3538
3539 }
3540 }
3541#endif
3542
3543 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId())) {
3544 SoKeyboardEvent* ke = (SoKeyboardEvent*)ev;
3545
3546 if (SoKeyboardEvent::isKeyPressEvent(ev, ke->getKey())) {
3547 switch (ke->getKey()) {
3548 case SoKeyboardEvent::E:
3549 if (externalQtApp) {
3550 // G4cout << "E KEY PRESSED" << G4endl;
3551 return TRUE;
3552 } else {
3553 G4cout <<
3554 "E KEY PRESSED, EXITING OIQT VIEWER SECONDARY LOOP" <<
3555 G4endl;
3556 SoQt::exitMainLoop();
3557 // escapeCallback();
3558 return TRUE;
3559 }
3560 case SoKeyboardEvent::LEFT_SHIFT:
3561 this->lshiftdown = true;
3562 return TRUE;
3563 case SoKeyboardEvent::RIGHT_SHIFT:
3564 this->rshiftdown = true;
3565 return TRUE;
3566 case SoKeyboardEvent::LEFT_CONTROL:
3567 this->lctrldown = true;
3568 return TRUE;
3569 case SoKeyboardEvent::RIGHT_CONTROL:
3570 this->rctrldown = true;
3571 return TRUE;
3572 case SoKeyboardEvent::SPACE:
3573 if (currentState == ANIMATION
3577 if (animateSensor->isScheduled())
3578 animateSensor->unschedule();
3579 return TRUE;
3580 } else if (currentState == PAUSED_ANIMATION) {
3581 if (maxSpeed) {
3582 if ((beforePausing == ANIMATION
3584 < (int) refParticleTrajectory.size() - 1)
3586 && refParticleIdx > 0)) {
3589 }
3590 }
3591 return TRUE;
3592 }
3593 break;
3594 case SoKeyboardEvent::ESCAPE:
3595 if (currentState == ANIMATION
3598
3599 if (animateSensor->isScheduled())
3600 animateSensor->unschedule();
3603 setSuperimpositionEnabled(superimposition, FALSE);
3604 maxSpeed = 0.0f;
3605 step = 1;
3606
3607 scheduleRedraw();
3608 if (currentState == VIEWPOINT) {
3609 setSuperimpositionEnabled(superimposition, TRUE);
3610 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3611 animSpeedOutlineSwitch->whichChild.setValue(
3612 SO_SWITCH_NONE);
3613 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3614
3615 scheduleRedraw();
3616 }
3617 restoreCamera();
3618 return TRUE;
3619 }
3620 break;
3621 case SoKeyboardEvent::DELETE:
3622 if (viewPtList.size()
3623 && (currentState != ANIMATION
3626 // FWJ IMPLEMENT LATER
3627 // String dialogName = (char *) "Delete Viewpoint";
3628 // std::string msg = "Are you sure you want to delete current viewpoint?";
3629 // warningMsgDialog(msg, dialogName, deleteViewPtCB);
3630 return TRUE;
3631 }
3632 break;
3633 case SoKeyboardEvent::LEFT_ARROW:
3634 switch (currentState) {
3635 case BEAMLINE:
3636 if ((this->lshiftdown) || (this->rshiftdown)) {
3638 moveCamera();
3639 }
3640 else if ((this->lctrldown) || (this->rctrldown)) {
3641 if (SoQtExaminerViewer::isAnimating())
3642 stopAnimating();
3645 animateBtwPtsPeriod = 0.08f;
3646
3647 SbVec3f tmp = camDir;
3648 tmp.negate();
3649 rotAxis = tmp;
3650
3651 rotCnt = ROT_CNT;
3652 moveCamera(); // To make sure camera is perpendicular to the beamline
3653 rotateCamera();
3654 }
3655 else {
3656 if (SoQtExaminerViewer::isAnimating())
3657 stopAnimating();
3660 animateBtwPtsPeriod = 0.08f;
3661
3662 SbVec3f tmp = camUpVec;
3663 tmp.negate();
3664 rotAxis = tmp;
3665
3666 rotCnt = ROT_CNT;
3667 moveCamera(); // To make sure camera is perpendicular to the beamline
3668 rotateCamera();
3669
3670 }
3671 return TRUE;
3672
3673 case ANIMATION:
3674 case REVERSED_ANIMATION:
3675 left_right -= 1.5f;
3676 return TRUE;
3677 case PAUSED_ANIMATION:
3678 left_right -= 1.5f;
3680 cam->position = myCam->position;
3681 return TRUE;
3682 case GENERAL:
3683 case VIEWPOINT:
3684 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3685 // Using this allows us to look around without
3686 // changing the camera parameters (camDir, camUpVec)
3687 this->bottomWheelMotion(
3688 this->getBottomWheelValue() + 0.1f);
3689
3690 return TRUE;
3691 }
3692 break;
3693 case ROTATING:
3694 // For this state, let the keyboard event
3695 // be handled by superclass
3696 break;
3697 default:
3698 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3699 "Unhandled viewer state");
3700 break;
3701 }
3702 break;
3703
3704 case SoKeyboardEvent::RIGHT_ARROW:
3705 switch(currentState) {
3706 case BEAMLINE:
3707 if ((this->lshiftdown) || (this->rshiftdown)) {
3709 moveCamera();
3710 }
3711 else if ((this->lctrldown) || (this->rctrldown)) {
3712 if (SoQtExaminerViewer::isAnimating())
3713 stopAnimating();
3716 animateBtwPtsPeriod = 0.08f;
3717
3718 rotAxis = camDir;
3719
3720 rotCnt = ROT_CNT;
3721 moveCamera(); // To make sure camera is perpendicular to the beamline
3722 rotateCamera();
3723 }
3724 else{
3725 if (SoQtExaminerViewer::isAnimating())
3726 stopAnimating();
3729 animateBtwPtsPeriod = 0.08f;
3730
3731 rotAxis = camUpVec;
3732
3733 rotCnt = ROT_CNT;
3734 moveCamera(); // To make sure camera is perpendicular to the beamline
3735 rotateCamera();
3736 }
3737 return TRUE;
3738
3739 case ANIMATION:
3740 case REVERSED_ANIMATION:
3741 left_right += 1.5f;
3742 return TRUE;
3743 case PAUSED_ANIMATION:
3744 left_right += 1.5f;
3746 cam->position = myCam->position;
3747 return TRUE;
3748 case GENERAL:
3749 case VIEWPOINT:
3750 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3751 // Using this allows us to look around without
3752 // changing the camera parameters (camDir, camUpVec)
3753 this->bottomWheelMotion(
3754 this->getBottomWheelValue() - 0.1f);
3755 return TRUE;
3756 }
3757 break;
3758 case ROTATING:
3759 // For this state, let the keyboard event
3760 // be handled by superclass
3761 break;
3762 default:
3763 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3764 "Unhandled viewer state");
3765 break;
3766 }
3767 break;
3768
3769 case SoKeyboardEvent::DOWN_ARROW:
3770 switch(currentState) {
3771 case BEAMLINE:
3772
3773 if ((this->lshiftdown) || (this->rshiftdown)) {
3775 moveCamera();
3776 }
3777 else{
3778 if (SoQtExaminerViewer::isAnimating())
3779 stopAnimating();
3782 animateBtwPtsPeriod = 0.08f;
3783
3784 rotAxis = camDir.cross(camUpVec);
3785
3786 rotCnt = ROT_CNT;
3787 moveCamera(); // To make sure camera is perpendicular to the beamline
3788 rotateCamera();
3789
3790 }
3791 return TRUE;
3792
3793 case ANIMATION:
3794 case REVERSED_ANIMATION:
3795 up_down -= 1.5f;
3796 return TRUE;
3797 case PAUSED_ANIMATION:
3798 up_down -= 1.5f;
3800 cam->position = myCam->position;
3801 return TRUE;
3802 case GENERAL:
3803 case VIEWPOINT:
3804 // Using this allows us to look around without
3805 // changing the camera parameters (camDir, camUpVec)
3806 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3807 this->leftWheelMotion(this->getLeftWheelValue() - 0.1f);
3808 return TRUE;
3809 }
3810 break;
3811 case ROTATING:
3812 // For this state, let the keyboard event
3813 // be handled by superclass
3814 break;
3815 default:
3816 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3817 "Unhandled viewer state");
3818 break;
3819 }
3820 break;
3821
3822 case SoKeyboardEvent::UP_ARROW:
3823 switch(currentState) {
3824 case BEAMLINE:
3825 if ((this->lshiftdown) || (this->rshiftdown)) {
3827 moveCamera();
3828 }
3829 else{
3830 if (SoQtExaminerViewer::isAnimating())
3831 stopAnimating();
3834 animateBtwPtsPeriod = 0.08f;
3835
3836 rotAxis = camUpVec.cross(camDir);
3837
3838 rotCnt = ROT_CNT;
3839 moveCamera();
3840
3841 rotateCamera();
3842
3843
3844 }
3845 return TRUE;
3846 case ANIMATION:
3847 case REVERSED_ANIMATION:
3848 up_down += 1.5f;
3849 return TRUE;
3850 case PAUSED_ANIMATION:
3851 up_down += 1.5f;
3853 cam->position = myCam->position;
3854 return TRUE;
3855 case GENERAL:
3856 case VIEWPOINT:
3857 // Using this allows us to look around without
3858 // changing the camera parameters (camDir, camUpVec)
3859 if ((!this->lshiftdown) && (!this->rshiftdown)) {
3860 this->leftWheelMotion(this->getLeftWheelValue() + 0.1f);
3861 return TRUE;
3862 }
3863 break;
3864 case ROTATING:
3865 // For this state, let the keyboard event
3866 // be handled by superclass
3867 break;
3868 default:
3869 SoDebugError::post("G4OpenInventorQtExaminerViewer::processSoEvent",
3870 "Unhandled viewer state");
3871 break;
3872 }
3873 break;
3874
3875 case SoKeyboardEvent::PAGE_UP:
3876 switch(currentState) {
3877 case BEAMLINE:
3878 if (step < (int) refParticleTrajectory.size() / 5) // Magic number
3879 step++;
3880 return TRUE;
3881 case ANIMATION:
3882 incSpeed();
3884 if (maxSpeed > 0.8)
3886 scheduleRedraw();
3887
3888 return TRUE;
3889 case REVERSED_ANIMATION:
3890 if(!animateSensor->isScheduled()) {
3892 if (refParticleIdx
3893 < (int) refParticleTrajectory.size() - 1) {
3896 scheduleRedraw();
3898 }
3899 }
3900 else{
3902 decSpeed();
3903 scheduleRedraw();
3904 }
3905 return TRUE;
3906 case PAUSED_ANIMATION:
3908 if (maxSpeed > 0.8)
3910
3911 if (beforePausing == ANIMATION) {
3912 incSpeed();
3913 } else {
3914 decSpeed();
3917 }
3918
3919 scheduleRedraw();
3920 return TRUE;
3921 default: //fall through
3922 break;
3923 }
3924 break;
3925
3926 case SoKeyboardEvent::PAGE_DOWN:
3927 switch(currentState) {
3928 case BEAMLINE:
3929 if (step > 1)
3930 step--;
3931 return TRUE;
3932 case ANIMATION:
3933 if(!animateSensor->isScheduled()) {
3935 if (refParticleIdx > 1) {
3938 scheduleRedraw();
3940 }
3941 }
3942 else{
3944 decSpeed();
3945 scheduleRedraw();
3946 }
3947 return TRUE;
3948 case REVERSED_ANIMATION:
3949 incSpeed();
3951 if (maxSpeed < -0.8)
3953 scheduleRedraw();
3954 return TRUE;
3955 case PAUSED_ANIMATION:
3957 if (maxSpeed < -0.8)
3960 incSpeed();
3961 } else {
3962 decSpeed();
3965 }
3966 scheduleRedraw();
3967 return TRUE;
3968 default:
3969 //fall through
3970 break;
3971 }
3972 break;
3973
3974 // FROM XT VIEWER
3975 // case SoKeyboardEvent::E:
3976 // this->escapeCallback(this->examinerObject);
3977 // break;
3978
3979 default:
3980 break; // To get rid of compiler warnings
3981 }
3982 }
3983 if (SoKeyboardEvent::isKeyReleaseEvent(ev, ke->getKey())) {
3984 switch (ke->getKey()) {
3985 case SoKeyboardEvent::LEFT_SHIFT:
3986 this->lshiftdown = false;
3987 return TRUE;
3988 case SoKeyboardEvent::RIGHT_SHIFT:
3989 this->rshiftdown = false;
3990 return TRUE;
3991 case SoKeyboardEvent::LEFT_CONTROL:
3992 this->lctrldown = false;
3993 return TRUE;
3994 case SoKeyboardEvent::RIGHT_CONTROL:
3995 this->rctrldown = false;
3996 return TRUE;
3997 default:
3998 break;
3999 }
4000 }
4001 }
4002
4003 // Pass the event on to the viewer
4004 // Need some checks here as in Xt viewer?
4005
4007 || currentState == ROTATING)
4008 return FALSE;
4009 else
4010 return SoQtExaminerViewer::processSoEvent(ev);
4011}
#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 3335 of file G4OpenInventorQtExaminerViewer.cc.

3336{
3337 std::size_t idx = 0, end, pos;
3338 std::size_t size = viewPtList.size();
3339 std::string line, newName;
3340 fileIn.open(fileName.c_str());
3341
3342 newName = vpName;
3343 while ((int) newName.size() < MAX_VP_NAME)
3344 newName += " ";
3345
3346 getline(fileIn, line);
3347 pos = fileIn.tellg();
3348 while (getline(fileIn, line)) {
3349 end = line.find_last_not_of(' ');
3350 line = line.substr(0, end + 1);
3351 if (!strcmp(line.c_str(), curViewPtName)) {
3352 fileOut.seekp(pos);
3353 fileOut << newName;
3354 fileOut.seekp(0, std::ios::end); // Set the file pointer to the end of the file
3355 break;
3356 }
3357 while (line.size())
3358 getline(fileIn, line);
3359 pos = fileIn.tellg();
3360 }
3361
3362 fileIn.close();
3363 fileIn.clear();
3364
3365 while (idx < size) {
3366 if (!strcmp(viewPtList[idx].viewPtName, curViewPtName)) {
3367 strcpy(viewPtList[idx].viewPtName, vpName);
3368 break;
3369 }
3370 idx++;
3371 }
3372}

◆ restoreCamera()

void G4OpenInventorQtExaminerViewer::restoreCamera ( )
protected

Definition at line 2329 of file G4OpenInventorQtExaminerViewer.cc.

2330{
2331 SoCamera *cam = getCamera();
2332
2333 cam->viewportMapping = camB4Animation.viewportMapping;
2334 cam->position = camB4Animation.position;
2335 cam->orientation = camB4Animation.orientation;
2336 cam->aspectRatio = camB4Animation.aspectRatio;
2337 cam->nearDistance = camB4Animation.nearDistance;
2338 cam->farDistance = camB4Animation.farDistance;
2339 cam->focalDistance = camB4Animation.focalDistance;
2340
2341 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2343 toggleCameraType();
2344 cam = getCamera();
2345 ((SoOrthographicCamera *) cam)->height.setValue(
2347 } else
2348 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2350 } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2352 toggleCameraType();
2353 cam = getCamera();
2354 ((SoPerspectiveCamera *) cam)->heightAngle.setValue(
2356 } else
2357 ((SoOrthographicCamera *) cam)->height.setValue(
2359 }
2360}

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 2306 of file G4OpenInventorQtExaminerViewer.cc.

2307{
2308 SoCamera *cam = getCamera();
2309 camB4Animation.viewportMapping = cam->viewportMapping.getValue();
2310 camB4Animation.position = cam->position.getValue();
2311 camB4Animation.orientation = cam->orientation.getValue();
2312 camB4Animation.aspectRatio = cam->aspectRatio.getValue();
2313 camB4Animation.nearDistance = cam->nearDistance.getValue();
2314 camB4Animation.farDistance = cam->farDistance.getValue();
2315 camB4Animation.focalDistance = cam->focalDistance.getValue();
2316
2317 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2319 ((SoPerspectiveCamera *) cam)->heightAngle.getValue();
2321 } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
2323 ((SoOrthographicCamera *) cam)->height.getValue();
2325 }
2326}

◆ saveViewPt()

void G4OpenInventorQtExaminerViewer::saveViewPt ( char *  name)
protected

Definition at line 2870 of file G4OpenInventorQtExaminerViewer.cc.

2871{
2872 SbVec3f axis;
2873 viewPtData tmp;
2874 float x, y, z, angle;
2875 SoCamera* camera = getCamera();
2876
2877 // NOTE: Xt VSN increments this at end of procedure
2878 // viewPtIdx++;
2879
2880 // FWJ DEBUG
2881 // G4cout << "saveViewPt: saving bookmark " << viewPtIdx << " " << name
2882 // << G4endl;
2883
2884 if (viewPtList.size() == 0) {
2886 }
2887
2888 tmp.viewPtName = name;
2889 tmp.viewportMapping = camera->viewportMapping.getValue();
2890 tmp.position = camera->position.getValue();
2891 tmp.orientation = camera->orientation.getValue();
2892 tmp.aspectRatio = camera->aspectRatio.getValue();
2893 tmp.nearDistance = camera->nearDistance.getValue();
2894 tmp.farDistance = camera->farDistance.getValue();
2895 tmp.focalDistance = camera->focalDistance.getValue();
2896
2897 // Save camera height (changed by zooming)
2898 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
2899 tmp.height = ((SoPerspectiveCamera *) camera)->heightAngle.getValue();
2900 tmp.camType = PERSPECTIVE;
2901 } else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
2902 tmp.height = ((SoOrthographicCamera *) camera)->height.getValue();
2903 tmp.camType = ORTHOGRAPHIC;
2904 } else {
2905 SoDebugError::post("G4OpenInventorQtExaminerViewer::saveViewPtCB",
2906 "Only Perspective and Orthographic cameras are supported.");
2907 return;
2908 }
2909
2910 viewPtList.push_back(tmp);
2911
2912 // Now save the view point to a .txt file
2913 // FWJ DEBUG
2914 // G4cout << "saveViewPt: writing to Bookmark file " << fileName << G4endl;
2915
2916 std::string vpName = name;
2917
2918 while ((int) vpName.size() <= MAX_VP_NAME)
2919 vpName += " ";
2920
2921 fileOut << vpName << std::endl;
2922 tmp.position.getValue(x, y, z);
2923 fileOut << x << " " << y << " " << z << std::endl;
2924
2925 // Reusing x, y and z for storing the axis
2926 tmp.orientation.getValue(axis, angle);
2927 axis.getValue(x, y, z);
2928 fileOut << x << " " << y << " " << z << " " << angle << std::endl;
2929
2930 fileOut << tmp.camType << " " << tmp.height << std::endl;
2931 fileOut << tmp.focalDistance << " ";
2932 fileOut << tmp.nearDistance << " ";
2933 fileOut << tmp.farDistance << std::endl;
2934 fileOut << tmp.viewportMapping << " ";
2935 fileOut << tmp.aspectRatio << "\n" << std::endl;
2936 fileOut.flush();
2937
2938 viewPtIdx++;
2939
2940 // FWJ DEBUG
2941 // G4cout << "saveViewPt: finished writing to file" << G4endl <<
2942 // " Next viewPtIdx is " << viewPtIdx << G4endl;
2943}

◆ sceneChangeCB()

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

Definition at line 2599 of file G4OpenInventorQtExaminerViewer.cc.

2600{
2601 // FWJ DEBUG
2602 // G4cout << "SCENE CHANGE callback" << G4endl;
2603 // NOTE: could/should be disabled during animation
2604
2607 if(This->newEvents) {
2608 This->findAndSetRefPath();
2609 This->newEvents = false;
2610 }
2611}

Referenced by afterRealizeHook().

◆ setExternalQtApp()

void G4OpenInventorQtExaminerViewer::setExternalQtApp ( )
inline

Definition at line 209 of file G4OpenInventorQtExaminerViewer.hh.

209{ externalQtApp = TRUE; }

Referenced by G4OpenInventorQtViewer::Initialise().

◆ setOrigWindowSize()

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

Definition at line 200 of file G4OpenInventorQtExaminerViewer.hh.

200{ 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 2437 of file G4OpenInventorQtExaminerViewer.cc.

2438{
2439 if (SoQtExaminerViewer::isAnimating())
2440 stopAnimating();
2441
2442 SbRotation rot;
2443 SbVec3f p1, p2, p2_tmp, camUpV, camD, camD_tmp, leftRightAxis;
2444 float x1, y1, z1, x2, y2, z2;
2445
2446 if (currentState == ANIMATION) {
2449 } else if (currentState == REVERSED_ANIMATION) {
2452 } else if (currentState == PAUSED_ANIMATION) {
2453 if (refParticleIdx < (int) refParticleTrajectory.size()) {
2456 } else {
2459 }
2460 }
2461 p1.getValue(x1, y1, z1);
2462 p2.getValue(x2, y2, z2);
2463
2464 camD = p2 - p1;
2465 camD.normalize();
2466
2467 p2_tmp.setValue(x2, y1, z2);
2468 camD_tmp = p2_tmp - p1;
2469 camD_tmp.normalize();
2470
2471 camUpV.setValue(0, 1, 0);
2472 rot.setValue(camD_tmp, camD);
2473 rot.multVec(camUpV, camUpV);
2474
2475 leftRightAxis = camD.cross(camUpV);
2476
2477 myCam->position = p1;
2478 myCam->pointAt(p2, camUpV);
2479
2480 // Update camera position
2481 p1 = p1 + (up_down * camUpV) + (left_right * leftRightAxis);
2482 myCam->position = p1;
2483 // FWJ Try look-ahead here
2484 int idx = refParticleIdx + pathLookahead;
2485 idx = std::min(idx, (int)refParticleTrajectory.size() - 1);
2486 myCam->pointAt(refParticleTrajectory[idx], camUpV);
2487 // myCam->pointAt(refParticleTrajectory[idx], camUpVec);
2488 myCam->focalDistance = 0.1f;
2489}

Referenced by animateRefParticle(), and processSoEvent().

◆ setViewPt()

void G4OpenInventorQtExaminerViewer::setViewPt ( )
protected

Definition at line 2998 of file G4OpenInventorQtExaminerViewer.cc.

2999{
3001 || currentState == ROTATING) {
3002 if (animateSensor->isScheduled()) animateSensor->unschedule();
3003 setSuperimpositionEnabled(superimposition, FALSE);
3004 maxSpeed = 0.0f;
3005 scheduleRedraw();
3006 }
3007
3008 SoCamera * camera = getCamera();
3009 if (camera == NULL) {
3010 G4warn << "setViewPt: Camera is null. Unable to set the viewpoint." <<
3011 G4endl;
3012 // String dialogName = (char *) "Missing Camera Node";
3013 // std::string msg = "Camera is null. Unable to set the viewpoint.";
3014 // warningMsgDialog(msg, dialogName, NULL);
3015 return;
3016 }
3017
3018 if (!viewPtList.size()) {
3019 G4warn << "setViewPt: There are no viewpoints to load." << G4endl;
3020 // String dialogName = (char *) "Missing Viewpoints";
3021 // std::string msg = "There are no viewpoints to load.";
3022 // warningMsgDialog(msg, dialogName, NULL);
3023 return;
3024 }
3025
3026 if (SoQtExaminerViewer::isAnimating()) stopAnimating();
3027
3028 if (currentState != VIEWPOINT) {
3030 //////////////////////////////////////////////////////////////
3031 setSuperimpositionEnabled(superimposition, TRUE);
3032 axisSwitch->whichChild.setValue(SO_SWITCH_NONE);
3033 animSpeedOutlineSwitch->whichChild.setValue(SO_SWITCH_NONE);
3034 animSpeedSwitch->whichChild.setValue(SO_SWITCH_NONE);
3035 scheduleRedraw();
3036 ///////////////////////////////////////////////////////////////
3037 }
3038
3039 curViewPtName = viewPtList[viewPtIdx].viewPtName;
3040 camera->viewportMapping = viewPtList[viewPtIdx].viewportMapping;
3041 camera->position = viewPtList[viewPtIdx].position;
3042 camera->orientation = viewPtList[viewPtIdx].orientation;
3043 camera->aspectRatio = viewPtList[viewPtIdx].aspectRatio;
3044 camera->nearDistance = viewPtList[viewPtIdx].nearDistance;
3045 camera->farDistance = viewPtList[viewPtIdx].farDistance;
3046 camera->focalDistance = viewPtList[viewPtIdx].focalDistance;
3047
3048 // Restore camera height (changed by zooming)
3049 if (camera->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3050 if (viewPtList[viewPtIdx].camType == ORTHOGRAPHIC) {
3051 toggleCameraType();
3052 camera = getCamera();
3053 ((SoOrthographicCamera *) camera)->height.setValue(
3054 viewPtList[viewPtIdx].height);
3055 } else
3056 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3057 viewPtList[viewPtIdx].height);
3058 } else if (camera->isOfType(SoOrthographicCamera::getClassTypeId())) {
3059 if (viewPtList[viewPtIdx].camType == PERSPECTIVE) {
3060 toggleCameraType();
3061 camera = getCamera();
3062 ((SoPerspectiveCamera *) camera)->heightAngle.setValue(
3063 viewPtList[viewPtIdx].height);
3064 } else
3065 ((SoOrthographicCamera *) camera)->height.setValue(
3066 viewPtList[viewPtIdx].height);
3067 } else {
3068 SoDebugError::post("G4OpenInventorQtExaminerViewer::setViewPt",
3069 "Only Perspective and Orthographic cameras are supported.");
3070 return;
3071 }
3072
3073}

Referenced by deleteViewPt().

◆ sortElements()

void G4OpenInventorQtExaminerViewer::sortElements ( )
protected

Definition at line 1906 of file G4OpenInventorQtExaminerViewer.cc.

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

3418{
3419 SbVec3f axis;
3420 float x, y, z, angle;
3421 std::size_t sortIdx = 0, unsortIdx = 0;
3422
3423 if (fileOut.is_open())
3424 fileOut.close();
3425
3426 fileOut.open(fileName.c_str()); // Erase current viewpoint file
3427
3429
3430 std::size_t size = sortedViewPts.size();
3431 while (sortIdx < size) {
3432 while (strcmp(sortedViewPts[sortIdx].c_str(),
3433 viewPtList[unsortIdx].viewPtName))
3434 unsortIdx++;
3435
3436 std::string vpName = viewPtList[unsortIdx].viewPtName;
3437
3438 while ((int) vpName.size() < MAX_VP_NAME)
3439 vpName += " ";
3440 fileOut << vpName << std::endl;
3441 viewPtList[unsortIdx].position.getValue(x, y, z);
3442 fileOut << x << " " << y << " " << z << std::endl;
3443
3444 // Reusing x, y and z for storing the axis
3445 viewPtList[unsortIdx].orientation.getValue(axis, angle);
3446 axis.getValue(x, y, z);
3447 fileOut << x << " " << y << " " << z << " " << angle << std::endl;
3448
3449 fileOut << viewPtList[unsortIdx].camType << " "
3450 << viewPtList[unsortIdx].height << std::endl;
3451 fileOut << viewPtList[unsortIdx].focalDistance << " ";
3452
3453 fileOut << viewPtList[unsortIdx].nearDistance << " ";
3454
3455 fileOut << viewPtList[unsortIdx].farDistance << std::endl;
3456
3457 fileOut << viewPtList[unsortIdx].viewportMapping << " ";
3458 fileOut << viewPtList[unsortIdx].aspectRatio << "\n" << std::endl;
3459 fileOut.flush();
3460
3461 unsortIdx = 0;
3462 sortIdx++;
3463 }
3464}

◆ sqrlen()

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

Definition at line 1806 of file G4OpenInventorQtExaminerViewer.cc.

1807{
1808 float x,y,z;
1809 a.getValue(x,y,z);
1810 return x*x + y*y + z*z;
1811}

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 2948 of file G4OpenInventorQtExaminerViewer.cc.

2949{
2950 std::string idxStr;
2951 std::stringstream out;
2952
2953 out << viewPtIdx;
2954 idxStr = out.str();
2955 fileOut.seekp(0, std::ios::beg);
2956
2957 while ((int) idxStr.length() < MAX_VP_IDX) {
2958 idxStr += " ";
2959 }
2960
2961 // FWJ DEBUG
2962 // G4cout << "writeViewPtIdx: " << viewPtIdx << G4endl;
2963 fileOut << idxStr << "\n";
2964 fileOut.flush();
2965 fileOut.seekp(0, std::ios::end);
2966}

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

◆ zoom()

void G4OpenInventorQtExaminerViewer::zoom ( const float  diffvalue)
protected

Definition at line 3471 of file G4OpenInventorQtExaminerViewer.cc.

3472{
3473 float multiplicator = float(std::exp(diffvalue));
3474 SoCamera *cam = getCamera();
3475
3476 if (cam->isOfType(SoPerspectiveCamera::getClassTypeId())) {
3477 const float oldfocaldist = cam->focalDistance.getValue();
3478 const float newfocaldist = oldfocaldist * multiplicator;
3479
3480 SbVec3f direction;
3481 cam->orientation.getValue().multVec(SbVec3f(0, 0, -1), direction);
3482
3483 const SbVec3f oldpos = cam->position.getValue();
3484 const SbVec3f newpos = oldpos + (newfocaldist - oldfocaldist) * -direction;
3485 cam->position = newpos;
3486 cam->focalDistance = newfocaldist;
3487 } else if (cam->isOfType(SoOrthographicCamera::getClassTypeId())) {
3488 SoOrthographicCamera * oc = (SoOrthographicCamera *)cam;
3489 oc->height = oc->height.getValue() * multiplicator;
3490 }
3491}

Referenced by processSoEvent().

Friends And Related Function Documentation

◆ G4OpenInventorQtViewer

friend class G4OpenInventorQtViewer
friend

Definition at line 94 of file G4OpenInventorQtExaminerViewer.hh.

◆ HookEventProcState

friend class HookEventProcState
friend

Definition at line 238 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

Member Data Documentation

◆ abbrOutputFlag

bool G4OpenInventorQtExaminerViewer::abbrOutputFlag

Definition at line 217 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 435 of file G4OpenInventorQtExaminerViewer.hh.

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

◆ beforePausing

State G4OpenInventorQtExaminerViewer::beforePausing
protected

Definition at line 385 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by processSoEvent().

◆ camB4Animation

viewPtData G4OpenInventorQtExaminerViewer::camB4Animation
protected

Definition at line 393 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by restoreCamera(), and saveCurCamera().

◆ camDir

SbVec3f G4OpenInventorQtExaminerViewer::camDir
protected

Definition at line 259 of file G4OpenInventorQtExaminerViewer.hh.

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

◆ camEndOrient

SbRotation G4OpenInventorQtExaminerViewer::camEndOrient
protected

Definition at line 282 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camEndPos

SbVec3f G4OpenInventorQtExaminerViewer::camEndPos
protected

Definition at line 281 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camStartOrient

SbRotation G4OpenInventorQtExaminerViewer::camStartOrient
protected

Definition at line 282 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camStartPos

SbVec3f G4OpenInventorQtExaminerViewer::camStartPos
protected

Definition at line 281 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by animateRefParticle(), and animateSensorCB().

◆ camUpVec

SbVec3f G4OpenInventorQtExaminerViewer::camUpVec
protected

Definition at line 258 of file G4OpenInventorQtExaminerViewer.hh.

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

◆ center

SbVec3f G4OpenInventorQtExaminerViewer::center
protected

Definition at line 460 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ curEltName

std::string G4OpenInventorQtExaminerViewer::curEltName
protected

Definition at line 257 of file G4OpenInventorQtExaminerViewer.hh.

◆ curInfoFont

SoFont* G4OpenInventorQtExaminerViewer::curInfoFont
protected

Definition at line 430 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ curInfoSwitch

SoSwitch* G4OpenInventorQtExaminerViewer::curInfoSwitch
protected

Definition at line 438 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ curInfoText

SoText2* G4OpenInventorQtExaminerViewer::curInfoText
protected

Definition at line 421 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ curInfoTrans

SoTranslation* G4OpenInventorQtExaminerViewer::curInfoTrans
protected

Definition at line 413 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ currentState

◆ curViewPtName

char* G4OpenInventorQtExaminerViewer::curViewPtName
protected

◆ defaultHeight

float G4OpenInventorQtExaminerViewer::defaultHeight
protected

Definition at line 454 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by afterRealizeHook().

◆ defaultHeightAngle

float G4OpenInventorQtExaminerViewer::defaultHeightAngle
protected

Definition at line 455 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by afterRealizeHook().

◆ distance

float G4OpenInventorQtExaminerViewer::distance
protected

Definition at line 384 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 237 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 374 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 433 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverFontMaterial

SoFont* G4OpenInventorQtExaminerViewer::mouseOverFontMaterial
protected

Definition at line 432 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverFontSolid

SoFont* G4OpenInventorQtExaminerViewer::mouseOverFontSolid
protected

Definition at line 431 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverFontZPos

SoFont* G4OpenInventorQtExaminerViewer::mouseOverFontZPos
protected

Definition at line 434 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ mouseOverTextLogName

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextLogName
protected

Definition at line 427 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTextMaterial

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextMaterial
protected

Definition at line 426 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTextSolid

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextSolid
protected

Definition at line 425 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTextZPos

SoText2* G4OpenInventorQtExaminerViewer::mouseOverTextZPos
protected

Definition at line 428 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and mouseoverCB().

◆ mouseOverTransLogName

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransLogName
protected

Definition at line 416 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ mouseOverTransMaterial

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransMaterial
protected

Definition at line 415 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ mouseOverTransSolid

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransSolid
protected

Definition at line 414 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ mouseOverTransZPos

SoTranslation* G4OpenInventorQtExaminerViewer::mouseOverTransZPos
protected

Definition at line 417 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 463 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ offsetFromCenter

SbVec3f G4OpenInventorQtExaminerViewer::offsetFromCenter
protected

Definition at line 460 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ pathLookahead

G4int G4OpenInventorQtExaminerViewer::pathLookahead
protected

Definition at line 457 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and setStartingPtForAnimation().

◆ pickRefPathFlag

bool G4OpenInventorQtExaminerViewer::pickRefPathFlag

Definition at line 218 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and pickingCB().

◆ prevColorField

void* G4OpenInventorQtExaminerViewer::prevColorField
protected

Definition at line 391 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ prevParticleDir

SbVec3f G4OpenInventorQtExaminerViewer::prevParticleDir
protected

Definition at line 390 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ prevPt

SbVec3f G4OpenInventorQtExaminerViewer::prevPt
protected

Definition at line 389 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera(), and rotateCamera().

◆ prevRefIdx

int G4OpenInventorQtExaminerViewer::prevRefIdx
protected

Definition at line 383 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by processSoEvent().

◆ prevState

State G4OpenInventorQtExaminerViewer::prevState
protected

Definition at line 385 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 395 of file G4OpenInventorQtExaminerViewer.hh.

◆ returnToSaveVP

bool G4OpenInventorQtExaminerViewer::returnToSaveVP
protected

Definition at line 394 of file G4OpenInventorQtExaminerViewer.hh.

◆ rotAxis

SbVec3f G4OpenInventorQtExaminerViewer::rotAxis
protected

Definition at line 399 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by processSoEvent(), and rotateCamera().

◆ rotCnt

int G4OpenInventorQtExaminerViewer::rotCnt
protected

◆ rotUpVec

bool G4OpenInventorQtExaminerViewer::rotUpVec
protected

Definition at line 461 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct().

◆ saveRefCoordsFileName

std::string G4OpenInventorQtExaminerViewer::saveRefCoordsFileName

Definition at line 213 of file G4OpenInventorQtExaminerViewer.hh.

◆ saveScenegraphFileName

std::string G4OpenInventorQtExaminerViewer::saveScenegraphFileName

Definition at line 212 of file G4OpenInventorQtExaminerViewer.hh.

◆ sceneChangeSensor

SoNodeSensor* G4OpenInventorQtExaminerViewer::sceneChangeSensor
protected

Definition at line 280 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by afterRealizeHook().

◆ sceneElements

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

◆ searcher

SoSearchAction* G4OpenInventorQtExaminerViewer::searcher
protected

Definition at line 406 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and getSuperimpositionNode().

◆ sgeometry

SoCoordinate3* G4OpenInventorQtExaminerViewer::sgeometry
protected

Definition at line 409 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and updateSpeedIndicator().

◆ speedStep

double G4OpenInventorQtExaminerViewer::speedStep
protected

Definition at line 274 of file G4OpenInventorQtExaminerViewer.hh.

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

◆ sscale

SoScale* G4OpenInventorQtExaminerViewer::sscale
protected

Definition at line 410 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by construct(), and superimpositionEvent().

◆ step

int G4OpenInventorQtExaminerViewer::step
protected

Definition at line 388 of file G4OpenInventorQtExaminerViewer.hh.

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

◆ stranslation

SoTranslation* G4OpenInventorQtExaminerViewer::stranslation
protected

Definition at line 412 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 460 of file G4OpenInventorQtExaminerViewer.hh.

Referenced by moveCamera().

◆ viewingBeforePickRef

bool G4OpenInventorQtExaminerViewer::viewingBeforePickRef

Definition at line 219 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 366 of file G4OpenInventorQtExaminerViewer.hh.

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


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