Commit 08eb4598 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Added conveniences to Grid.

parent c0edcb8e
Pipeline #7029 skipped
......@@ -51,7 +51,7 @@ Grid::Grid(const Grid& orig)
Grid::Grid(Point3D lowerLeftCorner
, Real deltaX, Real deltaY, Real deltaZ
, int numX, int numY, int numZ)
: mTranslation(lowerLeftCorner)
: mTranslation(0, 0, 0)
, mXPlanes(numX+1)
, mYPlanes(numY+1)
, mZPlanes(numZ+1)
......@@ -61,9 +61,9 @@ Grid::Grid(Point3D lowerLeftCorner
radix_check(mZPlanes.size() >= 2);
//
// Initialize first planes with lower left corner
mXPlanes[0] = 0;
mYPlanes[0] = 0;
mZPlanes[0] = 0;
mXPlanes[0] = lowerLeftCorner.x;
mYPlanes[0] = lowerLeftCorner.y;
mZPlanes[0] = lowerLeftCorner.z;
//
// auto populate grid with delta#
for(size_t i = 1; i < mXPlanes.size(); ++i)
......@@ -235,6 +235,11 @@ bool Grid::start(Real xo, Real yo, Real zo,
// <<",zcount="<<zplanes.size());
return foundx && foundy && foundz && !prior && !exiting;
}
void Grid::next(const Ray &r, int &xi, int &yi, int &zi, Real &t) const
{
next(r.o.x, r.o.y, r.o.z, r.d.x, r.d.y, r.d.z, xi, yi, zi, t);
} // end of start
/**
......
......@@ -90,6 +90,17 @@ public:
Real xd, Real yd, Real zd,
int& xi, int& yi, int&zi
) const;
/**
* @brief next convenience method
* @param r
* @param xi - the xi index that contains xo, and once complete the new x index
* @param yi - the yi index that contains yo, and once complete the new y index
* @param zi - the zi index that contains zo, and once complete the new z index
* @param t - the track length to populate with the distance to the next index (if any)
*/
void next(const Ray& r, int& xi, int& yi, int& zi, Real& t) const;
/**
* Determine the next array index that the given ray will move into
* @param xo - the x origin
......
......@@ -15,19 +15,20 @@ using namespace std;
using namespace radix;
TEST(Grid, Constructor)
{
Real deltaX = 0.05, deltaY = 0.05;
Point3D point(-116.15, 37.16667, 0);
Grid grid(point, 0.05, 0.05, 1000, 40, 20, 5);
Grid grid(point, deltaX, deltaY, 1000, 40, 20, 5);
EXPECT_EQ(grid.xcount(), 41);
EXPECT_EQ(grid.ycount(), 21);
EXPECT_EQ(grid.zcount(), 6);
EXPECT_FLOAT_EQ(grid.xplanes()[0], 0);
EXPECT_FLOAT_EQ(grid.yplanes()[0], 0);
EXPECT_FLOAT_EQ(grid.zplanes()[0], 0);
EXPECT_FLOAT_EQ(grid.xplanes()[0], point.x);
EXPECT_FLOAT_EQ(grid.yplanes()[0], point.y);
EXPECT_FLOAT_EQ(grid.zplanes()[0], point.z);
EXPECT_FLOAT_EQ(grid.xplanes()[40], 40*.05);
EXPECT_FLOAT_EQ(grid.yplanes()[20], 20*.05);
EXPECT_FLOAT_EQ(grid.zplanes()[5], 5000);
EXPECT_FLOAT_EQ(grid.xplanes()[40], point.x+(40*deltaX));
EXPECT_FLOAT_EQ(grid.yplanes()[20], point.y+(20*deltaY));
EXPECT_FLOAT_EQ(grid.zplanes()[5], point.z+5000);
// override the zplanes
......@@ -40,10 +41,41 @@ TEST(Grid, Constructor)
EXPECT_EQ(zplanes, grid.zplanes());
Ray ray(Point3D(-116.15,37.16667,1000)
, Vector3D(-116.14, 37.165, 1000));
Ray ray( point
, Vector3D(0, 1, 0));
ray.d.normalize();
std::cout << ray.toString() << std::endl;
EXPECT_TRUE(grid.inside(ray));
int x, y, z;
grid.start(ray, x, y, z);
EXPECT_EQ(x, 0); // first x cell since delta is 0.05.
EXPECT_EQ(y, 0); // first y cell since delta y is 0.05.
EXPECT_EQ(z, 0);
Real t;
// test cell 0 y distance
grid.next(ray, x, y, z, t);
EXPECT_FLOAT_EQ(t, deltaY);
// update ray direction for x test
ray.d = Vector3D(1, 0, 0);
grid.next(ray, x, y, z, t);
EXPECT_FLOAT_EQ(t, deltaX);
// update ray direction for z test
ray.d = Vector3D(0, 0, 1);
grid.next(ray, x, y, z, t);
EXPECT_FLOAT_EQ(t, 500.0);
// test ray out of grid
x = -1, y = -1, z = -1;
radix_line("("
<< grid.xplanes().front() << ","
<< grid.yplanes().front() << ","
<< grid.zplanes().front() << ")=>"
<< "("
<< grid.xplanes().back() << ","
<< grid.yplanes().back() << ","
<< grid.zplanes().back() << ")");
ray.o.x = -100;
ray.o.y = 38;
EXPECT_FALSE(grid.inside(ray));
}
TEST(Grid, Uniform)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment