Giter VIP home page Giter VIP logo

copc-lib's Introduction

copc-lib

copc-lib provides an easy-to-use reader and writer interface for COPC point clouds, with bindings for python and C++.

Installation

The quickest way to get started with copc-lib is with our conda and pip packages.

Conda

Conda includes both the C++ and python bindings:

conda install -c conda-forge copc-lib

Pip

Pip provide only python bindings:

pip install copclib

Building from source

Dependencies

copc-lib has the following dependencies:

  • laz-perf>=3.0.0
  • Catch2 v2.x (test suite only)
  • Pybind11 (python bindings only)

To install all dependencies:

conda install -c conda-forge "laz-perf>=3.0" Catch2=2.13 pybind11

C++

git clone https://github.com/RockRobotic/copc-lib.git
cd copc-lib
mkdir build && cd build
cmake ..
cmake --build .
sudo cmake --install .

Python

git clone https://github.com/RockRobotic/copc-lib.git
pip install ./copc-lib

Example Files & Unit Tests

To build the copc-lib examples and unit tests along with the main library, you must enable them:

mkdir build && cd build
cmake .. -DWITH_TESTS=ON -DWITH_PYTHON=ON
cmake --build .
ctest # All tests should pass

Usage

The Reader and Writer objects provide the primary means of interfacing with your COPC files. For more complex use cases, we also provide additional objects such as LAZ Compressors and Decompressors (see example/example-writer.cpp).

For common use cases, see the example and test folders for full examples.

C++

copc-lib is compatible with CMake. Assuming copc-lib and lazperf are installed on the system, you can link with them in your CMakeLists.txt:

find_package(COPCLIB REQUIRED)
find_package(LAZPERF REQUIRED)

add_executable(funlib fun-main.cpp)
target_link_libraries(funlib COPCLIB::copc-lib LAZPERF::lazperf)

The primary public interface will be your FileReader and FileWriter objects. Check the headers and example files for documentation.

#include <iostream>
#include <copc-lib/io/reader.hpp>

void main()
{
    // Create a reader object
    FileReader reader("autzen-classified.copc.laz");

    // Get the node metadata from the hierarchy
    auto node = reader.FindNode(copc.VoxelKey(0, 0, 0, 0));
    // Fetch the points of a node
    auto points = reader.GetPoints(node);

    // Iterate through each point
    for (const auto &point : points)
        std::cout << "X: " << point.X ", Y: " << point.Y << ", Z: " << point.Z  << std::endl;
}

Python

Example files are also provided for python.

import copclib as copc

# Create a reader object
reader = copc.FileReader("autzen-classified.copc.laz")

# Get the node metadata from the hierarchy
node = reader.FindNode(copc.VoxelKey(0, 0, 0, 0))
# Fetch the points of a node
points = reader.GetPoints(node)

# Iterate through each point
for point in points:
    print(point.x, point.y, point.z)

Note that, in python, dimension names for points follow the laspy naming scheme, with the exception of scan_angle.

Helpful Links

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Please see LICENSE.md

Credits

copc-lib is created and maintained by Chris Lee, Leo Stanislas and other members of RockRobotic.

The COPC file format is created and maintained by HOBU Inc. Some code has been adopted from PDAL and lazperf, both of which are maintained by HOBU Inc.

copc-lib's People

Contributors

ccinc avatar hobu avatar leo-stan avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

copc-lib's Issues

Enforce VoxelKey validity

Invalidate a voxelkey if it violates:

Each node at depth D may have up to 8 child nodes at depth D + 1 which represent bisected sub-volumes.

Configure failure

I assume something needs to be committed?

#!/bin/bash

rm -rf build
mkdir build
cd build
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -Dgtest_force_shared_crt=ON -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX

I installed catch2 via conda-forge, and I'm on OSX x86-64.


-- The C compiler identification is Clang 11.1.0
-- The CXX compiler identification is Clang 11.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/hobu/miniconda3/envs/pdal-build/bin/x86_64-apple-darwin13.4.0-clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/hobu/miniconda3/envs/pdal-build/bin/x86_64-apple-darwin13.4.0-clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:44 (add_subdirectory):
  The source directory

    /Users/hobu/dev/git/copc-lib/lib/Catch2

  does not contain a CMakeLists.txt file.


CMake Error at CMakeLists.txt:55 (include):
  include could not find requested file:

    Catch


CMake Error at CMakeLists.txt:56 (catch_discover_tests):
  Unknown CMake command "catch_discover_tests".


Make Vector3 Iterable

>>> list(reader.copc_config.las_header.min)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'copclib._core.Vector3' object is not iterable

Add scaled x/y/z support

@leo-stan Let me know your thoughts on this. If we want to be able to get the scaled x/y/z values within the point class, we'll need to either store the lasheader or store the offset/scale factors (maybe store pointer or ref so no overhead?)

Better Error for Int Overflow

point.red = 65537

The above code will throw this error:

TypeError: (): incompatible function arguments. The following argument types are supported:
1. (arg0: copclib._core.Point, arg1: int) -> None

The error message should better describe the issue

Required extents vlr

Hi,

Thank you for this library, I've been using it for the past few weeks and it's working great.

I was wondering what your plan was for the extents vlr. From what I understand, it's been removed from the spec, but it seems to be required when opening a COPC file. I found a related discussion here: copcio/copcio.github.io#50

I've been working with COPC files generated from Untwine and PDAL, but both of these don't produce an extents vlr, so the following error happens when I try to open the files with copc-lib:

RuntimeError: Reader::ReadCopcExtentsVlr: No COPC Extents VLR found in file.

To work with these files, I removed the extents vlr entirely in this branch : https://github.com/davidcaron/copc-lib/tree/remove-extents-vlr.

I guess my question is: did you plan on making the extents vlr optional, or to remove it?

License clarity

I would suggest updating the license to just the MIT license, which seems to be the intent. Unless you've copied significant bits of laz-perf into the codebase, you shouldn't have to take in the LGPL license it has into this one.

Make writing Extents VLR optional.

We currently don't offer the option to not write that VLR, since it's not in the COPC specs anymore we should probably provide that option.

cannot build python bindings on ubuntu 20.04LTS

I managed to build the C++ library, but I cannot build the python wrapper:
I did install pybind11, but I did not install catch2 since I may skip tests:
sudo apt install python3-pybind11

My python version is 3.8.10

pip install ./copc-lib
..................
[ 88%] Linking CXX shared library ../../lib.linux-x86_64-3.8/libcopc-lib.so
    [ 88%] Built target copc-lib
    Scanning dependencies of target copclib
    [ 94%] Building CXX object python/CMakeFiles/copclib.dir/bindings.cpp.o
    /tmp/pip-req-build-sl2zyo4s/python/bindings.cpp: In function ‘void pybind11_init_copclib(pybind11::module&)’:
    /tmp/pip-req-build-sl2zyo4s/python/bindings.cpp:72:27: error: could not convert ‘pybind11::detail::self’ from ‘const pybind11::detail::self_t’ to ‘pybind11::handle’
       72 |         .def(py::hash(py::self))
          |                       ~~~~^~~~
          |                           |
          |                           const pybind11::detail::self_t
    make[2]: *** [python/CMakeFiles/copclib.dir/build.make:63: python/CMakeFiles/copclib.dir/bindings.cpp.o] Error 1
    make[1]: *** [CMakeFiles/Makefile2:170: python/CMakeFiles/copclib.dir/all] Error 2
    make: *** [Makefile:130: all] Error 2
    Traceback (most recent call last):

memory leak in copc::FileReader

The constructor of copc::FileReader calls initialization functions which may throw an exception. When an exception is thrown, the construction of the copc::FileReader object is interrupted and its deconstructor will not be called. Thus, the memory of std::fstream object 'f_stream' leaks.

Python example reader - Cannot Read WKT: UnicodeDecodeError

Hey all,

when tyring to use example_reader.py I get the following error at line 43 ( print("WKT: %s" % reader.copc_config.wkt)):

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 989: invalid continuation byte

This is with the provided example file. I have tried with my own copc files, all the same. I am trying to run it on windows 11. I also tried in wsl and a virtual machine running ubuntu.

I hope this is just a simple and dumb error on my part, but I cant find any info.

release 2.1.3 broken : inconsitent laz-perf version 2.1 or 3.0

Hi,
thanks for sharing this work

when building the last release of this copc-lib (2.1.3) the Readme says that laz-perf>= commit 4819611 is a pre-requisite

Current master README says : laz-perf>=3.0.0 is a pre-requisite

However when building with env :
export LAZPERF_DIR=/home/opt/laz-perf-3.0.0/build/CMakeFiles/Export/lib/cmake/LAZPERF
I get an error saying that I should use LAZPERF 2.1.0

-- Detecting C compile features - done
CMake Error at CMakeLists.txt:84 (find_package):
  Could not find a configuration file for package "LAZPERF" that is
  compatible with requested version "2.1.0".

  The following configuration files were considered but not accepted:

    /usr/local/lib/cmake/LAZPERF/lazperf-config.cmake, version: 3.0.0



-- Configuring incomplete, errors occurred!
See also "/home/opt/copc-lib-2.1.3/build/CMakeFiles/CMakeOutput.log".

When I try to build with laz-perf 2.1 the configure step is ok, but I got error at compile time:

[  6%] Building CXX object cpp/CMakeFiles/copc-lib.dir/src/copc/info.cpp.o
In file included from /home/opt/copc-lib-2.1.3/cpp/src/copc/info.cpp:1:
/home/opt/copc-lib-2.1.3/cpp/include/copc-lib/copc/info.hpp:15:29: error: ‘copc_info_vlr’ in namespace ‘lazperf’ does not name a type; did you mean ‘copc_vlr’?
   15 |     CopcInfo(const lazperf::copc_info_vlr &copc_info_vlr);
      |                             ^~~~~~~~~~~~~
      |                             copc_vlr

When I try to build with laz-perf 3.0 the configure step is ok, but I got error at compile time:

cmake --build .
Scanning dependencies of target copc-lib
[  6%] Building CXX object cpp/CMakeFiles/copc-lib.dir/src/copc/info.cpp.o
[ 12%] Building CXX object cpp/CMakeFiles/copc-lib.dir/src/copc/extents.cpp.o
In file included from /home/opt/copc-lib-2.1.3/cpp/include/copc-lib/copc/extents.hpp:10,
                 from /home/opt/copc-lib-2.1.3/cpp/src/copc/extents.cpp:1:
/home/opt/copc-lib-2.1.3/cpp/include/copc-lib/las/vlr.hpp:15:33: error: ‘copc_extents_vlr’ in namespace ‘lazperf’ does not name a type; did you mean ‘copc_info_vlr’?
   15 | using CopcExtentsVlr = lazperf::copc_extents_vlr;
      |                                 ^~~~~~~~~~~~~~~~
      |                                 copc_info_vlr

When I try to build copc-lib master branch with laz-perf 3.0 the configure step is OK, and compilation is OK.

python example should show how to read a LAS or LAZ and convert it to COPC

Hi,
I just like to try copc build by doing read LAS -> write COPC.
Unfortunately, if I want to stick to a minimal set of dependencies I think LAZperf which is included in copc-lib should be able to read a LAS or LAZ file.

However, there is no doc and no example on how to do this :(

>>> import copclib as copc
>>> reader = copc.FileReader("/home/jlu/Downloads/autzen-classified.laz")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Reader::InitReader: Either Info or Hierarchy VLR missing, make sure you are loading a COPC file.

In addition if i read a LAS using for example laspy module, is it still required to :

  • generate manually a copc header
  • generate manually the slippy tiles hierarchy
    ?

Do you have a simple LAS -> COPC python converter to share ?

Opening writer on a non-existant path throws seg fault

If you create a FileWriter on a path that doesn't exist, a seg fault will be thrown. For example:

writer = copclib.FileWriter("~/thispathdoesnotexist/test.laz", cfg)

Instead, a proper error message should be thrown, or the folder should be created automatically.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.