Skip to content

Commit

Permalink
Intial working version of the code for bcf2hdf5
Browse files Browse the repository at this point in the history
  • Loading branch information
imikejackson committed Sep 10, 2022
1 parent 1fa9c12 commit f22cbcb
Show file tree
Hide file tree
Showing 17 changed files with 5,780 additions and 332 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ CMakeLists.txt.*
test_data/
CMakeUserPresets.json
Workspace
cmake-build-debug-visual-studio
cmake-build-release-visual-studio
99 changes: 97 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,65 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(BUILD_SHARED_LIBS ON)

# ---------- Setup output Directories -------------------------
if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
${BCFTools_BINARY_DIR}/Bin
CACHE PATH
"Single Directory for all Libraries"
)
endif()

# --------- Setup the Executable output Directory -------------
if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${BCFTools_BINARY_DIR}/Bin
CACHE PATH
"Single Directory for all Executables."
)
endif()

# --------- Setup the Executable output Directory -------------
if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY
${BCFTools_BINARY_DIR}/Bin
CACHE PATH
"Single Directory for all static libraries."
)
endif()



#-------------------------------------------------------------------------------
# PUGIXML Library
#-------------------------------------------------------------------------------
add_subdirectory(${BCFTools_SOURCE_DIR}/3rdparty/pugixml)

#-------------------------------------------------------------------------------
# HDF5 Library
#-------------------------------------------------------------------------------
set(HDF5_BUILD_WITH_INSTALL_NAME ON CACHE BOOL "" FORCE)
set(HDF5_BUILD_CPP_LIB OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_HL_LIB OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_HL_TOOLS OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
set(HDF5_BUILD_UTILS OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(HDF_PACKAGE_NAMESPACE "hdf5::")
set(HDF5_ALLOW_EXTERNAL_SUPPORT ON CACHE BOOL "" FORCE)
set(HDF5_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

add_subdirectory(${BCFTools_SOURCE_DIR}/3rdparty/hdf5)

#-------------------------------------------------------------------------------
# H5Support Library
#-------------------------------------------------------------------------------
#set(H5Support_INCLUDE_QT_API OFF)
#set(H5Support_INSTALL_HDF5 OFF)
#add_subdirectory(${BCFTools_SOURCE_DIR}/3rdparty/H5Support)


#-------------------------------------------------------------------------------
# unbcf executable
Expand All @@ -25,7 +84,43 @@ set(unbcf_sources
${BCFTools_SOURCE_DIR}/src/SFSNodeItem.cpp

${BCFTools_SOURCE_DIR}/src/SFSUtils.hpp
${BCFTools_SOURCE_DIR}/src/unbcf.cpp

)

add_executable(unbcf ${unbcf_sources} ${BCFTools_SOURCE_DIR}/src/unbcf.cpp)


#-------------------------------------------------------------------------------
# bcftohdf5 executable
#-------------------------------------------------------------------------------
set(bcf2hdf5_sources
${BCFTools_SOURCE_DIR}/src/bcf2hdf5.cpp
${BCFTools_SOURCE_DIR}/src/BcfHdf5Convertor.h
${BCFTools_SOURCE_DIR}/src/BcfHdf5Convertor.cpp

${BCFTools_SOURCE_DIR}/src/BrukerIntegration/BrukerIntegrationConstants.h
${BCFTools_SOURCE_DIR}/src/BrukerIntegration/BrukerIntegrationStructs.h

${BCFTools_SOURCE_DIR}/src/BrukerIntegrationFilters/BrukerDataLoader.h
${BCFTools_SOURCE_DIR}/src/BrukerIntegrationFilters/BrukerDataLoader.cpp

${BCFTools_SOURCE_DIR}/src/BrukerIntegrationFilters/EbsdPatterns.h
${BCFTools_SOURCE_DIR}/src/BrukerIntegrationFilters/EbsdPatterns.cpp

${BCFTools_SOURCE_DIR}/src/EbsdLib/Core/EbsdDataArray.hpp
${BCFTools_SOURCE_DIR}/src/EbsdLib/Core/EbsdDataArray.cpp
${BCFTools_SOURCE_DIR}/src/EbsdLib/Core/EbsdLibConstants.h
${BCFTools_SOURCE_DIR}/src/EbsdLib/Core/EbsdMacros.h
)

add_executable(unbcf ${unbcf_sources})
#add_executable(bcf2hdf5 ${unbcf_sources} ${BCFTools_SOURCE_DIR}/src/unbcf.cpp)

add_executable(bcf2hdf5 ${unbcf_sources} ${bcf2hdf5_sources})
target_link_libraries(bcf2hdf5 hdf5-shared pugixml)
target_include_directories(bcf2hdf5 PUBLIC
${BCFTools_SOURCE_DIR}/src
${BCFTools_SOURCE_DIR}/3rdparty/H5Support/Source
${BCFTools_SOURCE_DIR}/3rdparty/hdf5/src
${BCFTools_BINARY_DIR}/3rdparty/hdf5/src
${BCFTools_SOURCE_DIR}/3rdparty/pugixml/src
)
124 changes: 124 additions & 0 deletions src/Base64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#ifndef _MACARON_BASE64_H_
#define _MACARON_BASE64_H_

/**
* The MIT License (MIT)
* Copyright (c) 2016 tomykaira
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

#include <string>

namespace macaron {

class Base64 {
public:

static std::string Encode(const std::string data) {
static constexpr char sEncodingTable[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};

size_t in_len = data.size();
size_t out_len = 4 * ((in_len + 2) / 3);
std::string ret(out_len, '\0');
size_t i;
char *p = const_cast<char*>(ret.c_str());

for (i = 0; i < in_len - 2; i += 3) {
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int) (data[i + 2] & 0xC0) >> 6)];
*p++ = sEncodingTable[data[i + 2] & 0x3F];
}
if (i < in_len) {
*p++ = sEncodingTable[(data[i] >> 2) & 0x3F];
if (i == (in_len - 1)) {
*p++ = sEncodingTable[((data[i] & 0x3) << 4)];
*p++ = '=';
}
else {
*p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)];
*p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)];
}
*p++ = '=';
}

return ret;
}

static std::string Decode(const std::string& input, std::string& out) {
static constexpr unsigned char kDecodingTable[] = {
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
};

size_t in_len = input.size();
if (in_len % 4 != 0) return "Input data size is not a multiple of 4";

size_t out_len = in_len / 4 * 3;
if (input[in_len - 1] == '=') out_len--;
if (input[in_len - 2] == '=') out_len--;

out.resize(out_len);

for (size_t i = 0, j = 0; i < in_len;) {
uint32_t a = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t b = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t c = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];
uint32_t d = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast<int>(input[i++])];

uint32_t triple = (a << 3 * 6) + (b << 2 * 6) + (c << 1 * 6) + (d << 0 * 6);

if (j < out_len) out[j++] = (triple >> 2 * 8) & 0xFF;
if (j < out_len) out[j++] = (triple >> 1 * 8) & 0xFF;
if (j < out_len) out[j++] = (triple >> 0 * 8) & 0xFF;
}

return "";
}

};

}

#endif /* _MACARON_BASE64_H_ */

0 comments on commit f22cbcb

Please sign in to comment.