Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into pdal-tindex
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed May 1, 2015
2 parents 20d3f78 + a46515c commit 4737de3
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 112 deletions.
2 changes: 1 addition & 1 deletion include/pdal/DbWriter.hpp
Expand Up @@ -52,7 +52,7 @@ class PDAL_DLL DbWriter : public Writer
DbWriter()
{}

virtual void setAutoOffset(const PointViewPtr view);
virtual void setAutoXForm(const PointViewPtr view);
XMLDimList dbDimTypes() const
{ return m_dbDims; }
size_t readField(const PointView& view, char *pos, Dimension::Id::Enum id,
Expand Down
83 changes: 18 additions & 65 deletions include/pdal/PointView.hpp
Expand Up @@ -413,24 +413,17 @@ inline T PointView::getFieldAs(Dimension::Id::Enum dim,
val = 0;
break;
}
#ifdef PDAL_COMPILER_MSVC
// warning C4127: conditional expression is constant
#pragma warning(push)
#pragma warning(disable:4127)
#endif
try

if (Utils::inRange<T>(val))
{
if (std::is_same<T, double>::value)
retval = val;
else
if (std::is_integral<T>::value)
{
if (std::is_integral<T>::value == true )
retval = boost::numeric_cast<T>(lround(val));
else
retval = boost::numeric_cast<T>(val);
val = Utils::sround(val);
}

retval = static_cast<T>(val);
}
catch (boost::numeric::bad_numeric_cast& )
else
{
std::ostringstream oss;
oss << "Unable to fetch data and convert as requested: ";
Expand All @@ -439,70 +432,30 @@ inline T PointView::getFieldAs(Dimension::Id::Enum dim,
"(" << (double)val << ") -> " << Utils::typeidName<T>();
throw pdal_error(oss.str());
}

return retval;
#ifdef PDAL_COMPILER_MSVC
// warning C4127: conditional expression is constant
#pragma warning(pop)
#endif
}



template<typename T_IN, typename T_OUT>
bool PointView::convertAndSet(Dimension::Id::Enum dim, PointId idx, T_IN in)
{
// This mess, instead of just using boost::numeric_cast, is here to:
// 1) Prevent the throwing of exceptions. The entrance/exit of the try
// block seemed somewhat expensive.
// 2) Round to nearest instead of truncation without rounding before
// invoking the converter.
//
using namespace boost;
static bool ok;

struct RangeHandler
bool success(false);

if (Utils::inRange<T_IN, T_OUT>(in))
{
void operator() (numeric::range_check_result r)
if (std::is_integral<T_OUT>::value)
{
ok = (r == numeric::cInRange);
in = Utils::sround(in);
}
};

T_OUT out;

typedef numeric::conversion_traits<T_OUT, T_IN> conv_traits;
typedef numeric::numeric_cast_traits<T_OUT, T_IN> cast_traits;
typedef numeric::converter<
T_OUT,
T_IN,
conv_traits,
RangeHandler,
numeric::RoundEven<T_IN>,
numeric::raw_converter<conv_traits>,
typename cast_traits::range_checking_policy>
localConverter;

#ifdef PDAL_COMPILER_MSVC
// warning C4127: conditional expression is constant
#pragma warning(push)
#pragma warning(disable:4127)
#endif
ok = true;
// This is an optimization.
if (std::is_same<T_IN, T_OUT>::value == true)
out = in;
else
out = localConverter::convert(in);
if (!ok)
return false;

#ifdef PDAL_COMPILER_MSVC
// warning C4127: conditional expression is constant
#pragma warning(pop)
#endif
const T_OUT out(static_cast<T_OUT>(in));
setFieldInternal(dim, idx, &out);
success = true;
}

setFieldInternal(dim, idx, (void *)&out);
return true;
return success;
}


Expand Down
24 changes: 24 additions & 0 deletions include/pdal/Utils.hpp
Expand Up @@ -353,6 +353,30 @@ namespace Utils
out.rdbuf(redir.m_buf);
redir.m_out->close();
}

// Determine whether a value of a given input type may be safely
// statically casted to the given output type without over/underflow. If
// the output type is integral, inRange() will determine whether the
// rounded input value, rather than truncated, may be safely converted.
template<typename T_OUT>
bool inRange(double in)
{
if (std::is_integral<T_OUT>::value)
{
in = sround(in);
}

return std::is_same<double, T_OUT>::value ||
(in >= static_cast<double>(std::numeric_limits<T_OUT>::lowest()) &&
in <= static_cast<double>(std::numeric_limits<T_OUT>::max()));
}

template<typename T_IN, typename T_OUT>
bool inRange(T_IN in)
{
return std::is_same<T_IN, T_OUT>::value ||
inRange<T_OUT>(static_cast<double>(in));
}
};

} // namespace pdal
Expand Down
2 changes: 1 addition & 1 deletion include/pdal/Writer.hpp
Expand Up @@ -69,7 +69,7 @@ class PDAL_DLL Writer : public Stage
XForm m_zXform;
StringList m_outputDims;

virtual void setAutoOffset(const PointViewPtr view);
virtual void setAutoXForm(const PointViewPtr view);

private:
virtual PointViewSet run(PointViewPtr view)
Expand Down
2 changes: 1 addition & 1 deletion io/bpf/BpfWriter.cpp
Expand Up @@ -144,7 +144,7 @@ void BpfWriter::loadBpfDimensions(PointLayoutPtr layout)

void BpfWriter::write(const PointViewPtr dataShared)
{
setAutoOffset(dataShared);
setAutoXForm(dataShared);

// Avoid reference count overhead internally.
const PointView* data(dataShared.get());
Expand Down
7 changes: 5 additions & 2 deletions io/las/LasWriter.cpp
Expand Up @@ -506,7 +506,7 @@ void LasWriter::openCompression()

void LasWriter::write(const PointViewPtr view)
{
setAutoOffset(view);
setAutoXForm(view);

size_t pointLen = m_lasHeader.pointLen();

Expand Down Expand Up @@ -708,9 +708,12 @@ void LasWriter::done(PointTableRef table)
out << evlr;
}

// Reset the offset since it may have been auto-computed
// Reset the offset/scale since it may have been auto-computed
m_lasHeader.setOffset(m_xXform.m_offset, m_yXform.m_offset,
m_zXform.m_offset);
m_lasHeader.setScale(m_xXform.m_scale, m_yXform.m_scale,
m_zXform.m_scale);

// We didn't know the point count until we go through the points.
m_lasHeader.setPointCount(m_numPointsWritten);
// The summary is calculated as points are written.
Expand Down
2 changes: 1 addition & 1 deletion plugins/nitf/io/MetadataReader.hpp
Expand Up @@ -45,7 +45,7 @@
# pragma GCC diagnostic ignored "-Wcast-qual"
// The following pragma doesn't actually work:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653
# pragma GCC diagnostic ignored "-Wliteral-suffix"
//# pragma GCC diagnostic ignored "-Wliteral-suffix"
#endif
#ifdef PDAL_COMPILER_CLANG
# pragma clang diagnostic push
Expand Down
2 changes: 1 addition & 1 deletion plugins/nitf/io/NitfFile.hpp
Expand Up @@ -45,7 +45,7 @@
# pragma GCC diagnostic ignored "-Wcast-qual"
// The following pragma doesn't actually work:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653
# pragma GCC diagnostic ignored "-Wliteral-suffix"
//# pragma GCC diagnostic ignored "-Wliteral-suffix"
#endif
#ifdef PDAL_COMPILER_CLANG
# pragma clang diagnostic push
Expand Down
2 changes: 1 addition & 1 deletion plugins/nitf/io/NitfWriter.cpp
Expand Up @@ -49,7 +49,7 @@
# pragma GCC diagnostic ignored "-Wcast-qual"
// The following pragma doesn't actually work:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653
# pragma GCC diagnostic ignored "-Wliteral-suffix"
//# pragma GCC diagnostic ignored "-Wliteral-suffix"
#endif
#include <ogr_spatialref.h>
#include <cpl_conv.h>
Expand Down
2 changes: 1 addition & 1 deletion plugins/nitf/io/tre_plugins.cpp
Expand Up @@ -41,7 +41,7 @@
# pragma GCC diagnostic ignored "-Wcast-qual"
// The following pragma doesn't actually work:
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653
# pragma GCC diagnostic ignored "-Wliteral-suffix"
//# pragma GCC diagnostic ignored "-Wliteral-suffix"
#endif
#ifdef PDAL_COMPILER_CLANG
# pragma clang diagnostic push
Expand Down
7 changes: 4 additions & 3 deletions plugins/oci/io/OciWriter.cpp
Expand Up @@ -590,7 +590,7 @@ void OciWriter::createPCEntry()
OCILobLocator *schema_locator;
OCILobLocator *boundary_locator;

statement->WriteCLob(&schema_locator, (char *)schemaData.c_str());
statement->WriteCLob(&schema_locator, const_cast<char *>(schemaData.c_str()));
statement->BindClob(&schema_locator);

std::ostringstream wkt_s;
Expand Down Expand Up @@ -623,7 +623,8 @@ void OciWriter::createPCEntry()

if (!m_baseTableBoundaryColumn.empty())
{
statement->WriteCLob(&boundary_locator, (char *)wkt_s.str().c_str());
statement->WriteCLob(&boundary_locator,
const_cast<char *>(wkt_s.str().c_str()));
statement->BindClob(&boundary_locator);
statement->Bind((int*)&m_srid);
}
Expand Down Expand Up @@ -723,7 +724,7 @@ void OciWriter::write(const PointViewPtr view)
// While we'd like a separate offset for each tile, the schema is stored
// for the entire point cloud.
if (m_lastBlockId == 0)
setAutoOffset(view);
setAutoXForm(view);
writeInit();
writeTile(view);
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/oci/test/OCITest.cpp
Expand Up @@ -55,7 +55,7 @@ GTEST_API_ int main(int argc, char **argv)
if (Utils::startsWith(s, "--connection"))
{
auto pos = s.find_first_of('=');
if (pos == string::npos)
if (pos == std::string::npos)
throw pdal_error("Invalid command line connection string.");
TestConfig::g_oracle_connection = s.substr(pos + 1);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/DbWriter.cpp
Expand Up @@ -136,11 +136,11 @@ void DbWriter::ready(PointTableRef /*table*/)


/// Make sure that computed offsets are stored in the schema.
void DbWriter::setAutoOffset(const PointViewPtr view)
void DbWriter::setAutoXForm(const PointViewPtr view)
{
using namespace Dimension;

Writer::setAutoOffset(view);
Writer::setAutoXForm(view);
for (auto& xmlDim : m_dbDims)
{
if (xmlDim.m_dimType.m_id == Id::X)
Expand Down

0 comments on commit 4737de3

Please sign in to comment.