Skip to content

Commit

Permalink
Use DimType in XMLDim. Minimize use of XMLDim.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Dec 18, 2014
1 parent 5a63cb0 commit b08f607
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 126 deletions.
2 changes: 1 addition & 1 deletion include/pdal/DbReader.hpp
Expand Up @@ -51,7 +51,7 @@ class PDAL_DLL DbReader : public Reader
DimTypeList dbDimTypes() const;
void loadSchema(PointContextRef ctx, const std::string& schemaString);
void loadSchema(PointContextRef ctx, const XMLSchema& schema);
void writeField(PointBuffer& pb, const char *pos, XMLDim dim,
void writeField(PointBuffer& pb, const char *pos, const DimType& dim,
PointId idx);
void writePoint(PointBuffer& pb, PointId idx, const char *buf);

Expand Down
2 changes: 2 additions & 0 deletions include/pdal/Dimension.hpp
Expand Up @@ -751,6 +751,8 @@ inline Type::Enum type(std::string s)

struct DimType
{
DimType() : m_id(Dimension::Id::Unknown), m_type(Dimension::Type::None)
{}
DimType(Dimension::Id::Enum id, Dimension::Type::Enum type) :
m_id(id), m_type(type)
{}
Expand Down
39 changes: 23 additions & 16 deletions include/pdal/XMLSchema.hpp
Expand Up @@ -63,20 +63,22 @@ namespace pdal
void OCISchemaGenericErrorHandler(void * ctx, const char* message, ...);
void OCISchemaStructuredErrorHandler(void * userData, xmlErrorPtr error);

class XMLSchema;

struct XMLDim
{
XMLDim() : m_min(0.0), m_max(0.0), m_type(Dimension::Type::None),
m_id(Dimension::Id::Unknown)
friend class XMLSchema;

public:
XMLDim() : m_min(0.0), m_max(0.0)
{}

std::string m_name;
std::string m_description;
uint32_t m_position;
double m_min;
double m_max;
XForm m_xform;
Dimension::Type::Enum m_type;
Dimension::Id::Enum m_id;
DimType m_dimType;
};
typedef std::vector<XMLDim> XMLDimList;
inline bool operator < (const XMLDim& d1, const XMLDim& d2)
Expand All @@ -85,25 +87,29 @@ inline bool operator < (const XMLDim& d1, const XMLDim& d2)
class PDAL_DLL XMLSchema
{
public:
XMLSchema(Orientation::Enum orientation = Orientation::PointMajor) :
m_orientation(orientation)
XMLSchema(std::string xml, std::string xsd = "",
Orientation::Enum orientation = Orientation::PointMajor);
XMLSchema(const DimTypeList& dims, MetadataNode m = MetadataNode(),
Orientation::Enum orientation = Orientation::PointMajor);
XMLSchema() : m_orientation(Orientation::PointMajor)
{}
~XMLSchema();

void read(std::string xml, std::string xsd = "");
~XMLSchema()
{ xmlCleanupParser(); }

std::string xml() const;
DimTypeList dimTypes() const;
XMLDimList dims() const
XMLDimList xmlDims() const
{ return m_dims; }

MetadataNode getMetadata() const
{ return m_metadata;}
std::string getXML(const DimTypeList& dims,
MetadataNode m = MetadataNode());
std::string getXML();
void setId(const std::string& name, Dimension::Id::Enum id)
{ xmlDim(name).m_dimType.m_id = id; }
void setXForm(Dimension::Id::Enum id, XForm xform)
{ xmlDim(id).m_xform = xform; }
{ xmlDim(id).m_dimType.m_xform = xform; }
XForm xForm(Dimension::Id::Enum id) const
{ return xmlDim(id).m_xform; }
{ return xmlDim(id).m_dimType.m_xform; }
void setOrientation(Orientation::Enum orientation)
{ m_orientation = orientation; }
Orientation::Enum orientation() const
Expand All @@ -117,12 +123,13 @@ class PDAL_DLL XMLSchema

XMLDim& xmlDim(Dimension::Id::Enum id);
const XMLDim& xmlDim(Dimension::Id::Enum id) const;
XMLDim& xmlDim(const std::string& name);
xmlDocPtr init(const std::string& xml, const std::string& xsd);
bool validate(xmlDocPtr doc, const std::string& xsd);
std::string remapOldNames(const std::string& input);
bool loadMetadata(xmlNode *startNode, MetadataNode& input);
bool load(xmlDocPtr doc);
void write(xmlTextWriterPtr w, const DimTypeList& dims, MetadataNode m);
void writeXml(xmlTextWriterPtr w) const;
};

} // namespace pdal
Expand Down
15 changes: 4 additions & 11 deletions plugins/oci/io/OciCommon.cpp
Expand Up @@ -129,13 +129,7 @@ XMLSchema fetchSchema(Statement stmt, BlockPtr block)
}
std::ostringstream fname;
int cloudId = stmt->GetInteger(&(block->pc->pc_id)) ;
// fname << "schema-" << cloudId <<".xml";
// std::ostream* out = FileUtils::createFile(fname.str());
// out->write(pc_schema_xml.c_str(), pc_schema_xml.size());
// FileUtils::closeFile(out);
XMLSchema schema;
schema.read(pc_schema_xml);
return schema;
return XMLSchema(pc_schema_xml);
}


Expand Down Expand Up @@ -171,12 +165,11 @@ void Block::update(XMLSchema *s)
m_point_size = 0; // Wipe the size to reset
m_num_remaining = num_points;
m_schema.setOrientation(s->orientation());
XMLDimList dims = s->dims();
DimTypeList dims = s->dimTypes();
for (auto di = dims.begin(); di != dims.end(); ++di)
{
Id::Enum id = m_ctx.findDim(di->m_name);
if (id == Id::X || id == Id::Y || id == Id::Z)
m_schema.setXForm(id, di->m_xform);
if (di->m_id == Id::X || di->m_id == Id::Y || di->m_id == Id::Z)
m_schema.setXForm(di->m_id, di->m_xform);
m_point_size += Dimension::size(di->m_type);
}
}
Expand Down
12 changes: 5 additions & 7 deletions plugins/oci/io/OciReader.cpp
Expand Up @@ -249,8 +249,7 @@ void OciReader::addDimensions(PointContextRef ctx)

if (m_schemaFile.size())
{
std::string pcSchema =
m_block->m_schema.getXML(m_block->m_schema.dimTypes());
std::string pcSchema = m_block->m_schema.xml();
std::ostream *out = FileUtils::createFile(m_schemaFile);
out->write(pcSchema.c_str(), pcSchema.size());
FileUtils::closeFile(out);
Expand Down Expand Up @@ -294,7 +293,7 @@ point_count_t OciReader::readDimMajor(PointBuffer& buffer, BlockPtr block,
point_count_t blockRemaining;
point_count_t numRead = 0;

XMLDimList dims = block->m_schema.dims();
DimTypeList dims = block->m_schema.dimTypes();
for (auto di = dims.begin(); di != dims.end(); ++di)
{
PointId nextId = startId;
Expand Down Expand Up @@ -325,7 +324,6 @@ point_count_t OciReader::readPointMajor(PointBuffer& buffer,
PointId nextId = buffer.size();
point_count_t numRead = 0;

XMLDimList dims = block->m_schema.dims();
char *pos = seekPointMajor(block);
while (numRead < numPts && numRemaining > 0)
{
Expand All @@ -340,10 +338,10 @@ point_count_t OciReader::readPointMajor(PointBuffer& buffer,
}


char *OciReader::seekDimMajor(const XMLDim& d, BlockPtr block)
char *OciReader::seekDimMajor(const DimType& d, BlockPtr block)
{
size_t size = 0;
XMLDimList dims = block->m_schema.dims();
DimTypeList dims = block->m_schema.dimTypes();
for (auto di = dims.begin(); di->m_id != d.m_id; ++di)
size += Dimension::size(di->m_type);
return block->data() +
Expand Down Expand Up @@ -373,7 +371,7 @@ bool OciReader::readOci(Statement stmt, BlockPtr block)
// Read the points from the blob in the row.
readBlob(stmt, block);
XMLSchema *s = findSchema(stmt, block);
m_dims = s->dims();
m_dims = s->xmlDims();
block->update(s);
block->clearFetched();
return true;
Expand Down
2 changes: 1 addition & 1 deletion plugins/oci/io/OciReader.hpp
Expand Up @@ -76,7 +76,7 @@ class PDAL_DLL OciReader : public DbReader
point_count_t numPts);
point_count_t readPointMajor(PointBuffer& buffer, BlockPtr block,
point_count_t numPts);
char *seekDimMajor(const XMLDim& d, BlockPtr block);
char *seekDimMajor(const DimType& d, BlockPtr block);
char *seekPointMajor(BlockPtr block);
bool readOci(Statement stmt, BlockPtr block);
XMLSchema *findSchema(Statement stmt, BlockPtr block);
Expand Down
4 changes: 2 additions & 2 deletions plugins/oci/io/OciWriter.cpp
Expand Up @@ -547,8 +547,8 @@ void OciWriter::createPCEntry()
s_geom << "," << bounds.maxy;
s_geom << "))";

XMLSchema schema(m_orientation);
std::string schemaData = schema.getXML(dbDimTypes());
XMLSchema schema(dbDimTypes(), MetadataNode(), m_orientation);
std::string schemaData = schema.xml();

oss << "declare\n"
" pc_id NUMBER := :" << nPCPos << ";\n"
Expand Down
2 changes: 1 addition & 1 deletion plugins/pgpointcloud/io/PgReader.cpp
Expand Up @@ -242,7 +242,7 @@ void PgReader::ready(PointContextRef ctx)

m_point_size = 0;
for (auto di = m_dims.begin(); di != m_dims.end(); ++di)
m_point_size += Dimension::size(di->m_type);
m_point_size += Dimension::size(di->m_dimType.m_type);

CursorSetup();
}
Expand Down
6 changes: 2 additions & 4 deletions plugins/pgpointcloud/io/PgWriter.cpp
Expand Up @@ -280,8 +280,8 @@ uint32_t PgWriter::SetupSchema(uint32_t srid)
MetadataNode m = metadata.getNode();
m.add("compression", compression);

XMLSchema schema;
std::string xml = schema.getXML(dbDimTypes(), m);
XMLSchema schema(dbDimTypes(), m);
std::string xml = schema.xml();

// Do any of the existing schemas match the one we want to use?
if (schema_count > 0)
Expand Down Expand Up @@ -315,8 +315,6 @@ uint32_t PgWriter::SetupSchema(uint32_t srid)
pcid = atoi(pcid_str);
}



const char* paramValues = xml.c_str();
oss << "INSERT INTO pointcloud_formats (pcid, srid, schema) "
"VALUES (" << pcid << "," << srid << ",$1)";
Expand Down
3 changes: 1 addition & 2 deletions plugins/sqlite/io/SQLiteReader.cpp
Expand Up @@ -191,8 +191,7 @@ void SQLiteReader::addDimensions(PointContextRef ctx)
FileUtils::closeFile(out);
}

XMLSchema schema;
schema.read(s.data);
XMLSchema schema(s.data);
m_patch->m_metadata = schema.getMetadata();
m_patch->m_ctx = ctx;

Expand Down
4 changes: 2 additions & 2 deletions plugins/sqlite/io/SQLiteWriter.cpp
Expand Up @@ -455,8 +455,8 @@ void SQLiteWriter::CreateCloud()
m.add("compression", "lazperf");
m.add("version", "1.0");
}
XMLSchema schema;
std::string xml = schema.getXML(dbDimTypes(), m);
XMLSchema schema(dbDimTypes(), m);
std::string xml = schema.xml();

records rs;
row r;
Expand Down
28 changes: 15 additions & 13 deletions src/DbReader.cpp
Expand Up @@ -38,14 +38,13 @@ namespace pdal
void DbReader::loadSchema(PointContextRef ctx,
const std::string& schemaString)
{
XMLSchema schema;
schema.read(schemaString);
XMLSchema schema(schemaString);
loadSchema(ctx, schema);
}

void DbReader::loadSchema(PointContextRef ctx, const XMLSchema& schema)
{
m_dims = schema.dims();
m_dims = schema.xmlDims();

// Override XYZ to doubles and use those going forward
// we will apply any scaling set before handing it off
Expand All @@ -57,8 +56,9 @@ void DbReader::loadSchema(PointContextRef ctx, const XMLSchema& schema)
m_packedPointSize = 0;
for (auto di = m_dims.begin(); di != m_dims.end(); ++di)
{
di->m_id = ctx.registerOrAssignDim(di->m_name, di->m_type);
m_packedPointSize += Dimension::size(di->m_type);
di->m_dimType.m_id =
ctx.registerOrAssignDim(di->m_name, di->m_dimType.m_type);
m_packedPointSize += Dimension::size(di->m_dimType.m_type);
}
}

Expand All @@ -68,12 +68,12 @@ DimTypeList DbReader::dbDimTypes() const
DimTypeList dimTypes;

for (auto di = m_dims.begin(); di != m_dims.end(); ++di)
dimTypes.push_back(DimType(di->m_id, di->m_type, di->m_xform));
dimTypes.push_back(di->m_dimType);
return dimTypes;
}


void DbReader::writeField(PointBuffer& pb, const char *pos, XMLDim dim,
void DbReader::writeField(PointBuffer& pb, const char *pos, const DimType& dim,
PointId idx)
{
using namespace Dimension;
Expand Down Expand Up @@ -102,20 +102,22 @@ void DbReader::writePoint(PointBuffer& pb, PointId idx, const char *buf)

for (auto di = m_dims.begin(); di != m_dims.end(); ++di)
{
DimType dimType = di->m_dimType;
// If we read X, Y or Z as a signed 32, apply the transform and write
// the transformed value (double).
if (di->m_type == Type::Signed32 &&
(di->m_id == Id::X || di->m_id == Id::Y || di->m_id == Id::Z))
if (dimType.m_type == Type::Signed32 &&
(dimType.m_id == Id::X || dimType.m_id == Id::Y ||
dimType.m_id == Id::Z))
{
int32_t i;

memcpy(&i, buf, sizeof(int32_t));
double d = (i * di->m_xform.m_scale) + di->m_xform.m_offset;
pb.setField(di->m_id, idx, d);
double d = (i * dimType.m_xform.m_scale) + dimType.m_xform.m_offset;
pb.setField(dimType.m_id, idx, d);
}
else
pb.setField(di->m_id, di->m_type, idx, buf);
buf += Dimension::size(di->m_type);
pb.setField(dimType.m_id, dimType.m_type, idx, buf);
buf += Dimension::size(dimType.m_type);
}
}

Expand Down

0 comments on commit b08f607

Please sign in to comment.