|
| 1 | +/*========================================================================= |
| 2 | + * |
| 3 | + * Copyright NumFOCUS |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * https://www.apache.org/licenses/LICENSE-2.0.txt |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + *=========================================================================*/ |
| 18 | +#include "itkMesh.h" |
| 19 | +#include "itkPolyData.h" |
| 20 | +#include "itkInputMesh.h" |
| 21 | +#include "itkOutputPolyData.h" |
| 22 | +#include "itkPipeline.h" |
| 23 | +#include "itkSupportInputMeshTypes.h" |
| 24 | +#include "itkWasmMeshIOFactory.h" |
| 25 | +#include "itkMeshToPolyDataFilter.h" |
| 26 | +#include "itkVector.h" |
| 27 | + |
| 28 | +template<typename TMesh> |
| 29 | +class PipelineFunctor |
| 30 | +{ |
| 31 | +public: |
| 32 | + int operator()(itk::wasm::Pipeline & pipeline) |
| 33 | + { |
| 34 | + using MeshType = TMesh; |
| 35 | + |
| 36 | + using InputMeshType = itk::wasm::InputMesh<MeshType>; |
| 37 | + InputMeshType inputMesh; |
| 38 | + pipeline.add_option("input-mesh", inputMesh, "Input mesh")->required()->type_name("INPUT_MESH"); |
| 39 | + |
| 40 | + using PolyDataType = itk::PolyData<typename MeshType::PixelType>; |
| 41 | + using OutputPolyDataType = itk::wasm::OutputPolyData<PolyDataType>; |
| 42 | + OutputPolyDataType outputPolyData; |
| 43 | + pipeline.add_option("output-polydata", outputPolyData, "Output polydata")->required()->type_name("OUTPUT_POLYDATA"); |
| 44 | + |
| 45 | + ITK_WASM_PARSE(pipeline); |
| 46 | + |
| 47 | + using MeshToPolyDataFilterType = itk::MeshToPolyDataFilter<MeshType>; |
| 48 | + auto meshToPolyDataFilter = MeshToPolyDataFilterType::New(); |
| 49 | + meshToPolyDataFilter->SetInput(inputMesh.Get()); |
| 50 | + meshToPolyDataFilter->Update(); |
| 51 | + |
| 52 | + outputPolyData.Set(meshToPolyDataFilter->GetOutput()); |
| 53 | + |
| 54 | + return EXIT_SUCCESS; |
| 55 | + } |
| 56 | +}; |
| 57 | + |
| 58 | +int main (int argc, char * argv[]) |
| 59 | +{ |
| 60 | + itk::wasm::Pipeline pipeline("mesh-to-poly-data", "Convert an itk::Mesh to an itk::PolyData", argc, argv); |
| 61 | + |
| 62 | + itk::WasmMeshIOFactory::RegisterOneFactory(); |
| 63 | + |
| 64 | + return itk::wasm::SupportInputMeshTypes<PipelineFunctor, |
| 65 | + uint8_t, |
| 66 | + int8_t, |
| 67 | + float, |
| 68 | + double, |
| 69 | + itk::Vector<uint8_t, 3>, |
| 70 | + itk::Vector<float, 3> |
| 71 | + > |
| 72 | + ::Dimensions<2U,3U>("input-mesh", pipeline); |
| 73 | +} |
0 commit comments