Skip to content

Commit

Permalink
Tweak filter name and add documentation.
Browse files Browse the repository at this point in the history
Signed-off-by: Joey Kleingers <[email protected]>
  • Loading branch information
joeykleingers committed Jan 2, 2025
1 parent 46c0865 commit 54d4500
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 87 deletions.
4 changes: 2 additions & 2 deletions src/Plugins/SimplnxCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ set(FilterList
WriteDREAM3DFilter
WriteFeatureDataCSVFilter
WriteLosAlamosFFTFilter
WriteNodesAndElementsFileFilter
WriteNodesAndElementsFilesFilter
WriteStlFileFilter
WriteVtkRectilinearGridFilter
WriteVtkStructuredPointsFilter
Expand Down Expand Up @@ -227,7 +227,7 @@ set(AlgorithmList
WriteAvizoRectilinearCoordinate
WriteAvizoUniformCoordinate
WriteLosAlamosFFT
WriteNodesAndElementsFile
WriteNodesAndElementsFiles
WriteStlFile
WriteVtkRectilinearGrid
WriteVtkStructuredPoints
Expand Down
24 changes: 24 additions & 0 deletions src/Plugins/SimplnxCore/docs/WriteNodesAndElementsFilesFilter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Write Nodes and Elements File(s)

## Group (Subgroup)

IO (Output)

## Description

This **Filter** exports geometric data into structured text files. It allows users to save the following:

1. Node Data (Vertices): Export the coordinates of points that define the geometry.
2. Element Data (Connectivity): Export the node indices that make up the edges, faces, or volumes of the geometry.

The filter gives the user the option to export a node file, element file, or both. It also allows the user to decide whether or not to number the nodes and elements and whether or not to include headers for the node and element files.

% Auto generated parameter table will be inserted here

## 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
@@ -1,4 +1,4 @@
#include "WriteNodesAndElementsFile.hpp"
#include "WriteNodesAndElementsFiles.hpp"

#include "simplnx/DataStructure/DataArray.hpp"
#include "simplnx/DataStructure/Geometry/EdgeGeom.hpp"
Expand Down Expand Up @@ -40,7 +40,7 @@ Result<> WriteFile(const fs::path& outputFilePath, const DataArray<T>& array, bo
std::ofstream file(outputFilePath.string());
if(!file.is_open())
{
return MakeErrorResult(to_underlying(WriteNodesAndElementsFile::ErrorCodes::FailedToOpenOutputFile), fmt::format("Failed to open output file \"{}\".", outputFilePath.string()));
return MakeErrorResult(to_underlying(WriteNodesAndElementsFiles::ErrorCodes::FailedToOpenOutputFile), fmt::format("Failed to open output file \"{}\".", outputFilePath.string()));
}

file << fmt::format("# This file was created by simplnx v{}", Version::Complete()) << std::endl;
Expand Down Expand Up @@ -81,8 +81,8 @@ Result<> WriteFile(const fs::path& outputFilePath, const DataArray<T>& array, bo
} // namespace

// -----------------------------------------------------------------------------
WriteNodesAndElementsFile::WriteNodesAndElementsFile(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel,
WriteNodesAndElementsFileInputValues* inputValues)
WriteNodesAndElementsFiles::WriteNodesAndElementsFiles(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel,
WriteNodesAndElementsFilesInputValues* inputValues)
: m_DataStructure(dataStructure)
, m_InputValues(inputValues)
, m_ShouldCancel(shouldCancel)
Expand All @@ -91,22 +91,22 @@ WriteNodesAndElementsFile::WriteNodesAndElementsFile(DataStructure& dataStructur
}

// -----------------------------------------------------------------------------
WriteNodesAndElementsFile::~WriteNodesAndElementsFile() noexcept = default;
WriteNodesAndElementsFiles::~WriteNodesAndElementsFiles() noexcept = default;

// -----------------------------------------------------------------------------
const std::atomic_bool& WriteNodesAndElementsFile::getCancel()
const std::atomic_bool& WriteNodesAndElementsFiles::getCancel()
{
return m_ShouldCancel;
}

// -----------------------------------------------------------------------------
void WriteNodesAndElementsFile::sendMessage(const std::string& message)
void WriteNodesAndElementsFiles::sendMessage(const std::string& message)
{
m_MessageHandler(IFilter::Message::Type::Info, message);
}

// -----------------------------------------------------------------------------
Result<> WriteNodesAndElementsFile::operator()()
Result<> WriteNodesAndElementsFiles::operator()()
{
auto& iNodeGeometry = m_DataStructure.getDataRefAs<INodeGeometry0D>(m_InputValues->SelectedGeometryPath);
auto geomType = iNodeGeometry.getGeomType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace fs = std::filesystem;
namespace nx::core
{

struct SIMPLNXCORE_EXPORT WriteNodesAndElementsFileInputValues
struct SIMPLNXCORE_EXPORT WriteNodesAndElementsFilesInputValues
{
DataPath SelectedGeometryPath;
bool WriteNodeFile;
Expand All @@ -31,16 +31,16 @@ struct SIMPLNXCORE_EXPORT WriteNodesAndElementsFileInputValues
/**
* @class
*/
class SIMPLNXCORE_EXPORT WriteNodesAndElementsFile
class SIMPLNXCORE_EXPORT WriteNodesAndElementsFiles
{
public:
WriteNodesAndElementsFile(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, WriteNodesAndElementsFileInputValues* inputValues);
~WriteNodesAndElementsFile() noexcept;
WriteNodesAndElementsFiles(DataStructure& dataStructure, const IFilter::MessageHandler& mesgHandler, const std::atomic_bool& shouldCancel, WriteNodesAndElementsFilesInputValues* inputValues);
~WriteNodesAndElementsFiles() noexcept;

WriteNodesAndElementsFile(const WriteNodesAndElementsFile&) = delete;
WriteNodesAndElementsFile(WriteNodesAndElementsFile&&) noexcept = delete;
WriteNodesAndElementsFile& operator=(const WriteNodesAndElementsFile&) = delete;
WriteNodesAndElementsFile& operator=(WriteNodesAndElementsFile&&) noexcept = delete;
WriteNodesAndElementsFiles(const WriteNodesAndElementsFiles&) = delete;
WriteNodesAndElementsFiles(WriteNodesAndElementsFiles&&) noexcept = delete;
WriteNodesAndElementsFiles& operator=(const WriteNodesAndElementsFiles&) = delete;
WriteNodesAndElementsFiles& operator=(WriteNodesAndElementsFiles&&) noexcept = delete;

enum class ErrorCodes : int64
{
Expand All @@ -58,7 +58,7 @@ class SIMPLNXCORE_EXPORT WriteNodesAndElementsFile

private:
DataStructure& m_DataStructure;
const WriteNodesAndElementsFileInputValues* m_InputValues = nullptr;
const WriteNodesAndElementsFilesInputValues* m_InputValues = nullptr;
const std::atomic_bool& m_ShouldCancel;
const IFilter::MessageHandler& m_MessageHandler;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "WriteNodesAndElementsFileFilter.hpp"
#include "WriteNodesAndElementsFilesFilter.hpp"

#include "simplnx/Common/TypeTraits.hpp"
#include "simplnx/DataStructure/DataGroup.hpp"
Expand All @@ -9,45 +9,45 @@
#include "simplnx/Pipeline/PipelineFilter.hpp"
#include "simplnx/Utilities/SIMPLConversion.hpp"

#include "SimplnxCore/Filters/Algorithms/WriteNodesAndElementsFile.hpp"
#include "SimplnxCore/Filters/Algorithms/WriteNodesAndElementsFiles.hpp"

#include <filesystem>
namespace fs = std::filesystem;

namespace nx::core
{
//------------------------------------------------------------------------------
std::string WriteNodesAndElementsFileFilter::name() const
std::string WriteNodesAndElementsFilesFilter::name() const
{
return FilterTraits<WriteNodesAndElementsFileFilter>::name;
return FilterTraits<WriteNodesAndElementsFilesFilter>::name;
}

//------------------------------------------------------------------------------
std::string WriteNodesAndElementsFileFilter::className() const
std::string WriteNodesAndElementsFilesFilter::className() const
{
return FilterTraits<WriteNodesAndElementsFileFilter>::className;
return FilterTraits<WriteNodesAndElementsFilesFilter>::className;
}

//------------------------------------------------------------------------------
Uuid WriteNodesAndElementsFileFilter::uuid() const
Uuid WriteNodesAndElementsFilesFilter::uuid() const
{
return FilterTraits<WriteNodesAndElementsFileFilter>::uuid;
return FilterTraits<WriteNodesAndElementsFilesFilter>::uuid;
}

//------------------------------------------------------------------------------
std::string WriteNodesAndElementsFileFilter::humanName() const
std::string WriteNodesAndElementsFilesFilter::humanName() const
{
return "Write Nodes And Elements File(s)";
}

//------------------------------------------------------------------------------
std::vector<std::string> WriteNodesAndElementsFileFilter::defaultTags() const
std::vector<std::string> WriteNodesAndElementsFilesFilter::defaultTags() const
{
return {className(), "IO", "Output", "Write", "Export", "Nodes", "Elements", "Cells", "Vertices", "Geometry"};
}

//------------------------------------------------------------------------------
Parameters WriteNodesAndElementsFileFilter::parameters() const
Parameters WriteNodesAndElementsFilesFilter::parameters() const
{
Parameters params;

Expand Down Expand Up @@ -80,20 +80,20 @@ Parameters WriteNodesAndElementsFileFilter::parameters() const
}

//------------------------------------------------------------------------------
IFilter::VersionType WriteNodesAndElementsFileFilter::parametersVersion() const
IFilter::VersionType WriteNodesAndElementsFilesFilter::parametersVersion() const
{
return 1;
}

//------------------------------------------------------------------------------
IFilter::UniquePointer WriteNodesAndElementsFileFilter::clone() const
IFilter::UniquePointer WriteNodesAndElementsFilesFilter::clone() const
{
return std::make_unique<WriteNodesAndElementsFileFilter>();
return std::make_unique<WriteNodesAndElementsFilesFilter>();
}

//------------------------------------------------------------------------------
IFilter::PreflightResult WriteNodesAndElementsFileFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& args, const MessageHandler& messageHandler,
const std::atomic_bool& shouldCancel) const
IFilter::PreflightResult WriteNodesAndElementsFilesFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& args, const MessageHandler& messageHandler,
const std::atomic_bool& shouldCancel) const
{
DataPath selectedGeometryPath = args.value<GeometrySelectionParameter::ValueType>(k_SelectedGeometry);
bool writeNodeFile = args.value<BoolParameter::ValueType>(k_WriteNodeFile);
Expand All @@ -105,26 +105,26 @@ IFilter::PreflightResult WriteNodesAndElementsFileFilter::preflightImpl(const Da

if(!writeNodeFile && !writeElementFile)
{
return {MakeErrorResult<OutputActions>(to_underlying(WriteNodesAndElementsFile::ErrorCodes::NoFileWriterChosen),
return {MakeErrorResult<OutputActions>(to_underlying(WriteNodesAndElementsFiles::ErrorCodes::NoFileWriterChosen),
"Neither 'Write Node File' nor 'Write Element/Cell File' have been chosen. Please choose at least one of these options.")};
}

auto& selectedGeometry = dataStructure.getDataRefAs<IGeometry>(selectedGeometryPath);
if(selectedGeometry.getGeomType() == IGeometry::Type::Vertex && writeElementFile)
{
return {MakeErrorResult<OutputActions>(
to_underlying(WriteNodesAndElementsFile::ErrorCodes::VertexGeomHasNoElements),
to_underlying(WriteNodesAndElementsFiles::ErrorCodes::VertexGeomHasNoElements),
"The selected geometry is a vertex geometry, so an element file cannot be written. Please turn off 'Write Element/Cell File' or select a different geometry with a type other than Vertex.")};
}

return {};
}

//------------------------------------------------------------------------------
Result<> WriteNodesAndElementsFileFilter::executeImpl(DataStructure& dataStructure, const Arguments& args, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler,
const std::atomic_bool& shouldCancel) const
Result<> WriteNodesAndElementsFilesFilter::executeImpl(DataStructure& dataStructure, const Arguments& args, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler,
const std::atomic_bool& shouldCancel) const
{
WriteNodesAndElementsFileInputValues inputValues;
WriteNodesAndElementsFilesInputValues inputValues;

inputValues.SelectedGeometryPath = args.value<GeometrySelectionParameter::ValueType>(k_SelectedGeometry);
inputValues.WriteNodeFile = args.value<BoolParameter::ValueType>(k_WriteNodeFile);
Expand All @@ -136,6 +136,6 @@ Result<> WriteNodesAndElementsFileFilter::executeImpl(DataStructure& dataStructu
inputValues.IncludeElementFileHeader = args.value<BoolParameter::ValueType>(k_IncludeElementFileHeader);
inputValues.ElementFilePath = args.value<FileSystemPathParameter::ValueType>(k_ElementFilePath);

return WriteNodesAndElementsFile(dataStructure, messageHandler, shouldCancel, &inputValues)();
return WriteNodesAndElementsFiles(dataStructure, messageHandler, shouldCancel, &inputValues)();
}
} // namespace nx::core
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
namespace nx::core
{
/**
* @class WriteNodesAndElementsFileFilter
* @brief The WriteNodesAndElementsFileFilter is an IFilter class designed to export the
* @class WriteNodesAndElementsFilesFilter
* @brief The WriteNodesAndElementsFilesFilter is an IFilter class designed to export the
* DataStructure to a target HDF5 file.
*/
class SIMPLNXCORE_EXPORT WriteNodesAndElementsFileFilter : public IFilter
class SIMPLNXCORE_EXPORT WriteNodesAndElementsFilesFilter : public IFilter
{
public:
WriteNodesAndElementsFileFilter() = default;
~WriteNodesAndElementsFileFilter() noexcept override = default;
WriteNodesAndElementsFilesFilter() = default;
~WriteNodesAndElementsFilesFilter() noexcept override = default;

WriteNodesAndElementsFileFilter(const WriteNodesAndElementsFileFilter&) = delete;
WriteNodesAndElementsFileFilter(WriteNodesAndElementsFileFilter&&) noexcept = delete;
WriteNodesAndElementsFilesFilter(const WriteNodesAndElementsFilesFilter&) = delete;
WriteNodesAndElementsFilesFilter(WriteNodesAndElementsFilesFilter&&) noexcept = delete;

WriteNodesAndElementsFileFilter& operator=(const WriteNodesAndElementsFileFilter&) = delete;
WriteNodesAndElementsFileFilter& operator=(WriteNodesAndElementsFileFilter&&) noexcept = delete;
WriteNodesAndElementsFilesFilter& operator=(const WriteNodesAndElementsFilesFilter&) = delete;
WriteNodesAndElementsFilesFilter& operator=(WriteNodesAndElementsFilesFilter&&) noexcept = delete;

// Parameter Keys
static inline constexpr StringLiteral k_SelectedGeometry = "selected_geometry_path";
Expand Down Expand Up @@ -57,7 +57,7 @@ class SIMPLNXCORE_EXPORT WriteNodesAndElementsFileFilter : public IFilter
std::string className() const override;

/**
* @brief Returns the WriteNodesAndElementsFileFilter class's UUID.
* @brief Returns the WriteNodesAndElementsFilesFilter class's UUID.
* @return Uuid
*/
Uuid uuid() const override;
Expand Down Expand Up @@ -119,4 +119,4 @@ class SIMPLNXCORE_EXPORT WriteNodesAndElementsFileFilter : public IFilter
};
} // namespace nx::core

SIMPLNX_DEF_FILTER_TRAITS(nx::core, WriteNodesAndElementsFileFilter, "8c563174-0183-45fe-8ef8-756104f215d5");
SIMPLNX_DEF_FILTER_TRAITS(nx::core, WriteNodesAndElementsFilesFilter, "8c563174-0183-45fe-8ef8-756104f215d5");
2 changes: 1 addition & 1 deletion src/Plugins/SimplnxCore/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ set(${PLUGIN_NAME}UnitTest_SRCS
WriteBinaryDataTest.cpp
WriteFeatureDataCSVTest.cpp
WriteLosAlamosFFTTest.cpp
WriteNodesAndElementsFileTest.cpp
WriteNodesAndElementsFilesTest.cpp
WriteStlFileTest.cpp
WriteVtkRectilinearGridTest.cpp
)
Expand Down
Loading

0 comments on commit 54d4500

Please sign in to comment.