<commit_before>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  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
 *
 *         http://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 "itkVTKTetrahedralMeshReader.h"
#include "itkImage.h"
#include "itkVector.h"
#include "itkImageFileReader.h"
#include "itkPhysicsBasedNonRigidRegistrationMethod.h"
#include "itkWarpImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkImageFileWriter.h"
#include "itkTestingMacros.h"

#include <iostream>


int itkPhysicsBasedNonRigidRegistrationMethodTest( int argc, char *argv[] )
{
  if( argc != 12 )
    {
    std::cerr << "Missing Parameters" << std::endl;
    std::cerr << "Usage: " << argv[0]
      << " fixedImageFile"
      << " movingImageFile"
      << " maskImageFile"
      << " meshFile"
      << " outputImageFile"
      << " selectionFraction"
      << " nonConnectivity"
      << " blockRadius"
      << " searchRadius"
      << " approximationSteps"
      << " outlierRejectionSteps";
    std::cerr << std::endl;
    return EXIT_FAILURE;
    }

  const unsigned int ImageDimension = 3;

  typedef short                                          InputPixelType;
  typedef itk::Image< InputPixelType,  ImageDimension >  InputImageType;
  typedef float                                          MeshPixelType;
  typedef itk::Mesh< MeshPixelType, ImageDimension >     MeshType;

  typedef itk::ImageFileReader< InputImageType >         ImageReaderType;

  // Read fixed image
  ImageReaderType::Pointer fixedImageReader = ImageReaderType::New();
  fixedImageReader->SetFileName( argv[1] );

  TRY_EXPECT_NO_EXCEPTION( fixedImageReader->Update() );

  // Read moving image
  ImageReaderType::Pointer movingImageReader = ImageReaderType::New();
  movingImageReader->SetFileName( argv[2] );

  TRY_EXPECT_NO_EXCEPTION( movingImageReader->Update() );

  // Read mask image
  ImageReaderType::Pointer maskImageReader = ImageReaderType::New();
  maskImageReader->SetFileName( argv[3] );

  TRY_EXPECT_NO_EXCEPTION( maskImageReader->Update() );

  // Read mesh
  typedef itk::VTKTetrahedralMeshReader< MeshType > MeshReaderType;

  MeshReaderType::Pointer meshReader = MeshReaderType::New();
  meshReader->SetFileName( argv[4] );

  TRY_EXPECT_NO_EXCEPTION( meshReader->Update() );

  // Create PhysicsBasedNonRigidRegistrationMethod filter
  typedef itk::Image< itk::Vector< MeshPixelType, ImageDimension >,
    ImageDimension > DeformationFieldType;
  typedef itk::fem::PhysicsBasedNonRigidRegistrationMethod<
    InputImageType, InputImageType, InputImageType, MeshType,
    DeformationFieldType> PBNRRFilterType;

  PBNRRFilterType::Pointer filter = PBNRRFilterType::New();

  EXERCISE_BASIC_OBJECT_METHODS( filter,
    PhysicsBasedNonRigidRegistrationMethod,
    ImageToImageFilter );


  InputImageType::Pointer fixedImage = fixedImageReader->GetOutput();
  filter->SetFixedImage( fixedImage );
  TEST_SET_GET_VALUE( fixedImage, filter->GetFixedImage() );

  InputImageType::Pointer movingImage = movingImageReader->GetOutput();
  filter->SetMovingImage( movingImage );
  TEST_SET_GET_VALUE( movingImage, filter->GetMovingImage() );

  InputImageType::Pointer maskImage = maskImageReader->GetOutput();
  filter->SetMaskImage( maskImage );
  TEST_SET_GET_VALUE( maskImage, filter->GetMaskImage() );

  MeshType::Pointer mesh = meshReader->GetOutput();
  filter->SetMesh( mesh );
  TEST_SET_GET_VALUE( mesh, filter->GetMesh() );

  double selectionFraction = atof( argv[6] );
  filter->SetSelectFraction( selectionFraction );
  TEST_SET_GET_VALUE( selectionFraction, filter->GetSelectFraction() );

  unsigned int nonConnectivity = atoi( argv[7] );
  filter->SetNonConnectivity( nonConnectivity );
  TEST_SET_GET_VALUE( nonConnectivity, filter->GetNonConnectivity() );

  PBNRRFilterType::ImageSizeType::SizeValueType blockRadiusValue =
    atof( argv[8] );
  PBNRRFilterType::ImageSizeType blockRadius;
  blockRadius.Fill( blockRadiusValue );
  filter->SetBlockRadius( blockRadius );
  TEST_SET_GET_VALUE( blockRadius, filter->GetBlockRadius() );

  PBNRRFilterType::ImageSizeType::SizeValueType searchRadiusValue =
    atof( argv[9] );
  PBNRRFilterType::ImageSizeType searchRadius;<commit_msg>COMP: Fix itkPhysicsBasedNonRigidRegistrationMethodTest cast warning.<commit_after>/*=========================================================================
 *
 *  Copyright Insight Software Consortium
 *
 *  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
 *
 *         http://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 "itkVTKTetrahedralMeshReader.h"
#include "itkImage.h"
#include "itkVector.h"
#include "itkImageFileReader.h"
#include "itkPhysicsBasedNonRigidRegistrationMethod.h"
#include "itkWarpImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"
#include "itkImageFileWriter.h"
#include "itkTestingMacros.h"

#include <iostream>


int itkPhysicsBasedNonRigidRegistrationMethodTest( int argc, char *argv[] )
{
  if( argc != 12 )
    {
    std::cerr << "Missing Parameters" << std::endl;
    std::cerr << "Usage: " << argv[0]
      << " fixedImageFile"
      << " movingImageFile"
      << " maskImageFile"
      << " meshFile"
      << " outputImageFile"
      << " selectionFraction"
      << " nonConnectivity"
      << " blockRadius"
      << " searchRadius"
      << " approximationSteps"
      << " outlierRejectionSteps";
    std::cerr << std::endl;
    return EXIT_FAILURE;
    }

  const unsigned int ImageDimension = 3;

  typedef short                                          InputPixelType;
  typedef itk::Image< InputPixelType,  ImageDimension >  InputImageType;
  typedef float                                          MeshPixelType;
  typedef itk::Mesh< MeshPixelType, ImageDimension >     MeshType;

  typedef itk::ImageFileReader< InputImageType >         ImageReaderType;

  // Read fixed image
  ImageReaderType::Pointer fixedImageReader = ImageReaderType::New();
  fixedImageReader->SetFileName( argv[1] );

  TRY_EXPECT_NO_EXCEPTION( fixedImageReader->Update() );

  // Read moving image
  ImageReaderType::Pointer movingImageReader = ImageReaderType::New();
  movingImageReader->SetFileName( argv[2] );

  TRY_EXPECT_NO_EXCEPTION( movingImageReader->Update() );

  // Read mask image
  ImageReaderType::Pointer maskImageReader = ImageReaderType::New();
  maskImageReader->SetFileName( argv[3] );

  TRY_EXPECT_NO_EXCEPTION( maskImageReader->Update() );

  // Read mesh
  typedef itk::VTKTetrahedralMeshReader< MeshType > MeshReaderType;

  MeshReaderType::Pointer meshReader = MeshReaderType::New();
  meshReader->SetFileName( argv[4] );

  TRY_EXPECT_NO_EXCEPTION( meshReader->Update() );

  // Create PhysicsBasedNonRigidRegistrationMethod filter
  typedef itk::Image< itk::Vector< MeshPixelType, ImageDimension >,
    ImageDimension > DeformationFieldType;
  typedef itk::fem::PhysicsBasedNonRigidRegistrationMethod<
    InputImageType, InputImageType, InputImageType, MeshType,
    DeformationFieldType> PBNRRFilterType;

  PBNRRFilterType::Pointer filter = PBNRRFilterType::New();

  EXERCISE_BASIC_OBJECT_METHODS( filter,
    PhysicsBasedNonRigidRegistrationMethod,
    ImageToImageFilter );


  InputImageType::Pointer fixedImage = fixedImageReader->GetOutput();
  filter->SetFixedImage( fixedImage );
  TEST_SET_GET_VALUE( fixedImage, filter->GetFixedImage() );

  InputImageType::Pointer movingImage = movingImageReader->GetOutput();
  filter->SetMovingImage( movingImage );
  TEST_SET_GET_VALUE( movingImage, filter->GetMovingImage() );

  InputImageType::Pointer maskImage = maskImageReader->GetOutput();
  filter->SetMaskImage( maskImage );
  TEST_SET_GET_VALUE( maskImage, filter->GetMaskImage() );

  MeshType::Pointer mesh = meshReader->GetOutput();
  filter->SetMesh( mesh );
  TEST_SET_GET_VALUE( mesh, filter->GetMesh() );

  double selectionFraction = atof( argv[6] );
  filter->SetSelectFraction( selectionFraction );
  TEST_SET_GET_VALUE( selectionFraction, filter->GetSelectFraction() );

  unsigned int nonConnectivity = atoi( argv[7] );
  filter->SetNonConnectivity( nonConnectivity );
  TEST_SET_GET_VALUE( nonConnectivity, filter->GetNonConnectivity() );

  PBNRRFilterType::ImageSizeType::SizeValueType blockRadiusValue =
    static_cast< PBNRRFilterType::ImageSizeType::SizeValueType >( atof( argv[8] ) );
  PBNRRFilterType::ImageSizeType blockRadius;
  blockRadius.Fill( blockRadiusValue );
  filter->SetBlockRadius( blockRadius );
  TEST_SET_GET_VALUE( blockRadius, filter->GetBlockRadius() );

  PBNRRFilterType::ImageSizeType::SizeValueType searchRadiusValue =
    static_cast< PBNRRFilterType::ImageSizeType::SizeValueType >( atof( argv[9] ) );
  PBNRRFilterType::ImageSizeType searchRadius;
{'fraction_non_alphanumeric': 0.1329538524090262, 'fraction_numerical': 0.0032526936369180726, 'mean_word_length': 4.78764705882353, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5046926', 'n_tokens_mistral': 2899, 'n_tokens_neox': 2807, 'n_words': 601}