Skip to content

Commit

Permalink
add scaffolding 'pdal diff' command
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Mar 17, 2014
1 parent 2abe807 commit 337f002
Show file tree
Hide file tree
Showing 6 changed files with 323 additions and 0 deletions.
7 changes: 7 additions & 0 deletions apps/pdal.cpp
Expand Up @@ -47,6 +47,7 @@ void outputVersion()
std::cout << "pdal " << "(" << pdal::GetFullVersionString() << ")" << std::endl;
std::cout << headline << std::endl;
std::cout << " available actions: " << std::endl;
std::cout << " - diff" << std::endl;
std::cout << " - info" << std::endl;
std::cout << " - pipeline" << std::endl;
std::cout << " - query" << std::endl;
Expand Down Expand Up @@ -133,6 +134,12 @@ int main(int argc, char* argv[])
return app.run();
}

if (boost::iequals(action, "diff"))
{
pdal::kernel::Diff app(count, args);
return app.run();
}

std::cerr << "Action '" << action <<"' not recognized" << std::endl << std::endl;
outputVersion();
return 1;
Expand Down
1 change: 1 addition & 0 deletions hobu-config.sh
Expand Up @@ -15,6 +15,7 @@ CXX=/Users/hobu/bin/clang++
ORACLE_HOME=$HOME/oracle
export ORACLE_HOME
CONFIG="Unix Makefiles"
CONFIG="Ninja"

if ! [ -z "$1" ]; then
CONFIG="$1"
Expand Down
72 changes: 72 additions & 0 deletions include/pdal/kernel/Diff.hpp
@@ -0,0 +1,72 @@
/******************************************************************************
* Copyright (c) 2014, Howard Butler (howard@hobu.co)
*
* 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 Hobu, Inc. or Flaxen Geo Consulting 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 INCLUDED_PDAL_KERNEL_DIFF_HPP
#define INCLUDED_PDAL_KERNEL_DIFF_HPP

#include <pdal/Stage.hpp>
#include <pdal/StageIterator.hpp>
#include <pdal/FileUtils.hpp>
#include <pdal/PointBuffer.hpp>

#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/json_parser.hpp>

#include "Application.hpp"

namespace pdal { namespace kernel {


class PDAL_DLL Diff : public Application
{
public:
Diff(int argc, const char* argv[]);
int execute(); // overrride


private:
void addSwitches(); // overrride
void validateSwitches(); // overrride

void readPoints( StageSequentialIterator* iter,
PointBuffer& data);
std::string m_sourceFile;
std::string m_candidateFile;
bool m_useXML;
bool m_useJSON;
};

}} // pdal::kernel

#endif
1 change: 1 addition & 0 deletions include/pdal/kernel/Kernel.hpp
Expand Up @@ -43,5 +43,6 @@
#include "Pipeline.hpp"
#include "Query.hpp"
#include "Translate.hpp"
#include "Diff.hpp"

#endif
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -574,6 +574,7 @@ set(PDAL_KERNEL_SRC "${PROJECT_SOURCE_DIR}/src/${PDAL_KERNEL_PATH}")
set(PDAL_KERNEL_HPP
${PDAL_KERNEL_HEADERS}/Application.hpp
${PDAL_KERNEL_HEADERS}/Support.hpp
${PDAL_KERNEL_HEADERS}/Diff.hpp
${PDAL_KERNEL_HEADERS}/Info.hpp
${PDAL_KERNEL_HEADERS}/Kernel.hpp
${PDAL_KERNEL_HEADERS}/Pipeline.hpp
Expand All @@ -584,6 +585,7 @@ set(PDAL_KERNEL_HPP
set(PDAL_KERNEL_CPP
${PDAL_KERNEL_SRC}/Application.cpp
${PDAL_KERNEL_SRC}/Support.cpp
${PDAL_KERNEL_SRC}/Diff.cpp
${PDAL_KERNEL_SRC}/Info.cpp
${PDAL_KERNEL_SRC}/Pipeline.cpp
${PDAL_KERNEL_SRC}/Query.cpp
Expand Down
240 changes: 240 additions & 0 deletions src/kernel/Diff.cpp
@@ -0,0 +1,240 @@
/******************************************************************************
* Copyright (c) 2014, Howard Butler (howard@hobu.co)
*
* 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 Hobu, Inc. or Flaxen Geo Consulting 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.
****************************************************************************/

#include <pdal/kernel/Diff.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>

using boost::property_tree::ptree;

namespace pdal { namespace kernel {

Diff::Diff(int argc, const char* argv[])
: Application(argc, argv, "dif")
, m_sourceFile("")
, m_candidateFile("")
{
return;
}


void Diff::validateSwitches()
{


return;
}


void Diff::addSwitches()
{
namespace po = boost::program_options;

po::options_description* file_options = new po::options_description("file options");


file_options->add_options()
("source", po::value<std::string>(&m_sourceFile), "source file name")
("candidate", po::value<std::string>(&m_candidateFile), "candidate file name")
("xml", po::value<bool>(&m_useXML)->zero_tokens()->implicit_value(true), "dump XML")
("json", po::value<bool>(&m_useJSON)->zero_tokens()->implicit_value(true), "dump JSON")

;

addSwitchSet(file_options);

po::options_description* processing_options = new po::options_description("processing options");

processing_options->add_options()

;

addSwitchSet(processing_options);

addPositionalSwitch("source", 1);
addPositionalSwitch("candidate", 2);

return;
}



void Diff::readPoints( StageSequentialIterator* iter,
PointBuffer& data)
{
while (!iter->atEnd())
{
const boost::uint32_t numRead = iter->read(data);
}

}


int Diff::execute()
{

Options sourceOptions;
{
sourceOptions.add<std::string>("filename", m_sourceFile);
sourceOptions.add<bool>("debug", isDebug());
sourceOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
}
Stage* source = AppSupport::makeReader(sourceOptions);
source->initialize();

PointBuffer source_data(source->getSchema(), m_chunkSize);
StageSequentialIterator* source_iter = source->createSequentialIterator(source_data);

ptree errors;




Options candidateOptions;
{
candidateOptions.add<std::string>("filename", m_candidateFile);
candidateOptions.add<bool>("debug", isDebug());
candidateOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
}

Stage* candidate = AppSupport::makeReader(candidateOptions);
// pdal::filters::Index* index_filter = new pdal::filters::Index(*candidate, candidateOptions);
candidate->initialize();


PointBuffer candidate_data(candidate->getSchema(), m_chunkSize);
StageSequentialIterator* candidate_iter = candidate->createSequentialIterator(candidate_data);
// readPoints(candidate_iter, candidate_data);


if (candidate->getNumPoints() != source->getNumPoints())
{
std::ostringstream oss;

oss << "Source and candidate files do not have the same point count";
errors.put<std::string>("count.error", oss.str());
errors.put<boost::uint32_t>("count.candidate" , candidate->getNumPoints());
errors.put<boost::uint32_t>("count.source" , source->getNumPoints());

}



Schema const& candidate_schema = candidate_data.getSchema();


Schema const& source_schema = source_data.getSchema();

if (! ( candidate_schema == source_schema))
{
std::ostringstream oss;

oss << "Source and candidate files do not have the same schema";
errors.put<std::string>("schema.error", oss.str());
errors.put_child("schema.source", source_schema.toPTree());
errors.put_child("schema.candidate", candidate_schema.toPTree());

}

write_json(std::cout, errors);

delete candidate_iter;
delete candidate;


delete source_iter;
delete source;

return 0;



// for (boost::uint32_t i = 0; i < source_data.getNumPoints(); ++i)
// {
// double sx = source_data.applyScaling(sDimX, i);
// double sy = source_data.applyScaling(sDimY, i);
// double sz = source_data.applyScaling(sDimZ, i);
//
// std::vector<std::size_t> ids = candidate_data.neighbors(sx, sy, sz, 1);
//
// if (!ids.size())
// {
// std::ostringstream oss;
// oss << "unable to find point for id '" << i <<"'";
// throw app_runtime_error(oss.str() );
// }
//
// std::size_t id = ids[0];
// double cx = candidate_data.applyScaling(cDimX, id);
// double cy = candidate_data.applyScaling(cDimY, id);
// double cz = candidate_data.applyScaling(cDimZ, id);
//
// double xd = sx - cx;
// double yd = sy - cy;
// double zd = sz - cz;
//
// if (!bWroteHeader)
// {
// writeHeader(ostr, m_3d);
// bWroteHeader = true;
// }
// ostr << i << ",";
// boost::uint32_t precision = Utils::getStreamPrecision(cDimX.getNumericScale());
// ostr.setf(std::ios_base::fixed, std::ios_base::floatfield);
// ostr.precision(precision);
// ostr << xd << ",";
//
// precision = Utils::getStreamPrecision(cDimY.getNumericScale());
// ostr.precision(precision);
// ostr << yd;
//
// if (m_3d)
// {
// ostr << ",";
// precision = Utils::getStreamPrecision(cDimZ.getNumericScale());
// ostr.precision(precision);
// ostr << zd;
// }
//
// ostr << std::endl;
//
// }



return 0;
}

}} // pdal::kernel

0 comments on commit 337f002

Please sign in to comment.