void AdvancedRenameManager::parseFiles(ParseSettings& _settings) { if (!d->widget) { if (!(_settings.parseString.isEmpty())) { parseFiles(_settings.parseString, _settings); } } else { parseFiles(d->widget->parseString(), _settings); } }
void AdvancedRenameManager::parseFiles() { if (!d->widget) { return; } parseFiles(d->widget->parseString()); }
/// The '|' in the input denotes the cursor position. DoxygenTestCase(const QByteArray &original, const QByteArray &expected, CppTools::CommentsSettings *settings = 0) { QVERIFY(succeededSoFar()); TestDocument testDocument("file.cpp", original, '|'); QVERIFY(testDocument.hasCursorMarker()); testDocument.m_source.remove(testDocument.m_cursorPosition, 1); QVERIFY(testDocument.writeToDisk()); // Update Code Model QVERIFY(parseFiles(testDocument.filePath())); // Open Editor QVERIFY(openCppEditor(testDocument.filePath(), &testDocument.m_editor, &testDocument.m_editorWidget)); closeEditorAtEndOfTestCase(testDocument.m_editor); if (settings) { auto *cts = CppTools::CppToolsSettings::instance(); oldSettings.reset(new CppTools::CommentsSettings(cts->commentsSettings())); cts->setCommentsSettings(*settings); } // We want to test documents that start with a comment. By default, the // editor will fold the very first comment it encounters, assuming // it is a license header. Currently unfoldAll() does not work as // expected (some blocks are still hidden in some test cases, so the // cursor movements are not as expected). For the time being, we just // prepend a declaration before the initial test comment. // testDocument.m_editorWidget->unfoldAll(); testDocument.m_editor->setCursorPosition(testDocument.m_cursorPosition); waitForRehighlightedSemanticDocument(testDocument.m_editorWidget); // Send 'ENTER' key press QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); QCoreApplication::sendEvent(testDocument.m_editorWidget, &event); const QByteArray result = testDocument.m_editorWidget->document()->toPlainText().toUtf8(); QCOMPARE(QLatin1String(result), QLatin1String(expected)); testDocument.m_editorWidget->undo(); const QString contentsAfterUndo = testDocument.m_editorWidget->document()->toPlainText(); QCOMPARE(contentsAfterUndo, testDocument.m_source); }
void parseInput() { // atexit(exitDoxygen); /************************************************************************** * Make sure the output directory exists **************************************************************************/ QString string; QCString outputDirectory = "C:\\Projects\\docs"; if (outputDirectory.isEmpty()) { outputDirectory=QDir::currentDirPath().utf8(); } else { QDir dir(outputDirectory); if (!dir.exists()) { dir.setPath(QDir::currentDirPath()); if (!dir.mkdir(outputDirectory)) { // cleanUpDoxygen(); exit(1); } else { } dir.cd(outputDirectory); } outputDirectory=dir.absPath().utf8(); } searchInputFiles(); Entry *root=new Entry; EntryNav *rootNav = new EntryNav(0,root); rootNav->setEntry(root); parseFiles(root, rootNav); delete rootNav; }
// getParams void getParams(int argc, char** argv) { char* outFile = NULL, *inFile = NULL, *dupFile = NULL; // parse argv for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], HELP)) usage(); else if (i < argc - 1) { if (!strcmp(argv[i], OUTFILE)) outFile = argv[++i]; else if (!strcmp(argv[i], INFILE)) inFile = argv[++i]; else if (!strcmp(argv[i], DUPFILE)) dupFile = argv[++i]; } else usage(); } if (outFile == NULL || inFile == NULL) usage(); FILE* out = NULL, *dup = NULL; openFiles(outFile, &out, dupFile, &dup); parseFiles(inFile); int leaf = 0, rem = 0; for (int i = 0; i < CHILD; i++) printTrie(out, dup, root->child[i], 0, &leaf, &rem); printf("Leaf reads: %10d\n", leaf); if (dup != NULL) printf("Removed reads:%10d\n", rem); if (fclose(out) || (dup != NULL && fclose(dup))) exit(error("", ERRCLOSE)); }
void McEnvironment::parseFile(const std::string& filename) { vector<string> input; input.push_back(filename); parseFiles(input); }
static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags, const char *buildRoot, int recursing) { int parsePart = PART_PREAMBLE; int initialPackage = 1; rpmSpec spec; /* Set up a new Spec structure with no packages. */ spec = newSpec(); spec->specFile = rpmGetPath(specFile, NULL); pushOFI(spec, spec->specFile); /* If buildRoot not specified, use default %{buildroot} */ if (buildRoot) { spec->buildRoot = xstrdup(buildRoot); } else { spec->buildRoot = rpmGetPath("%{?buildroot:%{buildroot}}", NULL); } addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC); addMacro(NULL, "_licensedir", NULL, "%{_defaultlicensedir}", RMIL_SPEC); spec->recursing = recursing; spec->flags = flags; /* All the parse*() functions expect to have a line pre-read */ /* in the spec's line buffer. Except for parsePreamble(), */ /* which handles the initial entry into a spec file. */ while (parsePart != PART_NONE) { int goterror = 0; switch (parsePart) { case PART_ERROR: /* fallthrough */ default: goterror = 1; break; case PART_PREAMBLE: parsePart = parsePreamble(spec, initialPackage); initialPackage = 0; break; case PART_PREP: parsePart = parsePrep(spec); break; case PART_BUILD: case PART_INSTALL: case PART_CHECK: case PART_CLEAN: parsePart = parseBuildInstallClean(spec, parsePart); break; case PART_CHANGELOG: parsePart = parseChangelog(spec); break; case PART_DESCRIPTION: parsePart = parseDescription(spec); break; case PART_PRE: case PART_POST: case PART_PREUN: case PART_POSTUN: case PART_PRETRANS: case PART_POSTTRANS: case PART_VERIFYSCRIPT: case PART_TRIGGERPREIN: case PART_TRIGGERIN: case PART_TRIGGERUN: case PART_TRIGGERPOSTUN: case PART_FILETRIGGERIN: case PART_FILETRIGGERUN: case PART_FILETRIGGERPOSTUN: case PART_TRANSFILETRIGGERIN: case PART_TRANSFILETRIGGERUN: case PART_TRANSFILETRIGGERPOSTUN: parsePart = parseScript(spec, parsePart); break; case PART_FILES: parsePart = parseFiles(spec); break; case PART_POLICIES: parsePart = parsePolicies(spec); break; case PART_NONE: /* XXX avoid gcc whining */ case PART_LAST: case PART_BUILDARCHITECTURES: break; } if (goterror || parsePart >= PART_LAST) { goto errxit; } if (parsePart == PART_BUILDARCHITECTURES) { int index; int x; closeSpec(spec); spec->BASpecs = xcalloc(spec->BACount, sizeof(*spec->BASpecs)); index = 0; if (spec->BANames != NULL) for (x = 0; x < spec->BACount; x++) { /* Skip if not arch is not compatible. */ if (!rpmMachineScore(RPM_MACHTABLE_BUILDARCH, spec->BANames[x])) continue; addMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC); spec->BASpecs[index] = parseSpec(specFile, flags, buildRoot, 1); if (spec->BASpecs[index] == NULL) { spec->BACount = index; goto errxit; } delMacro(NULL, "_target_cpu"); index++; } spec->BACount = index; if (! index) { rpmlog(RPMLOG_ERR, _("No compatible architectures found for build\n")); goto errxit; } /* * Return the 1st child's fully parsed Spec structure. * The restart of the parse when encountering BuildArch * causes problems for "rpm -q --specfile". This is * still a hack because there may be more than 1 arch * specified (unlikely but possible.) There's also the * further problem that the macro context, particularly * %{_target_cpu}, disagrees with the info in the header. */ if (spec->BACount >= 1) { rpmSpec nspec = spec->BASpecs[0]; spec->BASpecs = _free(spec->BASpecs); rpmSpecFree(spec); spec = nspec; } goto exit; } } if (spec->clean == NULL) { char *body = rpmExpand("%{?buildroot: %{__rm} -rf %{buildroot}}", NULL); spec->clean = newStringBuf(); appendLineStringBuf(spec->clean, body); free(body); } /* Check for description in each package */ for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) { if (!headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) { rpmlog(RPMLOG_ERR, _("Package has no %%description: %s\n"), headerGetString(pkg->header, RPMTAG_NAME)); goto errxit; } } /* Add arch, os and platform, self-provides etc for each package */ addTargets(spec->packages); /* Check for encoding in each package unless disabled */ if (!(spec->flags & RPMSPEC_NOUTF8)) { int badenc = 0; for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) { if (checkForEncoding(pkg->header, 0) != RPMRC_OK) { badenc = 1; } } if (badenc) goto errxit; } closeSpec(spec); exit: /* Assemble source header from parsed components */ initSourceHeader(spec); return spec; errxit: rpmSpecFree(spec); return NULL; }
bool GRTags::exec(int argc, char **argv) { option options[] = { { "help", no_argument, 0, 'h' }, { "version", no_argument, 0, 'V' }, { "verbose", no_argument, 0, 'v' }, { "exclude", required_argument, 0, 'e' }, { "references", required_argument, 0, 'R' }, { "list-symbols", optional_argument, 0, 'S' }, { "find-symbols", required_argument, 0, 'F' }, { "all-symbols", required_argument, 0, 'l' }, { "show-context", no_argument, 0, 'C' }, { "find-file", optional_argument, 0, 'P' }, { "dir", required_argument, 0, 'd' }, { "dump", no_argument, 0, 's' }, { "create", no_argument, 0, 'c' }, { "silent", no_argument, 0, 'i' }, { "update", no_argument, 0, 'u' }, { "match-icase", no_argument, 0, 'I' }, { "find-file-prefer-exact", no_argument, 0, 'A' }, { "absolute-path", no_argument, 0, 'K' }, { 0, 0, 0, 0 } }; int logLevel = 0; Path dir; int c; const ByteArray shortOptions = RTags::shortOptions(options); ByteArray pattern; while ((c = getopt_long(argc, argv, shortOptions.constData(), options, 0)) != -1) { switch (c) { case '?': return false; case 'h': printf("grtags [...options]\n" " --help|-h Display this help\n" " --version|-V Display version information\n" " --verbose|-v Increase verbosity\n" " --silent|-i Be silent\n" " --exclude|-e [filter] Exclude this pattern (e.g. .git, *.cpp)\n" " --references|-R [arg] Show references to arg\n" " --list-symbols|-S [arg] List symbols matching arg\n" " --all-symbols|-l [arg] List symbols and references matching arg\n" " --find-symbols|-F [arg] Find symbols matching arg\n" " --context|-C Show context\n" " --dump|-s Dump db contents\n" " --create|-c Force creation of new DB\n" " --update|-u Update existing DB (noop with no DB)\n" " --find-file|-P [arg] List files matching optional arg\n" " --match-icase|-I Match paths case insensitively\n" " --find-file-prefer-exact|-A Use to make --find-file prefer exact matches over partial\n" " --absolute-path|-K Print files with absolute path.\n" " --dir|-d [arg] Parse this directory (default .)\n"); return true; case 'V': printf("GRTags version 0.2\n"); return true; case 'C': mKeyFlags |= Location::ShowContext; break; case 'A': mFlags |= PreferExact; break; case 'I': mFlags |= MatchCaseInsensitive; break; case 'K': mFlags |= AbsolutePath; break; case 'P': mMode = Paths; if (optarg) { pattern = optarg; } else if (optind < argc && *argv[optind] != '-') { pattern = argv[optind++]; } break; case 'R': mMode = FindReferences; pattern = optarg; break; case 'F': mMode = FindSymbols; pattern = optarg; break; case 'l': mMode = FindAll; pattern = optarg; break; case 'S': mMode = ListSymbols; if (optarg) { pattern = optarg; } else if (optind < argc && *argv[optind] != '-') { pattern = argv[optind++]; } break; case 'c': mMode = Create; break; case 'u': mMode = Update; break; case 'e': mFilters.append(optarg); break; case 'v': if (logLevel >= 0) ++logLevel; break; case 'i': logLevel = -1; break; case 's': mMode = Dump; break; case 'd': dir = optarg; if (!dir.isDir()) { fprintf(stderr, "%s is not a valid directory\n", optarg); return false; } break; } } if (dir.isEmpty()) { Path p = Path::pwd(); while (!p.isEmpty()) { const Path db = p + "/.gr"; if (db.isDir()) { dir = p; break; } p = p.parentDir(); } if (dir.isEmpty()) { if (mMode == Detect) mMode = Create; if (mMode == Create) dir = Path::pwd(); } } if (dir.isEmpty()) { warning() << "Can't find database"; return false; } initLogging(logLevel, Path(), 0); if (!load(dir + "/.gr")) return false; switch (mMode) { case Dump: dump(); return true; case Update: case Create: dir.visit(&GRTags::visit, this); if (parseFiles()) return save(); return true; case Paths: paths(pattern); break; case FindReferences: case FindAll: case FindSymbols: findSymbols(pattern); break; case ListSymbols: listSymbols(pattern); break; case Detect: break; } return false; }
int parseSpec(rpmts ts, const char *specFile, const char *rootDir, const char *buildRoot, int recursing, const char *passPhrase, const char *cookie, int anyarch, int force) { rpmParseState parsePart = PART_PREAMBLE; int initialPackage = 1; Package pkg; rpmSpec spec; /* Set up a new Spec structure with no packages. */ spec = newSpec(); spec->specFile = rpmGetPath(specFile, NULL); spec->fileStack = newOpenFileInfo(); spec->fileStack->fileName = xstrdup(spec->specFile); /* If buildRoot not specified, use default %{buildroot} */ if (buildRoot) { spec->buildRoot = xstrdup(buildRoot); } else { spec->buildRoot = rpmGetPath("%{?buildroot:%{buildroot}}", NULL); } addMacro(NULL, "_docdir", NULL, "%{_defaultdocdir}", RMIL_SPEC); spec->recursing = recursing; spec->anyarch = anyarch; spec->force = force; if (rootDir) spec->rootDir = xstrdup(rootDir); if (passPhrase) spec->passPhrase = xstrdup(passPhrase); if (cookie) spec->cookie = xstrdup(cookie); spec->timeCheck = rpmExpandNumeric("%{_timecheck}"); /* All the parse*() functions expect to have a line pre-read */ /* in the spec's line buffer. Except for parsePreamble(), */ /* which handles the initial entry into a spec file. */ while (parsePart != PART_NONE) { int goterror = 0; switch (parsePart) { /* XXX Trap unexpected RPMRC_FAIL returns for now */ case RPMRC_FAIL: rpmlog(RPMLOG_ERR, "FIXME: got RPMRC_FAIL from spec parse\n"); abort(); case PART_ERROR: /* fallthrough */ default: goterror = 1; break; case PART_PREAMBLE: parsePart = parsePreamble(spec, initialPackage); initialPackage = 0; break; case PART_PREP: parsePart = parsePrep(spec); break; case PART_BUILD: case PART_INSTALL: case PART_CHECK: case PART_CLEAN: parsePart = parseBuildInstallClean(spec, parsePart); break; case PART_CHANGELOG: parsePart = parseChangelog(spec); break; case PART_DESCRIPTION: parsePart = parseDescription(spec); break; case PART_PRE: case PART_POST: case PART_PREUN: case PART_POSTUN: case PART_PRETRANS: case PART_POSTTRANS: case PART_VERIFYSCRIPT: case PART_TRIGGERPREIN: case PART_TRIGGERIN: case PART_TRIGGERUN: case PART_TRIGGERPOSTUN: parsePart = parseScript(spec, parsePart); break; case PART_FILES: parsePart = parseFiles(spec); break; case PART_NONE: /* XXX avoid gcc whining */ case PART_LAST: case PART_BUILDARCHITECTURES: break; } if (goterror || parsePart >= PART_LAST) { goto errxit; } if (parsePart == PART_BUILDARCHITECTURES) { int index; int x; closeSpec(spec); spec->BASpecs = xcalloc(spec->BACount, sizeof(*spec->BASpecs)); index = 0; if (spec->BANames != NULL) for (x = 0; x < spec->BACount; x++) { /* Skip if not arch is not compatible. */ if (!rpmMachineScore(RPM_MACHTABLE_BUILDARCH, spec->BANames[x])) continue; addMacro(NULL, "_target_cpu", NULL, spec->BANames[x], RMIL_RPMRC); spec->BASpecs[index] = NULL; if (parseSpec(ts, specFile, spec->rootDir, buildRoot, 1, passPhrase, cookie, anyarch, force) || (spec->BASpecs[index] = rpmtsSetSpec(ts, NULL)) == NULL) { spec->BACount = index; goto errxit; } delMacro(NULL, "_target_cpu"); index++; } spec->BACount = index; if (! index) { rpmlog(RPMLOG_ERR, _("No compatible architectures found for build\n")); goto errxit; } /* * Return the 1st child's fully parsed Spec structure. * The restart of the parse when encountering BuildArch * causes problems for "rpm -q --specfile". This is * still a hack because there may be more than 1 arch * specified (unlikely but possible.) There's also the * further problem that the macro context, particularly * %{_target_cpu}, disagrees with the info in the header. */ if (spec->BACount >= 1) { rpmSpec nspec = spec->BASpecs[0]; spec->BASpecs = _free(spec->BASpecs); spec = freeSpec(spec); spec = nspec; } (void) rpmtsSetSpec(ts, spec); return 0; } } if (spec->clean == NULL) { char *body = rpmExpand("%{?buildroot: %{__rm} -rf %{buildroot}}", NULL); spec->clean = newStringBuf(); appendLineStringBuf(spec->clean, body); free(body); } /* Check for description in each package and add arch and os */ { char *platform = rpmExpand("%{_target_platform}", NULL); char *arch = rpmExpand("%{_target_cpu}", NULL); char *os = rpmExpand("%{_target_os}", NULL); for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) { if (!headerIsEntry(pkg->header, RPMTAG_DESCRIPTION)) { rpmlog(RPMLOG_ERR, _("Package has no %%description: %s\n"), headerGetString(pkg->header, RPMTAG_NAME)); goto errxit; } headerPutString(pkg->header, RPMTAG_OS, os); /* noarch subpackages already have arch set here, leave it alone */ if (!headerIsEntry(pkg->header, RPMTAG_ARCH)) { headerPutString(pkg->header, RPMTAG_ARCH, arch); } headerPutString(pkg->header, RPMTAG_PLATFORM, platform); pkg->ds = rpmdsThis(pkg->header, RPMTAG_REQUIRENAME, RPMSENSE_EQUAL); } platform = _free(platform); arch = _free(arch); os = _free(os); } closeSpec(spec); (void) rpmtsSetSpec(ts, spec); return 0; errxit: spec = freeSpec(spec); return PART_ERROR; }
/** * Program entry-point. * */ int main(int argc, char **argv) { // parse arguments while (true) { int index = -1; getopt_long(argc, argv, "", options, &index); if (index == -1) { if (argc != optind + 2) { usage(); return 1; } input_file = argv[optind++]; if (access(input_file, R_OK)) { fprintf(stderr, "Error: input file not readable: %s\n", input_file); return 2; } output_file = argv[optind++]; if (access(output_file, W_OK) && errno == EACCES) { fprintf(stderr, "Error: output file not writable: %s\n", output_file); return 2; } break; } switch (index) { case OPTION_WIDTH: sample_width = atoi(optarg); break; case OPTION_HEIGHT: sample_height = atoi(optarg); break; case OPTION_COUNT: sample_count = atoi(optarg); break; case OPTION_ROTATE_STDDEV_X: rotate_stddev_x = atof(optarg) / 180.0 * M_PI; break; case OPTION_ROTATE_STDDEV_Y: rotate_stddev_y = atof(optarg) / 180.0 * M_PI; break; case OPTION_ROTATE_STDDEV_Z: rotate_stddev_z = atof(optarg) / 180.0 * M_PI; break; case OPTION_LUMINOSITY_STDDEV: luminosity_stddev = atof(optarg); break; case OPTION_BACKGROUNDS: backgrounds_file = optarg; if (access(backgrounds_file, R_OK)) { fprintf(stderr, "Error: backgrounds file not readable: %s\n", backgrounds_file); return 2; } break; default: usage(); return 1; } } // read input files std::vector<std::string> samples; if (!parseFiles(input_file, samples)) { fprintf(stderr, "Error: cannot parse file listing: %s\n", input_file); return 2; } // read background files std::vector<std::string> backgrounds; if (backgrounds_file != NULL && !parseFiles(backgrounds_file, backgrounds)) { fprintf(stderr, "Error: cannot parse file listing: %s\n", backgrounds_file); return 2; } // create output file FILE *fp = fopen(output_file, "wb"); if (fp == NULL) { fprintf(stderr, "Error: cannot open output file for writing: %s\n", output_file); return 2; } icvWriteVecHeader(fp, sample_count, sample_width, sample_height); // generate distortions std::default_random_engine generator(time(NULL)); std::normal_distribution<double> xdist(0.0, rotate_stddev_x / 3.0); std::normal_distribution<double> ydist(0.0, rotate_stddev_y / 3.0); std::normal_distribution<double> zdist(0.0, rotate_stddev_z / 3.0); std::normal_distribution<double> ldist(0.0, luminosity_stddev / 3.0); cv::Mat el = cv::getStructuringElement(cv::MORPH_ELLIPSE, cv::Size(5, 5)); int variations = MAX(1, (int)floor((double)sample_count / (double)samples.size())); int idx = 0; int i = 0; while (i < sample_count) { // suffle the input lists if (idx % samples.size() == 0) { std::shuffle(samples.begin(), samples.end(), generator); std::shuffle(backgrounds.begin(), backgrounds.end(), generator); } // read sample image auto const &sample_file(samples[idx % samples.size()]); cv::Mat sample = cv::imread(sample_file); double sampleRatio = (double)sample.cols / (double)sample.rows; double outputRatio = (double)sample_width / (double)sample_height; // normalize sample cv::Mat greySample = sample; double min, max; if (sample.channels() != 1) { cv::cvtColor(sample, greySample, cv::COLOR_RGB2GRAY); } cv::minMaxIdx(greySample, &min, &max); greySample -= min; greySample /= (max - min) / 255.0; // generate mask cv::Mat mask(cv::Mat::ones(greySample.rows, greySample.cols, greySample.type())); // enlarge canvas to fit output ratio cv::Mat resizedSample, resizedMask; if (backgrounds.size() > 0 && sampleRatio < outputRatio) { int width = (int)((double)greySample.rows * outputRatio); cv::Rect area( (width - greySample.cols) / 2, 0, greySample.cols, greySample.rows ); resizedSample = cv::Mat::zeros(greySample.rows, width, greySample.type()); resizedMask = cv::Mat::zeros(greySample.rows, width, greySample.type()); greySample.copyTo(resizedSample(area)); mask.copyTo(resizedMask(area)); } else if (backgrounds.size() > 0 && sampleRatio > outputRatio) { int height = (int)((double)greySample.cols / outputRatio); cv::Rect area( 0, (height - greySample.rows) / 2, greySample.cols, greySample.rows ); resizedSample = cv::Mat::zeros(height, greySample.cols, greySample.type()); resizedMask = cv::Mat::zeros(height, greySample.cols, greySample.type()); greySample.copyTo(resizedSample(area)); mask.copyTo(resizedMask(area)); } else { resizedSample = greySample; resizedMask = mask; } // apply distortions cv::Mat target(resizedSample.rows, resizedSample.cols, resizedSample.type()); cv::Mat targetMask(resizedSample.rows, resizedSample.cols, resizedSample.type()); double halfWidth = resizedSample.cols / 2.0; double halfHeight = resizedSample.rows / 2.0; cv::Mat rotationVector(3, 1, CV_64FC1); cv::Mat rotation4(cv::Mat::eye(4, 4, CV_64FC1)); cv::Mat translate4(cv::Mat::eye(4, 4, CV_64FC1)); cv::Mat translate3(cv::Mat::eye(3, 3, CV_64FC1)); cv::Mat scale3(cv::Mat::eye(3, 3, CV_64FC1)); int dx = (resizedSample.cols - greySample.cols) / 2; int dy = (resizedSample.rows - greySample.rows) / 2; cv::Point2f points1[4] = { cv::Point2f(dx, dy), cv::Point2f(dx, greySample.rows), cv::Point2f(greySample.cols, greySample.rows), cv::Point2f(greySample.cols, dy) }; cv::Point2f points2[4]; translate4.at<double>(0, 3) = -halfWidth; translate4.at<double>(1, 3) = -halfHeight; for (int k = 0; k < variations; k++) { double rx = k > 0 && rotate_stddev_x > 0.0 ? xdist(generator) : 0.0; double ry = k > 0 && rotate_stddev_y > 0.0 ? ydist(generator) : 0.0; double rz = k > 0 && rotate_stddev_z > 0.0 ? zdist(generator) : 0.0; double rl = k > 0 && luminosity_stddev > 0.0 ? ldist(generator) : 0.0; // compute rotation in 3d rotationVector.at<double>(0) = rx; rotationVector.at<double>(1) = ry; rotationVector.at<double>(2) = rz; cv::Rodrigues(rotationVector, cv::Mat(rotation4, cv::Rect(0, 0, 3, 3))); // compute transformation in 3d cv::Mat transform4(rotation4 * translate4); double minx = DBL_MAX, miny = DBL_MAX; double maxx = DBL_MIN, maxy = DBL_MIN; for (int j = 0; j < 4; j++) { cv::Mat point(4, 1, CV_64FC1); point.at<double>(0) = points1[j].x; point.at<double>(1) = points1[j].y; point.at<double>(2) = 0.0; point.at<double>(3) = 1.0; point = transform4 * point; points2[j].x = point.at<double>(0); points2[j].y = point.at<double>(1); if (points2[j].x < minx) { minx = points2[j].x; } if (points2[j].x > maxx) { maxx = points2[j].x; } if (points2[j].y < miny) { miny = points2[j].y; } if (points2[j].y > maxy) { maxy = points2[j].y; } } // compute transformation in 2d cv::Mat projection3(cv::getPerspectiveTransform(points1, points2)); double scalex = (resizedSample.cols - dx) / (maxx - minx); double scaley = (resizedSample.rows - dy) / (maxy - miny); translate3.at<double>(0, 2) = halfWidth; translate3.at<double>(1, 2) = halfHeight; scale3.at<double>(0, 0) = scalex; //MIN(scalex, scaley); scale3.at<double>(1, 1) = scaley; //MIN(scalex, scaley); // transform sample and mask in 2d cv::Mat transform3(translate3 * scale3 * projection3); cv::warpPerspective(resizedSample, target, transform3, target.size()); cv::warpPerspective(resizedMask, targetMask, transform3, targetMask.size()); // apply luminosity change if (rl != 0.0) { rl += 1.0; target *= rl; } // read background image cv::Mat greyBackground; if (backgrounds.size() > 0) { auto const &background_file(backgrounds[i % backgrounds.size()]); cv::Mat background = cv::imread(background_file); // normalize background image if (background.channels() != 1) { cv::cvtColor(background, greyBackground, cv::COLOR_RGB2GRAY); } else { greyBackground = background; } cv::minMaxIdx(greyBackground, &min, &max); greyBackground -= min; greyBackground /= (max - min) / 255.0; // reshape background to fit output ratio double backgroundRatio = (double)greyBackground.cols / (double)greyBackground.rows; cv::Mat tmp; if (backgroundRatio < outputRatio) { int height = (int)((double)greyBackground.cols / outputRatio); std::uniform_int_distribution<int> hdist(0, greyBackground.rows - height); tmp = greyBackground( cv::Rect( 0, hdist(generator), greyBackground.cols, height ) ); } else if (backgroundRatio > outputRatio) { int width = (int)((double)greyBackground.rows * outputRatio); std::uniform_int_distribution<int> wdist(0, greyBackground.cols - width); tmp = greyBackground( cv::Rect( wdist(generator), 0, width, greyBackground.rows ) ); } else { tmp = greyBackground; } cv::resize(tmp, greyBackground, resizedSample.size(), 0, 0, cv::INTER_CUBIC); } else { // random noise background greyBackground = cv::Mat(target.rows, target.cols, CV_8UC1); cv::randn(greyBackground, 255.0 / 2, 255.0 / 2 / 3); cv::GaussianBlur(greyBackground, greyBackground, cv::Size(5, 5), 10); } // blend background cv::Mat sampleMask, backgroundMask, tmp; cv::threshold(targetMask, sampleMask, 0.1, 255.0, cv::THRESH_BINARY); cv::erode(sampleMask, tmp, el); cv::blur(tmp, sampleMask, cv::Size(5, 5)); cv::threshold(targetMask, backgroundMask, 0.1, 255.0, cv::THRESH_BINARY_INV); cv::dilate(backgroundMask, tmp, el); cv::blur(tmp, backgroundMask, cv::Size(5, 5)); cv::multiply(target, sampleMask, target, 1.0 / 255.0); cv::multiply(greyBackground, backgroundMask, greyBackground, 1.0 / 255.0); target += greyBackground; // cv::namedWindow("preview", cv::WINDOW_NORMAL); // cv::imshow("preview", target); // while ((cv::waitKey(0) & 0xff) != '\n'); // cv::namedWindow("preview", cv::WINDOW_NORMAL); // cv::imshow("preview", greyBackground); // while ((cv::waitKey(0) & 0xff) != '\n'); // sample resize cv::Mat finalSample; cv::resize(target, finalSample, cv::Size(sample_width, sample_height), 0, 0, cv::INTER_CUBIC); // cv::namedWindow("preview", cv::WINDOW_NORMAL); // cv::imshow("preview", finalSample); // while ((cv::waitKey(0) & 0xff) != '\n'); // sample save CvMat targetfinal_ = finalSample; icvWriteVecSample(fp, &targetfinal_); i++; if (i % 100 == 0) { fprintf(stdout, "processed %d images, %d samples\n", idx, i); fflush(stdout); } } idx++; } // close output file fclose(fp); return 0; }
void ModelsimGenerator::parseFiles( QSharedPointer<Component> component, const QString& viewName ) { Q_ASSERT_X(component, "ModelsimGenerator::parseFiles", "Null component-pointer given as parameter"); // inform user that component is being processed emit noticeMessage(tr("Processing view %1 of component %2:%3:%4:%5").arg( viewName).arg( component->getVlnv()->getVendor()).arg( component->getVlnv()->getLibrary()).arg( component->getVlnv()->getName()).arg( component->getVlnv()->getVersion())); // pointer to the named view under given component View* view = component->findView(viewName); // if view was not found if (!view) { // if component does not contain any views if (component->viewCount() == 0) { emit noticeMessage(tr("Component %1 didn't contain any views, " "adding all found RTL-files from component file sets.").arg( component->getVlnv()->getName())); parseBlindFileSet(component); viewName_ = viewName; return; } // component did contain views but not the specified view else { emit errorMessage(tr("View %1 not found within component %2").arg( viewName).arg(component->getVlnv()->getName())); return; } } // if the view was found but was not hierarchical if (view && !view->isHierarchical()) { // ask which file sets are included in the view QStringList fileSets = view->getFileSetRefs(); // parse the file sets from the component and add them to the list of files parseFileSets(component, fileSets); } // view was found and was hierarchical else if (view && view->isHierarchical()) { VLNV designVLNV; QSharedPointer<Design> design; VLNV desConfVLNV; QSharedPointer<DesignConfiguration> designConf; VLNV vlnv = view->getHierarchyRef(); // if the specified vlnv is not found within library if (!handler_->contains(vlnv)) { emit errorMessage(tr("Hierarchy reference %1:%2:%3:%4 referenced " "within view %5 in component %6 was not found in the library." " Stopping generation.").arg( vlnv.getVendor()).arg( vlnv.getLibrary()).arg( vlnv.getName()).arg( vlnv.getVersion()).arg( viewName).arg( component->getVlnv()->getName())); return; } // get the real type of the referenced document vlnv.setType(handler_->getDocumentType(vlnv)); // if component contained reference to a design configuration if (vlnv.getType() == VLNV::DESIGNCONFIGURATION) { // parse the design configuration desConfVLNV = vlnv; QSharedPointer<LibraryComponent> libComp = handler_->getModel(desConfVLNV); designConf = libComp.staticCast<DesignConfiguration>(); // find the referenced design designVLNV = designConf->getDesignRef(); } // if component contained direct reference to a design else if (vlnv.getType() == VLNV::DESIGN) { designVLNV = vlnv; } // if item was some other type else { emit errorMessage(tr("Item %1:%2:%3:%4 was not neither design or " "design configuration, stopping generation.").arg( vlnv.getVendor()).arg( vlnv.getLibrary()).arg( vlnv.getName()).arg( vlnv.getVersion())); return; } // if design does not exist if (!handler_->contains(designVLNV)) { emit errorMessage(tr("Design %1:%2:%3:%4 referenced within " "design configuration %5 was not found within library. " "Stopping generation.").arg( designVLNV.getVendor()).arg( designVLNV.getLibrary()).arg( designVLNV.getName()).arg( designVLNV.getVersion()).arg( desConfVLNV.getName())); return; } // parse the design QSharedPointer<LibraryComponent> libComp = handler_->getModel(designVLNV); design = libComp.staticCast<Design>(); // read the design and it's component instances readDesign(design, designConf); // if this view contains a reference to a view that contains component's // top level implementation QString topLevelView = view->getTopLevelView(); if (!topLevelView.isEmpty()) { parseFiles(component, topLevelView); } } viewName_ = viewName; sourceXml_ = handler_->getPath(*component->getVlnv()); }
int main(int argc, char *argv[]) { initializeSigHandler(); setpgid(0, 0); int i = 0; int ret = 0; pid_t pid; cmpQty = argc - 2; cmp = malloc(sizeof(company*) * cmpQty); map = malloc(sizeof(graph)); sem_id = createSem(SEM_CREAT_KEY, cmpQty + SEM_QTY); setAllSem(sem_id, cmpQty + SEM_QTY, 0); if (initPIDS() == MALLOC_ERROR ) return MALLOC_ERROR; /***PARSER***/ if (cmp == NULL || map == NULL ) return parserError(NULL, NULL, MALLOC_ERROR, NULL); if ((ret = parseFiles(argc, argv, map, cmp)) != EXIT_SUCCESS ) return ret; /***INITIALIZES ARRAYS FOR THE EXECL***/ initializeArray(&semMsg, sem_id); initializeArray(&procQty, ID_QTY + cmpQty); /***MAP AND COMPANIES CREATION***/ if (createIPC(MAIN_ID, cmpQty + ID_QTY) == ERROR ) return ERROR; int map_pid = 0; int io_pid = 0; int mult_pid = 0; if ((pid = fork()) == 0) { execl("io", semMsg, procQty, NULL); exit(1); } else { io_pid = pid; addPid(io_pid); if ((pid = fork()) == 0) { execl("map", semMsg, procQty, NULL); exit(1); } else { map_pid = pid; addPid(map_pid); if ((pid = fork()) == 0) { execl("multitasker", semMsg, procQty, NULL); exit(1); } else { mult_pid = pid; addPid(mult_pid); for (i = 0; i < cmpQty; i++) { if ((pid = fork()) == 0) { char *buf = NULL; int id = CMP_ID + i; initializeArray(&buf, id); execl("company", buf, procQty, semMsg, NULL); } else { addPid(pid); } } } } } upSem(sem_id, MAIN_ID); downSem(sem_id, IO_ID); downSem(sem_id, MULTITASKER_ID); for (i = 0; i < cmpQty; i++) { downSem(sem_id, CMP_ID + i); if (initializeCmp(cmp[i], MAIN_ID, CMP_ID + i) == ERROR ) return ERROR; } downSem(sem_id, MAP_ID); if (initializeMap(map, MAIN_ID, MAP_ID) == ERROR) { return ERROR; } downSem(sem_id, MAP_ID); for (i = 0; i < cmpQty; i++) { wait(0); //Waits for all the companies to finish } kill(mult_pid, SIGTERM); waitpid(mult_pid, 0, 0); kill(map_pid, SIGTERM); waitpid(map_pid, 0, 0); kill(io_pid, SIGTERM); waitpid(io_pid, 0, 0); if (disconnectFromIPC(MAIN_ID) == ERROR) { destroyIPC(MAIN_ID); } destroySem(sem_id); /***FREES***/ freeAll(); return EXIT_SUCCESS; }