Esempio n. 1
0
void MainWindow::useTorques(bool toggle)
{
  if (toggle) {
    ui->glWidget->getWorld()->follow(2);
    zeroForces();
  }
}
Esempio n. 2
0
void  RigidBody::calcForcesAndTorques() {
    unsigned int i;
    unsigned int j;
    //Vector3d apos;
    Vector3d afrc;
    Vector3d atrq;
    Vector3d rpos;
    Vector3d frc;
    Vector3d trq;
    //Vector3d pos;

    zeroForces();
    
    //pos = getPos();
    frc = getFrc();
    trq = getTrq();

    for (i = 0; i < atoms_.size(); i++) {

        afrc = atoms_[i]->getFrc();

        //apos = atoms_[i]->getPos(apos);
        //rpos = apos - pos;
        rpos = refCoords_[i];
        
        frc += afrc;

        trq[0] += rpos[1]*afrc[2] - rpos[2]*afrc[1];
        trq[1] += rpos[2]*afrc[0] - rpos[0]*afrc[2];
        trq[2] += rpos[0]*afrc[1] - rpos[1]*afrc[0];

        // If the atom has a torque associated with it, then we also need to 
        // migrate the torques onto the center of mass:

        if (atoms_[i]->isDirectional()) {
            atrq = atoms_[i]->getTrq();
            trq += atrq;
        }
        
    }
    
    setFrc(frc);
    setTrq(trq);
    
}
Esempio n. 3
0
/**
 * @brief MainWindow::MainWindow Initialize the main window and everything else
 * @param parent
 */
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
  // Initialize the interface
  ui->setupUi(this);
  ui->glWidget->addAction(ui->actionFullscreen);
  ui->glWidget->addAction(ui->actionExit);

  connect(ui->actionExit,SIGNAL(triggered()),this,SLOT(close()));
  connect(ui->actionFullscreen,SIGNAL(triggered()),this,SLOT(toggleFullscreenSlot()));

  // The test script runs a simple experiment
  experimentScript = new TestScript(this,this);

  // Add a cosmetic line to the splitter handle
  // so that it's easier to grab with the mouse
  QSplitterHandle *handle = ui->splitter->handle(1);
  QVBoxLayout *layout = new QVBoxLayout(handle);
  layout->setSpacing(0);
  layout->setMargin(0);
  QFrame *line = new QFrame(handle);
  line->setFrameShape(QFrame::VLine);
  line->setFrameShadow(QFrame::Sunken);
  layout->addWidget(line);

  // In a future revision, we'll move the SimWorld
  // to a more intelligent place.  It doesn't
  // belong as a child to the graphics widget.
  SimWorld* world = ui->glWidget->getWorld();
  CapBody* capBody = world->getBody();
#if defined( BOARD_DATA )
  BoardMarkerData* md = ui->glWidget->getWorld()->getMarkerData();
#elif defined( POKE_DATA )
  PokeMarkerData* md = ui->glWidget->getWorld()->getMarkerData();
#else
  MarkerData* md = world->getMarkerData();
#endif

  // We populate a ScrollArea with the same number of
  // MarkerWidgets as there are markers in the data file.
  QScrollArea* sa = new QScrollArea;
  QWidget* wid = new QWidget;
  layout = new QVBoxLayout;
  layout->setContentsMargins(0,0,0,0);

  // This part needs to become part of a function
  // that is called everytime a new data file is
  // loaded.
  int markCnt = md->marker_count;
  ui->markerCountLineEdit->setText(QString::number(markCnt));
  ui->frameCountLineEdit->setText(QString::number(md->size()));
  ui->markerFileLineEdit->setText("data.c3d");
  ui->markerFrameStartBox->setValue(0);
  setDataRange(md->size());

  QHBoxLayout* innerLayout = new QHBoxLayout;
  QPushButton* connectButton = new QPushButton("Connect");
  QPushButton* releaseButton = new QPushButton("Release");
  QPushButton* updateButton = new QPushButton("Update Anchors");
  innerLayout->addWidget(connectButton);
  innerLayout->addWidget(releaseButton);
  innerLayout->addWidget(updateButton);
  connect(connectButton,SIGNAL(clicked()),this,SLOT(connectMarkers()));
  connect(releaseButton,SIGNAL(clicked()),this,SLOT(releaseMarkers()));
  connect(updateButton,SIGNAL(clicked()),this,SLOT(updateMarkerAnchors()));
  layout->addLayout(innerLayout);

  markerWidgetArray.resize(markCnt);
  for (int ii=0;ii<markCnt;++ii) {
    markerWidgetArray[ii] = new MarkerWidget(ii,0);
    layout->addWidget(markerWidgetArray[ii]);
  }
  wid->setLayout(layout);
  sa->setWidget(wid);
  ui->controlTabWidget->addTab(sa,"Markers");

  // Joint control tab
  sa = new QScrollArea;
  wid = new QWidget;
  layout = new QVBoxLayout;
  layout->setContentsMargins(0,0,0,0);

  // A couple buttons at the top of the joint tab make it possible
  // to rapidly change all the force limits
  innerLayout = new QHBoxLayout;
  QPushButton* zeroButton = new QPushButton("Zero");
  QPushButton* lightButton = new QPushButton("Light");
  QPushButton* resetButton = new QPushButton("Strong");
  innerLayout->addWidget(zeroButton);
  innerLayout->addWidget(lightButton);
  innerLayout->addWidget(resetButton);
  layout->addLayout(innerLayout);
  connect(zeroButton,SIGNAL(clicked()),this,SLOT(zeroForces()));
  connect(lightButton,SIGNAL(clicked()),this,SLOT(lightForces()));
  connect(resetButton,SIGNAL(clicked()),this,SLOT(strongForces()));

  // Fill the tab with hard-coded data about the model...
  populateJointTab(capBody,layout);
  wid->setLayout(layout);
  sa->setWidget(wid);
  ui->controlTabWidget->addTab(sa,"Joints");

  // Body dimensions widget
  sa = new QScrollArea;
  wid = new QWidget;
  layout = new QVBoxLayout;
  layout->setContentsMargins(0,0,0,0);
  QCheckBox* keepBodyRel = new QCheckBox("Body Rel");
  layout->addWidget(keepBodyRel);

  // Fill the tab with model-specific widgets
  populateBodyTab(capBody,layout);
  wid->setLayout(layout);
  sa->setWidget(wid);
  ui->controlTabWidget->addTab(sa,"Model dimensions");

  // Hook up the interface elements to their respecitve functionality
  connect(ui->saveButton,SIGNAL(clicked()),capBody,SLOT(saveBody()));
  connect(ui->loadButton,SIGNAL(clicked()),capBody,SLOT(loadBody()));
  connect(ui->testButton,SIGNAL(clicked()),this,SLOT(experimentSlot()));

  // When a the CapBody loads the marker map, tell the interface
  // how and where the markers are connected.
  connect(capBody,SIGNAL(markMap(int,int)),this,SLOT(setMarkMap(int,int)));
  connect(capBody,SIGNAL(markPoint(int,double,double,double)),
          this,SLOT(setMarkPoint(int,double,double,double)));

  // *****
  // (Each MarkerWidget informs the capBody when the interface
  //  changes).
  for (int ii=0;ii<markCnt;++ii) {
    connect(markerWidgetArray[ii],SIGNAL(markBodySet(int,int)),md,SLOT(changeBodyConnect(int,int)));
    connect(markerWidgetArray[ii],SIGNAL(markConnect(int,bool)),md,SLOT(changeBodyLink(int,bool)));
    connect(markerWidgetArray[ii],SIGNAL(markPosSet(int,double,double,double)),
            md,SLOT(changeLinkPos(int,double,double,double)));
    connect(markerWidgetArray[ii],SIGNAL(markGrab(int)),this, SLOT(grabMarkPos(int)));
  }

  connect(ui->clearPlotButton,SIGNAL(clicked()),this,SLOT(clearData()));
  connect(ui->glWidget->getWorld(),SIGNAL(useMarkers(bool)),this,SLOT(usingMarkers(bool)));
  connect(ui->frictionSpinBox,SIGNAL(valueChanged(double)),world,SLOT(setGroundFriction(double)));
  connect(ui->terrainSpinBox,SIGNAL(valueChanged(double)),world,SLOT(setTerrainSoftness(double)));
  connect(ui->zBox,SIGNAL(valueChanged(double)),ui->glWidget->getWorld(),SLOT(setTerrainZ(double)));
  connect(ui->forceLinesCheckBox,SIGNAL(clicked(bool)),ui->glWidget,SLOT(setDrawLines(bool)));
  connect(ui->camFollowCheckBox,SIGNAL(clicked(bool)),ui->glWidget,SLOT(setFollowCamera(bool)));
  connect(ui->timeSlider,SIGNAL(valueChanged(int)),world->getMarkerData(),SLOT(setFrame(int)));
  connect(ui->glWidget->getWorld()->getMarkerData(),SIGNAL(frameChanged(int)),ui->timeSlider,SLOT(setValue(int)));
  connect(ui->bodyAlpha,SIGNAL(valueChanged(double)),ui->glWidget,SLOT(setBodyAlpha(double)));
  connect(ui->showMarkBox,SIGNAL(toggled(bool)),ui->glWidget,SLOT(setShowMarkers(bool)));
  connect(ui->selfCollideBox,SIGNAL(toggled(bool)),world,SLOT(setSelfCollide(bool)));
  connect(ui->saveStateButton,SIGNAL(clicked()),this,SLOT(saveModel()));
  connect(ui->restoreButton,SIGNAL(clicked()),this,SLOT(restoreModel()));

  connect(ui->markerRadio,SIGNAL(toggled(bool)),this,SLOT(useMarkers(bool)));
  connect(ui->torqueRadio,SIGNAL(toggled(bool)),this,SLOT(useTorques(bool)));
  connect(ui->altRadio,SIGNAL(toggled(bool)),this,SLOT(useAltForces(bool)));

  connect(ui->playAllButton,SIGNAL(clicked(bool)),this,SLOT(playPauseAll(bool)));
  connect(ui->playPauseDataButton,SIGNAL(clicked(bool)),this,SLOT(playPauseData(bool)));
  connect(ui->playPauseSimButton,SIGNAL(clicked(bool)),this,SLOT(playPauseSim(bool)));

  connect(ui->stepAllButton,SIGNAL(clicked()),this,SLOT(stepAll()));
  connect(ui->stepDataButton,SIGNAL(clicked()),this,SLOT(stepData()));
  connect(ui->stepSimButton,SIGNAL(clicked()),this,SLOT(stepSim()));


  connect(ui->selectFileToolButton,SIGNAL(clicked()),this,SLOT(markerFileDialog()));
  connect(ui->dataStepBox,SIGNAL(valueChanged(int)),this,SLOT(setDataStep(int)));
  connect(ui->dataFrameBox,SIGNAL(valueChanged(int)),this,SLOT(setDataFrame(int)));
  connect(ui->timeSlider,SIGNAL(valueChanged(int)),ui->dataFrameBox,SLOT(setValue(int)));

  // *****
  // Need to dynamically change this
  ui->timeSlider->setRange(0,world->getMarkerData()->size()-1);
  connect(ui->globalBox,SIGNAL(toggled(bool)),this,SLOT(useGlobalForces(bool)));

#if defined( BOARD_DATA )
  bd = new BoardData(this);
  bd->loadData("boardData.dat");
  ui->glWidget->setBoardData(bd);
#endif

  // Start the timer for updating the data, sim, and graphics
  updateTimer.setSingleShot(false);
  connect(&updateTimer,SIGNAL(timeout()),this,SLOT(updateLoop()));

  connect(ui->frameTimeBox,SIGNAL(valueChanged(double)),this,SLOT(setFrameTime(double)));
  ui->frameTimeBox->setValue(1/60.0);
  ui->dataStepBox->setValue(2);

  capBody->loadBody();
  useMarkers(true);
  saveModel();
}