Ejemplo n.º 1
0
/*! The IntersectAction callback for Geometry. It computes if the ray used in
    the IntersectAction \a action hits this object and if that is the case,
    which triangle is hit.

    \param[in] action IntersectAction performing the intersect test.
    \return Action result code, \see OSG::Action.

    \note This method is registered with the IntersectAction and automatically
    called from there, you probably never have to call it manually.
*/
Action::ResultE Geometry::intersect(Action * action)
{
    IntersectAction      *ia = dynamic_cast<IntersectAction*>(action);
   
    ia->getActNode()->updateVolume();
    const BoxVolume      &bv = ia->getActNode()->getVolume();

    if(bv.isValid() && !bv.intersect(ia->getLine()))
    {
        return Action::Skip; //bv missed -> can not hit children
    }

    TriangleIterator it  = this->beginTriangles();
    TriangleIterator end = this->endTriangles  ();
    Real32           t;
    Vec3f            norm;
    Line             ia_line(ia->getLine());

    for(; it != end; ++it)
    {
        if(ia_line.intersect(it.getPosition(0),
                             it.getPosition(1),
                             it.getPosition(2), t, &norm))
        {
            ia->setHit(t, ia->getActNode(), it.getIndex(), norm, -1);
        }
    }

    // If we need to test lines, iterate over lines and test for
    // lines that are within width distance from the line
    if(ia->getTestLines())
    {       
       Real32 range_sq  = ia->getTestLineWidth();
       range_sq         = range_sq * range_sq;
       LineIterator it  = this->beginLines();
       LineIterator end = this->endLines  ();
       Pnt3f  pt1, pt2;
       OSG::Vec3f  norm;       

       // Find closest points and if they are within the range, then add a hit
       for(; it != end; ++it)
       {          
          Line cur_line(it.getPosition(0), it.getPosition(1));
          ia_line.getClosestPoints(cur_line, pt1, pt2);
          Real32 dist_sq( pt1.dist2(pt2) );

          if (dist_sq <= range_sq)
          {
             t = ia_line.getPosition().dist(pt1);
             ia->setHit(t, ia->getActNode(), -1, norm, it.getIndex());
          }
       }
    }

    return Action::Continue;
}
Ejemplo n.º 2
0
void Preprocessor::handleSpecialMacro(const LineIterator& line)
{
    trim(*line);
    if(*line == "skip whitespace")
        rm_ws = !rm_ws;
    else if(*line == "reduce whitespace")
        rd_ws = !rd_ws;
    else if(line->substr(0, 7) == "include")
        handleIncludeMacro(line->substr(line->find(' ') + 1), line);
}
Ejemplo n.º 3
0
void Preprocessor::addMacro(const LineIterator& line)
{
    *line = line->substr(1);
    size_t pos = line->find(":=");
    if(pos == std::string::npos)
        return handleSpecialMacro(line);

    std::string name = line->substr(0, pos);
    trim(name);
    std::string replacement = line->substr(pos + 2);
    trim(replacement);
    parseEscapes(replacement);
    aliases.push_back(Alias(name, replacement));
}
Ejemplo n.º 4
0
Archivo: INIFile.C Proyecto: HeyJJ/ball
	bool INIFile::deleteLine(LineIterator line_it)
	{
		// test if line exists and if we try to remove a section line
		if (!isValid(line_it) || (*line_it)[0] == '[')
		{
			return false;
		}

		// falls key, entfernen		
		if ((*line_it).hasSubstring("=", 1))
		{
			String key((*line_it).before("="));
			key.trim();
			line_it.getSection()->key_map_.remove(key);
		}
		line_it.getSection()->lines_.erase(line_it.position_);

		return true;
	}
Ejemplo n.º 5
0
Archivo: INIFile.C Proyecto: HeyJJ/ball
	bool INIFile::insertLine(LineIterator line_it, const String& line)
	{
		if (!isValid(line_it))
		{
      Log.error() << "In INIFile " << filename_ << " , error while inserting line: "
                  << line << " . Illegal iterator!" << endl;			
			return false;
		}

		if (line_it.isSectionLastLine())
    {
			return appendLine(line_it.getSection()->getName(), line);
		}

		Section& section(*line_it.getSection());

		// key?
    if (line.hasSubstring("=", 1))
    {
			String key(line.before("="));
			key.trim();

			if (section.key_map_.has(key) && check_duplicate_keys_)
			{

        Log.error() << "In INIFile " << filename_ << " , error while appending line: "
                    << line << " . Key '" << key << "' already exists in section." << endl;
				return false;
			}

			line_it.getSectionNextLine();

			section.key_map_[key] = section.lines_.insert(line_it.position_, line);
			return true;
		}

		line_it.getSectionNextLine();
		section.lines_.insert(line_it.position_, line);
		return true;
	}
Ejemplo n.º 6
0
Archivo: INIFile.C Proyecto: HeyJJ/ball
	bool INIFile::setLine(LineIterator line_it, const String& line)
	{
		// section lines cannot be changed with this method
		if (!isValid(line_it) || (*line_it)[0] == '[')
		{
			return false;
		}
		
		String new_key(line.before("="));
		new_key.trim();

		if ((*line_it).hasSubstring("=", 1))
		{
			// oh, this line had a key :(
			String old_key((*line_it).before("="));
			old_key.trim();

			if (old_key == new_key)
			{
				line_it.setLine_(line);
				return true;
			}

			// its a new key: delete the old one.
			line_it.getSection()->key_map_.remove(old_key);
		}

		line_it.setLine_(line);

		if (line.hasSubstring("=", 1))
		{
			// oh, the new line has a key :(
			line_it.getSection()->key_map_[new_key] = line_it.getPosition();		
		}

		return true;
	}
Ejemplo n.º 7
0
pair< Point, bool > findCorresPointLeft(Mat img1, Mat img2, Point p, LineIterator it2) {
  Point match_pos = p;
  long min_error = 10000000000;
  int error_threshold = 10000;
  vector< long > errors;
  for(int i = 0; i < it2.count; i+=4)
  {
    Point cur_pt = it2.pos();
    int disp = cur_pt.x - p.x;
    if (abs(disp) > 60) {
      for (int z = 0; z < 4; z++) it2++;
      continue;
    }
    long error = 0;
    int w = 7;
    for (int k = -w; k <= w; k++) {
      for (int j = -w; j <= w; j++) {
        if (inImg(p.x + k, p.y + j) && inImg(cur_pt.x + k, cur_pt.y + j)) {
          
          
          error += (long)(abs((img1.at<Vec3b>(p.y + j, p.x + k)[0] - img2.at<Vec3b>(cur_pt.y + j, cur_pt.x + k)[0]))
                      +abs((img1.at<Vec3b>(p.y + j, p.x + k)[1] - img2.at<Vec3b>(cur_pt.y + j, cur_pt.x + k)[1]))
                      +abs((img1.at<Vec3b>(p.y + j, p.x + k)[2] - img2.at<Vec3b>(cur_pt.y + j, cur_pt.x + k)[2])));
        
          
        }
      }
    }
    if (error < min_error) {
      min_error = error;
      match_pos = cur_pt;
    }
    errors.push_back(error);
    for (int z = 0; z < 4; z++) ++it2;
  }
  bool good_match = true;
  /*
  int bad_points = 0;
  float error_thresh = 1.1 * min_error;
  for (int i = 0; i < errors.size(); i++) {
    if (errors[i] < (long)error_thresh) bad_points++;
  }
  if (bad_points > 5) {
    good_match = false;
  }
  */
  return make_pair(match_pos, good_match);
}
Ejemplo n.º 8
0
pair< Point, bool > findCorresPointRight(Mat img1, Mat img2, Point p, LineIterator it2) {
  Point match_pos = p;
  float min_error = 10000000000;
  vector< long > errors;
  Point2d p_dis = getDistortedPoint(p, K1, D1);
  for(int i = 0; i < it2.count; i+=2)
  {
    Point cur_pt = it2.pos();
		int disp = cur_pt.x - p.x;
    if (abs(disp) > 70) {
      for (int z = 0; z < 2; z++) it2++;
      continue;
    }
    Point2d cur_pt_dis = getDistortedPoint(Point2d(cur_pt.x, cur_pt.y), K2, D2);
    float error = 0;
    //float error = costFunction(img1_distorted, img2_distorted, Point(p_dis.x, p_dis.y), Point(cur_pt_dis.x, cur_pt_dis.y), "SAD");
    for (int k = -w; k <= w; k++) {
      for (int l = -w; l <= w; l++) {
        for (int ch = 0; ch < channels; ch++) {
          error += abs(img1_distorted.at<Vec3b>(k+p_dis.y,l+p_dis.x)[ch] - img2_distorted.at<Vec3b>(k+cur_pt_dis.y,l+cur_pt_dis.x)[ch]);
        }
      }
    }
    if (error < min_error) {
			min_error = error;
      match_pos = cur_pt;
    }
    errors.push_back(error);
    for (int z = 0; z < 2; z++) ++it2;
  }
  bool good_match = true;
  /*
	int bad_points = 0;
	float error_thresh = 1.1 * min_error;
	for (int i = 0; i < errors.size(); i++) {
		if (errors[i] < (long)error_thresh) bad_points++;
	}
	if (bad_points > 5) {
		good_match = false;
	}
	*/
  return make_pair(match_pos, good_match);
}
Ejemplo n.º 9
0
Archivo: INIFile.C Proyecto: HeyJJ/ball
	bool INIFile::isValid(const LineIterator& it) const
	{
		return (it.isValid() && it.getBound_() == &sections_);
	}