From d17f4633feb266a7d0e8d4a0dfac7c08f1515d28 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Tue, 3 Dec 2024 07:58:29 -0500 Subject: [PATCH] DOC: Add untested Python example script --- examples/ReadWriteMZ3Mesh.py | 38 ++++++++++++++++++++++++++++++++ examples/WriteMZ3Mesh.py | 42 ------------------------------------ 2 files changed, 38 insertions(+), 42 deletions(-) create mode 100644 examples/ReadWriteMZ3Mesh.py delete mode 100644 examples/WriteMZ3Mesh.py diff --git a/examples/ReadWriteMZ3Mesh.py b/examples/ReadWriteMZ3Mesh.py new file mode 100644 index 0000000..0a4d67d --- /dev/null +++ b/examples/ReadWriteMZ3Mesh.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +# Copyright NumFOCUS +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0.txt +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +__doc__ = """ +Example of how to read and write a Mesh in MZ3 format + +Any mesh file format supported by ITK can be read and written using the +script below. The file format is determined by the file extension. + +If compression is enabled, the file will be written in a compressed format. +For MZ3 files, GZip compression is used. +""" + +import argparse + +import itk + +parser = argparse.ArgumentParser(description="Read and write a Mesh in MZ3 format") +parser.add_argument("input_mesh") +parser.add_argument("output_mesh") +parser.add_argument("-c", "--compression", action="store_true", help="Enable compression") +args = parser.parse_args() + +mesh = itk.meshread(args.input_mesh) +itk.meshwrite(mesh, args.output_mesh, compression=args.compression) diff --git a/examples/WriteMZ3Mesh.py b/examples/WriteMZ3Mesh.py deleted file mode 100644 index e5f9de6..0000000 --- a/examples/WriteMZ3Mesh.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python - -# Copyright NumFOCUS -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0.txt -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Run with: -# ./WriteMZ3Mesh.py -# -# e.g. -# ./WriteMZ3Mesh.py MyImage.mha Output.mha 2 0.2 -# (A rule of thumb is to set the Threshold to be about 1 / 100 of the Level.) -# -# parameter_1: absolute minimum... -# The assumption is that... -# parameter_2: controls the.. -# A tradeoff between... - -import argparse - -import itk - - -parser = argparse.ArgumentParser(description="Example short description.") -parser.add_argument("input_image") -parser.add_argument("output_image") -parser.add_argument("parameter_1") -args = parser.parse_args() - -# Please, write a complete, self-containted and useful example that -# demonstrate a class when being used along with other ITK classes or in -# the context of a wider or specific application.