void PlaneObject::getTextureCordsAtPoint(photonCPU::Vector3D* point, float* u, float* v, float* w) {
	// Project onto our plane and take that, this should account for rounding errors
	// that result in points just off of our plane.
	Vector3D adjustedLoc = (*point)-(*position);
	float m = adjustedLoc.dotProduct(normal);
	Vector3D projection = (*point)-((*normal)*m);
	// right, convert this to local cordinates on the plane
	Vector3D diff = projection-(*position);
	*u = diff.dotProduct(right);
	*v = diff.dotProduct(up);
	*w = 0;
}
// The 'computeSliceSpacing' method
double LoadSeriesThread::computeSliceSpacing(OrthancClient::Series& series) const
{
    OrthancClient::Instance instance = series.GetInstance(0);
    instance.LoadTagContent("0020-0032"); // ImagePositionPatient
    QString pos1 = instance.GetLoadedTagContent().c_str();
    QStringList pos1s = pos1.split("\\");
    Vector3D pos1vector(pos1s.at(0).toDouble(), pos1s.at(1).toDouble(),
                        pos1s.at(2).toDouble());

    instance.LoadTagContent("0020-0037"); // ImageOrientationPatient
    QString or1 = instance.GetLoadedTagContent().c_str();
    QStringList or1s = or1.split("\\");
    Vector3D v(or1s.at(0).toDouble(), or1s.at(1).toDouble(), or1s.at(2).toDouble());
    Vector3D w(or1s.at(3).toDouble(), or1s.at(4).toDouble(), or1s.at(5).toDouble());

    Vector3D n = v.crossProduct(w);
    n.normalize();

    double min = -1;
    for(unsigned int i = 1 ; i < series.GetInstanceCount() ; i++) // TODO normally one can be enough but some bug forced me to search for the minest
    {
        OrthancClient::Instance instance2 = series.GetInstance(i);
        instance2.LoadTagContent("0020-0032");
        QString pos2 = instance2.GetLoadedTagContent().c_str();
        QStringList pos2s = pos2.split("\\");
        Vector3D pos2vector(pos2s.at(0).toDouble(), pos2s.at(1).toDouble(),
                            pos2s.at(2).toDouble());

        double dist = fabs(n.dotProduct(pos1vector-pos2vector));
        if(dist < min || min < 0)
            min = dist;
    }

    return min;
}
Example #3
0
double Plane::findIntersection(Ray ray){
	Vector3D rayDirection = ray.getDirection();
	double a = rayDirection.dotProduct(this->normal);
	if (a == 0){
		//Ray is parallel to the plane.
		return -1.0;
	}
	else {
		double b = this->normal.dotProduct(ray.getOrigin().add(this->normal.multiply(this->distanceFromOrigin).negate()));
		return (-1*b)/a; //Distance from ray origin to point intersection.
	}
}
Example #4
0
/**
 * A ray is represented by l0 + l * t = p
 *      l0 - ray origin
 *      l  - ray direction
 *      t  - parameter
 *      p  - point on plane
 * A plane is represented by (p - p0) dot n = 0 (because perpendicular)
 *      p0 - a point representing the distance from the origin
 *      n  - normal of plane
 * Solving for t by substituting p gives that
 * t = [ (p0 - l0) dot n ] / [ l dot n ]
 */
double Plane::findIntersection(const Ray3D & ray) const {
    Vector3D rayDirection = ray.getDirection();
    Vector3D l = rayDirection;
    Vector3D n = normal;
    double ldotn = l.dotProduct(n);
    if (0 == ldotn) { // Ray is || to plane
        return -1; // Never intersects
    } else {
        Vector3D p0 = normal * distance;
        Vector3D l0 = ray.getOrigin();
        double numerator = (p0 - l0).dotProduct(n);
        return numerator / ldotn;
    }
}
Example #5
0
bool pointBehindCut(Vector3D* point, Triangle* cut) {
	/*for (unsigned int i=0;i<cut->size();i++) {
	 Triangle* tri = cut->at(i);
	 Vector3D* normal = tri->getNormal();
	 Vector3D* tpoint1 = point->copy();
	 tpoint1->sub(tri->getV1());
	 Vector3D* tpoint2 = point->copy();
	 tpoint2->sub(tri->getV2());
	 Vector3D* tpoint3 = point->copy();
	 tpoint3->sub(tri->getV3());
	 Vector3D* e1 = tri->getV2()->copy();
	 e1->sub(tri->getV1());
	 Vector3D* e2 = tri->getV3()->copy();
	 e2->sub(tri->getV2());
	 Vector3D* e3 = tri->getV1()->copy();
	 e3->sub(tri->getV3());	//
	 Vector3D* ov1 = e1->crossProduct(e2);
	 Vector3D* enorm1 = ov1->crossProduct(e1);
	 Vector3D* ov2 = e2->crossProduct(e3);
	 Vector3D* enorm2 = ov2->crossProduct(e2);
	 Vector3D* ov3 = e3->crossProduct(e1);
	 Vector3D* enorm3 = ov3->crossProduct(e3);
	 if (normal->dotProduct(tpoint1)>0 && enorm1->dotProduct(tpoint1)>0 && enorm2->dotProduct(tpoint2)>0 && enorm3->dotProduct(tpoint3)>0) {
	 behind = true;
	 }
	 delete normal;
	 delete tpoint1;
	 delete tpoint2;
	 delete tpoint3;
	 delete e1;
	 delete e2;
	 delete e3;
	 delete ov1;
	 delete ov2;
	 delete ov3;
	 delete enorm1;
	 delete enorm2;
	 delete enorm3;
	 }*/
	Vector3D* normal = cut->getNormal();
	Vector3D* tpoint = point->copy();
	tpoint->sub(cut->getV1());
	bool behind = (normal->dotProduct(tpoint) < 0);
	delete normal;
	delete tpoint;
	return behind;
}
Example #6
0
Vector3D RigidBody::calcCollisionForce(const PBTime& theTime, float timestepFrac, Vector3D normal,
	                              float mass0, float fric0, float elastic0, Vector3D vel0,
	                              float mass1, float fric1, float elastic1, Vector3D vel1) const
{
	float timestep = theTime.getTimestep();

	// Get velocity at time of collision
	Vector3D vc = vel0 + ((vel1 - vel0) * timestepFrac);
	
	// Get velocity immediately after collision
	Vector3D vn = normal * vc.dotProduct(normal);
	Vector3D vt = vc - vn;
	Vector3D vnPrime = vn * -elastic0;
	Vector3D vtPrime = vt * (1 - fric0); // TODO LATER: implement more accurate model

	Vector3D newVelocity = vnPrime + vtPrime;

	return ((newVelocity - vel0)/(timestep)) * mass0;
}
Example #7
0
// Return distance from ray origin to intersection
// See comments for variables and the equations in Plane.cpp's findIntersection
double Triangle::findIntersection(const Ray3D & ray) const {
    // See if the ray intersects the bounding box
    // *** With bounding box
    if (!Object::intersectsBBox(ray)) { return -1; }
    // First check if the ray intersects with the plane (use same calculations)
    Vector3D rayDirection = ray.getDirection();
    Vector3D rayOrigin = ray.getOrigin();
    double ldotn = rayDirection.dotProduct(normal);
    if (0 == ldotn) { // Ray is || to triangle
        return -1;
    } else {
        Vector3D p0 = normal * distance;
        double distanceToPlane = (p0 - rayOrigin).dotProduct(normal) / ldotn;
        // Then see if the point is inside the triangle (3 conditions)
        // Q is the point of intersection
        Vector3D Q = (rayDirection * distanceToPlane) + rayOrigin;
        Vector3D sideCA = epC - epA;
        Vector3D segQA = Q - epA;
        // 1. (CA x QA) * n >= 0
        if (sideCA.crossProduct(segQA).dotProduct(normal) < 0) {
            return -1;
        }
        Vector3D sideBC = epB - epC;
        Vector3D segQC = Q - epC;
        // 2. (BC x QC) * n >= 0
        if (sideBC.crossProduct(segQC).dotProduct(normal) < 0) {
            return -1;
        }
        Vector3D sideAB = epA - epB;
        Vector3D segQB = Q - epB;
        // 3. (AB x QB) * n >= 0
        if (sideAB.crossProduct(segQB).dotProduct(normal) < 0) {
            return -1;
        }
        return distanceToPlane;
    }
}
double dotProduct(const Vector3D & a, const Vector3D & b){
	return a.dotProduct(b);
}