-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FILT: WriteVtkStructuredPoints implemented
Signed-off-by: Michael Jackson <[email protected]>
- Loading branch information
1 parent
8e46119
commit 2c9a894
Showing
11 changed files
with
496 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/Plugins/SimplnxCore/docs/WriteVtkStructuredPointsFilter.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Write Vtk Structured Points File | ||
|
||
## Group (Subgroup) | ||
|
||
I/O Filters | ||
|
||
## Description | ||
|
||
This Filter writes a VTK legacy file with a Dataset type of `STRUCTURED_POINTS`. The user can select which arrays from the Image Geometry will be written to the file. | ||
|
||
% Auto generated parameter table will be inserted here | ||
|
||
## Example Pipelines | ||
|
||
## License & Copyright | ||
|
||
Please see the description file distributed with this **Plugin** | ||
|
||
## DREAM3D-NX Help | ||
|
||
If you need help, need to file a bug report or want to request a new feature, please head over to the [DREAM3DNX-Issues](https://github.com/BlueQuartzSoftware/DREAM3DNX-Issues/discussions) GItHub site where the community of DREAM3D-NX users can help answer your questions. |
114 changes: 114 additions & 0 deletions
114
src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#include "WriteVtkStructuredPoints.hpp" | ||
|
||
#include "simplnx/DataStructure/DataArray.hpp" | ||
#include "simplnx/DataStructure/Geometry/ImageGeom.hpp" | ||
#include "simplnx/Utilities/FilterUtilities.hpp" | ||
#include "simplnx/Utilities/StringUtilities.hpp" | ||
|
||
#include "SimplnxCore/utils/VtkUtilities.hpp" | ||
|
||
using namespace nx::core; | ||
|
||
namespace | ||
{ | ||
|
||
} // namespace | ||
|
||
// ----------------------------------------------------------------------------- | ||
WriteVtkStructuredPoints::WriteVtkStructuredPoints(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, | ||
WriteVtkStructuredPointsInputValues* inputValues) | ||
: m_DataStructure(dataStructure) | ||
, m_InputValues(inputValues) | ||
, m_ShouldCancel(shouldCancel) | ||
, m_MessageHandler(mesgHandler) | ||
{ | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
WriteVtkStructuredPoints::~WriteVtkStructuredPoints() noexcept = default; | ||
|
||
// ----------------------------------------------------------------------------- | ||
const std::atomic_bool& WriteVtkStructuredPoints::getCancel() | ||
{ | ||
return m_ShouldCancel; | ||
} | ||
|
||
// ----------------------------------------------------------------------------- | ||
Result<> WriteVtkStructuredPoints::operator()() | ||
{ | ||
const auto& imageGeom = m_DataStructure.getDataRefAs<ImageGeom>(m_InputValues->ImageGeometryPath); | ||
SizeVec3 dims = imageGeom.getDimensions(); | ||
FloatVec3 spacing = imageGeom.getSpacing(); | ||
FloatVec3 origin = imageGeom.getOrigin(); | ||
|
||
std::string vtkOutPath = m_InputValues->OutputFile; | ||
Check failure on line 44 in src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp GitHub Actions / build (windows-2022, v142)
Check failure on line 44 in src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp GitHub Actions / build (windows-2022, v143)
|
||
std::ofstream outStrm(vtkOutPath, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); | ||
if(!outStrm.is_open()) | ||
{ | ||
return MakeErrorResult(-66667, fmt::format("Output file could not be opened for writing: '{}'", m_InputValues->OutputFile.string())); | ||
} | ||
outStrm << "# vtk DataFile Version 3.0\n"; | ||
outStrm << "vtk output\n"; | ||
|
||
if(m_InputValues->WriteBinaryFile) | ||
{ | ||
outStrm << "BINARY\n"; | ||
} | ||
else | ||
{ | ||
outStrm << "ASCII\n"; | ||
} | ||
outStrm << "DATASET STRUCTURED_POINTS\n"; | ||
|
||
outStrm << fmt::format("DIMENSIONS {} {} {}\n", dims[0] + 1, dims[1] + 1, dims[2] + 1); | ||
outStrm << fmt::format("SPACING {} {} {}\n", spacing[0], spacing[1], spacing[2]); | ||
outStrm << fmt::format("ORIGIN {} {} {}\n", origin[0], origin[1], origin[2]); | ||
|
||
outStrm << fmt::format("CELL_DATA {}\n", dims[0] * dims[1] * dims[2]); | ||
Result<> result; | ||
|
||
for(const auto& arrayPath : m_InputValues->SelectedDataArrayPaths) | ||
{ | ||
m_MessageHandler({nx::core::IFilter::Message::Type::Info, fmt::format("Writing {}", arrayPath.toString())}); | ||
IDataArray& dataArray = m_DataStructure.getDataRefAs<IDataArray>(arrayPath); | ||
auto dataType = dataArray.getDataType(); | ||
|
||
switch(dataType) | ||
{ | ||
case DataType::int8: | ||
MergeResults(result, writeVtkData<int8>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::uint8: | ||
MergeResults(result, writeVtkData<uint8>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::int16: | ||
MergeResults(result, writeVtkData<int16>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::uint16: | ||
MergeResults(result, writeVtkData<uint16>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::int32: | ||
MergeResults(result, writeVtkData<int32>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::uint32: | ||
MergeResults(result, writeVtkData<uint32>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::int64: | ||
MergeResults(result, writeVtkData<int64>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::uint64: | ||
MergeResults(result, writeVtkData<uint64>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::float32: | ||
MergeResults(result, writeVtkData<float32>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
case DataType::float64: | ||
MergeResults(result, writeVtkData<float64>(outStrm, m_DataStructure, arrayPath, m_InputValues->WriteBinaryFile, m_MessageHandler, m_ShouldCancel)); | ||
break; | ||
default: | ||
MergeResults(result, MakeErrorResult(-666666, "The chosen scalar type is not supported by this filter.")); | ||
} | ||
} | ||
|
||
return result; | ||
} |
68 changes: 68 additions & 0 deletions
68
src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include "SimplnxCore/SimplnxCore_export.hpp" | ||
|
||
#include "simplnx/DataStructure/DataPath.hpp" | ||
#include "simplnx/DataStructure/DataStructure.hpp" | ||
#include "simplnx/Filter/IFilter.hpp" | ||
#include "simplnx/Parameters/FileSystemPathParameter.hpp" | ||
#include "simplnx/Parameters/MultiArraySelectionParameter.hpp" | ||
|
||
namespace nx::core | ||
{ | ||
class ImageGeom; | ||
class IDataArray; | ||
|
||
struct SIMPLNXCORE_EXPORT WriteVtkStructuredPointsInputValues | ||
{ | ||
FileSystemPathParameter::ValueType OutputFile; | ||
bool WriteBinaryFile; | ||
DataPath ImageGeometryPath; | ||
MultiArraySelectionParameter::ValueType SelectedDataArrayPaths; | ||
}; | ||
|
||
/** | ||
* @class VtkRectilinearGridWriter | ||
* @brief This filter ... | ||
*/ | ||
|
||
class SIMPLNXCORE_EXPORT WriteVtkStructuredPoints | ||
{ | ||
public: | ||
WriteVtkStructuredPoints(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, WriteVtkStructuredPointsInputValues* inputValues); | ||
~WriteVtkStructuredPoints() noexcept; | ||
|
||
WriteVtkStructuredPoints(const WriteVtkStructuredPoints&) = delete; | ||
WriteVtkStructuredPoints(WriteVtkStructuredPoints&&) noexcept = delete; | ||
WriteVtkStructuredPoints& operator=(const WriteVtkStructuredPoints&) = delete; | ||
WriteVtkStructuredPoints& operator=(WriteVtkStructuredPoints&&) noexcept = delete; | ||
|
||
Result<> operator()(); | ||
|
||
const std::atomic_bool& getCancel(); | ||
|
||
void writeVtkHeader(FILE* outputFile) const; | ||
|
||
/** | ||
* @brief This function writes a set of Axis coordinates to that are needed | ||
* for a Rectilinear Grid based data set. | ||
* @param outputFile The "C" FILE* pointer to the file being written to. | ||
* @param axis The name of the Axis that is being written | ||
* @param type The type of primitive being written (float, int, ...) | ||
* @param nPoints The total number of points in the array | ||
* @param min The minimum value of the axis | ||
* @param max The maximum value of the axis | ||
* @param step The step value between each point on the axis. | ||
* @param binary Whether or not to write the vtk file data in binary | ||
*/ | ||
template <typename T> | ||
Result<> writeCoords(FILE* outputFile, const std::string& axis, const std::string& type, int64 nPoints, T min, T max, T step); | ||
|
||
private: | ||
DataStructure& m_DataStructure; | ||
const WriteVtkStructuredPointsInputValues* m_InputValues = nullptr; | ||
const std::atomic_bool& m_ShouldCancel; | ||
const IFilter::MessageHandler& m_MessageHandler; | ||
}; | ||
|
||
} // namespace nx::core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.