<commit_before>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSFile: $
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) 2000 National Library of Medicine
  All rights reserved.

  See COPYRIGHT.txt for copyright details.

=========================================================================*/

#ifndef __itkImageMomentsCalculator_h
#define __itkImageMomentsCalculator_h

#include "itkAffineTransform.h"
#include "itkMacro.h"

#include "vnl/vnl_vector_fixed.h"
#include "vnl/vnl_matrix_fixed.h"
#include "vnl/vnl_diag_matrix.h"

namespace itk
{

/** 
 * Compute moments of an n-dimensional image.
 *
 * This class provides methods for computing the moments and related
 * properties of a single-echo image.  Computing the (non-central)
 * moments of a large image can easily take a million times longer
 * than computing the various other values derived from them, so we
 * compute the moments only on explicit request, and save their values
 * (in an ImageMomentsCalculator object) for later retrieval by the user.
 *
 * The non-central moments computed by this class are not really 
 * intended for general use and are therefore in index coordinates;
 * that is, we pretend that the index that selects a particular
 * pixel also equals its physical coordinates.  The center of gravity,
 * central moments, principal moments and principal axes are all
 * more generally useful and are computed in the physical coordinates
 * defined by the Origin and Spacing parameters of the image.
 *
 * The methods that return values return the values themselves rather
 * than references because the cost is small compared to the cost of
 * computing the moments and doing so simplifies memory management for
 * the caller.
 *
 * FIXME: It's not yet clear how multi-echo images should be handled here.
 *
 * FIXME: The current implementation supports rank 3 images only.
 *
 */

// FIXME:  Find right incantation to doxygenate the template parameters
template <
    class TPixel,             // Type of the image data
    int   VRank >             // Rank = Number of dimensions
class ImageMomentsCalculator
{
public:

    /// Standard self typedef
    typedef ImageMomentsCalculator<TPixel, VRank>            Self;

    /// Standard scalar type within this class.
    typedef double                                 ScalarType;

    /// Standard vector type within this class.
    typedef vnl_vector_fixed<double,VRank>         VectorType;

    /// Standard matrix type within this class.
    typedef vnl_matrix_fixed<double,VRank,VRank>   MatrixType;

    /// Standard image type within this class.
    typedef typename Image<TPixel, VRank>::Pointer ImageType;

    /// Standard affine transform type for this class
    typedef AffineTransform<double, VRank> AffineTransformType;

    /**
     * Compute moments of a new or modified image.
     *
     * This method computes the moments of the image given as a
     * parameter and stores them in the object.  The values of these
     * moments and related parameters can then be retrieved by using
     * other methods of this object.
     *<commit_msg>ENH: vnl vector and matrix types changed by itkVector and itkMatrix<commit_after>/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSFile: $
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) 2000 National Library of Medicine
  All rights reserved.

  See COPYRIGHT.txt for copyright details.

=========================================================================*/

#ifndef __itkImageMomentsCalculator_h
#define __itkImageMomentsCalculator_h

#include "itkAffineTransform.h"
#include "itkMacro.h"

#include "vnl/vnl_vector_fixed.h"
#include "vnl/vnl_matrix_fixed.h"
#include "vnl/vnl_diag_matrix.h"

namespace itk
{

/** 
 * Compute moments of an n-dimensional image.
 *
 * This class provides methods for computing the moments and related
 * properties of a single-echo image.  Computing the (non-central)
 * moments of a large image can easily take a million times longer
 * than computing the various other values derived from them, so we
 * compute the moments only on explicit request, and save their values
 * (in an ImageMomentsCalculator object) for later retrieval by the user.
 *
 * The non-central moments computed by this class are not really 
 * intended for general use and are therefore in index coordinates;
 * that is, we pretend that the index that selects a particular
 * pixel also equals its physical coordinates.  The center of gravity,
 * central moments, principal moments and principal axes are all
 * more generally useful and are computed in the physical coordinates
 * defined by the Origin and Spacing parameters of the image.
 *
 * The methods that return values return the values themselves rather
 * than references because the cost is small compared to the cost of
 * computing the moments and doing so simplifies memory management for
 * the caller.
 *
 * FIXME: It's not yet clear how multi-echo images should be handled here.
 *
 * FIXME: The current implementation supports rank 3 images only.
 *
 */

// FIXME:  Find right incantation to doxygenate the template parameters
template <
    class TPixel,             // Type of the image data
    int   VRank >             // Rank = Number of dimensions
class ImageMomentsCalculator
{
public:

    /// Standard self typedef
    typedef ImageMomentsCalculator<TPixel, VRank>            Self;

    /// Standard scalar type within this class.
    typedef double                                 ScalarType;

    /// Standard vector type within this class.
    typedef Vector<double,VRank>         VectorType;

    /// Standard matrix type within this class.
    typedef Matrix<double,VRank,VRank>   MatrixType;

    /// Standard image type within this class.
    typedef typename Image<TPixel, VRank>::Pointer ImageType;

    /// Standard affine transform type for this class
    typedef AffineTransform<double, VRank> AffineTransformType;

    /**
     * Compute moments of a new or modified image.
     *
     * This method computes the moments of the image given as a
     * parameter and stores them in the object.  The values of these
     * moments and related parameters can then be retrieved by using
     * other methods of this object.
     *
{'fraction_non_alphanumeric': 0.10113916256157636, 'fraction_numerical': 0.001539408866995074, 'mean_word_length': 3.4107264086897486, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6191010', 'n_tokens_mistral': 1664, 'n_tokens_neox': 1567, 'n_words': 740}