示例#1
0
TEST(GeoLib, SearchNearestPointsInDenseGrid)
{
	const std::size_t i_max(50), j_max(50), k_max(50);
	std::vector<GeoLib::Point*> pnts(i_max*j_max*k_max);

	// fill the vector with equi-distant points in the
	// cube [0,(i_max-1)/i_max] x [0,(j_max-1)/j_max] x [0,(k_max-1)/k_max]
	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				pnts[offset1 + k] = new GeoLib::Point(
					std::array<double,3>({{static_cast<double>(i) / i_max,
						static_cast<double>(j) / j_max,
						static_cast<double>(k) / k_max}}), offset1+k);
			}
		}
	}

	// create the grid
	GeoLib::Grid<GeoLib::Point>* grid(nullptr);
	ASSERT_NO_THROW(grid = new GeoLib::Grid<GeoLib::Point> (pnts.begin(), pnts.end()));

	// search point (1,1,1) is outside of the point set
	GeoLib::Point search_pnt(std::array<double,3>({{1,1,1}}), 0);
	GeoLib::Point* res(grid->getNearestPoint(search_pnt));
	ASSERT_EQ(i_max*j_max*k_max-1, res->getID());
	ASSERT_NEAR(sqrt(3.0)/50.0, sqrt(MathLib::sqrDist(*res, search_pnt)), std::numeric_limits<double>::epsilon());

	// search point (0,1,1) is outside of the point set
	search_pnt[0] = 0;
	res = grid->getNearestPoint(search_pnt);
	ASSERT_EQ(j_max*k_max - 1, res->getID());
	ASSERT_NEAR(sqrt(2.0)/50.0, sqrt(MathLib::sqrDist(*res, search_pnt)), std::numeric_limits<double>::epsilon());

	// search point (0.5,1,1) is outside of the point set
	search_pnt[0] = 0.5;
	res = grid->getNearestPoint(search_pnt);
	ASSERT_EQ(j_max*k_max*(i_max/2 + 1) - 1, res->getID());
	ASSERT_NEAR(sqrt(2.0)/50.0, sqrt(MathLib::sqrDist(*res, search_pnt)), std::numeric_limits<double>::epsilon());

	// checking only every fourth point per direction to reduce the run time of
	// the test
	for (std::size_t i(0); i < i_max; i=i+4) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j=j+4) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k=k+4) {
				res = grid->getNearestPoint(*pnts[offset1+k]);
				ASSERT_EQ(offset1+k, res->getID());
				ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, *pnts[offset1+k])), 0.0, std::numeric_limits<double>::epsilon());
			}
		}
	}

	delete grid;
	std::for_each(pnts.begin(), pnts.end(), std::default_delete<GeoLib::Point>());
}
示例#2
0
文件: TestGrid.cpp 项目: XRuiWang/ogs
TEST(GeoLib, SearchNearestPointsInDenseGrid)
{
	const std::size_t i_max(50), j_max(50), k_max(50);
	std::vector<GeoLib::PointWithID*> pnts(i_max*j_max*k_max);

	// fill the vector with equi-distant points in the
	// cube [0,(i_max-1)/i_max] x [0,(j_max-1)/j_max] x [0,(k_max-1)/k_max]
	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				pnts[offset1 + k] = new GeoLib::PointWithID(static_cast<double>(i) / i_max,
						static_cast<double>(j) / j_max, static_cast<double>(k) / k_max, offset1+k);
			}
		}
	}

	// create the grid
	GeoLib::Grid<GeoLib::PointWithID>* grid(nullptr);
	ASSERT_NO_THROW(grid = new GeoLib::Grid<GeoLib::PointWithID> (pnts.begin(), pnts.end()));

	// search point (1,1,1) is outside of the point set
	GeoLib::PointWithID search_pnt(1,1,1, 0);
	GeoLib::PointWithID* res(grid->getNearestPoint(search_pnt.getCoords()));
	ASSERT_EQ(res->getID(), i_max*j_max*k_max-1);
	ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, search_pnt)), sqrt(3.0)/50.0, std::numeric_limits<double>::epsilon());

	// search point (0,1,1) is outside of the point set
	search_pnt[0] = 0;
	res = grid->getNearestPoint(search_pnt.getCoords());
	ASSERT_EQ(res->getID(), j_max*k_max - 1);
	ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, search_pnt)), sqrt(2.0)/50.0, std::numeric_limits<double>::epsilon());

	// search point (0.5,1,1) is outside of the point set
	search_pnt[0] = 0.5;
	res = grid->getNearestPoint(search_pnt.getCoords());
	ASSERT_EQ(res->getID(), j_max*k_max*(i_max/2 + 1) - 1);
	ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, search_pnt)), sqrt(2.0)/50.0, std::numeric_limits<double>::epsilon());

	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				res = grid->getNearestPoint(pnts[offset1+k]->getCoords());
				ASSERT_EQ(res->getID(), offset1+k);
				ASSERT_NEAR(sqrt(MathLib::sqrDist(*res, *pnts[offset1+k])), 0.0, std::numeric_limits<double>::epsilon());
			}
		}
	}

	delete grid;
	std::for_each(pnts.begin(), pnts.end(), std::default_delete<GeoLib::PointWithID>());
}
void CPlayerStateSwim_WaterTestProxy::DebugDraw(const CPlayer& player, const Vec3& referencePosition)
{
	// DEBUG RENDERING
	const SPlayerStats& stats = *player.GetActorStats();
	const bool debugSwimming = (g_pGameCVars->cl_debugSwimming != 0);
	if (debugSwimming && (m_playerWaterLevel > -10.0f) && (m_playerWaterLevel < 10.0f))
	{
		const Vec3 surfacePosition(referencePosition.x, referencePosition.y, m_waterLevel);

		const Vec3 vRight(player.GetBaseQuat().GetColumn0());

		const static ColorF referenceColor(1,1,1,1);
		const static ColorF surfaceColor1(0,0.5f,1,1);
		const static ColorF surfaceColor0(0,0,0.5f,0);
		const static ColorF bottomColor(0,0.5f,0,1);

		gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(referencePosition, 0.1f, referenceColor);

		gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(referencePosition, surfaceColor1, surfacePosition, surfaceColor1, 2.0f);
		gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(surfacePosition, 0.2f, surfaceColor1);
		gEnv->pRenderer->DrawLabel(referencePosition + vRight * 0.5f, 1.5f, "WaterLevel %3.2f (Head underwater: %d)", m_playerWaterLevel, m_headUnderwater ? 1 : 0);

		const static int lines = 16;
		const static float radius0 = 0.5f;
		const static float radius1 = 1.0f;
		const static float radius2 = 2.0f;
		for (int i = 0; i < lines; ++i)
		{
			float radians = ((float)i / (float)lines) * gf_PI2;
			Vec3 offset0(radius0 * cos_tpl(radians), radius0 * sin_tpl(radians), 0);
			Vec3 offset1(radius1 * cos_tpl(radians), radius1 * sin_tpl(radians), 0);
			Vec3 offset2(radius2 * cos_tpl(radians), radius2 * sin_tpl(radians), 0);
			gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(surfacePosition+offset0, surfaceColor0, surfacePosition+offset1, surfaceColor1, 2.0f);
			gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(surfacePosition+offset1, surfaceColor1, surfacePosition+offset2, surfaceColor0, 2.0f);
		}

		if (m_bottomLevel > 0.0f)
		{
			const Vec3 bottomPosition(referencePosition.x, referencePosition.y, m_bottomLevel);

			gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine(referencePosition, bottomColor, bottomPosition, bottomColor, 2.0f);
			gEnv->pRenderer->GetIRenderAuxGeom()->DrawSphere(bottomPosition, 0.2f, bottomColor);
			gEnv->pRenderer->DrawLabel(bottomPosition + Vec3(0,0,0.5f) - vRight * 0.5f, 1.5f, "BottomDepth %3.3f", m_waterLevel - m_bottomLevel);
		}
	}
}
示例#4
0
文件: TestGrid.cpp 项目: Stefan6/ogs
TEST(GeoLib, InsertManyPointsInGrid)
{
	const std::size_t i_max(100), j_max(100), k_max(100);
	std::vector<GeoLib::Point*> pnts(i_max*j_max*k_max);

	// fill the vector with points
	for (std::size_t i(0); i < i_max; i++) {
		std::size_t offset0(i * j_max * k_max);
		for (std::size_t j(0); j < j_max; j++) {
			std::size_t offset1(j * k_max + offset0);
			for (std::size_t k(0); k < k_max; k++) {
				pnts[offset1 + k] = new GeoLib::Point(static_cast<double>(i) / i_max,
						static_cast<double>(j) / j_max, static_cast<double>(k) / k_max);
			}
		}
	}

	ASSERT_NO_THROW(GeoLib::Grid<GeoLib::Point> grid(pnts.begin(), pnts.end()));
}