Esempio n. 1
0
void Point3DTest::testSimleAdditions() {
    Point3D resultPoint(0, 0, 0);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, resultPoint.getX(), maxTolerance);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, resultPoint.getY(), maxTolerance);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, resultPoint.getZ(), maxTolerance);

    resultPoint = *point000 + point111;
    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, resultPoint.getX(), maxTolerance);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, resultPoint.getY(), maxTolerance);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, resultPoint.getZ(), maxTolerance);

    /* reset result point */
    resultPoint.setX(1.0);
    resultPoint.setY(1.0);
    resultPoint.setZ(1.0);

    resultPoint = resultPoint + pointMinus123;
    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, resultPoint.getX(), maxTolerance);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.0, resultPoint.getY(), maxTolerance);
    CPPUNIT_ASSERT_DOUBLES_EQUAL(-2.0, resultPoint.getZ(), maxTolerance);

    /* reset result point */
    resultPoint.setX(1.0);
    resultPoint.setY(1.0);
    resultPoint.setZ(1.0);

}
Esempio n. 2
0
OGRPoint GetTangetPoint(OGRLineString &line, double dfDist)
{
    double dfLength = line.get_Length();
    OGRPoint ptBeg, ptEnd;
    line.StartPoint(&ptBeg);
    line.EndPoint(&ptEnd);

    double dx = ptEnd.getX() - ptBeg.getX();
    double dy = ptEnd.getY() - ptBeg.getY();

    double ux = dfDist * dx / dfLength;
    double uy = dfDist * dy / dfLength;

    OGRPoint resultPoint(ptEnd.getX() - uy, ptEnd.getY() + ux);

    return resultPoint;
}
void Scene::CheckForIntersections(BVH* bvh)
{
	std::ofstream stream;
	stream.open("logRegular.txt");

	std::ofstream stream1;
	stream1.open("logBVH.txt");

	int intersectionsAmount = 0;

	stream << "Total rays: " << m_numberOfRays << " Total spheres: " << m_numberOfSpheres << std::endl;
	stream1 << "Total rays: " << m_numberOfRays << " Total spheres: " << m_numberOfSpheres << std::endl;

	m_timer->Start();

#ifdef MULTITHREADED
	std::mutex mtx;
	#pragma omp parallel for
#endif
	for (int i = 0; i < m_numberOfRays; i++)
	{
		for (int j = 0; j < m_numberOfSpheres; j++)
		{
			Vector3D resultPoint(0, 0, 0);

			IntersectionInfo info;

			bool intersect = m_spheres[j].GetIntersection(&m_rays[i], info);

			if (intersect)
			{
#ifdef PRINTOUTPUT
#ifdef MULTITHREADED
				mtx.lock();
#endif
				stream << intersectionsAmount << ": Ray " << i << " start:" << m_rays[i].m_startPos << " dir:" << m_rays[i].m_direction;
				stream << "Sphere " << j << " c:" << m_spheres[j].m_center << " rad:" << m_spheres[j].m_radius;
				stream << " Inters. point:" << info.m_intersPoint << "\n";

				intersectionsAmount++;
#ifdef MULTITHREADED
				mtx.unlock();
#endif
#endif
			}
		}
	}

	auto elapsed = m_timer->Stop();

	std::cout << "Intersection test with O(M.N) complexity: " << elapsed.count() << " milliseconds" << std::endl;

	m_timer->Start();

#ifdef MULTITHREADED
	#pragma omp parallel for
#endif
	for (int i = 0; i < m_numberOfRays; i++)
	{
		std::vector<IntersectionInfo> intersInfo;
		BVHNode* rootNode = &bvh->m_nodes[0];
		bool bIntersect = RayBVHTest(&m_rays[i], bvh, rootNode, intersInfo);

		if (bIntersect)
		{
#ifdef PRINTOUTPUT
			for (auto& it : intersInfo)
			{

#ifdef MULTITHREADED
				mtx.lock();
#endif
				stream1 << intersectionsAmount << ": Ray " << i << " start:" << m_rays[i].m_startPos << " dir:" << m_rays[i].m_direction;
				stream1 << "Sphere " << " c:" << it.m_object->m_center << " rad:" << it.m_object->m_radius;
				stream1 << " Inters. point:" << it.m_intersPoint << std::endl;
#ifdef MULTITHREADED
				mtx.unlock();
#endif

			}
#endif
		}
	}

	elapsed = m_timer->Stop();
	std::cout << "Intersection test with BVH: " << elapsed.count() << " milliseconds" << std::endl;

	stream.close();
	stream1.close();
}