Skip to content

Commit

Permalink
FILT: WriteVtkStructuredPoints implemented
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Jackson <[email protected]>
  • Loading branch information
imikejackson committed Mar 22, 2024
1 parent 8e46119 commit 2c9a894
Show file tree
Hide file tree
Showing 11 changed files with 496 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/Plugins/SimplnxCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ set(FilterList
WriteLosAlamosFFTFilter
WriteStlFileFilter
WriteVtkRectilinearGridFilter
WriteVtkStructuredPointsFilter
ReadVtkStructuredPointsFilter
)

Expand Down Expand Up @@ -208,6 +209,7 @@ set(AlgorithmList
WriteLosAlamosFFT
WriteStlFile
WriteVtkRectilinearGrid
WriteVtkStructuredPoints
ReadVtkStructuredPoints
)

Expand Down Expand Up @@ -321,7 +323,7 @@ set(PLUGIN_EXTRA_SOURCES
"${${PLUGIN_NAME}_SOURCE_DIR}/src/${PLUGIN_NAME}/utils/AvizoWriter.hpp"
"${${PLUGIN_NAME}_SOURCE_DIR}/src/${PLUGIN_NAME}/utils/AvizoWriter.cpp"
"${${PLUGIN_NAME}_SOURCE_DIR}/src/${PLUGIN_NAME}/utils/PythonPluginTemplateFile.hpp"

"${${PLUGIN_NAME}_SOURCE_DIR}/src/${PLUGIN_NAME}/utils/VtkUtilities.hpp"
"${${PLUGIN_NAME}_SOURCE_DIR}/src/${PLUGIN_NAME}/SurfaceNets/MMCellFlag.cpp"
"${${PLUGIN_NAME}_SOURCE_DIR}/src/${PLUGIN_NAME}/SurfaceNets/MMCellFlag.h"
"${${PLUGIN_NAME}_SOURCE_DIR}/src/${PLUGIN_NAME}/SurfaceNets/MMCellMap.cpp"
Expand Down
21 changes: 21 additions & 0 deletions src/Plugins/SimplnxCore/docs/WriteVtkStructuredPointsFilter.md
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.
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

View workflow job for this annotation

GitHub Actions / build (windows-2022, v142)

'initializing': cannot convert from 'const nx::core::FileSystemPathParameter::ValueType' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' [D:\a\simplnx\simplnx\build\Plugins\SimplnxCore\SimplnxCore.vcxproj]

Check failure on line 44 in src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/WriteVtkStructuredPoints.cpp

View workflow job for this annotation

GitHub Actions / build (windows-2022, v143)

'initializing': cannot convert from 'const nx::core::FileSystemPathParameter::ValueType' to 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' [D:\a\simplnx\simplnx\build\Plugins\SimplnxCore\SimplnxCore.vcxproj]
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;
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::string WriteVtkRectilinearGridFilter::humanName() const
//------------------------------------------------------------------------------
std::vector<std::string> WriteVtkRectilinearGridFilter::defaultTags() const
{
return {className(), "IO", "Output", "Write", "Export"};
return {className(), "IO", "Output", "Write", "Export", "Vtk", "Rectilinear Grid"};
}

//------------------------------------------------------------------------------
Expand All @@ -55,7 +55,7 @@ Parameters WriteVtkRectilinearGridFilter::parameters() const
Parameters params;

// Create the parameter descriptors that are needed for this filter
params.insert(std::make_unique<FileSystemPathParameter>(k_OutputFile_Key, "Output File", "The output vtk file in which the geometry data is written", fs::path("Data/Output/RectilinearGrid.vtk"),
params.insert(std::make_unique<FileSystemPathParameter>(k_OutputFile_Key, "Output File", "The output vtk file in which the geometry data is written", fs::path("data.vtk"),
FileSystemPathParameter::ExtensionsType{".vtk"}, FileSystemPathParameter::PathType::OutputFile));
params.insert(std::make_unique<BoolParameter>(k_WriteBinaryFile_Key, "Write Binary File", "Whether or not to write the vtk file in binary", false));
params.insert(std::make_unique<GeometrySelectionParameter>(k_ImageGeometryPath_Key, "Image Geometry", "The path to the image geometry in which to write out to the vtk file", DataPath{},
Expand Down
Loading

0 comments on commit 2c9a894

Please sign in to comment.