Esempio n. 1
0
//--------------------------------------------------------------------------------------------------
/// The window coordinates are in OpenGL style coordinates, which means a right handed 
/// coordinate system with the origin in the lower left corner of the window.
//--------------------------------------------------------------------------------------------------
bool LocatorTranslateOnPlane::update(int x, int y)
{
    CVF_ASSERT(m_camera.notNull());

    Vec3d oldPos = m_pos;

    ref<Ray> ray = m_camera->rayFromWindowCoordinates(x, y);

    Vec3d isect(0, 0, 0);
    if (ray->planeIntersect(m_plane, &isect))
    {
        Vec3d delta = (isect - m_lastPos);
        m_plane.projectVector(delta, &delta);
        m_pos += delta;

        m_lastPos = isect;
    }

    if (m_pos == oldPos)
    {
        return false;
    }
    else
    {
        return true;
    }
}
Esempio n. 2
0
//--------------------------------------------------------------------------------------------------
/// The window coordinates are in OpenGL style coordinates, which means a right handed 
/// coordinate system with the origin in the lower left corner of the window.
//--------------------------------------------------------------------------------------------------
void LocatorTranslateOnPlane::start(int x, int y)
{
    CVF_ASSERT(m_camera.notNull());
    ref<Ray> ray = m_camera->rayFromWindowCoordinates(x, y);
    
    Vec3d isect(0, 0, 0);
    ray->planeIntersect(m_plane, &isect);

    m_lastPos = isect;
}
Esempio n. 3
0
    // Pown Range Test
   TEST(POWN, RangeTest)
    {
      typedef yalaa::details::double_iv_t iv_t;
      typedef yalaa::details::base_traits<iv_t> iv_traits;
      typedef double base_t;
      std::deque<iv_t> m_x;
      for(int exp = -10; exp <= 10; exp++) {
        m_x.clear();
        if(exp < 0)
          m_x.push_back(iv_t(0.1, 10));
        else
          m_x.push_back(iv_t(-10, 10));
        while(!m_x.empty()) {
          iv_t x(m_x.front());
          iv_t fiv(iv_traits::my_pow(x, exp));
          AFF_TYPE aarg(x);
          AFF_TYPE faff(pown(aarg, exp));
          iv_t faffiv (to_iv(faff));
          iv_t isect(intersect(faffiv, fiv));
          if(!exp)
            ASSERT_EQ(faffiv, iv_traits::my_one())
              << "pown(x,0) does not yield iv_traits::my_one()"
              << "Input was " << x << "^" << exp << " fiv: " << fiv << " faff " << faff << std::endl;
          else if(exp == 1)
            ASSERT_EQ(faff, aarg)
              << "pown(x,1) does not preserve identity of x!"
              << "Input was " << x << "^" << exp << " fiv: " << fiv << " faff " << faff << std::endl;

          ASSERT_TRUE(iv_traits::my_inf(faffiv) <= iv_traits::my_sup(fiv) &&
                      iv_traits::my_sup(faffiv) >= iv_traits::my_inf(fiv))
            << "Interval and affine evaluation do not intersect!" << std::endl
            << "Input was " << x << "^" << exp << " fiv: " << fiv << " faff " << faff << std::endl;
          // ASSERT_LE(iv_traits::my_inf(faffiv), iv_traits::my_inf(fiv))
          //    << "Affine evaluation was tigher than IV for a single elementary function."
          //    << "Input was " << x << " fiv: " << fiv << " faff " << faff << std::endl;
          // ASSERT_GE(iv_traits::my_sup(faffiv), iv_traits::my_sup(fiv))
          //   << "Affine evaluation was tigher than IV for a single elementary function."
          //   << "Input was " << x << " fiv: " << fiv << " faff " << faff << std::endl;
          if(iv_traits::my_sup(x) - iv_traits::my_inf(x) > 0.0001) {
            base_t mid = (iv_traits::my_inf(x) + iv_traits::my_sup(x))/2;
            m_x.push_back(iv_t(iv_traits::my_inf(x), mid));
            m_x.push_back(iv_t(mid, iv_traits::my_sup(x)));
          }
          m_x.pop_front();
        }
      }
    }
Esempio n. 4
0
//---------------------------------------------------------------------------
bool csIntersect2::PlanePolygon (
  const csPlane2 &plane,
  csPoly2D *poly,
  csSegment2 &seg)
{
  csVector2 &v1 = seg.Start ();
  csVector2 &v2 = seg.End ();
  size_t i, i1;
  float c, c1;
  csVector2 isect(0.0,0.0);
  float dist;
  i1 = poly->GetVertexCount () - 1;
  c1 = plane.Classify ((*poly)[i1]);

  bool found_v1 = false;
  bool found_v2 = false;
  for (i = 0; i < poly->GetVertexCount (); i++)
  {
    c = plane.Classify ((*poly)[i]);
    if ((c < 0 && c1 > 0) || (c1 < 0 && c > 0))
    {
      csIntersect2::SegmentPlane ((*poly)[i1], (*poly)[i], plane, isect, dist);
      if (!found_v1)
      {
        v1 = isect;
        found_v1 = true;
      }
      else
      {
        v2 = isect;
        found_v2 = true;
        break;
      }
    }

    i1 = i;
    c1 = c;
  }

  if (!found_v1) return false;
  if (!found_v2) v2 = v1;
  return true;
}
Esempio n. 5
0
 void unique_update(unique_type &us, const unique_type &us1)
 {
     if (us.empty() || us1.empty())
     {
         us.clear();
         return;
     }
     unique_type isect(key_type_less(pref_.cont()->keys()));
     std::set_intersection(
         us.begin(),
         us.end(),
         us1.begin(),
         us1.end(),
         std::inserter(isect, isect.end()),
         us.key_comp());
     if (isect.empty())
         us.insert(us1.begin(), us1.end());
     else
         us.clear();
 }
Esempio n. 6
0
bool Sphere::sampleSurface(const Point& refPosition,
	const Vector& refNormal,
	float u1, float u2, float u3,
	Point& outPosition,
	Vector& outNormal,
	float& outPdf)
{
	Vector toCenter = origin - refPosition;
	float dist2 = toCenter.length2();
	if (dist2 < squared(radius) * 1.00001f)
	{
		// Point is on or in the sphere
		outNormal = uniformToSphere(u1, u2);
		outPosition = origin + outNormal * radius;
		Vector toSurf = refPosition - outPosition;
		outPdf = toSurf.length2() * surfaceAreaPDF() / std::fabs(dot(toSurf.normalized(), outNormal));
		return true;
	}

	// Outside the sphere, fit a cone around to sample more efficiently
	float sinThetaMax2 = squared(radius) / dist2;
	float cosThetaMax = std::sqrt(std::max(0.0f, 1 - sinThetaMax2));
	Vector x, y, z;
	makeCoordinateSpace(toCenter, x, y, z);
	Vector localCone = uniformToCone(u1, u2, cosThetaMax);
	Vector cone = transformFromLocalSpace(localCone, x, y, z);

	// Make sure direction hits sphere
	Ray ray(refPosition, cone);
	Intersection isect(ray);
	if (!intersect(isect))
		isect.dist = dot(toCenter, cone);

	outPosition = ray.calc(isect.dist);
	outNormal = (outPosition - origin).normalized();
	outPdf = uniformConePdf(cosThetaMax);
	return true;
}
Esempio n. 7
0
std::unique_ptr<struct Intersection> Box::intersect(const struct Ray& ray, decimal &currentdepth) const{
	vec3 ray_origin = vec3(_inv_modelTransform * vec4(ray.origin, 1.0f));
	vec3 ray_direction = vec3(_inv_modelTransform * vec4(ray.direction, 0.0f));

	float t1 = (_min.x - ray_origin.x)*(1.0 / ray_direction.x);
	float t2 = (_max.x - ray_origin.x)*(1.0 / ray_direction.x);
	float t3 = (_min.y - ray_origin.y)*(1.0 / ray_direction.y);
	float t4 = (_max.y - ray_origin.y)*(1.0 / ray_direction.y);
	float t5 = (_min.z - ray_origin.z)*(1.0 / ray_direction.z);
	float t6 = (_max.z - ray_origin.z)*(1.0 / ray_direction.z);
	decimal t = max(max(min(t1, t2), min(t3, t4)), min(t5, t6));
	float tmax = min(min(max(t1, t2), max(t3, t4)), max(t5, t6));
	if (tmax < 0)
		return nullptr;
	if (t > tmax)
		return nullptr;

	vec3 ray_isect = ray_origin + t * ray_direction;

	//Calcul des normales
	decimal min_face_dist = INFINITY;
	uint index=0;
	for (uint i = 0; i < _faces_points.size(); i++){
		decimal curr_face_dist = length(_faces_points[i] - ray_isect);
		if (curr_face_dist < min_face_dist){
			min_face_dist = curr_face_dist;
			index = i;
		}
	}

	vec3 normal = glm::normalize(_faces_points[index]);
	normal = glm::normalize((vec3(glm::transpose(_inv_modelTransform) * vec4(normal, 0.0f))));

	// Calcul des coordonees uv		
	vec3 uv_coord_0_0;
	vec3 uv_coord_1_0;
	vec3 uv_coord_0_1;

	// test pour savoir sur quel plan se trouve l'intersection
	if (index == 0) {
		uv_coord_0_0 = points[4];
		uv_coord_1_0 = points[2];
		uv_coord_0_1 = points[3];
	}

	if (index == 1) {
		uv_coord_0_0 = points[3];
		uv_coord_1_0 = points[0];
		uv_coord_0_1 = points[6];
	}

	if (index == 2) {
		uv_coord_0_0 = points[2];
		uv_coord_1_0 = points[7];
		uv_coord_0_1 = points[0];
	}

	if (index == 3) {
		uv_coord_0_0 = points[1];
		uv_coord_1_0 = points[7];
		uv_coord_0_1 = points[6];
	}

	if (index == 4) {
		uv_coord_0_0 = points[1];
		uv_coord_1_0 = points[7];
		uv_coord_0_1 = points[4];
	}

	if (index == 5) {
		uv_coord_0_0 = points[1];
		uv_coord_1_0 = points[4];
		uv_coord_0_1 = points[6];
	}

	vec3 u_vec = glm::cross((ray_isect - uv_coord_0_0), (ray_isect - uv_coord_1_0));
	float u = glm::length(u_vec) / (2 * glm::length(uv_coord_1_0 - uv_coord_0_0));
	vec3 v_vec = glm::cross((ray_isect - uv_coord_0_0), (ray_isect - uv_coord_0_1));
	float v = glm::length(v_vec) / (2 * glm::length(uv_coord_0_1 - uv_coord_0_0));

	ray_isect = vec3(_modelTransform * vec4(ray_isect, 1.0f));
	vec2 uv = glm::vec2(u, v);
	std::unique_ptr<struct Intersection> isect(new Intersection{ ray, ray_isect, normal, uv, _material });
	return std::move(isect);
}