Commit 78d3cbdc authored by Jørgen Lind's avatar Jørgen Lind
Browse files

OpenVDSHandle and starting to parse downloaded VDS json

parent 271687be
......@@ -10,7 +10,8 @@ set(SOURCE_FILES
VDS/VolumeDataChunk.cpp
VDS/VolumeDataRegion.cpp
VDS/VolumeDataHash.cpp
VDS/DimensionGroup.cpp)
VDS/DimensionGroup.cpp
VDS/ParseVDSJson.cpp)
set (PRIVATE_HEADER_FILES
IO/File.h
......@@ -27,7 +28,8 @@ set (PRIVATE_HEADER_FILES
VDS/DimensionGroup.h
VDS/Hash.h
Math/Vector.h
VDS/Bitmask.h)
VDS/Bitmask.h
VDS/ParseVDSJson.h)
set (EXPORTED_HEADER_FILES
OpenVDS/OpenVDS.h
......@@ -41,7 +43,9 @@ add_library(openvds SHARED
add_dependencies(openvds aws-cpp-sdk)
target_include_directories(openvds PRIVATE "${aws-cpp-sdk_INCLUDE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}")
target_compile_definitions(openvds PRIVATE openvds_EXPORTS)
target_link_libraries(openvds PUBLIC Threads::Threads ${aws-cpp-sdk_EXTERNAL_LIBS} ${aws-cpp-sdk_LIBS})
target_link_libraries(openvds Threads::Threads)
target_link_libraries(openvds jsoncpp_lib_static)
target_link_libraries(openvds ${aws-cpp-sdk_EXTERNAL_LIBS} ${aws-cpp-sdk_LIBS})
if (WIN32)
set_source_files_properties(IO/Linux_File.cpp PROPERTIES HEADER_FILE_ONLY TRUE)
......
......@@ -28,15 +28,29 @@
#include <aws/s3/model/BucketLocationConstraint.h>
#include <aws/s3/model/GetObjectRequest.h>
namespace OpenVDS
{
namespace S3
{
static std::string convert_aws_string(const Aws::String &str)
{
return std::string(str.data(), str.size());
}
OPENVDS_EXPORT void s3_function()
static void initializeAWSSDK()
{
static bool initialized = false;
if (initialized)
return;
initialized = true;
Aws::SDKOptions options;
Aws::InitAPI(options);
}
void test_function()
{
initializeAWSSDK();
std::string bucket_name = "";
std::string location;
{
......@@ -149,5 +163,33 @@ OPENVDS_EXPORT void s3_function()
}
}
Aws::ShutdownAPI(options);
}
bool DownloadJson(const std::string &region, const std::string& bucket, const std::string &key, std::string &json, Error &error)
{
initializeAWSSDK();
Aws::Client::ClientConfiguration config;
config.region = region.c_str();
Aws::S3::S3Client s3_client(config);
Aws::S3::Model::GetObjectRequest object_request;
object_request.SetBucket(bucket.c_str());
object_request.SetKey(key.c_str());
auto get_object_outcome = s3_client.GetObject(object_request);
if (!get_object_outcome.IsSuccess())
{
auto s3error = get_object_outcome.GetError();
error.code = int(s3error.GetResponseCode());
error.string = (s3error.GetExceptionName() + " : " + s3error.GetMessage()).c_str();
return false;
}
auto result = get_object_outcome.GetResultWithOwnership();
auto& retrieved_object = result.GetBody();
auto content_length = result.GetContentLength();
if (content_length > 0)
{
json.resize(content_length);
retrieved_object.read(&json[0], content_length);
}
return true;
}
}
}
......@@ -17,3 +17,15 @@
//void s3_function();
#include <OpenVDS/openvds_export.h>
#include <OpenVDS/OpenVDS.h>
namespace OpenVDS
{
namespace S3
{
OPENVDS_EXPORT void test_function();
bool DownloadJson(const std::string &region, const std::string& bucket, const std::string &key, std::string &json, Error &error);
}
}
......@@ -81,6 +81,10 @@ using Vec3 = Vector<T, 3>;
template<typename T>
using Vec4 = Vector<T, 4>;
using IntVec2 = Vec2<int>;
using IntVec3 = Vec3<int>;
using IntVec4 = Vec4<int>;
using FloatVec2 = Vec2<float>;
using FloatVec3 = Vec3<float>;
using FloatVec4 = Vec4<float>;
......
......@@ -17,4 +17,26 @@
#include "OpenVDS/OpenVDS.h"
#include <OpenVDSHandle.h>
#include <IO/S3_Downloader.h>
#include <VDS/ParseVDSJson.h>
#include <memory>
namespace OpenVDS
{
VDSHandle *Open(const OpenOptions &options, Error &error)
{
std::unique_ptr<VDSHandle> ret(new VDSHandle());
if (!DownloadAndParseVDSJson(options, *ret.get(), error))
{
return nullptr;
}
return ret.release();
}
void Destroy(VDSHandle *handle)
{
}
}
......@@ -20,6 +20,26 @@
#include "openvds_export.h"
OPENVDS_EXPORT void s3_function();
#include <string>
namespace OpenVDS
{
struct OpenOptions
{
std::string bucket;
std::string key;
std::string region;
};
struct Error
{
int code = 0;
std::string string;
};
struct VDSHandle;
OPENVDS_EXPORT VDSHandle* Open(const OpenOptions& options, Error &error);
OPENVDS_EXPORT void Destroy(VDSHandle *handle);
}
#endif //OPENVDS_H
/****************************************************************************
** 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.
****************************************************************************/
#ifndef OPENVDSHANDLE_H
#define OPENVDSHANDLE_H
#include <VDS/VolumeDataLayoutDescriptor.h>
#include <VDS/VolumeDataAxisDescriptor.h>
#include <VDS/VolumeDataChannelDescriptor.h>
#include <VDS/VolumeDataLayer.h>
#include <Math/Vector.h>
#include <vector>
#include <memory>
#include <unordered_map>
namespace OpenVDS
{
struct VDSMetaDataKey
{
std::string category;
std::string name;
};
inline bool operator==(const VDSMetaDataKey& a, const VDSMetaDataKey& b)
{
return a.category == b.category
&& a.name == b.name;
}
}
namespace std
{
template<>
struct hash<OpenVDS::VDSMetaDataKey>
{
std::size_t operator()(const OpenVDS::VDSMetaDataKey &k) const
{
size_t const h1= std::hash<std::string>()(k.category);
size_t const h2= std::hash<std::string>()(k.name);
return h1 ^ (h2 << 1);
}
};
}
namespace OpenVDS
{
struct VDSMetaContainer
{
std::unordered_map<VDSMetaDataKey, int> intData;
std::unordered_map<VDSMetaDataKey, IntVec2> intVec2Data;
std::unordered_map<VDSMetaDataKey, IntVec3> intVec3Data;
std::unordered_map<VDSMetaDataKey, IntVec4> intVec4Data;
std::unordered_map<VDSMetaDataKey, float> floatData;
std::unordered_map<VDSMetaDataKey, FloatVec2> floatVec2Data;
std::unordered_map<VDSMetaDataKey, FloatVec3> floatVec3Data;
std::unordered_map<VDSMetaDataKey, FloatVec4> floatVec4Data;
std::unordered_map<VDSMetaDataKey, double> doubleData;
std::unordered_map<VDSMetaDataKey, DoubleVec2> doubleVec2Data;
std::unordered_map<VDSMetaDataKey, DoubleVec3> doubleVec3Data;
std::unordered_map<VDSMetaDataKey, DoubleVec4> doubleVec4Data;
std::unordered_map<VDSMetaDataKey, std::string> stringData;
std::unordered_map<VDSMetaDataKey, std::vector<uint8_t>> blobData;
};
struct VDSFreeDelete
{
void operator()(void* x) { free(x); }
};
struct VDSDescriptorString
{
uint32_t size;
char data[];
};
struct VDSHandle
{
std::string url;
VolumeDataLayoutDescriptor layoutDescriptor;
std::vector<VolumeDataAxisDescriptor> axisDescriptors;
std::vector<VolumeDataChannelDescriptor> channelDescriptors;
std::vector<std::unique_ptr<VDSDescriptorString, VDSFreeDelete>> descriptorStrings;
std::vector<VolumeDataLayer::ProduceStatus> produceStatuses;
VDSMetaContainer metaDataContainer;
};
}
#endif //OPENVDSHANDLE_H
......@@ -62,6 +62,7 @@ struct bit_mask {
friend constexpr bit_mask<V> operator&(V a, const bit_mask<V> &b);
template<typename V>
friend constexpr bit_mask<V> operator^(V a, const bit_mask<V> &b);
T to_enum() const { return T(_flags); }
U _flags;
};
......
This diff is collapsed.
/****************************************************************************
** 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.
****************************************************************************/
#ifndef PARSEVDSJSON_H
#define PARSEVDSJSON_H
#include <OpenVDS/OpenVDS.h>
#include <OpenVDSHandle.h>
namespace OpenVDS
{
bool DownloadAndParseVDSJson(const OpenOptions &options, VDSHandle &handle, Error &error);
}
#endif //PARSEVDSJSON_H
\ No newline at end of file
......@@ -18,6 +18,8 @@
#ifndef VOLUMEDATA_H
#define VOLUMEDATA_H
#include <cstdint>
namespace OpenVDS
{
......@@ -72,10 +74,10 @@ enum class DimensionsND
};
/// Mapping volume data channels
enum class VolumeDataMapping
enum class VolumeDataMapping : uint64_t
{
Direct, ///< Each voxel in the volume has a value
PerTrace ///< Each trace in the volume has a specified number of values. A trace is the entire length of dimension 0
Direct = 0xFFFFFFFFFFFFFFFFULL, ///< Each voxel in the volume has a value
PerTrace = 0x1B6F015EB8864888ULL ///< Each trace in the volume has a specified number of values. A trace is the entire length of dimension 0
};
enum class CompressionMethod
......
......@@ -15,9 +15,9 @@
** limitations under the License.
****************************************************************************/
#define _USE_MATH_DEFINES
#include "VolumeDataLayer.h"
#define _USE_MATH_DEFINES
#include <cmath>
#include "VolumeDataLayout.h"
......
......@@ -242,7 +242,7 @@ VolumeDataMapping VolumeDataLayout::GetChannelMapping(int32_t iChannel) const
// }
// else if (pcVolumeDataChannelDescriptor->GetChannelMapping() == TraceVolumeDataChannelMapping_c::GetInstance().GetObjID())
// {
// return ::SpaceLib::VOLUMEDATAMAPPING_PER_TRACE;
// return VOLUMEDATAMAPPING_PER_TRACE;
// }
// else
// {
......
/****************************************************************************
** 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.
****************************************************************************/
#ifndef VOLUMEDATALAYOUTDESCRIPTOR_H
#define VOLUMEDATALAYOUTDESCRIPTOR_H
namespace OpenVDS
{
class VolumeDataLayoutDescriptor
{
public:
enum BrickSize
{
BrickSize_32 = 5,
BrickSize_64 = 6,
BrickSize_128 = 7,
BrickSize_256 = 8,
BrickSize_512 = 9,
BrickSize_1024 = 10,
BrickSize_2048 = 11,
BrickSize_4096 = 12
};
enum LODLevels
{
LODLevelNone = 0,
LODLevel1 = 1,
LODLevel2 = 2,
LODLevel3 = 3,
LODLevel4 = 4,
LODLevel5 = 5,
LODLevel6 = 6,
LODLevel7 = 7,
LODLevel8 = 8,
LODLevel9 = 9,
LODLevel10 = 10,
LODLevel11 = 11,
LODLevel12 = 12
};
enum Options
{
Options_None = 0,
Options_Create2DLODs = (1 << 0),
Options_ForceFullResolutionDimension = (1 << 1)
};
private:
BrickSize brickSize;
int negativeMargin,
positiveMargin;
LODLevels lodLevels;
Options options;
int fullResolutionDimension;
public:
VolumeDataLayoutDescriptor() : brickSize((enum BrickSize)0), negativeMargin(0), positiveMargin(0), lodLevels(LODLevelNone), options(Options_None), fullResolutionDimension(0) {}
VolumeDataLayoutDescriptor(BrickSize brickSize, int negativeMargin, int positiveMargin, LODLevels lodLevels, Options options, int fullResolutionDimension = 0) : brickSize(brickSize), negativeMargin(negativeMargin), positiveMargin(positiveMargin), lodLevels(lodLevels), options(options), fullResolutionDimension(fullResolutionDimension) {}
bool IsValid() const { return brickSize != 0; }
BrickSize BrickSize() const { return brickSize; }
int NegativeMargin() const { return negativeMargin; }
int PositiveMargin() const { return positiveMargin; }
LODLevels LODLevels() const { return lodLevels; }
bool IsCreate2DLODs() const { return (options & Options_Create2DLODs) != 0; }
bool IsForceFullResolutionDimension() const { return (options & Options_ForceFullResolutionDimension) != 0; }
int FullResolutionDimension() const { return fullResolutionDimension; }
};
}
#endif //VOLUMEDATALAYOUTDESCRIPTOR_H
\ No newline at end of file
......@@ -36,3 +36,10 @@ target_include_directories(segy_tests PRIVATE ../src/SEG-Y)
copyDllForTarget(segy_tests)
gtest_discover_tests(segy_tests)
set_target_properties(segy_tests PROPERTIES FOLDER tests)
add_executable(vds_integration_tests
VDS/VDSIntegrationTest.cpp)
target_link_libraries(vds_integration_tests openvds Threads::Threads gtest gtest_main)
copyDllForTarget(vds_integration_tests)
gtest_discover_tests(vds_integration_tests)
set_target_properties(vds_integration_tests PROPERTIES FOLDER tests)
/****************************************************************************
** 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.
****************************************************************************/
#include <OpenVDS/OpenVDS.h>
#include <gtest/gtest.h>
GTEST_TEST(DownloadJson, OpenVDS_integration)
{
OpenVDS::Error error;
OpenVDS::OpenOptions options;
options.bucket = "bluware-vds-us-east-2";
options.key = "47231464AA898322";
options.region = "us-east-2";
OpenVDS::VDSHandle *handle = OpenVDS::Open(options, error);
EXPECT_TRUE(handle);
}
\ No newline at end of file
......@@ -15,13 +15,13 @@
** limitations under the License.
****************************************************************************/
#include "OpenVDS/OpenVDS.h"
#include <IO/S3_Downloader.h>
#include <gtest/gtest.h>
GTEST_TEST(BasicS3Test, io_s3)
{
fprintf(stderr, "S3 Downloader\n");
s3_function();
EXPECT_TRUE(&s3_function);
OpenVDS::S3::test_function();
EXPECT_TRUE(&OpenVDS::S3::test_function);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment