Skip to content

Commit

Permalink
Catch up to master
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Oct 24, 2018
2 parents 0a571ff + c07438e commit 9b98eab
Show file tree
Hide file tree
Showing 30 changed files with 289 additions and 196 deletions.
4 changes: 2 additions & 2 deletions filters/DividerFilter.cpp
Expand Up @@ -80,9 +80,9 @@ std::ostream& operator<<(std::ostream& out, const DividerFilter::Mode& mode)

void DividerFilter::addArgs(ProgramArgs& args)
{
args.add("mode", "A mode of partition will write sequential points "
args.add("mode", "A mode of 'partition' will write sequential points "
"to an output view until the view meets its predetermined size. "
"round_robin mode will iterate through the output views as it "
"'round_robin' mode will iterate through the output views as it "
"writes sequential points.", m_mode, DividerFilter::Mode::Partition);
m_cntArg = &args.add("count", "Number of output views", m_size);
m_capArg = &args.add("capacity", "Maximum number of points in each "
Expand Down
4 changes: 3 additions & 1 deletion io/HeaderVal.hpp
Expand Up @@ -104,14 +104,16 @@ inline std::istream& operator>>(std::istream& in, NumHeaderVal<T, MIN, MAX>& h)
return in;
}


template<typename T, T MIN, T MAX>
inline std::ostream& operator<<(std::ostream& out,
const NumHeaderVal<T, MIN, MAX>& h)
{
out << h.val();
out << Utils::toString(h.val());
return out;
}


class DoubleHeaderVal : public BaseHeaderVal<double>
{
public:
Expand Down
43 changes: 28 additions & 15 deletions pdal/PointView.hpp
Expand Up @@ -441,54 +441,67 @@ inline T PointView::getFieldAs(Dimension::Id dim,
{
assert(pointIndex < m_size);
T retval;
bool ok = false;
const Dimension::Detail *dd = layout()->dimDetail(dim);
double val;
Everything e;

switch (dd->type())
{
case Dimension::Type::Float:
val = getFieldInternal<float>(dim, pointIndex);
e.f = getFieldInternal<float>(dim, pointIndex);
ok = Utils::numericCast(e.f, retval);
break;
case Dimension::Type::Double:
val = getFieldInternal<double>(dim, pointIndex);
e.d = getFieldInternal<double>(dim, pointIndex);
ok = Utils::numericCast(e.d, retval);
break;
case Dimension::Type::Signed8:
val = getFieldInternal<int8_t>(dim, pointIndex);
e.s8 = getFieldInternal<int8_t>(dim, pointIndex);
ok = Utils::numericCast(e.s8, retval);
break;
case Dimension::Type::Signed16:
val = getFieldInternal<int16_t>(dim, pointIndex);
e.s16 = getFieldInternal<int16_t>(dim, pointIndex);
ok = Utils::numericCast(e.s16, retval);
break;
case Dimension::Type::Signed32:
val = getFieldInternal<int32_t>(dim, pointIndex);
e.s32 = getFieldInternal<int32_t>(dim, pointIndex);
ok = Utils::numericCast(e.s32, retval);
break;
case Dimension::Type::Signed64:
val = static_cast<double>(getFieldInternal<int64_t>(dim, pointIndex));
e.s64 = getFieldInternal<int64_t>(dim, pointIndex);
ok = Utils::numericCast(e.s64, retval);
break;
case Dimension::Type::Unsigned8:
val = getFieldInternal<uint8_t>(dim, pointIndex);
e.u8 = getFieldInternal<uint8_t>(dim, pointIndex);
ok = Utils::numericCast(e.u8, retval);
break;
case Dimension::Type::Unsigned16:
val = getFieldInternal<uint16_t>(dim, pointIndex);
e.u16 = getFieldInternal<uint16_t>(dim, pointIndex);
ok = Utils::numericCast(e.u16, retval);
break;
case Dimension::Type::Unsigned32:
val = getFieldInternal<uint32_t>(dim, pointIndex);
e.u32 = getFieldInternal<uint32_t>(dim, pointIndex);
ok = Utils::numericCast(e.u32, retval);
break;
case Dimension::Type::Unsigned64:
val = static_cast<double>(getFieldInternal<uint64_t>(dim, pointIndex));
e.u64 = getFieldInternal<uint64_t>(dim, pointIndex);
ok = Utils::numericCast(e.u64, retval);
break;
case Dimension::Type::None:
default:
val = 0;
ok = true;
retval = 0;
break;
}
} // switch

if (!Utils::numericCast(val, retval))
if (!ok)
{
std::ostringstream oss;
oss << "Unable to fetch data and convert as requested: ";
oss << Dimension::name(dim) << ":" <<
Dimension::interpretationName(dd->type()) <<
"(" << (double)val << ") -> " << Utils::typeidName<T>();
"(" << Utils::toDouble(e, dd->type()) << ") -> " <<
Utils::typeidName<T>();
throw pdal_error(oss.str());
}

Expand Down
22 changes: 22 additions & 0 deletions pdal/util/Utils.hpp
Expand Up @@ -728,6 +728,28 @@ namespace Utils
return false;
}

/**
Convert a numeric value from double to float. Specialization to handle
NaN.
\param in Value to convert.
\param out Converted value.
\return \c true if the conversion was successful, \c false if the
datatypes/input value don't allow conversion.
*/
template<>
inline bool numericCast(double in, float& out)
{
if ((in <= static_cast<double>((std::numeric_limits<float>::max)()) &&
in >= static_cast<double>(std::numeric_limits<float>::lowest())) ||
std::isnan(in))
{
out = static_cast<float>(in);
return true;
}
return false;
}

/**
Convert a value to its string representation by writing to a stringstream.
Expand Down
2 changes: 1 addition & 1 deletion plugins/greyhound/io/GreyhoundWriter.cpp
Expand Up @@ -142,7 +142,7 @@ void GreyhoundWriter::write(const PointViewPtr view)
m_params["compress"] = true;

std::vector<char> comp;
comp.reserve(static_cast<float>(data.size()) * 0.2);
comp.reserve(data.size() / 5);

auto cb([&comp](char* p, std::size_t s)
{
Expand Down
16 changes: 8 additions & 8 deletions plugins/icebridge/test/IcebridgeReaderTest.cpp
Expand Up @@ -48,8 +48,8 @@ template <typename T>
void checkDimension(const PointView& data, std::size_t index,
Dimension::Id dim, T expected)
{
float actual = data.getFieldAs<T>(dim, index);
EXPECT_FLOAT_EQ(expected, actual);
T actual = data.getFieldAs<T>(dim, index);
EXPECT_FLOAT_EQ((float)expected, (float)actual);
}

void checkPoint(
Expand Down Expand Up @@ -108,9 +108,9 @@ TEST(IcebridgeReaderTest, testRead)
checkPoint(
*view,
0,
141437548, // time
82.605319, // latitude
-58.593811, // longitude
1414375e2f, // time
82.60531f, // latitude
-58.59381f, // longitude
18.678, // elevation
2408, // xmtSig
181, // rcvSig
Expand All @@ -124,9 +124,9 @@ TEST(IcebridgeReaderTest, testRead)
checkPoint(
*view,
1,
141437548, // time
82.605287, // latitude
-58.595123, // longitude
1414375e2f, // time
82.60528f, // latitude
-58.59512f, // longitude
18.688, // elevation
2642, // xmtSig
173, // rcvSig
Expand Down
9 changes: 8 additions & 1 deletion plugins/nitf/CMakeLists.txt
Expand Up @@ -26,7 +26,10 @@ target_include_directories(${reader_libname} PRIVATE
${PDAL_VENDOR_DIR}/pdalboost
${PDAL_JSONCPP_INCLUDE_DIR}
${ROOT_DIR})

if (WIN32)
target_compile_definitions(${reader_libname} PRIVATE
NOMINMAX)
endif()
#
# NITF Writer
#
Expand All @@ -45,6 +48,10 @@ target_include_directories(${writer_libname} PRIVATE
${PDAL_VENDOR_DIR}/pdalboost
${PDAL_JSONCPP_INCLUDE_DIR}
${ROOT_DIR})
if (WIN32)
target_compile_definitions(${writer_libname} PRIVATE
NOMINMAX)
endif()

if (WITH_TESTS)
PDAL_ADD_TEST(pdal_io_nitf_writer_test
Expand Down
2 changes: 1 addition & 1 deletion plugins/nitf/io/NitfWriter.cpp
Expand Up @@ -121,7 +121,7 @@ void NitfWriter::doneFile()
finishOutput();

std::streambuf *buf = m_oss.rdbuf();
long size = buf->pubseekoff(0, m_oss.end);
std::streamoff size = buf->pubseekoff(0, m_oss.end);
buf->pubseekoff(0, m_oss.beg);

std::vector<char> bytes(size);
Expand Down
2 changes: 1 addition & 1 deletion plugins/nitf/test/NitfReaderTest.cpp
Expand Up @@ -58,7 +58,7 @@ TEST(NitfReaderTest, test_one)
PointTable table;

Stage* nitf_reader(f.createStage("readers.nitf"));
EXPECT_NE((int)nitf_reader,0);
EXPECT_TRUE(nitf_reader != nullptr);
nitf_reader->setOptions(nitf_opts);
nitf_reader->prepare(table);
PointViewSet pbSet = nitf_reader->execute(table);
Expand Down
4 changes: 3 additions & 1 deletion plugins/pgpointcloud/io/PgWriter.cpp
Expand Up @@ -450,7 +450,9 @@ void PgWriter::writeTile(const PointViewPtr view)

std::ostringstream options;

uint32_t num_points = htobe32(view->size());
if (view->size() > (std::numeric_limits<uint32_t>::max)())
throwError("Too many points for tile.");
uint32_t num_points = htobe32(static_cast<uint32_t>(view->size()));
int32_t pcid = htobe32(m_pcid);
CompressionType compression_v = CompressionType::None;
uint32_t compression = htobe32(static_cast<uint32_t>(compression_v));
Expand Down
2 changes: 1 addition & 1 deletion plugins/python/io/NumpyReader.cpp
Expand Up @@ -303,7 +303,7 @@ void NumpyReader::createFields(PointLayoutPtr layout)

m_numFields = 0;
if (m_dtype->fields != Py_None)
m_numFields = PyDict_Size(m_dtype->fields);
m_numFields = static_cast<int>(PyDict_Size(m_dtype->fields));

// Array isn't structured - just a bunch of data.
if (m_numFields <= 0)
Expand Down
56 changes: 28 additions & 28 deletions plugins/python/test/PythonFilterTest.cpp
Expand Up @@ -708,11 +708,11 @@ TEST(PLangTest, PLangTest_outs)
void *output = meth.extractResult("X", Dimension::Type::Double, arrSize);

double *d = (double *)output;
EXPECT_FLOAT_EQ(*d++, 1.0);
EXPECT_FLOAT_EQ(*d++, 1.0);
EXPECT_FLOAT_EQ(*d++, 1.0);
EXPECT_FLOAT_EQ(*d++, 1.0);
EXPECT_FLOAT_EQ(*d++, 1.0);
EXPECT_DOUBLE_EQ(*d++, 1.0);
EXPECT_DOUBLE_EQ(*d++, 1.0);
EXPECT_DOUBLE_EQ(*d++, 1.0);
EXPECT_DOUBLE_EQ(*d++, 1.0);
EXPECT_DOUBLE_EQ(*d++, 1.0);
}


Expand Down Expand Up @@ -763,19 +763,19 @@ TEST(PLangTest, PLangTest_aliases)
size_t arrSize;
void *output = meth.extractResult("Y", Dimension::Type::Double, arrSize);
double *d = (double *)output;
EXPECT_FLOAT_EQ(*d++, 2.0);
EXPECT_FLOAT_EQ(*d++, 4.0);
EXPECT_FLOAT_EQ(*d++, 6.0);
EXPECT_FLOAT_EQ(*d++, 8.0);
EXPECT_FLOAT_EQ(*d++, 10.0);
EXPECT_DOUBLE_EQ(*d++, 2.0);
EXPECT_DOUBLE_EQ(*d++, 4.0);
EXPECT_DOUBLE_EQ(*d++, 6.0);
EXPECT_DOUBLE_EQ(*d++, 8.0);
EXPECT_DOUBLE_EQ(*d++, 10.0);

output = meth.extractResult("prefix.Y", Dimension::Type::Double, arrSize);
d = (double *)output;
EXPECT_FLOAT_EQ(*d++, 2.0);
EXPECT_FLOAT_EQ(*d++, 4.0);
EXPECT_FLOAT_EQ(*d++, 6.0);
EXPECT_FLOAT_EQ(*d++, 8.0);
EXPECT_FLOAT_EQ(*d++, 10.0);
EXPECT_DOUBLE_EQ(*d++, 2.0);
EXPECT_DOUBLE_EQ(*d++, 4.0);
EXPECT_DOUBLE_EQ(*d++, 6.0);
EXPECT_DOUBLE_EQ(*d++, 8.0);
EXPECT_DOUBLE_EQ(*d++, 10.0);
}

{
Expand Down Expand Up @@ -854,11 +854,11 @@ TEST(PLangTest, PLangTest_reentry)
void *output = meth.extractResult("Y", Dimension::Type::Double, arrSize);

double *d = (double *)output;
EXPECT_FLOAT_EQ(*d++, 1.0);
EXPECT_FLOAT_EQ(*d++, 2.0);
EXPECT_FLOAT_EQ(*d++, 3.0);
EXPECT_FLOAT_EQ(*d++, 4.0);
EXPECT_FLOAT_EQ(*d++, 5.0);
EXPECT_DOUBLE_EQ(*d++, 1.0);
EXPECT_DOUBLE_EQ(*d++, 2.0);
EXPECT_DOUBLE_EQ(*d++, 3.0);
EXPECT_DOUBLE_EQ(*d++, 4.0);
EXPECT_DOUBLE_EQ(*d++, 5.0);
}

{
Expand All @@ -870,11 +870,11 @@ TEST(PLangTest, PLangTest_reentry)
void *output = meth.extractResult("Y", Dimension::Type::Double, arrSize);

double *d = (double *)output;
EXPECT_FLOAT_EQ(*d++, 11.0);
EXPECT_FLOAT_EQ(*d++, 21.0);
EXPECT_FLOAT_EQ(*d++, 31.0);
EXPECT_FLOAT_EQ(*d++, 41.0);
EXPECT_FLOAT_EQ(*d++, 51.0);
EXPECT_DOUBLE_EQ(*d++, 11.0);
EXPECT_DOUBLE_EQ(*d++, 21.0);
EXPECT_DOUBLE_EQ(*d++, 31.0);
EXPECT_DOUBLE_EQ(*d++, 41.0);
EXPECT_DOUBLE_EQ(*d++, 51.0);
}
}

Expand Down Expand Up @@ -965,9 +965,9 @@ PointViewPtr makeTestView(PointTableRef table, point_count_t cnt = 17)
// write the data into the view
for (PointId i = 0; i < cnt; i++)
{
const uint8_t x = (uint8_t)(i + 1);
const int32_t y = i * 10;
const double z = i * 100;
const uint8_t x = static_cast<uint8_t>(i + 1);
const int32_t y = static_cast<int32_t>(i * 10);
const double z = static_cast<double>(i * 100);

view->setField(Dimension::Id::Classification, i, x);
view->setField(Dimension::Id::X, i, y);
Expand Down
2 changes: 2 additions & 0 deletions plugins/rxp/io/RxpReader.cpp
Expand Up @@ -91,6 +91,8 @@ void RxpReader::addArgs(ProgramArgs& args)
args.add("reflectance_as_intensity", "Reflectance as intensity", m_reflectanceAsIntensity, DEFAULT_REFLECTANCE_AS_INTENSITY);
args.add("min_reflectance", "Minimum reflectance", m_minReflectance, DEFAULT_MIN_REFLECTANCE);
args.add("max_reflectance", "Maximum reflectance", m_maxReflectance, DEFAULT_MAX_REFLECTANCE);
args.add("minimal", "Load only X, Y, Z, time and Intensity dimensions "
"to save memory", m_minimal);
}

void RxpReader::initialize()
Expand Down
2 changes: 1 addition & 1 deletion plugins/sqlite/io/SQLiteWriter.cpp
Expand Up @@ -426,7 +426,7 @@ void SQLiteWriter::CreateCloud()
m_session->insert(oss.str(), rs);
oss.str("");

long id = m_session->last_row_id();
int32_t id = static_cast<int32_t>(m_session->last_row_id());
m_obj_id = id;

log()->get(LogLevel::Debug) << "Point cloud id was " << id << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions test/unit/PointTableTest.cpp
Expand Up @@ -166,9 +166,9 @@ TEST(PointTable, userView)
double y = customView.getFieldAs<double>(Dimension::Id::Y, id);
double z = customView.getFieldAs<double>(Dimension::Id::Z, id);

EXPECT_FLOAT_EQ(xDef, x);
EXPECT_FLOAT_EQ(yDef, y);
EXPECT_FLOAT_EQ(zDef, z);
EXPECT_DOUBLE_EQ(xDef, x);
EXPECT_DOUBLE_EQ(yDef, y);
EXPECT_DOUBLE_EQ(zDef, z);
};

reader.setReadCb(readCb);
Expand Down

0 comments on commit 9b98eab

Please sign in to comment.