Skip to content

Commit

Permalink
Merge branch 'stream' of github.com:PDAL/PDAL into stream
Browse files Browse the repository at this point in the history
  • Loading branch information
connormanning committed Dec 11, 2015
2 parents f383053 + 10a593c commit c94c31d
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 56 deletions.
3 changes: 3 additions & 0 deletions appveyor.yml
Expand Up @@ -5,6 +5,9 @@ os: Windows Server 2012
platform:
- x64

init:
- SET PATH=C:\Python27-x64\;%PATH%

configuration: Release

environment:
Expand Down
10 changes: 2 additions & 8 deletions cmake/geos.cmake
Expand Up @@ -5,14 +5,8 @@ find_package(GEOS QUIET 3.3)
set_package_properties(GEOS PROPERTIES TYPE OPTIONAL
PURPOSE "Provides general purpose geometry support")
if (GEOS_FOUND)
find_file(GEOS_VERSION_H version.h "${GEOS_INCLUDE_DIR}/geos")
if ("${GEOS_VERSION_H}" STREQUAL "GEOS_VERSION_H-NOTFOUND")
set(GEOS_LIBRARY "")
set(GEOS_FOUND FALSE)
else()
include_directories("${GEOS_INCLUDE_DIR}")
set(PDAL_HAVE_GEOS 1)
endif()
include_directories("${GEOS_INCLUDE_DIR}")
set(PDAL_HAVE_GEOS 1)
else()
set(GEOS_LIBRARY "")
endif()
28 changes: 18 additions & 10 deletions filters/colorization/ColorizationFilter.cpp
Expand Up @@ -183,26 +183,34 @@ void ColorizationFilter::ready(PointTableRef table)
}


void ColorizationFilter::filter(PointView& view)
bool ColorizationFilter::processOne(PointRef& point)
{
std::vector<double> data;

for (PointId idx = 0; idx < view.size(); ++idx)
{
double x = view.getFieldAs<double>(Dimension::Id::X, idx);
double y = view.getFieldAs<double>(Dimension::Id::Y, idx);
static std::vector<double> data;

if (!m_raster->read(x, y, data))
continue;
double x = point.getFieldAs<double>(Dimension::Id::X);
double y = point.getFieldAs<double>(Dimension::Id::Y);

if (m_raster->read(x, y, data))
{
int i(0);
for (auto bi = m_bands.begin(); bi != m_bands.end(); ++bi)
{
BandInfo& b = *bi;
view.setField(b.m_dim, idx, data[i] * b.m_scale);
point.setField(b.m_dim, data[i] * b.m_scale);
++i;
}
}
return true;
}

void ColorizationFilter::filter(PointView& view)
{
PointRef point = view.point(0);
for (PointId idx = 0; idx < view.size(); ++idx)
{
point.setPointId(idx);
processOne(point);
}
}

} // namespace pdal
1 change: 1 addition & 0 deletions filters/colorization/ColorizationFilter.hpp
Expand Up @@ -87,6 +87,7 @@ class PDAL_DLL ColorizationFilter : public Filter
virtual void processOptions(const Options&);
virtual void addDimensions(PointLayoutPtr layout);
virtual void ready(PointTableRef table);
virtual bool processOne(PointRef& point);
virtual void filter(PointView& view);

std::string m_rasterFilename;
Expand Down
14 changes: 13 additions & 1 deletion filters/reprojection/ReprojectionFilter.cpp
Expand Up @@ -125,6 +125,14 @@ void ReprojectionFilter::initialize()
"for the 'out_srs' option.";
throw pdal_error(oss.str());
}

// If we have our input and output spatial references, create the transform
// now. Otherwise, if this filter is used via the FilterWrapper, it will
// not be initialized properly since run() won't get called.
if (!m_inferInputSRS)
{
createTransform(0);
}
}


Expand All @@ -133,6 +141,7 @@ void ReprojectionFilter::createTransform(PointView *view)
if (m_inferInputSRS)
{
m_inSRS = view->spatialReference();

if (m_inSRS.empty())
{
std::ostringstream oss;
Expand Down Expand Up @@ -196,7 +205,10 @@ PointViewSet ReprojectionFilter::run(PointViewPtr view)
PointViewSet viewSet;
PointViewPtr outView = view->makeNew();

createTransform(view.get());
if (m_inferInputSRS)
{
createTransform(view.get());
}

double x, y, z;

Expand Down
4 changes: 3 additions & 1 deletion include/pdal/Compression.hpp
Expand Up @@ -139,7 +139,9 @@ class TypedLazPerfBuf
{}

void putBytes(const unsigned char *b, size_t len)
{ m_buf.insert(m_buf.end(), (CTYPE *)b, (CTYPE *)(b + len)); }
{
m_buf.insert(m_buf.end(), (const CTYPE *)b, (const CTYPE *)(b + len));
}
void putByte(const unsigned char b)
{ m_buf.push_back((CTYPE)b); }
unsigned char getByte()
Expand Down
11 changes: 10 additions & 1 deletion include/pdal/Dimension.hpp
Expand Up @@ -184,7 +184,8 @@ enum Enum
EchoRange,
ScanChannel,
Infrared,
HeightAboveGround
HeightAboveGround,
ClassFlags
};
} // namespace Id
typedef std::vector<Id::Enum> IdList;
Expand Down Expand Up @@ -321,6 +322,8 @@ inline std::string description(Id::Enum id)
return "Near Infrared";
case Id::HeightAboveGround:
return "Height above ground";
case Id::ClassFlags:
return "Classification Flags";
case Id::Unknown:
return "";
}
Expand Down Expand Up @@ -437,6 +440,8 @@ inline Id::Enum id(std::string s)
return Id::Infrared;
else if (s == "HEIGHTABOVEGROUND")
return Id::HeightAboveGround;
else if (s == "CLASSFLAGS")
return Id::ClassFlags;
return Id::Unknown;
}

Expand Down Expand Up @@ -549,6 +554,8 @@ inline std::string name(Id::Enum id)
return "Infrared";
case Id::HeightAboveGround:
return "HeightAboveGround";
case Id::ClassFlags:
return "ClassFlags";
case Id::Unknown:
return "";
}
Expand Down Expand Up @@ -668,6 +675,8 @@ inline Type::Enum defaultType(Id::Enum id)
return Unsigned16;
case Id::HeightAboveGround:
return Double;
case Id::ClassFlags:
return Unsigned8;
case Id::Unknown:
throw pdal_error("No type for undefined dimension ID.");
}
Expand Down
41 changes: 36 additions & 5 deletions include/pdal/Geometry.hpp
Expand Up @@ -96,7 +96,8 @@ static void finish()
namespace Geometry
{

static std::string smoothPolygon(const std::string& wkt, double tolerance, uint32_t precision)
static std::string smoothPolygon(const std::string& wkt, double tolerance,
uint32_t precision, double area_threshold)
{
GEOSContextHandle_t env = init();

Expand All @@ -115,15 +116,30 @@ static std::string smoothPolygon(const std::string& wkt, double tolerance, uint3
for (int n = 0; n < numGeom; ++n)
{
const GEOSGeometry* m = GEOSGetGeometryN_r(env, smoothed, n);
if (!m)
throw pdal::pdal_error("Unable to Get GeometryN");

const GEOSGeometry* ering = GEOSGetExteriorRing_r(env, m);
if (!ering)
throw pdal::pdal_error("Unable to Get Exterior Ring");

GEOSGeometry* exterior = GEOSGeom_clone_r(env, GEOSGetExteriorRing_r(env, m));
if (!exterior)
throw pdal::pdal_error("Unable to clone exterior ring!");

std::vector<GEOSGeometry*> keep_rings;
int numRings = GEOSGetNumInteriorRings_r(env, m);
double area_threshold = 6 * tolerance * tolerance;
for (int i = 0; i < numRings; ++i)
{
double area(0.0);
GEOSGeometry* cring = GEOSGeom_clone_r(env, GEOSGetInteriorRingN_r(env, smoothed, i));

const GEOSGeometry* iring = GEOSGetInteriorRingN_r(env, m, i);
if (!iring)
throw pdal::pdal_error("Unable to Get Interior Ring");

GEOSGeometry* cring = GEOSGeom_clone_r(env, iring);
if (!cring)
throw pdal::pdal_error("Unable to clone interior ring!");
GEOSGeometry* aring = GEOSGeom_createPolygon_r(env, cring, NULL, 0);

int errored = GEOSArea_r(env, aring, &area);
Expand Down Expand Up @@ -171,16 +187,31 @@ static double computeArea(const std::string& wkt)
finish();
return output;
}

} // namespace Geometry

#else

static std::string smoothPolygon(const std::string& wkt, double tolerance)
namespace Geometry
{

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
static std::string smoothPolygon(const std::string& wkt, double tolerance,
uint32_t precision, double area_threshold)
{
throw pdal_error("Can't call smoothPolygon. PDAL not built with GEOS.");
}

#endif
static double computeArea(const std::string& wkt)
{
throw pdal_error("Can't call computeArea. PDAL not built with GEOS.");
}
#pragma GCC diagnostic pop

} // namespace Geometry

#endif

} // namespace pdal

9 changes: 8 additions & 1 deletion include/pdal/util/OStream.hpp
Expand Up @@ -74,6 +74,8 @@ class PDAL_DLL OStream
m_fstream = NULL;
m_stream = NULL;
}
bool isOpen() const
{ return (bool)m_stream; }
void flush()
{ m_stream->flush(); }
operator bool ()
Expand Down Expand Up @@ -209,7 +211,12 @@ class OStreamMarker
{
public:
OStreamMarker(OStream& stream) : m_stream(stream)
{ m_pos = m_stream.position(); }
{
if (m_stream.isOpen())
m_pos = m_stream.position();
else
m_pos = 0;
}

void mark()
{ m_pos = m_stream.position(); }
Expand Down
5 changes: 4 additions & 1 deletion io/bpf/BpfReader.cpp
Expand Up @@ -179,8 +179,11 @@ bool BpfReader::readUlemFiles()
{
BpfUlemFile file;
while (file.read(m_stream))
m_metadata.addEncoded(file.m_filename,
{
MetadataNode m = m_metadata.add("bundled_file");
m.addEncoded(file.m_filename,
(const unsigned char *)file.m_buf.data(), file.m_len);
}
return (bool)m_stream;
}

Expand Down
5 changes: 4 additions & 1 deletion io/las/LasReader.cpp
Expand Up @@ -606,7 +606,10 @@ void LasReader::addDimensions(PointLayoutPtr layout)
if (m_lasHeader.hasInfrared())
layout->registerDim(Id::Infrared);
if (m_lasHeader.versionAtLeast(1, 4))
{
layout->registerDim(Id::ScanChannel);
layout->registerDim(Id::ClassFlags);
}

for (auto& dim : m_extraDims)
{
Expand Down Expand Up @@ -863,13 +866,13 @@ void LasReader::loadPointV14(PointRef& point, char *buf, size_t bufsize)
uint8_t scanDirFlag = (flags >> 6) & 0x01;
uint8_t flight = (flags >> 7) & 0x01;

//ABELL - Need to do something with the classFlags;
point.setField(Dimension::Id::X, x);
point.setField(Dimension::Id::Y, y);
point.setField(Dimension::Id::Z, z);
point.setField(Dimension::Id::Intensity, intensity);
point.setField(Dimension::Id::ReturnNumber, returnNum);
point.setField(Dimension::Id::NumberOfReturns, numReturns);
point.setField(Dimension::Id::ClassFlags, classFlags);
point.setField(Dimension::Id::ScanChannel, scanChannel);
point.setField(Dimension::Id::ScanDirectionFlag, scanDirFlag);
point.setField(Dimension::Id::EdgeOfFlightLine, flight);
Expand Down
13 changes: 10 additions & 3 deletions io/las/LasWriter.cpp
Expand Up @@ -320,13 +320,14 @@ void LasWriter::prepOutput(std::ostream *outStream, const SpatialReference& srs)
// Use stage SRS if provided.
m_srs = getSpatialReference().empty() ? srs : getSpatialReference();

handleHeaderForwards(m_forwardMetadata);

// Filling the header here gives the VLR functions below easy access to
// the version information and so on.
fillHeader();

// Spatial reference can potentially change for multiple output files.
setVlrsFromSpatialRef();
handleHeaderForwards(m_forwardMetadata);
setVlrsFromMetadata(m_forwardMetadata);

m_summaryData.reset(new SummaryData());
Expand Down Expand Up @@ -709,6 +710,7 @@ void LasWriter::openCompression()

bool LasWriter::processOne(PointRef& point)
{
//ABELL - Need to do something about auto offset.
LeInserter ostream(m_pointBuf.data(), m_pointBuf.size());

if (!fillPointBuf(point, ostream))
Expand Down Expand Up @@ -861,12 +863,17 @@ bool LasWriter::fillPointBuf(PointRef& point, LeInserter& ostream)
point.getFieldAs<uint8_t>(Id::ScanDirectionFlag);
uint8_t edgeOfFlightLine =
point.getFieldAs<uint8_t>(Id::EdgeOfFlightLine);

if (has14Format)
{
uint8_t bits = returnNumber | (numberOfReturns << 4);
ostream << bits;
bits = (scanChannel << 4) | (scanDirectionFlag << 6) |
(edgeOfFlightLine << 7);

uint8_t classFlags = point.getFieldAs<uint8_t>(Id::ClassFlags);
bits = (classFlags & 0x0F) |
((scanChannel & 0x03) << 4) |
((scanDirectionFlag & 0x01) << 6) |
((edgeOfFlightLine & 0x01) << 7);
ostream << bits;
}
else
Expand Down
2 changes: 1 addition & 1 deletion io/las/LasWriter.hpp
Expand Up @@ -108,7 +108,7 @@ class PDAL_DLL LasWriter : public FlexWriter
// MSVC doesn't see numeric_limits::max() as constexpr do doesn't allow
// it as defaults for templates. Remove when possible.
NumHeaderVal<uint16_t, 0, 65535> m_filesourceId;
NumHeaderVal<uint16_t, 0, 15> m_globalEncoding;
NumHeaderVal<uint16_t, 0, 31> m_globalEncoding;
UuidHeaderVal m_projectId;
StringHeaderVal<32> m_systemId;
StringHeaderVal<32> m_softwareId;
Expand Down

0 comments on commit c94c31d

Please sign in to comment.