From 1c889e11072e9f8f3f4e7c93b166c8221ec9c540 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 23 Feb 2024 13:58:32 -0500 Subject: [PATCH] WIP: pnpm build --- itkwasm-sub-mesh/CMakeLists.txt | 16 ++-- itkwasm-sub-mesh/README.md | 2 +- itkwasm-sub-mesh/cow-cells-to-extract.json | 1 + itkwasm-sub-mesh/environment.yml | 9 ++ itkwasm-sub-mesh/package.json | 48 ++++++++++ itkwasm-sub-mesh/pnpm-workspace.yaml | 2 + itkwasm-sub-mesh/sub-mesh.cxx | 49 ---------- itkwasm-sub-mesh/sub-mesh/CMakeLists.txt | 4 + .../sub-mesh/cow-cells-to-extract.json | 0 itkwasm-sub-mesh/{ => sub-mesh}/cow.vtk | 0 itkwasm-sub-mesh/sub-mesh/sub-mesh.cxx | 91 +++++++++++++++++++ 11 files changed, 162 insertions(+), 60 deletions(-) create mode 100644 itkwasm-sub-mesh/cow-cells-to-extract.json create mode 100644 itkwasm-sub-mesh/environment.yml create mode 100644 itkwasm-sub-mesh/package.json create mode 100644 itkwasm-sub-mesh/pnpm-workspace.yaml delete mode 100644 itkwasm-sub-mesh/sub-mesh.cxx create mode 100644 itkwasm-sub-mesh/sub-mesh/CMakeLists.txt create mode 100644 itkwasm-sub-mesh/sub-mesh/cow-cells-to-extract.json rename itkwasm-sub-mesh/{ => sub-mesh}/cow.vtk (100%) create mode 100644 itkwasm-sub-mesh/sub-mesh/sub-mesh.cxx diff --git a/itkwasm-sub-mesh/CMakeLists.txt b/itkwasm-sub-mesh/CMakeLists.txt index dc57615..07e4b86 100644 --- a/itkwasm-sub-mesh/CMakeLists.txt +++ b/itkwasm-sub-mesh/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.16) -project(sub-mesh) +project(itkwasm-sub-mesh LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(io_components) if(NOT EMSCRIPTEN) @@ -15,12 +15,8 @@ find_package(ITK REQUIRED ) include(${ITK_USE_FILE}) -add_executable(sub-mesh sub-mesh.cxx) -target_link_libraries(sub-mesh PUBLIC ${ITK_LIBRARIES}) - enable_testing() -add_test(NAME sub-mesh - COMMAND sub-mesh ${CMAKE_CURRENT_SOURCE_DIR}/cow.vtk - ${CMAKE_CURRENT_SOURCE_DIR}/cow-cells-to-extract.json - ${CMAKE_CURRENT_BINARY_DIR}/sub-cow.vtk - ) + +# Begin create-itk-wasm added pipelines. +add_subdirectory(sub-mesh) +# End create-itk-wasm added pipelines. diff --git a/itkwasm-sub-mesh/README.md b/itkwasm-sub-mesh/README.md index 1a9886a..5fdd131 100644 --- a/itkwasm-sub-mesh/README.md +++ b/itkwasm-sub-mesh/README.md @@ -1,3 +1,3 @@ # itkwasm-sub-mesh -Extract subset of a mesh given by the cell identifiers. +Extract a subset of a mesh given by the cell identifiers. diff --git a/itkwasm-sub-mesh/cow-cells-to-extract.json b/itkwasm-sub-mesh/cow-cells-to-extract.json new file mode 100644 index 0000000..4d83159 --- /dev/null +++ b/itkwasm-sub-mesh/cow-cells-to-extract.json @@ -0,0 +1 @@ +[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199] \ No newline at end of file diff --git a/itkwasm-sub-mesh/environment.yml b/itkwasm-sub-mesh/environment.yml new file mode 100644 index 0000000..b6e6f66 --- /dev/null +++ b/itkwasm-sub-mesh/environment.yml @@ -0,0 +1,9 @@ +name: itkwasm-sub-mesh +channels: + - conda-forge +dependencies: + - pytest + - python=3.11 + - pip + - pip: + - hatch diff --git a/itkwasm-sub-mesh/package.json b/itkwasm-sub-mesh/package.json new file mode 100644 index 0000000..31d7c45 --- /dev/null +++ b/itkwasm-sub-mesh/package.json @@ -0,0 +1,48 @@ +{ + "name": "itkwasm-sub-mesh-build", + "version": "0.1.0", + "private": true, + "packageManager": "pnpm@8.15.1", + "description": "Scripts to generate itkwasm-sub-mesh itk-wasm artifacts.", + "type": "module", + "itk-wasm": { + "package-description": "Extract a subset of a mesh given by the cell identifiers.", + "typescript-package-name": "@itk-wasm/sub-mesh", + "python-package-name": "itkwasm-sub-mesh", + "repository": "https://github.com/uncbiag/OAI_analysis_2" + }, + "license": "Apache-2.0", + "scripts": { + "build": "pnpm build:gen:typescript && pnpm build:gen:python", + "build:emscripten": "itk-wasm pnpm-script build:emscripten", + "build:emscripten:debug": "itk-wasm pnpm-script build:emscripten:debug", + "build:wasi": "itk-wasm pnpm-script build:wasi", + "build:wasi:debug": "itk-wasm pnpm-script build:wasi:debug", + "build:python:wasi": "itk-wasm pnpm-script build:python:wasi", + "bindgen:typescript": "itk-wasm pnpm-script bindgen:typescript", + "bindgen:python": "itk-wasm pnpm-script bindgen:python", + "build:gen:typescript": "itk-wasm pnpm-script build:gen:typescript", + "build:gen:python": "itk-wasm pnpm-script build:gen:python", + "build:micromamba": "itk-wasm pnpm-script build:micromamba", + "build:python:versionSync": "itk-wasm pnpm-script build:python:versionSync", + "publish:python": "itk-wasm pnpm-script publish:python", + "test": "pnpm test:data:download && pnpm build:gen:python && pnpm test:python", + "test:data:download": "dam download test/data test/data.tar.gz bafkreigpkk3pqcoqzjzcauogw6dml52yig3ksmcrobau5pkoictymizzri https://github.com/InsightSoftwareConsortium/itk-wasm/releases/download/itk-wasm-v1.0.0-b.163/create-itk-wasm-test-data.tar.gz https://bafybeiczuxeuma5cjuli5mtapqnjqypeaum5ikd45zcmfhtt2emp365tca.ipfs.w3s.link/ipfs/bafybeiczuxeuma5cjuli5mtapqnjqypeaum5ikd45zcmfhtt2emp365tca/create-itk-wasm-test-data.tar.gz https://ipfs.filebase.io/ipfs/QmcxyvUKnaoTTwUqEPXwp1sdcbrFh3XnnwckLKVRpctJx9", + "test:data:pack": "dam pack test/data test/data.tar.gz", + "test:python:wasi": "itk-wasm pnpm-script test:python:wasi", + "test:python:emscripten": "itk-wasm pnpm-script test:python:emscripten", + "test:python:dispatch": "itk-wasm pnpm-script test:python:emscripten", + "test:python": "itk-wasm pnpm-script test:python", + "test:wasi": "itk-wasm pnpm-script test:wasi" + }, + "devDependencies": { + "@itk-wasm/dam": "^1.1.1", + "@thewtex/setup-micromamba": "^1.9.7", + "itk-wasm": "1.0.0-b.167" + }, + "author": "Matt McCormick", + "repository": { + "type": "git", + "url": "https://github.com/uncbiag/OAI_analysis_2" + } +} \ No newline at end of file diff --git a/itkwasm-sub-mesh/pnpm-workspace.yaml b/itkwasm-sub-mesh/pnpm-workspace.yaml new file mode 100644 index 0000000..27c86b7 --- /dev/null +++ b/itkwasm-sub-mesh/pnpm-workspace.yaml @@ -0,0 +1,2 @@ +packages: + - 'typescript' diff --git a/itkwasm-sub-mesh/sub-mesh.cxx b/itkwasm-sub-mesh/sub-mesh.cxx deleted file mode 100644 index 7ee6e27..0000000 --- a/itkwasm-sub-mesh/sub-mesh.cxx +++ /dev/null @@ -1,49 +0,0 @@ -/*========================================================================= - * - * 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. - * - *=========================================================================*/ -#include "itkMesh.h" -#include "itkInputTextStream.h" -#include "itkInputMesh.h" -#include "itkOutputMesh.h" -#include "itkPipeline.h" -#include "itkSupportInputMeshTypes.h" - -int main( int argc, char * argv[] ) -{ - itk::wasm::Pipeline pipeline("extract-sub-mesh", "Extract a subset of a mesh given by the cell identifiers", argc, argv); - - using PixelType = float; - constexpr unsigned int Dimension = 3; - using MeshType = itk::Mesh< PixelType, Dimension >; - - using InputMeshType = itk::wasm::InputMesh; - InputMeshType inputMesh; - pipeline.add_option("mesh", inputMesh, "Full mesh")->required()->type_name("INPUT_MESH"); - - itk::wasm::InputTextStream cellIdentifiers; - pipeline.add_option("cell-identifiers", cellIdentifiers, "Cell identifiers")->type_name("INPUT_JSON"); - - using OutputMeshType = itk::wasm::OutputMesh; - OutputMeshType subMesh; - pipeline.add_option("sub-mesh", subMesh, "Sub mesh")->required()->type_name("OUTPUT_MESH"); - - ITK_WASM_PARSE(pipeline); - - subMesh.Set(inputMesh.Get()); - - return EXIT_SUCCESS; -} diff --git a/itkwasm-sub-mesh/sub-mesh/CMakeLists.txt b/itkwasm-sub-mesh/sub-mesh/CMakeLists.txt new file mode 100644 index 0000000..941eeb6 --- /dev/null +++ b/itkwasm-sub-mesh/sub-mesh/CMakeLists.txt @@ -0,0 +1,4 @@ +add_executable(sub-mesh sub-mesh.cxx) +target_link_libraries(sub-mesh PUBLIC ${ITK_LIBRARIES}) + +add_test(NAME sub-mesh-help COMMAND sub-mesh --help) diff --git a/itkwasm-sub-mesh/sub-mesh/cow-cells-to-extract.json b/itkwasm-sub-mesh/sub-mesh/cow-cells-to-extract.json new file mode 100644 index 0000000..e69de29 diff --git a/itkwasm-sub-mesh/cow.vtk b/itkwasm-sub-mesh/sub-mesh/cow.vtk similarity index 100% rename from itkwasm-sub-mesh/cow.vtk rename to itkwasm-sub-mesh/sub-mesh/cow.vtk diff --git a/itkwasm-sub-mesh/sub-mesh/sub-mesh.cxx b/itkwasm-sub-mesh/sub-mesh/sub-mesh.cxx new file mode 100644 index 0000000..b74e726 --- /dev/null +++ b/itkwasm-sub-mesh/sub-mesh/sub-mesh.cxx @@ -0,0 +1,91 @@ +/*========================================================================= + + * 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. + * + *=========================================================================*/ + +#include "itkPipeline.h" +#include "itkInputMesh.h" +#include "itkInputTextStream.h" +#include "itkOutputMesh.h" +#include "itkSupportInputMeshTypes.h" + +#include "itkTriangleCell.h" +#include "itkVertexCell.h" +#include "itkQuadrilateralCell.h" +#include "itkTetrahedronCell.h" +#include "itkHexahedronCell.h" + +#include "itkAutomaticTopologyMeshSource.h" + +template +int subMesh(itk::wasm::Pipeline &pipeline, const TMesh *mesh) +{ + using MeshType = TMesh; + constexpr unsigned int Dimension = MeshType::PointDimension; + using PixelType = typename MeshType::PixelType; + + pipeline.get_option("mesh")->required()->type_name("INPUT_MESH"); + + std::vector< uint32_t > cellIdentifiers; + pipeline.add_option("cell-identifiers", cellIdentifiers, "Cell identifiers for output mesh.")->required(); + + itk::wasm::OutputMesh subMesh; + pipeline.add_option("sub-mesh", subMesh, "Sub mesh.")->required()->type_name("OUTPUT_MESH"); + + ITK_WASM_PARSE(pipeline); + + std::set< itk::IdentifierType > usedPoints; + for (auto cellIdentifier : cellIdentifiers) + { + const typename MeshType::CellType * cell = mesh->GetCell(cellIdentifier); + + // meshSource->AddCellIdentifier(cellIdentifier); + } + + using MeshSourceType = itk::AutomaticTopologyMeshSource< MeshType >; + auto meshSource = MeshSourceType::New(); + + subMesh.Set(mesh); + + return EXIT_SUCCESS; +} + +template +class PipelineFunctor +{ +public: + int operator()(itk::wasm::Pipeline &pipeline) + { + using MeshType = TMesh; + + itk::wasm::InputMesh mesh; + pipeline.add_option("mesh", mesh, "Full mesh")->type_name("INPUT_MESH"); + + ITK_WASM_PRE_PARSE(pipeline); + + typename MeshType::ConstPointer meshRef = mesh.Get(); + return subMesh(pipeline, meshRef); + } +}; + +int main(int argc, char * argv[]) +{ + itk::wasm::Pipeline pipeline("sub-mesh", "Extract a subset of a mesh given by the cell identifiers.", argc, argv); + + return itk::wasm::SupportInputMeshTypes + ::Dimensions<3U>("mesh", pipeline); +}