void MasterFromWallChannel::processMessages() { while( _processMessages ) { const ProbeResult result = _mpiChannel->probe(); if( !result.isValid( )) { put_flog( LOG_ERROR, "Invalid probe result size: %d", result.size ); continue; } _buffer.setSize( result.size ); _mpiChannel->receive( _buffer.data(), result.size, result.src, result.message ); switch( result.message ) { case MPI_MESSAGE_TYPE_REQUEST_FRAME: { QString uri; _buffer.deserialize( uri ); emit receivedRequestFrame( uri ); break; } case MPI_MESSAGE_TYPE_QUIT: _processMessages = false; break; default: put_flog( LOG_WARN, "Invalid message type: %d", result.message ); break; } } }
bool ContentLoader::load( const QString& filename, const QPointF& windowCenterPosition, const QSizeF& windowSize ) { put_flog( LOG_INFO, "opening: '%s'", filename.toLocal8Bit().constData( )); ContentPtr content = ContentFactory::getContent( filename ); if( !content ) { put_flog( LOG_WARN, "ignoring unsupported file: '%s'", filename.toLocal8Bit().constData( )); return false; } ContentWindowPtr contentWindow( new ContentWindow( content )); ContentWindowController controller( *contentWindow, *displayGroup_ ); if( windowSize.isValid( )) controller.resize( windowSize ); else controller.adjustSize( SIZE_LARGE ); if( windowCenterPosition.isNull( )) controller.moveCenterTo( displayGroup_->getCoordinates().center( )); else controller.moveCenterTo( windowCenterPosition ); displayGroup_->addContentWindow( contentWindow ); return true; }
bool StateSerializationHelper::load( const QString& filename ) { put_flog( LOG_INFO, "Restoring session: '%s'", filename.toStdString().c_str( )); State state; // For backward compatibility, try to load the file as a legacy state file first if( !state.legacyLoadXML( filename )) { // De-serialize state file std::ifstream ifs( filename.toStdString( )); if ( !ifs.good( )) return false; try { boost::archive::xml_iarchive ia( ifs ); ia >> BOOST_SERIALIZATION_NVP( state ); } catch( const boost::archive::archive_exception& e ) { put_flog( LOG_ERROR, "Could not restore session: '%s': %s", filename.toStdString().c_str(), e.what( )); return false; } catch( const std::exception& e ) { put_flog( LOG_ERROR, "Could not restore state file '%s''," "wrong file format: %s", filename.toStdString().c_str(), e.what( )); return false; } ifs.close(); }
bool Configuration::save(const QString &filename) const { QDomDocument doc("XmlDoc"); QFile infile(filename_); if (!infile.open(QIODevice::ReadOnly)) { put_flog(LOG_ERROR, "could not open configuration xml file for saving"); return false; } doc.setContent(&infile); infile.close(); QDomElement root = doc.documentElement(); QDomElement background = root.firstChildElement("background"); if (background.isNull()) { background = doc.createElement("background"); root.appendChild(background); } background.setAttribute("uri", backgroundUri_); background.setAttribute("color", backgroundColor_.name()); QFile outfile(filename); if (!outfile.open(QIODevice::WriteOnly | QIODevice::Text)) { put_flog(LOG_ERROR, "could not open configuration xml file for saving"); return false; } QTextStream out(&outfile); out << doc.toString(4); outfile.close(); return true; }
EpidemicDataSet::EpidemicDataSet(const char * filename) { // defaults isValid_ = false; numTimes_ = 1; numNodes_ = 0; // load stratifications data if(loadStratificationsFile() != true) { put_flog(LOG_ERROR, "could not load stratifications file"); return; } // load node name and group data std::string nodeNameGroupFilename = g_dataDirectory + "/fips_county_names_HSRs.csv"; if(loadNodeNameGroupFile(nodeNameGroupFilename.c_str()) != true) { put_flog(LOG_ERROR, "could not load file %s", nodeNameGroupFilename.c_str()); return; } // population data std::string nodePopulationFilename = g_dataDirectory + "/fips_populations_stratified.csv"; if(loadNodePopulationFile(nodePopulationFilename.c_str()) != true) { put_flog(LOG_ERROR, "could not load file %s", nodePopulationFilename.c_str()); return; } // travel data std::string nodeTravelFilename = g_dataDirectory + "/county_travel_fractions.csv"; if(loadNodeTravelFile(nodeTravelFilename.c_str()) != true) { put_flog(LOG_ERROR, "could not load file %s", nodeTravelFilename.c_str()); return; } // data set if(filename != NULL) { if(loadNetCdfFile(filename) != true) { put_flog(LOG_ERROR, "could not load file %s", filename); return; } // todo: for now, duplicate population data over all times, since this isn't stored in the data set for(int time=1; time<numTimes_; time++) { copyVariableToNewTimeStep("population"); } } isValid_ = true; }
float EpidemicDataSet::getValue(const std::string &varName, const int &time, const int &nodeId, const std::vector<int> &stratificationValues) { // handle derived variables if(derivedVariables_.count(varName) > 0) { return derivedVariables_[varName](time, nodeId, stratificationValues); } if(variables_.count(varName) == 0) { put_flog(LOG_ERROR, "no such variable %s (nodeId = %i)", varName.c_str(), nodeId); return 0.; } else if(nodeId != NODES_ALL && nodeIdToIndex_.count(nodeId) == 0) { put_flog(LOG_ERROR, "could not map nodeId %i to an index (varName = %s)", nodeId, varName.c_str()); return 0.; } // the variable we're getting blitz::Array<float, 2+NUM_STRATIFICATION_DIMENSIONS> variable = variables_[varName]; // the full domain blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> lowerBound = variable.lbound(); blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> upperBound = variable.ubound(); // make sure this variable is valid for the specified time if(time < lowerBound(0) || time > upperBound(0)) { put_flog(LOG_WARN, "variable %s not valid for time %i", varName.c_str(), time); return 0.; } // limit by time lowerBound(0) = upperBound(0) = time; // limit by node if(nodeId != NODES_ALL) { lowerBound(1) = upperBound(1) = nodeIdToIndex_[nodeId]; } // limit by stratification values for(unsigned int i=0; i<stratificationValues.size(); i++) { if(stratificationValues[i] != STRATIFICATIONS_ALL) { lowerBound(2+i) = upperBound(2+i) = stratificationValues[i]; } } // the subdomain blitz::RectDomain<2+NUM_STRATIFICATION_DIMENSIONS> subdomain(lowerBound, upperBound); // return the sum of the array over the subdomain return blitz::sum(variable(subdomain)); }
bool EpidemicDataSet::loadStratificationsFile() { std::string filename = g_dataDirectory + "/" + STRATIFICATIONS_FILENAME; std::ifstream in(filename.c_str()); if(in.is_open() != true) { put_flog(LOG_ERROR, "could not load file %s", filename.c_str()); return false; } // clear existing entries stratificationNames_.clear(); stratifications_.clear(); // use boost tokenizer to parse the file typedef boost::tokenizer< boost::escaped_list_separator<char> > Tokenizer; std::vector<std::string> vec; std::string line; // read names of stratifications getline(in, line); Tokenizer tok(line); vec.assign(tok.begin(), tok.end()); // make sure this matches what we expect if(vec.size() != NUM_STRATIFICATION_DIMENSIONS) { put_flog(LOG_ERROR, "got %i stratification dimensions, expected %i", vec.size(), NUM_STRATIFICATION_DIMENSIONS); return false; } stratificationNames_ = vec; // read stratification value names for(unsigned int i=0; i<NUM_STRATIFICATION_DIMENSIONS; i++) { vec.clear(); getline(in, line); Tokenizer tok(line); vec.assign(tok.begin(), tok.end()); stratifications_.push_back(vec); } return true; }
void MasterApplication::_initRestInterface() { _restInterface = make_unique<RestInterface>( _config->getWebServicePort(), _options, *_config ); _logger = make_unique<LoggingUtility>(); connect( _restInterface.get(), &RestInterface::browse, [this]( QString uri ) { #if TIDE_USE_QT5WEBKITWIDGETS || TIDE_USE_QT5WEBENGINE if( uri.isEmpty( )) uri = _config->getWebBrowserDefaultURL(); _pixelStreamerLauncher->openWebBrowser( QPointF(), QSize(), uri ); #else put_flog( LOG_INFO, "Can't browse url '%s', Tide was compiled without" "webbrowser support", uri.toLocal8Bit().constData( )); #endif }); connect( _restInterface.get(), &RestInterface::whiteboard, [this]() { _pixelStreamerLauncher->openWhiteboard(); }); connect( _restInterface.get(), &RestInterface::open, this, &MasterApplication::_open); connect( _restInterface.get(), &RestInterface::load, this, &MasterApplication::load ); connect( _restInterface.get(), &RestInterface::save, this, &MasterApplication::_save ); connect( _restInterface.get(), &RestInterface::clear, [this]() { _displayGroup->clear(); }); connect( _restInterface.get(), &RestInterface::screenshot, [this]( const QString filename ) { _screenshotFilename = filename; _masterToWallChannel->sendRequestScreenshot(); }); connect( _restInterface.get(), &RestInterface::exit, [this]() { exit(); }); connect( _displayGroup.get(), &DisplayGroup::contentWindowAdded, _logger.get(), &LoggingUtility::contentWindowAdded ); connect( _displayGroup.get(), &DisplayGroup::contentWindowRemoved, _logger.get(), &LoggingUtility::contentWindowRemoved ); connect( _displayGroup.get(), &DisplayGroup::contentWindowMovedToFront, _logger.get(), &LoggingUtility::contentWindowMovedToFront ); _restInterface.get()->exposeStatistics( *_logger ); _restInterface.get()->setupHtmlInterface( *_displayGroup, *_config ); }
int main(int argc, char * argv[]) { QApplication * app = new QApplication(argc, argv); // get directory of application QDir appDirectory = QDir(QCoreApplication::applicationDirPath()); // and data directory QDir dataDirectory = appDirectory; #ifdef __APPLE__ dataDirectory.cdUp(); dataDirectory.cd("Resources"); dataDirectory.cd("data"); #elif WIN32 dataDirectory.cdUp(); dataDirectory.cd("data"); #endif g_dataDirectory = dataDirectory.absolutePath().toStdString(); put_flog(LOG_DEBUG, "data directory: %s", g_dataDirectory.c_str()); // disable VTK console messages vtkObject::GlobalWarningDisplayOff(); g_mainWindow = new MainWindow(); // enter Qt event loop app->exec(); delete g_mainWindow; return 0; }
bool EpidemicDataSet::newVariable(std::string varName) { if(variables_.count(varName) != 0) { put_flog(LOG_ERROR, "variable %s already exists", varName.c_str()); return false; } // full shape blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> shape; shape(0) = numTimes_; shape(1) = numNodes_; for(int j=0; j<NUM_STRATIFICATION_DIMENSIONS; j++) { shape(2 + j) = stratifications_[j].size(); } // create the variable blitz::Array<float, 2+NUM_STRATIFICATION_DIMENSIONS> var(shape); // initialize values to zero var = 0.; // add the variable to the vector variables_[varName].reference(var); return true; }
void MasterConfiguration::loadMasterSettings() { QXmlQuery query; if(!query.setFocus(QUrl(filename_))) { put_flog(LOG_FATAL, "failed to load %s", filename_.toLatin1().constData()); exit(-1); } QString queryResult; // dock start directory query.setQuery("string(/configuration/dock/@directory)"); if (query.evaluateTo(&queryResult)) dockStartDir_ = queryResult.remove(QRegExp("[\\n\\t\\r]")); if( dockStartDir_.isEmpty( )) dockStartDir_ = QDir::homePath(); // WebService server port query.setQuery("string(/configuration/webservice/@port)"); if (query.evaluateTo(&queryResult)) { if (queryResult.isEmpty()) dcWebServicePort_ = DEFAULT_WEBSERVICE_PORT; else dcWebServicePort_ = queryResult.toInt(); } }
void MapWidget::exportSVGToDisplayCluster() { if(g_dcSocket != NULL && svgTmpFile_.open()) { QSvgGenerator generator; generator.setFileName(svgTmpFile_.fileName()); generator.setResolution(90); generator.setSize(QSize(1400, 1200)); generator.setViewBox(viewRect_); QPainter painter; painter.begin(&generator); // set logical coordinates of the render window painter.setWindow(viewRect_.toRect()); // draw a black background painter.setBrush(QBrush(QColor::fromRgbF(0,0,0,1))); painter.drawRect(QRect(QPoint(-107,37), QPoint(-93,25))); renderAll(&painter, false); painter.end(); put_flog(LOG_DEBUG, "wrote %s", svgTmpFile_.fileName().toStdString().c_str()); // now, send it to DisplayCluster sendSVGToDisplayCluster((svgTmpFile_.fileName()).toStdString(), (QString("ExerciseMap-") + QString::number(index_) + ".svg").toStdString()); } }
bool EpidemicDataSet::copyVariableToNewTimeStep(std::string varName) { if(variables_.count(varName) == 0) { put_flog(LOG_ERROR, "no such variable %s", varName.c_str()); return false; } // get current shape of variable blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> shape = variables_[varName].shape(); // add a time step shape(0) = shape(0) + 1; // resize variable for the new shape variables_[varName].resizeAndPreserve(shape); // copy data to the new time step // the full domain blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> lowerBound = variables_[varName].lbound(); blitz::TinyVector<int, 2+NUM_STRATIFICATION_DIMENSIONS> upperBound = variables_[varName].ubound(); // domain for previous time and new time lowerBound(0) = upperBound(0) = variables_[varName].extent(0) - 2; blitz::RectDomain<2+NUM_STRATIFICATION_DIMENSIONS> subdomain0(lowerBound, upperBound); lowerBound(0) = upperBound(0) = variables_[varName].extent(0) - 1; blitz::RectDomain<2+NUM_STRATIFICATION_DIMENSIONS> subdomain1(lowerBound, upperBound); // make the copy variables_[varName](subdomain1) = variables_[varName](subdomain0); return true; }
void PDF::generateTexture(const QRectF& screenRect, const QRectF& fullRect, const QRectF& texCoords) { // figure out the coordinates of the topLeft corner of the texture in the PDF page const double tXp = texCoords.x()/texCoords.width()*fullRect.width() + (screenRect.x() - fullRect.x()); const double tYp = texCoords.y()/texCoords.height()*fullRect.height() + (screenRect.y() - fullRect.y()); // Compute the actual texture dimensions const QRect textureRect(tXp, tYp, screenRect.width(), screenRect.height()); // TODO The instance of this class is shared between GLWindows, so the // texture is constantly regenerated because the size changes... if(textureRect == textureRect_) return; // no need to regenerate texture // Adjust the quality to match the actual displayed size // Multiply resolution by the zoom factor (1/t[W,H]) const double resFactorX = fullRect.width() / pdfPage_->pageSize().width() / texCoords.width(); const double resFactorY = fullRect.height() / pdfPage_->pageSize().height() / texCoords.height(); // Generate a QImage of the rendered page QImage image = pdfPage_->renderToImage(72.0*resFactorX , 72.0*resFactorY, textureRect.x(), textureRect.y(), textureRect.width(), textureRect.height() ); if (image.isNull()) { put_flog(LOG_DEBUG, "Could not render pdf to image"); return; } texture_.update(image, GL_BGRA); textureRect_ = textureRect; // keep rendered texture information so we know when to rerender }
bool StateSerializationHelper::save( const QString& filename, const bool generatePreview ) { put_flog( LOG_INFO, "Saving session: '%s'", filename.toStdString().c_str( )); ContentWindowPtrs contentWindows = displayGroup_->getContentWindows(); if( generatePreview ) { const QSizeF& size = displayGroup_->getCoordinates().size(); const QSize dimensions( (int)size.width(), (int)size.height( )); StatePreview filePreview( filename ); filePreview.generateImage( dimensions, contentWindows ); filePreview.saveToFile(); } // serialize state std::ofstream ofs( filename.toStdString( )); if ( !ofs.good( )) return false; // brace this so destructor is called on archive before we use the stream { State state( displayGroup_ ); boost::archive::xml_oarchive oa( ofs ); oa << BOOST_SERIALIZATION_NVP( state ); } ofs.close(); return true; }
void loadImageDataThread(boost::shared_ptr<PixelStream> pixelStream, QByteArray imageData) { // use libjpeg-turbo for JPEG conversion tjhandle handle = pixelStream->getHandle(); // get information from header int width, height, jpegSubsamp; int success = tjDecompressHeader2(handle, (unsigned char *)imageData.data(), (unsigned long)imageData.size(), &width, &height, &jpegSubsamp); if(success != 0) { put_flog(LOG_ERROR, "libjpeg-turbo header decompression failure"); return; } // decompress image data int pixelFormat = TJPF_BGRX; int pitch = width * tjPixelSize[pixelFormat]; int flags = TJ_FASTUPSAMPLE; QImage image = QImage(width, height, QImage::Format_RGB32); success = tjDecompress2(handle, (unsigned char *)imageData.data(), (unsigned long)imageData.size(), (unsigned char *)image.scanLine(0), width, pitch, height, pixelFormat, flags); if(success != 0) { put_flog(LOG_ERROR, "libjpeg-turbo image decompression failure"); return; } /* uint c = 0x0000ff00; int width=64; int height=64; QImage image = QImage(width, height, QImage::Format_RGB32); for (int i=0; i<height; i++) { for (int j=0; j<height; j++) image.setPixel(i,j,c); }*/ pixelStream->imageReady(image); }
ChartWidget::~ChartWidget() { // the tempory file doesn't have the extension as written by the SVG exporter // so, we need to delete the file with the extension, too if(svgTmpFile_.fileName().isEmpty() != true) { QFile svgTmpFileOther(svgTmpFile_.fileName() + ".svg"); if(svgTmpFileOther.exists() == true && svgTmpFileOther.remove() == true) { put_flog(LOG_DEBUG, "removed temporary file %s", svgTmpFileOther.fileName().toStdString().c_str()); } else { put_flog(LOG_ERROR, "could not remove temporary file %s", svgTmpFileOther.fileName().toStdString().c_str()); } } }
std::string EpidemicDataSet::getNodeName(int nodeId) { if(nodeIdToName_.count(nodeId) == 0) { put_flog(LOG_ERROR, "could not map nodeId %i to a name", nodeId); return std::string(""); } return nodeIdToName_[nodeId]; }
blitz::Array<float, 1+NUM_STRATIFICATION_DIMENSIONS> EpidemicDataSet::getVariableAtTime(std::string varName, int time) { if(variables_.count(varName) == 0) { put_flog(LOG_ERROR, "no such variable %s", varName.c_str()); return blitz::Array<float, 1+NUM_STRATIFICATION_DIMENSIONS>(); } if(time >= variables_[varName].extent(0)) { put_flog(LOG_ERROR, "time %i >= time extent %i", time, variables_[varName].extent(0)); return blitz::Array<float, 1+NUM_STRATIFICATION_DIMENSIONS>(); } // this should produce a slice that references the data in the original variable array blitz::Array<float, 1+NUM_STRATIFICATION_DIMENSIONS> subVar = variables_[varName](time, blitz::Range::all(), BOOST_PP_ENUM(NUM_STRATIFICATION_DIMENSIONS, TEXT, blitz::Range::all())); return subVar; }
float EpidemicDataSet::getTravel(int nodeId0, int nodeId1) { if(nodeIdToIndex_.count(nodeId0) == 0 || nodeIdToIndex_.count(nodeId1) == 0) { put_flog(LOG_ERROR, "could not map a nodeId to an index for: %i, %i", nodeId0, nodeId1); return 0.; } return travel_(nodeIdToIndex_[nodeId0], nodeIdToIndex_[nodeId1]); }
std::vector<int> EpidemicDataSet::getNodeIds(std::string groupName) { if(groupNameToNodeIds_.count(groupName) == 0) { put_flog(LOG_ERROR, "could not map group name %s to node ids", groupName.c_str()); return std::vector<int>(); } return groupNameToNodeIds_[groupName]; }
SVG::SVG(const QString uri) : uri_(uri) , width_(0) , height_(0) { QFile file(uri); if(!file.open(QIODevice::ReadOnly)) { put_flog(LOG_WARN, "could not open file %s", uri.toLocal8Bit().constData()); return; } if(!setImageData(file.readAll())) { put_flog(LOG_WARN, "could not setImageData %s", uri.toLocal8Bit().constData()); return; } }
float EpidemicDataSet::getPopulation(int nodeId) { if(nodeIdToIndex_.count(nodeId) == 0) { put_flog(LOG_ERROR, "could not map nodeId %i to an index", nodeId); return 0.; } return getValue("population", 0, nodeId); }
bool StatePreview::saveToFile() const { const bool success = previewImage_.save( previewFilename(), "PNG" ); if ( !success ) put_flog( LOG_ERROR, "Saving StatePreview image failed: %s", previewFilename().toLocal8Bit().constData( )); return success; }
bool EpidemicDataSet::copyVariable(std::string sourceVarName, std::string destVarName) { if(variables_.count(sourceVarName) == 0) { put_flog(LOG_ERROR, "no such variable %s", sourceVarName.c_str()); return false; } if(variables_.count(destVarName) != 0) { put_flog(LOG_ERROR, "destination variable %s already exists", destVarName.c_str()); return false; } blitz::Array<float, 2+NUM_STRATIFICATION_DIMENSIONS> varCopy = variables_[sourceVarName].copy(); variables_[destVarName].reference(varCopy); return true; }
QString StatePreview::previewFilename() const { QFileInfo fileinfo( dcxFileName_ ); if ( fileinfo.suffix().toLower() != "dcx" ) { put_flog( LOG_WARN, "wrong state file extension (expected .dcx)" ); return QString(); } return fileinfo.path() + "/" + fileinfo.completeBaseName() + getFileExtension(); }
void MasterApplication::_deleteTempContentFile( ContentWindowPtr window ) { const bool isFile = contentTypeIsFile( window->getContent()->getType( )); const auto& filename = window->getContent()->getURI(); if( isFile && filename.startsWith( QDir::tempPath() + "/" )) { QDir().remove( filename ); put_flog( LOG_INFO, "Deleted temporary file: %s", filename.toLocal8Bit().constData( )); } }
std::vector<std::string> EpidemicDataSet::getStratificationNames() { if(stratificationNames_.size() == 0) { if(loadStratificationsFile() != true) { put_flog(LOG_ERROR, "could not load stratifications file"); } } return stratificationNames_; }
QJsonObject toObject( const std::string& data ) { const auto input = QByteArray::fromRawData( data.c_str(), data.size( )); const auto doc = QJsonDocument::fromJson( input ); if( doc.isNull() || !doc.isObject( )) { put_flog( LOG_INFO, "Error parsing JSON string: '%s'", data.c_str( )); return QJsonObject{}; } return doc.object(); }
void MasterConfiguration::loadMasterSettings() { QXmlQuery query; if(!query.setFocus(QUrl(filename_))) { put_flog(LOG_FATAL, "failed to load %s", filename_.toLatin1().constData()); exit(-1); } loadDockStartDirectory(query); loadWebBrowserStartURL(query); }