Skip to content

Commit

Permalink
BUG: When reading a hex grid file do NOT attempt to fix location
Browse files Browse the repository at this point in the history
of the data.

* Updated version 1.0.25

Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
  • Loading branch information
imikejackson authored and JDuffeyBQ committed Sep 8, 2023
1 parent 171658d commit 71609c5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# set project's name
project(EbsdLibProj VERSION 1.0.17)
project(EbsdLibProj VERSION 1.0.25)

# ---------- Setup output Directories -------------------------
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY
Expand Down
42 changes: 24 additions & 18 deletions Source/EbsdLib/IO/TSL/AngReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@

#include <algorithm>
#include <fstream>
#include <optional>
#include <sstream>
#include <utility>
#include <optional>

namespace
{

using Vec3Type = std::array<float, 3>;
using Size3Type = std::array<size_t, 3>;

std::optional<size_t> GetGridIndex(Vec3Type& coords, Vec3Type& m_Origin, Vec3Type& m_Spacing, Size3Type& m_Dimensions )
std::optional<size_t> GetGridIndex(Vec3Type& coords, Vec3Type& m_Origin, Vec3Type& m_Spacing, Size3Type& m_Dimensions)
{
if(coords[0] < m_Origin[0] || coords[0] > (static_cast<float>(m_Dimensions[0]) * m_Spacing[0] + m_Origin[0]))
if(coords[0] < m_Origin[0] || coords[0] > (static_cast<float>(m_Dimensions[0]) * m_Spacing[0] + m_Origin[0]))
{
return {};
}
Expand All @@ -69,7 +69,7 @@ std::optional<size_t> GetGridIndex(Vec3Type& coords, Vec3Type& m_Origin, Vec3Typ
return {};
}

size_t x = static_cast<size_t>(std::floor((coords[0] - m_Origin[0]) / m_Spacing[0]));
size_t x = static_cast<size_t>(std::floor((coords[0] - m_Origin[0]) / m_Spacing[0]));
if(x >= m_Dimensions[0])
{
return {};
Expand All @@ -89,7 +89,7 @@ std::optional<size_t> GetGridIndex(Vec3Type& coords, Vec3Type& m_Origin, Vec3Typ

return (m_Dimensions[1] * m_Dimensions[0] * z) + (m_Dimensions[0] * y) + x;
}
}
} // namespace

// -----------------------------------------------------------------------------
//
Expand Down Expand Up @@ -395,13 +395,17 @@ int AngReader::readFile()
return getErrorCode();
}
std::vector<int64_t> indexMap;
std::pair<int, std::string> result = fixOrderOfData(indexMap);

if(result.first < 0)
std::string grid = getGrid();
if(grid.find(EbsdLib::Ang::SquareGrid) == 0)
{
setErrorCode(result.first);
setErrorMessage(result.second);
return result.first;
std::pair<int, std::string> result = fixOrderOfData(indexMap);

if(result.first < 0)
{
setErrorCode(result.first);
setErrorMessage(result.second);
return result.first;
}
}

std::vector<std::string> arrayNames = {"Phi1", "Phi", "Phi2", "X Position", "Y Position", "Image Quality", "Confidence Index", "PhaseData", "SEM Signal", "Fit"};
Expand Down Expand Up @@ -995,14 +999,15 @@ std::pair<int, std::string> AngReader::fixOrderOfData(std::vector<int64_t>& inde
if(std::nearbyint((xMax - xMin) / xStep) + 1 != numCols)
{
std::stringstream message;
message << "Error: The calculated number of columns (" << ((xMax - xMin) / xStep) + 1 << ") does not match the actual number of columns (" << numCols << ")" << std::endl;
return {-100, message.str()};
message << "Error: The calculated number of columns XMax: " << xMax << ", XMin: " << xMin << ", XStep: " << xStep << " (" << ((xMax - xMin) / xStep) + 1
<< ") does not match the actual number of columns (" << numCols + 1 << ")" << std::endl;
return {-101100, message.str()};
}
if(std::nearbyint((yMax - yMin) / yStep) + 1 != numRows)
{
std::stringstream message;
message << "Error: The calculated number of rows YMax: " << yMax << ", YMin: " << yMin << ", YStep: " << yStep << " (" << ((yMax - yMin) / yStep) + 1 << ") does not match the actual number of rows (" << numRows + 1
<< ")" << std::endl;
message << "Error: The calculated number of rows YMax: " << yMax << ", YMin: " << yMin << ", YStep: " << yStep << " (" << ((yMax - yMin) / yStep) + 1
<< ") does not match the actual number of rows (" << numRows + 1 << ")" << std::endl;
return {-101101, message.str()};
}

Expand All @@ -1021,9 +1026,10 @@ std::pair<int, std::string> AngReader::fixOrderOfData(std::vector<int64_t>& inde
{
std::stringstream message;
message << "AngReader Error: The calculated index for the X and Y Position " << coords[0] << ", " << coords[1] << " will fall outside of the calculated grid.\n "
<< "Origin: " << m_Origin[0] <<", " << m_Origin[1] << "\n "
<< "Spacing: " << m_Spacing[1] << ", " << m_Spacing[1] << "\n "
<< "Dimensions: " << m_Dimensions[0] << ", " << m_Dimensions[1] << "\n" << std::endl;
<< "Origin: " << m_Origin[0] << ", " << m_Origin[1] << "\n "
<< "Spacing: " << m_Spacing[1] << ", " << m_Spacing[1] << "\n "
<< "Dimensions: " << m_Dimensions[0] << ", " << m_Dimensions[1] << "\n"
<< std::endl;
return {-101111, message.str()};
}
}
Expand Down

0 comments on commit 71609c5

Please sign in to comment.