MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); play_or_pause_ = true; selected_item_ = NULL; SceneContainer::viewer_reference_ = ui->viewer; this->setWindowTitle(QString("Animation Studio")); connect( ui->button_play, SIGNAL(clicked()), ui->viewer, SLOT(play()) ); connect( ui->button_stop, SIGNAL(clicked()), ui->viewer, SLOT(stop())); connect( ui->button_stop, SIGNAL(clicked()), this, SLOT(stop())); connect(ui->button_play,SIGNAL(clicked()),this,SLOT(playPause())); connect(ui->viewer,SIGNAL(signalUpdateObjects()),this,SLOT(updateObjects())); connect( ui->timebar, SIGNAL(setSelectedFrame(int)), ui->viewer, SLOT(setCurrentFrame(int))); connect( ui->timebar, SIGNAL(setSelectedFrame(int)), this, SLOT(selectedFramePause()) ); connect( ui->viewer, SIGNAL(currentFrame(int)), ui->timebar, SLOT(setCurrentFrame(int))); connect( ui->spin_frame_count, SIGNAL(valueChanged(int)), this, SLOT(updateFrameCount(int))); connect( ui->combo_velocity_control, SIGNAL(activated(int)), this, SLOT(updateSpeedControl(int))); connect( ui->combo_pos_interpolator, SIGNAL(activated(int)), this, SLOT(updatePositionInterpolation(int))); connect( ui->combo_ori_interpolator, SIGNAL(activated(int)), this, SLOT(updateOrientationInterpolation(int))); connect( ui->checkbox_freeze_pos, SIGNAL(clicked()), this, SLOT(updateFreeze())); connect( ui->checkbox_freeze_ori, SIGNAL(clicked()), this, SLOT(updateFreeze())); // Object 3D Manipulation connect( ui->line_edit_label, SIGNAL(textChanged(QString)), this, SLOT(updateSelectedLabel(QString))); connect( ui->add_keyframe_pos, SIGNAL(pressed()), this, SLOT(addPositionKeyframe())); connect( ui->add_keyframe_ori, SIGNAL(pressed()), this, SLOT(addOrientationKeyframe())); connect( ui->rem_keyframe_pos, SIGNAL(pressed()), this, SLOT(removePositionKeyframe())); connect( ui->rem_keyframe_ori, SIGNAL(pressed()), this, SLOT(removeOrientationKeyframe())); connect( ui->push_button_traj_pos, SIGNAL(toggled(bool)), this, SLOT(displayTrajectoryPosition(bool))); connect( ui->push_button_traj_ori, SIGNAL(toggled(bool)), this, SLOT(displayTrajectoryOrientation(bool))); //render connect( ui->checkbox_render_box, SIGNAL(toggled(bool)), this, SLOT(updateRenderBox(bool)) ); connect( ui->checkBox_render_bones, SIGNAL(toggled(bool)), this, SLOT(updateRenderBones(bool)) ); connect( ui->comboBox_shader, SIGNAL(currentIndexChanged(int)), ui->viewer, SLOT(setCurrentShader(int)) ); //scene connect( ui->comboBox_scene, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCurrentScene(int)) ); connect( ui->viewer, SIGNAL(updateSelected(int)), this, SLOT(setSelectedByID(int)) ); //connect( ui->push_ikmode, SIGNAL(toggled(bool)), this, SLOT(setIKMode(bool)) ); connect( ui->inverse, SIGNAL(currentIndexChanged(int)), this, SLOT(setInverse(int)) ); connect(ui->tab_widget, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); connect(ui->combo_end, SIGNAL(currentIndexChanged(int)), this, SLOT(setIKTarget()) ); connect(ui->spinx, SIGNAL(valueChanged(double)), this, SLOT(changeGoal()) ); connect(ui->spiny, SIGNAL(valueChanged(double)), this, SLOT(changeGoal()) ); connect(ui->spinz, SIGNAL(valueChanged(double)), this, SLOT(changeGoal()) ); connect(ui->save_orientations, SIGNAL(clicked()), this, SLOT(saveAngles()) ) ; connect(ui->spin_frame, SIGNAL(valueChanged(int)), this, SLOT(changeCurrentFrame(int)) ); // interface this->showMaximized(); play_icon = QIcon(QPixmap::fromImage(QImage(":/buttons/play.png"))); pause_icon = QIcon(QPixmap::fromImage(QImage(":/buttons/pause.png"))); stop_icon = QIcon(QPixmap::fromImage(QImage(":/buttons/stop.png"))); }
void SimCalcs::intramolecularMove(int molIdx) { // Save the molecule data for rolling back // TODO (blm): Put these in the GPU with GPUCopy saveBonds(molIdx); saveAngles(molIdx); // Max with one to avoid divide by zero if no intra moves int numMoveTypes = max(ENABLE_BOND + ENABLE_ANGLE + ENABLE_DIHEDRAL, 1); Real intraScaleFactor = 0.25 + (0.75 / (Real)(numMoveTypes)); Real scaleFactor; std::set<int> indexes; Real newEnergy = 0, currentEnergy = calcIntraMolecularEnergy(molIdx); // TODO (blm): allow max to be configurable int numBonds = sb->moleculeData[MOL_BOND_COUNT][molIdx]; int bondStart = sb->moleculeData[MOL_BOND_START][molIdx]; int numAngles = sb->moleculeData[MOL_ANGLE_COUNT][molIdx]; int angleStart = sb->moleculeData[MOL_ANGLE_START][molIdx]; Real bondDelta = sb->maxBondDelta, angleDelta = sb->maxAngleDelta; // Handle bond moves if (ENABLE_BOND && sb->hasFlexibleBonds) { int numBondsToMove = sb->moleculeData[MOL_BOND_COUNT][molIdx]; if (numBondsToMove > 3) { numBondsToMove = (int)randomReal(2, numBonds); numBondsToMove = min(numBondsToMove, sb->maxIntraMoves); } scaleFactor = 0.25 + (0.75 / (Real)numBondsToMove) * intraScaleFactor; sb->numBondMoves += numBondsToMove; // Select the indexes of the bonds to move while (indexes.size() < numBondsToMove) { indexes.insert((int)randomReal(0, numBonds)); } // Move each bond for (auto bondIdx = indexes.begin(); bondIdx != indexes.end(); bondIdx++) { Real stretchDist = scaleFactor * randomReal(-bondDelta, bondDelta); if (sb->bondData[BOND_VARIABLE][bondStart + *bondIdx]) { stretchBond(molIdx, *bondIdx, stretchDist); } } // Do an MC test for delta tuning // Note: Failing does NOT mean we rollback newEnergy = calcIntraMolecularEnergy(molIdx); if (SimCalcs::acceptMove(currentEnergy, newEnergy)) { sb->numAcceptedBondMoves += numBondsToMove; } currentEnergy = newEnergy; indexes.clear(); } // Handle angle movements if (ENABLE_ANGLE && sb->hasFlexibleAngles) { int numAnglesToMove = sb->moleculeData[MOL_ANGLE_COUNT][molIdx]; if (numAnglesToMove > 3) { numAnglesToMove = (int)randomReal(2, numAngles); numAnglesToMove = min(numAnglesToMove, sb->maxIntraMoves); } scaleFactor = 0.25 + (0.75 / (Real)numAnglesToMove) * intraScaleFactor; sb->numAngleMoves += numAnglesToMove; // Select the indexes of the bonds to move while (indexes.size() < numAnglesToMove) { indexes.insert((int)randomReal(0, numAngles)); } // Move each angle for (auto angle = indexes.begin(); angle != indexes.end(); angle++) { Real expandDist = scaleFactor * randomReal(-angleDelta, angleDelta); if (sb->angleData[ANGLE_VARIABLE][angleStart + *angle]) { expandAngle(molIdx, *angle, expandDist); } } // Do an MC test for delta tuning // Note: Failing does NOT mean we rollback newEnergy = calcIntraMolecularEnergy(molIdx); if (SimCalcs::acceptMove(currentEnergy, newEnergy)) { sb->numAcceptedAngleMoves += numAnglesToMove; } currentEnergy = newEnergy; indexes.clear(); } // TODO: Put dihedral movements here // Tune the deltas to acheive 40% intramolecular acceptance ratio // FIXME: Make interval configurable if (ENABLE_TUNING && sb->stepNum != 0 && (sb->stepNum % 1000) == 0) { Real bondRatio = (Real)sb->numAcceptedBondMoves / sb->numBondMoves; Real angleRatio = (Real)sb->numAcceptedAngleMoves / sb->numAngleMoves; Real diff; diff = bondRatio - TARGET_RATIO; if (fabs(diff) > RATIO_MARGIN) { sb->maxBondDelta += sb->maxBondDelta * diff; } diff = angleRatio - TARGET_RATIO; if (fabs(angleDelta) > RATIO_MARGIN) { sb->maxAngleDelta += sb->maxAngleDelta * diff; } // Reset the ratio values sb->numAcceptedBondMoves = 0; sb->numBondMoves = 0; sb->numAcceptedAngleMoves = 0; sb->numAngleMoves = 0; } }