Skip to content

Commit

Permalink
Support direct X/Y/Z access.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Feb 13, 2020
1 parent 84502f2 commit 814843a
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 11 deletions.
7 changes: 5 additions & 2 deletions filters/SkewnessBalancingFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void SkewnessBalancingFilter::processGround(PointViewPtr view)
};
std::sort(view->begin(), view->end(), cmp);

for (PointId idx = 0; idx < view->size(); idx++)
std::cerr << "Z = " << view->getFieldAs<double>(Dimension::Id::Z, idx) << "!\n";

auto setClass = [&view](PointId first, PointId last, int cl)
{
for (PointId idx = first; idx <= last; ++idx)
Expand All @@ -81,6 +84,7 @@ void SkewnessBalancingFilter::processGround(PointViewPtr view)
for (PointId i = 0; i < view->size(); ++i)
{
double z = view->getFieldAs<double>(Dimension::Id::Z, i);
std::cerr << "Z value = " << z << "!\n";
n1 = n;
n++;
delta = z - M1;
Expand Down Expand Up @@ -114,8 +118,7 @@ PointViewSet SkewnessBalancingFilter::run(PointViewPtr input)
return viewSet;
viewSet.insert(input);

bool logOutput = log()->getLevel() > LogLevel::Debug1;
if (logOutput)
if (log()->getLevel() > LogLevel::Debug1)
log()->floatPrecision(8);

processGround(input);
Expand Down
5 changes: 5 additions & 0 deletions io/private/EptSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ class PDAL_DLL ShallowPointTable : public BasePointTable
std::copy(src, src + d->size(), dst);
}

void *getFieldDirect(Dimension::Id id, PointId idx) override
{
return nullptr;
}

char *getDimension(const Dimension::Detail* d, PointId idx)
{
return getPoint(idx) + d->offset();
Expand Down
1 change: 1 addition & 0 deletions pdal/PointContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class PDAL_DLL PointContainer
const void *val) = 0;
virtual void getFieldInternal(Dimension::Id dim, PointId idx,
void *val) const = 0;
virtual void *getFieldDirect(Dimension::Id dim, PointId idx) = 0;
public:
virtual PointLayoutPtr layout() const = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions pdal/PointLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ PointLayout::PointLayout()

void PointLayout::finalize()
{
if (!m_finalized)
registerDims( {Dimension::Id::X, Dimension::Id::Y, Dimension::Id::Z} );
m_finalized = true;
}

Expand Down
24 changes: 24 additions & 0 deletions pdal/PointRef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ class PDAL_DLL PointRef
bool hasDim(Dimension::Id dim) const
{ return m_layout.hasDim(dim); }


double& x()
{
void *v = m_container.getFieldDirect(Dimension::Id::X, m_idx);
return *reinterpret_cast<double *>(v);
}

double& y()
{
void *v = m_container.getFieldDirect(Dimension::Id::Y, m_idx);
return *reinterpret_cast<double *>(v);
}

double& z()
{
void *v = m_container.getFieldDirect(Dimension::Id::Z, m_idx);
return *reinterpret_cast<double *>(v);
}

std::tuple<double &, double &, double &> xyz()
{
return std::forward_as_tuple(x(), y(), z());
}

/**
Get the value of a field/dimension, converting it to the type as
requested. NOTE: Throws an exception if the value of the dimension
Expand Down
4 changes: 3 additions & 1 deletion pdal/PointTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ class PDAL_DLL SimplePointTable : public BasePointTable
const void *value);
virtual void getFieldInternal(Dimension::Id id, PointId idx,
void *value) const;
virtual void *getFieldDirect(Dimension::Id id, PointId idx)
{ return getDimension(m_layoutRef.dimDetail(id), idx); }

// The number of points in each memory block.
// Get a pointer to the field data.
char *getDimension(const Dimension::Detail *d, PointId idx)
{ return getPoint(idx) + d->offset(); }

Expand Down
33 changes: 31 additions & 2 deletions pdal/PointView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,32 @@ class PDAL_DLL PointView : public PointContainer
inline void getField(char *pos, Dimension::Id d,
Dimension::Type type, PointId id) const;

double& x(PointId idx)
{
void *v = m_pointTable.getFieldDirect(Dimension::Id::X, idx);
return *reinterpret_cast<double *>(v);
}

double& y(PointId idx)
{
void *v = m_pointTable.getFieldDirect(Dimension::Id::Y, idx);
return *reinterpret_cast<double *>(v);
}

double& z(PointId idx)
{
void *v = m_pointTable.getFieldDirect(Dimension::Id::Z, idx);
return *reinterpret_cast<double *>(v);
}

std::tuple<double&, double&, double&> xyz(PointId idx)
{
double& xr = x(idx);
double& yr = y(idx);
double& zr = z(idx);
return std::forward_as_tuple(xr, yr, zr);
}

template<typename T>
void setField(Dimension::Id dim, PointId idx, T val);

Expand Down Expand Up @@ -317,8 +343,10 @@ class PDAL_DLL PointView : public PointContainer
virtual void setFieldInternal(Dimension::Id dim, PointId idx,
const void *buf);
virtual void getFieldInternal(Dimension::Id dim, PointId idx,
void *buf) const
{ m_pointTable.getFieldInternal(dim, m_index[idx], buf); }
void *buf) const
{ m_pointTable.getFieldInternal(dim, m_index[idx], buf); }
virtual void *getFieldDirect(Dimension::Id dim, PointId idx)
{ return m_pointTable.getFieldDirect(dim, m_index[idx]); }

template<class T>
T getFieldInternal(Dimension::Id dim, PointId pointIndex) const;
Expand Down Expand Up @@ -434,6 +462,7 @@ inline void PointView::setField(Dimension::Id dim,
}
}


template <class T>
inline T PointView::getFieldAs(Dimension::Id dim,
PointId pointIndex) const
Expand Down
1 change: 1 addition & 0 deletions test/unit/filters/MortonOrderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ TEST(MortonOrderTest, test_code)
PointTable table;
table.layout()->registerDim(Dimension::Id::X);
table.layout()->registerDim(Dimension::Id::Y);
table.finalize();

PointViewPtr view(new PointView(table));

Expand Down
12 changes: 6 additions & 6 deletions test/unit/filters/SkewnessFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ TEST(SkewnessTest, t3)
t.layout()->registerDims(
{Dimension::Id::Z, Dimension::Id::Classification} );

PointViewPtr bv(new PointView(t));
for (int i = 0; i < 10; ++i)
bv->setField(Dimension::Id::Z, i, i - 5);

BufferReader reader;
reader.addView(bv);

Stage* filter(f.createStage("filters.skewnessbalancing"));
filter->setInput(reader);

filter->prepare(t);
t.finalize();

PointViewPtr bv(new PointView(t));
for (int i = 0; i < 10; ++i)
bv->setField(Dimension::Id::Z, i, i - 5);
reader.addView(bv);

PointViewSet s = filter->execute(t);

Expand All @@ -135,4 +136,3 @@ TEST(SkewnessTest, t3)
EXPECT_EQ(ground, 10U);
}


2 changes: 2 additions & 0 deletions test/unit/filters/StatsFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ TEST(Stats, handcalc)
{
PointTable table;
table.layout()->registerDim(Dimension::Id::X);
table.finalize();
PointViewPtr v(new PointView(table));
v->setField(Dimension::Id::X, 0, 1);
v->setField(Dimension::Id::X, 1, 5);
Expand Down Expand Up @@ -88,6 +89,7 @@ TEST(Stats, baseline)
{
PointTable table;
table.layout()->registerDim(Dimension::Id::X);
table.finalize();
PointViewPtr v(new PointView(table));

for (PointId idx = 0; idx < 100; idx++)
Expand Down

0 comments on commit 814843a

Please sign in to comment.