diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt index 2525cc8a4f116a2d63080e5caf9884774ac98083..81397d3abf2805c58f5fa9dcf1ae504f82f244c2 100644 --- a/java/CMakeLists.txt +++ b/java/CMakeLists.txt @@ -28,6 +28,7 @@ set(JAVA_SOURCE_FILES java/src/org/opengroup/openvds/JniPointer.java java/src/org/opengroup/openvds/JniPointerWithoutDeletion.java java/src/org/opengroup/openvds/MemoryVdsGenerator.java + java/src/org/opengroup/openvds/MetadataContainer.java java/src/org/opengroup/openvds/MetadataKey.java java/src/org/opengroup/openvds/MetadataReadAccess.java java/src/org/opengroup/openvds/MetadataType.java @@ -36,7 +37,9 @@ set(JAVA_SOURCE_FILES java/src/org/opengroup/openvds/OpenOptions.java java/src/org/opengroup/openvds/OpenVDS.java java/src/org/opengroup/openvds/QuantizingValueConverter_FloatToByte.java + java/src/org/opengroup/openvds/VdsError.java java/src/org/opengroup/openvds/VdsHandle.java + java/src/org/opengroup/openvds/VDSFileOpenOptions.java java/src/org/opengroup/openvds/VDSProduceStatus.java java/src/org/opengroup/openvds/VolumeDataAccessManager.java java/src/org/opengroup/openvds/VolumeDataAccessor.java @@ -47,6 +50,12 @@ set(JAVA_SOURCE_FILES java/src/org/opengroup/openvds/VolumeDataMapping.java java/src/org/opengroup/openvds/VolumeDataPage.java java/src/org/opengroup/openvds/VolumeDataPageAccessor.java + java/src/org/opengroup/openvds/VolumeIndexerBase.java + java/src/org/opengroup/openvds/VolumeIndexer2D.java + java/src/org/opengroup/openvds/VolumeIndexer3D.java + java/src/org/opengroup/openvds/VolumeIndexer4D.java + java/src/org/opengroup/openvds/VolumeIndexer5D.java + java/src/org/opengroup/openvds/VolumeIndexer6D.java java/demo/AWSSliceDumpDemo.java java/demo/OpenVdsDemo.java @@ -102,16 +111,24 @@ add_library(openvds-javacpp cpp/src/CommonJni.cpp cpp/src/JniPointer.cpp cpp/src/MemoryVdsGenerator.cpp + cpp/src/MetadataContainer.cpp cpp/src/MetadataReadAccess.cpp cpp/src/OpenVDSJava.cpp cpp/src/QuantizingValueConverter_FloatToByte.cpp cpp/src/VariousJavaTests.cpp + cpp/src/VdsError.cpp cpp/src/VdsHandle.cpp cpp/src/VolumeDataAccessManager.cpp cpp/src/VolumeDataAccessor.cpp cpp/src/VolumeDataLayout.cpp cpp/src/VolumeDataPage.cpp cpp/src/VolumeDataPageAccessor.cpp + cpp/src/VolumeIndexerBase.cpp + cpp/src/VolumeIndexer2D.cpp + cpp/src/VolumeIndexer3D.cpp + cpp/src/VolumeIndexer4D.cpp + cpp/src/VolumeIndexer5D.cpp + cpp/src/VolumeIndexer6D.cpp cpp/src/WriteVolumeData.cpp ) diff --git a/java/cpp/include/CommonJni.h b/java/cpp/include/CommonJni.h index 980e61553752fc42d3fcb4b22dcf449f85f578d7..11ef5f8df5dd65970620c1054c641df714f89514 100644 --- a/java/cpp/include/CommonJni.h +++ b/java/cpp/include/CommonJni.h @@ -41,6 +41,7 @@ std::vector JArrayToVector( JNIEnv* env, jbyteArray jArr, int start, int l std::vector JArrayToVector( JNIEnv* env, jshortArray jArr ); std::vector JArrayToVector( JNIEnv* env, jintArray jArr ); std::vector JArrayToVector( JNIEnv* env, jfloatArray jArr ); +std::vector JArrayToVector( JNIEnv* env, jdoubleArray jArr ); jbyteArray NewJByteArray( JNIEnv* env, const std::string& str ); jstring NewJString( JNIEnv* env, const char* str ); diff --git a/java/cpp/src/CommonJni.cpp b/java/cpp/src/CommonJni.cpp index f8fd2006be83308e2c4f3bd0e2ab37a0f251e8b1..698238b752a8be521631ffb3347fc5a9c24637aa 100644 --- a/java/cpp/src/CommonJni.cpp +++ b/java/cpp/src/CommonJni.cpp @@ -117,6 +117,16 @@ std::vector JArrayToVector( JNIEnv* env, jfloatArray jArr ) { return arr; } +std::vector JArrayToVector( JNIEnv* env, jdoubleArray jArr ) { + if( !jArr ) + return std::vector(); + if( sizeof( jdouble ) != sizeof( double ) ) + ThrowJavaException( env, "sizeof(jdouble)!=sizeof(double)" ); + jsize len = env->GetArrayLength( jArr ); + std::vector arr( len ); + env->GetDoubleArrayRegion( jArr, 0, len, (jdouble*)arr.data() ); + return arr; +} jstring NewJString( JNIEnv* env, const char* str ) { if( !str || !*str ) diff --git a/java/cpp/src/MetadataContainer.cpp b/java/cpp/src/MetadataContainer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d99ca48b05bcfe777479b1cb9018baff701a53f6 --- /dev/null +++ b/java/cpp/src/MetadataContainer.cpp @@ -0,0 +1,290 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + inline MetadataContainer* GetAccess( jlong handle ) { + return (MetadataContainer*)CheckHandle( handle ); + } + + /* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpCreateMetadataContainerHandle + * Signature: ()J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_MetadataContainer_cpCreateMetadataContainerHandle + (JNIEnv * env, jclass) + { + try { + MetadataContainer* container = new MetadataContainer(); + return reinterpret_cast(container); + } + CATCH_EXCEPTIONS_FOR_JAVA; + + return -1L; + } + + /* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpDeleteHandle + * Signature: (J)J + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpDeleteHandle + (JNIEnv * env, jclass, jlong handle) { + try { + delete GetAccess( handle ); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataInt + * Signature: (JLjava/lang/String;Ljava/lang/String;I)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataInt + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jint value) + { + try { + GetAccess( handle )->SetMetadataInt( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), value); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataIntVector2 + * Signature: (JLjava/lang/String;Ljava/lang/String;[I)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataIntVector2 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jintArray vec2i) +{ + try { + std::vector vec = JArrayToVector(env, vec2i); + IntVector2 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + GetAccess( handle )->SetMetadataIntVector2( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataIntVector3 + * Signature: (JLjava/lang/String;Ljava/lang/String;[I)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataIntVector3 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jintArray vec3i) +{ + try { + std::vector vec = JArrayToVector(env, vec3i); + IntVector3 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + vdsVec[2] = vec[2]; + GetAccess( handle )->SetMetadataIntVector3( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataIntVector4 + * Signature: (JLjava/lang/String;Ljava/lang/String;[I)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataIntVector4 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jintArray vec4i) +{ + try { + std::vector vec = JArrayToVector(env, vec4i); + IntVector4 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + vdsVec[2] = vec[2]; + vdsVec[3] = vec[3]; + GetAccess( handle )->SetMetadataIntVector4( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataFloat + * Signature: (JLjava/lang/String;Ljava/lang/String;F)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataFloat + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jfloat value) +{ + try { + GetAccess( handle )->SetMetadataFloat( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), value); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataFloatVector2 + * Signature: (JLjava/lang/String;Ljava/lang/String;[F)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataFloatVector2 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jfloatArray vec2f) +{ + try { + std::vector vec = JArrayToVector(env, vec2f); + FloatVector2 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + GetAccess( handle )->SetMetadataFloatVector2( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataFloatVector3 + * Signature: (JLjava/lang/String;Ljava/lang/String;[F)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataFloatVector3 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jfloatArray vec3f) +{ + try { + std::vector vec = JArrayToVector(env, vec3f); + FloatVector3 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + vdsVec[2] = vec[2]; + GetAccess( handle )->SetMetadataFloatVector3( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataFloatVector4 + * Signature: (JLjava/lang/String;Ljava/lang/String;[F)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataFloatVector4 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jfloatArray vec4f) +{ + try { + std::vector vec = JArrayToVector(env, vec4f); + FloatVector4 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + vdsVec[2] = vec[2]; + vdsVec[3] = vec[3]; + GetAccess( handle )->SetMetadataFloatVector4( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataDouble + * Signature: (JLjava/lang/String;Ljava/lang/String;D)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataDouble + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jdouble value) +{ + try { + GetAccess( handle )->SetMetadataDouble( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), value); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataDoubleVector2 + * Signature: (JLjava/lang/String;Ljava/lang/String;[D)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataDoubleVector2 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jdoubleArray vec2d) +{ + try { + std::vector vec = JArrayToVector(env, vec2d); + DoubleVector2 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + GetAccess( handle )->SetMetadataDoubleVector2( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataDoubleVector3 + * Signature: (JLjava/lang/String;Ljava/lang/String;[D)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataDoubleVector3 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jdoubleArray vec3d) +{ + try { + std::vector vec = JArrayToVector(env, vec3d); + DoubleVector3 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + vdsVec[2] = vec[2]; + GetAccess( handle )->SetMetadataDoubleVector3( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataDoubleVector4 + * Signature: (JLjava/lang/String;Ljava/lang/String;[D)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataDoubleVector4 + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jdoubleArray vec4d) +{ + try { + std::vector vec = JArrayToVector(env, vec4d); + DoubleVector4 vdsVec; + vdsVec[0] = vec[0]; + vdsVec[1] = vec[1]; + vdsVec[2] = vec[2]; + vdsVec[3] = vec[3]; + GetAccess( handle )->SetMetadataDoubleVector4( JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), vdsVec); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_MetadataContainer + * Method: cpSetMetadataString + * Signature: (JLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_MetadataContainer_cpSetMetadataString + (JNIEnv * env, jclass, jlong handle, jstring category, jstring name, jstring value) +{ + try { + GetAccess( handle )->SetMetadataString(JStringToString( env, category ).c_str(), JStringToString( env, name ).c_str(), JStringToString(env, value).c_str()); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +#ifdef __cplusplus +} +#endif diff --git a/java/cpp/src/OpenVDSJava.cpp b/java/cpp/src/OpenVDSJava.cpp index 89743d7d5127b99abc83401611653df3e1ec73f7..fb4c585652f96baac4c736e051e5edae65781342 100644 --- a/java/cpp/src/OpenVDSJava.cpp +++ b/java/cpp/src/OpenVDSJava.cpp @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -86,6 +87,20 @@ jlong JNICALL Java_org_opengroup_openvds_OpenVDS_cpOpenGoogle return openVDSOrThrowJavaIOException(env, openOptions); } +/* + * Class: org_opengroup_openvds_OpenVDS + * Method: cpOpenVDSFile + * Signature: (Ljava/lang/String;)J + */ +JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_OpenVDS_cpOpenVDSFile + (JNIEnv *env, jclass, jstring jfilepath) { + OpenVDS::VDSFileOpenOptions openOptions; + + openOptions.fileName = JStringToString(env, jfilepath); + + return openVDSOrThrowJavaIOException(env, openOptions); +} + /* * Class: org_opengroup_openvds_OpenVDS * Method: cpOpenAzurePresigned @@ -163,6 +178,22 @@ getMetadata(JNIEnv *env, jobject md) return reinterpret_cast(CheckHandle(handle)); } +static OpenVDS::MetadataContainer* +getMetadataContainer(JNIEnv *env, jobject mdc) +{ + jclass obj_class = env->GetObjectClass(mdc); + jlong handle = env->CallLongMethod(mdc, env->GetMethodID(obj_class, "handle", "()J")); + return reinterpret_cast(CheckHandle(handle)); +} + +static OpenVDS::Error* +getError(JNIEnv *env, jobject err) +{ + jclass obj_class = env->GetObjectClass(err); + jlong handle = env->CallLongMethod(err, env->GetMethodID(obj_class, "handle", "()J")); + return reinterpret_cast(CheckHandle(handle)); +} + static std::vector getValueDataAxisDescriptors(JNIEnv *env, jobjectArray obj, std::multiset& string_buffer) { @@ -269,12 +300,19 @@ getDescriptor(JNIEnv *env, jobject obj) int brickSize2DMultiplier = env->CallIntMethod(obj, env->GetMethodID(obj_class, "getBrickSizeMultiplier2D", "()I")); auto lodLevels = getLODLevels(env, obj); - int fullResolutionDimension = env->CallBooleanMethod(obj, env->GetMethodID(obj_class, "isForceFullResolutionDimension", "()Z")); - - int options = (env->CallBooleanMethod(obj, env->GetMethodID(obj_class, "isCreate2DLODs", "()Z")) << 1); + bool forceFullResolutionDimension = env->CallBooleanMethod(obj, env->GetMethodID(obj_class, "isForceFullResolutionDimension", "()Z")); + int fullResDim = env->CallIntMethod(obj, env->GetMethodID(obj_class, "getFullResolutionDimension", "()I")); + bool lod2D = env->CallBooleanMethod(obj, env->GetMethodID(obj_class, "isCreate2DLODs", "()Z")); + int optionsP = OpenVDS::VolumeDataLayoutDescriptor::Options::Options_None; + if (lod2D) { + optionsP |= OpenVDS::VolumeDataLayoutDescriptor::Options::Options_Create2DLODs; + } + if (forceFullResolutionDimension) { + optionsP |= OpenVDS::VolumeDataLayoutDescriptor::Options::Options_ForceFullResolutionDimension; + } return OpenVDS::VolumeDataLayoutDescriptor(brickSize, negativeMargin, positiveMargin, brickSize2DMultiplier, - lodLevels, (OpenVDS::VolumeDataLayoutDescriptor::Options) options, fullResolutionDimension); + lodLevels, (OpenVDS::VolumeDataLayoutDescriptor::Options) optionsP, fullResDim); } jboolean JNICALL @@ -321,6 +359,21 @@ Java_org_opengroup_openvds_OpenVDS_cpCreateAzure(JNIEnv *env, jclass, jstring jC return createVDSOrThrowJavaIOException(env, openOptions, ld, vda, vdc, md, compressionMethod, compressionTolerance); } +/* + * Class: org_opengroup_openvds_OpenVDS + * Method: cpCreateVDSFile + * Signature: (Ljava/lang/String;Lorg/opengroup/openvds/VolumeDataLayoutDescriptor;[Lorg/opengroup/openvds/VolumeDataAxisDescriptor;[Lorg/opengroup/openvds/VolumeDataChannelDescriptor;Lorg/opengroup/openvds/MetadataReadAccess;)J + */ +JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_OpenVDS_cpCreateVDSFile + (JNIEnv *env, jclass, jstring jVDSFilePath, + jobject ld, jobjectArray vda, jobjectArray vdc, jobject md, jint compressionMethod, jfloat compressionTolerance) { + OpenVDS::VDSFileOpenOptions openOptions; + + openOptions.fileName = JStringToString(env, jVDSFilePath); + + return createVDSOrThrowJavaIOException(env, openOptions, ld, vda, vdc, md, compressionMethod, compressionTolerance); +} + jlong JNICALL Java_org_opengroup_openvds_OpenVDS_cpCreateAws(JNIEnv *env, jclass, jstring jbucket, jstring jkey, jstring jregion, jstring jendpointoverhide, jstring jaccessKeyId, jstring jsecretKey, jstring jsessionToken, jstring jexpiration, @@ -390,3 +443,4 @@ Java_org_opengroup_openvds_OpenVDS_cpCreateConnection(JNIEnv* env, jclass, return (jlong)pVds; } + diff --git a/java/cpp/src/VdsError.cpp b/java/cpp/src/VdsError.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9cfae8be67e4c69a3f41b44092f7a6d8c42d4af1 --- /dev/null +++ b/java/cpp/src/VdsError.cpp @@ -0,0 +1,125 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + +inline Error* GetError( jlong handle ) { + return (Error*)CheckHandle( handle ); +} + +/* + * Class: org_opengroup_openvds_VdsError + * Method: cpCreateErrorHandle + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VdsError_cpCreateErrorHandle + (JNIEnv * env, jclass) +{ + try { + Error *error = new Error(); + return reinterpret_cast(error); + } + CATCH_EXCEPTIONS_FOR_JAVA; + + return -1L; +} + +/* + * Class: org_opengroup_openvds_VdsError + * Method: cpDeleteHandle + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_VdsError_cpDeleteHandle + (JNIEnv * env, jclass, jlong handle) +{ + try { + delete &GetError( handle )->string; + delete GetError( handle ); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_VdsError + * Method: cpSetErrorCode + * Signature: (JI)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_VdsError_cpSetErrorCode + (JNIEnv * env, jclass, jlong handle, jint errorCode) +{ + try { + GetError( handle )->code = errorCode; + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_VdsError + * Method: cpSetErrorMessage + * Signature: (JLjava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_opengroup_openvds_VdsError_cpSetErrorMessage + (JNIEnv * env, jclass, jlong handle, jstring errorMsg) +{ + try { + GetError( handle )->string = JStringToString( env, errorMsg ).c_str(); + } + CATCH_EXCEPTIONS_FOR_JAVA; +} + +/* + * Class: org_opengroup_openvds_VdsError + * Method: cpGetErrorCode + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VdsError_cpGetErrorCode + (JNIEnv * env, jclass, jlong handle) +{ + try { + return GetError(handle)->code; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; +} + +/* + * Class: org_opengroup_openvds_VdsError + * Method: cpGetErrorMessage + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_opengroup_openvds_VdsError_cpGetErrorMessage + (JNIEnv * env, jclass, jlong handle) +{ + try { + return NewJString(env, GetError(handle)->string); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; +} + + +#ifdef __cplusplus +} +#endif diff --git a/java/cpp/src/VolumeDataAccessManager.cpp b/java/cpp/src/VolumeDataAccessManager.cpp index c9d86c0968a81b8e3cf1ffc80430c7612e888e70..65ba0f8d53a423b32f4f8df838316f6d6d3f3313 100644 --- a/java/cpp/src/VolumeDataAccessManager.cpp +++ b/java/cpp/src/VolumeDataAccessManager.cpp @@ -16,11 +16,8 @@ */ #include -#include #include #include -#include - using namespace OpenVDS; @@ -76,11 +73,11 @@ JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpGetV } /* -* Class: org_opengroup_openvds_VolumeDataAccessManager -* Method: cpCreateVolumeDataPageAccessor -* Signature: (JIIIII)J -*/ -JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpCreateVolumeDataPageAccessor__JJIIIII + * Class: org_opengroup_openvds_VolumeDataAccessManager + * Method: cpCreateVolumeDataPageAccessor + * Signature: (JIIIII)J + */ +JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpCreateVolumeDataPageAccessor__JIIIII (JNIEnv *env, jclass, jlong managerHandle, jint dimensionsND, jint lod, jint channel, jint maxPages, jint accessMode) { try { @@ -93,11 +90,11 @@ JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpCre } /* -* Class: org_opengroup_openvds_VolumeDataAccessManager -* Method: cpCreateVolumeDataPageAccessor -* Signature: (JIIIIII)J -*/ -JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpCreateVolumeDataPageAccessor__JJIIIIII + * Class: org_opengroup_openvds_VolumeDataAccessManager + * Method: cpCreateVolumeDataPageAccessor + * Signature: (JIIIIII)J + */ +JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpCreateVolumeDataPageAccessor__JIIIIII (JNIEnv *env, jclass, jlong managerHandle, jint dimensionsND, jint lod, jint channel, jint maxPages, jint accessMode, jint chunkMetadataPageSize) { try { @@ -566,6 +563,26 @@ JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpUplo return 0; } +/* + * Class: org_opengroup_openvds_VolumeDataAccessManager + * Method: cpGetCurrentUploadErrorCode + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeDataAccessManager_cpGetCurrentUploadErrorCode + (JNIEnv * env, jclass, jlong handle) +{ + try { + const char *pObjectID = nullptr; + const char *pErrorString = nullptr; + int32_t errorCode = 0; + + GetManager(handle)->GetCurrentUploadError(&pObjectID, &errorCode, &pErrorString); + return errorCode; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; +} + #ifdef __cplusplus } #endif diff --git a/java/cpp/src/VolumeDataPage.cpp b/java/cpp/src/VolumeDataPage.cpp index fdc3fada56979ce3559bf16901629599be91bea1..3e6f33bc2bf390132afb9410c1aa5e282eec374b 100644 --- a/java/cpp/src/VolumeDataPage.cpp +++ b/java/cpp/src/VolumeDataPage.cpp @@ -16,17 +16,239 @@ */ #include +#include +#include +#include #ifdef __cplusplus extern "C" { #endif -/* - * Class: org_opengroup_openvds_VolumeDataPage - * Method: cpDeleteHandle - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpDeleteHandle - (JNIEnv *, jclass, jlong); + + inline OpenVDS::VolumeDataPage* GetVolumePage( jlong handle ) { + return (OpenVDS::VolumeDataPage*) CheckHandle( handle ); + } + + inline int GetBufferAllocatedSize(OpenVDS::VolumeDataPage* page) { + OpenVDS::VolumeDataPageImpl* pageImpl = (OpenVDS::VolumeDataPageImpl*)page; + const OpenVDS::DataBlock block = pageImpl->GetDataBlock(); + int nbElem = 1; + for (int i = 0 ; i < OpenVDS::DataBlock::Dimensionality::Dimensionality_Max ; i++) { + nbElem *= block.AllocatedSize[i]; + } + return nbElem; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpDeleteHandle + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpDeleteHandle + (JNIEnv *, jclass, jlong); + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpRelease + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpRelease + (JNIEnv * env, jclass, jlong handle) + { + try { + GetVolumePage( handle )->Release(); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetMinMax + * Signature: (J[I[I)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetMinMax + (JNIEnv * env, jclass, jlong handle, jintArray minArr, jintArray maxArr) + { + try { + int cMin[OpenVDS::Dimensionality_Max]; + int cMax[OpenVDS::Dimensionality_Max]; + GetVolumePage(handle)->GetMinMax(cMin, cMax); + env->SetIntArrayRegion(minArr, 0, OpenVDS::Dimensionality_Max, cMin); + env->SetIntArrayRegion(maxArr, 0, OpenVDS::Dimensionality_Max, cMax); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetMinMaxExcludingMargin + * Signature: (J[I[I)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetMinMaxExcludingMargin + (JNIEnv * env, jclass, jlong handle, jintArray minArr, jintArray maxArr) + { + try { + int cMin[OpenVDS::Dimensionality_Max]; + int cMax[OpenVDS::Dimensionality_Max]; + GetVolumePage(handle)->GetMinMaxExcludingMargin(cMin, cMax); + env->SetIntArrayRegion(minArr, 0, OpenVDS::Dimensionality_Max, cMin); + env->SetIntArrayRegion(maxArr, 0, OpenVDS::Dimensionality_Max, cMax); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetAllocatedSize + * Signature: (J)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetAllocatedSize + (JNIEnv * env, jclass, jlong handle) + { + try { + return GetBufferAllocatedSize(GetVolumePage(handle)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetPitch + * Signature: (J[I)[I + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetPitch + (JNIEnv * env, jclass, jlong handle, jintArray pitchArray) + { + try { + int pitch[OpenVDS::Dimensionality_Max]; + OpenVDS::VolumeDataPage* page = GetVolumePage(handle); + page->GetBuffer(pitch); + env->SetIntArrayRegion(pitchArray, 0, OpenVDS::Dimensionality_Max, pitch); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetByteBuffer + * Signature: (J[I)[B + */ + JNIEXPORT jbyteArray JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetByteBuffer + (JNIEnv * env, jclass, jlong handle, jintArray pitchParam, jint lod) + { + try { + int pitch[OpenVDS::Dimensionality_Max]; + OpenVDS::VolumeDataPage* page = GetVolumePage(handle); + + const char* readData = static_cast(page->GetBuffer(pitch)); + env->SetIntArrayRegion(pitchParam, 0, OpenVDS::Dimensionality_Max, pitch); + int nbElem = GetBufferAllocatedSize(page); + return NewJByteArray(env, readData, nbElem); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return NULL; + } + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpSetByteBuffer + * Signature: (J[B)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpSetByteBuffer + (JNIEnv * env, jclass, jlong handle, jbyteArray values) + { + try { + OpenVDS::VolumeDataPage * page = GetVolumePage(handle); + int pitch[OpenVDS::Dimensionality_Max]; + unsigned char* pageBuffer = reinterpret_cast(page->GetWritableBuffer(pitch)); + int valueSize = env->GetArrayLength(values); + jbyte *src = env->GetByteArrayElements(values, 0); + std::memcpy(pageBuffer, src, valueSize * sizeof (char)); + env->ReleaseByteArrayElements(values, src, 0); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetWritableFloatBuffer + * Signature: (J[I)[F + */ + JNIEXPORT jfloatArray JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetFloatBuffer + (JNIEnv * env, jclass, jlong handle, jintArray pitchParam, jint lod) + { + try { + int pitch[OpenVDS::Dimensionality_Max]; + OpenVDS::VolumeDataPage* page = GetVolumePage(handle); + + const float* readData = static_cast(page->GetBuffer(pitch)); + env->SetIntArrayRegion(pitchParam, 0, OpenVDS::Dimensionality_Max, pitch); + int nbElem = GetBufferAllocatedSize(page); + return NewJFloatArray(env, readData, nbElem); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return NULL; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpSetFloatBuffer + * Signature: (J[F[I)[F + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpSetFloatBuffer + (JNIEnv * env, jclass, jlong handle, jfloatArray values) + { + try { + OpenVDS::VolumeDataPage * page = GetVolumePage(handle); + int pitch[OpenVDS::Dimensionality_Max]; + float* pageBuffer = reinterpret_cast(page->GetWritableBuffer(pitch)); + int valueSize = env->GetArrayLength(values); + jfloat *src = env->GetFloatArrayElements(values, 0); + std::memcpy(pageBuffer, src, valueSize * sizeof (float)); + env->ReleaseFloatArrayElements(values, src, 0); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpGetDoubleBuffer + * Signature: (J[I)[D + */ + JNIEXPORT jdoubleArray JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpGetDoubleBuffer + (JNIEnv * env, jclass, jlong handle, jintArray pitchParam, jint lod) + { + try { + int pitch[OpenVDS::Dimensionality_Max]; + OpenVDS::VolumeDataPage* page = GetVolumePage(handle); + + const double* readData = static_cast(page->GetBuffer(pitch)); + env->SetIntArrayRegion(pitchParam, 0, OpenVDS::Dimensionality_Max, pitch); + int nbElem = GetBufferAllocatedSize(page); + return NewJDoubleArray(env, readData, nbElem); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return NULL; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPage + * Method: cpSetDoubleBuffer + * Signature: (J[D)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPage_cpSetDoubleBuffer + (JNIEnv * env, jclass, jlong handle, jdoubleArray values) + { + try { + OpenVDS::VolumeDataPage * page = GetVolumePage(handle); + int pitch[OpenVDS::Dimensionality_Max]; + double* pageBuffer = reinterpret_cast(page->GetWritableBuffer(pitch)); + int valueSize = env->GetArrayLength(values); + jdouble *src = env->GetDoubleArrayElements(values, 0); + std::memcpy(pageBuffer, src, valueSize * sizeof (double)); + env->ReleaseDoubleArrayElements(values, src, 0); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } #ifdef __cplusplus } diff --git a/java/cpp/src/VolumeDataPageAccessor.cpp b/java/cpp/src/VolumeDataPageAccessor.cpp index f80dfd59f7c8896dfdc3a0c2fb1d424faf4120d6..bbff5bf6fe16ac399f081baac1e8db324397319c 100644 --- a/java/cpp/src/VolumeDataPageAccessor.cpp +++ b/java/cpp/src/VolumeDataPageAccessor.cpp @@ -16,17 +16,241 @@ */ #include +#include +#include #ifdef __cplusplus extern "C" { #endif -/* - * Class: org_opengroup_openvds_VolumeDataPageAccessor - * Method: cpGetLayout - * Signature: (J)J - */ -JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetLayout - (JNIEnv *, jclass, jlong); + + inline OpenVDS::VolumeDataPageAccessor* GetPageAccessor( jlong handle ) { + return (OpenVDS::VolumeDataPageAccessor*) CheckHandle( handle ); + } + + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetLayout + * Signature: (J)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetLayout + (JNIEnv * env, jclass, jlong handle) + { + try { + const OpenVDS::VolumeDataLayout* layout = GetPageAccessor( handle )->GetLayout(); + return (jlong) layout; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetLOD + * Signature: (J)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetLOD + (JNIEnv * env, jclass, jlong handle) + { + try { + return GetPageAccessor( handle )->GetLOD(); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetChannelIndex + * Signature: (J)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetChannelIndex + (JNIEnv * env, jclass, jlong handle) + { + try { + return GetPageAccessor( handle )->GetChannelIndex(); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetNumSamples + * Signature: (J)[I + */ + JNIEXPORT jintArray JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetNumSamples + (JNIEnv * env, jclass, jlong handle) + { + try { + int dims[OpenVDS::Dimensionality_Max]; + GetPageAccessor( handle )->GetNumSamples(dims); + return NewJIntArray(env, dims, OpenVDS::Dimensionality_Max); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return NULL; + } + + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetChunkCount + * Signature: (J)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetChunkCount + (JNIEnv * env, jclass, jlong handle) + { + try { + return GetPageAccessor( handle )->GetChunkCount(); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpCreatePage + * Signature: (JJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpCreatePage + (JNIEnv * env, jclass, jlong handle, jlong pageIndex) + { + try { + OpenVDS::VolumeDataPage* volumePage = GetPageAccessor( handle )->CreatePage(pageIndex); + return (jlong) volumePage; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpReadPage + * Signature: (JJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpReadPage + (JNIEnv * env, jclass, jlong handle, jlong pageIndex) + { + try { + OpenVDS::VolumeDataPage* volumePage = GetPageAccessor( handle )->ReadPage(pageIndex); + return (jlong) volumePage; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetChunkMinMax + * Signature: (JI[I[I)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetChunkMinMax + (JNIEnv * env, jclass, jlong handle, jint chunk, jintArray chunkMin, jintArray chunkMax) + { + try { + int cMin[OpenVDS::Dimensionality_Max]; + int cMax[OpenVDS::Dimensionality_Max]; + GetPageAccessor( handle )->GetChunkMinMax(chunk, cMin, cMax); + env->SetIntArrayRegion(chunkMin, 0, OpenVDS::Dimensionality_Max, cMin); + env->SetIntArrayRegion(chunkMax, 0, OpenVDS::Dimensionality_Max, cMax); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetChunkMinMaxExcludingMargin + * Signature: (JI[I[I)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetChunkMinMaxExcludingMargin + (JNIEnv * env, jclass, jlong handle, jint chunk, jintArray chunkMin, jintArray chunkMax) + { + try { + int cMin[OpenVDS::Dimensionality_Max]; + int cMax[OpenVDS::Dimensionality_Max]; + GetPageAccessor( handle )->GetChunkMinMaxExcludingMargin(chunk, cMin, cMax); + env->SetIntArrayRegion(chunkMin, 0, OpenVDS::Dimensionality_Max, cMin); + env->SetIntArrayRegion(chunkMax, 0, OpenVDS::Dimensionality_Max, cMax); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetChunkIndex + * Signature: (J[I)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray positionArr) + { + try { + jint * position = env->GetIntArrayElements(positionArr, 0); + int positionParam[OpenVDS::Dimensionality_Max]; + for (int i = 0 ; i < OpenVDS::Dimensionality_Max ; ++i) positionParam[i] = position[i]; + env->ReleaseIntArrayElements(positionArr, position, 0); + return GetPageAccessor( handle )->GetChunkIndex(positionParam); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetMappedChunkIndex + * Signature: (JJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetMappedChunkIndex + (JNIEnv * env, jclass, jlong handle, jlong primaryChannelChunkIndex) + { + try { + return GetPageAccessor( handle )->GetMappedChunkIndex(primaryChannelChunkIndex); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpGetPrimaryChannelChunkIndex + * Signature: (JJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpGetPrimaryChannelChunkIndex + (JNIEnv * env, jclass, jlong handle, jlong chunkIndex) + { + try { + return GetPageAccessor( handle )->GetPrimaryChannelChunkIndex(chunkIndex); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpCommit + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpCommit + (JNIEnv * env, jclass, jlong handle) + { + try { + GetPageAccessor( handle )->Commit(); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeDataPageAccessor + * Method: cpSetMaxPage + * Signature: (JI)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeDataPageAccessor_cpSetMaxPage + (JNIEnv * env, jclass, jlong handle, jint maxPages) + { + try { + GetPageAccessor( handle )->SetMaxPages(maxPages); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } #ifdef __cplusplus } diff --git a/java/cpp/src/VolumeIndexer2D.cpp b/java/cpp/src/VolumeIndexer2D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..507af7c1eab62e38eb10cc6ddaa2395c0b9de280 --- /dev/null +++ b/java/cpp/src/VolumeIndexer2D.cpp @@ -0,0 +1,249 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + + inline VolumeIndexer2D * GetVolumeIndexer2D( jlong handle ) { + return (VolumeIndexer2D*)CheckHandle( handle ); + } + + inline OpenVDS::VolumeDataLayout *GetLayout(jlong handle) { + return (OpenVDS::VolumeDataLayout *) CheckHandle(handle); + } + + inline OpenVDS::VolumeDataPage *GetVolumePage(jlong handle) { + return (OpenVDS::VolumeDataPage *) CheckHandle(handle); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpCreateVolumeIndexer2D + * Signature: (JIIIJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpCreateVolumeIndexer2D + (JNIEnv * env, jclass, jlong vlPageHandle, jint channelIndex, jint lod, jint dimND, jlong layoutHandle) + { + try { + VolumeDataPage* volumeDataPage = GetVolumePage(vlPageHandle); + VolumeDataLayout* layout = GetLayout(layoutHandle); + VolumeIndexer2D* indexer2D = new VolumeIndexer2D(volumeDataPage, channelIndex, lod, (DimensionsND)dimND, layout); + return (jlong)indexer2D; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; + } + + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalIndexToVoxelIndex + * Signature: (JI[III)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j) + { + try { + IntVector2 res2 = GetVolumeIndexer2D(handle)->LocalIndexToVoxelIndex(IntVector2(i, j)); + env->SetIntArrayRegion(resOutIndex, 0, 2, res2.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalIndexToLocalChunkIndex + * Signature: (J[III)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j) + { + try { + IntVector2 res2 = GetVolumeIndexer2D(handle)->LocalIndexToLocalChunkIndex(IntVector2(i, j)); + env->SetIntArrayRegion(resOutIndex, 0, 2, res2.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpVoxelIndexToLocalIndex + * Signature: (J[III)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpVoxelIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j) + { + try { + IntVector2 res2 = GetVolumeIndexer2D(handle)->VoxelIndexToLocalIndex(IntVector2(i, j)); + env->SetIntArrayRegion(resOutIndex, 0, 2, res2.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpVoxelIndexToLocalChunkIndex + * Signature: (J[III)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpVoxelIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j) + { + try { + IntVector2 res2 = GetVolumeIndexer2D(handle)->VoxelIndexToLocalChunkIndex(IntVector2(i, j)); + env->SetIntArrayRegion(resOutIndex, 0, 2, res2.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalChunkIndexToLocalIndex + * Signature: (J[III)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalChunkIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j) + { + try { + IntVector2 res2 = GetVolumeIndexer2D(handle)->LocalChunkIndexToLocalIndex(IntVector2(i, j)); + env->SetIntArrayRegion(resOutIndex, 0, 2, res2.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalChunkIndexToVoxelIndex + * Signature: (J[III)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalChunkIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j) + { + try { + IntVector2 res2 = GetVolumeIndexer2D(handle)->LocalChunkIndexToVoxelIndex(IntVector2(i, j)); + env->SetIntArrayRegion(resOutIndex, 0, 2, res2.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalIndexToDataIndex + * Signature: (JII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j) + { + try { + return GetVolumeIndexer2D(handle)->LocalIndexToDataIndex(IntVector2(i, j)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpVoxelIndexToDataIndex + * Signature: (JII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpVoxelIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j) + { + try { + return GetVolumeIndexer2D(handle)->VoxelIndexToDataIndex(IntVector2(i, j)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalChunkIndexToDataIndex + * Signature: (JII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalChunkIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j) + { + try { + return GetVolumeIndexer2D(handle)->LocalChunkIndexToDataIndex(IntVector2(i, j)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpVoxelIndexInProcessArea + * Signature: (JII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpVoxelIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j) + { + try { + return GetVolumeIndexer2D(handle)->VoxelIndexInProcessArea(IntVector2(i, j)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalIndexInProcessArea + * Signature: (JII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j) + { + try { + return GetVolumeIndexer2D(handle)->LocalIndexInProcessArea(IntVector2(i, j)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer2D + * Method: cpLocalChunkIndexInProcessArea + * Signature: (JII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer2D_cpLocalChunkIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j) + { + try { + return GetVolumeIndexer2D(handle)->LocalChunkIndexInProcessArea(IntVector2(i, j)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + +#ifdef __cplusplus +} +#endif + + + diff --git a/java/cpp/src/VolumeIndexer3D.cpp b/java/cpp/src/VolumeIndexer3D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9e74a9b11ad7e8313695b5ec34a6874db61329f --- /dev/null +++ b/java/cpp/src/VolumeIndexer3D.cpp @@ -0,0 +1,247 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + + inline VolumeIndexer3D * GetVolumeIndexer3D( jlong handle ) { + return (VolumeIndexer3D*)CheckHandle( handle ); + } + + inline OpenVDS::VolumeDataLayout *GetLayout(jlong handle) { + return (OpenVDS::VolumeDataLayout *) CheckHandle(handle); + } + + inline OpenVDS::VolumeDataPage *GetVolumePage(jlong handle) { + return (OpenVDS::VolumeDataPage *) CheckHandle(handle); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpCreateVolumeIndexer3D + * Signature: (Lorg/opengroup/openvds/VolumeDataPage;IILorg/opengroup/openvds/DimensionsND;Lorg/opengroup/openvds/VolumeDataLayout;)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpCreateVolumeIndexer3D + (JNIEnv * env, jclass, jlong vlPageHandle, jint channelIndex, jint lod, jint dimND, jlong layoutHandle) + { + try { + VolumeDataPage* volumeDataPage = GetVolumePage(vlPageHandle); + VolumeDataLayout* layout = GetLayout(layoutHandle); + VolumeIndexer3D* indexer3D = new VolumeIndexer3D(volumeDataPage, channelIndex, lod, (DimensionsND)dimND, layout); + return (jlong)indexer3D; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalIndexToVoxelIndex + * Signature: (JI[IIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j , jint k) + { + try { + IntVector3 res3 = GetVolumeIndexer3D(handle)->LocalIndexToVoxelIndex(IntVector3(i, j, k)); + env->SetIntArrayRegion(resOutIndex, 0, 3, res3.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalIndexToLocalChunkIndex + * Signature: (J[IIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k) + { + try { + IntVector3 res3 = GetVolumeIndexer3D(handle)->LocalIndexToLocalChunkIndex(IntVector3(i, j, k)); + env->SetIntArrayRegion(resOutIndex, 0, 3, res3.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpVoxelIndexToLocalIndex + * Signature: (J[IIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpVoxelIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k) + { + try { + IntVector3 res3 = GetVolumeIndexer3D(handle)->VoxelIndexToLocalIndex(IntVector3(i, j, k)); + env->SetIntArrayRegion(resOutIndex, 0, 3, res3.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpVoxelIndexToLocalChunkIndex + * Signature: (J[IIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpVoxelIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k) + { + try { + IntVector3 res3 = GetVolumeIndexer3D(handle)->VoxelIndexToLocalChunkIndex(IntVector3(i, j, k)); + env->SetIntArrayRegion(resOutIndex, 0, 3, res3.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalChunkIndexToLocalIndex + * Signature: (J[IIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalChunkIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k) + { + try { + IntVector3 res3 = GetVolumeIndexer3D(handle)->LocalChunkIndexToLocalIndex(IntVector3(i, j, k)); + env->SetIntArrayRegion(resOutIndex, 0, 3, res3.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalChunkIndexToVoxelIndex + * Signature: (J[IIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalChunkIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k) + { + try { + IntVector3 res3 = GetVolumeIndexer3D(handle)->LocalChunkIndexToVoxelIndex(IntVector3(i, j, k)); + env->SetIntArrayRegion(resOutIndex, 0, 3, res3.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalIndexToDataIndex + * Signature: (JIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k) + { + try { + return GetVolumeIndexer3D(handle)->LocalIndexToDataIndex(IntVector3(i, j, k)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpVoxelIndexToDataIndex + * Signature: (JIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpVoxelIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k) + { + try { + return GetVolumeIndexer3D(handle)->VoxelIndexToDataIndex(IntVector3(i, j, k)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalChunkIndexToDataIndex + * Signature: (JIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalChunkIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k) + { + try { + return GetVolumeIndexer3D(handle)->LocalChunkIndexToDataIndex(IntVector3(i, j, k)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpVoxelIndexInProcessArea + * Signature: (JIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpVoxelIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k) + { + try { + return GetVolumeIndexer3D(handle)->VoxelIndexInProcessArea(IntVector3(i, j, k)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalIndexInProcessArea + * Signature: (JIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k) + { + try { + return GetVolumeIndexer3D(handle)->LocalIndexInProcessArea(IntVector3(i, j, k)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer3D + * Method: cpLocalChunkIndexInProcessArea + * Signature: (JIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer3D_cpLocalChunkIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k) + { + try { + return GetVolumeIndexer3D(handle)->LocalChunkIndexInProcessArea(IntVector3(i, j, k)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + +#ifdef __cplusplus +} +#endif + + + diff --git a/java/cpp/src/VolumeIndexer4D.cpp b/java/cpp/src/VolumeIndexer4D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..912aded974103916823653ffef8f515c49abc2b0 --- /dev/null +++ b/java/cpp/src/VolumeIndexer4D.cpp @@ -0,0 +1,245 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + + inline VolumeIndexer4D * GetVolumeIndexer4D( jlong handle ) { + return (VolumeIndexer4D*)CheckHandle( handle ); + } + + inline OpenVDS::VolumeDataLayout *GetLayout(jlong handle) { + return (OpenVDS::VolumeDataLayout *) CheckHandle(handle); + } + + inline OpenVDS::VolumeDataPage *GetVolumePage(jlong handle) { + return (OpenVDS::VolumeDataPage *) CheckHandle(handle); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpCreateVolumeIndexer4D + * Signature: (JIIIJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpCreateVolumeIndexer4D + (JNIEnv * env, jclass, jlong vlPageHandle, jint channelIndex, jint lod, jint dimND, jlong layoutHandle) + { + try { + VolumeDataPage* volumeDataPage = GetVolumePage(vlPageHandle); + VolumeDataLayout* layout = GetLayout(layoutHandle); + VolumeIndexer4D* indexer4D = new VolumeIndexer4D(volumeDataPage, channelIndex, lod, (DimensionsND)dimND, layout); + return (jlong)indexer4D; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalIndexToVoxelIndex + * Signature: (J[IIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l) + { + try { + IntVector4 res4 = GetVolumeIndexer4D(handle)->LocalIndexToVoxelIndex(IntVector4(i, j, k, l)); + env->SetIntArrayRegion(resOutIndex, 0, 4, res4.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalIndexToLocalChunkIndex + * Signature: (J[IIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l) + { + try { + IntVector4 res4 = GetVolumeIndexer4D(handle)->LocalIndexToLocalChunkIndex(IntVector4(i, j, k, l)); + env->SetIntArrayRegion(resOutIndex, 0, 4, res4.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpVoxelIndexToLocalIndex + * Signature: (J[IIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpVoxelIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l) + { + try { + IntVector4 res4 = GetVolumeIndexer4D(handle)->VoxelIndexToLocalIndex(IntVector4(i, j, k, l)); + env->SetIntArrayRegion(resOutIndex, 0, 4, res4.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpVoxelIndexToLocalChunkIndex + * Signature: (J[IIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpVoxelIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l) + { + try { + IntVector4 res4 = GetVolumeIndexer4D(handle)->VoxelIndexToLocalChunkIndex(IntVector4(i, j, k, l)); + env->SetIntArrayRegion(resOutIndex, 0, 4, res4.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalChunkIndexToLocalIndex + * Signature: (J[IIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalChunkIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l) + { + try { + IntVector4 res4 = GetVolumeIndexer4D(handle)->LocalChunkIndexToLocalIndex(IntVector4(i, j, k, l)); + env->SetIntArrayRegion(resOutIndex, 0, 4, res4.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalChunkIndexToVoxelIndex + * Signature: (J[IIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalChunkIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l) + { + try { + IntVector4 res4 = GetVolumeIndexer4D(handle)->LocalChunkIndexToVoxelIndex(IntVector4(i, j, k, l)); + env->SetIntArrayRegion(resOutIndex, 0, 4, res4.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalIndexToDataIndex + * Signature: (JIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l) + { + try { + return GetVolumeIndexer4D(handle)->LocalIndexToDataIndex(IntVector4(i, j, k, l)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpVoxelIndexToDataIndex + * Signature: (JIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpVoxelIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l) + { + try { + return GetVolumeIndexer4D(handle)->VoxelIndexToDataIndex(IntVector4(i, j, k, l)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalChunkIndexToDataIndex + * Signature: (JIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalChunkIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l) + { + try { + return GetVolumeIndexer4D(handle)->LocalChunkIndexToDataIndex(IntVector4(i, j, k, l)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpVoxelIndexInProcessArea + * Signature: (JIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpVoxelIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l) + { + try { + return GetVolumeIndexer4D(handle)->VoxelIndexInProcessArea(IntVector4(i, j, k, l)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalIndexInProcessArea + * Signature: (JIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l) + { + try { + return GetVolumeIndexer4D(handle)->LocalIndexInProcessArea(IntVector4(i, j, k, l)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer4D + * Method: cpLocalChunkIndexInProcessArea + * Signature: (JIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer4D_cpLocalChunkIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l) + { + try { + return GetVolumeIndexer4D(handle)->LocalChunkIndexInProcessArea(IntVector4(i, j, k, l)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + +#ifdef __cplusplus +} +#endif + + + diff --git a/java/cpp/src/VolumeIndexer5D.cpp b/java/cpp/src/VolumeIndexer5D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9dcbd76257ed72931f05ad1ac0700036841a9d14 --- /dev/null +++ b/java/cpp/src/VolumeIndexer5D.cpp @@ -0,0 +1,245 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + + inline VolumeIndexer5D * GetVolumeIndexer5D( jlong handle ) { + return (VolumeIndexer5D*)CheckHandle( handle ); + } + + inline OpenVDS::VolumeDataLayout *GetLayout(jlong handle) { + return (OpenVDS::VolumeDataLayout *) CheckHandle(handle); + } + + inline OpenVDS::VolumeDataPage *GetVolumePage(jlong handle) { + return (OpenVDS::VolumeDataPage *) CheckHandle(handle); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpCreateVolumeIndexer5D + * Signature: (JIIIJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpCreateVolumeIndexer5D + (JNIEnv * env, jclass, jlong vlPageHandle, jint channelIndex, jint lod, jint dimND, jlong layoutHandle) + { + try { + VolumeDataPage* volumeDataPage = GetVolumePage(vlPageHandle); + VolumeDataLayout* layout = GetLayout(layoutHandle); + VolumeIndexer5D* indexer5D = new VolumeIndexer5D(volumeDataPage, channelIndex, lod, (DimensionsND)dimND, layout); + return (jlong)indexer5D; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalIndexToVoxelIndex + * Signature: (J[IIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m) + { + try { + IntVector<5> res5 = GetVolumeIndexer5D(handle)->LocalIndexToVoxelIndex(IntVector<5>(i, j, k, l, m)); + env->SetIntArrayRegion(resOutIndex, 0, 5, res5.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalIndexToLocalChunkIndex + * Signature: (J[IIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m) + { + try { + IntVector<5> res5 = GetVolumeIndexer5D(handle)->LocalIndexToLocalChunkIndex(IntVector<5>(i, j, k, l, m)); + env->SetIntArrayRegion(resOutIndex, 0, 5, res5.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpVoxelIndexToLocalIndex + * Signature: (J[IIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpVoxelIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m) + { + try { + IntVector<5> res5 = GetVolumeIndexer5D(handle)->LocalIndexToLocalChunkIndex(IntVector<5>(i, j, k, l, m)); + env->SetIntArrayRegion(resOutIndex, 0, 5, res5.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpVoxelIndexToLocalChunkIndex + * Signature: (J[IIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpVoxelIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m) + { + try { + IntVector<5> res5 = GetVolumeIndexer5D(handle)->VoxelIndexToLocalChunkIndex(IntVector<5>(i, j, k, l, m)); + env->SetIntArrayRegion(resOutIndex, 0, 5, res5.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalChunkIndexToLocalIndex + * Signature: (J[IIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalChunkIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m) + { + try { + IntVector<5> res5 = GetVolumeIndexer5D(handle)->LocalChunkIndexToLocalIndex(IntVector<5>(i, j, k, l, m)); + env->SetIntArrayRegion(resOutIndex, 0, 5, res5.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalChunkIndexToVoxelIndex + * Signature: (J[IIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalChunkIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m) + { + try { + IntVector<5> res5 = GetVolumeIndexer5D(handle)->LocalChunkIndexToVoxelIndex(IntVector<5>(i, j, k, l, m)); + env->SetIntArrayRegion(resOutIndex, 0, 5, res5.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalIndexToDataIndex + * Signature: (JIIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m) + { + try { + return GetVolumeIndexer5D(handle)->LocalIndexToDataIndex(IntVector<5>(i, j, k, l, m)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpVoxelIndexToDataIndex + * Signature: (JIIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpVoxelIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m) + { + try { + return GetVolumeIndexer5D(handle)->VoxelIndexToDataIndex(IntVector<5>(i, j, k, l, m)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalChunkIndexToDataIndex + * Signature: (JIIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalChunkIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m) + { + try { + return GetVolumeIndexer5D(handle)->LocalChunkIndexToDataIndex(IntVector<5>(i, j, k, l, m)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpVoxelIndexInProcessArea + * Signature: (JIIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpVoxelIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m) + { + try { + return GetVolumeIndexer5D(handle)->VoxelIndexInProcessArea(IntVector<5>(i, j, k, l, m)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalIndexInProcessArea + * Signature: (JIIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m) + { + try { + return GetVolumeIndexer5D(handle)->LocalIndexInProcessArea(IntVector<5>(i, j, k, l, m)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer5D + * Method: cpLocalChunkIndexInProcessArea + * Signature: (JIIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer5D_cpLocalChunkIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m) + { + try { + return GetVolumeIndexer5D(handle)->LocalChunkIndexInProcessArea(IntVector<5>(i, j, k, l, m)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + +#ifdef __cplusplus +} +#endif + + + diff --git a/java/cpp/src/VolumeIndexer6D.cpp b/java/cpp/src/VolumeIndexer6D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..765c1c984de4561b86d201b37341b546544af04e --- /dev/null +++ b/java/cpp/src/VolumeIndexer6D.cpp @@ -0,0 +1,245 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + + inline VolumeIndexer6D * GetVolumeIndexer6D( jlong handle ) { + return (VolumeIndexer6D*)CheckHandle( handle ); + } + + inline OpenVDS::VolumeDataLayout *GetLayout(jlong handle) { + return (OpenVDS::VolumeDataLayout *) CheckHandle(handle); + } + + inline OpenVDS::VolumeDataPage *GetVolumePage(jlong handle) { + return (OpenVDS::VolumeDataPage *) CheckHandle(handle); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpCreateVolumeIndexer6D + * Signature: (JIIIJ)J + */ + JNIEXPORT jlong JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpCreateVolumeIndexer6D + (JNIEnv * env, jclass, jlong vlPageHandle, jint channelIndex, jint lod, jint dimND, jlong layoutHandle) + { + try { + VolumeDataPage* volumeDataPage = GetVolumePage(vlPageHandle); + VolumeDataLayout* layout = GetLayout(layoutHandle); + VolumeIndexer6D* indexer6D = new VolumeIndexer6D(volumeDataPage, channelIndex, lod, (DimensionsND)dimND, layout); + return (jlong)indexer6D; + } + CATCH_EXCEPTIONS_FOR_JAVA; + return 0; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalIndexToVoxelIndex + * Signature: (J[IIIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + IntVector<6> res6 = GetVolumeIndexer6D(handle)->LocalIndexToVoxelIndex(IntVector<6>(i, j, k, l, m, n)); + env->SetIntArrayRegion(resOutIndex, 0, 6, res6.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalIndexToLocalChunkIndex + * Signature: (J[IIIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + IntVector<6> res6 = GetVolumeIndexer6D(handle)->LocalIndexToLocalChunkIndex(IntVector<6>(i, j, k, l, m, n)); + env->SetIntArrayRegion(resOutIndex, 0, 6, res6.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpVoxelIndexToLocalIndex + * Signature: (J[IIIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpVoxelIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + IntVector<6> res6 = GetVolumeIndexer6D(handle)->VoxelIndexToLocalIndex(IntVector<6>(i, j, k, l, m, n)); + env->SetIntArrayRegion(resOutIndex, 0, 6, res6.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpVoxelIndexToLocalChunkIndex + * Signature: (J[IIIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpVoxelIndexToLocalChunkIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + IntVector<6> res6 = GetVolumeIndexer6D(handle)->VoxelIndexToLocalChunkIndex(IntVector<6>(i, j, k, l, m, n)); + env->SetIntArrayRegion(resOutIndex, 0, 6, res6.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalChunkIndexToLocalIndex + * Signature: (J[IIIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalChunkIndexToLocalIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + IntVector<6> res6 = GetVolumeIndexer6D(handle)->LocalChunkIndexToLocalIndex(IntVector<6>(i, j, k, l, m, n)); + env->SetIntArrayRegion(resOutIndex, 0, 6, res6.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalChunkIndexToVoxelIndex + * Signature: (J[IIIIIII)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalChunkIndexToVoxelIndex + (JNIEnv * env, jclass, jlong handle, jintArray resOutIndex, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + IntVector<6> res6 = GetVolumeIndexer6D(handle)->LocalChunkIndexToVoxelIndex(IntVector<6>(i, j, k, l, m, n)); + env->SetIntArrayRegion(resOutIndex, 0, 6, res6.data); + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalIndexToDataIndex + * Signature: (JIIIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + return GetVolumeIndexer6D(handle)->LocalIndexToDataIndex(IntVector<6>(i, j, k, l, m, n)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpVoxelIndexToDataIndex + * Signature: (JIIIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpVoxelIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + return GetVolumeIndexer6D(handle)->VoxelIndexToDataIndex(IntVector<6>(i, j, k, l, m, n)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalChunkIndexToDataIndex + * Signature: (JIIIIII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalChunkIndexToDataIndex + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + return GetVolumeIndexer6D(handle)->LocalChunkIndexToDataIndex(IntVector<6>(i, j, k, l, m, n)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpVoxelIndexInProcessArea + * Signature: (JIIIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpVoxelIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + return GetVolumeIndexer6D(handle)->VoxelIndexInProcessArea(IntVector<6>(i, j, k, l, m, n)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalIndexInProcessArea + * Signature: (JIIIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + return GetVolumeIndexer6D(handle)->LocalIndexInProcessArea(IntVector<6>(i, j, k, l, m, n)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexer6D + * Method: cpLocalChunkIndexInProcessArea + * Signature: (JIIIIII)Z + */ + JNIEXPORT jboolean JNICALL Java_org_opengroup_openvds_VolumeIndexer6D_cpLocalChunkIndexInProcessArea + (JNIEnv * env, jclass, jlong handle, jint i, jint j, jint k, jint l, jint m, jint n) + { + try { + return GetVolumeIndexer6D(handle)->LocalChunkIndexInProcessArea(IntVector<6>(i, j, k, l, m, n)); + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + +#ifdef __cplusplus +} +#endif + + + diff --git a/java/cpp/src/VolumeIndexerBase.cpp b/java/cpp/src/VolumeIndexerBase.cpp new file mode 100644 index 0000000000000000000000000000000000000000..41d885e714986ca0ca7c63a4c603eea495dce420 --- /dev/null +++ b/java/cpp/src/VolumeIndexerBase.cpp @@ -0,0 +1,190 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +using namespace OpenVDS; + +#ifdef __cplusplus +extern "C" { +#endif + + inline VolumeIndexer2D * GetVolumeIndexer2D( jlong handle ) { + return (VolumeIndexer2D*)CheckHandle( handle ); + } + + inline VolumeIndexer3D * GetVolumeIndexer3D( jlong handle ) { + return (VolumeIndexer3D*)CheckHandle( handle ); + } + + inline VolumeIndexer4D * GetVolumeIndexer4D( jlong handle ) { + return (VolumeIndexer4D*)CheckHandle( handle ); + } + + inline VolumeIndexer5D * GetVolumeIndexer5D( jlong handle ) { + return (VolumeIndexer5D*)CheckHandle( handle ); + } + + inline VolumeIndexer6D * GetVolumeIndexer6D( jlong handle ) { + return (VolumeIndexer6D*)CheckHandle( handle ); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexerBase + * Method: cpDeleteHandle + * Signature: (J)V + */ + JNIEXPORT void JNICALL Java_org_opengroup_openvds_VolumeIndexerBase_cpDeleteHandle + (JNIEnv * env, jclass, jlong handle, jint volumeDimension) + { + try { + switch (volumeDimension) { + case 2: + delete GetVolumeIndexer2D(handle); + break; + case 3: + delete GetVolumeIndexer3D(handle); + break; + case 4: + delete GetVolumeIndexer4D(handle); + break; + case 5: + delete GetVolumeIndexer5D(handle); + break; + case 6: + delete GetVolumeIndexer6D(handle); + break; + } + } + CATCH_EXCEPTIONS_FOR_JAVA; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexerBase + * Method: cpGetValueRangeMin + * Signature: (JI)F + */ + JNIEXPORT jfloat JNICALL Java_org_opengroup_openvds_VolumeIndexerBase_cpGetValueRangeMin + (JNIEnv * env, jclass, jlong handle, jint volumeDimension) + { + try { + switch (volumeDimension) { + case 2: + return GetVolumeIndexer2D(handle)->valueRangeMin; + case 3: + return GetVolumeIndexer3D(handle)->valueRangeMin; + case 4: + return GetVolumeIndexer4D(handle)->valueRangeMin; + case 5: + return GetVolumeIndexer5D(handle)->valueRangeMin; + case 6: + return GetVolumeIndexer6D(handle)->valueRangeMin; + } + } + CATCH_EXCEPTIONS_FOR_JAVA; + return std::numeric_limits::min(); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexerBase + * Method: cpGetValueRangeMax + * Signature: (JI)F + */ + JNIEXPORT jfloat JNICALL Java_org_opengroup_openvds_VolumeIndexerBase_cpGetValueRangeMax + (JNIEnv * env, jclass, jlong handle, jint volumeDimension) + { + try { + switch (volumeDimension) { + case 2: + return GetVolumeIndexer2D(handle)->valueRangeMax; + case 3: + return GetVolumeIndexer3D(handle)->valueRangeMax; + case 4: + return GetVolumeIndexer4D(handle)->valueRangeMax; + case 5: + return GetVolumeIndexer5D(handle)->valueRangeMax; + case 6: + return GetVolumeIndexer6D(handle)->valueRangeMax; + } + } + CATCH_EXCEPTIONS_FOR_JAVA; + return std::numeric_limits::max(); + } + + /* + * Class: org_opengroup_openvds_VolumeIndexerBase + * Method: cpGetDataBlockNumSamples + * Signature: (JII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexerBase_cpGetDataBlockNumSamples + (JNIEnv * env, jclass, jlong handle, jint volumeDimension, jint dim) + { + try { + switch (volumeDimension) { + case 2: + return GetVolumeIndexer2D(handle)->GetDataBlockNumSamples(dim); + case 3: + return GetVolumeIndexer3D(handle)->GetDataBlockNumSamples(dim); + case 4: + return GetVolumeIndexer4D(handle)->GetDataBlockNumSamples(dim); + case 5: + return GetVolumeIndexer5D(handle)->GetDataBlockNumSamples(dim); + case 6: + return GetVolumeIndexer6D(handle)->GetDataBlockNumSamples(dim); + } + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + + /* + * Class: org_opengroup_openvds_VolumeIndexerBase + * Method: cpGetLocalChunkNumSamples + * Signature: (JII)I + */ + JNIEXPORT jint JNICALL Java_org_opengroup_openvds_VolumeIndexerBase_cpGetLocalChunkNumSamples + (JNIEnv * env, jclass, jlong handle, jint volumeDimension, jint dim) + { + try { + switch (volumeDimension) { + case 2: + return GetVolumeIndexer2D(handle)->GetLocalChunkNumSamples(dim); + case 3: + return GetVolumeIndexer3D(handle)->GetLocalChunkNumSamples(dim); + case 4: + return GetVolumeIndexer4D(handle)->GetLocalChunkNumSamples(dim); + case 5: + return GetVolumeIndexer5D(handle)->GetLocalChunkNumSamples(dim); + case 6: + return GetVolumeIndexer6D(handle)->GetLocalChunkNumSamples(dim); + } + } + CATCH_EXCEPTIONS_FOR_JAVA; + return -1; + } + +#ifdef __cplusplus +} +#endif + + + diff --git a/java/java/demo/CreateVDS.java b/java/java/demo/CreateVDS.java new file mode 100644 index 0000000000000000000000000000000000000000..0931bd120c66a3ed6eef538f08444cc78bffd153 --- /dev/null +++ b/java/java/demo/CreateVDS.java @@ -0,0 +1,500 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.opengroup.openvds.*; + +import java.io.File; +import java.io.IOException; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +public class CreateVDS { + + // usage : CreateVDSWithLOD n /path/to/file + // where n is the LOD level wanted + public static void main(String[] args) { + try { + if (!checkParams(args)) { + System.out.println("Bad params, usage : n /path/to/file dimX dimY dimZ"); + System.out.println("n is the LOD level wanted (0 <= lod <= 12), path must be a valid non existing file path"); + System.out.println("dims are cube dimension (must be > 0)"); + } + else { + Instant start = Instant.now(); + process(Integer.parseInt(args[0]), args[1], Integer.parseInt(args[2]), Integer.parseInt(args[3]), Integer.parseInt(args[4])); + Instant end = Instant.now(); + + Duration elapsed = Duration.between(start, end); + long hrs = elapsed.toHours(); + long min = elapsed.toMinutes() - (hrs * 60); + long s = (elapsed.toMillis() - (elapsed.toMinutes() * 60 * 1000)) / 1000; + System.out.println("Write VDS TIME : " + hrs + " hrs " + min + " min " + s + "s (" + elapsed.toMillis() + " ms)"); + } + } + catch (Throwable t) { + System.out.println(); + t.printStackTrace(); + } + } + + private static boolean checkParams(String[] args) { + if (args == null || args.length != 5) { + return false; + } + try { + Integer lod = Integer.parseInt(args[0]); + if (lod < 0 || lod > 12) { + System.err.println("Invalid LOD value (must be between 0 and 12) !"); + return false; + } + } + catch (NumberFormatException nfe) { + return false; + } + String path = args[1]; + File file = new File(path); + try { + file.getCanonicalPath(); + } + catch (IOException e) { + System.err.println("VDS File path is invalid !"); + return false; + } + if (!path.endsWith(".vds")) { + System.err.println("VDS File path must have vds extension !"); + return false; + } + if (file.exists()) { + System.err.println("VDS File already exists !"); + return false; + } + try { + Integer dimX = Integer.parseInt(args[2]); + if (dimX < 0) { + System.err.println("Invalid x dimension !"); + return false; + } + Integer dimY = Integer.parseInt(args[3]); + if (dimX < 0) { + System.err.println("Invalid y dimension !"); + return false; + } + Integer dimZ = Integer.parseInt(args[4]); + if (dimX < 0) { + System.err.println("Invalid Z dimension !"); + return false; + } + } + catch (NumberFormatException nfe) { + return false; + } + return true; + } + + static void process(int lodParam, String vdsFilePath, int dimX, int dimY, int dimZ) throws Exception { + + int samplesX = dimZ; // time + int samplesY = dimY; // XL + int samplesZ = dimX; // IL + VolumeDataChannelDescriptor.Format format = VolumeDataChannelDescriptor.Format.FORMAT_R32; + + double sizeX = samplesX; + double sizeY = samplesY; + double sizeZ = samplesZ; + + double distMax = distance3D(0, 0, 0, sizeX, sizeY, sizeZ); + double cycles = Math.PI * 2 * 20; + double midX = samplesX / 2f; + double midY = samplesY / 2f; + double midZ = samplesZ / 2f; + + VolumeDataLayoutDescriptor.BrickSize brickSize = VolumeDataLayoutDescriptor.BrickSize.BRICK_SIZE_64; + int negativeMargin = 4; + int positiveMargin = 4; + int brickSize2DMultiplier = 4; + + VolumeDataLayoutDescriptor.LODLevels lodLevels = VolumeDataLayoutDescriptor.LODLevels.values()[lodParam]; + + //VolumeDataLayoutDescriptor.Options layoutOptions = VolumeDataLayoutDescriptor.Options.NONE; + VolumeDataLayoutDescriptor layoutDescriptor = new VolumeDataLayoutDescriptor(brickSize, negativeMargin, positiveMargin, + brickSize2DMultiplier, lodLevels, false,false,0); + + List axisDescriptors = new ArrayList<>(); + axisDescriptors.add(new VolumeDataAxisDescriptor(samplesX, "Sample", "s", 0.0f,6.0f)); + axisDescriptors.add(new VolumeDataAxisDescriptor(samplesY, "Crossline", "",0f, 0f + samplesY - 1f)); + axisDescriptors.add(new VolumeDataAxisDescriptor(samplesZ, "Inline", "", 0f, 0f + samplesZ - 1f)); + + List channelDescriptors = new ArrayList<>(); + + float rangeMin = -1f; + float rangeMax = 1f; + float[] scaleOffset = getScaleOffsetForFormat(rangeMin, rangeMax, true, format); + + VolumeDataChannelDescriptor channelDescriptor = new VolumeDataChannelDescriptor(format, VolumeDataChannelDescriptor.Components.COMPONENTS_1, + "Amplitude", + "", + rangeMin, // range min + rangeMax, // range max + VolumeDataMapping.DIRECT, // mapping + 1, // mapped value count + false, // is discrete + true, // is renderable + false, // allow lossy compression + false, // use zip for lossless compresion + true, // use no value + -999.25f, // no value + scaleOffset[0], // integer scale + scaleOffset[1]); // integer offset + channelDescriptors.add(channelDescriptor); + + // file options + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsFilePath); + + MetadataContainer metadataContainer = new MetadataContainer(); + StringBuilder builder = new StringBuilder(); + builder.append("CreateVDS Demo "); + builder.append("dimX: "); + builder.append(dimX); + builder.append(" dimY: "); + builder.append(dimY); + builder.append(" dimZ: "); + builder.append(dimZ); + + metadataContainer.setMetadataString("General Info", "Cube layout", builder.toString()); + metadataContainer.setMetadataInt("General Info", "LOD", lodLevels.ordinal()); + metadataContainer.setMetadataString("General Info", "Brick Size", "BRICK_SIZE_64"); + + VdsHandle vds = OpenVDS.create(options, layoutDescriptor, + axisDescriptors.toArray(new VolumeDataAxisDescriptor[0]), + channelDescriptors.toArray(new VolumeDataChannelDescriptor[0]), metadataContainer); + + // for compression use +// float compressionTolerance = 0f; // +// VdsHandle vds = OpenVDS.create(options, layoutDescriptor, +// axisDescriptors.toArray(new VolumeDataAxisDescriptor[0]), +// channelDescriptors.toArray(new VolumeDataChannelDescriptor[0]), metadataContainer, CompressionMethod.ZIP, compressionTolerance); + + VolumeDataLayout layout = vds.getLayout(); + VolumeDataAccessManager accessManager = vds.getAccessManager(); + + int channel = 0; + + int lodCount = lodLevels.ordinal(); + + int[] localIndex = new int[3]; + int[] voxelPos = new int[3]; + + int[] pitch = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMin = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMax = new int[VolumeDataLayout.Dimensionality_Max]; + + for (int lod = 0 ; lod <= lodCount ; ++lod) { + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + lod, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + + //ASSERT_TRUE(pageAccessor); + int paLOD = pageAccessor.getLOD(); + int paCI = pageAccessor.getChannelIndex(); + int[] paNumSamples = pageAccessor.getNumSamples(); + + int chunkCount = (int) pageAccessor.getChunkCount(); + System.out.println("LOD : " + lod + " Chunk count : " + chunkCount); + + for (int i = 0; i < chunkCount; i++) { + + long time_1 = System.currentTimeMillis(); + + VolumeDataPage page = pageAccessor.createPage(i); + System.out.print("LOD : " + lod + " / Page " + (i + 1) + " / " + chunkCount); + + VolumeIndexer3D outputIndexer = new VolumeIndexer3D(page, 0, lod, DimensionsND.DIMENSIONS_012.ordinal(), layout); + + int[] numSamplesChunk = new int[3]; + int[] numSamplesDB = new int[3]; + + for (int j = 0; j < 3; j++) { + numSamplesChunk[j] = outputIndexer.getLocalChunkNumSamples(j); + numSamplesDB[j] = outputIndexer.getDataBlockNumSamples(j); + } + System.out.print("\tDimensions Chunk : [" + numSamplesChunk[0] + ", " + numSamplesChunk[1] + ", " + numSamplesChunk[2] + "]"); + System.out.print("\tDimensions DataBlock : [" + numSamplesDB[0] + ", " + numSamplesDB[1] + ", " + numSamplesDB[2] + "]"); + + page.getMinMax(chunkMin, chunkMax); + + System.out.print("\tCoords page : " + chunkMin[0] + "/" + chunkMax[0] + " " + chunkMin[1] + "/" + chunkMax[1] + " " + chunkMin[2] + "/" + chunkMax[2]); + int chunkSizeY = chunkMax[2] - chunkMin[2]; + int chunkSizeX = chunkMax[1] - chunkMin[1]; + int chunkSizeZ = chunkMax[0] - chunkMin[0]; + + // get pitch and allocate buffer size + page.getPitch(pitch); + float[] output = new float[page.getAllocatedBufferSize()]; + + // or read buffer of page + //float[] output = page.readFloatBuffer(pitch); + + System.out.print( " Page Buffer Size : " + output.length + " ");/// [" + stats.getMin() + "," + stats.getMax() + "]"); + // dimension of buffer + System.out.println(" Pitch : [" + pitch[0] + ", " + pitch[1] + ", " + pitch[2] + "]"); + + int[] numSamples = numSamplesChunk; + + for (int iDim2 = 0; iDim2 < numSamples[2]; iDim2++) { + localIndex[2] = iDim2; + for (int iDim1 = 0; iDim1 < numSamples[1]; iDim1++) { + localIndex[1] = iDim1; + for (int iDim0 = 0; iDim0 < numSamples[0]; iDim0++) { + localIndex[0] = iDim0; + + int[] voxelIndex = outputIndexer.localIndexToVoxelIndex(localIndex); + for (int vp = 0; vp < 3; ++vp) { + voxelPos[vp] = voxelIndex[vp]; + } + + float value = 0f; + double dist = 0; + if (voxelPos[0] >= midX) { + dist = distance2D(midY, midZ, voxelPos[1], voxelPos[2]); + } else { + dist = distance3D(midX, midY, midZ, voxelPos[0], voxelPos[1], voxelPos[2]); + } + value = (float) Math.sin((dist * cycles) / distMax); + + int iPos = outputIndexer.localIndexToDataIndex(localIndex); + output[iPos] = value; + } + } + } + + // write buffer then release page + page.writeFloatBuffer(output, pitch); + page.pageRelease(); + } + + pageAccessor.commit(); + pageAccessor.setMaxPages(0); + accessManager.flushUploadQueue(); + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + } + + // Adds slice data : additional layouts +// System.out.println("\nCreate 01 Layout"); +// create2DLayout(distMax, cycles, midX, midY, midZ, layout, accessManager, channel, lodCount, DimensionsND.DIMENSIONS_01); +// +// System.out.println("\nCreate 02 Layout"); +// create2DLayout(distMax, cycles, midX, midY, midZ, layout, accessManager, channel, lodCount, DimensionsND.DIMENSIONS_02); +// +// System.out.println("\nCreate 12 Layout"); +// create2DLayout(distMax, cycles, midX, midY, midZ, layout, accessManager, channel, lodCount, DimensionsND.DIMENSIONS_12); + + + vds.close(); + System.out.println("VDS closed"); + } + + + private static void create2DLayout(double distMax, double cycles, double midX, double midY, double midZ, VolumeDataLayout layout, VolumeDataAccessManager accessManager, + int channel, int lodCount, DimensionsND dimLYT) { + + int[] localIndex = new int[3]; + + int[] pitch = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMin = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMax = new int[VolumeDataLayout.Dimensionality_Max]; + for (int lod = 0 ; lod <= lodCount ; ++lod) { + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + dimLYT.ordinal(), // dimension ND + lod, // lod + channel, // channel + 200, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + int chunkCount = (int) pageAccessor.getChunkCount(); + System.out.println("2D Layout LOD : " + lod + " Chunk count : " + chunkCount); + + for (int i = 0; i < chunkCount; i++) { + VolumeDataPage page = pageAccessor.createPage(i); + System.out.print("2D Layout LOD : " + lod + " / Page " + (i + 1) + " / " + chunkCount); + + VolumeIndexer2D outputIndexer = new VolumeIndexer2D(page, 0, lod, dimLYT.ordinal(), layout); + float valueRangeScale = outputIndexer.getValueRangeMax() - outputIndexer.getValueRangeMin(); + + int[] numSamplesChunk = new int[3]; + int[] numSamplesDB = new int[3]; + + for (int j = 0; j < 3 ; j++) { + numSamplesChunk[j] = outputIndexer.getLocalChunkNumSamples(j); + numSamplesDB[j] = outputIndexer.getDataBlockNumSamples(j); + } + System.out.print("\t2D Layout Dimensions Chunk : [" + numSamplesChunk[0] + ", " + numSamplesChunk[1] + ", " + numSamplesChunk[2] + "]"); + System.out.print("\t2D Layout Dimensions DataBlock : [" + numSamplesDB[0] + ", " + numSamplesDB[1] + ", " + numSamplesDB[2] + "]"); + + page.getMinMax(chunkMin, chunkMax); + + // determine fixed position index and value + int fixedCoordIndex = -1; + int fixedCoordValue = -1; + for (int pos = 0; pos < 3 && fixedCoordIndex == -1 ; ++pos) { + if (Math.abs(chunkMax[pos] - chunkMin[pos]) == 1) { + fixedCoordIndex = pos; + fixedCoordValue = chunkMin[pos]; + } + } + + System.out.print("\tCoords page : " + chunkMin[0] + "/" + chunkMax[0] + " " + chunkMin[1] + "/" + chunkMax[1] + "/" + chunkMin[2] + "/" + chunkMax[2]); + int chunkSizeY = chunkMax[2] - chunkMin[2]; + int chunkSizeX = chunkMax[1] - chunkMin[1]; + int chunkSizeZ = chunkMax[0] - chunkMin[0]; + + // get pitch and allocate buffer size + page.getPitch(pitch); + float[] output = new float[page.getAllocatedBufferSize()]; + + System.out.print( " Page Buffer Size : " + output.length);// + " / [" + stats.getMin() + "," + stats.getMax() + "]"); + // dimension of buffer + System.out.println(" Pitch : [" + pitch[0] + ", " + pitch[1] + "," + pitch[2] + "]"); + + long time_2 = System.currentTimeMillis(); + + int[] numSamples = numSamplesChunk; + + for (int iDim2 = 0; iDim2 < numSamples[2]; iDim2++) { + localIndex[2] = iDim2; + for (int iDim1 = 0; iDim1 < numSamples[1]; iDim1++) { + localIndex[1] = iDim1; + for (int iDim0 = 0; iDim0 < numSamples[0]; iDim0++) { + localIndex[0] = iDim0; + int[] local2DIndex = convertTo2DLocalIndex(localIndex, fixedCoordIndex); + int[] voxelIndex = outputIndexer.localChunkIndexToLocalIndex(local2DIndex); + int[] voxelPos = convertTo3DCoord(voxelIndex, fixedCoordIndex, fixedCoordValue); + + float value = 0f; + double dist = 0; + if (voxelPos[0] >= midX) { + dist = distance2D(midY, midZ, voxelPos[1], voxelPos[2]); + } else { + dist = distance3D(midX, midY, midZ, voxelPos[0], voxelPos[1], voxelPos[2]); + } + value = (float) Math.sin((dist * cycles) / distMax); + + int iPos = outputIndexer.localIndexToDataIndex(local2DIndex); + output[iPos] = value; + } + } + } + + // write buffer then release page + page.writeFloatBuffer(output, pitch); + page.pageRelease(); + } + + pageAccessor.commit(); + accessManager.flushUploadQueue(); + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + } + } + + + /** + * Convert 3D index to 2D index + */ + private static int[] convertTo2DLocalIndex(int[] localIndex, int fixedCoordIndex) { + int[] local2DIndex = new int[2]; + if (fixedCoordIndex == 0) { + local2DIndex[0] = localIndex[1]; + local2DIndex[1] = localIndex[2]; + } + else if (fixedCoordIndex == 1) { + local2DIndex[0] = localIndex[0]; + local2DIndex[1] = localIndex[2]; + } + else if (fixedCoordIndex == 2) { + local2DIndex[0] = localIndex[0]; + local2DIndex[1] = localIndex[1]; + } + return local2DIndex; + } + + /** + * Convert 2D index to 3D index + * @param voxelIndex + * @param fixedCoordIndex + * @param fixedCoordValue + */ + private static int[] convertTo3DCoord(int[] voxelIndex, int fixedCoordIndex, int fixedCoordValue) { + int[] voxelPos = new int[3]; + voxelPos[fixedCoordIndex] = fixedCoordValue; + if (fixedCoordIndex == 0) { + voxelPos[1] = voxelIndex[0]; + voxelPos[2] = voxelIndex[1]; + } + else if (fixedCoordIndex == 1) { + voxelPos[0] = voxelIndex[0]; + voxelPos[2] = voxelIndex[1]; + } + else if (fixedCoordIndex == 2) { + voxelPos[0] = voxelIndex[0]; + voxelPos[1] = voxelIndex[1]; + } + return voxelPos; + } + + private static double distance2D(double x1, double y1, double x2, double y2) { + double diffX = x2 - x1; + double diffY = y2 - y1; + return Math.sqrt((diffX * diffX) + (diffY * diffY)); + } + + private static double distance3D(double x1, double y1, double z1, double x2, double y2, double z2) { + double diffX = x2 - x1; + double diffY = y2 - y1; + double diffZ = z2 - z1; + return Math.sqrt((diffX * diffX) + (diffY * diffY) + (diffZ * diffZ)); + } + + static float[] getScaleOffsetForFormat(float min, float max, boolean useNoValue, VolumeDataChannelDescriptor.Format format) { + float res[] = new float[] {1f, 0f}; + float noValueCmp = useNoValue ? 1f : 0f; + switch (format) { + case FORMAT_U8: + res[0] = 1.f / (255.f - noValueCmp) * (max - min); + res[1] = min; + break; + case FORMAT_U16: + res[0] = 1.f / (65535.f - noValueCmp) * (max - min); + res[1] = min; + break; + case FORMAT_R32: + case FORMAT_U32: + case FORMAT_R64: + case FORMAT_U64: + case FORMAT_1BIT: + case FORMAT_ANY: + res[0] = 1.0f; + res[1] = 0.0f; + } + return res; + } + +} diff --git a/java/java/demo/WriteDataDemo.java b/java/java/demo/WriteDataDemo.java new file mode 100644 index 0000000000000000000000000000000000000000..74847dc1a5612d18bcb7774cc04fc9ead1caf62e --- /dev/null +++ b/java/java/demo/WriteDataDemo.java @@ -0,0 +1,178 @@ +import org.opengroup.openvds.*; + +import java.io.IOException; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +public class WriteDataDemo { + public static void main(String[] args) throws IOException { + roundtrip_2d(); + roundtrip_3d(); + } + + private static void roundtrip_2d() throws IOException { + final int nz = 113; + final int nx = 128; + + AzureOpenOptions options = new AzureOpenOptions(); + options.connectionString = System.getenv("CONNECTION_STRING"); + + if (options.connectionString == null) { + return; + } + + options.container = "test"; + options.blob = "rtrip_2d"; + + String[] names = new String[]{"chan1", "chan2"}; + VolumeDataChannelDescriptor.Format f = VolumeDataChannelDescriptor.Format.FORMAT_R32; + VdsHandle vds = new org.opengroup.openvds.AzureVdsGenerator(options, nz, nx, f, names); + + java.util.Random r = new java.util.Random(); + + double[] src1 = r.doubles(nx * nz).toArray(); + double[] src2 = r.doubles(nx * nz).toArray(); + + OpenVDS.writeArray(vds, src1, "chan1"); + OpenVDS.writeArray(vds, src2, "chan2"); + + vds.getAccessManager().flushUploadQueue(); + VdsHandle vds2; + + try { + vds2 = OpenVDS.open(options); + } catch (java.io.IOException e) { + fail(); + return; + } + + VolumeDataAccessManager access = vds2.getAccessManager(); + VolumeDataLayout layout = vds2.getLayout(); + NDBox box = new NDBox(0, 0, 0, 0, 0, 0, nz, nx, 0, 0, 0, 0); + + int channel = layout.getChannelIndex("chan1"); + long size = access.getVolumeSubsetBufferSize(box, f, 0, channel); + + java.nio.FloatBuffer outbuf = BufferUtils.createFloatBuffer((int) size / 4); + DimensionsND dims = DimensionsND.DIMENSIONS_01; + + long t = access.requestVolumeSubset(outbuf, dims, 0, channel, box); + access.waitForCompletion(t); + float[] arr = new float[outbuf.remaining()]; + outbuf.get(arr); + assertEquals(arr[0], src1[0], 1e-6); + assertEquals(arr[1], src1[1], 1e-6); + assertEquals(arr[nx], src1[nx], 1e-6); + } + + + private static void roundtrip_3d() throws IOException { + final int nz = 113; + final int ny = 107; + final int nx = 108; + +// AzureOpenOptions options = new AzureOpenOptions(); +// options.connectionString = System.getenv("CONNECTION_STRING"); +// +// if (options.connectionString == null) { +// return; +// } +// +// options.container = "test"; +// options.blob = "rtrip_3d"; +// +// String[] names = new String[]{"chan1", "chan2"}; +// VolumeDataChannelDescriptor.Format f = VolumeDataChannelDescriptor.Format.FORMAT_R32; +// VdsHandle vds = new org.opengroup.openvds.AzureVdsGenerator(options, nz, ny, nx, f, names); + + VDSFileOpenOptions options = new VDSFileOpenOptions(); + options.filePath = "/mnt/dataDD/tmp/test.vds"; + + if (options.filePath == null) { + return; + } + + String[] names = new String[]{"chan1", "chan2"}; + VolumeDataChannelDescriptor.Format f = VolumeDataChannelDescriptor.Format.FORMAT_R32; + + VolumeDataLayoutDescriptor ld = new VolumeDataLayoutDescriptor( + VolumeDataLayoutDescriptor.BrickSize.BRICK_SIZE_64, + 0, + 0, + 4, + VolumeDataLayoutDescriptor.LODLevels.LOD_LEVELS_NONE, + false, + false, + -1); + + VolumeDataAxisDescriptor[] vda = new VolumeDataAxisDescriptor[]{ + new VolumeDataAxisDescriptor(nz, "Sample", "ms", 0, nz * 4), + new VolumeDataAxisDescriptor(ny, "Xline", null, 0, ny), + new VolumeDataAxisDescriptor(nx, "Inline", null, 0, nx) + }; + + /** True data range */ + float valueRangeMax = Float.MAX_VALUE; + float valueRangeMin = -Float.MAX_VALUE; + + VolumeDataChannelDescriptor[] vdc = new VolumeDataChannelDescriptor[]{ + new VolumeDataChannelDescriptor( + VolumeDataChannelDescriptor.Format.FORMAT_R32, + VolumeDataChannelDescriptor.Components.COMPONENTS_1, + "Amplitude", "", + valueRangeMin, valueRangeMax, VolumeDataMapping.DIRECT, + 1, false, true, true, false, false, 0f, 1f, 0f), + new VolumeDataChannelDescriptor( + VolumeDataChannelDescriptor.Format.FORMAT_U8, + VolumeDataChannelDescriptor.Components.COMPONENTS_1, + "Trace", "", + 0, 1, VolumeDataMapping.PER_TRACE, + 1, true, true, false, false, false, 0, 1f, 0f), + new VolumeDataChannelDescriptor( + VolumeDataChannelDescriptor.Format.FORMAT_U8, + VolumeDataChannelDescriptor.Components.COMPONENTS_1, + "SEGYTraceHeader", "", + 0, 255, VolumeDataMapping.PER_TRACE, + 240, true, true, false, false, false, 0, 1f, 0f) + }; + + MetadataReadAccess md = new MetadataReadAccess(0); + VdsHandle vds = OpenVDS.create(options, ld, vda, vdc, md); + + java.util.Random r = new java.util.Random(); + + double[] src1 = r.doubles(nx * ny * nz).toArray(); + + float[] src2 = new float[src1.length]; + for (int i = 0; i < src2.length; i++) + src2[i] = i; + + OpenVDS.writeArray(vds, src1, "chan1"); + OpenVDS.writeArray(vds, src2, "chan2"); + + vds.getAccessManager().flushUploadQueue(); + VdsHandle vds2; + + vds2 = OpenVDS.open(options); + + VolumeDataAccessManager access = vds2.getAccessManager(); + VolumeDataLayout layout = vds2.getLayout(); + + NDBox box = new NDBox(0, 0, 0, 0, 0, 0, nz, ny, nx, 0, 0, 0); + + int channel = layout.getChannelIndex("chan2"); + long size = access.getVolumeSubsetBufferSize(box, f, 0, channel); + java.nio.FloatBuffer outbuf = BufferUtils.createFloatBuffer((int) size / 4); + DimensionsND dims = DimensionsND.DIMENSIONS_012; + + long t = access.requestVolumeSubset(outbuf, dims, 0, channel, box); + access.waitForCompletion(t); + float[] arr = new float[outbuf.remaining()]; + outbuf.get(arr); +// assertEquals(arr[0], src2[0], 1e-6); +// assertEquals(arr[nx], src2[nx], 1e-6); +// assertEquals(arr[nx * ny], src2[nx * ny], 1e-6); +// assertEquals(arr[nx * ny * nz - 42], src2[nx * ny * nz - 42], 1e-6); + } +} diff --git a/java/java/experimental/OpenVdsDemoWithArrayIntoBuffers.java b/java/java/experimental/OpenVdsDemoWithArrayIntoBuffers.java index 6d7bd6a67d1ebe26ad917b2701fa657ae18d4c25..b7aa40d82e34d98a05fc0976bc3c35c3b29695e2 100644 --- a/java/java/experimental/OpenVdsDemoWithArrayIntoBuffers.java +++ b/java/java/experimental/OpenVdsDemoWithArrayIntoBuffers.java @@ -83,7 +83,7 @@ public class OpenVdsDemoWithArrayIntoBuffers { final FloatBuffer positions = BufferUtils.toBuffer(samples); final FloatBuffer sampleBuffer = BufferUtils.createFloatBuffer(output_width * output_height); - long request = accessManager.requestVolumeSamples(sampleBuffer, layout, DimensionsND.DIMENSIONS_012, 0, 0, + long request = accessManager.requestVolumeSamples(sampleBuffer, DimensionsND.DIMENSIONS_012, 0, 0, positions, elemCount, InterpolationMethod.LINEAR); System.out.println("Wait for request completion..."); diff --git a/java/java/experimental/OpenVdsDemoWithBuffers.java b/java/java/experimental/OpenVdsDemoWithBuffers.java index 773d14d643bee9f7916b68229305ae6bfa2758f6..a783e12857c93aec4b25e16808f5c1bc4b389117 100644 --- a/java/java/experimental/OpenVdsDemoWithBuffers.java +++ b/java/java/experimental/OpenVdsDemoWithBuffers.java @@ -88,7 +88,7 @@ public class OpenVdsDemoWithBuffers { System.out.println("Request samples from VolumeDataAccessManager..."); final FloatBuffer samplesBuffer = BufferUtils.createFloatBuffer(output_width * output_height); - long request = accessManager.requestVolumeSamples(samplesBuffer, layout, DimensionsND.DIMENSIONS_012, 0, 0, + long request = accessManager.requestVolumeSamples(samplesBuffer, DimensionsND.DIMENSIONS_012, 0, 0, posBuffer, elemCount, InterpolationMethod.LINEAR); System.out.println("Wait for request completion..."); diff --git a/java/java/experimental/OpenVdsDemoWithSubset.java b/java/java/experimental/OpenVdsDemoWithSubset.java index 02dc8640ebc6703bac3ac8cda8de6eb6fdbd7aba..0a0c0b44c5599236d95691b453d829af5bb7dc87 100644 --- a/java/java/experimental/OpenVdsDemoWithSubset.java +++ b/java/java/experimental/OpenVdsDemoWithSubset.java @@ -49,7 +49,7 @@ public class OpenVdsDemoWithSubset { final FloatBuffer data = BufferUtils.createFloatBuffer(nZSamples * nYSamples); - final long request = accessManager.requestVolumeSubset(data, layout, DimensionsND.DIMENSIONS_012, 0, 0, box); + final long request = accessManager.requestVolumeSubset(data, DimensionsND.DIMENSIONS_012, 0, 0, box); System.out.println("Wait for request completion..."); while (!accessManager.waitForCompletion(request, 100)) { if (accessManager.isCanceled(request)) throw new RuntimeException("Cancelled job"); diff --git a/java/java/experimental/OpenVdsDemoWithSubsetAndBytes.java b/java/java/experimental/OpenVdsDemoWithSubsetAndBytes.java index 3159e373d98fd5315433afd0dee4b295b93e8a92..5062a341ff8f8576a4d186b9f5eab478fb7bd9cc 100644 --- a/java/java/experimental/OpenVdsDemoWithSubsetAndBytes.java +++ b/java/java/experimental/OpenVdsDemoWithSubsetAndBytes.java @@ -50,7 +50,7 @@ public class OpenVdsDemoWithSubsetAndBytes { final ByteBuffer data = BufferUtils.createByteBuffer(nZSamples * nYSamples); - final long request = accessManager.requestVolumeSubset(data, layout, DimensionsND.DIMENSIONS_012, 0, 0, box); + final long request = accessManager.requestVolumeSubset(data, DimensionsND.DIMENSIONS_012, 0, 0, box); System.out.println("Wait for request completion..."); while (!accessManager.waitForCompletion(request, 100)) { if (accessManager.isCanceled(request)) throw new RuntimeException("Cancelled job"); diff --git a/java/java/src/org/opengroup/openvds/MetadataContainer.java b/java/java/src/org/opengroup/openvds/MetadataContainer.java new file mode 100644 index 0000000000000000000000000000000000000000..e156e11c2cea30f2648a2e6c154ceebdf3f411f0 --- /dev/null +++ b/java/java/src/org/opengroup/openvds/MetadataContainer.java @@ -0,0 +1,225 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +import java.util.HashMap; +import java.util.Map; + +public class MetadataContainer extends MetadataReadAccess { + + private static native long cpCreateMetadataContainerHandle(); + + private static native void cpDeleteHandle(long handle); + + private static native void cpSetMetadataInt(long handle, String category, String name, int value); + + private static native void cpSetMetadataIntVector2(long handle, String category, String name, int[] value); + + private static native void cpSetMetadataIntVector3(long handle, String category, String name, int[] value); + + private static native void cpSetMetadataIntVector4(long handle, String category, String name, int[] value); + + private static native void cpSetMetadataFloat(long handle, String category, String name, float value); + + private static native void cpSetMetadataFloatVector2(long handle, String category, String name, float[] value); + + private static native void cpSetMetadataFloatVector3(long handle, String category, String name, float[] value); + + private static native void cpSetMetadataFloatVector4(long handle, String category, String name, float[] value); + + private static native void cpSetMetadataDouble(long handle, String category, String name, double value); + + private static native void cpSetMetadataDoubleVector2(long handle, String category, String name, double[] value); + + private static native void cpSetMetadataDoubleVector3(long handle, String category, String name, double[] value); + + private static native void cpSetMetadataDoubleVector4(long handle, String category, String name, double[] value); + + private static native void cpSetMetadataString(long handle, String category, String name, String value); + + /** + * Constructor around existing JNI object + * @param handle jni pointer to existing container + */ + public MetadataContainer(long handle) { + super(handle); + } + + /** + * Creates new MetadataContainer + */ + public MetadataContainer() { + super(cpCreateMetadataContainerHandle()); + setOwnHandle(true); + } + + // Called by JniPointer.release() + @Override + protected synchronized void deleteHandle() { + cpDeleteHandle(_handle); + } + + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataInt(String category, String name, int value) { + cpSetMetadataInt(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataIntVector2(String category, String name, int[] value) { + checkArrayArgument(value, 2); + cpSetMetadataIntVector2(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataIntVector3(String category, String name, int[] value) { + checkArrayArgument(value, 3); + cpSetMetadataIntVector3(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataIntVector4(String category, String name, int[] value) { + checkArrayArgument(value, 4); + cpSetMetadataIntVector4(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataFloat(String category, String name, float value) { + cpSetMetadataFloat(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataFloatVector2(String category, String name, float[] value) { + checkArrayArgument(value, 2); + cpSetMetadataFloatVector2(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataFloatVector3(String category, String name, float[] value) { + checkArrayArgument(value, 3); + cpSetMetadataFloatVector3(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataFloatVector4(String category, String name, float[] value) { + checkArrayArgument(value, 4); + cpSetMetadataFloatVector4(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataDouble(String category, String name, double value) { + cpSetMetadataDouble(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataDoubleVector2(String category, String name, double[] value) { + checkArrayArgument(value, 2); + cpSetMetadataDoubleVector2(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataDoubleVector3(String category, String name, double[] value) { + checkArrayArgument(value, 3); + cpSetMetadataDoubleVector3(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataDoubleVector4(String category, String name, double[] value) { + checkArrayArgument(value, 4); + cpSetMetadataDoubleVector4(_handle, category, name, value); + } + + /** + * @param category + * @param name + * @param value + */ + public void setMetadataString(String category, String name, String value) { + if (value == null) { + throw new IllegalArgumentException("Null String Metadata."); + } + cpSetMetadataString(_handle, category, name, value); + } + + + private void checkArrayArgument(int[] array, int expectedSize) { + if (array == null || array.length != expectedSize) { + throw new IllegalArgumentException("Wrong IntVector parameter size, expected " + expectedSize + " got " + (array == null ? "null" : array.length)); + } + } + + private void checkArrayArgument(float[] array, int expectedSize) { + if (array == null || array.length != expectedSize) { + throw new IllegalArgumentException("Wrong FloatVector parameter size, expected 2, got " + (array == null ? "null" : array.length)); + } + } + + private void checkArrayArgument(double[] array, int expectedSize) { + if (array == null || array.length != expectedSize) { + throw new IllegalArgumentException("Wrong DoubleVector parameter size, expected 2, got " + (array == null ? "null" : array.length)); + } + } +} \ No newline at end of file diff --git a/java/java/src/org/opengroup/openvds/OpenVDS.java b/java/java/src/org/opengroup/openvds/OpenVDS.java index 76e55661eac8a216c086d4b31f3c1c3fc8662856..5ba85648d1b0127df9750ab1541f57f81826f4f8 100644 --- a/java/java/src/org/opengroup/openvds/OpenVDS.java +++ b/java/java/src/org/opengroup/openvds/OpenVDS.java @@ -29,16 +29,21 @@ public class OpenVDS extends VdsHandle{ private static native long cpOpenAzurePresigned(String baseUrl, String urlSuffix) throws IOException; + private static native long cpOpenVDSFile(String filePath) throws IOException; + private static native long cpOpenConnection(String url, String connectionString) throws IOException; private static native boolean cpIsCompressionMethodSupported(int compressionMethod); + private static native long cpCreateVDSFile(String pFilePath, + VolumeDataLayoutDescriptor ld, VolumeDataAxisDescriptor[] vda, + VolumeDataChannelDescriptor[] vdc, MetadataReadAccess md, int compressionMethod, float compressionTolerance) throws IOException; + private static native long cpCreateAzure(String pConnectionString, String pContainer, String pBlob, int pParallelismFactor, int pMaxExecutionTime, VolumeDataLayoutDescriptor ld, VolumeDataAxisDescriptor[] vda, VolumeDataChannelDescriptor[] vdc, MetadataReadAccess md, int compressionMethod, float compressionTolerance) throws IOException; - private static native long cpCreateAws(String bucket, String key, String region, String endpointoverhide, String accessKeyId, String secretKey, String sessionToken, String expiration, VolumeDataLayoutDescriptor ld, VolumeDataAxisDescriptor[] vda, VolumeDataChannelDescriptor[] vdc, MetadataReadAccess md, int compressionMethod, float compressionTolerance) throws IOException; @@ -85,20 +90,25 @@ public class OpenVDS extends VdsHandle{ if ("".equals(url)) throw new IllegalArgumentException("url can't be empty"); return new OpenVDS(cpOpenConnection(url, connectionString), true); } - + + public static OpenVDS open(VDSFileOpenOptions o) throws IOException { + if (o == null) throw new IllegalArgumentException("open option can't be null"); + return new OpenVDS(cpOpenVDSFile(o.filePath), true); + } + private static void validateCreateArguments(VolumeDataLayoutDescriptor ld, VolumeDataAxisDescriptor[] vda, VolumeDataChannelDescriptor[] vdc, - MetadataReadAccess md) throws IOException { + MetadataReadAccess md) throws IllegalArgumentException { if (ld == null) { throw new IllegalArgumentException("VolumeDataLayoutDescriptor can't be null"); } - if (vda == null || java.util.Arrays.stream(vda).allMatch(a -> {return a == null;})) { + if (vda == null || java.util.Arrays.stream(vda).allMatch(a -> a == null)) { throw new IllegalArgumentException("VolumeDataLayoutDescriptor or its elements can't be null"); } - if (vdc == null || java.util.Arrays.stream(vdc).allMatch(a -> {return a == null;})) { + if (vdc == null || java.util.Arrays.stream(vdc).allMatch(a -> a == null)) { throw new IllegalArgumentException("VolumeDataChannelDescriptor or its elements can't be null"); } @@ -109,7 +119,7 @@ public class OpenVDS extends VdsHandle{ private static void validateCreateArguments(OpenOpt o, VolumeDataLayoutDescriptor ld, VolumeDataAxisDescriptor[] vda, VolumeDataChannelDescriptor[] vdc, - MetadataReadAccess md) throws IOException { + MetadataReadAccess md) throws IllegalArgumentException { if (o == null) { throw new IllegalArgumentException("open option can't be null"); @@ -136,11 +146,25 @@ public class OpenVDS extends VdsHandle{ MetadataReadAccess md, CompressionMethod compressionMethod, float compressionTolerance) throws IOException { validateCreateArguments(o, ld, vda, vdc, md); - return new OpenVDS(cpCreateAzure(o.connectionString, o.container, o.blob, + return new OpenVDS(cpCreateAzure(o.connectionString, o.container, o.blob, o.parallelism_factor, o.max_execution_time, ld, vda, vdc, md, compressionMethod.ordinal(), compressionTolerance), true); } + public static OpenVDS create(VDSFileOpenOptions o, VolumeDataLayoutDescriptor ld, + VolumeDataAxisDescriptor[] vda, VolumeDataChannelDescriptor[] vdc, + MetadataReadAccess md) throws IOException { + validateCreateArguments(o, ld, vda, vdc, md); + return new OpenVDS(cpCreateVDSFile(o.filePath, ld, vda, vdc, md, 0, 0), true); + } + + public static OpenVDS create(VDSFileOpenOptions o, VolumeDataLayoutDescriptor ld, + VolumeDataAxisDescriptor[] vda, VolumeDataChannelDescriptor[] vdc, + MetadataReadAccess md, CompressionMethod compressionMethod, float compressionTolerance) throws IOException { + validateCreateArguments(o, ld, vda, vdc, md); + return new OpenVDS(cpCreateVDSFile(o.filePath, ld, vda, vdc, md, compressionMethod.ordinal(), compressionTolerance), true); + } + public static OpenVDS create(AWSOpenOptions o, VolumeDataLayoutDescriptor ld, VolumeDataAxisDescriptor[] vda, VolumeDataChannelDescriptor[] vdc, MetadataReadAccess md) throws IOException { @@ -173,7 +197,7 @@ public class OpenVDS extends VdsHandle{ MetadataReadAccess md, CompressionMethod compressionMethod, float compressionTolerance) throws IOException { validateCreateArguments(o, ld, vda, vdc, md); - return new OpenVDS(cpCreateGoogle(o.bucket, o.pathPrefix, + return new OpenVDS(cpCreateGoogle(o.bucket, o.pathPrefix, ld, vda, vdc, md, compressionMethod.ordinal(), compressionTolerance), true); } diff --git a/java/java/src/org/opengroup/openvds/VDSFileOpenOptions.java b/java/java/src/org/opengroup/openvds/VDSFileOpenOptions.java new file mode 100644 index 0000000000000000000000000000000000000000..d17c89ea9bd5e2bd04f0bab5535aca421c800e9b --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VDSFileOpenOptions.java @@ -0,0 +1,44 @@ +/* + * Copyright 2019 The Open Group + * Copyright 2019 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +/** + * Options for opening a VDS in Microsoft Azure cloud computing platform. + */ +public class VDSFileOpenOptions extends OpenOptions { + + public String filePath; + + /** + * Default constructor. + */ + public VDSFileOpenOptions() { + super(ConnectionType.File); + } + + /** + * Constructor. + * + * @param pFilePath the file path the VDS + */ + public VDSFileOpenOptions(String pFilePath) { + super(ConnectionType.File); + + this.filePath = pFilePath; + } +} diff --git a/java/java/src/org/opengroup/openvds/VdsError.java b/java/java/src/org/opengroup/openvds/VdsError.java new file mode 100644 index 0000000000000000000000000000000000000000..097316198769c1379966a6e2a9a642c300702265 --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VdsError.java @@ -0,0 +1,47 @@ +package org.opengroup.openvds; + +public class VdsError extends JniPointerWithoutDeletion { + + private static native long cpCreateErrorHandle(); + + private static native void cpDeleteHandle(long handle); + + private static native void cpSetErrorCode(long handle, int code); + + private static native void cpSetErrorMessage(long handle, String message); + + private static native int cpGetErrorCode(long handle); + + private static native String cpGetErrorMessage(long handle); + + public VdsError() { + super(cpCreateErrorHandle()); + setOwnHandle(true); + } + + public VdsError(long handle) { + super(handle); + } + + // Called by JniPointer.release() + @Override + protected synchronized void deleteHandle() { + cpDeleteHandle(_handle); + } + + public int getErrorCode() { + return cpGetErrorCode(_handle); + } + + public void setErrorCode(int errorCode) { + cpSetErrorCode(_handle, errorCode); + } + + public String getMessage() { + return cpGetErrorMessage(_handle); + } + + public void setMessage(String message) { + cpSetErrorMessage(_handle, message); + } +} diff --git a/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java b/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java index 4388c139f92da9dc2e67b9edde719b8ff0bcbc49..087f9f38d2b6bc86e673034459c06d2956c76782 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataAccessManager.java @@ -117,6 +117,8 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { private static native int cpUploadErrorCount(long handle); + private static native int cpGetCurrentUploadErrorCode(long handle); + public VolumeDataAccessManager(long handle) { super(handle); } @@ -132,7 +134,7 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { * @return the VolumeDataLayout object associated with the VDS or null if * there is no valid VolumeDataLayout. */ - VolumeDataLayout getVolumeDataLayout() { + public VolumeDataLayout getVolumeDataLayout() { return new VolumeDataLayout(cpGetVolumeDataLayout(_handle)); } @@ -147,7 +149,7 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { * @return The produce status for the specific DimensionsND/LOD/Channel * combination. */ - VDSProduceStatus getVDSProduceStatus(DimensionsND dimensionsND, int lod, int channel) { + public VDSProduceStatus getVDSProduceStatus(DimensionsND dimensionsND, int lod, int channel) { return VDSProduceStatus.values()[cpGetVDSProduceStatus(_handle, dimensionsND.ordinal(), lod, channel)]; } @@ -167,7 +169,7 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { * @return a VolumeDataPageAccessor object for the VDS associated with the * given VolumeDataLayout object. */ - VolumeDataPageAccessor createVolumeDataPageAccessor(int dimensionsND, int lod, int channel, int maxPages, int accessMode) { + public VolumeDataPageAccessor createVolumeDataPageAccessor(int dimensionsND, int lod, int channel, int maxPages, int accessMode) { return new VolumeDataPageAccessor(cpCreateVolumeDataPageAccessor(_handle, dimensionsND, lod, channel, maxPages, accessMode)); } @@ -190,7 +192,7 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { * @return a VolumeDataPageAccessor object for the VDS associated with the * given VolumeDataLayout object. */ - VolumeDataPageAccessor createVolumeDataPageAccessor(int dimensionsND, int lod, int channel, int maxPages, int accessMode, int chunkMetadataPageSize) { + public VolumeDataPageAccessor createVolumeDataPageAccessor(int dimensionsND, int lod, int channel, int maxPages, int accessMode, int chunkMetadataPageSize) { return new VolumeDataPageAccessor(cpCreateVolumeDataPageAccessor(_handle, dimensionsND, lod, channel, maxPages, accessMode, chunkMetadataPageSize)); } @@ -200,7 +202,7 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { * @param volumeDataPageAccessor the VolumeDataPageAccessor object to * destroy. */ - void destroyVolumeDataPageAccessor(VolumeDataPageAccessor volumeDataPageAccessor) { + public void destroyVolumeDataPageAccessor(VolumeDataPageAccessor volumeDataPageAccessor) { cpDestroyVolumeDataPageAccessor(_handle, volumeDataPageAccessor.handle()); } @@ -209,7 +211,7 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { * * @param accessor the VolumeDataAccessor object to destroy. */ - void destroyVolumeDataAccessor(VolumeDataAccessor accessor) { + public void destroyVolumeDataAccessor(VolumeDataAccessor accessor) { cpDestroyVolumeDataAccessor(_handle, accessor.handle()); } @@ -219,7 +221,7 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { * @param accessor the VolumeDataAccessor object to clone. * @return a clone of supplied VolumeDataAccessor object */ - VolumeDataAccessor cloneVolumeDataAccessor(VolumeDataAccessor accessor) { + public VolumeDataAccessor cloneVolumeDataAccessor(VolumeDataAccessor accessor) { return new VolumeDataAccessor(cpCloneVolumeDataAccessor(_handle, accessor.handle()), true); } @@ -725,4 +727,8 @@ public class VolumeDataAccessManager extends JniPointerWithoutDeletion { public int uploadErrorCount() { return cpUploadErrorCount(_handle); } + + public int getCurrentUploadErrorCode() { + return cpGetCurrentUploadErrorCode(_handle); + } } diff --git a/java/java/src/org/opengroup/openvds/VolumeDataAxisDescriptor.java b/java/java/src/org/opengroup/openvds/VolumeDataAxisDescriptor.java index 6c5c5d8e2c50eca7f223f4856df89dbb02205c79..9b9ecd16b8a03a7ec571c3d1571d9a4603b1d873 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataAxisDescriptor.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataAxisDescriptor.java @@ -28,6 +28,19 @@ public class VolumeDataAxisDescriptor { private float coordinateMin; private float coordinateMax; + /** + * Default constructor Needed by JNI + */ + private VolumeDataAxisDescriptor() { } + + public VolumeDataAxisDescriptor(int numSamples, String name, String unit, float coordinateMin, float coordinateMax) { + this.numSamples = numSamples; + this.name = name; + this.unit = unit; + this.coordinateMin = coordinateMin; + this.coordinateMax = coordinateMax; + } + public int getNumSamples() { return numSamples; } diff --git a/java/java/src/org/opengroup/openvds/VolumeDataChannelDescriptor.java b/java/java/src/org/opengroup/openvds/VolumeDataChannelDescriptor.java index 1d77e8b5a08c50f6ee7edfd1c6ad27d033bb4e21..b7dfba66513503a99bc6c884ae7ca2baeacd3e88 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataChannelDescriptor.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataChannelDescriptor.java @@ -126,6 +126,44 @@ public class VolumeDataChannelDescriptor { private float integerScale; private float integerOffset; + private VolumeDataChannelDescriptor(){ + // Used by c++ + } + + public VolumeDataChannelDescriptor( + Format format, + Components components, + String name, + String unit, + float valueRangeMin, float valueRangeMax, + VolumeDataMapping mapping, + int mappedValueCount, + boolean isDiscrete, + boolean isRenderable, + boolean isAllowLossyCompression, + boolean isUseZipForLosslessCompression, + boolean useNoValue, + float noValue, + float integerScale, + float integerOffset) { + this.format = format.code; + this.components = components.code; + this.name = name; + this.unit = unit; + this.valueRangeMin = valueRangeMin; + this.valueRangeMax = valueRangeMax; + this.mapping = mapping.code; + this.mappedValueCount = mappedValueCount; + this.isDiscrete = isDiscrete; + this.isRenderable = isRenderable; + this.isAllowLossyCompression = isAllowLossyCompression; + this.isUseZipForLosslessCompression = isUseZipForLosslessCompression; + this.useNoValue = useNoValue; + this.noValue = noValue; + this.integerScale = integerScale; + this.integerOffset = integerOffset; + } + public int getFormat() { return format; } diff --git a/java/java/src/org/opengroup/openvds/VolumeDataLayoutDescriptor.java b/java/java/src/org/opengroup/openvds/VolumeDataLayoutDescriptor.java index e43070c3d4602d1cd17e7a1945debd289dfaf3d2..801087046226fc77f04655d6a263aedbac3f003f 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataLayoutDescriptor.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataLayoutDescriptor.java @@ -26,19 +26,21 @@ import java.util.Optional; public class VolumeDataLayoutDescriptor { public enum BrickSize { - BRICK_SIZE_32(5), - BRICK_SIZE_64(6), - BRICK_SIZE_128(7), - BRICK_SIZE_256(8), - BRICK_SIZE_512(9), - BRICK_SIZE_1024(10), - BRICK_SIZE_2048(11), - BRICK_SIZE_4096(12); + BRICK_SIZE_32(5, 32), + BRICK_SIZE_64(6, 64), + BRICK_SIZE_128(7, 128), + BRICK_SIZE_256(8, 256), + BRICK_SIZE_512(9, 512), + BRICK_SIZE_1024(10, 1024), + BRICK_SIZE_2048(11, 2048), + BRICK_SIZE_4096(12, 4096); private final int code; + private final int dimension; - BrickSize(int code) { + BrickSize(int code, int dim) { this.code = code; + this.dimension = dim; } public static BrickSize fromCode(int code) { @@ -54,6 +56,10 @@ public class VolumeDataLayoutDescriptor { public int getCode() { return code; } + + public int getDimension() { + return dimension; + } } public enum LODLevels { @@ -81,13 +87,13 @@ public class VolumeDataLayoutDescriptor { IS_FORCE_FULL_RESOLUTION_DIMENSION = 6, FULL_RESOLUTION_DIMENSION = 7; - private int[] _values; + private int[] _values = new int[8]; public VolumeDataLayoutDescriptor(BrickSize brickSize, int negativeMargin, int positiveMargin, int brickSize2DMultiplier, LODLevels lodLevels, boolean isCreate2DLODs, boolean isForceFullResolutionDimension, int fullResolutionDimension) { - _values[BRICK_SIZE] = brickSize.ordinal(); + _values[BRICK_SIZE] = brickSize.getCode(); _values[NEGATIVE_MARGIN] = negativeMargin; _values[POSITIVE_MARGIN] = positiveMargin; _values[BRICK_SIZE_2D_MULTIPLIER] = brickSize2DMultiplier; diff --git a/java/java/src/org/opengroup/openvds/VolumeDataPage.java b/java/java/src/org/opengroup/openvds/VolumeDataPage.java index f1f490fd7c7884b6fc593d6f243673152a14bf14..b041a25f65c4402dac5686e5e52ff78c3a71cbd1 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataPage.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataPage.java @@ -19,10 +19,47 @@ package org.opengroup.openvds; public class VolumeDataPage extends JniPointer { + private static native void cpRelease(long handle); + private static native void cpDeleteHandle(long handle); - public VolumeDataPage(long handle) { + private static native void cpGetMinMax(long handle, int[] min, int[] max); + + private static native void cpGetMinMaxExcludingMargin(long handle, int[] min, int[] max); + + private static native int cpGetAllocatedSize(long handle); + + private static native void cpGetPitch(long handle, int[] pitch); + + private static native byte[] cpGetByteBuffer(long handle, int[] pitch, int lod); + + private static native void cpSetByteBuffer(long handle, byte[] buffer); + + private static native float[] cpGetFloatBuffer(long handle, int[] pitch, int lod); + + private static native void cpSetFloatBuffer(long handle, float[] buffer); + + private static native double[] cpGetDoubleBuffer(long handle, int[] pitch, int lod); + + private static native void cpSetDoubleBuffer(long handle, double[] buffer); + + private final int dimensionality; + private final int lod; + + public VolumeDataPage(long handle, int dimensionality, int lod) { super(handle, true); + this.dimensionality = dimensionality; + this.lod = lod; + } + + public VolumeDataPage(long handle, int dimensionality, int lod, boolean ownHandle) { + super(handle, ownHandle); + this.dimensionality = dimensionality; + this.lod = lod; + } + + public void pageRelease() { + cpRelease(_handle); } // Called by JniPointer.release() @@ -30,4 +67,149 @@ public class VolumeDataPage extends JniPointer { protected synchronized void deleteHandle() { cpDeleteHandle(_handle); } + + /** + * Get min max extent, and set results in array parameters + * @param min arrays that will receive min values + * @param max arrays that will receive max values + */ + public void getMinMax(int[] min, int[] max) { + checkDimParamArray(min, "Wrong min array parameter size, expected "); + checkDimParamArray(max, "Wrong max array parameter size, expected "); + cpGetMinMax(_handle, min, max); + } + + /** + * Get min max extent, and set results in array parameters + * @param min arrays that will receive min values + * @param max arrays that will receive max values + */ + public void getMinMaxExcludingMargin(int[] min, int[] max) { + checkDimParamArray(min, "Wrong min array parameter size, expected "); + checkDimParamArray(max, "Wrong max array parameter size, expected "); + cpGetMinMaxExcludingMargin(_handle, min, max); + } + + /** + * @return the buffer size of this page + */ + public int getAllocatedBufferSize() { + return cpGetAllocatedSize(_handle); + } + + /** + * Read the pitch of this volume page and puts it in pitch array parameter + */ + public void getPitch(int pitch[]) { + checkDimParamArray(pitch, "Wrong pitch array parameter size, expected "); + cpGetPitch(_handle, pitch); + } + + /** + * Read byte array of page + * @param pitch will receive pitch values for this page + * @return the float array of page data + */ + public byte[] readByteBuffer(int[] pitch) { + checkDimParamArray(pitch, "Wrong pitch array parameter size, expected "); + return cpGetByteBuffer(_handle, pitch, lod); + } + + /** + * Set byte array int page + * @param buffer values to set. Size must match page sample size + * @param pitch chunk pitch (got by a read) + */ + public void writeByteBuffer(byte[] buffer, int[] pitch) { + checkBufferSize(buffer, pitch, dimensionality, lod); + cpSetByteBuffer(_handle, buffer); + } + + /** + * Read float array of page + * @param pitch will receive pitch values for this page + * @return the float array of page data + */ + public float[] readFloatBuffer(int[] pitch) { + checkDimParamArray(pitch, "Wrong pitch array parameter size, expected "); + return cpGetFloatBuffer(_handle, pitch, lod); + } + + /** + * Set float array int page + * @param buffer values to set. Size must match page sample size + * @param pitch chunk pitch (got by a read) + */ + public void writeFloatBuffer(float[] buffer, int[] pitch) { + checkBufferSize(buffer, pitch, dimensionality, lod); + cpSetFloatBuffer(_handle, buffer); + } + + /** + * Read double array of page + * @param pitch will receive pitch values for this page + * @return the double array of page data + */ + public double[] readDoubleBuffer(int[] pitch) { + checkDimParamArray(pitch, "Wrong pitch array parameter size, expected "); + return cpGetDoubleBuffer(_handle, pitch, lod); + } + + /** + * Set double array int page + * @param buffer values to set. Size must match page sample size + * @param pitch chunk pitch (got by a read) + */ + public void writeDoubleBuffer(double[] buffer, int[] pitch) { + checkBufferSize(buffer, pitch, dimensionality, lod); + cpSetDoubleBuffer(_handle, buffer); + } + + private int getElementCount() { + int[] chunkMin = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMax = new int[VolumeDataLayout.Dimensionality_Max]; + getMinMax(chunkMin, chunkMax); + return getElementCount(chunkMin, chunkMax); + } + + private void checkBufferSize(byte[] buffer, int[] pitch, int dim, int lod) { + if (buffer == null) { + throw new IllegalArgumentException("Wrong buffer size, got NULL"); + } + checkBufferSize(buffer.length, pitch, dimensionality, lod); + } + + private void checkBufferSize(float[] buffer, int[] pitch, int dim, int lod) { + if (buffer == null) { + throw new IllegalArgumentException("Wrong buffer size, got NULL"); + } + checkBufferSize(buffer.length, pitch, dimensionality, lod); + } + + private void checkBufferSize(double[] buffer, int[] pitch, int dim, int lod) { + if (buffer == null) { + throw new IllegalArgumentException("Wrong buffer size, got NULL"); + } + checkBufferSize(buffer.length, pitch, dimensionality, lod); + } + + private void checkBufferSize(int sizeInputBuffer, int[] pitch, int dim, int lod) { + int pageBufferSize = getAllocatedBufferSize(); + if (sizeInputBuffer != pageBufferSize) { + throw new IllegalArgumentException("Wrong buffer size, expected " + pageBufferSize + ", got " + sizeInputBuffer); + } + } + + private void checkDimParamArray(int[] pitch, String s) { + if (pitch == null || pitch.length != VolumeDataLayout.Dimensionality_Max) { + throw new IllegalArgumentException(s + VolumeDataLayout.Dimensionality_Max + ", got " + (pitch == null ? "null" : pitch.length)); + } + } + + private int getElementCount(int[] min, int[] max) { + int chunkSizeI = max[2] - min[2]; + int chunkSizeX = max[1] - min[1]; + int chunkSizeZ = max[0] - min[0]; + return chunkSizeI * chunkSizeX * chunkSizeZ; + } } diff --git a/java/java/src/org/opengroup/openvds/VolumeDataPageAccessor.java b/java/java/src/org/opengroup/openvds/VolumeDataPageAccessor.java index e6ba2937e20e0319776c788e0793dd6cc8098444..333af15a152086d0a980be21b08e837673af0e6d 100644 --- a/java/java/src/org/opengroup/openvds/VolumeDataPageAccessor.java +++ b/java/java/src/org/opengroup/openvds/VolumeDataPageAccessor.java @@ -17,18 +17,186 @@ package org.opengroup.openvds; +import java.util.Arrays; +import java.util.Optional; + public class VolumeDataPageAccessor extends JniPointerWithoutDeletion { - + + public enum AccessMode { + ReadOnly(0), + ReadWrite(1), + Create(2); + + private final int code; + + AccessMode(int code) { + this.code = code; + } + + public int getCode() { + return code; + } + + public static AccessMode fromCode(int codeParam) { + Optional first = Arrays + .stream(values()) + .filter(e -> e.getCode() == codeParam) + .findFirst(); + if (!first.isPresent()) + throw new IllegalArgumentException("invalid code"); + return first.get(); + } + } + private static native long cpGetLayout( long handle ); + private static native int cpGetLOD( long handle ); + private static native int cpGetChannelIndex(long handle); + private static native int[] cpGetNumSamples(long handle); + private static native long cpGetChunkCount( long handle ); + private static native void cpGetChunkMinMax( long handle, int chunk, int[] chunkMin, int[] chunkMax); + private static native void cpGetChunkMinMaxExcludingMargin( long handle, int chunk, int[] chunkMin, int[] chunkMax); + private static native long cpGetChunkIndex(long handle, int[] position); + private static native long cpGetMappedChunkIndex(long handle, long primaryChannelChunkIndex); + private static native long cpGetPrimaryChannelChunkIndex(long handle, long chunkIndex); + private static native long cpCreatePage( long handle, long chunkIndex); + private static native long cpReadPage( long handle, long chunkIndex); + private static native void cpCommit(long handle); + private static native void cpSetMaxPage(long handle, int maxPage); VolumeDataPageAccessor(long handle) { super(handle); } - VolumeDataLayout getLayout() { - return new VolumeDataLayout( cpGetLayout(_handle) ); - } + /** + * Get volume layout + * @return + */ + public VolumeDataLayout getLayout() { + return new VolumeDataLayout( cpGetLayout(_handle) ); + } + + /** + * @return the LOD value for this page accessor + */ + public int getLOD() { + return cpGetLOD(_handle); + } + + /** + * @return the channel index for this page accessor + */ + public int getChannelIndex() { + return cpGetChannelIndex(_handle); + } + + /** + * Get the num samples for this page accessor on each dimension + * @return an array of size Dimensionality_Max (or null if error) + */ + public int[] getNumSamples() { + return cpGetNumSamples(_handle); + } + + + /** + * @return the chunk count + */ + public long getChunkCount() { + return cpGetChunkCount(_handle); + } + /** + * Get chunk dimension + * @param chunk chunk index + * @param chunkMin array that will receive min values + * @param chunkMax array that will receive max values + * @throws IllegalArgumentException if chunk min and max array don't have the correct size, or if chunk index is incorrect + */ + public void getChunkMinMax(int chunk, int[] chunkMin, int[] chunkMax) { + checkChunkAndArraySize(chunk, chunkMin, chunkMax); + cpGetChunkMinMax(_handle, chunk, chunkMin, chunkMax); + } + + /** + * Get chunk dimension (without margin) + * @param chunk chunk index + * @param chunkMin array that will receive min values + * @param chunkMax array that will receive max values + * @throws IllegalArgumentException if chunk min and max array don't have the correct size, or if chunk index is incorrect + */ + public void getChunkMinMaxExcludingMargin(int chunk, int[] chunkMin, int[] chunkMax) { + checkChunkAndArraySize(chunk, chunkMin, chunkMax); + cpGetChunkMinMaxExcludingMargin(_handle, chunk, chunkMin, chunkMax); + } + + /** + * Get index of chunk for a given position + * @param position voxel position (array must be VolumeDataLayout.Dimensionality_Max size) + * @return chunk position + */ + public long getChunkIndex(int[] position) { + checkPosition(position); + return cpGetChunkIndex(_handle, position); + } + + /** + * Create page for given chunk index + * @param chunkIndex + * @return A VolumeDataPage + * @throws IllegalArgumentException if chunkIndex is incorrect + */ + public VolumeDataPage createPage(long chunkIndex) { + if (chunkIndex < 0 || chunkIndex >= getChunkCount()) { + throw new IllegalArgumentException("VolumeDataPageAccessor::createPage : wrong chunk index"); + } + return new VolumeDataPage(cpCreatePage(_handle, chunkIndex), getLayout().getDimensionality(), getLOD()); + } + + /** + * Reads page for given chunk index + * @param chunkIndex + * @return A VolumeDataPage + * @throws IllegalArgumentException if chunkIndex is incorrect + */ + public VolumeDataPage readPage(long chunkIndex) { + if (chunkIndex < 0 || chunkIndex >= getChunkCount()) { + throw new IllegalArgumentException("VolumeDataPageAccessor::readPage : wrong chunk index"); + } + return new VolumeDataPage(cpReadPage(_handle, chunkIndex), getLayout().getDimensionality(), getLOD()); + } + + /** + * Commit modification + */ + public void commit() { + cpCommit(_handle); + } + + /** + * Set maximum number of pages + * @param maxPages page count + */ + public void setMaxPages(int maxPages) { + cpSetMaxPage(_handle, maxPages); + } + + private void checkPosition(int[] position) { + if (position == null || position.length != VolumeDataLayout.Dimensionality_Max) { + throw new IllegalArgumentException("VolumeDataPageAccessor::getChunkIndex : wrong position vector"); + } + } + + private void checkChunkAndArraySize(int chunk, int[] chunkMin, int[] chunkMax) { + if (chunk < 0 || chunk >= getChunkCount()) { + throw new IllegalArgumentException("VolumeDataPageAccessor::getChunkMinMax : wrong chunk index"); + } + if (chunkMin == null || chunkMin.length != VolumeDataLayout.Dimensionality_Max) { + throw new IllegalArgumentException("VolumeDataPageAccessor::getChunkMinMax : wrong chunkMin array, expected non null or size 6"); + } + if (chunkMax == null || chunkMax.length != VolumeDataLayout.Dimensionality_Max) { + throw new IllegalArgumentException("VolumeDataPageAccessor::getChunkMinMax : wrong chunkMax array, expected non null or size 6"); + } + } /* virtual int GetLOD() const = 0; virtual int GetChannelIndex() const = 0; diff --git a/java/java/src/org/opengroup/openvds/VolumeIndexer2D.java b/java/java/src/org/opengroup/openvds/VolumeIndexer2D.java new file mode 100644 index 0000000000000000000000000000000000000000..b773dc5b49b0c31f79b01de3b4f2176668832523 --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VolumeIndexer2D.java @@ -0,0 +1,145 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +public class VolumeIndexer2D extends VolumeIndexerBase { + + private static native long cpCreateVolumeIndexer2D(long pageHandle, int channelIndex, int lod, int dimensions, long layoutHandle); + + private static native void cpLocalIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j); + private static native void cpLocalIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j); + + private static native void cpVoxelIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j); + private static native void cpVoxelIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j); + + private static native void cpLocalChunkIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j); + private static native void cpLocalChunkIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j); + + private static native int cpLocalIndexToDataIndex(long handle, int i, int j); + private static native int cpVoxelIndexToDataIndex(long handle, int i, int j); + private static native int cpLocalChunkIndexToDataIndex(long handle, int i, int j); + + private static native boolean cpVoxelIndexInProcessArea(long handle, int i, int j); + private static native boolean cpLocalIndexInProcessArea(long handle, int i, int j); + private static native boolean cpLocalChunkIndexInProcessArea(long handle, int i, int j); + + /** + * Constructor + * @param page + * @param channelIndex + * @param lod + * @param dimensions + * @param layout + */ + public VolumeIndexer2D(VolumeDataPage page, int channelIndex, int lod, int dimensions, VolumeDataLayout layout) { + super(cpCreateVolumeIndexer2D(page.handle(), channelIndex, lod, dimensions, layout.handle()), 2, true); + } + + /** + * Constructor + * @param handle + */ + public VolumeIndexer2D(long handle) { + super(handle, 2, false); + } + + @Override + public int[] localIndexToVoxelIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToVoxelIndex(_handle, res, localIndex[0], localIndex[1]); + return res; + } + + @Override + public int[] localIndexToLocalChunkIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToLocalChunkIndex(_handle, res, localIndex[0], localIndex[1]); + return res; + } + + @Override + public int[] voxelIndexToLocalIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalIndex(_handle, res, voxelIndex[0], voxelIndex[1]); + return res; + } + + @Override + public int[] voxelIndexToLocalChunkIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalChunkIndex(_handle, res, voxelIndex[0], voxelIndex[1]); + return res; + } + + @Override + public int[] localChunkIndexToLocalIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToLocalIndex(_handle, res, localChunkIndex[0], localChunkIndex[1]); + return res; + } + + @Override + public int[] localChunkIndexToVoxelIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToVoxelIndex(_handle, res, localChunkIndex[0], localChunkIndex[1]); + return res; + } + + @Override + public int localIndexToDataIndex(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexToDataIndex(_handle, localIndex[0], localIndex[1]); + } + + @Override + public int voxelIndexToDataIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexToDataIndex(_handle, voxelIndex[0], voxelIndex[1]); + } + + @Override + public int localChunkIndexToDataIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexToDataIndex(_handle, localChunkIndex[0], localChunkIndex[1]); + } + + @Override + public boolean voxelIndexInProcessArea(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexInProcessArea(_handle, voxelIndex[0], voxelIndex[1]); + } + + @Override + public boolean localIndexInProcessArea(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexInProcessArea(_handle, localIndex[0], localIndex[1]); + } + + @Override + public boolean localChunkIndexInProcessArea(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexInProcessArea(_handle, localChunkIndex[0], localChunkIndex[1]); + } +} + diff --git a/java/java/src/org/opengroup/openvds/VolumeIndexer3D.java b/java/java/src/org/opengroup/openvds/VolumeIndexer3D.java new file mode 100644 index 0000000000000000000000000000000000000000..74f9d54d47dfe7564629bed7798d1f4ebf55d9c7 --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VolumeIndexer3D.java @@ -0,0 +1,144 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +public class VolumeIndexer3D extends VolumeIndexerBase { + + private static native long cpCreateVolumeIndexer3D(long pageHandle, int channelIndex, int lod, int dimensions, long layoutHandle); + + private static native void cpLocalIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k); + private static native void cpLocalIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k); + + private static native void cpVoxelIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k); + private static native void cpVoxelIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k); + + private static native void cpLocalChunkIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k); + private static native void cpLocalChunkIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k); + + private static native int cpLocalIndexToDataIndex(long handle, int i, int j, int k); + private static native int cpVoxelIndexToDataIndex(long handle, int i, int j, int k); + private static native int cpLocalChunkIndexToDataIndex(long handle, int i, int j, int k); + + private static native boolean cpVoxelIndexInProcessArea(long handle, int i, int j, int k); + private static native boolean cpLocalIndexInProcessArea(long handle, int i, int j, int k); + private static native boolean cpLocalChunkIndexInProcessArea(long handle, int i, int j, int k); + + /** + * Constructor + * @param page + * @param channelIndex + * @param lod + * @param dimensions + * @param layout + */ + public VolumeIndexer3D(VolumeDataPage page, int channelIndex, int lod, int dimensions, VolumeDataLayout layout) { + super(cpCreateVolumeIndexer3D(page.handle(), channelIndex, lod, dimensions, layout.handle()), 3, true); + } + + /** + * Constructor + * @param handle + */ + public VolumeIndexer3D(long handle) { + super(handle, 3, false); + } + + @Override + public int[] localIndexToVoxelIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToVoxelIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2]); + return res; + } + + @Override + public int[] localIndexToLocalChunkIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToLocalChunkIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2]); + return res; + } + + @Override + public int[] voxelIndexToLocalIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2]); + return res; + } + + @Override + public int[] voxelIndexToLocalChunkIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalChunkIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2]); + return res; + } + + @Override + public int[] localChunkIndexToLocalIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToLocalIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2]); + return res; + } + + @Override + public int[] localChunkIndexToVoxelIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToVoxelIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2]); + return res; + } + + @Override + public int localIndexToDataIndex(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexToDataIndex(_handle, localIndex[0], localIndex[1], localIndex[2]); + } + + @Override + public int voxelIndexToDataIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexToDataIndex(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2]); + } + + @Override + public int localChunkIndexToDataIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexToDataIndex(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2]); + } + + @Override + public boolean voxelIndexInProcessArea(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexInProcessArea(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2]); + } + + @Override + public boolean localIndexInProcessArea(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexInProcessArea(_handle, localIndex[0], localIndex[1], localIndex[2]); + } + + @Override + public boolean localChunkIndexInProcessArea(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexInProcessArea(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2]); + } +} diff --git a/java/java/src/org/opengroup/openvds/VolumeIndexer4D.java b/java/java/src/org/opengroup/openvds/VolumeIndexer4D.java new file mode 100644 index 0000000000000000000000000000000000000000..3602428c33ee6a57fbcb1412eb56136b17798bfa --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VolumeIndexer4D.java @@ -0,0 +1,144 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +public class VolumeIndexer4D extends VolumeIndexerBase { + + private static native long cpCreateVolumeIndexer4D(long pageHandle, int channelIndex, int lod, int dimensions, long layoutHandle); + + private static native void cpLocalIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k, int l); + private static native void cpLocalIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k, int l); + + private static native void cpVoxelIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k, int l); + private static native void cpVoxelIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k, int l); + + private static native void cpLocalChunkIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k, int l); + private static native void cpLocalChunkIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k, int l); + + private static native int cpLocalIndexToDataIndex(long handle, int i, int j, int k, int l); + private static native int cpVoxelIndexToDataIndex(long handle, int i, int j, int k, int l); + private static native int cpLocalChunkIndexToDataIndex(long handle, int i, int j, int k, int l); + + private static native boolean cpVoxelIndexInProcessArea(long handle, int i, int j, int k, int l); + private static native boolean cpLocalIndexInProcessArea(long handle, int i, int j, int k, int l); + private static native boolean cpLocalChunkIndexInProcessArea(long handle, int i, int j, int k, int l); + + /** + * Constructor + * @param page + * @param channelIndex + * @param lod + * @param dimensions + * @param layout + */ + public VolumeIndexer4D(VolumeDataPage page, int channelIndex, int lod, int dimensions, VolumeDataLayout layout) { + super(cpCreateVolumeIndexer4D(page.handle(), channelIndex, lod, dimensions, layout.handle()), 4, true); + } + + /** + * Constructor + * @param handle + */ + public VolumeIndexer4D(long handle) { + super(handle, 4, false); + } + + @Override + public int[] localIndexToVoxelIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToVoxelIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2], localIndex[3]); + return res; + } + + @Override + public int[] localIndexToLocalChunkIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToLocalChunkIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2], localIndex[3]); + return res; + } + + @Override + public int[] voxelIndexToLocalIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3]); + return res; + } + + @Override + public int[] voxelIndexToLocalChunkIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalChunkIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3]); + return res; + } + + @Override + public int[] localChunkIndexToLocalIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToLocalIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3]); + return res; + } + + @Override + public int[] localChunkIndexToVoxelIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToVoxelIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3]); + return res; + } + + @Override + public int localIndexToDataIndex(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexToDataIndex(_handle, localIndex[0], localIndex[1], localIndex[2], localIndex[3]); + } + + @Override + public int voxelIndexToDataIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexToDataIndex(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3]); + } + + @Override + public int localChunkIndexToDataIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexToDataIndex(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3]); + } + + @Override + public boolean voxelIndexInProcessArea(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexInProcessArea(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3]); + } + + @Override + public boolean localIndexInProcessArea(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexInProcessArea(_handle, localIndex[0], localIndex[1], localIndex[2], localIndex[3]); + } + + @Override + public boolean localChunkIndexInProcessArea(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexInProcessArea(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3]); + } +} diff --git a/java/java/src/org/opengroup/openvds/VolumeIndexer5D.java b/java/java/src/org/opengroup/openvds/VolumeIndexer5D.java new file mode 100644 index 0000000000000000000000000000000000000000..377ba2d06a5f185f91f08f9fb5a13f5836dc34e2 --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VolumeIndexer5D.java @@ -0,0 +1,144 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +public class VolumeIndexer5D extends VolumeIndexerBase { + + private static native long cpCreateVolumeIndexer5D(long pageHandle, int channelIndex, int lod, int dimensions, long layoutHandle); + + private static native void cpLocalIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k, int l, int n); + private static native void cpLocalIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k, int l, int n); + + private static native void cpVoxelIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k, int l, int n); + private static native void cpVoxelIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k, int l, int n); + + private static native void cpLocalChunkIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k, int l, int n); + private static native void cpLocalChunkIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k, int l, int n); + + private static native int cpLocalIndexToDataIndex(long handle, int i, int j, int k, int l, int n); + private static native int cpVoxelIndexToDataIndex(long handle, int i, int j, int k, int l, int n); + private static native int cpLocalChunkIndexToDataIndex(long handle, int i, int j, int k, int l, int n); + + private static native boolean cpVoxelIndexInProcessArea(long handle, int i, int j, int k, int l, int n); + private static native boolean cpLocalIndexInProcessArea(long handle, int i, int j, int k, int l, int n); + private static native boolean cpLocalChunkIndexInProcessArea(long handle, int i, int j, int k, int l, int n); + + /** + * Constructor + * @param page + * @param channelIndex + * @param lod + * @param dimensions + * @param layout + */ + public VolumeIndexer5D(VolumeDataPage page, int channelIndex, int lod, int dimensions, VolumeDataLayout layout) { + super(cpCreateVolumeIndexer5D(page.handle(), channelIndex, lod, dimensions, layout.handle()), 5, true); + } + + /** + * Constructor + * @param handle + */ + public VolumeIndexer5D(long handle) { + super(handle, 5, false); + } + + @Override + public int[] localIndexToVoxelIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToVoxelIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4]); + return res; + } + + @Override + public int[] localIndexToLocalChunkIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToLocalChunkIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4]); + return res; + } + + @Override + public int[] voxelIndexToLocalIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4]); + return res; + } + + @Override + public int[] voxelIndexToLocalChunkIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalChunkIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4]); + return res; + } + + @Override + public int[] localChunkIndexToLocalIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToLocalIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4]); + return res; + } + + @Override + public int[] localChunkIndexToVoxelIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToVoxelIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4]); + return res; + } + + @Override + public int localIndexToDataIndex(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexToDataIndex(_handle, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4]); + } + + @Override + public int voxelIndexToDataIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexToDataIndex(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4]); + } + + @Override + public int localChunkIndexToDataIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexToDataIndex(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4]); + } + + @Override + public boolean voxelIndexInProcessArea(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexInProcessArea(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4]); + } + + @Override + public boolean localIndexInProcessArea(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexInProcessArea(_handle, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4]); + } + + @Override + public boolean localChunkIndexInProcessArea(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexInProcessArea(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4]); + } +} diff --git a/java/java/src/org/opengroup/openvds/VolumeIndexer6D.java b/java/java/src/org/opengroup/openvds/VolumeIndexer6D.java new file mode 100644 index 0000000000000000000000000000000000000000..3e9b57967d4132ec51551db63526e1adff989fde --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VolumeIndexer6D.java @@ -0,0 +1,144 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +public class VolumeIndexer6D extends VolumeIndexerBase { + + private static native long cpCreateVolumeIndexer6D(long pageHandle, int channelIndex, int lod, int dimensions, long layoutHandle); + + private static native void cpLocalIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k, int l, int m, int n); + private static native void cpLocalIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k, int l, int m, int n); + + private static native void cpVoxelIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k, int l, int m, int n); + private static native void cpVoxelIndexToLocalChunkIndex(long handle, int[] localChunkIndexRes, int i, int j, int k, int l, int m, int n); + + private static native void cpLocalChunkIndexToLocalIndex(long handle, int[] localIndexRes, int i, int j, int k, int l, int m, int n); + private static native void cpLocalChunkIndexToVoxelIndex(long handle, int[] voxelIndexRes, int i, int j, int k, int l, int m, int n); + + private static native int cpLocalIndexToDataIndex(long handle, int i, int j, int k, int l, int m, int n); + private static native int cpVoxelIndexToDataIndex(long handle, int i, int j, int k, int l, int m, int n); + private static native int cpLocalChunkIndexToDataIndex(long handle, int i, int j, int k, int l, int m, int n); + + private static native boolean cpVoxelIndexInProcessArea(long handle, int i, int j, int k, int l, int m, int n); + private static native boolean cpLocalIndexInProcessArea(long handle, int i, int j, int k, int l, int m, int n); + private static native boolean cpLocalChunkIndexInProcessArea(long handle, int i, int j, int k, int l, int m, int n); + + /** + * Constructor + * @param page + * @param channelIndex + * @param lod + * @param dimensions + * @param layout + */ + public VolumeIndexer6D(VolumeDataPage page, int channelIndex, int lod, int dimensions, VolumeDataLayout layout) { + super(cpCreateVolumeIndexer6D(page.handle(), channelIndex, lod, dimensions, layout.handle()), 6, true); + } + + /** + * Constructor + * @param handle + */ + public VolumeIndexer6D(long handle) { + super(handle, 6, false); + } + + @Override + public int[] localIndexToVoxelIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToVoxelIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4], localIndex[5]); + return res; + } + + @Override + public int[] localIndexToLocalChunkIndex(int[] localIndex) { + checkIndexArgument(localIndex); + int[] res = new int[localIndex.length]; + cpLocalIndexToLocalChunkIndex(_handle, res, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4], localIndex[5]); + return res; + } + + @Override + public int[] voxelIndexToLocalIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4], voxelIndex[5]); + return res; + } + + @Override + public int[] voxelIndexToLocalChunkIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + int[] res = new int[voxelIndex.length]; + cpVoxelIndexToLocalChunkIndex(_handle, res, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4], voxelIndex[5]); + return res; + } + + @Override + public int[] localChunkIndexToLocalIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToLocalIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4], localChunkIndex[5]); + return res; + } + + @Override + public int[] localChunkIndexToVoxelIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + int[] res = new int[localChunkIndex.length]; + cpLocalChunkIndexToVoxelIndex(_handle, res, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4], localChunkIndex[5]); + return res; + } + + @Override + public int localIndexToDataIndex(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexToDataIndex(_handle, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4], localIndex[5]); + } + + @Override + public int voxelIndexToDataIndex(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexToDataIndex(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4], voxelIndex[5]); + } + + @Override + public int localChunkIndexToDataIndex(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexToDataIndex(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4], localChunkIndex[5]); + } + + @Override + public boolean voxelIndexInProcessArea(int[] voxelIndex) { + checkIndexArgument(voxelIndex); + return cpVoxelIndexInProcessArea(_handle, voxelIndex[0], voxelIndex[1], voxelIndex[2], voxelIndex[3], voxelIndex[4], voxelIndex[5]); + } + + @Override + public boolean localIndexInProcessArea(int[] localIndex) { + checkIndexArgument(localIndex); + return cpLocalIndexInProcessArea(_handle, localIndex[0], localIndex[1], localIndex[2], localIndex[3], localIndex[4], localIndex[5]); + } + + @Override + public boolean localChunkIndexInProcessArea(int[] localChunkIndex) { + checkIndexArgument(localChunkIndex); + return cpLocalChunkIndexInProcessArea(_handle, localChunkIndex[0], localChunkIndex[1], localChunkIndex[2], localChunkIndex[3], localChunkIndex[4], localChunkIndex[5]); + } +} diff --git a/java/java/src/org/opengroup/openvds/VolumeIndexerBase.java b/java/java/src/org/opengroup/openvds/VolumeIndexerBase.java new file mode 100644 index 0000000000000000000000000000000000000000..535e6b67b2b5903b006c9cf1cd285c80db75c782 --- /dev/null +++ b/java/java/src/org/opengroup/openvds/VolumeIndexerBase.java @@ -0,0 +1,159 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +public abstract class VolumeIndexerBase extends JniPointer { + + private static native void cpDeleteHandle(long handle, int volumeDimension); + private static native float cpGetValueRangeMin(long handle, int volumeDimension); + private static native float cpGetValueRangeMax(long handle, int volumeDimension); + + private static native int cpGetDataBlockNumSamples(long handle, int volumeDimension, int dim); + private static native int cpGetLocalChunkNumSamples(long handle, int volumeDimension, int dim); + + protected final int dimensionVolume; + + public VolumeIndexerBase(long handle, int dimension, boolean ownHandle) { + super(handle, ownHandle); + this.dimensionVolume = dimension; + } + + protected int getVolumeDimension() { + return dimensionVolume; + } + + @Override + protected void deleteHandle() { + cpDeleteHandle(_handle, dimensionVolume); + } + + public float getValueRangeMin() { + return cpGetValueRangeMin(_handle, dimensionVolume); + } + + public float getValueRangeMax() { + return cpGetValueRangeMax(_handle, dimensionVolume); + } + + /** + * Gets the number of samples for a dimension in the DataBlock + * @param dimension the volume dimension + * @return the number of samples in the dimension + */ + public int getDataBlockNumSamples(int dimension) { + return cpGetDataBlockNumSamples(_handle, dimensionVolume, dimension); + } + + /** + * Get the number of samples for a dimension in the volume + * @param dimension the volume dimension + * @return the number of samples in the dimension + */ + public int getLocalChunkNumSamples(int dimension) { return cpGetLocalChunkNumSamples(_handle, dimensionVolume, dimension); }; + + /** + * Converts a local index to a voxel index + * @param localIndex the local index to convert + * @return the voxel index + */ + public abstract int[] localIndexToVoxelIndex(int[] localIndex); + + /** + * Converts a local index to a local chunk index + * @param localIndex the local index to convert + * @return the local chunk index + */ + public abstract int[] localIndexToLocalChunkIndex(int[] localIndex); + + /** + * Converts a voxel index to a local index + * @param voxelIndex the voxel index to convert + * @return the local index + */ + public abstract int[] voxelIndexToLocalIndex(int[] voxelIndex); + + /** + * Converts a voxel index to a local chunk index + * @param voxelIndex the voxel index to convert + * @return the local index + */ + public abstract int[] voxelIndexToLocalChunkIndex(int[] voxelIndex); + + /** + * Converts a local chunk index to a local index + * @param localChunkIndex the local chunk index to convert + * @return the local index + */ + public abstract int[] localChunkIndexToLocalIndex(int[] localChunkIndex); + + /** + * Converts a local chunk index to a voxel index + * @param localChunkIndex + * @return the local voxel index + */ + public abstract int[] localChunkIndexToVoxelIndex(int[] localChunkIndex); + + /** + * Converts a local index to a data index + * @param localIndex the local index to convert + * @return the buffer offset (position) for the local index + */ + public abstract int localIndexToDataIndex(int[] localIndex); + + /** + * Converts a voxel index to a data index + * @param voxelIndex the voxel index to convert + * @return the buffer offset for the voxel index + */ + public abstract int voxelIndexToDataIndex(int[] voxelIndex); + + /** + * Converts a voxel index to a data index + * @param localChunkIndex the local chunk index to convert + * @return the buffer offset for the local chunk index + */ + public abstract int localChunkIndexToDataIndex(int[] localChunkIndex); + + /** + * Checks if a voxel index is within the chunk this indexer was created with + * @param voxelIndex the voxel index to check + * @return true if the index is within this chunk, false otherwise + */ + public abstract boolean voxelIndexInProcessArea(int[] voxelIndex); + + /** + * Checks if a local index is within the chunk this indexer was created with + * @param localIndex the local index to check + * @return true if the index is within this chunk, false otherwise + */ + public abstract boolean localIndexInProcessArea(int[] localIndex); + + /** + * Checks if a local chunk index is within the chunk this indexer was created with + * @param localChunkIndex the local chunk index to check + * @return true if the index is within this chunk, false otherwise + */ + public abstract boolean localChunkIndexInProcessArea(int[] localChunkIndex); + + + protected void checkIndexArgument(int[] localIndex) { + if (localIndex == null || localIndex.length != dimensionVolume) { + throw new IllegalArgumentException("Local index size must match indexer dimension. Expected " + dimensionVolume + ", got " + (localIndex != null ? localIndex.length : "null")); + } + } +} diff --git a/java/java/test/org/opengroup/openvds/CreateVDSTest.java b/java/java/test/org/opengroup/openvds/CreateVDSTest.java index 559ad0b8a17875b3a46bef61d6eb876ec7b73aee..f37460cb7e395b1e139722500f5e6f58036ab319 100644 --- a/java/java/test/org/opengroup/openvds/CreateVDSTest.java +++ b/java/java/test/org/opengroup/openvds/CreateVDSTest.java @@ -69,6 +69,7 @@ public class CreateVDSTest { } } + @Test(expectedExceptions = IllegalArgumentException.class) public void testException1() { try { diff --git a/java/java/test/org/opengroup/openvds/MetaDataContainerTest.java b/java/java/test/org/opengroup/openvds/MetaDataContainerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..79b5d4ca9dc658bf41cd5a7f5814f76e5b5a5396 --- /dev/null +++ b/java/java/test/org/opengroup/openvds/MetaDataContainerTest.java @@ -0,0 +1,311 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.io.File; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.fail; + +public class MetaDataContainerTest { + + private static String TEMP_FILE_NAME = "vdsTestMetadata.vds"; + + public String url; + public VolumeDataLayoutDescriptor ld; + public VolumeDataAxisDescriptor[] vda; + public VolumeDataChannelDescriptor[] vdc; + public MetadataReadAccess md; + public MemoryVdsGenerator vds; + + @BeforeClass + public void init() { + vds = new MemoryVdsGenerator(16, 16, 16, VolumeDataChannelDescriptor.Format.FORMAT_U8); + url = "inmemory://create_test"; + VolumeDataLayout volumeDataLayout = vds.getLayout(); + + int nbChannel = volumeDataLayout.getChannelCount(); + VolumeDataAccessManager accessManager = vds.getAccessManager(); + + for (VolumeDataLayoutDescriptor.LODLevels l : VolumeDataLayoutDescriptor.LODLevels.values()) { + for (int channel = 0; channel < nbChannel; channel++) { + for (DimensionsND dimGroup : DimensionsND.values()) { + VDSProduceStatus vdsProduceStatus = accessManager.getVDSProduceStatus(dimGroup, l.ordinal(), channel); + } + } + } + + vda = new VolumeDataAxisDescriptor[] {volumeDataLayout.getAxisDescriptor(0), + volumeDataLayout.getAxisDescriptor(1), + volumeDataLayout.getAxisDescriptor(2)}; + vdc = new VolumeDataChannelDescriptor[] {volumeDataLayout.getChannelDescriptor(0)}; + + md = volumeDataLayout; + ld = volumeDataLayout.getLayoutDescriptor(); + } + + @AfterClass + public void cleanTempFile() { + String tempDir = System.getProperty("java.io.tmpdir"); + String tempFilePath = tempDir + File.separator + TEMP_FILE_NAME; + File fileTemp = new File(tempFilePath); + if (fileTemp.exists()) { + fileTemp.delete(); + } + } + + @Test + void testMetadataContainer() { + // creates object + MetadataContainer container = new MetadataContainer(); + + // set values + int singleInt = 1337; + container.setMetadataInt("CategoryInt", "intMetaData", singleInt); + + // get values + int readSingleInt = container.getMetadataInt("CategoryInt", "intMetaData"); + + // check equality + assertEquals(singleInt, readSingleInt); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckIntV2() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataIntVector2("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckIntV3() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataIntVector3("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckIntV4() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataIntVector4("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckFloatV2() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataFloatVector2("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckFloatV3() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataFloatVector3("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckFloatV4() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataFloatVector4("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckDoubleV2() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataDoubleVector2("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckDoubleV3() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataDoubleVector3("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullCheckDoubleV4() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataDoubleVector4("categoryArray", "nullArray", null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckIntV2() { + int[] vec3i = new int[] {54, 76, 99}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataIntVector2("categoryInt", "IntV2", vec3i); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckIntV3() { + int[] vec2i = new int[] {54, 76}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataIntVector3("categoryInt", "IntV3", vec2i); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckIntV4() { + int[] vec2i = new int[] {54, 76}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataIntVector4("categoryInt", "IntV3", vec2i); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckFloatV2() { + float[] vec3f = new float[] {54f, 76f, 99f}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataFloatVector2("categoryFloat", "FloatV2", vec3f); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckFloatV3() { + float[] vec2f = new float[] {54f, 76f}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataFloatVector3("categoryFloat", "FloatV3", vec2f); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckFloatV4() { + float[] vec5f = new float[] {54f, 76f, 55f, 50f, 88f}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataFloatVector4("categoryFloat", "FloatV4", vec5f); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckDoubleV2() { + double[] vec3d = new double[] {54d, 76d, 99d}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataDoubleVector2("categoryDouble", "DoubleV2", vec3d); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckDoubleV3() { + double[] vec2f = new double[] {54d, 76d}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataDoubleVector3("categoryDouble", "DoubleV3", vec2f); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testSizeCheckDoubleV4() { + double[] vec5d = new double[] {54d, 76d, 55d, 50d, 88d}; + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataDoubleVector4("categoryDouble", "DoubleV4", vec5d); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testNullMetadataString() { + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataString("categoryString", "nullMetaData", null); + } + + @Test + public void testCreateVDSWithMetaData() { + try { + int i1 = 1337; + int[] vec2i = new int[] {54, 76}; + int[] vec3i = new int[] {33, 66, 99}; + int[] vec4i = new int[] {11, 22, 44, 88}; + + float f1 = 13.37f; + float[] vec2f = new float[] {54.4f, 76.5f}; + float[] vec3f = new float[] {33.3f, 66.6f, 99.9f}; + float[] vec4f = new float[] {11.1f, 22.2f, 44.4f, 88.8f}; + + double d1 = 26.74d; + double[] vec2d = new double[] {54.45d, 76.67d}; + double[] vec3d = new double[] {33.33d, 666.666d, 999.999d}; + double[] vec4d = new double[] {11.11d, 22.222d, 44.4444d, 88.88888d}; + + String mdString = "Char sequence metadata"; + + MetadataContainer metaData = new MetadataContainer(); + metaData.setMetadataInt("categoryInt", "singleInt", i1); + metaData.setMetadataIntVector2("categoryInt", "IntV2", vec2i); + metaData.setMetadataIntVector3("categoryInt", "IntV3", vec3i); + metaData.setMetadataIntVector4("categoryInt", "IntV4", vec4i); + + metaData.setMetadataFloat("categoryFloat", "singleFloat", f1); + metaData.setMetadataFloatVector2("categoryFloat", "FloatV2", vec2f); + metaData.setMetadataFloatVector3("categoryFloat", "FloatV3", vec3f); + metaData.setMetadataFloatVector4("categoryFloat", "FloatV4", vec4f); + + metaData.setMetadataDouble("categoryDouble", "singleDouble", d1); + metaData.setMetadataDoubleVector2("categoryDouble", "DoubleV2", vec2d); + metaData.setMetadataDoubleVector3("categoryDouble", "DoubleV3", vec3d); + metaData.setMetadataDoubleVector4("categoryDouble", "DoubleV4", vec4d); + + metaData.setMetadataString("categoryString", "String", mdString); + + // create file in tmp dir + String tempDir = System.getProperty("java.io.tmpdir"); + String tempFilePath = tempDir + File.separator + TEMP_FILE_NAME; + + VDSFileOpenOptions options = new VDSFileOpenOptions(tempFilePath); + VdsError vdsError = new VdsError(); + OpenVDS createdVDS = OpenVDS.create(options, ld, vda, vdc, metaData); + + // test meta data + // int + int mdInt = createdVDS.getLayout().getMetadataInt("categoryInt", "singleInt"); + assertEquals(mdInt, i1); + + int[] mdIntVector2 = createdVDS.getLayout().getMetadataIntVector2("categoryInt", "IntV2"); + assertEquals(vec2i, mdIntVector2); + + int[] mdIntVector3 = createdVDS.getLayout().getMetadataIntVector3("categoryInt", "IntV3"); + assertEquals(vec3i, mdIntVector3); + + int[] mdIntVector4 = createdVDS.getLayout().getMetadataIntVector4("categoryInt", "IntV4"); + assertEquals(vec4i, mdIntVector4); + + // float + float mdFloat = createdVDS.getLayout().getMetadataFloat("categoryFloat", "singleFloat"); + assertEquals(mdFloat, f1); + + float[] mdFloatVector2 = createdVDS.getLayout().getMetadataFloatVector2("categoryFloat", "FloatV2"); + assertEquals(vec2f, mdFloatVector2); + + float[] mdFloatVector3 = createdVDS.getLayout().getMetadataFloatVector3("categoryFloat", "FloatV3"); + assertEquals(vec3f, mdFloatVector3); + + float[] mdFloatVector4 = createdVDS.getLayout().getMetadataFloatVector4("categoryFloat", "FloatV4"); + assertEquals(vec4f, mdFloatVector4); + + // double + double mdDouble = createdVDS.getLayout().getMetadataDouble("categoryDouble", "singleDouble"); + assertEquals(mdDouble, d1); + + double[] mdDoubleVector2 = createdVDS.getLayout().getMetadataDoubleVector2("categoryDouble", "DoubleV2"); + assertEquals(vec2d, mdDoubleVector2); + + double[] mdDoubleVector3 = createdVDS.getLayout().getMetadataDoubleVector3("categoryDouble", "DoubleV3"); + assertEquals(vec3d, mdDoubleVector3); + + double[] mdDoubleVector4 = createdVDS.getLayout().getMetadataDoubleVector4("categoryDouble", "DoubleV4"); + assertEquals(vec4d, mdDoubleVector4); + + // String + String mdS = createdVDS.getLayout().getMetadataString("categoryString", "String"); + assertEquals(mdS, mdString); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + +} diff --git a/java/java/test/org/opengroup/openvds/PageAccessorTest.java b/java/java/test/org/opengroup/openvds/PageAccessorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..42962694be1c9425f17b62a83e31fb7e92bd5ecd --- /dev/null +++ b/java/java/test/org/opengroup/openvds/PageAccessorTest.java @@ -0,0 +1,305 @@ +/* + * Copyright 2021 The Open Group + * Copyright 2021 INT, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.opengroup.openvds; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +import java.io.File; + +import static org.testng.Assert.fail; + +public class PageAccessorTest { + + private static String TEMP_FILE_NAME_VOL_INDEX = "volIndexer.vds"; + private static String TEMP_FILE_NAME_COPY = "vdsCopy.vds"; + + public String url; + public VolumeDataLayoutDescriptor ld; + public VolumeDataAxisDescriptor[] vda; + public VolumeDataChannelDescriptor[] vdc; + public MetadataReadAccess md; + public MemoryVdsGenerator vds; + public MetadataContainer metadataContainer; + + @BeforeClass + public void init() { + vds = new MemoryVdsGenerator(200, 300, 300, VolumeDataChannelDescriptor.Format.FORMAT_R32); + url = "inmemory://create_test"; + VolumeDataLayout volumeDataLayout = vds.getLayout(); + + int nbChannel = volumeDataLayout.getChannelCount(); + VolumeDataAccessManager accessManager = vds.getAccessManager(); + + for (VolumeDataLayoutDescriptor.LODLevels l : VolumeDataLayoutDescriptor.LODLevels.values()) { + for (int channel = 0; channel < nbChannel; channel++) { + for (DimensionsND dimGroup : DimensionsND.values()) { + VDSProduceStatus vdsProduceStatus = accessManager.getVDSProduceStatus(dimGroup, l.ordinal(), channel); + } + } + } + + vda = new VolumeDataAxisDescriptor[] { + volumeDataLayout.getAxisDescriptor(0), + volumeDataLayout.getAxisDescriptor(1), + volumeDataLayout.getAxisDescriptor(2)}; + vdc = new VolumeDataChannelDescriptor[] {volumeDataLayout.getChannelDescriptor(0)}; + + md = volumeDataLayout; + ld = volumeDataLayout.getLayoutDescriptor(); + + metadataContainer = new MetadataContainer(); + metadataContainer.setMetadataInt("categoryInt", "Int", 123); + metadataContainer.setMetadataIntVector2("categoryInt", "IntVector2", new int[] {45, 78}); + metadataContainer.setMetadataIntVector3("categoryInt", "IntVector3", new int[] {45, 78, 72}); + metadataContainer.setMetadataIntVector4("categoryInt", "IntVector4", new int[] {45, 78, 72, 84}); + metadataContainer.setMetadataFloat("categoryFloat", "Float", 123.f); + metadataContainer.setMetadataFloatVector2("categoryFloat", "FloatVector2", new float[] {45.5f, 78.75f}); + metadataContainer.setMetadataFloatVector3("categoryFloat", "FloatVector3", new float[] {45.5f, 78.75f, 72.75f}); + metadataContainer.setMetadataFloatVector4("categoryFloat", "FloatVector4", new float[] {45.5f, 78.75f, 72.75f, 84.1f}); + metadataContainer.setMetadataDouble("categoryDouble", "Double", 123.); + metadataContainer.setMetadataDoubleVector2("categoryDouble", "DoubleVector2", new double[] {45.5, 78.75}); + metadataContainer.setMetadataDoubleVector3("categoryDouble", "DoubleVector3", new double[] {45.5, 78.75, 72.75}); + metadataContainer.setMetadataDoubleVector4("categoryDouble", "DoubleVector4", new double[] {45.5, 78.75, 72.75, 84.1}); + metadataContainer.setMetadataString("categoryString", "String", "Test string"); + //metadataContainer.SetMetadataBLOB("categoryBLOB", "BLOB", data, 4 ); + } + + @AfterClass + public void cleanFiles() { + String tempDir = System.getProperty("java.io.tmpdir"); + String fileVolIndexPath = tempDir + File.separator + TEMP_FILE_NAME_VOL_INDEX; + File fileVolIndex = new File(fileVolIndexPath); + if (fileVolIndex.exists()) { + fileVolIndex.delete(); + } + + String fileCopyPath = tempDir + File.separator + TEMP_FILE_NAME_COPY; + File fileCopy = new File(fileCopyPath); + if (fileCopy.exists()) { + fileCopy.delete(); + } + } + + @Test + public void testVolumeIndexerCreationDeletion() { + try { + // create file in tmp dir + String tmpDir = System.getProperty("java.io.tmpdir"); + String volIndexPath = tmpDir + File.separator + TEMP_FILE_NAME_VOL_INDEX; + VDSFileOpenOptions options = new VDSFileOpenOptions(volIndexPath); + VdsHandle vdsTest = OpenVDS.create(options, ld, + vda, + vdc, metadataContainer); + VolumeDataAccessManager accessManager = vdsTest.getAccessManager(); + //ASSERT_TRUE(accessManager); + + int channel = 0; + VolumeDataLayout layout = vdsTest.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 100, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + VolumeDataPage page = pageAccessor.createPage(0); + VolumeIndexer3D outputIndexer = new VolumeIndexer3D(page, 0, 0, DimensionsND.DIMENSIONS_012.ordinal(), layout); + outputIndexer.finalize(); + + vdsTest.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + @Test + public void testCopyPageAccessor() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + TEMP_FILE_NAME_COPY; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + VdsHandle vdsCopy = OpenVDS.create(options, ld, + vda, + vdc, metadataContainer); + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + //ASSERT_TRUE(accessManager); + + int channel = 0; + VolumeDataLayout layout = vdsCopy.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.Create.getCode()); // access mode + + // get input manager + VolumeDataAccessManager inputAM = vds.getAccessManager(); + VolumeDataPageAccessor pageAccessorInput = inputAM.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // copy file + int[] pitch = new int[VolumeDataLayout.Dimensionality_Max]; + long chunkCount = pageAccessorInput.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessorInput.readPage(chunk); + VolumeDataPage page = pageAccessor.createPage(chunk); + float[] data = inputPage.readFloatBuffer(pitch); + page.writeFloatBuffer(data, pitch); + + inputPage.pageRelease(); + page.pageRelease(); + } + + pageAccessor.commit(); + pageAccessor.setMaxPages(0); + accessManager.flushUploadQueue(); + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + /** + * Will test that copied file is the same as the input + * Name of method is the same + Suffix so that it's executed after the copy test + */ + @Test + public void testCopyPageAccessorValidation() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + TEMP_FILE_NAME_COPY; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + VdsHandle vdsCopy = OpenVDS.open(options); + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + + int channel = 0; + VolumeDataLayout layout = vdsCopy.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // get input manager + VolumeDataAccessManager inputAM = vds.getAccessManager(); + VolumeDataPageAccessor pageAccessorInput = inputAM.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // compares block data + int[] pitchInput = new int[VolumeDataLayout.Dimensionality_Max]; + int[] pitchOutput = new int[VolumeDataLayout.Dimensionality_Max]; + + long chunkCount = pageAccessorInput.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessorInput.readPage(chunk); + VolumeDataPage page = pageAccessor.readPage(chunk); + float[] dataIn = inputPage.readFloatBuffer(pitchInput); + float[] dataOut = page.readFloatBuffer(pitchOutput); + + Assert.assertEquals(pitchInput, pitchOutput); + Assert.assertEquals(dataIn, dataOut); + + inputPage.pageRelease(); + page.pageRelease(); + } + + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } + } + + /** + * Will test that copied file has the same layout than original (test that 3D positions are in the same chunk index) + * Name of method is the same + Suffix so that it's executed after the copy test + */ + @Test + public void testCopyPageAccessorValidationChunkIndex() { + try { + String tmpDir = System.getProperty("java.io.tmpdir"); + String vdsPath = tmpDir + File.separator + TEMP_FILE_NAME_COPY; + VDSFileOpenOptions options = new VDSFileOpenOptions(vdsPath); + VdsHandle vdsCopy = OpenVDS.open(options); + VolumeDataAccessManager accessManager = vdsCopy.getAccessManager(); + + int channel = 0; + VolumeDataLayout layout = vdsCopy.getLayout(); + VolumeDataPageAccessor pageAccessor = accessManager.createVolumeDataPageAccessor( + DimensionsND.DIMENSIONS_012.ordinal(), // dimension ND + 0, // lod + channel, // channel + 20, // max pages + VolumeDataPageAccessor.AccessMode.ReadOnly.getCode()); // access mode + + // compares block data + int[] chunkMin = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMax = new int[VolumeDataLayout.Dimensionality_Max]; + int[] chunkMaxPos = new int[VolumeDataLayout.Dimensionality_Max]; + + long chunkCount = pageAccessor.getChunkCount(); + for (long chunk = 0 ; chunk < chunkCount ; ++chunk) { + VolumeDataPage inputPage = pageAccessor.readPage(chunk); + + // check that chunk index matches current index + inputPage.getMinMaxExcludingMargin(chunkMin, chunkMax); + for (int i = 0 ; i < VolumeDataLayout.Dimensionality_Max ; ++i) { + chunkMaxPos[i] = chunkMax[i] != 0 ? chunkMax[i] - 1 : chunkMax[i]; + } + long idxChMin = pageAccessor.getChunkIndex(chunkMin); + long idxChMax = pageAccessor.getChunkIndex(chunkMaxPos); + + Assert.assertEquals(chunk, idxChMin); + Assert.assertEquals(idxChMin, idxChMax); + + inputPage.pageRelease(); + } + + accessManager.destroyVolumeDataPageAccessor(pageAccessor); + + vdsCopy.close(); + } + catch (java.io.IOException e) { + System.out.println(e.getMessage()); + fail(); + } +} +} diff --git a/java/java/test/org/opengroup/openvds/VdsErrorTest.java b/java/java/test/org/opengroup/openvds/VdsErrorTest.java new file mode 100644 index 0000000000000000000000000000000000000000..441e89700aa6d9090613c8593af1d52eebb48329 --- /dev/null +++ b/java/java/test/org/opengroup/openvds/VdsErrorTest.java @@ -0,0 +1,25 @@ +package org.opengroup.openvds; + +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + +public class VdsErrorTest { + + @Test + void testVdsError() { + VdsError error = new VdsError(); + + int code = 43; + String errorMessage = "Error message for error 43"; + + error.setErrorCode(code); + error.setMessage(errorMessage); + + int resCode = error.getErrorCode(); + String resMsg = error.getMessage(); + + assertEquals(resCode, code); + assertEquals(resMsg, errorMessage); + } +} diff --git a/src/OpenVDS/OpenVDS/VolumeDataAccess.h b/src/OpenVDS/OpenVDS/VolumeDataAccess.h index 3afa0c1d608a8a8ed226abd8e90ea56820bfea5c..048f7364d0d49c37908912569df3bc7e51722e9a 100644 --- a/src/OpenVDS/OpenVDS/VolumeDataAccess.h +++ b/src/OpenVDS/OpenVDS/VolumeDataAccess.h @@ -63,7 +63,7 @@ public: virtual ~Manager() {} public: virtual void DestroyVolumeDataAccessor(IVolumeDataAccessor *accessor) = 0; - + virtual IVolumeDataAccessor * CloneVolumeDataAccessor(IVolumeDataAccessor const &accessor) = 0; }; @@ -122,7 +122,7 @@ public: struct Error { const char *message; - int errorCode; + int errorCode; }; protected: VolumeDataPage() {} diff --git a/tools/ScratchVDSFileCreate/CMakeLists.txt b/tools/ScratchVDSFileCreate/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9f1d3f96773297084cba357021e9e58ab6dac1b6 --- /dev/null +++ b/tools/ScratchVDSFileCreate/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(VDSFileCreate + VDSFileCreate.cpp + ) + +target_link_libraries(VDSFileCreate PRIVATE Threads::Threads openvds segyutils jsoncpp_lib_static fmt::fmt) + +setCompilerFlagsForTools(VDSFileCreate) diff --git a/tools/ScratchVDSFileCreate/VDSFileCreate.cpp b/tools/ScratchVDSFileCreate/VDSFileCreate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..46b198d114360089afda6dae25d52150a2725a72 --- /dev/null +++ b/tools/ScratchVDSFileCreate/VDSFileCreate.cpp @@ -0,0 +1,395 @@ +/**************************************************************************** +** Copyright 2019 The Open Group +** Copyright 2019 Bluware, Inc. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +****************************************************************************/ + +#define _CRT_SECURE_NO_WARNINGS 1 + +#include +#include "IO/File.h" +#include "VDS/Hash.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "cxxopts.hpp" +#include +#include + +#include + +#if defined(WIN32) +#undef WIN32_LEAN_AND_MEAN // avoid warnings if defined on command line +#define WIN32_LEAN_AND_MEAN 1 +#define NOMINMAX 1 +#include +#include + +int64_t GetTotalSystemMemory() +{ + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + return int64_t(status.ullTotalPhys); +} + +#else + +#include +#include +#include + + +void createNoLODVDS(const std::string &vdsFileName, int32_t samplesX, int32_t samplesY, int32_t samplesZ); +void createLODVDS(const std::string &vdsFileName, int32_t samplesX, int32_t samplesY, int32_t samplesZ, OpenVDS::VolumeDataLayoutDescriptor::LODLevels); +double distance2D(double x1, double y1, double x2, double y2); +double distance3D(double x1, double y1, double x2, double y2, double x3, double y3); + +int64_t GetTotalSystemMemory() { + long pages = sysconf(_SC_PHYS_PAGES); + long page_size = sysconf(_SC_PAGE_SIZE); + return int64_t(pages) * int64_t(page_size); +} + +#endif + +static void +getScaleOffsetForFormat(float min, float max, bool novalue, OpenVDS::VolumeDataChannelDescriptor::Format format, + float &scale, float &offset) { + switch (format) { + case OpenVDS::VolumeDataChannelDescriptor::Format_U8: + scale = 1.f / (255.f - novalue) * (max - min); + offset = min; + break; + case OpenVDS::VolumeDataChannelDescriptor::Format_U16: + scale = 1.f / (65535.f - novalue) * (max - min); + offset = min; + break; + case OpenVDS::VolumeDataChannelDescriptor::Format_R32: + case OpenVDS::VolumeDataChannelDescriptor::Format_U32: + case OpenVDS::VolumeDataChannelDescriptor::Format_R64: + case OpenVDS::VolumeDataChannelDescriptor::Format_U64: + case OpenVDS::VolumeDataChannelDescriptor::Format_1Bit: + case OpenVDS::VolumeDataChannelDescriptor::Format_Any: + scale = 1.0f; + offset = 0.0f; + } +} + +int +main(int argc, char *argv[]) { + cxxopts::Options options("VDSFileCreate", "Create synthetic vds file"); + std::string vdsFileName; + options.add_option("", "", "vdsfile", "Output VDS file name.", cxxopts::value(vdsFileName), ""); + + if (argc == 1) { + std::cout << options.help(); + return EXIT_SUCCESS; + } + + try { + options.parse(argc, argv); + } + catch(cxxopts::OptionParseException &e) { + fmt::print(stderr, "{}", e.what()); + return EXIT_FAILURE; + } + + int32_t samplesX = 500; + int32_t samplesY = 800; + int32_t samplesZ = 800; + + std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); + + createNoLODVDS(vdsFileName, samplesX, samplesY, samplesZ); + //createLODVDS(vdsFileName, samplesX, samplesY, samplesZ, OpenVDS::VolumeDataLayoutDescriptor::LODLevels_3); + + std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); + long elapsed = std::chrono::duration_cast(end - begin).count(); + long hrs = elapsed / (60 * 60 * 1000); + long min = (elapsed - (hrs * 60 * 60 * 1000)) / (60 * 1000); + long s = (elapsed - (hrs * 60 * 1000) - (min * 60 * 1000)) / 1000; + std::cout << "Write VDS TIME [CPP native] : " << hrs << " hrs " << min << " min " << s << "s (" << elapsed << " ms)" << std::endl; + return EXIT_SUCCESS; +} + +void createNoLODVDS(const std::string &vdsFileName, int32_t samplesX, int32_t samplesY, int32_t samplesZ) { + OpenVDS::VolumeDataChannelDescriptor::Format format = OpenVDS::VolumeDataChannelDescriptor::Format_R32; + + auto brickSize = OpenVDS::VolumeDataLayoutDescriptor::BrickSize_64; + int negativeMargin = 4; + int positiveMargin = 4; + int brickSize2DMultiplier = 4; + auto lodLevels = OpenVDS::VolumeDataLayoutDescriptor::LODLevels_None; + auto layoutOptions = OpenVDS::VolumeDataLayoutDescriptor::Options_None; + OpenVDS::VolumeDataLayoutDescriptor layoutDescriptor(brickSize, negativeMargin, positiveMargin, + brickSize2DMultiplier, lodLevels, layoutOptions); + + std::vector axisDescriptors; + axisDescriptors.emplace_back(samplesX, "Sample", "ms", 0.0f,4.f); + axisDescriptors.emplace_back(samplesY, "Crossline", "",1932.f, 1932.f + samplesY - 1.f); + axisDescriptors.emplace_back(samplesZ, "Inline", "", 9985.f, 9985.f + samplesZ - 1.f); + + std::vector channelDescriptors; + float rangeMin = -1.f; + float rangeMax = 1.f; + float intScale; + float intOffset; + getScaleOffsetForFormat(rangeMin, rangeMax, true, format, intScale, intOffset); + channelDescriptors.emplace_back(format, OpenVDS::VolumeDataChannelDescriptor::Components_1, + AMPLITUDE_ATTRIBUTE_NAME, "", rangeMin, rangeMax, + OpenVDS::VolumeDataMapping::Direct, 1, + OpenVDS::VolumeDataChannelDescriptor::Default, -999.25f, intScale, intOffset); + + //OpenVDS::InMemoryOpenOptions options; + OpenVDS::VDSFileOpenOptions options(vdsFileName); + OpenVDS::Error error; + + OpenVDS::MetadataContainer metadataContainer; + metadataContainer.SetMetadataInt("categoryInt", "Int", 123); + metadataContainer.SetMetadataIntVector2("categoryInt", "IntVector2", OpenVDS::IntVector2(45, 78)); + metadataContainer.SetMetadataIntVector3("categoryInt", "IntVector3", OpenVDS::IntVector3(45, 78, 72)); + metadataContainer.SetMetadataIntVector4("categoryInt", "IntVector4", OpenVDS::IntVector4(45, 78, 72, 84)); + metadataContainer.SetMetadataFloat("categoryFloat", "Float", 123.f); + metadataContainer.SetMetadataFloatVector2("categoryFloat", "FloatVector2", OpenVDS::FloatVector2(45.5f, 78.75f)); + metadataContainer.SetMetadataFloatVector3("categoryFloat", "FloatVector3", + OpenVDS::FloatVector3(45.5f, 78.75f, 72.75f)); + metadataContainer.SetMetadataFloatVector4("categoryFloat", "FloatVector4", + OpenVDS::FloatVector4(45.5f, 78.75f, 72.75f, 84.1f)); + metadataContainer.SetMetadataDouble("categoryDouble", "Double", 123.); + metadataContainer.SetMetadataDoubleVector2("categoryDouble", "DoubleVector2", OpenVDS::DoubleVector2(45.5, 78.75)); + metadataContainer.SetMetadataDoubleVector3("categoryDouble", "DoubleVector3", + OpenVDS::DoubleVector3(45.5, 78.75, 72.75)); + metadataContainer.SetMetadataDoubleVector4("categoryDouble", "DoubleVector4", + OpenVDS::DoubleVector4(45.5, 78.75, 72.75, 84.1)); + metadataContainer.SetMetadataString("categoryString", "String", std::string("Test string")); + + auto vds = OpenVDS::Create(options, layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, + error); + + OpenVDS::VolumeDataLayout *layout = OpenVDS::GetLayout(vds); + //ASSERT_TRUE(layout); + OpenVDS::VolumeDataAccessManager accessManager = OpenVDS::GetAccessManager(vds); + //ASSERT_TRUE(accessManager); + + int32_t channel = 0; + OpenVDS::VolumeDataPageAccessor *pageAccessor = accessManager.CreateVolumeDataPageAccessor(OpenVDS::Dimensions_012, 0, channel, 100, OpenVDS::VolumeDataAccessManager::AccessMode_Create); + //ASSERT_TRUE(pageAccessor); + + double distMax = distance3D(0, 0, 0, samplesX, samplesY, samplesZ); + double cycles = M_PI * 2 * 6; + double midX = samplesX / 2.f; + double midY = samplesY / 2.f; + double midZ = samplesZ / 2.f; + + int32_t chunkCount = int32_t(pageAccessor->GetChunkCount()); + //OpenVDS::VolumeDataChannelDescriptor::Format format = layout->GetChannelFormat(channel); + for (int i = 0; i < chunkCount; i++) + { + OpenVDS::VolumeDataPage *page = pageAccessor->CreatePage(i); + OpenVDS::VolumeIndexer3D outputIndexer(page, 0, 0, OpenVDS::Dimensions_012, layout); + OpenVDS::IntVector<3> numSamples; + + for (int j=0; j<3; j++) + { + numSamples[j] = outputIndexer.GetDataBlockNumSamples(j); + } + + int pitch[OpenVDS::Dimensionality_Max]; + void *buffer = page->GetWritableBuffer(pitch); + auto output = static_cast(buffer); + + for (int iDim2 = 0; iDim2 < numSamples[2]; iDim2++) + for (int iDim1 = 0; iDim1 < numSamples[1]; iDim1++) + for (int iDim0 = 0; iDim0 < numSamples[0]; iDim0++) + { + OpenVDS::IntVector<3> localOutIndex(iDim0, iDim1, iDim2); + OpenVDS::IntVector<3> vox = outputIndexer.LocalIndexToVoxelIndex(localOutIndex); + float value = 0.f; + double dist = 0.; + if (vox[0] >= midX) { + dist = distance2D(midY, midZ, vox[1], vox[2]); + } else { + dist = distance3D(midX, midY, midZ, vox[0], vox[1], vox[2]); + } + value = (float) sin((dist * cycles) / distMax); + int dataPos = outputIndexer.LocalIndexToDataIndex(localOutIndex); + output[dataPos] = value; + } + + page->Release(); + } + + pageAccessor->Commit(); + pageAccessor->SetMaxPages(0); + accessManager.FlushUploadQueue(); + accessManager.DestroyVolumeDataPageAccessor(pageAccessor); + + OpenVDS::Close(vds); +} + +void createLODVDS(const std::string &vdsFileName, int32_t samplesX, int32_t samplesY, int32_t samplesZ, OpenVDS::VolumeDataLayoutDescriptor::LODLevels lodLevel) { + + double distMax = distance3D(0, 0, 0, samplesX, samplesY, samplesZ); + double cycles = M_PI * 2 * 6; + double midX = samplesX / 2.f; + double midY = samplesY / 2.f; + double midZ = samplesZ / 2.f; + + OpenVDS::VolumeDataChannelDescriptor::Format format = OpenVDS::VolumeDataChannelDescriptor::Format_R32; + + auto brickSize = OpenVDS::VolumeDataLayoutDescriptor::BrickSize_256; + int negativeMargin = 4; + int positiveMargin = 4; + int brickSize2DMultiplier = 4; + auto lodLevels = lodLevel; + int lodLevelCount = lodLevel; + auto layoutOptions = OpenVDS::VolumeDataLayoutDescriptor::Options_None; + OpenVDS::VolumeDataLayoutDescriptor layoutDescriptor(brickSize, negativeMargin, positiveMargin, + brickSize2DMultiplier, lodLevels, layoutOptions); + + std::vector axisDescriptors; + axisDescriptors.emplace_back(samplesX, "Sample", "s", 0.0f,4.f); + axisDescriptors.emplace_back(samplesY, "Crossline", "",1932.f, 1932.f + samplesY - 1.f); + axisDescriptors.emplace_back(samplesZ, "Inline", "", 9985.f, 9985.f + samplesZ - 1.f); + + std::vector channelDescriptors; + float rangeMin = -1.f; + float rangeMax = 1.f; + float intScale; + float intOffset; + getScaleOffsetForFormat(rangeMin, rangeMax, true, format, intScale, intOffset); + channelDescriptors.emplace_back(format, OpenVDS::VolumeDataChannelDescriptor::Components_1, + AMPLITUDE_ATTRIBUTE_NAME, "", rangeMin, rangeMax, + OpenVDS::VolumeDataMapping::Direct, 1, + OpenVDS::VolumeDataChannelDescriptor::Default, -999.25f, intScale, intOffset); + + //OpenVDS::InMemoryOpenOptions options; + OpenVDS::VDSFileOpenOptions options(vdsFileName); + OpenVDS::Error error; + + OpenVDS::MetadataContainer metadataContainer; + metadataContainer.SetMetadataInt("categoryInt", "Int", 123); + metadataContainer.SetMetadataIntVector2("categoryInt", "IntVector2", OpenVDS::IntVector2(45, 78)); + metadataContainer.SetMetadataIntVector3("categoryInt", "IntVector3", OpenVDS::IntVector3(45, 78, 72)); + metadataContainer.SetMetadataIntVector4("categoryInt", "IntVector4", OpenVDS::IntVector4(45, 78, 72, 84)); + metadataContainer.SetMetadataFloat("categoryFloat", "Float", 123.f); + metadataContainer.SetMetadataFloatVector2("categoryFloat", "FloatVector2", OpenVDS::FloatVector2(45.5f, 78.75f)); + metadataContainer.SetMetadataFloatVector3("categoryFloat", "FloatVector3", + OpenVDS::FloatVector3(45.5f, 78.75f, 72.75f)); + metadataContainer.SetMetadataFloatVector4("categoryFloat", "FloatVector4", + OpenVDS::FloatVector4(45.5f, 78.75f, 72.75f, 84.1f)); + metadataContainer.SetMetadataDouble("categoryDouble", "Double", 123.); + metadataContainer.SetMetadataDoubleVector2("categoryDouble", "DoubleVector2", OpenVDS::DoubleVector2(45.5, 78.75)); + metadataContainer.SetMetadataDoubleVector3("categoryDouble", "DoubleVector3", + OpenVDS::DoubleVector3(45.5, 78.75, 72.75)); + metadataContainer.SetMetadataDoubleVector4("categoryDouble", "DoubleVector4", + OpenVDS::DoubleVector4(45.5, 78.75, 72.75, 84.1)); + metadataContainer.SetMetadataString("categoryString", "String", std::string("Test string")); + + auto vds = OpenVDS::Create(options, layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, + error); + + OpenVDS::VolumeDataLayout *layout = OpenVDS::GetLayout(vds); + //ASSERT_TRUE(layout); + OpenVDS::VolumeDataAccessManager accessManager = OpenVDS::GetAccessManager(vds); + //ASSERT_TRUE(accessManager); + + for (int lod = 0 ; lod <= lodLevelCount ; lod ++) { + int32_t channel = 0; + OpenVDS::VolumeDataPageAccessor *pageAccessor = accessManager.CreateVolumeDataPageAccessor(OpenVDS::Dimensions_012, lod, channel, 100, + OpenVDS::VolumeDataAccessManager::AccessMode_Create); + //ASSERT_TRUE(pageAccessor); + + int32_t chunkCount = int32_t(pageAccessor->GetChunkCount()); + //OpenVDS::VolumeDataChannelDescriptor::Format format = layout->GetChannelFormat(channel); + for (int i = 0; i < chunkCount; i++) { + OpenVDS::VolumeDataPage *page = pageAccessor->CreatePage(i); + OpenVDS::VolumeIndexer3D outputIndexer(page, 0, lod, OpenVDS::Dimensions_012, layout); + OpenVDS::IntVector<3> numSamples; + + for (int j = 0; j < 3; j++) { + numSamples[j] = outputIndexer.GetDataBlockNumSamples(j); + } + + int pitch[OpenVDS::VolumeDataLayout::Dimensionality_Max]; + int chunkMin[OpenVDS::VolumeDataLayout::Dimensionality_Max]; + int chunkMax[OpenVDS::VolumeDataLayout::Dimensionality_Max]; + + page->GetMinMax(chunkMin, chunkMax); + + void *buffer = page->GetWritableBuffer(pitch); + auto output = static_cast(buffer); + + for (int iDim2 = 0; iDim2 < numSamples[2]; iDim2++) + for (int iDim1 = 0; iDim1 < numSamples[1]; iDim1++) + for (int iDim0 = 0; iDim0 < numSamples[0]; iDim0++) { + OpenVDS::IntVector<3> localIndex(iDim0, iDim1, iDim2); + OpenVDS::IntVector<3> voxelPos = outputIndexer.LocalIndexToVoxelIndex(localIndex); + + float value = 0.f; + double dist = 0.; + if (voxelPos[0] >= midX) { + dist = distance2D(midY, midZ, voxelPos[1], voxelPos[2]); + } else { + dist = distance3D(midX, midY, midZ, voxelPos[0], voxelPos[1], voxelPos[2]); + } + value = (float) sin((dist * cycles) / distMax); + + int dataPos = outputIndexer.LocalIndexToDataIndex(localIndex); + output[dataPos] = value; + } + + page->Release(); + } + + pageAccessor->Commit(); + pageAccessor->SetMaxPages(0); + accessManager.FlushUploadQueue(); + accessManager.DestroyVolumeDataPageAccessor(pageAccessor); + } + + OpenVDS::Close(vds); +} + +double distance2D(double x1, double y1, double x2, double y2) { + double diffX = x2 - x1; + double diffY = y2 - y1; + return sqrt((diffX * diffX) + (diffY * diffY)); +} + +double distance3D(double x1, double y1, double z1, double x2, double y2, double z2) { + double diffX = x2 - x1; + double diffY = y2 - y1; + double diffZ = z2 - z1; + return sqrt((diffX * diffX) + (diffY * diffY) + (diffZ * diffZ)); +}