void QmitkTrackingDeviceConfigurationWidget::SetOptitrackCalibrationFileClicked() { std::string filename = QFileDialog::getOpenFileName(NULL,tr("Open Calibration File"), "/", "*.*").toLatin1().data(); if (filename=="") {return;} else { m_OptitrackCalibrationFile = filename; Poco::Path myPath = Poco::Path(m_OptitrackCalibrationFile.c_str()); m_Controls->m_OptitrackCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } }
void QmitkNPOptitrackWidget::SetOptitrackCalibrationFileClicked() { std::string filename = QFileDialog::getOpenFileName(nullptr, tr("Open Calibration File"), QmitkIGTCommonHelper::GetLastFileLoadPath(), "*.*").toLatin1().data(); if (filename == "") { return; } else { QmitkIGTCommonHelper::SetLastFileLoadPathByFileName(QString::fromStdString(filename)); m_OptitrackCalibrationFile = filename; Poco::Path myPath = Poco::Path(m_OptitrackCalibrationFile.c_str()); m_Controls->m_OptitrackCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } }
int countLoolKitProcesses() { // Give polls in the lool processes time to time out etc Poco::Thread::sleep(POLL_TIMEOUT_MS*5); int result = 0; for (auto i = Poco::DirectoryIterator(std::string("/proc")); i != Poco::DirectoryIterator(); ++i) { try { Poco::Path procEntry = i.path(); const std::string& fileName = procEntry.getFileName(); int pid; std::size_t endPos = 0; try { pid = std::stoi(fileName, &endPos); } catch (const std::invalid_argument&) { pid = 0; } if (pid > 1 && endPos == fileName.length()) { Poco::FileInputStream stat(procEntry.toString() + "/stat"); std::string statString; Poco::StreamCopier::copyToString(stat, statString); Poco::StringTokenizer tokens(statString, " "); if (tokens.count() > 3 && tokens[1] == "(loolkit)") { switch (tokens[2].c_str()[0]) { case 'x': case 'X': // Kinds of dead-ness. case 'Z': // zombies break; // ignore default: result++; break; } // std::cout << "Process:" << pid << ", '" << tokens[1] << "'" << " state: " << tokens[2] << std::endl; } } } catch (const Poco::Exception&) { } } // std::cout << "Number of loolkit processes: " << result << std::endl; return result; }
void QmitkTrackingDeviceConfigurationWidget::TrackingDeviceChanged() { //show the correspondig widget m_Controls->m_TrackingSystemWidget->setCurrentIndex(m_Controls->m_trackingDeviceChooser->currentIndex()); //the new trackingdevice is not configurated yet m_TrackingDeviceConfigurated = false; //reset output ResetOutput(); //print output and do further initializations if (m_Controls->m_trackingDeviceChooser->currentIndex()==0)//NDI Polaris { AddOutput("<br>NDI Polaris selected"); } else if (m_Controls->m_trackingDeviceChooser->currentIndex()==1) //NDI Aurora { AddOutput("<br>NDI Aurora selected"); } else if (m_Controls->m_trackingDeviceChooser->currentIndex()==2) //ClaronTechnology MicronTracker 2 { AddOutput("<br>Microntracker selected"); if (!mitk::ClaronTrackingDevice::New()->IsDeviceInstalled()) { AddOutput("<br>ERROR: not installed!"); } else if (this->m_MTCalibrationFile == "") //if configuration file for MicronTracker is empty: load default { mitk::ClaronTrackingDevice::Pointer tempDevice = mitk::ClaronTrackingDevice::New(); m_MTCalibrationFile = tempDevice->GetCalibrationDir(); Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str()); m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } } else if (m_Controls->m_trackingDeviceChooser->currentIndex()==3) { AddOutput("<br>Optitrack selected"); if (!mitk::OptitrackTrackingDevice::New()->IsDeviceInstalled()) { AddOutput("<br>ERROR: not installed!"); } } emit TrackingDeviceSelectionChanged(); }
mitk::TrackingDevice::Pointer QmitkMicronTrackerWidget::ConstructTrackingDevice() { mitk::ClaronTrackingDevice::Pointer newDevice = mitk::ClaronTrackingDevice::New(); if (this->m_MTCalibrationFile.empty()) //if configuration file for MicronTracker is empty: load default { mitk::ClaronTrackingDevice::Pointer tempDevice = mitk::ClaronTrackingDevice::New(); m_MTCalibrationFile = tempDevice->GetCalibrationDir(); Poco::Path myPath = Poco::Path(m_MTCalibrationFile.c_str()); m_Controls->m_MTCalibrationFile->setText("Calibration File: " + QString(myPath.getFileName().c_str())); } if (!this->m_MTCalibrationFile.empty()) { //extract path from calibration file and set the calibration dir of the device std::string path = itksys::SystemTools::GetFilenamePath(m_MTCalibrationFile); newDevice->SetCalibrationDir(path); } else AddOutput("<br>Warning: Calibration file is not set!"); return static_cast<mitk::TrackingDevice::Pointer>(newDevice); }
void FileSystemRoute::handleRequest(ServerEventArgs& evt) { Poco::Path dataFolder(ofToDataPath("", true)); Poco::Path documentRoot(ofToDataPath(getSettings().getDocumentRoot(), true)); std::string dataFolderString = dataFolder.toString(); std::string documentRootString = documentRoot.toString(); // Document root validity check. if (_settings.getRequireDocumentRootInDataFolder() && (documentRootString.length() < dataFolderString.length() || documentRootString.substr(0, dataFolderString.length()) != dataFolderString)) { ofLogError("FileSystemRoute::handleRequest") << "Document Root is not a sub directory of the data folder."; evt.getResponse() .setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); handleErrorResponse(evt); return; } // check path Poco::URI uri(evt.getRequest().getURI()); std::string path = uri.getPath(); // just get the path // make paths absolute if (path.empty()) { path = "/"; } Poco::Path requestPath = documentRoot.append(path).makeAbsolute(); // add the default index if no filename is requested if (requestPath.getFileName().empty()) { requestPath.append(getSettings().getDefaultIndex()).makeAbsolute(); } std::string requestPathString = requestPath.toString(); // double check path safety (not needed?) if ((requestPathString.length() < documentRootString.length() || requestPathString.substr(0, documentRootString.length()) != documentRootString)) { ofLogError("FileSystemRoute::handleRequest") << "Requested document not inside DocumentFolder."; evt.getResponse().setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND); handleErrorResponse(evt); return; } ofFile file(requestPathString); // use it to parse file name parts std::string mediaTypeString = MediaTypeMap::getDefault()->getMediaTypeForPath(file.path()).toString(); try { // TODO: this is where we would begin to work honoring /// Accept-Encoding:gzip, deflate, sdch evt.getResponse().sendFile(file.getAbsolutePath(), mediaTypeString); return; } catch (const Poco::FileNotFoundException& exc) { ofLogError("FileSystemRoute::handleRequest") << exc.displayText(); evt.getResponse().setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND); handleErrorResponse(evt); return; } catch (const Poco::OpenFileException& exc) { ofLogError("FileSystemRoute::handleRequest") << exc.displayText(); evt.getResponse().setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); handleErrorResponse(evt); return; } catch (const std::exception& exc) { ofLogError("FileSystemRoute::handleRequest") << "Unknown server error: " << exc.what(); evt.getResponse().setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); handleErrorResponse(evt); return; } }
void QmitkMITKIGTTrackingToolboxView::OnLoadTools() { //read in filename QString filename = QFileDialog::getOpenFileName(NULL,tr("Open Tool Storage"), "/", tr("Tool Storage Files (*.IGTToolStorage)")); if (filename.isNull()) return; //read tool storage from disk std::string errorMessage = ""; mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(GetDataStorage()); // try-catch block for exceptions try { this->ReplaceCurrentToolStorage(myDeserializer->Deserialize(filename.toStdString()),filename.toStdString()); } catch(mitk::IGTException) { std::string errormessage = "Error during deserializing. Problems with file,please check the file?"; QMessageBox::warning(NULL, "IGTPlayer: Error", errormessage.c_str()); return; } if(m_toolStorage->isEmpty()) { errorMessage = myDeserializer->GetErrorMessage(); MessageBox(errorMessage); return; } //update label Poco::Path myPath = Poco::Path(filename.toStdString()); //use this to seperate filename from path QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools from " + myPath.getFileName().c_str(); m_Controls->m_toolLabel->setText(toolLabel); //update tool preview m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); }
void FileSystemRouteHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { Poco::Path dataFolder(ofToDataPath("",true)); Poco::Path documentRoot(ofToDataPath(_parent.getSettings().getDocumentRoot(),true)); std::string dataFolderString = dataFolder.toString(); std::string documentRootString = documentRoot.toString(); // doc root validity check if(_parent.getSettings().getRequireDocumentRootInDataFolder() && (documentRootString.length() < dataFolderString.length() || documentRootString.substr(0,dataFolderString.length()) != dataFolderString)) { ofLogError("ServerDefaultRouteHandler::handleRequest") << "Document Root is not a sub directory of the data folder."; response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); _parent.handleRequest(request,response); return; } // check path Poco::URI uri(request.getURI()); std::string path = uri.getPath(); // just get the path // make paths absolute if(path.empty()) { path = "/"; } Poco::Path requestPath = documentRoot.append(path).makeAbsolute(); // add the default index if no filename is requested if(requestPath.getFileName().empty()) { requestPath.append(_parent.getSettings().getDefaultIndex()).makeAbsolute(); } std::string requestPathString = requestPath.toString(); // double check path safety (not needed?) if((requestPathString.length() < documentRootString.length() || requestPathString.substr(0,documentRootString.length()) != documentRootString)) { ofLogError("ServerDefaultRouteHandler::handleRequest") << "Requested document not inside DocumentFolder."; response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND); _parent.handleRequest(request,response); return; } ofFile file(requestPathString); // use it to parse file name parts try { // ofx::Media::MediaTypeMap mediaMap; // Poco::Net::MediaType mediaType = mediaMap.getMediaTypeForSuffix(file.getExtension()); std::string mediaTypeString = "application/octet-stream"; std::string ext = file.getExtension(); if(ext == "json") { mediaTypeString = "application/json"; } else if(ext == "html") { mediaTypeString = "text/html"; } else if(ext == "jpg" || ext == "jpeg") { mediaTypeString = "image/jpeg"; } else if(ext == "png") { mediaTypeString = "image/png"; } else if(ext == "js") { mediaTypeString = "application/javascript"; } else if(ext == "css") { mediaTypeString = "text/css"; } else if(ext == "xml") { mediaTypeString = "application/xml"; } else if(ext == "ico") { mediaTypeString = "image/x-icon"; } response.sendFile(file.getAbsolutePath(), mediaTypeString); // will throw exceptions return; } catch (const Poco::FileNotFoundException& ex) { ofLogError("ServerDefaultRouteHandler::handleRequest") << ex.displayText(); response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_NOT_FOUND); _parent.handleRequest(request,response); } catch (const Poco::OpenFileException& ex) { ofLogError("ServerDefaultRouteHandler::handleRequest") << ex.displayText(); response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); _parent.handleRequest(request,response); } catch (const exception& ex) { ofLogError("ServerDefaultRouteHandler::handleRequest") << "Unknown server error: " << ex.what(); response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR); _parent.handleRequest(request,response); } }