bool Line::intersect( float pickAngle, // The angle which makes the cone const Vec3f& v0, // One endpoint of the line segment const Vec3f& v1, // The other endpoint of the line segment Vec3f& intersection) const // The intersection point { Vec3f ptOnLine; Line inputLine(v0, v1); float distance; bool validIntersection = false; if(getClosestPoints(inputLine, ptOnLine, intersection)) { // check to make sure the intersection is within the line segment if((intersection - v0).dot(v1 - v0) < 0) { intersection = v0; } else if((intersection - v1).dot(v0 - v1) < 0) { intersection = v1; } distance = (ptOnLine - intersection).getLength(); if (pickAngle < 0.0) return (distance < -pickAngle); validIntersection = ((distance / (ptOnLine - getPosition()).getLength()) < pickAngle); } return validIntersection; }
// ----------------------------------------------------------------------------- int Action_NMRrst::ReadNmrRestraints( std::string const& rstfilename ) { BufferedLine infile; if (infile.OpenFileRead( rstfilename )) return 1; // Try to determine what kind of file. const char* ptr = infile.Line(); // Try to skip past any blank lines and comments while ( SkipChar( ptr ) ) ptr = infile.Line(); if (ptr == 0) { mprinterr("Error: Unexpected end of restraint file.\n"); return 1; } std::string inputLine( ptr ); infile.CloseFile(); // Re-open file if (infile.OpenFileRead( rstfilename )) return 1; int err = 0; if ( inputLine.compare(0, 7, "*HEADER")==0 || inputLine.compare(0, 6, "*TITLE")==0 || inputLine.compare(0, 6, "assign")==0 ) // XPLOR err = ReadXplor( infile ); else // Assume DIANA/Amber err = ReadAmber( infile ); infile.CloseFile(); if (err != 0) { mprinterr("Error: Could not parse restraint file.\n"); return 1; } return 0; }
bool InputWidget::eventFilter(QObject *watched, QEvent *event) { if (event->type() != QEvent::KeyPress) return false; QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); // keys from BufferView should be sent to (and focus) the input line BufferView *view = qobject_cast<BufferView *>(watched); if (view) { if (keyEvent->text().length() == 1 && !(keyEvent->modifiers() & (Qt::ControlModifier ^ Qt::AltModifier))) { // normal key press QChar c = keyEvent->text().at(0); if (c.isLetterOrNumber() || c.isSpace() || c.isPunct() || c.isSymbol()) { setFocus(); QCoreApplication::sendEvent(inputLine(), keyEvent); return true; } } return false; } else if (watched == ui.inputEdit) { if (keyEvent->matches(QKeySequence::Find)) { QAction *act = GraphicalUi::actionCollection()->action("ToggleSearchBar"); if (act) { act->toggle(); return true; } } return false; } return false; }
void File::loadFileCIF( const string filename , const int ID) { cerr<<"opening file into iofile\n"; ifstream file( filename.c_str() ); if ( !file ) { cerr << "[ERROR] Input file (" << filename << ") could not be opened!\n"; exit( 1 ); } // end if // cout<<"loadCIF\n"; const int MAX_BUFFER_SIZE = 10000; char buffer[ MAX_BUFFER_SIZE ]; string whatIS; Color color; clsRepository->currentModel = 0; undefineds.clear(); while ( true ) { file.getline( buffer, MAX_BUFFER_SIZE, '\n' ); //if ( file.eof() ) {cout<< "EOF\n"; break; } if ( !file ) { cerr << "[WARNING] Premature end of file.\n"; return; } // end if istringstream inputLine( buffer ); //cout << inputLine.str() << "\n"; inputLine >> whatIS; if ( !inputLine ) // linha vazia continue; if ( whatIS == "94" ) { parseLabelCIF( inputLine ); continue; } // SightLabel if ( whatIS == "B" ) { parseRectangleCIF( inputLine , ID); continue; } // Box if ( whatIS == "L" ) { parseLayerCIF( inputLine ); continue; } // Layer if ( whatIS == "W" ) { continue; } // Wire if ( whatIS == "C" ) { parseCallCIF( inputLine, ID ); continue; } // Call if ( whatIS == "R" ) { continue; } // Roundflash if ( whatIS == "P" ) { continue; } // Polygon if ( whatIS == "DS" ) { state = MODEL; parseModelCIF( inputLine ); continue; } // Define Subrotine if ( whatIS == "9" ) { parseModelName( inputLine ); continue;} // define model name if ( whatIS == "DF;" ) { state = FREE; continue; } // Define Finished if ( whatIS == "DD" ) { continue; } // Delete Subrotine if ( whatIS == "E;" || whatIS == "END;" || whatIS == "E" || whatIS == "END" ) { clsRepository->start(); return; }// End of CIF File if ( whatIS[0] == '(' ) continue; cerr << "[INFO] Ignoring line: " << inputLine.str() << "\n"; } // end while } // end function
int main(int argc, char* argv[]) { const std::string testKey = "abcdfgteqsdfrtedfsretkdpbdltesas"; Crypto28147SimpleReplacement crp(testKey); std::string encrypted; std::string decrypted; if (argc > 1) { if (0 == strcmp(argv[1], "-encr")) { std::cin >> std::noskipws; std::istream_iterator<char> it(std::cin); std::istream_iterator<char> end; std::string inputLine(it, end); crp.encrypt(inputLine, encrypted); std::cout << encrypted << std::endl; } else if (0 == strcmp(argv[1], "-decr"))
Item getStreamExtraction (std::string prompt, Item itemForTypeResolution, std::string itemName ) { do { std::istringstream inputLine( getLine(prompt) ); Item userInput; inputLine >> userInput; if ( inputLine.fail() ) { std::cout << "Input format error: please give an " << itemName << "." << std::endl; continue; } char junk; inputLine >> junk; if ( !inputLine.fail() ) { std::cout << "Input format error: please give ONLY an " << itemName << "." << std::endl; continue; } return userInput; } while ( true ); }
void InputHandle::start(){ sout << LogSystem::getLogString(LogSystem::Note, "System", "Welcome to RunCode Command Mode!"); loop: sout << ">"; this->sout.flush(); QString line = sin.readLine(); QStringList inputLine(line.split(QRegExp("\\s"), QString::SkipEmptyParts)); if(inputLine.size() == 0){ //sout << LogSystem::getLogString(LogSystem::Error, "System", "No command found."); goto loop; } QString cmd = inputLine.at(0); if(cmd == "quit" || cmd == "exit"){ sout << LogSystem::getLogString(LogSystem::Info, "System", "Quitting..."); //emit this->requestToExit(); return; }else if(cmd == "help"){ sout << LogSystem::getLogString(LogSystem::Info, "System", "Usage:"); sout << LogSystem::getLogString(LogSystem::Info, "System", "Can Use Command:"); sout << LogSystem::getLogString(LogSystem::Info, "System", "exit quit say"); goto loop; }else if(cmd == "say"){ for(auto i = inputLine.begin() + 1; i != inputLine.end(); i++){ sout << *i << " "; } sout << "\n"; goto loop; }else if(cmd == "output"){ //TODO: 之后完善, 组件全部移入MainController, 这个只做功能设置 }else{ sout << LogSystem::getLogString(LogSystem::Error, "System", QString("Unknown Command: %1").arg(cmd)); goto loop; } goto loop; }
InputWidget::InputWidget(QWidget *parent) : AbstractItemView(parent), _networkId(0) { ui.setupUi(this); connect(ui.ownNick, SIGNAL(activated(QString)), this, SLOT(changeNick(QString))); layout()->setAlignment(ui.ownNick, Qt::AlignBottom); layout()->setAlignment(ui.inputEdit, Qt::AlignBottom); layout()->setAlignment(ui.showStyleButton, Qt::AlignBottom); layout()->setAlignment(ui.styleFrame, Qt::AlignBottom); ui.styleFrame->setVisible(false); setFocusProxy(ui.inputEdit); ui.ownNick->setFocusProxy(ui.inputEdit); ui.ownNick->setSizeAdjustPolicy(QComboBox::AdjustToContents); ui.ownNick->installEventFilter(new MouseWheelFilter(this)); ui.inputEdit->installEventFilter(this); ui.inputEdit->setMinHeight(1); ui.inputEdit->setMaxHeight(5); ui.inputEdit->setMode(MultiLineEdit::MultiLine); ui.inputEdit->setPasteProtectionEnabled(true); ui.boldButton->setIcon(SmallIcon("format-text-bold")); ui.italicButton->setIcon(SmallIcon("format-text-italic")); ui.underlineButton->setIcon(SmallIcon("format-text-underline")); ui.textcolorButton->setIcon(SmallIcon("format-text-color")); ui.highlightcolorButton->setIcon(SmallIcon("format-fill-color")); ui.encryptionIconLabel->hide(); _colorMenu = new QMenu(); _colorFillMenu = new QMenu(); QStringList names; names << tr("White") << tr("Black") << tr("Dark blue") << tr("Dark green") << tr("Red") << tr("Dark red") << tr("Dark magenta") << tr("Orange") << tr("Yellow") << tr("Green") << tr("Dark cyan") << tr("Cyan") << tr("Blue") << tr("Magenta") << tr("Dark gray") << tr("Light gray"); QPixmap pix(16, 16); for (int i = 0; i < inputLine()->mircColorMap().count(); i++) { pix.fill(inputLine()->mircColorMap().values()[i]); _colorMenu->addAction(pix, names[i])->setData(inputLine()->mircColorMap().keys()[i]); _colorFillMenu->addAction(pix, names[i])->setData(inputLine()->mircColorMap().keys()[i]); } pix.fill(Qt::transparent); _colorMenu->addAction(pix, tr("Clear Color"))->setData(""); _colorFillMenu->addAction(pix, tr("Clear Color"))->setData(""); ui.textcolorButton->setMenu(_colorMenu); connect(_colorMenu, SIGNAL(triggered(QAction *)), this, SLOT(colorChosen(QAction *))); ui.highlightcolorButton->setMenu(_colorFillMenu); connect(_colorFillMenu, SIGNAL(triggered(QAction *)), this, SLOT(colorHighlightChosen(QAction *))); new TabCompleter(ui.inputEdit); UiStyleSettings fs("Fonts"); fs.notify("UseCustomInputWidgetFont", this, SLOT(setUseCustomFont(QVariant))); fs.notify("InputWidget", this, SLOT(setCustomFont(QVariant))); if (fs.value("UseCustomInputWidgetFont", false).toBool()) setCustomFont(fs.value("InputWidget", QFont())); UiSettings s("InputWidget"); #ifdef HAVE_KDE s.notify("EnableSpellCheck", this, SLOT(setEnableSpellCheck(QVariant))); setEnableSpellCheck(s.value("EnableSpellCheck", false)); #endif s.notify("EnableEmacsMode", this, SLOT(setEnableEmacsMode(QVariant))); setEnableEmacsMode(s.value("EnableEmacsMode", false)); s.notify("ShowNickSelector", this, SLOT(setShowNickSelector(QVariant))); setShowNickSelector(s.value("ShowNickSelector", true)); s.notify("ShowStyleButtons", this, SLOT(setShowStyleButtons(QVariant))); setShowStyleButtons(s.value("ShowStyleButtons", true)); s.notify("EnablePerChatHistory", this, SLOT(setEnablePerChatHistory(QVariant))); setEnablePerChatHistory(s.value("EnablePerChatHistory", false)); s.notify("MaxNumLines", this, SLOT(setMaxLines(QVariant))); setMaxLines(s.value("MaxNumLines", 5)); s.notify("EnableScrollBars", this, SLOT(setScrollBarsEnabled(QVariant))); setScrollBarsEnabled(s.value("EnableScrollBars", true)); s.notify("EnableLineWrap", this, SLOT(setLineWrapEnabled(QVariant))); setLineWrapEnabled(s.value("EnableLineWrap", false)); s.notify("EnableMultiLine", this, SLOT(setMultiLineEnabled(QVariant))); setMultiLineEnabled(s.value("EnableMultiLine", true)); ActionCollection *coll = QtUi::actionCollection(); Action *activateInputline = coll->add<Action>("FocusInputLine"); connect(activateInputline, SIGNAL(triggered()), SLOT(setFocus())); activateInputline->setText(tr("Focus Input Line")); activateInputline->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); connect(inputLine(), SIGNAL(textEntered(QString)), SLOT(onTextEntered(QString)), Qt::QueuedConnection); // make sure the line is already reset, bug #984 connect(inputLine(), SIGNAL(currentCharFormatChanged(QTextCharFormat)), this, SLOT(currentCharFormatChanged(QTextCharFormat))); }
void InputWidget::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) { BufferId currentBufferId = current.data(NetworkModel::BufferIdRole).value<BufferId>(); BufferId previousBufferId = previous.data(NetworkModel::BufferIdRole).value<BufferId>(); if (_perChatHistory) { //backup historyMap[previousBufferId].history = inputLine()->history(); historyMap[previousBufferId].tempHistory = inputLine()->tempHistory(); historyMap[previousBufferId].idx = inputLine()->idx(); historyMap[previousBufferId].inputLine = inputLine()->html(); //restore inputLine()->setHistory(historyMap[currentBufferId].history); inputLine()->setTempHistory(historyMap[currentBufferId].tempHistory); inputLine()->setIdx(historyMap[currentBufferId].idx); inputLine()->setHtml(historyMap[currentBufferId].inputLine); inputLine()->moveCursor(QTextCursor::End, QTextCursor::MoveAnchor); // FIXME this really should be in MultiLineEdit (and the const int on top removed) QTextBlockFormat format = inputLine()->textCursor().blockFormat(); format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents inputLine()->textCursor().setBlockFormat(format); } NetworkId networkId = current.data(NetworkModel::NetworkIdRole).value<NetworkId>(); if (networkId == _networkId) return; setNetwork(networkId); updateNickSelector(); updateEnabledState(); }
InputStream openFTPStream(ParsedURL *pu, URLFile *uf) { Str tmp; int status; char *user = NULL; char *pass = NULL; Str uname = NULL; Str pwd = NULL; int add_auth_cookie_flag = FALSE; char *realpathname = NULL; if (!pu->host) return NULL; if (pu->user == NULL && pu->pass == NULL) { if (find_auth_user_passwd(pu, NULL, &uname, &pwd, 0)) { if (uname) user = uname->ptr; if (pwd) pass = pwd->ptr; } } if (user) /* do nothing */ ; else if (pu->user) user = pu->user; else user = "******"; if (current_ftp.host) { if (!strcmp(current_ftp.host, pu->host) && current_ftp.port == pu->port && !strcmp(current_ftp.user, user)) { ftp_command(¤t_ftp, "NOOP", NULL, &status); if (status != 200) ftp_close(¤t_ftp); else goto ftp_read; } else ftp_quit(¤t_ftp); } if (pass) /* do nothing */ ; else if (pu->pass) pass = pu->pass; else if (pu->user) { pwd = NULL; find_auth_user_passwd(pu, NULL, &uname, &pwd, 0); if (pwd == NULL) { if (fmInitialized) { term_raw(); pwd = Strnew_charp(inputLine("Password: "******"Password: "******"Password: "******"anonymous"); #else tmp = Strnew_charp("anonymous"); #endif /* __MINGW32_VERSION */ Strcat_char(tmp, '@'); pass = tmp->ptr; } if (!current_ftp.host) { current_ftp.host = allocStr(pu->host, -1); current_ftp.port = pu->port; current_ftp.user = allocStr(user, -1); current_ftp.pass = allocStr(pass, -1); if (!ftp_login(¤t_ftp)) return NULL; } if (add_auth_cookie_flag) add_auth_user_passwd(pu, NULL, uname, pwd, 0); ftp_read: ftp_command(¤t_ftp, "TYPE", "I", &status); if (ftp_pasv(¤t_ftp) < 0) { ftp_quit(¤t_ftp); return NULL; } if (pu->file == NULL || *pu->file == '\0' || pu->file[strlen(pu->file) - 1] == '/') goto ftp_dir; realpathname = file_unquote(pu->file); if (*realpathname == '/' && *(realpathname + 1) == '~') realpathname++; /* Get file */ uf->modtime = ftp_modtime(¤t_ftp, realpathname); ftp_command(¤t_ftp, "RETR", realpathname, &status); if (status == 125 || status == 150) return newFileStream(current_ftp.data, (void (*)())closeFTPdata); ftp_dir: pu->scheme = SCM_FTPDIR; return NULL; }
int main(int argc, char* argv[]) { if (argc < 2) { std::cout << "Usage: SpeckleFitting xmlinputfile [outputdirectory]" << std::endl; return -1; } //Read the input file and get marker details XMLInputReader reader(argv[1]); //Get the transformation matrix related to the various views std::map<int, std::string> transforms = reader.getImagePlaneTransformations(); if (argc > 2) { if (std::string(argv[2]) == ".") { std::cout << "ISO Surfaces " << std::endl; std::string viewnames[] = { "", "aplax", "tch", "fch", "saxapex", "saxmid", "saxbase" }; for (int i = 1; i < 7; i++) { if (transforms.find(i) != transforms.end()) { printISOSurfaceGFX(reader.getImagePlaneTransformation(static_cast<MarkerTypes>(i)), viewnames[i]); } } std::cout << "Transformations " << std::endl; for (int i = 1; i < 7; i++) { if (transforms.find(i) != transforms.end()) { std::cout << viewnames[i] << "\t" << transforms[i] << std::endl; } } } } std::cout << "WORKLOAD:3" << std::endl; std::cout << "STEP TRANFORMATION completed" << std::endl; unsigned int numberOfFrames = reader.getNumberOfFrames(); //Create a LVMesh, let the cmgui context name be CMISS and create a LVmesh with numberOfFrames meshes LVHeartMesh mesh("CMISS", reader); mesh.fixWallLengths(); //Create a RV mesh that follows the user input and also ensure that the myocardial volume is conserved mesh.fixToMarkers(); std::cout << "STEP FIT completed" << std::endl; //Compute various strain measures StrainMeasures measure(mesh, reader); //Compute the measures for all long axis views, note the long axis information //for all the views may not be provided, even though the resulting mesh is 3D bool views[] = { true, true, true, false }; measure.setActiveViews(views); //If a directory is specified, output the mesh and strain data to that directory if (argc > 2) { if (std::string(argv[2]) == ".") { std::cout << "Heart\t" << mesh.getTransformation() << std::endl; std::vector<std::string> strains = measure.getSixteenSegmentStrains(); std::vector<std::string> speckleStrains = measure.getSpeckleStrains(true); //std::vector<std::string> fibreStrains = measure.getSixteenSegmentFibreStrains(0.0); measure.Print("strain.csv", strains); measure.Print("speckle.csv", speckleStrains); mesh.outputMesh("test", argv[2]); } } std::cout << "STEP MEASUREMENT completed" << std::endl; //If DICOM filename is not provided create the files in the given output directory if (reader.getDICOMFile() == "") { //Output mesh, strains, transformation in an xml file boost::filesystem::path dir(reader.getOutputDirectory()); //Create a file name with modelname in the specified directory std::string filename = reader.getModelName() + ".xml"; boost::filesystem::path qfilename = dir / filename; //Output the result in an xml formatted form std::ofstream file(qfilename.string().c_str(), std::ios_base::binary); std::string output(XMLSerialiser::buildXMLString(mesh, measure, reader.getDuration(), &transforms)); boost::replace_all(output, "</CMISSCAPIO>", ""); boost::trim(output); file << output << std::endl; file << "<SPECKLETRACKINGOUTPUT>" << std::endl; tinyxml2::XMLDocument* XMLdoc = new tinyxml2::XMLDocument(); if (XMLdoc->LoadFile(argv[1]) == tinyxml2::XML_SUCCESS) { tinyxml2::XMLPrinter printer; XMLdoc->Print(&printer); std::string inputLine(printer.CStr()); boost::replace_all(inputLine, "</SEGMENTATION>", ""); std::string tag("<SEGMENTATION>"); int index = inputLine.find(tag); std::string inputT = inputLine.substr(index + tag.length()); boost::trim(inputT); file << inputT << std::endl; } file << "</SPECKLETRACKINGOUTPUT>" << std::endl; file << "</CMISSCAPIO>"; file.close(); } else { //If a dicom file is specified - store the data in the dicom file (in the overlay tag) gdcm::Reader gdcmReader; //Read the dicom file std::string dicomFile(reader.getDICOMFile()); gdcmReader.SetFileName(dicomFile.c_str()); if (!gdcmReader.Read()) { std::stringstream msg; msg << "Unable to read file " << dicomFile; throw new BundleToDICOMException(msg.str()); } gdcm::File &file = gdcmReader.GetFile(); gdcm::DataSet &ds = file.GetDataSet(); std::string output(XMLSerialiser::buildXMLString(mesh, measure, reader.getDuration(), &transforms)); boost::replace_all(output, "</CMISSCAPIO>", ""); boost::trim(output); std::ostringstream sfx; sfx << output << std::endl; sfx << "<SPECKLETRACKINGOUTPUT>" << std::endl; tinyxml2::XMLDocument* XMLdoc = new tinyxml2::XMLDocument(); if (XMLdoc->LoadFile(argv[1]) == tinyxml2::XML_SUCCESS) { tinyxml2::XMLPrinter printer; XMLdoc->Print(&printer); std::string inputLine(printer.CStr()); std::string tag("<SEGMENTATION"); int index = inputLine.find(tag); std::string inputT = inputLine.substr(index); boost::trim(inputT); sfx << inputT << std::endl; } sfx << "</SPECKLETRACKINGOUTPUT>" << std::endl; sfx << "</CMISSCAPIO>"; //Compress the string.. wado seems to have a trouble with ascii data boost::iostreams::filtering_streambuf<boost::iostreams::input> in; in.push(boost::iostreams::gzip_compressor()); std::istringstream uncompressed_string(sfx.str()); in.push(uncompressed_string); std::ostringstream compressed_string; boost::iostreams::copy(in, compressed_string); std::string tagValue = compressed_string.str(); gdcm::Tag oytag(0x6000, 0x3000); //Overlay data tag ds.Remove(oytag); //Remove the data associated with the tag else it doesnt get updated gdcm::DataElement de; de.SetTag(oytag); de.SetVR(gdcm::VR::OB); de.SetByteValue(tagValue.c_str(), tagValue.length()); ds.Insert(de); //Write the file gdcm::Writer writer; writer.SetFile(file); writer.SetFileName(dicomFile.c_str()); writer.Write(); } std::cout << argv[0] << ":completed" << std::endl; return 0; }