Example #1
0
//===========================================================================
bool cCollisionSpheres::computeCollision(cVector3d& a_segmentPointA,
                                         cVector3d& a_segmentPointB,
                                         cCollisionRecorder& a_recorder,
                                         cCollisionSettings& a_settings)
{
    // if this is a subsequent call from the proxy algorithm after detecting
    // an initial collision, and if the flag to use neighbor checking is set,
    // only neighbors of the triangle from the first collision detection
    // need to be checked
    if ((m_useNeighbors) && (m_root != NULL) &&
        (m_lastCollision != NULL) && (m_lastCollision->m_neighbors != NULL))
    {
        // check each neighbor, and find the closest for which there is a
        // collision, if any
        for (unsigned int i=0; i<m_lastCollision->m_neighbors->size(); i++)
        {
            ((*(m_lastCollision->m_neighbors))[i])->computeCollision(
                    a_segmentPointA, a_segmentPointB, a_recorder, a_settings);
        }

        // if at least one neighbor triangle was intersected, return true
        if (a_recorder.m_collisions.size() > 0) return true;

        // otherwise there was no collision; return false
        m_lastCollision = NULL;
        return false;
    }

    // otherwise, if this is the first call in an iteration of the proxy
    // algorithm (or a call from any other algorithm), check the sphere tree

    // if the root is null, the tree is empty, so there can be no collision
    if (m_root == 0)
    {
        m_lastCollision = 0;
        return 0;
    }

    // create a cCollisionSpheresLine object and enclose it in a sphere leaf
    cCollisionSpheresLine curLine(a_segmentPointA,a_segmentPointB);
    cCollisionSpheresLeaf lineSphere(&curLine);

    // test for intersection between the line segment and the root of the
    // collision tree; the root will recursively call children down the tree
    bool result = cCollisionSpheresSphere::computeCollision(m_root,
                                                            &lineSphere,
                                                            a_recorder,
                                                            a_settings);

    // This prevents the destructor from deleting a stack-allocated SpheresLine
    // object
    lineSphere.m_prim = 0;

    // return whether there was an intersection
    return result;
}
void TemplightEntryPrinter::readBlacklists(const std::string& BLFilename) {
  if ( BLFilename.empty() ) {
    CoRegex.reset();
    IdRegex.reset();
    return;
  }
  
  std::string CoPattern, IdPattern;
  
  llvm::ErrorOr< std::unique_ptr<llvm::MemoryBuffer> >
    file_epbuf = llvm::MemoryBuffer::getFile(llvm::Twine(BLFilename));
  if(!file_epbuf || (!file_epbuf.get())) {
    llvm::errs() << "Error: [Templight-Action] Could not open the blacklist file!\n";
    CoRegex.reset();
    IdRegex.reset();
    return;
  }
  
  llvm::Regex findCo("^context ");
  llvm::Regex findId("^identifier ");
  
  const char* it      = file_epbuf.get()->getBufferStart();
  const char* it_mark = file_epbuf.get()->getBufferStart();
  const char* it_end  = file_epbuf.get()->getBufferEnd();
  
  while( it_mark != it_end ) {
    it_mark = std::find(it, it_end, '\n');
    if(*(it_mark-1) == '\r')
      --it_mark;
    llvm::StringRef curLine(&(*it), it_mark - it);
    if( findCo.match(curLine) ) {
      if(!CoPattern.empty())
        CoPattern += '|';
      CoPattern += '(';
      CoPattern.append(&(*(it+8)), it_mark - it - 8);
      CoPattern += ')';
    } else if( findId.match(curLine) ) {
      if(!IdPattern.empty())
        IdPattern += '|';
      IdPattern += '(';
      IdPattern.append(&(*(it+11)), it_mark - it - 11);
      IdPattern += ')';
    }
    while( (it_mark != it_end) && 
           ((*it_mark == '\n') || (*it_mark == '\r')) )
      ++it_mark;
    it = it_mark;
  }
  
  CoRegex.reset(new llvm::Regex(CoPattern));
  IdRegex.reset(new llvm::Regex(IdPattern));
  return;
}
Example #3
0
//build the map between the word and its line_no set
void TextQuery::build_map(){
	line_no lineNo = 0;
	for (lineNo = 0; lineNo != lines_of_text.size(); lineNo++){
		//Current content of line
		std::istringstream curLine(lines_of_text[lineNo]);
		//break each line into several words
		std::string curWord;
		while (curLine >> curWord){
			word_map[cleanUp(curWord)].insert(lineNo);
		}
	}
}