Skip to content

Commit

Permalink
Add streamer tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-alexandrov committed Nov 11, 2023
1 parent 9af6f7a commit 361ff60
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/writing-streamer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cmake_minimum_required(VERSION 3.6)
project(StreamerTutorial)

find_package(PDAL 2.0.0 REQUIRED CONFIG)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

add_executable(streamer_tutorial streamer_tutorial.cpp)

target_link_libraries(streamer_tutorial PRIVATE ${PDAL_LIBRARIES})
target_include_directories(streamer_tutorial PRIVATE
${PDAL_INCLUDE_DIRS}
${PDAL_INCLUDE_DIRS}/pdal)

63 changes: 63 additions & 0 deletions examples/writing-streamer/streamer_tutorial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <pdal/PointView.hpp>
#include <pdal/PointTable.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/Options.hpp>
#include <pdal/StageFactory.hpp>

#include <io/BufferReader.hpp>

#include <vector>

void fillView(pdal::PointViewPtr view)
{
struct Point
{
double x;
double y;
double z;
};

for (int i = 0; i < 1000; ++i)
{
Point p;

p.x = -93.0 + i*0.001;
p.y = 42.0 + i*0.001;
p.z = 106.0 + i;

view->setField(pdal::Dimension::Id::X, i, p.x);
view->setField(pdal::Dimension::Id::Y, i, p.y);
view->setField(pdal::Dimension::Id::Z, i, p.z);
}
}


int main(int argc, char* argv[])
{
using namespace pdal;

Options options;
options.add("filename", "myfile.las");

PointTable table;
table.layout()->registerDim(Dimension::Id::X);
table.layout()->registerDim(Dimension::Id::Y);
table.layout()->registerDim(Dimension::Id::Z);

PointViewPtr view(new PointView(table));

fillView(view);

BufferReader reader;
reader.addView(view);

StageFactory factory;

// StageFactory always "owns" stages it creates. They'll be destroyed with the factory.
Stage *writer = factory.createStage("writers.las");

writer->setInput(reader);
writer->setOptions(options);
writer->prepare(table);
writer->execute(table);
}

0 comments on commit 361ff60

Please sign in to comment.