void 
HeightMapLoaderCache::Get(const Point2d & pos, const size_t sz, HeightMap & hm) const
{
	Size2d point = Size2d::Cast(pos);

	// special case of patch corner request
	if (sz == 1)
	{
		if (point.x() == (partSize_ - 1))
			--point.x();
		if (point.y() == (partSize_ - 1))
			--point.y();

		Size2d cornerPos = point / (partSize_ - 1);
		cornerPos *= (partSize_ - 1);

		const auto patchFound = heightMapCache_.find(cornerPos);

		if (patchFound == heightMapCache_.end())
		{
			basePtr_->Get(pos, sz, hm);
		}
		else
		{
			HeightMap::Container vec;
			HeightMap::Value val = HeightMap::GetValueAt(pos - Point2d::Cast(cornerPos), patchFound->second, partSize_);
			vec.push_back(val);

			hm.Swap(vec);
		}
	}
	else
	{
		if (sz != partSize_)
		{
			throw std::runtime_error("Sizes other than part size aren't supported by height map cache (Get)");
		}
		
		HeightMapCache::iterator found = heightMapCache_.find(point);

		if (found == heightMapCache_.end())
		{
			basePtr_->Get(pos, sz, hm);
		}
		else
		{
			HeightMap::Container hmc = found->second;
			
			hm.Swap(hmc);
		}
	}
}
BOOST_FIXTURE_TEST_CASE(HeightMapTest1, Test4x4HeightMap)
{
	HeightMap hm;
	hm.Swap(sample4x4);
	BOOST_CHECK_EQUAL(hm.At(Point2d(1, 1)), 0.0f);
	BOOST_CHECK_EQUAL(hm.At(Point2d(1, 2)), 1.0f);
	BOOST_CHECK_EQUAL(hm.At(Point2d(1, 3)), 1.0f);
	BOOST_CHECK_EQUAL(hm.GetSize(), 4u);
}
BOOST_FIXTURE_TEST_CASE(HeightMapTest5, Test4x4HeightMap)
{
	HeightMap hm;
	hm.Swap(sample4x4);

	Triangle3dPair tp = utils::GetTriangles(hm);

	BOOST_CHECK_EQUAL(tp.first, Triangle3d(Point3d(0, 0, 0), Point3d(0, 3, 0), Point3d(3, 3, 0)));
	BOOST_CHECK_EQUAL(tp.second, Triangle3d(Point3d(3, 3, 0), Point3d(3, 0, 0), Point3d(0, 0, 0)));
}
Esempio n. 4
0
BOOST_FIXTURE_TEST_CASE(VarianceTest1, Test5x5HeightMap)
{
	HeightMap hm;
	hm.Swap(sample5x5);
	Variance v;
	v.Generate(Level5x5, hm, utils::GetTriangles(hm).first);

	BOOST_CHECK_EQUAL(2.0f, v.At(0));
	BOOST_CHECK_EQUAL(2.0f, v.At(1));
	BOOST_CHECK_EQUAL(0.5f, v.At(2));
	BOOST_CHECK_EQUAL(v.GetSize(), 15u);
}
void 
HeightMapLoaderConstant::Get(const Point2d & pos, const size_t sz, HeightMap & hm) const
{
	if (pos.x() >= totalSize_ || pos.y() >= totalSize_)
	{
		throw std::runtime_error("Out of constant loader range");
	}

	const float value = sz == 1 ? pointValue_ : patchValue_;

	const float increment = (pos.y() * totalSize_ + pos.x()) * increment_;

	HeightMap::Container v(sz * sz, value + increment);
	hm.Swap(v);
}
void
HeightMapLoaderTest::Get(const Point2d & /*pos*/, const size_t sz, HeightMap & hm) const
{
	std::vector<HeightMap::Value> terrainHeight(sz * sz, 0.0f);

	//hm.Load(&terrainHeight[0], terrainHeight.size());
	hm.Swap(terrainHeight);

	if (sz <= 9)
	{
		PrepareHeightMap8(hm);
	}
	else
	{
		PrepareHeightMap256(hm);
	}
}