### CMakeLists.txt for Installation Examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/3.12.md This CMakeLists.txt file is used for the installation examples, updated for CMake version 2.6. ```cmake ENH: Updated for CMake 2.6. ``` -------------------------------- ### Installing Documentation and Examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt Installs man pages, the README file, and example directories. This installation is conditional on the NIFTI_INSTALL_NO_DOCS option not being set. It uses file matching and permissions settings. ```cmake if(NOT NIFTI_INSTALL_NO_DOCS) install( DIRECTORY ${MAN_DIR}/ DESTINATION ${NIFTI_INSTALL_MAN_DIR} FILES_MATCHING REGEX ".*.1.gz" PERMISSIONS OWNER_READ WORLD_READ ) install( FILES ${PROJECT_SOURCE_DIR}/README.md DESTINATION ${NIFTI_INSTALL_DOC_DIR} ) install( DIRECTORY ${PROJECT_SOURCE_DIR}/real_easy/ DESTINATION ${NIFTI_INSTALL_DOC_DIR}/examples ) endif() ``` -------------------------------- ### Whitelist File Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Utilities/Maintenance/RemoteModuleIngest/INGESTION_STRATEGY_v4.md Illustrates the format of a whitelist file, specifying paths and globs relative to the repository root. Lines starting with '#' are comments. ```text # Public headers include/** # Test sources + fixtures test/** # CMake / module metadata CMakeLists.txt itk-module.cmake # Wrapping wrapping/** # License (always) LICENSE ``` -------------------------------- ### Configure Example Builds Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/HDF5/src/itkhdf5/CMakeLists.txt Enables the build of HDF5 examples if HDF5_BUILD_EXAMPLES is ON and sanitizers are not in use. It includes example-specific cache settings and adds the examples subdirectory. ```cmake if (EXISTS "${HDF5_SOURCE_DIR}/HDF5Examples" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/HDF5Examples") option (HDF5_BUILD_EXAMPLES "Build HDF5 Library Examples" ON) if (HDF5_BUILD_EXAMPLES AND NOT USE_SANITIZER) include (${HDF_RESOURCES_DIR}/HDF5ExampleCache.cmake) set (HDF5_VERSION ${HDF5_PACKAGE_VERSION}) add_subdirectory (HDF5Examples) endif () endif () ``` -------------------------------- ### CMakeLists.txt for Registration Examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/3.12.md This CMakeLists.txt file is used for registration examples, including the addition of a 3D version of the MultiResImageRegistration1.cxx example. ```cmake ENH: Adding 3D version of example MultiResImageRegistration1.cxx. ``` -------------------------------- ### Install zlib-ng with vcpkg Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/README.md Use vcpkg to clone the repository, bootstrap the tool, integrate it with your system, and then install the zlib-ng library. Ensure your vcpkg installation is up-to-date. ```sh git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh # "./bootstrap-vcpkg.bat" for powershell ./vcpkg integrate install ./vcpkg install zlib-ng ``` -------------------------------- ### First-Time Git Hook Setup Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/AI/git-commits.md This bash script must be run once after cloning the repository to install the necessary pre-commit and commit-msg hooks. Commits will not be validated locally without this setup. ```bash ./Utilities/SetupForDevelopment.sh ``` -------------------------------- ### Prepare Docker for Linux ARM Builds Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/Maintenance/Release.md Sets up a Docker environment on macOS for building Linux ARM wheels. This involves installing Colima, starting a Colima instance, and creating a custom Docker image from a base image. ```bash # FLOSS Docker on mac brew install colima colima start --cpu 9 --memory 20 --mount $PWD:/work:w # Get your UID, e.g. 501 id -u # Get your GID, e.g. 20 id -g docker run --name itk-manylinux-aarch64-base-2025-08-12 -it quay.io/pypa/manylinux_2_28_aarch64:2025.08.12-1 # Upgrade GPG keys dnf upgrade -y almalinux-release yum install sudo ninja-build vim # Set up corresponding uid, gid accounts mkdir /home/manualuser echo "manualuser:x:501:20:,,,:/home/manualuser:/bin/bash" >> /etc/passwd # Ensure that a group exists for your GID in /etc/group chown -R manualuser:20 /home/manualuser sudo visudo # Add at the end: manualuser ALL=(ALL) NOPASSWD: ALL # Add to the end of /etc/shadow: manualuser:*:19485:0:99999:7::: exit docker commit itk-manylinux-aarch64-base-2025-08-12 itk-manylinux-aarch64-build-2025-08-12 ``` -------------------------------- ### Build and Install NIFTI Tool Application Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/NIFTI/src/nifti/niftilib/CMakeLists.txt Compiles and installs the nifti1_tool executable if NIFTI applications are enabled. Links against the NIFTI library and installs its man page. ```cmake if(NIFTI_BUILD_APPLICATIONS) add_nifti_executable(${NIFTI_PACKAGE_PREFIX}nifti1_tool nifti1_tool.c) target_link_libraries(${NIFTI_PACKAGE_PREFIX}nifti1_tool PUBLIC ${NIFTI_NIFTILIB_NAME}) install_nifti_target(${NIFTI_PACKAGE_PREFIX}nifti1_tool) install_man_page( ${NIFTI_PACKAGE_PREFIX}nifti1_tool OPTS "--help-option=-help;--version-option=-ver_man;--no-info" ) endif() ``` -------------------------------- ### Set Installation Directories Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmmd5/CMakeLists.txt Defines default installation directories for binaries and libraries if not already set. This ensures consistent installation paths. ```cmake if(NOT MD5_INSTALL_BIN_DIR) set(MD5_INSTALL_BIN_DIR "bin") endif() if(NOT MD5_INSTALL_LIB_DIR) set(MD5_INSTALL_LIB_DIR "lib") endif() ``` -------------------------------- ### Basic ITK Project Setup with CMake Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Examples/Installation/CMakeLists.txt This snippet shows the fundamental CMake commands to configure a project with ITK. Ensure ITK is installed and discoverable by CMake. The `find_package(ITK REQUIRED)` command is crucial for locating ITK and its components. ```cmake cmake_minimum_required(VERSION 3.22.1...3.29.0 FATAL_ERROR) project(HelloWorld) find_package(ITK REQUIRED) itk_generate_factory_registration() add_executable(HelloWorld HelloWorld.cxx) target_link_libraries(HelloWorld ITK::ITKCommonModule) ``` -------------------------------- ### Python Example: Create Mesh and Cells Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/5.3rc04.md This Python code demonstrates how to create a mesh and define its cells using the ITK library. It requires the `itk` package to be installed. ```python import itk # Create a mesh mesh = itk.Mesh.New() # Create cells cell = itk.PolygonCell.New() cell.SetIds([0, 1, 2]) mesh.AddCell(cell) print(mesh) ``` -------------------------------- ### Set Installation Directories Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmuuid/CMakeLists.txt Defines default installation directories for the library's binary and library files if they are not already set. This provides sensible defaults for the install command. ```cmake if(NOT UUID_INSTALL_BIN_DIR) set(UUID_INSTALL_BIN_DIR "bin") endif() if(NOT UUID_INSTALL_LIB_DIR) set(UUID_INSTALL_LIB_DIR "lib") endif() ``` -------------------------------- ### Install zlib-ng with Configure Script Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/README.md After configuring zlib-ng with the bash script, use this command to install it system-wide. This is a simpler installation method compared to manual installation. ```sh make install ``` -------------------------------- ### Install Podman Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/s390/README.md Installs the Podman containerization tool, a prerequisite for setting up the actions runner. ```bash sudo dnf install podman ``` -------------------------------- ### Configure Installation Directories Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmcharls/CMakeLists.txt Sets default installation directories for binaries, libraries, and include files if not already defined by the user. These paths are used during the installation phase. ```cmake if(NOT CHARLS_INSTALL_BIN_DIR) set(CHARLS_INSTALL_BIN_DIR "bin") endif() if(NOT CHARLS_INSTALL_LIB_DIR) set(CHARLS_INSTALL_LIB_DIR "lib") endif() if(NOT CHARLS_INSTALL_INCLUDE_DIR) set(CHARLS_INSTALL_INCLUDE_DIR "include") endif() ``` -------------------------------- ### Installing Package Configuration Files Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt Installs the generated NIFTIConfig.cmake and NIFTIConfigVersion.cmake files into the installation directory. These files are essential for the find_package mechanism used by external projects. ```cmake install( FILES ${CONFIG_SETUP_DIR}/${PACKAGE_NAME}Config.cmake ${CONFIG_SETUP_DIR}/${PACKAGE_NAME}ConfigVersion.cmake COMPONENT Development DESTINATION ${ConfigPackageLocation} ) ``` -------------------------------- ### Build C code examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/Expat/src/itkexpat/CMakeLists.txt Compiles C example programs that demonstrate Expat usage. Each example is built as a separate executable linked against the Expat library. ```cmake if(EXPAT_BUILD_EXAMPLES) foreach(_target element_declarations elements outline) add_executable(${_target} examples/${_target}.c) set_property(TARGET ${_target} PROPERTY RUNTIME_OUTPUT_DIRECTORY examples) target_link_libraries(${_target} expat) endforeach() endif() ``` -------------------------------- ### Install VCL Target Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/VNL/src/vxl/vcl/CMakeLists.txt Installs the 'vcl' target, including its archive, library, and runtime components, to their respective installation directories. ```cmake install(TARGETS vcl EXPORT ${VXL_INSTALL_EXPORT_NAME} ARCHIVE DESTINATION ${VXL_INSTALL_LIBRARY_DIR} LIBRARY DESTINATION ${VXL_INSTALL_LIBRARY_DIR} RUNTIME DESTINATION ${VXL_INSTALL_RUNTIME_DIR}) ``` -------------------------------- ### Install ZLIB Libraries Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/CMakeLists.txt Installs ZLIB runtime, archive, and library files. This is conditional on NOT skipping installation of libraries or all components. ```cmake if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL) install(TARGETS ${ZLIB_INSTALL_LIBRARIES} EXPORT ${EXPORT_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() ``` -------------------------------- ### Install Changelog Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/Expat/src/itkexpat/CMakeLists.txt Installs the AUTHORS file and the generated changelog to the documentation directory. ```cmake configure_file(Changes changelog COPYONLY) expat_install( FILES AUTHORS ${CMAKE_CURRENT_BINARY_DIR}/changelog DESTINATION ${CMAKE_INSTALL_DOCDIR}) ``` -------------------------------- ### Install ITK with vcpkg Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/download.md Install ITK using the vcpkg package manager. ```bash vcpkg install itk ``` -------------------------------- ### MetaImage Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/learn/metaio.md An example demonstrating the structure of a MetaImage file. ```APIDOC ## MetaImage Example ### Description This example shows the typical format of a MetaImage file header. ### Example ```default ObjectType = Image NDims = 2 BinaryData = True BinaryDataByteOrderMSB = False ElementSpacing = 1 2 DimSize = 8 8 ElementType = MET_CHAR ElementDataFile = LOCAL [Pixel Data] ``` ``` -------------------------------- ### Install Package Config Files Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/Expat/src/itkexpat/CMakeLists.txt Installs the generated expat-config.cmake and expat-config-version.cmake files. ```cmake expat_install( FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/expat-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/expat-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/expat-${PROJECT_VERSION}/) ``` -------------------------------- ### Install ITK with Homebrew Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/download.md Install ITK using the Homebrew package manager. ```bash brew install itk ``` -------------------------------- ### Add example for PermuteAxesImageFilter Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/4.7.md A new example has been added to demonstrate the PermuteAxesImageFilter. ```python add example for PermuteAxesImageFilter ``` -------------------------------- ### Fix failing setup of SegmentBloodVessels example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/4.7.md Compilation fix to resolve issues with the setup of the SegmentBloodVessels example. ```plaintext COMP: Fix failing setup of SegmentBloodVessels example ``` -------------------------------- ### First-Time Development Setup Script Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/AI/enforced-code-style.md Run this script for initial setup of git hooks (pre-commit clang-format, commit-msg KWStyle check) and remote configuration. It is required before your first commit. ```bash ./Utilities/SetupForDevelopment.sh ``` -------------------------------- ### Install Dependencies and Build Documentation Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/README.md Set up a Python virtual environment, install required packages, and build the Sphinx documentation locally. This is for Linux/macOS environments. ```bash cd ITK/Documentation/docs python -m venv env source env/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Add derivativeImage Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/5.3rc04.md This Python example demonstrates the derivativeImage functionality. It requires ITK to be installed. ```python import itk # Define image dimensions and pixel type ImageDimension = 2 PixelType = itk.UC # Create an image ImageType = itk.Image[PixelType, ImageDimension] image = ImageType.New() # Set the size of the image size = [128, 64] image.SetRegions(size) image.Allocate() # Fill the image with a constant value (e.g., 100) image.FillBuffer(100) # Apply the derivative filter # The derivative filter computes the gradient of the image # For a 2D image, it computes the gradient in x and y directions # The output is a vector image with components corresponding to the derivatives # For simplicity, let's assume a simple derivative operation (e.g., Sobel) # Note: ITK's derivative filter is typically used with Gaussian smoothing first. # For a direct derivative example, one might use GradientRecursiveGaussianImageFilter. # Example using GradientRecursiveGaussianImageFilter for demonstration gradient_filter = itk.GradientRecursiveGaussianImageFilter[ImageType, itk.VectorImage[itk.F, ImageDimension]].New() gradient_filter.SetInput(image) gradient_filter.SetSigma(1.0) # Standard deviation for the Gaussian smoothing gradient_filter.Update() derivative_image = gradient_filter.GetOutput() print(f"Input image size: {image.GetLargestPossibleRegion().GetSize()}") print(f"Derivative image size: {derivative_image.GetLargestPossibleRegion().GetSize()}") print(f"Derivative image pixel type: {derivative_image.GetPixelIDTypeAsString()}") ``` -------------------------------- ### Add ImageBufferAndIndexRange Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/5.3rc04.md This example demonstrates the usage of ImageBuffer and IndexRange in ITK. It requires ITK to be installed. ```python import itk # Define image dimensions and pixel type ImageDimension = 2 PixelType = itk.F # Create an image ImageType = itk.Image[PixelType, ImageDimension] image = ImageType.New() # Set the size of the image size = [64, 64] image.SetRegions(size) image.Allocate() # Fill the image with some values for i in range(size[0]): for j in range(size[1]): image[i, j] = float(i + j) # Get the image buffer image_buffer = image.GetBufferPointer() # Get the index range of the image index_range = image.GetLargestPossibleRegion() print(f"Image size: {image.GetLargestPossibleRegion().GetSize()}") print(f"Image buffer pointer: {image_buffer}") print(f"Index range start: {index_range.GetIndex()}") print(f"Index range size: {index_range.GetSize()}") # Accessing elements using index range start_index = index_range.GetIndex() end_index = [start_index[0] + index_range.GetSize()[0] - 1, start_index[1] + index_range.GetSize()[1] - 1] print(f"Value at start index {start_index}: {image[start_index]}") print(f"Value at end index {end_index}: {image[end_index]}") ``` -------------------------------- ### Installing License and Documentation Files Source: https://github.com/insightsoftwareconsortium/itk/blob/main/CMakeLists.txt This command installs license and documentation files to the specified destination directory. These files are typically required for runtime distribution. ```cmake install( FILES "LICENSE" "NOTICE" "README.md" DESTINATION ${ITK_INSTALL_DOC_DIR} COMPONENT Runtime ) ``` -------------------------------- ### Path CMakeLists.txt Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/1.8.md Configuration file for building path-related examples using CMake. It specifies build targets and dependencies. ```cmake Examples/DataRepresentation/Path/CMakeLists.txt ``` -------------------------------- ### Add GlobalRegistrationOfTwoImages Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/5.3rc04.md This Python example demonstrates the global registration of two images using ITK. It requires ITK to be installed. ```python import itk # Define image dimensions and pixel type ImageDimension = 2 PixelType = itk.F # Create a fixed image (e.g., a simple square) FixedImageType = itk.Image[PixelType, ImageDimension] fixed_image = FixedImageType.New() fixed_image.SetRegions([64, 64]) fixed_image.Allocate() fixed_image.FillBuffer(0) # Draw a square in the fixed image for i in range(20, 44): for j in range(20, 44): fixed_image[i, j] = 100 # Create a moving image (e.g., a translated and slightly rotated square) MovingImageType = itk.Image[PixelType, ImageDimension] moving_image = MovingImageType.New() moving_image.SetRegions([64, 64]) moving_image.Allocate() moving_image.FillBuffer(0) # Draw a square in the moving image for i in range(25, 49): for j in range(25, 49): moving_image[i, j] = 100 # Define the registration components # Optimizer optimizer = itk.PowellOptimizer.New() optimizer.SetLearningRate(0.05) optimizer.SetNumberOfIterations(100) # Metric metric = itk.MeanSquaresImageToImageMetric.New() metric.SetFixedImage(fixed_image) metric.SetMovingImage(moving_image) # Transform initial_transform = itk.TranslationTransform[itk.D, ImageDimension].New() initial_transform.SetIdentity() # Setup the registration framework registration = itk.ImageRegistrationMethod.New() registration.SetMetric(metric) registration.SetOptimizer(optimizer) registration.SetInitialTransform(initial_transform) # Connect observer functions for monitoring progress (optional) # registration.AddCommand(itk.IterationEvent(), lambda: print(f"Iteration {registration.GetOptimizerIteration()}")) # Execute the registration try: registration.Update() print("Registration successful!") final_transform = registration.GetTransform() print(f"Final translation: {final_transform.GetOffset()}") except Exception as e: print(f"Registration failed: {e}") # To visualize the result, you would typically use a Resample filter # with the final_transform to warp the moving image to the fixed image space. ``` -------------------------------- ### Define Option to Build Examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/CMakeLists.txt Defines a CMake option `BUILD_EXAMPLES` to control whether examples from the ITK Software Guide are built. It is off by default. ```cmake option(BUILD_EXAMPLES "Build the examples from the ITK Software Guide." OFF) ``` -------------------------------- ### Build All Libraries Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/NIFTI/src/nifti/README.md Use this command to build all libraries and place them in the bin/, include/, and lib/ directories. ```bash "make all" ``` -------------------------------- ### Configure Expat Examples Build Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/Expat/src/itkexpat/CMakeLists.txt Sets the option to build the examples for the Expat library. ```cmake expat_shy_set(EXPAT_BUILD_EXAMPLES ON CACHE BOOL "Build the examples for expat library") ``` -------------------------------- ### Python Example: Set and Get Cell Data Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/5.3rc04.md This Python code illustrates how to set and get data associated with cells in an ITK mesh. Ensure you have a mesh object with cells defined. ```python import itk # Assume 'mesh' is an existing itk.Mesh object with cells # Create a cell data object cell_data = itk.VectorCellData[itk.D].New() cell_data.SetNumberOfComponents(1) cell_data.Set(0, 10.0) # Set data for the first cell # Assign cell data to the mesh mesh.SetCellData(cell_data) # Get cell data retrieved_cell_data = mesh.GetCellData() print(retrieved_cell_data.Get(0)) ``` -------------------------------- ### Project Configuration and Installation Paths Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/GIFTI/src/gifticlib/CMakeLists.txt Sets up project name and defines installation directories for binaries, libraries, and headers. These paths are adjusted based on ITK integration. ```cmake project(gifticlib) # install destinations set(GIFTI_INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin") set(GIFTI_INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") set(GIFTI_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/include/gifti") ``` -------------------------------- ### Add NumPy Interfacing Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/5.3rc04.md This snippet demonstrates interfacing with NumPy. Ensure NumPy is installed and imported for use. ```python import numpy as np import itk # Create a NumPy array array = np.random.rand(10, 10) * 255 # Convert NumPy array to ITK image itk_image = itk.image_from_array(array) # Convert ITK image back to NumPy array output_array = itk.array_from_image(itk_image) print(f"Original NumPy array shape: {array.shape}") print(f"ITK image size: {itk_image.GetLargestPossibleRegion().GetSize()}") print(f"Converted NumPy array shape: {output_array.shape}") ``` -------------------------------- ### Add itk.RGBToLuminanceImageFilter Python Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/4.12.md This snippet demonstrates how to use the itk.RGBToLuminanceImageFilter in Python. Ensure the ITK Python package is installed. ```python import itk # Example usage of itk.RGBToLuminanceImageFilter ``` -------------------------------- ### Prepare RISC-V Toolchain and QEMU Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/riscv/README.md Use this script to download and build the RISC-V Clang toolchain and QEMU. Modify the script according to your specific requirements, such as the toolchain version. Ensure you have the necessary permissions and dependencies. ```bash ./prepare_riscv_toolchain_qemu.sh ``` -------------------------------- ### CPack Component Dependencies Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/GDCM/src/gdcm/CMakeLists.txt Defines dependencies between CPack components. For example, headers depend on libraries, ensuring a logical installation structure. ```cmake # It doesn't make sense to install the headers without the libraries # (because you could never use the headers!), so make the headers component # depend on the libraries component. set(CPACK_COMPONENT_HEADERS_DEPENDS Libraries) set(CPACK_COMPONENT_DEBUGDEVEL_DEPENDS Libraries) set(CPACK_COMPONENT_APPLICATIONS_DEPENDS Libraries) set(CPACK_COMPONENT_PYTHONMODULE_DEPENDS Libraries) set(CPACK_COMPONENT_CSHARPMODULE_DEPENDS Libraries) set(CPACK_COMPONENT_JAVAMODULE_DEPENDS Libraries) set(CPACK_COMPONENT_PHPMODULE_DEPENDS Libraries) set(CPACK_COMPONENT_VTKHEADERS_DEPENDS VTKLibraries) set(CPACK_COMPONENT_VTKLIBRARIES_DEPENDS Libraries) set(CPACK_COMPONENT_VTKAPPLICATIONS_DEPENDS VTKLibraries) set(CPACK_COMPONENT_VTKPYTHONMODULE_DEPENDS VTKLibraries) set(CPACK_COMPONENT_VTKCSHARPMODULE_DEPENDS VTKLibraries) set(CPACK_COMPONENT_VTKJAVAMODULE_DEPENDS VTKLibraries) set(CPACK_COMPONENT_VTKPHPMODULE_DEPENDS VTKLibraries) set(CPACK_COMPONENT_PARAVIEWMODULE_DEPENDS VTKLibraries) ``` -------------------------------- ### Add Examples for chan and vesse Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/3.16.md Adds examples for 'chan' and 'vesse' to the Review subdirectory in the CMakeLists.txt file. ```cmake ENH: added examples for chan and vesse in the not-empty-anymore Review Subdir. ``` -------------------------------- ### MetaImage Constructor Examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/learn/metaio.md Demonstrates different ways to construct a MetaImage object, from specifying a filename to providing detailed image properties. ```c++ MetaImage(const char *_headerName); ``` ```c++ MetaImage(MetaImage *_im); ``` ```c++ MetaImage(int _nDims, const int * _dimSize, const float *_elementSpacing, MET_ValueEnumType _elementType, int _elementNumberOfChannels=1, void *_elementData=NULL); ``` ```c++ MetaImage(int _x, int _y, float _elementSpacingX, float _elementSpacingY, MET_ValueEnumType _elementType, int _elementNumberOfChannels=1, void *_elementData=NULL); ``` ```c++ MetaImage(int _x, int _y, int _z, float _elementSpacingX, float _elementSpacingY, float _elementSpacingZ, MET_ValueEnumType _elementType, int _elementNumberOfChannels=1, void *_elementData=NULL); ``` -------------------------------- ### NrrdIO Sample IO Utility Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/1.8.md An example or utility demonstrating sample I/O operations for Nrrd files. This can serve as a basic usage guide. ```c++ Utilities/NrrdIO/sampleIO ``` -------------------------------- ### Add CreateAnImageOfVectors Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/4.12.md Demonstrates the creation of an image containing vector data using ITK in Python. Ensure ITK Python package is installed. ```python # Add CreateAnImageOfVectors ``` -------------------------------- ### Serve Documentation with Autobuild Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/README.md Start a local server using sphinx-autobuild that automatically rebuilds the documentation when source files change. The server will be available at http://127.0.0.1:8000. ```bash sphinx-autobuild -a . _build/html ``` -------------------------------- ### GoogleTest Driver Creation in C++ Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/4.13.md Example of how to create a GoogleTest driver for an ITK module using CMake. This function adds the GTest dependency to your test setup. ```c++ CreateGoogleTestDriver() ``` -------------------------------- ### Documenting an ITK Method with Doxygen Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/contributing/document_itk.md Use this minimal example to document an ITK method. It covers documentation for the method's brief description, detailed explanation, parameters (input, output, input/output), and return value. ```cpp /** \brief A short description of Method1. * * A more detailed documentation for Method1. * * \param[in] iP1 Documentation for the first parameter, an input parameter. * \param[in] iValue Documentation for the second parameter, an input parameter. * \param[out] oValue Documentation for the third parameter, an output parameter. * \param[in,out] ioP2 Documentation for the fourth parameter, an input/output parameter. * \return Description about the return value. */ int Method1(PixelType iP1, unsigned int iValue, unsigned int& oValue, PixelType& ioP2) const ``` -------------------------------- ### Image Read/Write Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Examples/IO/CMakeLists.txt Demonstrates basic image reading and writing capabilities. Requires ITKImageIO and ITKCommonModule. ```cmake project(IOExamples) add_executable(ImageReadWrite ImageReadWrite.cxx) target_link_libraries( ImageReadWrite PRIVATE ITK::ITKImageIO ITK::ITKCommonModule ) ``` -------------------------------- ### MetaImage Field Description Examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/learn/metaio.md Shows how to get and set various image properties like modality, dimension size, sequence ID, element size, type, number of channels, and data. ```c++ MET_ImageModalityEnumType Modality(void) const; ``` ```c++ void Modality(MET_ImageModalityEnumType _modality); ``` ```c++ void DimSize(const int * _dimSize); ``` ```c++ void DimSize(int _i, int _value); ``` ```c++ const float * SequenceID(void) const; ``` ```c++ float SequenceID(int _i) const; ``` ```c++ void SequenceID(const float * _sequenceID); ``` ```c++ void SequenceID(int _i, float _value); ``` ```c++ const float * ElementSize(void) const; ``` ```c++ float ElementSize(int i) const; ``` ```c++ void ElementSize(const float * _pointSize); ``` ```c++ void ElementSize(int _i, float _value); ``` ```c++ MET_ValueEnumType ElementType(void) const; ``` ```c++ void ElementType(MET_ValueEnumType _elementType); ``` ```c++ int ElementNumberOfChannels(void) const; ``` ```c++ void ElementNumberOfChannels(int _elementNumberOfChannels); ``` ```c++ void * ElementData(void); ``` ```c++ double ElementData(int _i) const; ``` ```c++ void ElementData(void * _data); ``` ```c++ bool ElementData(int _i, double _v); ``` ```c++ const char * ElementDataFileName(void) const; ``` ```c++ void ElementDataFileName(const char * _dataFileName); ``` -------------------------------- ### Create and Populate a MetaSurface Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/learn/metaio.md Shows how to create a MetaSurface and add points with defined positions and normals. Use the correct object reference when adding points. ```default MetaSurface surface(3); SurfacePnt* pnt; for(unsigned int i=0;i<10;i++) { pnt = new SurfacePnt(3); /** Position */ pnt->m_X=(float)0.2; pnt->m_X[^1]=i; pnt->m_X=i; /* Normal */ pnt->m_V=(float)0.8; pnt->m_V[^1]=i; pnt->m_V=i; surface.GetPoints().push_back(pnt); // Corrected: surface, not surface-> } ``` -------------------------------- ### Zlib Usage Examples Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/INDEX.md Provides examples of Zlib library usage for build testing purposes. ```c #include #include "zlib.h" int main() { z_stream strm; unsigned char in[CHUNK]; unsigned char out[CHUNK]; int ret, flush; unsigned have; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; ret = deflateInit(&strm, Z_DEFAULT_COMPRESSION); if (ret != Z_OK) return ret; /* assume chunks of file are read into 'in' and processed */ /* for each chunk, call deflate(&strm, flush) */ /* ... */ (void)deflateEnd(&strm); return 0; } ``` -------------------------------- ### Convert ITK Python Image to itkwasm Image Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/learn/python_quick_start.md This example demonstrates converting a native ITK Python image into an `itkwasm` dataclass interface type. It uses `itk.dict_from_image` to get a dictionary representation, which is then used to construct the `itkwasm` Image object. ```python import itk from itkwasm import Image # Assuming itk_image is an existing ITK Python image object # Convert ITK image to dictionary image_dict = itk.dict_from_image(itk_image) # Convert dictionary to itkwasm Image object itkwasm_image = Image(**image_dict) ``` -------------------------------- ### Clone and Set Up Third-Party Project Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/contributing/updating_third_party.md Clone the third-party project, set up a remote for ITK, and push tags. Then, checkout a specific tag and create a new branch for applying patches. ```bash git clone https://github.com/InsightSoftwareConsortium/foo.git cd foo/ git remote add insight git@github.com:InsightSoftwareConsortium/ITK.git:Modules/ThirdParty/foo.git git push -u insight git push -u insight --tags git checkout foo-3.0.0 git checkout -b for/itk git push --set-upstream insight for/itk ``` -------------------------------- ### Install zlib-config.cmake Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/HDF5/src/itkhdf5/config/cmake/ZLIBNG/CMakeLists.txt Installs the generated zlib-config.cmake file to the installation directory. This is performed only if ZLIB_EXTERNALLY_CONFIGURED is not set. ```cmake if (NOT ZLIB_EXTERNALLY_CONFIGURED) install ( FILES ${ZLIB_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/zlib-config.cmake DESTINATION ${ZLIB_INSTALL_CMAKE_DIR} COMPONENT configinstall ) endif () ``` -------------------------------- ### Install License File Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/KWSys/src/KWSys/CMakeLists.txt Installs the Copyright.txt license file to the specified documentation directory, optionally assigning it to a specific component. ```cmake if(KWSYS_INSTALL_DOC_DIR) # Assign the license to the runtime component since it must be # distributed with binary forms of this software. if(KWSYS_INSTALL_COMPONENT_NAME_RUNTIME) set(KWSYS_INSTALL_LICENSE_OPTIONS ${KWSYS_INSTALL_LICENSE_OPTIONS} COMPONENT ${KWSYS_INSTALL_COMPONENT_NAME_RUNTIME} ) endif() # Install the license under the documentation directory. install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt DESTINATION ${KWSYS_INSTALL_DOC_DIR}/${KWSYS_NAMESPACE} ${KWSYS_INSTALL_LICENSE_OPTIONS}) ``` -------------------------------- ### Install Package Config File Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/HDF5/src/itkhdf5/config/cmake/LIBAEC/CMakeLists.txt Installs the generated libaec-config.cmake file to the install destination if it was not externally configured. ```cmake if (NOT LIBAEC_EXTERNALLY_CONFIGURED) install ( FILES ${LIBAEC_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${LIBAEC_PACKAGE}${LIBAEC_PACKAGE_EXT}-config.cmake DESTINATION ${LIBAEC_INSTALL_CMAKE_DIR} COMPONENT configinstall ) endif () ``` -------------------------------- ### Configure Expat Installation Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/Expat/src/itkexpat/CMakeLists.txt Sets the option to install Expat files using the CMake install target. ```cmake expat_shy_set(EXPAT_ENABLE_INSTALL ON CACHE BOOL "Install expat files in cmake install target") ``` -------------------------------- ### Enable and Start Actions Runner Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/s390/README.md Enables the actions-runner service to start automatically on boot and starts it immediately. ```bash sudo systemctl enable --now actions-runner ``` -------------------------------- ### Configure zlib-config.cmake for Install Directory Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/HDF5/src/itkhdf5/config/cmake/ZLIBNG/CMakeLists.txt Generates the zlib-config.cmake file for the installation directory. This configuration is used when the project is installed. ```cmake set (INCLUDE_INSTALL_DIR ${ZLIB_INSTALL_INCLUDE_DIR}) set (SHARE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${ZLIB_INSTALL_CMAKE_DIR}" ) set (CURRENT_BUILD_DIR "${CMAKE_INSTALL_PREFIX}") configure_package_config_file ( ${ZLIB_RESOURCES_DIR}/zlib-config.cmake.in "${ZLIB_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/zlib-config.cmake" INSTALL_DESTINATION "${ZLIB_INSTALL_CMAKE_DIR}" PATH_VARS INCLUDE_INSTALL_DIR SHARE_INSTALL_DIR CURRENT_BUILD_DIR ) ``` -------------------------------- ### Install Man Page for Library Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/OpenJPEG/src/openjpeg/src/lib/openjp2/CMakeLists.txt Installs the man page for the libopenjp2 library if the BUILD_DOC option is enabled. ```cmake if(BUILD_DOC) # install man page of the library install( FILES ${OPENJPEG_SOURCE_DIR}/doc/man/man3/libopenjp2.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3) endif() ``` -------------------------------- ### RGB Image Read/Write Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Examples/IO/CMakeLists.txt Shows how to read and write RGB images. Links ITKImageIO and ITKCommonModule. ```cmake add_executable(RGBImageReadWrite RGBImageReadWrite.cxx) target_link_libraries( RGBImageReadWrite PRIVATE ITK::ITKImageIO ITK::ITKCommonModule ) ``` -------------------------------- ### Build and Install OpenJPEG Library Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/OpenJPEG/src/openjpeg/src/lib/openjp2/CMakeLists.txt Defines the library target, handles static/dynamic builds, and sets up installation rules for the library and headers. ```cmake add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS}) set(INSTALL_LIBS ${OPENJPEG_LIBRARY_NAME}) if(WIN32) if(BUILD_SHARED_LIBS) target_compile_definitions(${OPENJPEG_LIBRARY_NAME} PRIVATE OPJ_EXPORTS) else() target_compile_definitions(${OPENJPEG_LIBRARY_NAME} PUBLIC OPJ_STATIC) endif() elseif(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) add_library(openjp2_static STATIC ${OPENJPEG_SRCS}) set_target_properties(openjp2_static PROPERTIES OUTPUT_NAME ${OPENJPEG_LIBRARY_NAME}) list(APPEND INSTALL_LIBS openjp2_static) target_include_directories(openjp2_static PUBLIC $) endif() target_include_directories(${OPENJPEG_LIBRARY_NAME} PUBLIC $) if(UNIX) target_link_libraries(${OPENJPEG_LIBRARY_NAME} m) endif() set_target_properties(${OPENJPEG_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES}) target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJP2_COMPILE_OPTIONS}) ``` ```cmake install(TARGETS ${INSTALL_LIBS} EXPORT OpenJPEGTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries ) ``` ```cmake install(FILES openjpeg.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR} COMPONENT Headers ) ``` -------------------------------- ### Generate and install pkgconfig file Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/HDF5/src/itkhdf5/hl/c++/src/CMakeLists.txt Generates the pkgconfig file (.pc) from a template and installs it to the appropriate directory. This ensures the library is discoverable by package managers. ```cmake configure_file ( ${HDF_CONFIG_DIR}/libhdf5.pc.in ${HDF5_BINARY_DIR}/CMakeFiles/${HDF5_HL_CPP_LIB_CORENAME}.pc @ONLY ) install ( FILES ${HDF5_BINARY_DIR}/CMakeFiles/${HDF5_HL_CPP_LIB_CORENAME}.pc DESTINATION ${HDF5_INSTALL_LIB_DIR}/pkgconfig COMPONENT hlcpplibraries ) ``` -------------------------------- ### Install Development Components Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/MINC/src/libminc/CMakeLists.txt Installs CMake configuration files for development purposes if the installation directory is specified and development is not explicitly disabled. ```cmake if(LIBMINC_INSTALL_LIB_DIR AND NOT LIBMINC_INSTALL_NO_DEVELOPMENT) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Use${LIBMINC_EXTERNAL_LIB_PREFIX}LIBMINC.cmake ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${LIBMINC_EXTERNAL_LIB_PREFIX}LIBMINCConfig.cmake DESTINATION ${LIBMINC_INSTALL_LIB_DIR}/cmake COMPONENT Development) endif() ``` -------------------------------- ### Build TIFF from Source Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/TIFF/src/itktiff/README.md Standard commands to configure, build, and install the TIFF library from source. Ensure you have the necessary build tools installed. ```bash % ./configure % make % su # make install ``` -------------------------------- ### Install MD5 Library Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/GDCM/src/gdcm/Utilities/gdcmmd5/CMakeLists.txt Installs the MD5 library target. Components are specified for different types of installations (Applications, Libraries, DebugDevel). ```cmake if(NOT MD5_INSTALL_NO_LIBRARIES) install(TARGETS ${MD5_LIBRARY_NAME} EXPORT ${GDCM_TARGETS_NAME} RUNTIME DESTINATION ${MD5_INSTALL_BIN_DIR} COMPONENT Applications LIBRARY DESTINATION ${MD5_INSTALL_LIB_DIR} COMPONENT Libraries ARCHIVE DESTINATION ${MD5_INSTALL_LIB_DIR} COMPONENT DebugDevel ${CPACK_NAMELINK_TYPE} ) endif() ``` -------------------------------- ### Configure and Install PkgConfig File Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/Eigen3/src/itkeigen/CMakeLists.txt Configures the 'eigen3.pc.in' file to 'eigen3.pc' if EIGEN_BUILD_PKGCONFIG is enabled, and then installs it to the PkgConfig directory. ```cmake if(EIGEN_BUILD_PKGCONFIG) configure_file(eigen3.pc.in eigen3.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/eigen3.pc DESTINATION ${PKGCONFIG_INSTALL_DIR}) endif() ``` -------------------------------- ### Add Python package installation instructions Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Documentation/docs/releases/4.12.md Documentation providing instructions on how to install the ITK Python package. Essential for users wanting to utilize ITK's Python bindings. ```text # DOC: Add Python package installation instructions ``` -------------------------------- ### Install ZLIB Headers Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/ZLIB/src/itkzlib-ng/CMakeLists.txt Installs ZLIB header files, including zlib.h, zlib_name_mangling.h, and zconf.h. This is conditional on NOT skipping header installation or all components. ```cmake if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zlib${SUFFIX}.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RENAME zlib${SUFFIX}.h) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zlib_name_mangling${SUFFIX}.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RENAME zlib_name_mangling${SUFFIX}.h) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/zconf${SUFFIX}.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" RENAME zconf${SUFFIX}.h) endif() ``` -------------------------------- ### Configure and Install libopenjpip.pc Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/OpenJPEG/src/openjpeg/CMakeLists.txt Generates and installs the libopenjpip.pc pkg-config file if BUILD_JPIP is enabled. This file provides information about the installed OpenJPIP library. ```cmake if(BUILD_JPIP) get_pkgconfig_deps(openjpip deps) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) endif() ``` -------------------------------- ### Image Series Read/Write Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Examples/IO/CMakeLists.txt Demonstrates reading and writing a series of images. Requires ITKImageIO, ITKCommonModule, and ITKIOPNGModule. ```cmake add_executable(ImageSeriesReadWrite ImageSeriesReadWrite.cxx) target_link_libraries( ImageSeriesReadWrite PRIVATE ITK::ITKImageIO ITK::ITKCommonModule ITK::ITKIOPNGModule ) ``` -------------------------------- ### Configure and Install libopenjp2.pc Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/OpenJPEG/src/openjpeg/CMakeLists.txt Generates and installs the libopenjp2.pc pkg-config file. This file provides information about the installed OpenJPEG library for other projects to use. ```cmake configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) ``` -------------------------------- ### Display Build Options Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/NIFTI/src/nifti/README.md This command will display a list of available build options and targets for the project. ```bash "make help" ``` -------------------------------- ### Reporting Installed Targets Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Modules/ThirdParty/NIFTI/src/nifti/CMakeLists.txt Reports the list of installed NIFTI targets using a message. This is useful for debugging and verifying which targets have been marked for installation. ```cmake # Report installed targets get_property(nifti_installed_targets GLOBAL PROPERTY nifti_installed_targets) message(STATUS "nifti_installed_targets: ${nifti_installed_targets}") ``` -------------------------------- ### Image Series Read/Write Example 2 Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Examples/IO/CMakeLists.txt Another example for reading and writing image series. Links ITKImageIO, ITKCommonModule, and ITKIOPNGModule. ```cmake add_executable(ImageSeriesReadWrite2 ImageSeriesReadWrite2.cxx) target_link_libraries( ImageSeriesReadWrite2 PRIVATE ITK::ITKImageIO ITK::ITKCommonModule ITK::ITKIOPNGModule ) ``` -------------------------------- ### Installing ITKTargets.cmake Source: https://github.com/insightsoftwareconsortium/itk/blob/main/CMakeLists.txt This section conditionally installs the ITKTargets.cmake file. If ITKTargets_MODULES is defined, it installs the targets directly; otherwise, it creates a placeholder file. ```cmake get_property(ITKTargets_MODULES GLOBAL PROPERTY ITKTargets_MODULES) if(ITKTargets_MODULES) install( EXPORT ITKTargets DESTINATION ${ITK_INSTALL_PACKAGE_DIR} COMPONENT Development ) else() set(CMAKE_CONFIGURABLE_FILE_CONTENT "# No targets!") configure_file( ${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in ${ITK_BINARY_DIR}/CMakeFiles/ITKTargets.cmake @ONLY ) install( FILES ${ITK_BINARY_DIR}/CMakeFiles/ITKTargets.cmake DESTINATION ${ITK_INSTALL_PACKAGE_DIR} COMPONENT Development ) endif() ``` -------------------------------- ### Configure ITKConfig.cmake for Install Tree Source: https://github.com/insightsoftwareconsortium/itk/blob/main/CMakeLists.txt Generates the ITKConfig.cmake file for the install tree. This file helps determine the installation prefix based on its location. ```cmake set( ITK_CONFIG_CODE "\n# Compute the installation prefix from this ITKConfig.cmake file location.\nget_filename_component(ITK_INSTALL_PREFIX \"${CMAKE_CURRENT_LIST_FILE}\" PATH)" ) # Construct the proper number of get_filename_component(... PATH) ``` -------------------------------- ### Configuring ITK Example Data Root Source: https://github.com/insightsoftwareconsortium/itk/blob/main/CMakeLists.txt Sets the ITK_EXAMPLE_DATA_ROOT variable, indicating the path to ITK example data. This is used for examples and demonstrations. ```cmake set(ITK_EXAMPLE_DATA_ROOT "${ITK_SOURCE_DIR}/Examples/Data") ``` -------------------------------- ### Install ITK Python Bindings Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Wrapping/Generators/Python/CMakeLists.txt Installs the generated ITK Python bindings and configuration files. The `wrap_itk_python_bindings_install` macro is used to manage the installation process. ```cmake wrap_itk_python_bindings_install(/ "ITKCommon" "${ITK_WRAP_PYTHON_ROOT_BINARY_DIR}/itkConfig.py") ``` -------------------------------- ### Transform Read/Write Example Source: https://github.com/insightsoftwareconsortium/itk/blob/main/Examples/IO/CMakeLists.txt Demonstrates reading and writing ITK transforms. Requires ITKTransformIO, ITKTransformModule, and ITKTransformFactoryModule. ```cmake add_executable(TransformReadWrite TransformReadWrite.cxx) target_link_libraries( TransformReadWrite PRIVATE ITK::ITKTransformIO ITK::ITKTransformModule ITK::ITKTransformFactoryModule ) ```