-
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.
FILTER : ExtractPipelineToFile added (#897)
This filter extracts the JSON formatted pipeline from either a DREAM3D version 6 or DREAM3D-NX version 7 .dream3d file and saves that pipeline into a file on the local drive.
- Loading branch information
1 parent
a51dd5f
commit 8b74807
Showing
8 changed files
with
437 additions
and
1 deletion.
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
15 changes: 15 additions & 0 deletions
15
src/Plugins/SimplnxCore/docs/ExtractPipelineToFileFilter.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,15 @@ | ||
# Extract DREAM.3D Pipeline To File | ||
|
||
## Description | ||
|
||
This **Filter** reads the pipeline from an hdf5 file with the .dream3d extension and writes it back out to a json formatted pipeline file with the appropriate extension based on whether the pipeline is a DREAM.3D version 6 (.json) or DREAM3D-NX version 7 (.d3dpipeline) formatted pipeline. | ||
|
||
% Auto generated parameter table will be inserted here | ||
|
||
## Example Pipelines | ||
|
||
ExtractPipelineToFile | ||
|
||
## License & Copyright | ||
|
||
Please see the description file distributed with this plugin. |
21 changes: 21 additions & 0 deletions
21
src/Plugins/SimplnxCore/pipelines/ExtractPipelineToFile.d3dpipeline
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 @@ | ||
{ | ||
"isDisabled": false, | ||
"name": "ExtractPipelineToFile.d3dpipeline", | ||
"pinnedParams": [], | ||
"pipeline": [ | ||
{ | ||
"args": { | ||
"input_file_path": "Data/Output/Reconstruction/SmallIN100_Final.dream3d", | ||
"output_file_path": "Data/Output/Reconstruction/SmallIN100_Final_Pipeline.d3dpipeline" | ||
}, | ||
"comments": "", | ||
"filter": { | ||
"name": "nx::core::ExtractPipelineToFileFilter", | ||
"uuid": "27203c99-9975-4528-88cc-42b270165d79" | ||
}, | ||
"isDisabled": false | ||
} | ||
], | ||
"version": 1, | ||
"workflowParams": [] | ||
} |
151 changes: 151 additions & 0 deletions
151
src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ExtractPipelineToFileFilter.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,151 @@ | ||
#include "ExtractPipelineToFileFilter.hpp" | ||
|
||
#include "simplnx/Common/AtomicFile.hpp" | ||
#include "simplnx/Common/StringLiteral.hpp" | ||
#include "simplnx/Parameters/FileSystemPathParameter.hpp" | ||
#include "simplnx/Parameters/StringParameter.hpp" | ||
#include "simplnx/Pipeline/Pipeline.hpp" | ||
#include "simplnx/Utilities/Parsing/DREAM3D/Dream3dIO.hpp" | ||
|
||
#include "simplnx/Utilities/SIMPLConversion.hpp" | ||
|
||
#include <nlohmann/json.hpp> | ||
|
||
namespace | ||
{ | ||
constexpr nx::core::StringLiteral k_ImportedPipeline = "Imported Pipeline"; | ||
} // namespace | ||
|
||
namespace nx::core | ||
{ | ||
//------------------------------------------------------------------------------ | ||
std::string ExtractPipelineToFileFilter::name() const | ||
{ | ||
return FilterTraits<ExtractPipelineToFileFilter>::name; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
std::string ExtractPipelineToFileFilter::className() const | ||
{ | ||
return FilterTraits<ExtractPipelineToFileFilter>::className; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
Uuid ExtractPipelineToFileFilter::uuid() const | ||
{ | ||
return FilterTraits<ExtractPipelineToFileFilter>::uuid; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
std::string ExtractPipelineToFileFilter::humanName() const | ||
{ | ||
return "Extract DREAM.3D Pipeline To File"; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
std::vector<std::string> ExtractPipelineToFileFilter::defaultTags() const | ||
{ | ||
return {className(), "IO", "Input", "Read", "Import", "Output", "Write", "Export", "Pipeline", "JSON"}; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
Parameters ExtractPipelineToFileFilter::parameters() const | ||
{ | ||
Parameters params; | ||
params.insertSeparator(Parameters::Separator{"Input Parameters"}); | ||
params.insert(std::make_unique<FileSystemPathParameter>(k_ImportFileData, "Input DREAM3D File Path", "The file path to the .dream3d that holds the pipeline to be extracted.", | ||
FileSystemPathParameter::ValueType{}, FileSystemPathParameter::ExtensionsType{".dream3d"}, FileSystemPathParameter::PathType::InputFile)); | ||
params.insertSeparator(Parameters::Separator{"Output Parameters"}); | ||
params.insert(std::make_unique<FileSystemPathParameter>(k_OutputFile, "Output File Path", "The file path in which to save the extracted pipeline", FileSystemPathParameter::ValueType{}, | ||
FileSystemPathParameter::ExtensionsType{Pipeline::k_Extension, Pipeline::k_SIMPLExtension}, FileSystemPathParameter::PathType::OutputFile)); | ||
return params; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
IFilter::UniquePointer ExtractPipelineToFileFilter::clone() const | ||
{ | ||
return std::make_unique<ExtractPipelineToFileFilter>(); | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
IFilter::PreflightResult ExtractPipelineToFileFilter::preflightImpl(const DataStructure& dataStructure, const Arguments& args, const MessageHandler& messageHandler, | ||
const std::atomic_bool& shouldCancel) const | ||
{ | ||
const auto importFile = args.value<FileSystemPathParameter::ValueType>(k_ImportFileData); | ||
auto outputFile = args.value<FileSystemPathParameter::ValueType>(k_OutputFile); | ||
|
||
Result<nlohmann::json> pipelineResult = DREAM3D::ImportPipelineJsonFromFile(importFile); | ||
if(pipelineResult.invalid()) | ||
{ | ||
return {ConvertInvalidResult<OutputActions, nlohmann::json>(std::move(pipelineResult))}; | ||
} | ||
|
||
Result<OutputActions> results; | ||
|
||
const nlohmann::json pipelineJson = pipelineResult.value(); | ||
const bool isLegacy = pipelineJson.contains(nx::core::Pipeline::k_SIMPLPipelineBuilderKey); | ||
|
||
fs::path finalOutputPath = outputFile; | ||
std::string extension = isLegacy ? Pipeline::k_SIMPLExtension : Pipeline::k_Extension; | ||
if(!finalOutputPath.has_extension()) | ||
{ | ||
finalOutputPath.concat(extension); | ||
results.warnings().push_back(Warning{ | ||
-2580, fmt::format("Output file '{}' is missing an extension. A {} extension will be added to the provided output file so that the extracted pipeline will be written to the file at path '{}'", | ||
outputFile.string(), extension, finalOutputPath.string())}); | ||
} | ||
if(finalOutputPath.extension().string() != extension) | ||
{ | ||
finalOutputPath.replace_extension(extension); | ||
results.warnings().push_back( | ||
Warning{-2581, fmt::format("Output file '{}' has the incorrect extension. A {} extension will be used instead so that the extracted pipeline will be written to the file at path '{}'", | ||
outputFile.string(), extension, finalOutputPath.string())}); | ||
} | ||
|
||
return {results}; | ||
} | ||
|
||
//------------------------------------------------------------------------------ | ||
Result<> ExtractPipelineToFileFilter::executeImpl(DataStructure& dataStructure, const Arguments& args, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler, | ||
const std::atomic_bool& shouldCancel) const | ||
{ | ||
const auto importFile = args.value<FileSystemPathParameter::ValueType>(k_ImportFileData); | ||
auto outputFile = args.value<FileSystemPathParameter::ValueType>(k_OutputFile); | ||
|
||
Result<nlohmann::json> pipelineResult = DREAM3D::ImportPipelineJsonFromFile(importFile); | ||
if(pipelineResult.invalid()) | ||
{ | ||
return ConvertResult<nlohmann::json>(std::move(pipelineResult)); | ||
} | ||
const nlohmann::json pipelineJson = pipelineResult.value(); | ||
const bool isLegacy = pipelineJson.contains(nx::core::Pipeline::k_SIMPLPipelineBuilderKey); | ||
|
||
std::string extension = isLegacy ? Pipeline::k_SIMPLExtension : Pipeline::k_Extension; | ||
if(!outputFile.has_extension()) | ||
{ | ||
outputFile.concat(extension); | ||
} | ||
if(outputFile.extension().string() != extension) | ||
{ | ||
outputFile.replace_extension(extension); | ||
} | ||
AtomicFile atomicFile(outputFile.string(), false); | ||
{ | ||
const fs::path exportFilePath = atomicFile.tempFilePath(); | ||
std::ofstream fOut(exportFilePath.string(), std::ofstream::out); // test name resolution and create file | ||
if(!fOut.is_open()) | ||
{ | ||
return MakeErrorResult(-2582, fmt::format("Error opening output path {}", exportFilePath.string())); | ||
} | ||
|
||
fOut << pipelineJson.dump(2); | ||
} | ||
atomicFile.commit(); | ||
return {}; | ||
} | ||
|
||
Result<Arguments> ExtractPipelineToFileFilter::FromSIMPLJson(const nlohmann::json& json) | ||
{ | ||
return {}; | ||
} | ||
} // namespace nx::core |
107 changes: 107 additions & 0 deletions
107
src/Plugins/SimplnxCore/src/SimplnxCore/Filters/ExtractPipelineToFileFilter.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,107 @@ | ||
#pragma once | ||
|
||
#include "SimplnxCore/SimplnxCore_export.hpp" | ||
|
||
#include "simplnx/Filter/Arguments.hpp" | ||
#include "simplnx/Filter/FilterTraits.hpp" | ||
#include "simplnx/Filter/IFilter.hpp" | ||
#include "simplnx/Filter/Parameters.hpp" | ||
|
||
namespace nx::core | ||
{ | ||
/** | ||
* @class ExtractPipelineToFileFilter | ||
* @brief The ExtractPipelineToFileFilter is an IFilter class designed to extract the pipeline data | ||
* from a target DREAM.3D file and export it out to it's own file. | ||
*/ | ||
class SIMPLNXCORE_EXPORT ExtractPipelineToFileFilter : public IFilter | ||
{ | ||
public: | ||
ExtractPipelineToFileFilter() = default; | ||
~ExtractPipelineToFileFilter() noexcept override = default; | ||
|
||
ExtractPipelineToFileFilter(const ExtractPipelineToFileFilter&) = delete; | ||
ExtractPipelineToFileFilter(ExtractPipelineToFileFilter&&) noexcept = delete; | ||
|
||
ExtractPipelineToFileFilter& operator=(const ExtractPipelineToFileFilter&) = delete; | ||
ExtractPipelineToFileFilter& operator=(ExtractPipelineToFileFilter&&) noexcept = delete; | ||
|
||
// Parameter Keys | ||
static inline constexpr StringLiteral k_ImportFileData = "input_file_path"; | ||
static inline constexpr StringLiteral k_OutputFile = "output_file_path"; | ||
|
||
/** | ||
* @brief Reads SIMPL json and converts it simplnx Arguments. | ||
* @param json | ||
* @return Result<Arguments> | ||
*/ | ||
static Result<Arguments> FromSIMPLJson(const nlohmann::json& json); | ||
|
||
/** | ||
* @brief Returns the name of the filter class. | ||
* @return std::string | ||
*/ | ||
std::string name() const override; | ||
|
||
/** | ||
* @brief Returns the C++ classname of this filter. | ||
* @return std::string | ||
*/ | ||
std::string className() const override; | ||
|
||
/** | ||
* @brief Returns the ExtractPipelineToFileFilter class's UUID. | ||
* @return Uuid | ||
*/ | ||
Uuid uuid() const override; | ||
|
||
/** | ||
* @brief Returns the human readable name of the filter. | ||
* @return std::string | ||
*/ | ||
std::string humanName() const override; | ||
|
||
/** | ||
* @brief Returns the default tags for this filter. | ||
* @return | ||
*/ | ||
std::vector<std::string> defaultTags() const override; | ||
|
||
/** | ||
* @brief Returns a collection of the filter's parameters (i.e. its inputs) | ||
* @return Parameters | ||
*/ | ||
Parameters parameters() const override; | ||
|
||
/** | ||
* @brief Returns a copy of the filter as a std::unique_ptr. | ||
* @return UniquePointer | ||
*/ | ||
UniquePointer clone() const override; | ||
|
||
protected: | ||
/** | ||
* @brief Classes that implement IFilter must provide this function for preflight. | ||
* Runs after the filter runs the checks in its parameters. | ||
* @param dataStructure | ||
* @param args | ||
* @param messageHandler | ||
* @return Result<OutputActions> | ||
*/ | ||
PreflightResult preflightImpl(const DataStructure& dataStructure, const Arguments& args, const MessageHandler& messageHandler, const std::atomic_bool& shouldCancel) const override; | ||
|
||
/** | ||
* @brief Classes that implement IFilter must provide this function for execute. | ||
* Runs after the filter applies the OutputActions from preflight. | ||
* @param dataStructure | ||
* @param args | ||
* @param pipelineNode | ||
* @param messageHandler | ||
* @return Result<> | ||
*/ | ||
Result<> executeImpl(DataStructure& dataStructure, const Arguments& args, const PipelineFilter* pipelineNode, const MessageHandler& messageHandler, | ||
const std::atomic_bool& shouldCancel) const override; | ||
}; | ||
} // namespace nx::core | ||
|
||
SIMPLNX_DEF_FILTER_TRAITS(nx::core, ExtractPipelineToFileFilter, "27203c99-9975-4528-88cc-42b270165d79"); |
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.