Skip to content

Commit

Permalink
addressed some comments and added docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemann16 committed Jan 26, 2021
1 parent 8551fa7 commit 77771e2
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 12 deletions.
31 changes: 31 additions & 0 deletions doc/stages/readers.draco.rst
@@ -0,0 +1,31 @@
.. _readers.draco:

readers.draco
=============

`Draco`_ is a library for compressing and decompressing 3D geometric meshes and
point clouds and was designed and built for compression efficiency and speed.
The code supports compressing points, connectivity information, texture coordinates,
color information, normals, and any other generic attributes associated with geometry.

Example
--------------------------------------------------------------------------------

.. code-block:: json
[
{
"type": "readers.draco",
"filename": "color.las"
}
]

Options
-------

filename
Input file name. [Required]

.. include:: reader_opts.rst

.. _Draco: https://github.com/google/draco
70 changes: 70 additions & 0 deletions doc/stages/writers.draco.rst
@@ -0,0 +1,70 @@
.. _writers.draco:

writers.draco
=============

`Draco`_ is a library for compressing and decompressing 3D geometric meshes and
point clouds and was designed and built for compression efficiency and speed.
The code supports compressing points, connectivity information, texture coordinates,
color information, normals, and any other generic attributes associated with geometry.

This writer aims to use the encoding feature of the Draco library to compress and
output Draco files.

Example
--------------------------------------------------------------------------------

This example will read in a las file and output a Draco encoded file, with options
to include PDAL dimensions X, Y, and Z as double, and explicitly setting quantization
levels of some of the Draco attributes.

.. code-block:: json
[
{
"type": "readers.las",
"filename": "color.las"
},
{
"type": "writers.draco",
"filename": "draco.drc",
"dimensions": {
"X": "double",
"Y": "double",
"Z": "double"
},
"quantization": {
"NORMAL": 8,
"TEX_COORD": 7,
"GENERIC": 6
}
}
]

Options
-------

filename
Output file name. [Required]

dimensions
A json map of PDAL dimensions to desired data types. Data types must be string
and must be available in `PDAL's Type specification`_.

quantization
A json map of Draco attributes to desired quantization levels. These levels
must be integers. Default quantization levels are below, and will be
overridden by any values placed in the options.

..code-block:: json
{
"POSITION": 11,
"NORMAL": 7,
"TEX_COORD": 10,
"COLOR": 8,
"GENERIC": 8
}



_PDAL's Type specification: https://github.com/PDAL/PDAL/blob/master/pdal/DimUtil.hpp
20 changes: 10 additions & 10 deletions plugins/draco/io/DracoReader.cpp
Expand Up @@ -131,10 +131,9 @@ void DracoReader::initialize()

void DracoReader::addOneDimension(Dimension::Id id, const draco::PointAttribute* attr, PointLayoutPtr layout, int index, int attNum)
{
//find corresponding pdal data type
draco::DataType dt = attr->data_type();
draco::GeometryAttribute::Type dracoAtt = attr->attribute_type();
Dimension::Type pdalType = getPdalType(dt);
int offset = draco::DataTypeLength(dt);

//add to pdal layout and dim vector
layout->registerDim(id);
Expand All @@ -146,31 +145,32 @@ void DracoReader::addDimensions(PointLayoutPtr layout)
{
using namespace draco;

log()->get(LogLevel::Debug) << "draco pc num_attributes: "
log()->get(LogLevel::Debug) << "Number of attributes in point cloud: "
<< m_pc->num_attributes() << std::endl;;

const GeometryMetadata *metadata = m_pc->GetMetadata();
//iterate and collect information on draco attributes
for (int i=0; i < m_pc->num_attributes(); ++i)
{
const PointAttribute* attr = m_pc->GetAttributeByUniqueId(i);
if (attr == nullptr)
throw new pdal_error("Invalid draco attribute configuration");
const AttributeMetadata* attr_metadata = m_pc->GetAttributeMetadataByAttributeId(i);

//get types
DataType dt = attr->data_type();
Dimension::Type pt = getPdalType(dt);
GeometryAttribute::Type at = attr->attribute_type();

int8_t nc = attr->num_components();
log()->get(LogLevel::Debug) << "named component: "
log()->get(LogLevel::Debug) << "Dimension read: "
<< GeometryAttribute::TypeToString(at)
<< " subcomponents: " << (int)nc << std::endl;;
<< ", Data type: " << Dimension::interpretationName(pt)
<< std::endl;;
std::string name;
if (attr_metadata)
{
log()->get(LogLevel::Debug) << "number of metadata entries: "
<< attr_metadata->num_entries()
<< std::endl;
attr_metadata->GetEntryString("name", &name);
log()->get(LogLevel::Debug) << "metadata name: "
log()->get(LogLevel::Debug) << " Generic type name: "
<< name
<< std::endl;
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/draco/io/DracoWriter.cpp
Expand Up @@ -210,7 +210,6 @@ void DracoWriter::parseDimensions()

void DracoWriter::ready(pdal::BasePointTable &table)
{
*m_stream << std::fixed;
auto layout = table.layout();

pdal::Dimension::IdList dimensions = layout->dims();
Expand Down Expand Up @@ -293,6 +292,7 @@ void DracoWriter::initPointCloud(point_count_t size)
{
addAttribute(dim.first, dim.second);
}
//do the same for generic attributes
for (auto &dim: m_genericDims)
{
addGeneric(dim, 1);
Expand Down Expand Up @@ -427,6 +427,7 @@ void DracoWriter::write(const PointViewPtr view)
draco::Encoder encoder;
encoder.SetEncodingMethod(draco::POINT_CLOUD_SEQUENTIAL_ENCODING);

//set quantization levels based on either defaults or user specifications
encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, m_quant.at("POSITION"));
encoder.SetAttributeQuantization(draco::GeometryAttribute::COLOR, m_quant.at("NORMAL"));
encoder.SetAttributeQuantization(draco::GeometryAttribute::NORMAL, m_quant.at("TEX_COORD"));
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/linux/cmake.sh
Expand Up @@ -8,7 +8,7 @@ LDFLAGS="$LDFLAGS -Wl,-rpath-link,$CONDA_PREFIX/lib" cmake .. \
-DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} \
-DBUILD_PLUGIN_I3S=ON \
-DBUILD_PLUGIN_NITF=ON \
-DBUILD_PLUGIN_TILEDB=OFF \
-DBUILD_PLUGIN_TILEDB=ON \
-DBUILD_PLUGIN_ICEBRIDGE=ON \
-DBUILD_PLUGIN_DRACO=ON \
-DBUILD_PLUGIN_HDF=ON \
Expand Down

0 comments on commit 77771e2

Please sign in to comment.