void RtDataStore::setAvailableData(RtDataID dataID) { // remove timepoint if one is set if(dataID.getTimePoint() != DATAID_NUM_UNSET_VALUE) { dataID.setTimePoint(DATAID_NUM_WILDCARD_VALUE); } // put data id into available data (insert will only add a unique value) // TODO will a position iterator add any efficiency here? availableData.insert(dataID); }
// process a single acquisition int RtDataViewer::process(ACE_Message_Block *mb) { ACE_TRACE(("RtDataViewer::process")); RtStreamMessage *msg = (RtStreamMessage*) mb->rd_ptr(); // get the current time unsigned int time = msg->getCurrentData()->getDataID().getTimePoint(); // debug getDataStore().getAvailableData(); RtDataID id; // find all data requested for(vector<string>::iterator i = dataIds.begin(); i != dataIds.end(); i++) { id.setFromString(*i); if(id.getTimePoint() != DATAID_NUM_UNSET_VALUE && id.getTimePoint() != DATAID_NUM_WILDCARD_VALUE) { id.setTimePoint(time); } cout << "RtDataViewer::process: searching for " << id << " from " << *i << endl; // find the data with the right ID RtData *dat = getDataStore().getData(id); if(dat == NULL) { cout << "RtDataViewer::process: could not find " << id << endl; if(logOutput) { stringstream logs(""); logs << "RtDataViewer::process: could not find " << id << endl; log(logs); } } else { cout << "RtDataViewer::process: found " << dat->getDataID() << endl; if(logOutput) { stringstream logs(""); logs << "RtDataViewer::process: found " << dat->getDataID() << endl; log(logs); } } } return 0; }
// hand off some data to be output void RtDataStore::setData(RtData *data) { mut.acquire(); // special check for processing done if(data->getDataID().getModuleID() == "end-task") { // update value of latestTR if (data->getDataID().getTimePoint() != DATAID_NUM_UNSET_VALUE && data->getDataID().getTimePoint() != DATAID_NUM_WILDCARD_VALUE) { latestTR = data->getDataID().getTimePoint(); } mut.release(); return; } // don't allow wildcards on insertion RtDataID insert = data->getDataID(); if(insert.hasWildcards()) { insert.eliminateWildcards(); } // put data into datastore with its dataID as the key store[data->getDataID()] = data; // add to availableData (needs a hard copy of the dataID) setAvailableData(data->getDataID()); mut.release(); //debug // set<RtDataID>::const_iterator it = getAvailableData(); //endebug // notify listeners for(vector<RtDataListener*>::iterator i = notifyList.begin(); i != notifyList.end(); i++) { (*i)->notify(data->getDataID()); } }
// process a single acquisition int RtCurrentActivation::process(ACE_Message_Block *mb) { ACE_TRACE(("RtCurrentActivation::process")); timer tim; if(printTiming) { tim.start(); } // get pointer to message RtStreamMessage *msg = (RtStreamMessage*) mb->rd_ptr(); // get the current image to operate on RtMRIImage *dat = (RtMRIImage*) msg->getCurrentData(); // check for validity of data if (dat == NULL) { cerr << "RtCurrentActivation::process: data passed is NULL" << endl; if(logOutput) { stringstream logs(""); logs << "RtCurrentActivation::process: data passed is NULL" << endl; log(logs); } return 0; } // get mask from msg RtMaskImage *mask = getMaskFromMessage(*msg); // check validity of mask if (mask == NULL) { cerr << "RtCurrentActivation::process: mask is NULL" << endl; if(logOutput) { stringstream logs(""); logs << "RtCurrentActivation::process: mask is NULL at tr " << dat->getDataID().getTimePoint() << endl; log(logs); } return 0; } // initialize the computation if necessary if (needsInit) { initEstimation(*dat, mask); } // get design // TODO this may not work if there are more than one design matrix RtDataID tempDataID; tempDataID.setDataName(NAME_DESIGN); // debug // getDataStore().getAvailableData(); RtDesignMatrix *design = static_cast<RtDesignMatrix*>( getDataStore().getData(tempDataID)); if(design == NULL) { cerr << "error: could not find design matrix in datastore!" << endl; cerr << "searched for design matrix id: " << tempDataID << endl; return 0; } // allocate a new data image for the stats RtActivation *currentActivation = new RtActivation(*dat); // setup the data id currentActivation->getDataID().setFromInputData(*dat, *this); currentActivation->getDataID().setDataName(NAME_ACTIVATION); currentActivation->getDataID().setRoiID(modelFitRoiID); currentActivation->initToNans(); // get the residual and the beta images for discounting nuissance // signals // find the betas RtActivation **betas = new RtActivation*[design->getNumColumns()]; for(unsigned int j = 0; j < design->getNumColumns(); j++) { betas[j] = (RtActivation*) msg->getData(modelFitModuleID, string(NAME_BETA) + "_" + design->getColumnName(j), modelFitRoiID); // check for found if (betas[j] == NULL) { cerr << "RtCurrentActivation:process: beta " << j << " is null" << endl; if(logOutput) { stringstream logs(""); logs << "RtCurrentActivation::process: beta " << j << " is NULL at tr " << dat->getDataID().getTimePoint() << endl; log(logs); } return 0; } } // get residual from message if timepoint is less than // numDataPointsForErrEst otherwise use the steady state // residual value RtActivation *residual; if (dat->getDataID().getTimePoint() < numDataPointsForErrEst) { // get residual off of msg residual = (RtActivation *) msg->getData(modelFitModuleID, NAME_RESIDUAL_MSE, modelFitRoiID); // save off residual steadyStateResidual = residual; } else { // post-numDataPointsForErrEst, use saved residual residual = steadyStateResidual; } // check that residual is not null if (residual == NULL) { cerr << "RtCurrentActivation:process: residual is null" << endl; if(logOutput) { stringstream logs(""); logs << "RtCurrentActivation::process: residual is NULL at tr " << dat->getDataID().getTimePoint() << endl; log(logs); } return 0; } // get this design matrix row vnl_vector<double> Xrow = design->getRow(dat->getDataID().getTimePoint()-1); // include this timepoint for each voxel RtElementAccess datAc(dat, mask); RtElementAccess resAc(residual, mask); vector<unsigned int> inds = datAc.getElementIndices(); for(vector<unsigned int>::iterator it = inds.begin(); it != inds.end(); it++) { // get voxel intensity double y = datAc.getDoubleElement(*it); double *betavals = new double[Xrow.size()]; // compute error double err = y; for (unsigned int j = 0; j < Xrow.size(); j++) { if (!design->isColumnOfInterest(j)) { double beta = betas[j]->getPixel(*it); err -= beta * Xrow[j]; betavals[j] = beta; } else { // for debug output betavals[j] = betas[j]->getPixel(*it); } } // compute the dev and current activation (magic happens here) double dev = sqrt(resAc.getDoubleElement(*it) / (residual->getDataID().getTimePoint())); currentActivation->setPixel(*it, err / dev); if (dumpAlgoVars && dat->getDataID().getTimePoint() > 2) { dumpFile << dat->getDataID().getTimePoint() << " " << *it << " " << y << " " << err << " " << Xrow[0] << " " << residual->getPixel(*it) << " " << dev << " " << currentActivation->getPixel(*it) << " "; for (unsigned int b = 0; b < design->getNumColumns(); b++) { dumpFile << betavals[b] << " "; } dumpFile << endl; } delete [] betavals; } setResult(msg, currentActivation); setResult(msg, residual); delete [] betas; if(printTiming) { tim.stop(); cout << "RtCurrentActivation process at tr " << dat->getDataID().getTimePoint() << " elapsed time: " << tim.elapsed_time()*1000 << "ms" << endl; } if(print) { cout << "RtCurrentActivation: done at tr " << dat->getDataID().getTimePoint() << endl; } if(logOutput) { stringstream logs(""); logs << "RtCurrentActivation: done at tr " << dat->getDataID().getTimePoint() << endl; log(logs); } if(saveResult) { string fn = getExperimentConfig().getVolFilename( dat->getDataID().getSeriesNum(), dat->getDataID().getTimePoint()); string stem = getExperimentConfig().get("study:volumeFileStem").str(); currentActivation->setFilename(fn.replace(fn.rfind(stem), stem.size(), "curact")); currentActivation->save(); } return 0; }
void PlotController::handleData(QString qid) { RtDataID id; id.setFromString(qid.toStdString()); if (id.getDataName() == NAME_DESIGN) { baseline_box->topLeft->setCoords(0, 10); baseline_box->bottomRight->setCoords(getNumDataPointsForErrEst(), -10); RtDesignMatrix *design = static_cast<RtDesignMatrix*>(getDataStore().getData(id)); updateTRIndicators(); plotDesign(design); roi_plot->xAxis->setRange(0, design->getNumRows()); roi_plot->replot(); motion_plot->xAxis->setRange(0, design->getNumRows()); motion_plot->replot(); } else if (id.getModuleID() == ID_ROICOMBINE) { map<string, int>::const_iterator it = roi_graphs.find(id.getRoiID()); if (it == roi_graphs.end()) { it = roi_graphs.insert( pair<string, int>(id.getRoiID(), roi_plot->graphCount())).first; roi_plot->addGraph(); roi_plot->graph(it->second)->setPen(QPen(roi_colormap.getColorForName( id.getRoiID()))); roi_plot->graph(it->second)->setName(QString(id.getRoiID().c_str())); roi_plot->legend->setVisible(true); } RtActivation *val = static_cast<RtActivation*>(getDataStore().getData(id)); roi_plot->graph(roi_graphs[id.getRoiID()])->addData(id.getTimePoint(), val->getPixel(0)); roi_plot->replot(); } else if (id.getModuleID() == ID_MOTION) { plotMotion(static_cast<RtMotion*>(getDataStore().getData(id))); } if (id.getTimePoint() != DATAID_NUM_UNSET_VALUE && id.getTimePoint() > current_tr) { current_tr = id.getTimePoint(); updateTRIndicators(); } }
// get data by id // // NOTE: this function is much more efficient if the requested data is // specified fully, i.e. there are no wildcards in the dataID (see RtDataID.h) // avoid using wildcards if possible RtData *RtDataStore::getData(RtDataID dataID) { // fill in wildcards (search through available data makes this inefficient) if(dataID.hasWildcards()) { // find corresponding full id by an exhaustive search through available // data for(set<RtDataID>::const_iterator id = availableData.begin(); id != availableData.end(); id++) { RtDataID avail = (*id); // handle potential timepoint-less data unsigned int tp = avail.getTimePoint(); if(dataID.getTimePoint() != DATAID_NUM_UNSET_VALUE) { avail.setTimePoint(DATAID_NUM_WILDCARD_VALUE); } else { avail.setTimePoint(DATAID_NUM_UNSET_VALUE); } if (avail == dataID) { // == respects wildcards // copy, preserving timepoint if not a timepointless datum unsigned int origTp = dataID.getTimePoint(); dataID = avail; if(tp != DATAID_NUM_UNSET_VALUE) { dataID.setTimePoint(origTp); } else { dataID.setTimePoint(tp); } break; } } // finally, handle wildcard in timepoint field by using the latest timepoint if (dataID.getTimePoint() == DATAID_NUM_WILDCARD_VALUE) { dataID.setTimePoint(latestTR); } if(dataID.hasWildcards()) { cerr << "filling in wildcards failed. no match found." << endl; return NULL; } } // iterator for map map<RtDataID,RtData*,RtDataIDCompare>::const_iterator it; mut.acquire(); it = store.find(dataID); // if not found if(it == store.end()) { mut.release(); return NULL; } mut.release(); return (*it).second; }
void MainWindow::notify(const RtDataID &id) { ui->imageWidget->handleData(id); emit dataReady(QString(id.toString().c_str())); }