Skip to content

Commit

Permalink
make the Dimension be a single enum, not an enum+datatype combination
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgerlek committed Sep 19, 2011
1 parent 9681e24 commit 13fb859
Show file tree
Hide file tree
Showing 48 changed files with 972 additions and 981 deletions.
12 changes: 6 additions & 6 deletions apps/pcview/main.cpp
Expand Up @@ -175,12 +175,12 @@ static void givePointsToEngine(ThreadArgs* threadArgs)
colors = new boost::uint16_t[numRead * 3];
}

const int offsetX = schema.getDimensionIndex(pdal::Dimension::Field_X, pdal::Dimension::Int32);
const int offsetY = schema.getDimensionIndex(pdal::Dimension::Field_Y, pdal::Dimension::Int32);
const int offsetZ = schema.getDimensionIndex(pdal::Dimension::Field_Z, pdal::Dimension::Int32);
const int offsetR = schema.getDimensionIndex(pdal::Dimension::Field_Red, pdal::Dimension::Uint16);
const int offsetG = schema.getDimensionIndex(pdal::Dimension::Field_Green, pdal::Dimension::Uint16);
const int offsetB = schema.getDimensionIndex(pdal::Dimension::Field_Blue, pdal::Dimension::Uint16);
const int offsetX = schema.getDimensionIndex(pdal::Dimension::Id_X_i32);
const int offsetY = schema.getDimensionIndex(pdal::Dimension::Id_Y_i32);
const int offsetZ = schema.getDimensionIndex(pdal::Dimension::Id_Z_i32);
const int offsetR = schema.getDimensionIndex(pdal::Dimension::Id_Red_u16);
const int offsetG = schema.getDimensionIndex(pdal::Dimension::Id_Green_u16);
const int offsetB = schema.getDimensionIndex(pdal::Dimension::Id_Blue_u16);

const pdal::Dimension& xDim = schema.getDimension(offsetX);
const pdal::Dimension& yDim = schema.getDimension(offsetY);
Expand Down
155 changes: 93 additions & 62 deletions include/pdal/Dimension.hpp
Expand Up @@ -44,6 +44,7 @@

#include <pdal/pdal.hpp>
#include <pdal/Utils.hpp>
#include <pdal/external/boost/uuid/uuid.hpp>
#include <boost/property_tree/ptree.hpp>


Expand All @@ -59,59 +60,79 @@ namespace pdal
class PDAL_DLL Dimension
{
public:
/// \name Enumerations
enum Field
//typedef pdal::external::boost::uuids::uuid Id;

enum Id
{
Field_INVALID = 0,
Field_X,
Field_Y,
Field_Z,
Field_Intensity,
Field_ReturnNumber,
Field_NumberOfReturns,
Field_ScanDirectionFlag,
Field_EdgeOfFlightLine,
Field_Classification,
Field_ScanAngleRank,
Field_UserData,
Field_PointSourceId,
Field_Time,
Field_Red,
Field_Green,
Field_Blue,
Field_WavePacketDescriptorIndex,
Field_WaveformDataOffset,
Field_ReturnPointWaveformLocation,
Field_WaveformXt,
Field_WaveformYt,
Field_WaveformZt,
Field_Alpha,
// ...

// add more here
Field_User1 = 512,
Field_User2,
Field_User3,
Field_User4,
Field_User5,
Field_User6,
Field_User7,
Field_User8,
Field_User9,
Field_User10,
Field_User11,
Field_User12,
Field_User13,
Field_User14,
Field_User15,
// ...
// feel free to use your own int here

Field_LAST = 1023
Id_X_i32 = 0,
Id_Y_i32,
Id_Z_i32,
Id_X_f64,
Id_Y_f64,
Id_Z_f64,

Id_Red_u8,
Id_Green_u8,
Id_Blue_u8,
Id_Red_u16,
Id_Green_u16,
Id_Blue_u16,

Id_Time_u64,

Id_Las_Intensity = 100,
Id_Las_ReturnNumber,
Id_Las_NumberOfReturns,
Id_Las_ScanDirectionFlag,
Id_Las_EdgeOfFlightLine,
Id_Las_Classification,
Id_Las_ScanAngleRank,
Id_Las_UserData,
Id_Las_PointSourceId,
Id_Las_WavePacketDescriptorIndex,
Id_Las_WaveformDataOffset,
Id_Las_ReturnPointWaveformLocation,
Id_Las_WaveformXt,
Id_Las_WaveformYt,
Id_Las_WaveformZt,
Id_Las_Time,

// terrasolid
Id_TerraSolid_Alpha = 200,
Id_TerraSolid_Classification,
Id_TerraSolid_PointSourceId_u8,
Id_TerraSolid_PointSourceId_u16,
Id_TerraSolid_ReturnNumber_u8,
Id_TerraSolid_ReturnNumber_u16,
Id_TerraSolid_Flag,
Id_TerraSolid_Mark,
Id_TerraSolid_Intensity,
Id_TerraSolid_Time,

// chipper stuff
Id_Chipper_1 = 300,
Id_Chipper_2,

// qfit
Id_Qfit_StartPulse = 400,
Id_Qfit_ReflectedPulse,
Id_Qfit_ScanAngleRank,
Id_Qfit_Pitch,
Id_Qfit_Roll,
Id_Qfit_Time,
Id_Qfit_PassiveSignal,
Id_Qfit_PassiveX,
Id_Qfit_PassiveY,
Id_Qfit_PassiveZ,
Id_Qfit_GpsTime,
Id_Qfit_PDOP,
Id_Qfit_PulseWidth,

Id_Qfit_User1 = 10000,

Id_Undefined = 100000
};

// Do not explicitly specify these enum values because they
// are (probably wrongly) used to iterate through for Schema::getX, Schema::getY, Schema::getZ
enum DataType
{
Int8,
Expand All @@ -122,40 +143,53 @@ class PDAL_DLL Dimension
Uint32,
Int64,
Uint64,
Pointer, // stored as 64 bits, even on a 32-bit box
Float, // 32 bits
Double, // 64 bits
Undefined
};

enum Flags
{
IsAdded = 0x1,
IsRead = 0x2,
IsWritten = 0x4,
};

/// \name Constructors
Dimension(Field field, DataType type);
Dimension& operator=(Dimension const& rhs);
Dimension(const Id& id); // will use table to lookup datatype, description, etc
Dimension(const Id& id, DataType datatype, std::string name); // for dimensions not in the master table
Dimension(Dimension const& other);

Dimension& operator=(Dimension const& rhs);

/// \name Equality
bool operator==(const Dimension& other) const;
bool operator!=(const Dimension& other) const;

/// \name Data Access
std::string const& getFieldName() const;
std::string const& getName() const;

Field getField() const
Id getId() const
{
return m_field;
return m_id;
}

boost::uint32_t getFlags() const { return m_flags; }
void setFlags(boost::uint32_t flags) { m_flags = flags; }

DataType getDataType() const
{
return m_dataType;
}


static std::string getDataTypeName(DataType);
static DataType getDataTypeFromString(const std::string&);
static std::size_t getDataTypeSize(DataType);
static bool getDataTypeIsNumeric(DataType);
static bool getDataTypeIsSigned(DataType);
static bool getDataTypeIsInteger(DataType);
static std::string const& getFieldName(Field);

/// \return Number of bytes required to serialize this dimension
std::size_t getByteSize() const
Expand Down Expand Up @@ -345,7 +379,9 @@ class PDAL_DLL Dimension

private:
DataType m_dataType;
Field m_field;
Id m_id;
std::string m_name;
boost::uint32_t m_flags;
EndianType m_endian;
std::size_t m_byteSize;
std::string m_description;
Expand All @@ -354,16 +390,11 @@ class PDAL_DLL Dimension
bool m_precise;
double m_numericScale;
double m_numericOffset;

static void initFieldNames();
static bool s_fieldNamesValid;
static std::string s_fieldNames[Field_LAST];
};


PDAL_DLL std::ostream& operator<<(std::ostream& os, pdal::Dimension const& d);


} // namespace pdal

#endif // PDAL_DIMENSION_HPP_INCLUDED
4 changes: 4 additions & 0 deletions include/pdal/DimensionLayout.hpp
Expand Up @@ -66,6 +66,9 @@ class PDAL_DLL DimensionLayout
return m_dimension;
}

bool isValid() const { return m_isValid; }
void setIsValid(bool v) { m_isValid = v; }

/// The byte location to start reading/writing
/// point data from in a composited schema. liblas::Schema
/// will set these values for you when liblas::Dimension are
Expand Down Expand Up @@ -118,6 +121,7 @@ class PDAL_DLL DimensionLayout
Dimension m_dimension;
std::size_t m_byteOffset;
std::size_t m_position;
bool m_isValid;
};


Expand Down
18 changes: 5 additions & 13 deletions include/pdal/Schema.hpp
Expand Up @@ -65,8 +65,6 @@
namespace pdal
{

typedef boost::tuple<Dimension::Field, Dimension::DataType> tpl_t;

/// Schema definition
class PDAL_DLL Schema
{
Expand All @@ -84,25 +82,22 @@ class PDAL_DLL Schema
bool operator==(const Schema& other) const;
bool operator!=(const Schema& other) const;

void addDimension(Dimension const& dim);
void addDimensions(const std::vector<Dimension>& dims);

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

const Dimension& getDimension(std::size_t index) const;
Dimension& getDimension(std::size_t index);
const Dimensions& getDimensions() const;
// Dimensions& getDimensions();

// returns the index of the field
//
// This function assumes the field is present and valid. If not, it will throw.
// (This behaviour is okay because looking up the diemsnion index is not expected
// to be on the critical path anywhere.)
int getDimensionIndex(Dimension::Field field, Dimension::DataType datatype) const;
int getDimensionIndex(const Dimension::Id& id) const;
int getDimensionIndex(const Dimension& dim) const;

bool hasDimension(Dimension::Field field, Dimension::DataType datatype) const;
bool hasDimension(const Dimension::Id& id) const;
bool hasDimension(const Dimension& dim) const;

// returns a ptree reprsenting the Schema
Expand All @@ -125,10 +120,7 @@ class PDAL_DLL Schema
private:
std::vector<Dimension> m_dimensions;

std::map<tpl_t, std::size_t> m_dimensions_map;
// this is a mapping from field name to index position in the
// m_dimensions array (or -1 if field not present)
// int m_indexTable[Dimension::Field_LAST];
std::map<Dimension::Id, std::size_t> m_dimensions_map;
};


Expand Down
2 changes: 1 addition & 1 deletion include/pdal/XMLSchema.hpp
Expand Up @@ -141,7 +141,7 @@ class PDAL_DLL Reader
void Initialize();
void Load();
Dimension::DataType GetDimensionType(std::string const& interpretation);
Dimension::Field GetDimensionField(std::string const& name, boost::uint32_t position);
Dimension::Id GetDimensionField(std::string const& name, boost::uint32_t position);

private:

Expand Down
4 changes: 2 additions & 2 deletions include/pdal/filters/StatsFilter.hpp
Expand Up @@ -97,7 +97,7 @@ class PDAL_DLL StatsFilter : public Filter
void processBuffer(PointBuffer& data) const;

// returns the stats for field i
const StatsCollector& getStats(Dimension::Field field) const;
const StatsCollector& getStats(Dimension::Id id) const;

// clears the counters for all fields
void reset();
Expand All @@ -117,7 +117,7 @@ class PDAL_DLL StatsFilter : public Filter
private:
// the stats are keyed by the field name
// BUG: not threadsafe, these should maybe live in the iterator
std::map<Dimension::Field,StatsCollector*> m_stats; // one Stats item per field in the schema
std::map<Dimension::Id,StatsCollector*> m_stats; // one Stats item per field in the schema

StatsFilter& operator=(const StatsFilter&); // not implemented
StatsFilter(const StatsFilter&); // not implemented
Expand Down

0 comments on commit 13fb859

Please sign in to comment.