[Liblas-commits] hg: 3 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Tue Nov 10 12:21:53 EST 2009
changeset 79e6ec10959a in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=79e6ec10959a
summary: add kdtree'ing script
changeset 46688ef85464 in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=46688ef85464
summary: support using kdtrees
changeset 05bb3bbad6dc in /home/www/liblas.org/hg
details: http://hg.liblas.org/main/hg?cmd=changeset;node=05bb3bbad6dc
summary: rename
diffstat:
apps/las2oci.cpp | 49 +++++++++---
apps/lasindex.cpp | 2 +-
include/liblas/index/query.hpp | 1 +
python/scripts/laskdtree.py | 154 ++++++++++++++++++++++++++++++++++++++
src/index/index.cpp | 6 +-
src/index/query.cpp | 52 +++++++++++++
6 files changed, 248 insertions(+), 16 deletions(-)
diffs (truncated from 329 to 300 lines):
diff -r d1470f08a3ee -r 05bb3bbad6dc apps/las2oci.cpp
--- a/apps/las2oci.cpp Fri Oct 30 08:23:00 2009 -0500
+++ b/apps/las2oci.cpp Tue Nov 10 11:17:45 2009 -0600
@@ -38,6 +38,21 @@
#endif
+bool KDTreeIndexExists(std::string& filename)
+{
+ struct stat stats;
+ std::ostringstream os;
+ os << filename << ".kdx";
+
+ std::string indexname = os.str();
+
+ // ret is -1 for no file existing and 0 for existing
+ int ret = stat(indexname.c_str(),&stats);
+
+ bool output = false;
+ if (ret == 0) output= true; else output =false;
+ return output;
+}
std::istream* OpenInput(std::string filename)
@@ -1015,21 +1030,31 @@
}
LASReader* reader = new LASReader(*istrm);
- LASIndexDataStream* idxstrm = new LASIndexDataStream(reader, idx_dimension);
+ LASQuery* query = 0;
+ if (!KDTreeIndexExists(input)) {
- LASIndex* idx = new LASIndex(input);
- idx->SetType(LASIndex::eExternalIndex);
- idx->SetLeafCapacity(nCapacity);
- idx->SetFillFactor(dFillFactor);
- idx->Initialize(*idxstrm);
+ LASIndexDataStream* idxstrm = new LASIndexDataStream(reader, idx_dimension);
- LASQuery* query = new LASQuery;
- idx->Query(*query);
+ LASIndex* idx = new LASIndex(input);
+ idx->SetType(LASIndex::eExternalIndex);
+ idx->SetLeafCapacity(nCapacity);
+ idx->SetFillFactor(dFillFactor);
+ idx->Initialize(*idxstrm);
+ query = new LASQuery;
+ idx->Query(*query);
+ if (idx != 0) delete idx;
+ if (reader != 0) delete reader;
+ if (istrm != 0 ) delete istrm;
+
+ } else {
+ std::cout << "Using kdtree ... " << std::endl;
+ std::ostringstream os;
+ os << input << ".kdx" ;
+
+ std::istream* kdx = OpenInput(os.str());
+ query = new LASQuery(*kdx);
+ }
- if (idx != 0) delete idx;
- if (reader != 0) delete reader;
- if (istrm != 0 ) delete istrm;
-
std::list<LASQueryResult>& results = query->GetResults();
std::list<LASQueryResult>::const_iterator i;
diff -r d1470f08a3ee -r 05bb3bbad6dc apps/lasindex.cpp
--- a/apps/lasindex.cpp Fri Oct 30 08:23:00 2009 -0500
+++ b/apps/lasindex.cpp Tue Nov 10 11:17:45 2009 -0600
@@ -142,7 +142,7 @@
LASIndex* idx = new LASIndex(input);
idx->SetType(LASIndex::eExternalIndex);
idx->SetLeafCapacity(capacity);
- idx->SetFillFactor(0.8);
+ idx->SetFillFactor(0.99);
idx->SetDimension(dimension);
if (bBulkLoad) {
diff -r d1470f08a3ee -r 05bb3bbad6dc include/liblas/index/query.hpp
--- a/include/liblas/index/query.hpp Fri Oct 30 08:23:00 2009 -0500
+++ b/include/liblas/index/query.hpp Tue Nov 10 11:17:45 2009 -0600
@@ -90,6 +90,7 @@
public:
LASQuery();
+ LASQuery(std::istream& input);
~LASQuery()
{
std::cout << "child count was" << m_count << std::endl;
diff -r d1470f08a3ee -r 05bb3bbad6dc python/scripts/laskdtree.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/python/scripts/laskdtree.py Tue Nov 10 11:17:45 2009 -0600
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+
+from scipy import spatial
+from numpy import array, vstack, empty, float
+
+from liblas import file
+from liblas import header
+from liblas import point
+from liblas import color
+from liblas import srs
+from liblas import guid
+
+
+import sys
+import os
+
+
+class Translator(object):
+
+ def construct_parser(self):
+ from optparse import OptionParser, OptionGroup
+ usage = "usage: %prog --leaf-size 1000 filename.las"
+ parser = OptionParser(usage)
+ g = OptionGroup(parser, "Base options", "Basic Translation Options")
+ g.add_option("-i", "--input", dest="input",
+ help="Input LAS file", metavar="INPUT")
+ g.add_option("-s", "--leaf-size", dest='leafsize',
+ help="Maximum Leaf size", metavar="LEAFSIZE")
+ g.add_option("-o", "--output", dest='output',
+ help="Column name containing the point cloud object ", metavar="OUTPUT")
+
+
+ g.add_option("-w", "--overwrite",
+ action="store_true", dest="overwrite",
+ help="overwrite the existing file")
+
+
+ g.add_option("-q", "--quiet",
+ action="store_false", dest="verbose", default=False,
+ help="Don't say what we're doing on stdout")
+
+ parser.add_option_group(g)
+
+ if self.opts:
+ g = OptionGroup(parser, "Special Options", "Special options")
+ for o in self.opts:
+ g.add_option(o)
+ parser.add_option_group(g)
+
+ parser.set_defaults(verbose=True, overwrite=False)
+
+ self.parser = parser
+
+ def __init__(self, arguments, options=None):
+ self.connection = None
+ self.output = None
+ self.sql = None
+
+ self.opts = options
+ self.construct_parser()
+ self.options, self.args = self.parser.parse_args(args=arguments)
+
+ if self.args:
+ self.options.input = self.args[0]
+
+ if not self.options.leafsize:
+ try:
+ self.options.leafsize = int(self.args[2])
+ except IndexError:
+ self.options.leafsize = 1000
+
+ if self.options.input:
+ self.options.input = os.path.abspath(self.options.input)
+ if os.path.isdir(self.options.input):
+ raise self.parser.error("Input '%s' is a directory, not a file " % self.options.input)
+
+ exists = os.path.isfile(self.options.input)
+ if not exists:
+ raise self.parser.error("Input file '%s' does not exist" % self.options.input)
+ else:
+ raise self.parser.error("No input was specified")
+
+
+
+ if self.options.output:
+ self.options.output = os.path.abspath(self.options.output)
+ if os.path.isdir(self.options.output):
+ raise self.parser.error("Output '%s' is a directory, not a file " % self.options.output)
+
+ if os.path.exists(self.options.output):
+ if not self.options.overwrite:
+ raise self.parser.error("Output file '%s' exists, but you have not selected the --overwrite option" % self.options.output)
+ self.options.output = open(self.args[1],'wb')
+ else:
+ self.options.output = open(self.options.input+'.kdx','wb')
+
+
+ def get_leaves(self, node):
+ leaves = []
+ if isinstance(node, spatial.KDTree.leafnode):
+ leaves.append(node)
+ else:
+ return self.get_leaves(node.less) + self.get_leaves(node.greater)
+ return leaves
+
+ def get_bounds(self, ids, data):
+ x, y = data[ids[0]]
+
+ minx, miny, maxx, maxy = x, y, x, y
+
+ for id in ids:
+ x,y = data[id]
+ minx = min(minx, x)
+ maxx = max(maxx, x)
+ miny = min(miny, y)
+ maxy = max(maxy, y)
+
+ return (minx, miny, maxx, maxy)
+
+ def write(self, i, leaf, minx, miny, maxx, maxy):
+ ids = ' '.join([str(i) for i in leaf.idx])
+ output = '%d %d %.8f %.8f %.8f %.8f \n%s\n' % (i, len(leaf.idx), minx, miny, maxx, maxy, ids)
+
+ self.options.output.write(output)
+ def process(self):
+ inp = file.File(self.options.input)
+
+ data = array(empty( (inp.header.point_records_count, 2)),dtype=float)
+
+ i=0
+ for p in inp:
+ data[i] = array([p.x, p.y])
+ i+=1
+
+ t = spatial.KDTree(data,leafsize=self.options.leafsize)
+
+ l = self.get_leaves(t.tree)
+
+ i = 0
+ for leaf in l:
+ minx, miny, maxx, maxy = self.get_bounds(leaf.idx, data)
+ self.write(i, leaf, minx, miny, maxx, maxy)
+ i+=1
+ self.options.output.close()
+def main():
+ import optparse
+
+ options = []
+
+ d = Translator(sys.argv[1:], options=options)
+ d.process()
+
+if __name__=='__main__':
+ main()
diff -r d1470f08a3ee -r 05bb3bbad6dc src/index/index.cpp
--- a/src/index/index.cpp Fri Oct 30 08:23:00 2009 -0500
+++ b/src/index/index.cpp Tue Nov 10 11:17:45 2009 -0600
@@ -67,12 +67,12 @@
m_idxId = 1;
m_idxCapacity = 1000;
- m_idxLeafCap = 1000;
+ m_idxLeafCap = 250;
m_idxDimension = 3;
- m_idxFillFactor = 0.7;
+ m_idxFillFactor = 0.99;
- m_bufferCapacity = 10;
+ m_bufferCapacity = 100;
m_bufferWriteThrough = false;
m_idxExists = false;
diff -r d1470f08a3ee -r 05bb3bbad6dc src/index/query.cpp
--- a/src/index/query.cpp Fri Oct 30 08:23:00 2009 -0500
+++ b/src/index/query.cpp Tue Nov 10 11:17:45 2009 -0600
@@ -161,4 +161,56 @@
return *this;
}
+
+LASQuery::LASQuery(std::istream& input) : m_count(0), m_first(true)
+{
+ long id_count = 0;
+ long id = 0;
+ long i = 0;
+
+
+ double low[2];
+ double high[2];
+
+ double mins[2];
+ double maxs[2];
+
+ bool first = true;
+
+ while(input) {
+ input >> id >> id_count >> low[0] >> low[1] >> high[0] >> high[1];
+ // printf("count:%d %.2f %.2f %.2f %.2f\n", id_count, low[0], low[1], high[0], high[1]);
+
+ if (first) {
+ mins[0] = low[0];
+ mins[1] = low[1];
+ maxs[0] = high[0];
More information about the Liblas-commits
mailing list