Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wasm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ add_test(NAME write-parameter-files-multiple-test
add_test(NAME default-parameter-map-test
COMMAND default-parameter-map
affine
${CMAKE_CURRENT_BINARY_DIR}/affine_default_parameters.json
${CMAKE_CURRENT_BINARY_DIR}/affine_default_parameters.toml
)
35 changes: 6 additions & 29 deletions wasm/default-parameter-map.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
#include "elxParameterObject.h"
#include "itkPipeline.h"
#include "itkOutputTextStream.h"

#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/stringbuffer.h"
#include "Install/elxConversion.h"

int
main(int argc, char * argv[])
Expand All @@ -44,38 +41,18 @@ main(int argc, char * argv[])
finalGridSpacingInPhysicalUnits,
"Final grid spacing in physical units for bspline transforms.");

itk::wasm::OutputTextStream parameterMapJson;
pipeline.add_option("parameter-map", parameterMapJson, "Elastix parameter map representation")
itk::wasm::OutputTextStream outputTextStream;
pipeline.add_option("parameter-map", outputTextStream, "Elastix parameter map representation")
->required()
->type_name("OUTPUT_JSON");
->type_name("OUTPUT_TEXT_STREAM");

ITK_WASM_PARSE(pipeline);

using ParameterObjectType = elastix::ParameterObject;
auto parameterMap =
ParameterObjectType::GetDefaultParameterMap(transformName, numberOfResolutions, finalGridSpacingInPhysicalUnits);

rapidjson::Document document;
document.SetObject();
rapidjson::Document::AllocatorType & allocator = document.GetAllocator();

for (const auto & parameter : parameterMap)
{
const auto & key = parameter.first;
const auto & value = parameter.second;
rapidjson::Value valueJson(rapidjson::kArrayType);
for (const auto & valueElement : value)
{
valueJson.PushBack(rapidjson::Value(valueElement.c_str(), allocator).Move(), allocator);
}
document.AddMember(rapidjson::Value(key.c_str(), allocator).Move(), valueJson, allocator);
}

rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);

parameterMapJson.Get() << buffer.GetString();

outputTextStream.Get() << elastix::Conversion::ParameterMapToString(parameterMap,
elastix::ParameterMapStringFormat::Toml);
return EXIT_SUCCESS;
}
Loading