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

Make public apis c++ library agnostic

parent 52f7306f
......@@ -175,20 +175,35 @@ void CreateVolumeDataLayout(VDS &vds)
}
}
VDS* Create(IOManager *ioManager, VolumeDataLayoutDescriptor const &layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const &axisDescriptors, std::vector<VolumeDataChannelDescriptor> const &channelDescriptors, MetadataContainer const &metadataContainer, Error &error)
static void copyMetadataToContainer(MetadataContainer &container, const MetadataReadAccess &readAccess)
{
std::unordered_set<std::string> copied;
for (auto &key : readAccess)
{
if (copied.count(key.category))
{
continue;
}
container.CopyMetadata(key.category, &readAccess);
}
}
VDSHandle Create(IOManager* ioManager, VolumeDataLayoutDescriptor const &layoutDescriptor, VectorWrapper<VolumeDataAxisDescriptor> axisDescriptors, VectorWrapper<VolumeDataChannelDescriptor> channelDescriptors, MetadataReadAccess const &metadata, Error &error)
{
error = Error();
std::unique_ptr<VDS> vds(new VDS(ioManager));
vds->layoutDescriptor = layoutDescriptor;
for(auto axisDescriptor : axisDescriptors)
for(size_t i = 0; i < axisDescriptors.size; i++)
{
auto &axisDescriptor = axisDescriptors.data[i];
vds->axisDescriptors.push_back(VolumeDataAxisDescriptor(axisDescriptor.GetNumSamples(), AddDescriptorString(axisDescriptor.GetName(), *vds), AddDescriptorString(axisDescriptor.GetUnit(), *vds), axisDescriptor.GetCoordinateMin(), axisDescriptor.GetCoordinateMax()));
}
for(auto channelDescriptor : channelDescriptors)
for(size_t i = 0; i < channelDescriptors.size; i++)
{
auto &channelDescriptor = channelDescriptors.data[i];
VolumeDataChannelDescriptor::Flags flags = VolumeDataChannelDescriptor::Default;
if(channelDescriptor.IsDiscrete()) flags = flags | VolumeDataChannelDescriptor::DiscreteData;
......@@ -206,7 +221,7 @@ VDS* Create(IOManager *ioManager, VolumeDataLayoutDescriptor const &layoutDescri
}
}
vds->metadataContainer = metadataContainer;
copyMetadataToContainer(vds->metadataContainer, metadata);
vds->produceStatuses.clear();
vds->produceStatuses.resize(int(Dimensions_45) + 1, VolumeDataLayer::ProduceStatus_Unavailable);
......@@ -225,14 +240,14 @@ VDS* Create(IOManager *ioManager, VolumeDataLayoutDescriptor const &layoutDescri
return vds.release();
}
VDS* Create(const OpenOptions& options, VolumeDataLayoutDescriptor const& layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const& axisDescriptors, std::vector<VolumeDataChannelDescriptor> const& channelDescriptors, MetadataContainer const& metadataContainer, Error& error)
VDSHandle Create(const OpenOptions& options, VolumeDataLayoutDescriptor const& layoutDescriptor, VectorWrapper<VolumeDataAxisDescriptor> axisDescriptors, VectorWrapper<VolumeDataChannelDescriptor> channelDescriptors, MetadataReadAccess const& metadata, Error& error)
{
error = Error();
IOManager* ioManager = IOManager::CreateIOManager(options, error);
if (error.code)
return nullptr;
return Create(ioManager, layoutDescriptor, axisDescriptors, channelDescriptors, metadataContainer, error);
return Create(ioManager, layoutDescriptor, axisDescriptors, channelDescriptors, metadata, error);
}
void Close(VDS *vds)
......
This diff is collapsed.
......@@ -18,9 +18,9 @@
#ifndef OPENVDS_H
#define OPENVDS_H
#include "openvds_export.h"
#include "Metadata.h"
#include "VolumeData.h"
#include <OpenVDS/openvds_export.h>
#include <OpenVDS/Metadata.h>
#include <OpenVDS/VolumeData.h>
#include <cstdint>
#include <string>
......@@ -70,6 +70,18 @@ struct Error
std::string string;
};
template<typename T>
struct VectorWrapper
{
VectorWrapper(const std::vector<T> &toWrap)
: data(toWrap.data())
, size(toWrap.size())
{}
const T *data;
size_t size;
};
typedef struct VDS *VDSHandle;
class VolumeDataLayout;
class VolumeDataAccessManager;
......@@ -115,7 +127,7 @@ OPENVDS_EXPORT VDSHandle Open(IOManager*ioManager, Error &error);
/// <returns>
/// The VDS handle that can be used to get the VolumeDataLayout and the VolumeDataAccessManager
/// </returns>
OPENVDS_EXPORT VDSHandle Create(const OpenOptions& options, VolumeDataLayoutDescriptor const& layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const& axisDescriptors, std::vector<VolumeDataChannelDescriptor> const& channelDescriptors, MetadataContainer const& metadataContainer, Error& error);
OPENVDS_EXPORT VDSHandle Create(const OpenOptions& options, VolumeDataLayoutDescriptor const& layoutDescriptor, VectorWrapper<VolumeDataAxisDescriptor> axisDescriptors, VectorWrapper<VolumeDataChannelDescriptor> channelDescriptors, MetadataReadAccess const& metadata, Error& error);
/// <summary>
/// Create a new VDS
......@@ -129,7 +141,8 @@ OPENVDS_EXPORT VDSHandle Create(const OpenOptions& options, VolumeDataLayoutDesc
/// <returns>
/// The VDS handle that can be used to get the VolumeDataLayout and the VolumeDataAccessManager
/// </returns>
OPENVDS_EXPORT VDSHandle Create(IOManager* ioManager, VolumeDataLayoutDescriptor const &layoutDescriptor, std::vector<VolumeDataAxisDescriptor> const &axisDescriptors, std::vector<VolumeDataChannelDescriptor> const &channelDescriptors, MetadataContainer const &metadataContainer, Error &error);
OPENVDS_EXPORT VDSHandle Create(IOManager* ioManager, VolumeDataLayoutDescriptor const &layoutDescriptor, VectorWrapper<VolumeDataAxisDescriptor> axisDescriptors, VectorWrapper<VolumeDataChannelDescriptor> channelDescriptors, MetadataReadAccess const &metadata, Error &error);
/// <summary>
/// Close a VDS and free up all associated resources
......
......@@ -262,17 +262,9 @@ createSEGYHeadersMetadata(OpenVDS::File const &file, OpenVDS::MetadataContainer
if(!success) return false;
// Create metadata
{
OpenVDS::MetadataKey key = { OpenVDS::MetadataType::BLOB, "SEGY", "TextHeader" };
metadataContainer.blobData[key] = textHeader;
metadataContainer.keys.push_back(key);
}
metadataContainer.SetMetadataBLOB("SEGY", "TextHeader", textHeader);
{
OpenVDS::MetadataKey key = { OpenVDS::MetadataType::BLOB, "SEGY", "BinaryHeader" };
metadataContainer.blobData[key] = binaryHeader;
metadataContainer.keys.push_back(key);
}
metadataContainer.SetMetadataBLOB("SEGY", "BinaryHeader", binaryHeader);
return success;
}
......@@ -351,23 +343,9 @@ createSurveyCoordinateSystemMetadata(SEGYFileInfo const &fileInfo, OpenVDS::Meta
origin[1] -= crosslineSpacing[1] * firstSegmentInfo.m_binInfoStart.m_crosslineNumber;
// Set coordinate system
{
OpenVDS::MetadataKey key = { OpenVDS::MetadataType::DoubleVector2, LATTICE_CATEGORY, LATTICE_ORIGIN };
metadataContainer.doubleVector2Data[key] = OpenVDS::DoubleVector2(origin[0], origin[1]);
metadataContainer.keys.push_back(key);
}
{
OpenVDS::MetadataKey key = { OpenVDS::MetadataType::DoubleVector2, LATTICE_CATEGORY, LATTICE_INLINE_SPACING };
metadataContainer.doubleVector2Data[key] = OpenVDS::DoubleVector2(inlineSpacing[0], inlineSpacing[1]);
metadataContainer.keys.push_back(key);
}
{
OpenVDS::MetadataKey key = { OpenVDS::MetadataType::DoubleVector2, LATTICE_CATEGORY, LATTICE_CROSSLINE_SPACING };
metadataContainer.doubleVector2Data[key] = OpenVDS::DoubleVector2(crosslineSpacing[0], crosslineSpacing[1]);
metadataContainer.keys.push_back(key);
}
metadataContainer.SetMetadataDoubleVector2(LATTICE_CATEGORY, LATTICE_ORIGIN, OpenVDS::DoubleVector2(origin[0], origin[1]));
metadataContainer.SetMetadataDoubleVector2(LATTICE_CATEGORY, LATTICE_INLINE_SPACING, OpenVDS::DoubleVector2(inlineSpacing[0], inlineSpacing[1]));
metadataContainer.SetMetadataDoubleVector2(LATTICE_CATEGORY, LATTICE_CROSSLINE_SPACING, OpenVDS::DoubleVector2(crosslineSpacing[0], crosslineSpacing[1]));
}
bool
......
......@@ -21,6 +21,8 @@
#include "VolumeDataHash.h"
#include "MetadataManager.h"
#include <OpenVDS/Vector.h>
#include <json/json.h>
#include "Bitmask.h"
......@@ -512,78 +514,81 @@ bool ParseVolumeDataLayout(const std::vector<uint8_t> &json, VDS &vds, Error &er
for (const Json::Value &metadata : root["metadata"])
{
MetadataKey key = { MetadataTypeFromJson(metadata["type"]), metadata["category"].asString(), metadata["name"].asString() };
//MetadataKey key = { MetadataTypeFromJson(metadata["type"]), metadata["category"].asString(), metadata["name"].asString() };
vds.metadataContainer.keys.push_back(key);
//vds.metadataContainer.keys.push_back(key);
if (metadata["type"].asString() == "Int")
std::string type = metadata["type"].asString();
std::string category = metadata["category"].asString();
std::string name = metadata["name"].asString();
const Json::Value &value = metadata["value"];
if (type == "Int")
{
vds.metadataContainer.intData[key] = metadata["value"].asInt();
vds.metadataContainer.SetMetadataInt(category.c_str(), name.c_str(), value.asInt());
}
else if (metadata["type"].asString() == "IntVector2")
else if (type == "IntVector2")
{
vds.metadataContainer.intVector2Data[key] = { metadata["value"][0].asInt(), metadata["value"][1].asInt()};
vds.metadataContainer.SetMetadataIntVector2(category.c_str(), name.c_str(), IntVector2(value[0].asInt(), value[1].asInt()));
}
else if (metadata["type"].asString() == "IntVector3")
else if (type == "IntVector3")
{
vds.metadataContainer.intVector3Data[key] = { metadata["value"][0].asInt(), metadata["value"][1].asInt(), metadata["value"][2].asInt() };
vds.metadataContainer.SetMetadataIntVector3(category.c_str(), name.c_str(), IntVector3(value[0].asInt(), value[1].asInt(), value[2].asInt()));
}
else if (metadata["type"].asString() == "IntVector4")
else if (type == "IntVector4")
{
vds.metadataContainer.intVector4Data[key] = { metadata["value"][0].asInt(), metadata["value"][1].asInt(), metadata["value"][2].asInt(), metadata["value"][3].asInt() };
vds.metadataContainer.SetMetadataIntVector4(category.c_str(), name.c_str(), IntVector4(value[0].asInt(), value[1].asInt(), value[2].asInt(), value[3].asInt()));
}
else if (metadata["type"].asString() == "Float")
else if (type == "Float")
{
vds.metadataContainer.floatData[key] = metadata["value"].asFloat();
vds.metadataContainer.SetMetadataFloat(category.c_str(), name.c_str(), value.asFloat());
}
else if (metadata["type"].asString() == "FloatVector2")
else if (type == "FloatVector2")
{
vds.metadataContainer.floatVector2Data[key] = { metadata["value"][0].asFloat(), metadata["value"][1].asFloat() };
vds.metadataContainer.SetMetadataFloatVector2(category.c_str(), name.c_str(), FloatVector2(value[0].asFloat(), value[1].asFloat()));
}
else if (metadata["type"].asString() == "FloatVector3")
else if (type == "FloatVector3")
{
vds.metadataContainer.floatVector3Data[key] = { metadata["value"][0].asFloat(), metadata["value"][1].asFloat(), metadata["value"][2].asFloat() };
vds.metadataContainer.SetMetadataFloatVector3(category.c_str(), name.c_str(), FloatVector3(value[0].asFloat(), value[1].asFloat(), value[2].asFloat()));
}
else if (metadata["type"].asString() == "FloatVector4")
else if (type == "FloatVector4")
{
vds.metadataContainer.floatVector4Data[key] = { metadata["value"][0].asFloat(), metadata["value"][1].asFloat(), metadata["value"][2].asFloat(), metadata["value"][3].asFloat() };
vds.metadataContainer.SetMetadataFloatVector4(category.c_str(), name.c_str(), FloatVector4(value[0].asFloat(), value[1].asFloat(), value[2].asFloat(), value[3].asFloat()));
}
else if (metadata["type"].asString() == "Double")
else if (type == "Double")
{
vds.metadataContainer.doubleData[key] = metadata["value"].asDouble();
vds.metadataContainer.SetMetadataDouble(category.c_str(), name.c_str(), value.asDouble());
}
else if (metadata["type"].asString() == "DoubleVector2")
else if (type == "DoubleVector2")
{
vds.metadataContainer.doubleVector2Data[key] = { metadata["value"][0].asDouble(), metadata["value"][1].asDouble() };
vds.metadataContainer.SetMetadataDoubleVector2(category.c_str(), name.c_str(), DoubleVector2(value[0].asDouble(), value[1].asDouble()));
}
else if (metadata["type"].asString() == "DoubleVector3")
else if (type == "DoubleVector3")
{
vds.metadataContainer.doubleVector3Data[key] = { metadata["value"][0].asDouble(), metadata["value"][1].asDouble(), metadata["value"][2].asDouble() };
vds.metadataContainer.SetMetadataDoubleVector3(category.c_str(), name.c_str(), DoubleVector3(value[0].asDouble(), value[1].asDouble(), value[2].asDouble()));
}
else if (metadata["type"].asString() == "DoubleVector4")
else if (type == "DoubleVector4")
{
vds.metadataContainer.doubleVector4Data[key] = { metadata["value"][0].asDouble(), metadata["value"][1].asDouble(), metadata["value"][2].asDouble(), metadata["value"][3].asDouble() };
vds.metadataContainer.SetMetadataDoubleVector4(category.c_str(), name.c_str(), DoubleVector4(value[0].asDouble(), value[1].asDouble(), value[2].asDouble(), value[3].asDouble()));
}
else if (metadata["type"].asString() == "String")
else if (type == "String")
{
vds.metadataContainer.stringData[key] = metadata["value"].asString();
vds.metadataContainer.SetMetadataString(category.c_str(), name.c_str(), value.asString());
}
else if (metadata["type"].asString() == "BLOB")
else if (type == "BLOB")
{
const char* value = metadata["value"].asCString();
int len = (int)strlen(value);
const char *v = value.asCString();
std::vector<uint8_t> &data = vds.metadataContainer.blobData[key];
data.clear();
int len = (int)strlen(v);
bool success = Base64Decode(value, len, data);
std::vector<uint8_t> data;
bool success = Base64Decode(v, len, data);
if (!success)
{
data.clear();
return false;
}
vds.metadataContainer.SetMetadataBLOB(category.c_str(), name.c_str(), data);
}
}
......@@ -860,8 +865,10 @@ Json::Value SerializeVector(T const &vector)
return vectorJson;
}
Json::Value SerializeBLOB(std::vector<uint8_t> const &blob)
Json::Value SerializeBLOB(MetadataKey const &key, MetadataReadAccess const &readAccess)
{
std::vector<uint8_t> blob;
readAccess.GetMetadataBLOB(key.category, key.name, blob);
std::vector<char> base64;
Base64Encode(blob.data(), blob.size(), base64);
......@@ -873,7 +880,7 @@ Json::Value SerializeMetadata(MetadataContainer const &metadataContainer)
Json::Value
metadataJsonArray(Json::arrayValue);
for(auto metadataKey : metadataContainer.keys)
for(auto &metadataKey : metadataContainer)
{
Json::Value metadataJson;
......@@ -882,24 +889,24 @@ Json::Value SerializeMetadata(MetadataContainer const &metadataContainer)
switch(metadataKey.type)
{
case MetadataType::Int: metadataJson["type"] = "Int"; metadataJson["value"] = Json::Value(metadataContainer.intData.at(metadataKey)); break;
case MetadataType::IntVector2: metadataJson["type"] = "IntVector2"; metadataJson["value"] = SerializeVector(metadataContainer.intVector2Data.at(metadataKey)); break;
case MetadataType::IntVector3: metadataJson["type"] = "IntVector3"; metadataJson["value"] = SerializeVector(metadataContainer.intVector3Data.at(metadataKey)); break;
case MetadataType::IntVector4: metadataJson["type"] = "IntVector4"; metadataJson["value"] = SerializeVector(metadataContainer.intVector4Data.at(metadataKey)); break;
case MetadataType::Int: metadataJson["type"] = "Int"; metadataJson["value"] = Json::Value(metadataContainer.GetMetadataInt(metadataKey.category, metadataKey.name)); break;
case MetadataType::IntVector2: metadataJson["type"] = "IntVector2"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataIntVector2(metadataKey.category, metadataKey.name)); break;
case MetadataType::IntVector3: metadataJson["type"] = "IntVector3"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataIntVector3(metadataKey.category, metadataKey.name)); break;
case MetadataType::IntVector4: metadataJson["type"] = "IntVector4"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataIntVector4(metadataKey.category, metadataKey.name)); break;
case MetadataType::Float: metadataJson["type"] = "Float"; metadataJson["value"] = Json::Value(metadataContainer.floatData.at(metadataKey)); break;
case MetadataType::FloatVector2: metadataJson["type"] = "FloatVector2"; metadataJson["value"] = SerializeVector(metadataContainer.floatVector2Data.at(metadataKey)); break;
case MetadataType::FloatVector3: metadataJson["type"] = "FloatVector3"; metadataJson["value"] = SerializeVector(metadataContainer.floatVector3Data.at(metadataKey)); break;
case MetadataType::FloatVector4: metadataJson["type"] = "FloatVector4"; metadataJson["value"] = SerializeVector(metadataContainer.floatVector4Data.at(metadataKey)); break;
case MetadataType::Float: metadataJson["type"] = "Float"; metadataJson["value"] = Json::Value(metadataContainer.GetMetadataFloat(metadataKey.category, metadataKey.name)); break;
case MetadataType::FloatVector2: metadataJson["type"] = "FloatVector2"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataFloatVector2(metadataKey.category, metadataKey.name)); break;
case MetadataType::FloatVector3: metadataJson["type"] = "FloatVector3"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataFloatVector3(metadataKey.category, metadataKey.name)); break;
case MetadataType::FloatVector4: metadataJson["type"] = "FloatVector4"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataFloatVector4(metadataKey.category, metadataKey.name)); break;
case MetadataType::Double: metadataJson["type"] = "Double"; metadataJson["value"] = Json::Value(metadataContainer.doubleData.at(metadataKey)); break;
case MetadataType::DoubleVector2: metadataJson["type"] = "DoubleVector2"; metadataJson["value"] = SerializeVector(metadataContainer.doubleVector2Data.at(metadataKey)); break;
case MetadataType::DoubleVector3: metadataJson["type"] = "DoubleVector3"; metadataJson["value"] = SerializeVector(metadataContainer.doubleVector3Data.at(metadataKey)); break;
case MetadataType::DoubleVector4: metadataJson["type"] = "DoubleVector4"; metadataJson["value"] = SerializeVector(metadataContainer.doubleVector4Data.at(metadataKey)); break;
case MetadataType::Double: metadataJson["type"] = "Double"; metadataJson["value"] = Json::Value(metadataContainer.GetMetadataDouble(metadataKey.category, metadataKey.name)); break;
case MetadataType::DoubleVector2: metadataJson["type"] = "DoubleVector2"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataDoubleVector2(metadataKey.category, metadataKey.name)); break;
case MetadataType::DoubleVector3: metadataJson["type"] = "DoubleVector3"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataDoubleVector3(metadataKey.category, metadataKey.name)); break;
case MetadataType::DoubleVector4: metadataJson["type"] = "DoubleVector4"; metadataJson["value"] = SerializeVector(metadataContainer.GetMetadataDoubleVector4(metadataKey.category, metadataKey.name)); break;
case MetadataType::String: metadataJson["type"] = "String"; metadataJson["value"] = Json::Value(metadataContainer.stringData.at(metadataKey)); break;
case MetadataType::String: metadataJson["type"] = "String"; metadataJson["value"] = Json::Value(metadataContainer.GetMetadataString(metadataKey.category, metadataKey.name)); break;
case MetadataType::BLOB: metadataJson["type"] = "BLOB"; metadataJson["value"] = SerializeBLOB(metadataContainer.blobData.at(metadataKey)); break;
case MetadataType::BLOB: metadataJson["type"] = "BLOB"; metadataJson["value"] = SerializeBLOB(metadataKey, metadataContainer); break;
}
metadataJsonArray.append(metadataJson);
......
......@@ -449,5 +449,7 @@ DoubleVector3 VolumeDataLayoutImpl::GetMetadataDoubleVector3(const char* categor
DoubleVector4 VolumeDataLayoutImpl::GetMetadataDoubleVector4(const char* category, const char* name) const { return m_vds.metadataContainer.GetMetadataDoubleVector4(category, name); }
const char* VolumeDataLayoutImpl::GetMetadataString(const char* category, const char* name) const { return m_vds.metadataContainer.GetMetadataString(category, name); }
void VolumeDataLayoutImpl::GetMetadataBLOB(const char* category, const char* name, const void **data, size_t *size) const { return m_vds.metadataContainer.GetMetadataBLOB(category, name, data, size); }
MetadataReadAccess::const_iterator VolumeDataLayoutImpl::begin() const { return m_vds.metadataContainer.begin(); }
MetadataReadAccess::const_iterator VolumeDataLayoutImpl::end() const { return m_vds.metadataContainer.end(); }
}
......@@ -202,6 +202,8 @@ public:
DoubleVector4 GetMetadataDoubleVector4(const char* category, const char* name) const override;
const char* GetMetadataString(const char* category, const char* name) const override;
void GetMetadataBLOB(const char* category, const char* name, const void **data, size_t *size) const override;
const_iterator begin() const override;
const_iterator end() const override;
};
}
#endif //VOLUMEDATALAYOUTIMPL_H
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