Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dimTypes reading #16

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ bin
target
build/
.gradle
cmake-build-debug

# Eclipse Project Files

Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name := "pdal-jni"

lazy val commonSettings = Seq(
version := "1.8.2" + Environment.versionSuffix,
version := "1.8.3" + Environment.versionSuffix,
scalaVersion := "2.11.12",
crossScalaVersions := Seq("2.12.8", "2.11.12"),
organization := "io.pdal",
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/io/pdal/DimType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

package io.pdal

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

object DimType {
object Id {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/io/pdal/PointCloud.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import scala.collection.JavaConversions._
case class PointCloud(bytes: Array[Byte], dimTypes: util.Map[String, SizedDimType]) {
val pointSize: Int = dimTypes.values.map(_.size).sum.toInt
val length: Int = bytes.length / pointSize
val isPoint: Boolean = length == pointSize
val isPoint: Boolean = length == 1

def dimSize(dim: SizedDimType) = dimTypes(dim.dimType.id).size
def dimSize(dim: DimType) = dimTypes(dim.id).size
Expand Down
11 changes: 11 additions & 0 deletions core/src/test/resources/test-pdal.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
X,Y,Z,TEST
289814.150,4320978.610,170.760,2.000
289814.640,4320978.840,170.760,2.000
289815.120,4320979.060,170.750,2.000
289815.600,4320979.280,170.740,2.000
289816.080,4320979.500,170.680,2.000
289816.560,4320979.710,170.660,2.000
289817.030,4320979.920,170.630,2.000
289817.530,4320980.160,170.620,2.000
289818.010,4320980.380,170.610,2.000
289818.500,4320980.590,170.580,2.000
61 changes: 61 additions & 0 deletions core/src/test/scala/io/pdal/PointCloudSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,67 @@ class PointCloudSpec extends TestEnvironmentSpec {
pv.dispose()
pvi.dispose()
}

it("should work as expected with csv files") {
val expected = getJson("/test-pdal.csv").split(" ").tail.map(_.split(",").toList.map(_.toDouble)).toList

val json =
"""
|{
| "pipeline":[
| {
| "type" : "readers.text",
| "filename":"core/src/test/resources/test-pdal.csv"
| }
| ]
|}
""".stripMargin

val pipeline = Pipeline(json)
pipeline.execute()
val pvi = pipeline.getPointViews()
val pv = pvi.next()
val length = pv.length

length should be (expected.size)

val layout = pv.layout()
val subsetDT = Array(layout.findDimType("X"), layout.findDimType("TEST"), layout.findDimType("Z"))

expected.zipWithIndex.foreach { case (List(x, y, z, test), idx) =>
val pc = pv.getPointCloud(idx)

val pcX = pc.getDouble(idx, "X")
val pcY = pc.getDouble(idx, "Y")
val pcZ = pc.getDouble(idx, "Z")
val pcTest = pc.getDouble(idx, "TEST")

val pvX = pv.getDouble(idx, "X")
val pvY = pv.getDouble(idx, "Y")
val pvZ = pv.getDouble(idx, "Z")
val pvTest = pv.getDouble(idx, "TEST")

val pcs = pv.getPointCloud(idx, subsetDT)

val pcsX = pc.getDouble(idx, "X")
val pcsZ = pc.getDouble(idx, "Z")
val pcsTest = pc.getDouble(idx, "TEST")

x should be(pcX)
x should be(pvX)
x should be(pcsX)
y should be(pcY)
y should be(pvY)
z should be(pcZ)
z should be(pvZ)
z should be(pcsZ)
test should be(pcTest)
test should be(pvTest)
test should be(pcsTest)
}

pipeline.dispose()
}
}

override def beforeAll() = {
Expand Down
8 changes: 4 additions & 4 deletions native/src/io_pdal_PointLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ JNIEXPORT jobjectArray JNICALL Java_io_pdal_PointLayout_dimTypes
DimTypeList dimTypes = pl->dimTypes();

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

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

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

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

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

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

return result;
}
Expand Down
19 changes: 6 additions & 13 deletions native/src/io_pdal_PointView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,18 @@ using pdal::DimType;
/// \param[in] dims JavaArray of DimTypes
/// \param[in] bufSize Dims sum size
/// \param[in] dimTypes Vector of DimTypes
void convertDimTypeJavaArrayToVector(JNIEnv *env, jobjectArray dims, std::size_t *pointSize, DimTypeList *dimTypes) {
void convertDimTypeJavaArrayToVector(JNIEnv *env, jobjectArray dims, std::size_t *pointSize, DimTypeList *dimTypes, PointLayoutPtr pl) {
for (jint i = 0; i < env->GetArrayLength(dims); i++) {
jobject jDimType = reinterpret_cast<jobject>(env->GetObjectArrayElement(dims, i));
jclass cDimType = env->GetObjectClass(jDimType);
jfieldID fid = env->GetFieldID(cDimType, "id", "Ljava/lang/String;");
jfieldID ftype = env->GetFieldID(cDimType, "type", "Ljava/lang/String;");
jfieldID fscale = env->GetFieldID(cDimType, "scale", "D");
jfieldID foffset = env->GetFieldID(cDimType, "offset", "D");

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

Id id = pdal::Dimension::id(std::string(env->GetStringUTFChars(jid, 0)));
Type type = pdal::Dimension::type(std::string(env->GetStringUTFChars(jtype, 0)));

*pointSize += pdal::Dimension::size(type);
dimTypes->insert(dimTypes->begin() + i, DimType(id, type, jscale, joffset));
*pointSize += pl->dimSize(dimType.m_id);
dimTypes->insert(dimTypes->begin() + i, dimType);
}
}

Expand Down Expand Up @@ -159,7 +152,7 @@ JNIEXPORT jbyteArray JNICALL Java_io_pdal_PointView_getPackedPoint
DimTypeList dimTypes;

// calculate result buffer length (for one point) and get dimTypes
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes);
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes, pl);

char *buf = new char[pointSize];

Expand All @@ -186,7 +179,7 @@ JNIEXPORT jbyteArray JNICALL Java_io_pdal_PointView_getPackedPoints
DimTypeList dimTypes;

// calculate result buffer length (for one point) and get dimTypes
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes);
convertDimTypeJavaArrayToVector(env, dims, &pointSize, &dimTypes, pl);

// reading all points
std::size_t bufSize = pointSize * pv->size();
Expand Down
Loading