diff --git a/Tests/gridSerialisation/gridSerialisation.cpp b/Tests/gridSerialisation/gridSerialisation.cpp index f5bc186..1149cc8 100644 --- a/Tests/gridSerialisation/gridSerialisation.cpp +++ b/Tests/gridSerialisation/gridSerialisation.cpp @@ -8,7 +8,7 @@ int main() { constexpr int D = 2; using BNCType = typename hrleGrid::boundaryType; - hrleIndexType min[D] = {-10, -10}; + hrleIndexType min[D] = {-10000000, -100000000}; hrleIndexType max[D] = {10, 10}; const double gridDelta = 1.0; BNCType boundaryCons[D]; @@ -21,6 +21,9 @@ int main() { // Initialise example grid auto grid = hrleGrid(min, max, gridDelta, boundaryCons); + // grid.print(); + // std::cout << "\n\n" << std::flush; + // grid.print(); // Open file for writing and save serialized level set in it @@ -39,6 +42,8 @@ int main() { fin.close(); + // newGrid.print(); + HRLETEST_ASSERT(grid == newGrid) return 0; diff --git a/include/hrleCartesianPlaneIterator.hpp b/include/hrleCartesianPlaneIterator.hpp index b6c3168..6df05b1 100644 --- a/include/hrleCartesianPlaneIterator.hpp +++ b/include/hrleCartesianPlaneIterator.hpp @@ -247,7 +247,7 @@ template class hrleCartesianPlaneIterator { unsigned getSize() { return planeCoords.size(); } - const DomainType& getDomain() { return domain; } + const DomainType &getDomain() { return domain; } bool isFinished() const { return getCenter().isFinished(); } diff --git a/include/hrleDenseCellIterator.hpp b/include/hrleDenseCellIterator.hpp index 86ded39..43fe532 100644 --- a/include/hrleDenseCellIterator.hpp +++ b/include/hrleDenseCellIterator.hpp @@ -185,7 +185,7 @@ template class hrleDenseCellIterator { const hrleIndexType &getIndices(unsigned i) { return currentCoords[i]; } - const DomainType& getDomain() { return domain; } + const DomainType &getDomain() { return domain; } bool isFinished() const { if (compare(currentCoords, maxIndex) > 0) { diff --git a/include/hrleDenseIterator.hpp b/include/hrleDenseIterator.hpp index 0d06f4c..fb7d836 100644 --- a/include/hrleDenseIterator.hpp +++ b/include/hrleDenseIterator.hpp @@ -159,7 +159,7 @@ template class hrleDenseIterator { return runsIterator.getStartIndices(); } - const DomainType& getDomain() { return domain; } + const DomainType &getDomain() { return domain; } void print() { std::cout << currentIndices << std::endl; diff --git a/include/hrleGrid.hpp b/include/hrleGrid.hpp index 5a0b496..6f3de0e 100644 --- a/include/hrleGrid.hpp +++ b/include/hrleGrid.hpp @@ -53,14 +53,32 @@ template class hrleGrid { // increasing and true if the grid_position function is // strictly monotonic decreasing - static char getByteSizeOfNumber(int number) { + static char getBitSizeOfNumber(long number) { + const bool isNegative = number < 0; number = std::abs(number); - char size = 0; + char bitSize = 0; while (number != 0) { - number >>= 8; - ++size; + number >>= 1; + ++bitSize; } - return size; + return isNegative ? bitSize + 1 : bitSize; + } + + static char getByteSizeOfNumber(long number) { + auto bitSize = getBitSizeOfNumber(number); + return bitSize / 8 + (bitSize % 8 != 0); + } + + hrleIndexType readGridBoundary(std::istream &stream, char gridBoundaryBytes) { + char number[sizeof(hrleIndexType)] = {}; + for (unsigned i = 0; i < gridBoundaryBytes; ++i) + stream.read(number + i, 1); + + if (number[gridBoundaryBytes - 1] >> 7) { + for (unsigned i = gridBoundaryBytes; i < sizeof(hrleIndexType); ++i) + number[i] = 0xFF; + } + return *reinterpret_cast(number); } public: @@ -652,20 +670,16 @@ template class hrleGrid { char gridBoundaryBytes = 0; stream.read(&gridBoundaryBytes, 1); - // READ GRID hrleIndexType gridMin[D], gridMax[D]; typename hrleGrid::boundaryType boundaryCons[D]; double gridDelta = 0.; for (int i = D - 1; i >= 0; --i) { + gridMin[i] = readGridBoundary(stream, gridBoundaryBytes); + gridMax[i] = readGridBoundary(stream, gridBoundaryBytes); char condition = 0; - char min, max; - stream.read(&min, gridBoundaryBytes); - stream.read(&max, gridBoundaryBytes); stream.read(&condition, 1); boundaryCons[i] = boundaryType(condition); - gridMin[i] = hrleIndexType(min); - gridMax[i] = hrleIndexType(max); } stream.read((char *)&gridDelta, sizeof(double)); // initialize new grid diff --git a/include/hrleSparseBoxIterator.hpp b/include/hrleSparseBoxIterator.hpp index d69551d..5974ad0 100644 --- a/include/hrleSparseBoxIterator.hpp +++ b/include/hrleSparseBoxIterator.hpp @@ -214,7 +214,7 @@ template class hrleSparseBoxIterator { unsigned getSize() { return neighborIterators.size(); } - const DomainType& getDomain() { return domain; } + const DomainType &getDomain() { return domain; } bool isFinished() const { return getCenter().isFinished(); } diff --git a/include/hrleSparseCellIterator.hpp b/include/hrleSparseCellIterator.hpp index ba125c0..b17d330 100644 --- a/include/hrleSparseCellIterator.hpp +++ b/include/hrleSparseCellIterator.hpp @@ -155,7 +155,7 @@ template class hrleSparseCellIterator { const hrleIndexType &getIndices(unsigned i) { return currentCoords[i]; } - const DomainType& getDomain() { return domain; } + const DomainType &getDomain() { return domain; } bool isFinished() const { return cornerIterators[0].isFinished(); } }; diff --git a/include/hrleSparseMultiIterator.hpp b/include/hrleSparseMultiIterator.hpp index 6b40a51..644f907 100644 --- a/include/hrleSparseMultiIterator.hpp +++ b/include/hrleSparseMultiIterator.hpp @@ -14,11 +14,11 @@ /// points are defined at one index (i.e.: the point is defined in more /// than one domain), it will only stop once. template class hrleSparseMultiIterator { - public: +public: using DomainType = hrleDomain; using DomainsType = std::vector; - private: +private: typedef typename std::conditional::value, const typename hrleDomain::hrleValueType, typename hrleDomain::hrleValueType>::type @@ -190,7 +190,7 @@ template class hrleSparseMultiIterator { return definedIterators; } - const DomainsType& getDomains() { return domains; } + const DomainsType &getDomains() { return domains; } /// If all iterators in all domains are finished, this will return true. bool isFinished() const { diff --git a/include/hrleSparseStarIterator.hpp b/include/hrleSparseStarIterator.hpp index 90192e4..0d876ba 100644 --- a/include/hrleSparseStarIterator.hpp +++ b/include/hrleSparseStarIterator.hpp @@ -176,7 +176,7 @@ template class hrleSparseStarIterator { const hrleVectorType &getIndices() { return currentCoords; } - const DomainType& getDomain() { return domain; } + const DomainType &getDomain() { return domain; } bool isFinished() const { return centerIterator.isFinished(); }