Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm #81

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft

Wasm #81

Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions itkcuberille/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.16)
project(itkwasm-cuberille LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)

find_package(ITK REQUIRED COMPONENTS
WebAssemblyInterface
)
include(${ITK_USE_FILE})

enable_testing()

# Begin create-itk-wasm added pipelines.
add_subdirectory(cuberille)
# End create-itk-wasm added pipelines.
3 changes: 3 additions & 0 deletions itkcuberille/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# itkwasm-cuberille

Cuberille implicit surface polygonization
4 changes: 4 additions & 0 deletions itkcuberille/cuberille/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(cuberille cuberille.cxx)
target_link_libraries(cuberille PUBLIC ${ITK_LIBRARIES})

add_test(NAME cuberille-help COMMAND cuberille --help)
93 changes: 93 additions & 0 deletions itkcuberille/cuberille/cuberille.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*=========================================================================

* 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 "itkInputImage.h"
#include "itkOutputMesh.h"
#include "itkSupportInputImageTypes.h"

template <typename TImage>
int cuberille(itk::wasm::Pipeline &pipeline, const TImage * image)
{
using ImageType = TImage;
constexpr unsigned int Dimension = ImageType::ImageDimension;
using PixelType = typename ImageType::PixelType; using MeshType = itk::Mesh<PixelType, Dimension>;


pipeline.get_option("image")->required()->type_name("INPUT_IMAGE");

bool quadrilateralFaces = false;
pipeline.add_flag("--quadrilateral-faces", quadrilateralFaces, "Generate quadrilateral faces instead of triangle faces.");

bool verticesNotProjectedToIsoSurface = false;
pipeline.add_flag("--vertices-not-projected-to-iso-surface", verticesNotProjectedToIsoSurface, "Do not project the vertices to the iso-surface.");

bool imagePixelToCellData = false;
pipeline.add_flag("--image-pixel-to-cell-data", imagePixelToCellData, "Whether the adjacent input pixel value should be saved as cell data in the output mesh.");

double projectVertexSurfaceDistanceThreshold = 0.5;
pipeline.add_option("--project-vertex-surface-distance-threshold", projectVertexSurfaceDistanceThreshold, "Threshold for the distance from the iso-surface during vertex projection in pixel units. Smaller is smoother but takes longer.");

double projectVertexStepLength = -1.0;
thewtex marked this conversation as resolved.
Show resolved Hide resolved
pipeline.add_option("--project-vertex-step-length", projectVertexStepLength, "Initial step length for vertex projection in physical units. Default is max spacing * 0.25.");

double projectVertexStepLengthRelaxationFactor = 0.95;
pipeline.add_option("--project-vertex-step-length-relaxation-factor", projectVertexStepLengthRelaxationFactor, "The step length relaxation factor during vertex projection. The step length is multiplied by this factor each iteration to allow convergence, [0.0, 1.0].");

uint32_t projectVertexMaximumNumberOfSteps = 50;
pipeline.add_option("--project-vertex-maximum-number-of-steps", projectVertexMaximumNumberOfSteps, "The maximum number of steps used during vertex projection.");

bool generateQuadrilateralFaces = false;
pipeline.add_flag("--generate-quadrilateral-faces", generateQuadrilateralFaces, "Generate quadrilateral faces instead of triangle faces.");

itk::wasm::OutputMesh<MeshType> mesh;
pipeline.add_option("mesh", mesh, "Output mesh.")->required()->type_name("OUTPUT_MESH");

ITK_WASM_PARSE(pipeline);

// Pipeline code goes here

return EXIT_SUCCESS;
}

template <typename TImage>
class PipelineFunctor
{
public:
int operator()(itk::wasm::Pipeline &pipeline)
{
using ImageType = TImage;

itk::wasm::InputImage<ImageType> image;
pipeline.add_option("image", image, "Input image")->type_name("INPUT_IMAGE");

ITK_WASM_PRE_PARSE(pipeline);

typename ImageType::ConstPointer imageRef = image.Get();
return cuberille<ImageType>(pipeline, imageRef);
}
};

int main(int argc, char * argv[])
{
itk::wasm::Pipeline pipeline("cuberille", "Create a mesh from an image via cuberille implicit surface polygonization.", argc, argv);

return itk::wasm::SupportInputImageTypes<PipelineFunctor,
uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, float, double>
::Dimensions<2U, 3U>("image", pipeline);
}
25 changes: 25 additions & 0 deletions itkcuberille/itk_wasm_env.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

function die() {
echo "$1"
exit 1
}

export ITK_WASM_TEST_DATA_HASH=${ITK_WASM_TEST_DATA_HASH:-$(cat package.json | jq -e -r '."itk-wasm"."test-data-hash"')}
export ITK_WASM_TEST_DATA_URLS=${ITK_WASM_TEST_DATA_URLS:-$(cat package.json | jq -e -r '."itk-wasm"."test-data-urls" | join(" ")')}

export ITK_WASM_ITK_REPOSITORY=${ITK_WASM_ITK_REPOSITORY:-"https://github.com/thewtex/ITK"}
thewtex marked this conversation as resolved.
Show resolved Hide resolved
export ITK_WASM_ITK_BRANCH=${ITK_WASM_ITK_BRANCH:-"itkwasm-2024-05-20-5db055d7ad3b-4"}

export ITK_WASM_NATIVE_WORKSPACE=${ITK_WASM_NATIVE_WORKSPACE:-$(pwd)/native}

export ITK_WASM_ITK_SOURCE_DIR=${ITK_WASM_ITK_SOURCE_DIR:-${ITK_WASM_NATIVE_WORKSPACE}/ITK}
export ITK_WASM_ITK_BUILD_DIR=${ITK_WASM_ITK_BUILD_DIR:-${ITK_WASM_NATIVE_WORKSPACE}/ITK-build}
mkdir -p ${ITK_WASM_ITK_BUILD_DIR} || die "Could not create ITK build directory"

export ITK_WASM_WEBASSEMBLY_INTERFACE_REPOSITORY=${ITK_WASM_WEBASSEMBLY_INTERFACE_REPOSITORY:-"https://github.com/InsightSoftwareConsortium/ITK-Wasm"}
export ITK_WASM_WEBASSEMBLY_INTERFACE_BRANCH=${ITK_WASM_WEBASSEMBLY_INTERFACE_BRANCH:-"main"}

export ITK_WASM_WEBASSEMBLY_INTERFACE_SOURCE_DIR=${ITK_WASM_WEBASSEMBLY_INTERFACE_SOURCE_DIR:-${ITK_WASM_NATIVE_WORKSPACE}/ITK-Wasm}
export ITK_WASM_WEBASSEMBLY_INTERFACE_BUILD_DIR=${ITK_WASM_WEBASSEMBLY_INTERFACE_BUILD_DIR:-${ITK_WASM_NATIVE_WORKSPACE}/ITK-Wasm-build}
mkdir -p ${ITK_WASM_WEBASSEMBLY_INTERFACE_BUILD_DIR} || die "Could not create ITK-Wasm build directory"
42 changes: 42 additions & 0 deletions itkcuberille/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "itkwasm-cuberille-build",
"version": "0.1.0",
"private": true,
"description": "Scripts to generate itkwasm-cuberille ITK-Wasm artifacts.",
"type": "module",
"itk-wasm": {
"test-data-hash": "bafkreidnoz54py66bn56uq6itwkfgngflaqilflfvwkxlps4ycmygstzja",
"test-data-urls": [
"https://github.com/InsightSoftwareConsortium/ITK-Wasm/releases/download/itk-wasm-v1.0.0-b.179/sample-data.tar.gz",
"https://bafybeidxatrsrrphfmntdyze6ec3jbiak527wj3kalwjptv4bimpcnzxdq.ipfs.w3s.link/ipfs/bafybeidxatrsrrphfmntdyze6ec3jbiak527wj3kalwjptv4bimpcnzxdq/sample-data.tar.gz"
],
"package-description": "Cuberille implicit surface polygonization",
"typescript-package-name": "@itk-wasm/cuberille",
"python-package-name": "itkwasm-cuberille",
"repository": "https://github.com/InsightSoftwareConsortium/ITKCuberille"
},
"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": "echo 'No build:python:wasi script required with pixi'",
"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",
"test": "pixi run download-test-data && pnpm build:gen:python",
"test:wasi": "itk-wasm pnpm-script test:wasi"
},
"devDependencies": {
"@itk-wasm/dam": "^1.1.1",
"itk-wasm": "1.0.0-b.182"
},
"author": "Matt McCormick <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/InsightSoftwareConsortium/ITKCuberille"
}
}
Loading