Skip to content

Commit

Permalink
refactoring to make SchemaLayout go away
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek committed Sep 29, 2011
1 parent 0149bac commit 7044413
Show file tree
Hide file tree
Showing 32 changed files with 95 additions and 284 deletions.
2 changes: 0 additions & 2 deletions apps/pcinfo.cpp
Expand Up @@ -138,7 +138,6 @@ void PcInfo::addSwitches()
void PcInfo::dumpOnePoint(const Stage& stage) const
{
const Schema& schema = stage.getSchema();
SchemaLayout layout(schema);

PointBuffer data(schema, 1);

Expand Down Expand Up @@ -167,7 +166,6 @@ void PcInfo::dumpStats(pdal::filters::StatsFilter& filter) const
{

const Schema& schema = filter.getSchema();
SchemaLayout layout(schema);

boost::scoped_ptr<StageSequentialIterator> iter(filter.createSequentialIterator());

Expand Down
1 change: 0 additions & 1 deletion apps/pcview/main.cpp
Expand Up @@ -161,7 +161,6 @@ static void givePointsToEngine(ThreadArgs* threadArgs)
boost::uint32_t numPoints = threadArgs->m_numPoints;

const pdal::Schema& schema = stage.getSchema();
const pdal::SchemaLayout schemaLayout(schema);

pdal::StageSequentialIterator* iter = stage.createSequentialIterator();
pdal::PointBuffer buffer(schema, numPoints);
Expand Down
20 changes: 6 additions & 14 deletions include/pdal/PointBuffer.hpp
Expand Up @@ -40,7 +40,7 @@
#include <boost/scoped_array.hpp>

#include <pdal/Bounds.hpp>
#include <pdal/SchemaLayout.hpp>
#include <pdal/Schema.hpp>

namespace pdal
{
Expand Down Expand Up @@ -84,12 +84,6 @@ class PDAL_DLL PointBuffer
// This is a fixed constant, set at ctor time by the person constructing the buffer.
inline boost::uint32_t getCapacity() const { return m_capacity; }

// schema (number and kinds of fields) for a point in this buffer
inline const SchemaLayout& getSchemaLayout() const
{
return m_schemaLayout;
}

// convenience function
const Schema& getSchema() const
{
Expand All @@ -116,7 +110,7 @@ class PDAL_DLL PointBuffer

const boost::uint8_t* src = srcPointBuffer.getData(srcPointIndex);
boost::uint8_t* dest = getData(destPointIndex);
const std::size_t len = getSchemaLayout().getByteSize();
const std::size_t len = getSchema().getByteSize();

memcpy(dest, src, len);

Expand All @@ -132,7 +126,7 @@ class PDAL_DLL PointBuffer

const boost::uint8_t* src = srcPointBuffer.getData(srcPointIndex);
boost::uint8_t* dest = getData(destPointIndex);
const std::size_t len = getSchemaLayout().getByteSize();
const std::size_t len = getSchema().getByteSize();

memcpy(dest, src, len * numPoints);

Expand Down Expand Up @@ -192,7 +186,6 @@ class PDAL_DLL PointBuffer

private:
Schema m_schema;
SchemaLayout m_schemaLayout;
boost::scoped_array<boost::uint8_t> m_data;
std::size_t m_pointSize;
boost::uint32_t m_numPoints;
Expand All @@ -209,7 +202,7 @@ inline void PointBuffer::setField(std::size_t pointIndex, boost::int32_t fieldIn
// this is a little harsh, but we'll keep it for now as we shake things out
throw pdal_error("filedIndex is not valid at this point of access");
}
const DimensionLayout& dimLayout = m_schemaLayout.getDimensionLayout(fieldIndex);
const DimensionLayout& dimLayout = m_schema.getDimensionLayout(fieldIndex);
std::size_t offset = (pointIndex * m_pointSize) + dimLayout.getByteOffset();
assert(offset + sizeof(T) <= m_pointSize * m_capacity);
boost::uint8_t* p = m_data.get() + offset;
Expand All @@ -224,7 +217,7 @@ inline void PointBuffer::setFieldData(std::size_t pointIndex, boost::int32_t fie
// this is a little harsh, but we'll keep it for now as we shake things out
throw pdal_error("filedIndex is not valid at this point of access");
}
const DimensionLayout& dimLayout = m_schemaLayout.getDimensionLayout(fieldIndex);
const DimensionLayout& dimLayout = m_schema.getDimensionLayout(fieldIndex);
const Dimension& dim = dimLayout.getDimension();
std::size_t offset = (pointIndex * m_pointSize) + dimLayout.getByteOffset();
std::size_t size = dim.getDataTypeSize(dim.getDataType());
Expand All @@ -245,8 +238,7 @@ inline T PointBuffer::getField(std::size_t pointIndex, boost::int32_t fieldIndex
throw pdal_error("filedIndex is not valid at this point of access");
}

const DimensionLayout& dimLayout = m_schemaLayout.getDimensionLayout(fieldIndex);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////assert(dimLayout.getDimension().isValid());
const DimensionLayout& dimLayout = m_schema.getDimensionLayout(fieldIndex);

std::size_t offset = (pointIndex * m_pointSize) + dimLayout.getByteOffset();
assert(offset + sizeof(T) <= m_pointSize * m_capacity);
Expand Down
19 changes: 18 additions & 1 deletion include/pdal/Schema.hpp
Expand Up @@ -48,6 +48,7 @@
#include <map>

#include <pdal/Dimension.hpp>
#include <pdal/DimensionLayout.hpp>

// boost
#include <boost/cstdint.hpp>
Expand Down Expand Up @@ -78,7 +79,6 @@ class PDAL_DLL Schema
bool operator!=(const Schema& other) const;

void appendDimension(Dimension const& dim);
void appendDimensions(const std::vector<Dimension>& dim);

const std::vector<Dimension>& getDimensions() const;
std::vector<Dimension>& getDimensions();
Expand All @@ -95,6 +95,19 @@ class PDAL_DLL Schema
int getDimensionIndex(const DimensionId::Id& id) const;
int getDimensionIndex(const Dimension& dim) const;

void recalculateSizes();

/// Fetch total byte size -- sum of all dimensions
inline std::size_t getByteSize() const
{
return m_byteSize;
}

const DimensionLayout& getDimensionLayout(std::size_t index) const
{
return m_dimensionLayouts[index];
}

// returns a ptree reprsenting the Schema
//
// looks like this:
Expand All @@ -113,7 +126,11 @@ class PDAL_DLL Schema
static std::string to_xml(Schema const& schema);

private:
void calculateSizes();

std::vector<Dimension> m_dimensions;
std::vector<DimensionLayout> m_dimensionLayouts;
std::size_t m_byteSize;

std::map<DimensionId::Id, std::size_t> m_dimensions_map;
};
Expand Down
86 changes: 0 additions & 86 deletions include/pdal/SchemaLayout.hpp
@@ -1,86 +0,0 @@
/******************************************************************************
* $Id$
*
* Project: libLAS - http://liblas.org - A BSD library for LAS format data.
* Purpose: LAS Schema implementation for C++ libLAS
* Author: Howard Butler, hobu.inc@gmail.com
*
******************************************************************************
* Copyright (c) 2010, Howard Butler
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the Martin Isenburg or Iowa Department
* of Natural Resources nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/

#ifndef PDAL_SCHEMALAYOUT_HPP_INCLUDED
#define PDAL_SCHEMALAYOUT_HPP_INCLUDED

#include <map>

#include <pdal/pdal.hpp>

#include <pdal/Schema.hpp>
#include <pdal/DimensionLayout.hpp>


namespace pdal
{


class PDAL_DLL SchemaLayout
{
public:
SchemaLayout(const Schema&);
SchemaLayout(SchemaLayout const& other);

/// Fetch total byte size -- sum of all dimensions
inline std::size_t getByteSize() const
{
return m_byteSize;
}

const DimensionLayout& getDimensionLayout(std::size_t index) const
{
return m_dimensionLayouts[index];
}


private:
void calculateSizes();

Schema m_schema;
std::vector<DimensionLayout> m_dimensionLayouts;
std::size_t m_byteSize;
};


} // namespace liblas

#endif // PDAL_SCHEMALAYOUT_HPP_INCLUDED
2 changes: 1 addition & 1 deletion include/pdal/drivers/las/Support.hpp
Expand Up @@ -37,7 +37,7 @@

#include <pdal/pdal.hpp>

#include <pdal/SchemaLayout.hpp>
#include <pdal/Schema.hpp>

#include <iostream>

Expand Down
24 changes: 9 additions & 15 deletions src/PointBuffer.cpp
Expand Up @@ -43,9 +43,8 @@ namespace pdal

PointBuffer::PointBuffer(const Schema& schema, boost::uint32_t capacity)
: m_schema(schema)
, m_schemaLayout(SchemaLayout(schema))
, m_data(new boost::uint8_t[m_schemaLayout.getByteSize() * capacity])
, m_pointSize(m_schemaLayout.getByteSize())
, m_data(new boost::uint8_t[m_schema.getByteSize() * capacity])
, m_pointSize(m_schema.getByteSize())
, m_numPoints(0)
, m_capacity(capacity)
, m_bounds(Bounds<double>::getDefaultSpatialExtent())
Expand All @@ -56,9 +55,8 @@ PointBuffer::PointBuffer(const Schema& schema, boost::uint32_t capacity)

PointBuffer::PointBuffer(PointBuffer const& other)
: m_schema(other.getSchema())
, m_schemaLayout(other.getSchemaLayout())
, m_data(new boost::uint8_t[m_schemaLayout.getByteSize() * other.m_capacity])
, m_pointSize(m_schemaLayout.getByteSize())
, m_data(new boost::uint8_t[m_schema.getByteSize() * other.m_capacity])
, m_pointSize(m_schema.getByteSize())
, m_numPoints(other.m_numPoints)
, m_capacity(other.m_capacity)
, m_bounds(other.m_bounds)
Expand All @@ -71,13 +69,11 @@ PointBuffer::PointBuffer(PointBuffer const& other)
}

PointBuffer& PointBuffer::operator=(PointBuffer const& rhs)

{
if (&rhs != this)
{
m_schema = rhs.getSchema();
m_schemaLayout = rhs.getSchemaLayout();
m_pointSize = m_schemaLayout.getByteSize();
m_pointSize = rhs.getSchema().getByteSize();
m_numPoints = rhs.getNumPoints();
m_capacity = rhs.getCapacity();
m_bounds = rhs.getSpatialBounds();
Expand Down Expand Up @@ -111,7 +107,7 @@ void PointBuffer::setSpatialBounds(const Bounds<double>& bounds)

void PointBuffer::setData(boost::uint8_t* data, std::size_t index)
{
memcpy(m_data.get() + m_pointSize * index, data, getSchemaLayout().getByteSize());
memcpy(m_data.get() + m_pointSize * index, data, getSchema().getByteSize());
}

void PointBuffer::setAllData(boost::uint8_t* data, boost::uint32_t byteCount)
Expand All @@ -132,7 +128,7 @@ boost::uint32_t PointBuffer::getNumPoints() const

void PointBuffer::getData(boost::uint8_t** data, std::size_t* array_size) const
{
*array_size = getSchemaLayout().getByteSize();
*array_size = getSchema().getByteSize();
*data = (boost::uint8_t*) malloc (*array_size);
memcpy(*data, m_data.get(), *array_size);
}
Expand All @@ -143,7 +139,6 @@ boost::property_tree::ptree PointBuffer::toPTree() const
boost::property_tree::ptree tree;

const Schema& schema = getSchema();
const SchemaLayout& schemaLayout = getSchemaLayout();
const std::vector<Dimension>& dimensions = schema.getDimensions();

const boost::uint32_t numPoints = getNumPoints();
Expand All @@ -156,7 +151,7 @@ boost::property_tree::ptree PointBuffer::toPTree() const
for (i=0; i<dimensions.size(); i++)
{
const Dimension& dimension = dimensions[i];
const DimensionLayout& dimensionLayout = schemaLayout.getDimensionLayout(i);
const DimensionLayout& dimensionLayout = schema.getDimensionLayout(i);
const std::size_t fieldIndex = dimensionLayout.getPosition();

const std::string key = pointstring + dimension.getName();
Expand Down Expand Up @@ -282,7 +277,6 @@ std::ostream& operator<<(std::ostream& ostr, const PointBuffer& pointBuffer)
using std::endl;

const Schema& schema = pointBuffer.getSchema();
const SchemaLayout& schemaLayout = pointBuffer.getSchemaLayout();
const std::vector<Dimension>& dimensions = schema.getDimensions();

const std::size_t numPoints = pointBuffer.getNumPoints();
Expand All @@ -298,7 +292,7 @@ std::ostream& operator<<(std::ostream& ostr, const PointBuffer& pointBuffer)
for (i=0; i<dimensions.size(); i++)
{
const Dimension& dimension = dimensions[i];
const DimensionLayout& dimensionLayout = schemaLayout.getDimensionLayout(i);
const DimensionLayout& dimensionLayout = schema.getDimensionLayout(i);
std::size_t fieldIndex = dimensionLayout.getPosition();

ostr << dimension.getName() << " (" << dimension.getDataTypeName(dimension.getDataType()) << ") : ";
Expand Down

0 comments on commit 7044413

Please sign in to comment.