Skip to content

Commit 8454f1a

Browse files
committed
Fix bindings Dims reading, we were lucky that it worked with las/laz files
1 parent dd51cb1 commit 8454f1a

File tree

9 files changed

+89
-23
lines changed

9 files changed

+89
-23
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ bin
99
target
1010
build/
1111
.gradle
12+
cmake-build-debug
1213

1314
# Eclipse Project Files
1415

build.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name := "pdal-jni"
22

33
lazy val commonSettings = Seq(
4-
version := "1.8.2" + Environment.versionSuffix,
4+
version := "1.8.3" + Environment.versionSuffix,
55
scalaVersion := "2.11.12",
66
crossScalaVersions := Seq("2.12.8", "2.11.12"),
77
organization := "io.pdal",

core/src/main/scala/io/pdal/DimType.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
package io.pdal
3535

36-
case class DimType(id: String, `type`: String, scale: Double = 1, offset: Double = 0)
36+
case class DimType(id: String, `type`: String)
3737

3838
object DimType {
3939
object Id {

core/src/main/scala/io/pdal/PointCloud.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import scala.collection.JavaConversions._
4545
case class PointCloud(bytes: Array[Byte], dimTypes: util.Map[String, SizedDimType]) {
4646
val pointSize: Int = dimTypes.values.map(_.size).sum.toInt
4747
val length: Int = bytes.length / pointSize
48-
val isPoint: Boolean = length == pointSize
48+
val isPoint: Boolean = length == 1
4949

5050
def dimSize(dim: SizedDimType) = dimTypes(dim.dimType.id).size
5151
def dimSize(dim: DimType) = dimTypes(dim.id).size

core/src/test/resources/test-pdal.csv

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
X,Y,Z,TEST
2+
289814.150,4320978.610,170.760,2.000
3+
289814.640,4320978.840,170.760,2.000
4+
289815.120,4320979.060,170.750,2.000
5+
289815.600,4320979.280,170.740,2.000
6+
289816.080,4320979.500,170.680,2.000
7+
289816.560,4320979.710,170.660,2.000
8+
289817.030,4320979.920,170.630,2.000
9+
289817.530,4320980.160,170.620,2.000
10+
289818.010,4320980.380,170.610,2.000
11+
289818.500,4320980.590,170.580,2.000

core/src/test/scala/io/pdal/PointCloudSpec.scala

+61
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,67 @@ class PointCloudSpec extends TestEnvironmentSpec {
175175
pv.dispose()
176176
pvi.dispose()
177177
}
178+
179+
it("should work as expected with csv files") {
180+
val expected = getJson("/test-pdal.csv").split(" ").tail.map(_.split(",").toList.map(_.toDouble)).toList
181+
182+
val json =
183+
"""
184+
|{
185+
| "pipeline":[
186+
| {
187+
| "type" : "readers.text",
188+
| "filename":"core/src/test/resources/test-pdal.csv"
189+
| }
190+
| ]
191+
|}
192+
""".stripMargin
193+
194+
val pipeline = Pipeline(json)
195+
pipeline.execute()
196+
val pvi = pipeline.getPointViews()
197+
val pv = pvi.next()
198+
val length = pv.length
199+
200+
length should be (expected.size)
201+
202+
val layout = pv.layout()
203+
val subsetDT = Array(layout.findDimType("X"), layout.findDimType("TEST"), layout.findDimType("Z"))
204+
205+
expected.zipWithIndex.foreach { case (List(x, y, z, test), idx) =>
206+
val pc = pv.getPointCloud(idx)
207+
208+
val pcX = pc.getDouble(idx, "X")
209+
val pcY = pc.getDouble(idx, "Y")
210+
val pcZ = pc.getDouble(idx, "Z")
211+
val pcTest = pc.getDouble(idx, "TEST")
212+
213+
val pvX = pv.getDouble(idx, "X")
214+
val pvY = pv.getDouble(idx, "Y")
215+
val pvZ = pv.getDouble(idx, "Z")
216+
val pvTest = pv.getDouble(idx, "TEST")
217+
218+
val pcs = pv.getPointCloud(idx, subsetDT)
219+
220+
val pcsX = pc.getDouble(idx, "X")
221+
val pcsZ = pc.getDouble(idx, "Z")
222+
val pcsTest = pc.getDouble(idx, "TEST")
223+
224+
x should be(pcX)
225+
x should be(pvX)
226+
x should be(pcsX)
227+
y should be(pcY)
228+
y should be(pvY)
229+
z should be(pcZ)
230+
z should be(pvZ)
231+
z should be(pcsZ)
232+
test should be(pcTest)
233+
test should be(pvTest)
234+
test should be(pcsTest)
235+
}
236+
237+
pipeline.dispose()
238+
}
178239
}
179240

180241
override def beforeAll() = {

native/src/io_pdal_PointLayout.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ JNIEXPORT jobjectArray JNICALL Java_io_pdal_PointLayout_dimTypes
4848
DimTypeList dimTypes = pl->dimTypes();
4949

5050
jclass dtClass = env->FindClass("io/pdal/DimType");
51-
jmethodID dtCtor = env->GetMethodID(dtClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;DD)V");
51+
jmethodID dtCtor = env->GetMethodID(dtClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
5252

5353
jobjectArray result = env->NewObjectArray(dimTypes.size(), dtClass, NULL);
5454

@@ -57,7 +57,7 @@ JNIEXPORT jobjectArray JNICALL Java_io_pdal_PointLayout_dimTypes
5757
auto dt = dimTypes.at(i);
5858
jstring id = env->NewStringUTF(pl->dimName(dt.m_id).c_str());
5959
jstring type = env->NewStringUTF(pdal::Dimension::interpretationName(dt.m_type).c_str());
60-
jobject element = env->NewObject(dtClass, dtCtor, id, type, dt.m_xform.m_scale.m_val, dt.m_xform.m_offset.m_val);
60+
jobject element = env->NewObject(dtClass, dtCtor, id, type);
6161

6262
env->SetObjectArrayElement(result, i, element);
6363

@@ -79,8 +79,8 @@ JNIEXPORT jobject JNICALL Java_io_pdal_PointLayout_findDimType
7979
jstring type = env->NewStringUTF(pdal::Dimension::interpretationName(dt.m_type).c_str());
8080

8181
jclass dtClass = env->FindClass("io/pdal/DimType");
82-
jmethodID dtCtor = env->GetMethodID(dtClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;DD)V");
83-
jobject result = env->NewObject(dtClass, dtCtor, id, type, dt.m_xform.m_scale.m_val, dt.m_xform.m_offset.m_val);
82+
jmethodID dtCtor = env->GetMethodID(dtClass, "<init>", "(Ljava/lang/String;Ljava/lang/String;)V");
83+
jobject result = env->NewObject(dtClass, dtCtor, id, type);
8484

8585
return result;
8686
}

native/src/io_pdal_PointView.cpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,18 @@ using pdal::DimType;
5757
/// \param[in] dims JavaArray of DimTypes
5858
/// \param[in] bufSize Dims sum size
5959
/// \param[in] dimTypes Vector of DimTypes
60-
void convertDimTypeJavaArrayToVector(JNIEnv *env, jobjectArray dims, std::size_t *pointSize, DimTypeList *dimTypes) {
60+
void convertDimTypeJavaArrayToVector(JNIEnv *env, jobjectArray dims, std::size_t *pointSize, DimTypeList *dimTypes, PointLayoutPtr pl) {
6161
for (jint i = 0; i < env->GetArrayLength(dims); i++) {
6262
jobject jDimType = reinterpret_cast<jobject>(env->GetObjectArrayElement(dims, i));
6363
jclass cDimType = env->GetObjectClass(jDimType);
6464
jfieldID fid = env->GetFieldID(cDimType, "id", "Ljava/lang/String;");
6565
jfieldID ftype = env->GetFieldID(cDimType, "type", "Ljava/lang/String;");
66-
jfieldID fscale = env->GetFieldID(cDimType, "scale", "D");
67-
jfieldID foffset = env->GetFieldID(cDimType, "offset", "D");
6866

6967
jstring jid = reinterpret_cast<jstring>(env->GetObjectField(jDimType, fid));
70-
jstring jtype = reinterpret_cast<jstring>(env->GetObjectField(jDimType, ftype));
71-
jdouble jscale = env->GetDoubleField(jDimType, fscale);
72-
jdouble joffset = env->GetDoubleField(jDimType, foffset);
68+
DimType dimType = pl->findDimType(std::string(env->GetStringUTFChars(jid, 0)));
7369

74-
Id id = pdal::Dimension::id(std::string(env->GetStringUTFChars(jid, 0)));
75-
Type type = pdal::Dimension::type(std::string(env->GetStringUTFChars(jtype, 0)));
76-
77-
*pointSize += pdal::Dimension::size(type);
78-
dimTypes->insert(dimTypes->begin() + i, DimType(id, type, jscale, joffset));
70+
*pointSize += pl->dimSize(dimType.m_id);
71+
dimTypes->insert(dimTypes->begin() + i, dimType);
7972
}
8073
}
8174

@@ -159,7 +152,7 @@ JNIEXPORT jbyteArray JNICALL Java_io_pdal_PointView_getPackedPoint
159152
DimTypeList dimTypes;
160153

161154
// calculate result buffer length (for one point) and get dimTypes
162-
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes);
155+
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes, pl);
163156

164157
char *buf = new char[pointSize];
165158

@@ -186,7 +179,7 @@ JNIEXPORT jbyteArray JNICALL Java_io_pdal_PointView_getPackedPoints
186179
DimTypeList dimTypes;
187180

188181
// calculate result buffer length (for one point) and get dimTypes
189-
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes);
182+
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes, pl);
190183

191184
// reading all points
192185
std::size_t bufSize = pointSize * pv->size();

scripts/merge-native.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ done
1717
export PDAL_VERSION_SUFFIX=${PDAL_VERSION_SUFFIX-"-SNAPSHOT"}
1818

1919
cd ./native/target
20-
rm -f ./pdal-native-1.8.2${PDAL_VERSION_SUFFIX}.jar
20+
rm -f ./pdal-native-1.8.3${PDAL_VERSION_SUFFIX}.jar
2121
rm -rf ./tmp; mkdir -p ./tmp
2222

23-
cd tmp; jar -xf ../pdal-native-x86_64-darwin-1.8.2${PDAL_VERSION_SUFFIX}.jar; cd ~-
24-
cd tmp; jar -xf ../pdal-native-x86_64-linux-1.8.2${PDAL_VERSION_SUFFIX}.jar; cd ~-
23+
cd tmp; jar -xf ../pdal-native-x86_64-darwin-1.8.3${PDAL_VERSION_SUFFIX}.jar; cd ~-
24+
cd tmp; jar -xf ../pdal-native-x86_64-linux-1.8.3${PDAL_VERSION_SUFFIX}.jar; cd ~-
2525

2626
jar -cvf pdal-native-1.8.0${PDAL_VERSION_SUFFIX}.jar -C tmp .
2727

0 commit comments

Comments
 (0)