Skip to content

Commit

Permalink
provide a method to copy like- dimensions from one PointBuffer to ano…
Browse files Browse the repository at this point in the history
…ther (static)
  • Loading branch information
hobu committed Mar 15, 2013
1 parent e3fb963 commit d603cf8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
13 changes: 11 additions & 2 deletions include/pdal/PointBuffer.hpp
Expand Up @@ -278,7 +278,7 @@ class PDAL_DLL PointBuffer
return m_arraySize;
}

static void scaleData(PointBuffer& source_buffer,
static void scaleData(PointBuffer const& source_buffer,
PointBuffer& destination_buffer,
Dimension const& source_dimension,
Dimension const& destination_dimension,
Expand Down Expand Up @@ -328,6 +328,15 @@ class PDAL_DLL PointBuffer
boost::property_tree::ptree toPTree() const;

pdal::Bounds<double> calculateBounds(bool bis3d=true) const;

/// Copies dimensions from the given PointBuff
static void copyLikeDimensions( PointBuffer const& source,
PointBuffer& destination,
boost::uint32_t source_starting_position,
boost::uint32_t destination_starting_position,
boost::uint32_t howMany);


/** @name private attributes
*/
private:
Expand Down Expand Up @@ -420,7 +429,7 @@ inline T const& PointBuffer::getField(pdal::Dimension const& dim, boost::uint32
# pragma warning(disable: 4244) // conversion from T1 to T2, possible loss of data
#endif

inline void PointBuffer::scaleData(PointBuffer& source,
inline void PointBuffer::scaleData(PointBuffer const& source,
PointBuffer& destination,
Dimension const& source_dimension,
Dimension const& destination_dimension,
Expand Down
55 changes: 55 additions & 0 deletions src/PointBuffer.cpp
Expand Up @@ -392,6 +392,61 @@ boost::property_tree::ptree PointBuffer::toPTree() const
return tree;
}

void PointBuffer::copyLikeDimensions( PointBuffer const& source,
PointBuffer& destination,
boost::uint32_t source_starting_position,
boost::uint32_t destination_starting_position,
boost::uint32_t howMany)
{

schema::index_by_index const& dimensions = destination.getSchema().getDimensions().get<schema::index>();
schema::index_by_index::size_type d(0);

assert(howMany < destination.getCapacity() - source_starting_position);
assert(howMany < source.getCapacity() - source_starting_position);

for (d = 0; d < dimensions.size(); ++d)
{
Dimension const& source_dim = dimensions[d];
Schema const& dest_schema = destination.getSchema();
boost::optional<Dimension const&> dest_dim_ptr = dest_schema.getDimensionOptional( source_dim.getName(),
source_dim.getNamespace());
if (!dest_dim_ptr)
{
continue;
}

Dimension const& dest_dim = *dest_dim_ptr;

for (boost::uint32_t i = 0; i < howMany; ++i)
{
if (dest_dim.getInterpretation() == source_dim.getInterpretation() &&
dest_dim.getByteSize() == source_dim.getByteSize() &&
pdal::Utils::compare_distance(dest_dim.getNumericScale(), source_dim.getNumericScale()) &&
pdal::Utils::compare_distance(dest_dim.getNumericOffset(), source_dim.getNumericOffset()) &&
dest_dim.getEndianness() == source_dim.getEndianness()
)
{
// FIXME: This test could produce false positives
boost::uint8_t* source_position = source.getData(source_starting_position+i) + source_dim.getByteOffset();
boost::uint8_t* destination_position = destination.getData(destination_starting_position + i) + dest_dim.getByteOffset();
memcpy(destination_position, source_position, source_dim.getByteSize());
}
else
{
throw pdal_error("Sclaing!");
PointBuffer::scaleData( source,
destination,
source_dim,
dest_dim,
source_starting_position + i,
destination_starting_position + i);
}
}
}


}

std::ostream& operator<<(std::ostream& ostr, const PointBuffer& pointBuffer)
{
Expand Down

0 comments on commit d603cf8

Please sign in to comment.