Skip to content

Commit

Permalink
Change default egs_view time window
Browse files Browse the repository at this point in the history
Change the time window default to 1% of the simulation duration for
tracks visualization. Also add a new input in egs_view for the number of
time steps to take in the animation. This allows for better control of
the visual speed of the motion.
  • Loading branch information
rtownson committed Jun 21, 2024
1 parent 68a835e commit cfea556
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 15 deletions.
42 changes: 30 additions & 12 deletions HEN_HOUSE/egs++/view/viewcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)

// set the widget to show near the left-upper corner of the screen
move(QPoint(25,25));

//set the play button active boolean to false
isPlaying=false;
}
Expand Down Expand Up @@ -1911,8 +1912,6 @@ void GeometryViewControl::loadTracksDialog() {
timeObjectVisibility();

gview->loadTracks(filename_tracks);


}

void GeometryViewControl::updateTracks(vector<size_t> ntracks, vector<EGS_Float> timeindexlist_p, vector<EGS_Float> timeindexlist_e, vector<EGS_Float> timeindexlist_po) {
Expand Down Expand Up @@ -1948,7 +1947,11 @@ void GeometryViewControl::updateTracks(vector<size_t> ntracks, vector<EGS_Float>
spin_tmine->setValue(1);
spin_tminpo->setValue(1);

updateView();
// Update the time window value
// This includes an updateView() call
slideTime();

// updateView();
}

void GeometryViewControl::viewAllMaterials() {
Expand Down Expand Up @@ -2751,23 +2754,24 @@ void GeometryViewControl::endTransformation() {
//A.D Time index visual elements methods//
void GeometryViewControl::playTime() {
if (isPlaying) {
button_timeplay->setText("play");
button_timeplay->setText("Play");
isPlaying=false;
}
else {
button_timeplay->setText("pause");
button_timeplay->setText("Pause");
isPlaying=true;
}
int sliderpos=slider_timeindex->sliderPosition();
if (sliderpos==999) {

if (sliderpos==spin_numTimeSteps->value()-1) {
sliderpos=0;
}
//this function controls the play button, and allows for the simulation to be automatically played out sequentially in time.
for (int i= sliderpos; i<1000;) { //the simulation plays through 1000 discrete time points (equivalent to possible slider steps) from 0.000 to 0.999 in 0.0001 increments
for (int i= sliderpos; i<spin_numTimeSteps->value();) { //the simulation plays through 1000 discrete time points (equivalent to possible slider steps) from 0.000 to 0.999 in 0.0001 increments
if (!isPlaying) {
break;
}
EGS_Float currtime = i/(float)1000;
EGS_Float currtime = i/(float)spin_numTimeSteps->value();
//below the time index display/input box is updated. The signals are blocked as it would lead to an infinite loop between the slider and the time index spin box
spin_timeindex->blockSignals(true);
spin_timeindex->setValue(currtime);
Expand All @@ -2780,7 +2784,7 @@ void GeometryViewControl::playTime() {
//the line below makes the program wait 10 milliseconds before making the next step, otherwise the motion would be difficult to follow
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
button_timeplay->setText("play");
button_timeplay->setText("Play");
isPlaying=false;
}

Expand All @@ -2789,14 +2793,16 @@ void GeometryViewControl::resetTime() {
* need only reset the slider and time window values to their original state. These will automatically call the particleslider() and slidetime() methods respectively due to
* 'valuechanged' signal emissions. All other elements (time index spinbox and the particle bounds) are returned to their initial states through these */
slider_timeindex->setValue(0);
spin_timewindow->setValue(2);

// Default the time window to 1% of the simulation time
spin_timewindow->setValue(0.01);
}

void GeometryViewControl::spinTime() {
//this function controls the time index spinbox, which is used both as a way to display the current index, and to input and go to a particular index
//first, get the new time index, and from it calculate the equivalent position on the slider (multiply by 1000 to get integer between 0 and 999)
EGS_Float slidertime=spin_timeindex->value();
int sliderpos=(int)(slidertime*1000);
int sliderpos=(int)(slidertime*spin_numTimeSteps->value());
//below the time index slider is updated. The signals are blocked as it would lead to an infinite loop between the slider and the time index spin box
slider_timeindex->blockSignals(true);
slider_timeindex->setValue(sliderpos);
Expand All @@ -2815,7 +2821,7 @@ void GeometryViewControl::slideTime() {
//first the slider position is grabbed. The slider ranges from 0 to 999 as it cannot have decimal increments
int sliderpos=slider_timeindex->sliderPosition();
//the time index corresponding to the position integer is determined by dividing the position by 1000
EGS_Float slidertime = sliderpos/(float)1000;
EGS_Float slidertime = sliderpos/(float)spin_numTimeSteps->value();
//below the time index spinbox is updated. The signals are blocked as it would lead to an infinite loop between the slider and the time index spin box
spin_timeindex->blockSignals(true);
spin_timeindex->setValue(slidertime);
Expand All @@ -2827,6 +2833,13 @@ void GeometryViewControl::slideTime() {
updateView();
}

void GeometryViewControl::updateNumTimeSteps() {
int newMaximum = spin_numTimeSteps->value()-1;
slider_timeindex->blockSignals(true);
slider_timeindex->setMaximum(newMaximum);
slider_timeindex->blockSignals(false);
spinTime();
}

void GeometryViewControl::particleSlider(EGS_Float slidertime) {
/* this function is called by the time index slider, the time window box, and the time index box, as the final step in updating the display. It is responsible for determining which
Expand All @@ -2838,6 +2851,7 @@ void GeometryViewControl::particleSlider(EGS_Float slidertime) {
if (tracks_extension=="syncptracks") {
//the size of the time window is obtained
EGS_Float t_window = spin_timewindow->value();

//a boolean variable hasstart is defined as initially set to false. This will track whether a starting index has been assigned
bool hasstart=false;
//start and end index integers defined
Expand Down Expand Up @@ -3214,6 +3228,8 @@ void GeometryViewControl::timeObjectVisibility() {
spin_timeindex->hide();
label_timeindex->hide();
groupBox_time->hide();
spin_numTimeSteps->hide();
label_numTimeSteps->hide();
spin_tmaxe->setReadOnly(false);
spin_tmine->setReadOnly(false);
spin_tmaxpo->setReadOnly(false);
Expand All @@ -3238,6 +3254,8 @@ void GeometryViewControl::timeObjectVisibility() {
spin_timeindex->show();
label_timeindex->show();
groupBox_time->show();
spin_numTimeSteps->show();
label_numTimeSteps->show();
}
//has dynamic is true when a dynamic geometry is present, or when the tracks are being given some time index (exmaple due to a dynamic source or phasespace file) and include time = yes in input file (syncptracks file)

Expand Down
1 change: 1 addition & 0 deletions HEN_HOUSE/egs++/view/viewcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public slots:
virtual void resetTime();
virtual void slideTime();
virtual void spinTime();
virtual void updateNumTimeSteps();
virtual void particleSlider(EGS_Float slidertime);
virtual void updateTracks(vector<size_t> ntracks, vector<EGS_Float> timeindexlist_p, vector<EGS_Float> timeindexlist_e, vector<EGS_Float> timeindexlist_po);

Expand Down
57 changes: 54 additions & 3 deletions HEN_HOUSE/egs++/view/viewcontrol.ui
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
<double>0.001000000000000</double>
</property>
<property name="value">
<double>2.000000000000000</double>
<double>0.010000000000000</double>
</property>
</widget>
</item>
Expand All @@ -349,7 +349,7 @@
</size>
</property>
<property name="text">
<string>reset</string>
<string>Reset</string>
</property>
</widget>
</item>
Expand All @@ -370,7 +370,7 @@
<property name="minimumSize">
<size>
<width>0</width>
<height>90</height>
<height>114</height>
</size>
</property>
<property name="title">
Expand Down Expand Up @@ -464,6 +464,41 @@
<string>Time index</string>
</property>
</widget>
<widget class="QSpinBox" name="spin_numTimeSteps">
<property name="geometry">
<rect>
<x>180</x>
<y>80</y>
<width>61</width>
<height>29</height>
</rect>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1000000</number>
</property>
<property name="singleStep">
<number>1000</number>
</property>
<property name="value">
<number>1000</number>
</property>
</widget>
<widget class="QLabel" name="label_numTimeSteps">
<property name="geometry">
<rect>
<x>10</x>
<y>85</y>
<width>151</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Number of time steps</string>
</property>
</widget>
</widget>
</item>
<item>
Expand Down Expand Up @@ -2906,6 +2941,22 @@ p, li { white-space: pre-wrap; }
<y>327</y>
</hint>
</hints>
</connection>
<connection>
<sender>spin_numTimeSteps</sender>
<signal>valueChanged(int)</signal>
<receiver>GeometryViewControl</receiver>
<slot>updateNumTimeSteps()</slot>
<hints>
<hint type="sourcelabel">
<x>594</x>
<y>334</y>
</hint>
<hint type="destinationlabel">
<x>358</x>
<y>327</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit cfea556

Please sign in to comment.