Skip to content

Commit 00a5994

Browse files
authored
Expand Code examples README.md (#77)
1 parent 5b00174 commit 00a5994

File tree

3 files changed

+106
-697
lines changed

3 files changed

+106
-697
lines changed

README.md

Lines changed: 104 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ libraryDependencies ++= Seq(
5252
Scala API covers PDAL 2.0.x, to use any custom DSL that is not covered by the
5353
current Scala API you can use `RawExpr` type to build `Pipeline Expression`.
5454

55-
### Code examples
55+
## Code examples
56+
57+
#### Demo project with examples
58+
59+
JNI bindings basic usage examples can be found [here](./examples).
60+
61+
### PDAL Core (Scala 2.x / 3.x)
5662

5763
```scala
58-
// To construct the expected json
59-
val expected =
64+
import io.pdal._
65+
66+
// pipeline definition
67+
val json =
6068
"""
6169
|{
6270
| "pipeline" : [
@@ -74,20 +82,43 @@ val expected =
7482
| ]
7583
|}
7684
""".stripMargin
77-
78-
// The same, but using scala DSL
79-
val pc = ReadLas("/path/to/las") ~ FilterCrop() ~ WriteLas("/path/to/new/las")
8085

81-
// The same, but using RawExpr, to support not implemented PDAL Pipeline API features
82-
// RawExpr accepts a circe.Json type, which can be a json object of any desired complexity
83-
val pcWithRawExpr = ReadLas("/path/to/las") ~ RawExpr(Map("type" -> "filters.crop").asJson) ~ WriteLas("/path/to/new/las")
86+
val pipeline = Pipeline(json)
87+
pipeline.validate() // check if our JSON and options were good
88+
pipeline.setLogLevel(LogLevel.Debug5) // make it really noisy
89+
pipeline.execute() // execute the pipeline
90+
val metadata = pipeline.getMetadata() // retrieve metadata
91+
val pvs = pipeline.getPointViews() // iterator over PointViews
92+
val pv = pvs.next() // let's take the first PointView
93+
94+
// load all points into JVM memory
95+
// PointCloud provides operations on PDAL points that
96+
// are loaded in this case into JVM memory as a single Array[Byte]
97+
val pointCloud = pv.getPointCloud()
98+
val x = pointCloud.getDouble(0, DimType.X) // get a point with PointId = 0 and only a single dimensions
99+
100+
// in some cases it is not neccesary to load everything into JVM memory
101+
// so it is possible to get only required points directly from the PointView
102+
val y = pv.getDouble(0, DimType.Y)
103+
104+
// it is also possible to get access to the triangular mesh generated via PDAL
105+
val mesh = pv.getTriangularMesh()
106+
// the output is an Array of Triangles
107+
// Each Triangle contains PointIds from the PDAL point table
108+
val triangles = mesh.asArray
109+
110+
pv.close()
111+
pvs.close()
112+
pipeline.close()
84113
```
85-
## Use PDAL inside a JAVA environment
86-
This is an example about how to use pdal inside a pure java environment.
114+
115+
### PDAL Core (Java)
87116

88117
```java
89-
// Create the expected json String
90-
String expectedJSON =
118+
import io.pdal.*;
119+
120+
// pipeline definition
121+
String json =
91122
"""
92123
|{
93124
| "pipeline" : [
@@ -104,32 +135,75 @@ String expectedJSON =
104135
| }
105136
| ]
106137
|}
107-
"""
108-
// Decide the verbosity of your output
109-
int logLevel = 0;
138+
""";
139+
140+
var pipeline = new Pipeline(json, LogLevel.Error());
141+
142+
pipeline.initialize(); // initialize the pipeline
143+
pipeline.execute(); // execute the pipeline
144+
145+
var metadata = pipeline.getMetadata(); // retrieve metadata
146+
var pvs = pipeline.getPointViews(); // iterator over PointViews
147+
var pv = pvs.next(); // let's take the first PointView
110148
111-
// Initialine a Pipeline object
112-
// Be careful, before version v2.5.0 the constructor was 'new Pipeline(String jsonString)'
113-
Pipeline pipeline = new Pipeline(json,3);
149+
// load all points into JVM memory
150+
// PointCloud provides operations on PDAL points that
151+
// are loaded in this case into JVM memory as a single Array[Byte]
152+
var pointCloud = pv.getPointCloud();
153+
var x = pointCloud.getDouble(0, DimType.X()); // get a point with PointId = 0 and only a single dimensions
114154
115-
// Initialize the pipeline
116-
pipeline.initialize();
155+
// in some cases it is not neccesary to load everything into JVM memory
156+
// so it is possible to get only required points directly from the PointView
157+
var y = pv.getDouble(0, DimType.Y());
117158
118-
// Execute the pipeline
119-
pipeline.execute();
159+
// it is also possible to get access to the triangular mesh generated via PDAL
160+
var mesh = pv.getTriangularMesh();
161+
// the output is an Array of Triangles
162+
// Each Triangle contains PointIds from the PDAL point table
163+
var triangles = mesh.asArray();
120164
121-
// Now you can for example extract a PointViewIterator
122-
PointViewIterator pvs = pipeline.getPointViews();
123-
// And a single PointView..
124-
PointView pv = pvs.next();
125-
// Now remember to close the pipeline to avoid a leak of resources
165+
pv.close();
126166
pvs.close();
127167
pipeline.close();
128168
```
129169
130-
### Demo project example
170+
### PDAL Scala
131171
132-
JNI bindings basic usage examples can be found [here](./examples).
172+
```scala
173+
import io.pdal._
174+
import io.pdal.pipeline._
175+
176+
// To construct the expected json
177+
val expected =
178+
"""
179+
|{
180+
| "pipeline" : [
181+
| {
182+
| "filename" : "/path/to/las",
183+
| "type" : "readers.las"
184+
| },
185+
| {
186+
| "type" : "filters.crop"
187+
| },
188+
| {
189+
| "filename" : "/path/to/new/las",
190+
| "type" : "writers.las"
191+
| }
192+
| ]
193+
|}
194+
""".stripMargin
195+
196+
// The same, but using scala DSL
197+
val pc = ReadLas("/path/to/las") ~ FilterCrop() ~ WriteLas("/path/to/new/las")
198+
199+
// The same, but using RawExpr, to support not implemented PDAL Pipeline API features
200+
// RawExpr accepts a circe.Json type, which can be a json object of any desired complexity
201+
val pcWithRawExpr = ReadLas("/path/to/las") ~ RawExpr(Map("type" -> "filters.crop").asJson) ~ WriteLas("/path/to/new/las")
202+
203+
// Create Pipelines from the constructed expressions
204+
val pipelinePc = pc.toPipeline
205+
val pipelinePc = pcWithRawExpr.toPipline
206+
```
133207

134208
## How to compile
135209

0 commit comments

Comments
 (0)