Example #1
0
const void * CSteppedConjunctionOptimizer::next()
{
    if (!hasCandidates() && !findCandidates(NULL, 0))
        return NULL;

    loop
    {
        const void * next = rootActivity->nextInputRow();
        if (next)
            return next;
        finishCandidates();

        if (!findCandidates(NULL, 0))
            return NULL;
    }
}
Example #2
0
const void * CSteppedConjunctionOptimizer::nextGE(const void * seek, unsigned numFields, bool & wasCompleteMatch, const SmartStepExtra & stepExtra)
{
    //First check the next row from the candidates, it may be ok.
    if (hasCandidates())
    {
        if (numFields <= numEqualFields)
        {
            if (stepCompare->docompare(seek, equalityRow, numFields) == 0)
                return next();
        }
        else
        {
            //This would be pretty unusual. - proximity(or(x and y), z) might trigger it.
            if (stepCompare->docompare(seek, equalityRow, numEqualFields) == 0)
            {
                const void * nextRow = rootActivity->nextInputRowGE(seek, numFields, wasCompleteMatch, stepExtra);
                if (nextRow)
                    return nextRow;
            }
        }
        finishCandidates();
    }

    if (!findCandidates(seek, numFields))
        return NULL;
    //MORE: If isCompleteMatch is provided, and seek row doesn't match returned, then shouldn't do complex join processing. 
    return next();
}
/*!
 Find and return markers
 */
void MarkerDetector::findMarkers( cv::Mat& src, std::vector<Marker>& markers)
{
    
    // convert image to a grayscale image.
    cv::cvtColor(src, _grayscale, CV_BGRA2GRAY);

    
    // Make it binary
    performThreshold(_grayscale, _threshold_image);
    
    _contours.clear();
    
    // Detect contours
    findContours(_threshold_image, _contours, _grayscale.cols / 5);
    
    // Find closed contours that can be approximated with 4 points
    findCandidates(_contours, detectedMarkers);
    
    // Find is them are markers
    recognizeMarkers(_grayscale, detectedMarkers);
    
    // Calculate their poses
    estimatePosition(detectedMarkers);
    
    //sort by id
    std::sort(detectedMarkers.begin(), detectedMarkers.end());

    markers = detectedMarkers;
}
Example #4
0
bool MarkerDetector::findMarkers(const BGRAVideoFrame& frame, std::vector<Marker>& detectedMarkers)
{
    cv::Mat bgraMat(frame.height, frame.width, CV_8UC4, frame.data, frame.stride);

    // Convert the image to grayscale
    prepareImage(bgraMat, m_grayscaleImage);

    // Make it binary
    performThreshold(m_grayscaleImage, m_thresholdImg);

    // Detect contours
    findContours(m_thresholdImg, m_contours, m_grayscaleImage.cols / 5);

    // Find closed contours that can be approximated with 4 points
    findCandidates(m_contours, detectedMarkers);

    // Find is them are markers
    recognizeMarkers(m_grayscaleImage, detectedMarkers);

    // Calculate their poses
    estimatePosition(detectedMarkers);

    //sort by id
    std::sort(detectedMarkers.begin(), detectedMarkers.end());
    return false;
}
Example #5
0
void TirFwExtractThread::run()
{
  emit progress(QString::fromUtf8("Commencing analysis of directory '%1'...").arg(path));
  gameDataFound = false;
  tirviewsFound = false;
  for(targets_iterator_t it = targets->begin(); it != targets->end(); ++it){
    it->second.clearFoundFlag();
  }

  findCandidates(path);
  emit progress(QString::fromUtf8("==============================="));
  if(allFound()){
    everything = true;
    emit progress(QString::fromUtf8("Extraction done!"));
  }else{
    everything = false;
    for(targets_iterator_t it = targets->begin(); it != targets->end(); ++it){
      if(!it->second.foundAlready())
        emit progress(QString::fromUtf8("Couldn't extract %1!").arg(it->second.getFname()));
    }
    if(!gameDataFound){
      emit progress(QString::fromUtf8("Couldn't extract game data!"));
    }
    if(!tirviewsFound){
      emit progress(QString::fromUtf8("Couldn't extract TIRViews.dll!"));
    }
  }
}
bool findCandidates(const std::vector<std::string> &candidates,
                    std::vector<std::string> &result, size_t tam) {

  if (result.size() == tam) {
    std::string flat;
    for (const std::string &word : result) {
      flat.append(word);
    }
    std::sort(flat.begin(), flat.end());
    return flat == letters;
  }

  std::string start;

  for (const std::string &s : result) {
    start.push_back(s[result.size()]);
  }

  auto first = std::lower_bound(candidates.begin(), candidates.end(), start);
  while (first->compare(0, start.size(), start) == 0) {
    result.push_back(*first);
    if (findCandidates(candidates, result, tam)) {
      return true;
    }
    result.pop_back();
    ++first;
  }

  return false;
}
std::vector<std::string>
findWordSquare(const std::vector<std::string> &candidates, size_t tam) {
  std::vector<std::string> wordSquare;

  for (std::string word : candidates) {
    wordSquare.push_back(word);
    if (findCandidates(candidates, wordSquare, tam)) {
      return wordSquare;
    } else {
      wordSquare.pop_back();
    }
  }
  return wordSquare;
}
void doAnagram(std::istream &in, std::ostream &out){
	std::string word{};
	getline(in, word);
	auto w=makeAnaword(word);
	print(out, w);
	auto start=std::chrono::system_clock::now();
	auto wl=collectFromFile(w,"linuxwords.txt");
	out << wl.size() << "matching words in set" << std::endl;
	auto res=findCandidates(wl,w);
	std::chrono::duration<double> delta=std::chrono::system_clock::now()-start;
	out << res.size() << " anagrams found\n";
	out << delta.count() << "s time\n";
	getline(in,word);
	printAllCandidates(out,res);
}
bool MarkerDetector::findMarkers(const cv::Mat& grayscale, std::vector<Marker>& detectedMarkers)
{

	if (grayscale.type()!=CV_8UC1) 
		throw cv::Exception(9000,"input.type()!=CV_8UC1","MarkerDetector::findMarkers",__FILE__,__LINE__);
    // Prepare the image for processing
    //prepareImage(frame, m_grayscaleImage);

    // Make it binary
    performThreshold(grayscale, m_thresholdImg);
	//cv::imshow("threshold", m_thresholdImg);
	//cv::waitKey(1);
	//cv::imshow("resul2", m_thresholdImg);
	//cv::waitKey(1);

    // Detect contours
	
	findCandidates(m_thresholdImg, detectedMarkers, m_thresholdImg.cols*0.16,m_thresholdImg.cols*2);

	
	/*
	for (size_t i=0; i<m_contours.size(); i++)
    {
			drawContours( frame, m_contours, i,  cv::Scalar(0,0,255), CV_FILLED, 8);
		
    }
	cv::imshow("resul2", frame);
	cv::waitKey(0);*/

    // Find closed contours that can be approximated with 4 points
   
    // Find is them are markers
    recognizeMarkers(grayscale, detectedMarkers);
	
    // Calculate their poses
    //estimatePosition(detectedMarkers);

    //sort by id
    //std::sort(detectedMarkers.begin(), detectedMarkers.end());
    return false;
}
Example #10
0
bool TirFwExtractThread::findCandidates(QString name)
{
  if(quit) return false;
  int i;
  QDir dir(name);
  QStringList patt;
  patt<<QString::fromUtf8("*.dll")<<QString::fromUtf8("*.exe")<<QString::fromUtf8("*.dat");
  QFileInfoList files = dir.entryInfoList(patt, QDir::Files | QDir::Readable);
  for(i = 0; i < files.size(); ++i){
    if(quit) return false;
    if(files[i].fileName().compare(QString::fromUtf8("TIRViews.dll")) == 0){
      QString outfile = QString::fromUtf8("%1/TIRViews.dll").arg(destPath);
      if((tirviewsFound = QFile::copy(files[i].canonicalFilePath(), outfile))){
        emit progress(QString::fromUtf8("Extracted TIRViews.dll..."));
      }
    }else if(files[i].fileName().compare(QString::fromUtf8("sgl.dat"))){
      analyzeFile(files[i].canonicalFilePath());
    }else{
      QString outfile = QString::fromUtf8("%1/gamedata.txt").arg(destPath);
      gameDataFound = get_game_data(files[i].canonicalFilePath().toUtf8().constData(),
                                    outfile.toUtf8().constData(), false);
      emit progress(QString::fromUtf8("Extracted game data..."));
    }
    if(allFound()){
      return true;
    }
  }

  QFileInfoList subdirs =
    dir.entryInfoList(QDir::AllDirs | QDir::NoDotAndDotDot | QDir::NoSymLinks);
  QString dirname;
  for(i = 0; i < subdirs.size(); ++i){
    dirname = subdirs[i].canonicalFilePath();
    if((!dirname.endsWith(QString::fromUtf8("windows"))) && findCandidates(dirname)){
      return true;
    }
  }
  return false;
}
Example #11
0
void IdenticalCodeFolding::foldIdenticalCode() {
  // 1. Find folding candidates.
  FoldingCandidates candidate_list;
  findCandidates(candidate_list);

  // 2. Initialize constant section content
  for (size_t i = 0; i < candidate_list.size(); ++i) {
    candidate_list[i].initConstantContent(m_Backend, m_KeptSections);
  }

  // 3. Find identical code until convergence
  bool converged = false;
  size_t iterations = 0;
  while (!converged && (iterations < m_Config.options().getICFIterations())) {
    converged = matchCandidates(candidate_list);
    ++iterations;
  }
  if (m_Config.options().printICFSections()) {
    debug(diag::debug_icf_iterations) << iterations;
  }

  // 4. Fold the identical code
  typedef std::set<Input*> FoldedObjects;
  FoldedObjects folded_objs;
  KeptSections::iterator kept, keptEnd = m_KeptSections.end();
  size_t index = 0;
  for (kept = m_KeptSections.begin(); kept != keptEnd; ++kept, ++index) {
    LDSection* sect = (*kept).first;
    Input* obj = (*kept).second.first;
    size_t kept_index = (*kept).second.second;
    if (index != kept_index) {
      sect->setKind(LDFileFormat::Folded);
      folded_objs.insert(obj);

      if (m_Config.options().printICFSections()) {
        KeptSections::iterator it = m_KeptSections.begin() + kept_index;
        LDSection* kept_sect = (*it).first;
        Input* kept_obj = (*it).second.first;
        debug(diag::debug_icf_folded_section) << sect->name() << obj->name()
                                              << kept_sect->name()
                                              << kept_obj->name();
      }
    }
  }

  // Adjust the fragment reference of the folded symbols.
  FoldedObjects::iterator fobj, fobjEnd = folded_objs.end();
  for (fobj = folded_objs.begin(); fobj != fobjEnd; ++fobj) {
    LDContext::sym_iterator sym, symEnd = (*fobj)->context()->symTabEnd();
    for (sym = (*fobj)->context()->symTabBegin(); sym != symEnd; ++sym) {
      if ((*sym)->hasFragRef() && ((*sym)->type() == ResolveInfo::Function)) {
        LDSymbol* out_sym = (*sym)->resolveInfo()->outSymbol();
        FragmentRef* frag_ref = out_sym->fragRef();
        LDSection* sect = &(frag_ref->frag()->getParent()->getSection());
        if (sect->kind() == LDFileFormat::Folded) {
          size_t kept_index = m_KeptSections[sect].second;
          LDSection* kept_sect = (*(m_KeptSections.begin() + kept_index)).first;
          frag_ref->assign(kept_sect->getSectionData()->front(),
                           frag_ref->offset());
        }
      }
    }  // for each symbol
  }    // for each folded object
}