<commit_before>
#include "antsUtilities.h"
#include <algorithm>

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkLabelGeometryImageFilter.h"

#include <iomanip>
#include <iostream>
#include <ostream>
#include <sstream>

namespace ants
{
template <unsigned int ImageDimension>
int LabelGeometryMeasures( int argc, char * argv[] )
{
  typedef int                                   LabelType;
  typedef itk::Image<LabelType, ImageDimension> LabelImageType;
  typedef itk::ImageFileReader<LabelImageType>  LabelReaderType;

  typedef float                                RealType;
  typedef itk::Image<RealType, ImageDimension> RealImageType;
  typedef itk::ImageFileReader<RealImageType>  ReaderType;

  typename LabelReaderType::Pointer labelReader = LabelReaderType::New();
  labelReader->SetFileName( argv[2] );
  labelReader->Update();

  typename ReaderType::Pointer reader = ReaderType::New();
  if( argc > 3 )
    {
    reader->SetFileName( argv[3] );
    reader->Update();
    }

  typedef itk::LabelGeometryImageFilter<LabelImageType, RealImageType> FilterType;
  typename FilterType::Pointer filter = FilterType::New();
  filter->SetInput( labelReader->GetOutput() );
  if( argc > 3 )
    {
    filter->SetIntensityInput( reader->GetOutput() );
    }
  filter->CalculatePixelIndicesOff();
  filter->CalculateOrientedBoundingBoxOff();
  filter->CalculateOrientedLabelRegionsOff();
  // These generate optional outputs.
//   filter->CalculatePixelIndicesOn();
//   filter->CalculateOrientedBoundingBoxOn();;
//   filter->CalculateOrientedLabelRegionsOn();
  filter->Update();

  typename FilterType::LabelsType allLabels = filter->GetLabels();
  typename FilterType::LabelsType::iterator allLabelsIt;
//   antscout << "Number of labels: " << labelGeometryFilter->GetNumberOfLabels() << std::endl;
//   antscout << "Label geometry measures." << std::endl;
  antscout << std::left << std::setw( 7 )  << "Label"
           << std::left << std::setw( 10 ) << "Volume"
           << std::left << std::setw( 15 ) << "Eccentricity"
           << std::left << std::setw( 15 ) << "Elongation"
           << std::left << std::setw( 15 ) << "Orientation"
           << std::left << std::setw( 30 ) << "Centroid"
           << std::left << std::setw( 30 ) << "Axes Length"
           << std::left << std::setw( 30 ) << "Bounding Box";
  if( filter->GetIntensityInput() )
    {
    antscout << std::left << std::setw( 20 )  << "Integrated Int."
             << std::left << std::setw( 30 ) << "Weighted Centroid";
    }
  antscout << std::endl;
  for( allLabelsIt = allLabels.begin(); allLabelsIt != allLabels.end(); allLabelsIt++ )
    {
    if( *allLabelsIt == 0 )
      {
      continue;
      }
    antscout << std::setw( 7 ) << *allLabelsIt;
    antscout << std::setw( 10 ) << filter->GetVolume( *allLabelsIt );
    antscout << std::setw( 15 ) << filter->GetEccentricity( *allLabelsIt );
    antscout << std::setw( 15 ) << filter->GetElongation( *allLabelsIt );
    antscout << std::setw( 15 ) << filter->GetOrientation( *allLabelsIt );

    std::stringstream oss;
    oss << filter->GetCentroid( *allLabelsIt );
    antscout << std::setw( 30 ) << ( oss.str() ).c_str();
    oss.str( "" );

    oss << filter->GetAxesLength( *allLabelsIt );
    antscout << std::setw( 30 ) << ( oss.str() ).c_str();<commit_msg>ENH:  Adding surface area calculation.<commit_after>#include "antsUtilities.h"
#include <algorithm>

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkLabelGeometryImageFilter.h"
#include "itkLabelPerimeterEstimationCalculator.h"

#include <iomanip>
#include <iostream>
#include <ostream>
#include <sstream>

namespace ants
{
template <unsigned int ImageDimension>
int LabelGeometryMeasures( int argc, char * argv[] )
{
  typedef int                                   LabelType;
  typedef itk::Image<LabelType, ImageDimension> LabelImageType;
  typedef itk::ImageFileReader<LabelImageType>  LabelReaderType;

  typedef float                                RealType;
  typedef itk::Image<RealType, ImageDimension> RealImageType;
  typedef itk::ImageFileReader<RealImageType>  ReaderType;

  typename LabelReaderType::Pointer labelReader = LabelReaderType::New();
  labelReader->SetFileName( argv[2] );
  labelReader->Update();

  typename ReaderType::Pointer reader = ReaderType::New();
  if( argc > 3 )
    {
    reader->SetFileName( argv[3] );
    reader->Update();
    }

  typedef itk::LabelGeometryImageFilter<LabelImageType, RealImageType> FilterType;
  typename FilterType::Pointer filter = FilterType::New();
  filter->SetInput( labelReader->GetOutput() );
  if( argc > 3 )
    {
    filter->SetIntensityInput( reader->GetOutput() );
    }
  filter->CalculatePixelIndicesOff();
  filter->CalculateOrientedBoundingBoxOff();
  filter->CalculateOrientedLabelRegionsOff();
  // These generate optional outputs.
//   filter->CalculatePixelIndicesOn();
//   filter->CalculateOrientedBoundingBoxOn();;
//   filter->CalculateOrientedLabelRegionsOn();
  filter->Update();

  typedef itk::LabelPerimeterEstimationCalculator<LabelImageType> AreaFilterType;
  typename AreaFilterType::Pointer areafilter = AreaFilterType::New();
  areafilter->SetImage( labelReader->GetOutput() );
  areafilter->Compute();


  typename FilterType::LabelsType allLabels = filter->GetLabels();
  typename FilterType::LabelsType::iterator allLabelsIt;
//   antscout << "Number of labels: " << labelGeometryFilter->GetNumberOfLabels() << std::endl;
//   antscout << "Label geometry measures." << std::endl;
  antscout << std::left << std::setw( 7 )  << "Label"
           << std::left << std::setw( 10 ) << "Volume"
           << std::left << std::setw( 15 ) << "SurfArea(mm^2)"
           << std::left << std::setw( 15 ) << "Eccentricity"
           << std::left << std::setw( 15 ) << "Elongation"
           << std::left << std::setw( 15 ) << "Orientation"
           << std::left << std::setw( 30 ) << "Centroid"
           << std::left << std::setw( 30 ) << "Axes Length"
           << std::left << std::setw( 30 ) << "Bounding Box";
  if( filter->GetIntensityInput() )
    {
    antscout << std::left << std::setw( 20 )  << "Integrated Int."
             << std::left << std::setw( 30 ) << "Weighted Centroid";
    }
  antscout << std::endl;
  for( allLabelsIt = allLabels.begin(); allLabelsIt != allLabels.end(); allLabelsIt++ )
    {
    if( *allLabelsIt == 0 )
      {
      continue;
      }
    antscout << std::setw( 7 ) << *allLabelsIt;
    antscout << std::setw( 10 ) << filter->GetVolume( *allLabelsIt );
    antscout << std::setw( 15 ) << areafilter->GetPerimeter( *allLabelsIt );
    antscout << std::setw( 15 ) << filter->GetEccentricity( *allLabelsIt );
    antscout << std::setw( 15 ) << filter->GetElongation( *allLabelsIt );
    antscout << std::setw( 15 ) << filter->GetOrientation( *allLabelsIt );

    std::stringstream oss;
    oss << filter->GetCentroid( *allLabelsIt );
    antscout << std::setw( 30 ) << ( oss.str() ).c_str();
    oss.str( "" );

    oss << filter->GetAxesLength( *allLabelsIt );
    antscout << std::setw( 30 ) << ( oss.str() ).c_str();
{'fraction_non_alphanumeric': 0.16199464713339906, 'fraction_numerical': 0.011128327933511763, 'mean_word_length': 3.698874917273329, 'pattern_counts': {'":': 0, '<': 244, '<?xml version=': 0, '>': 82, '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': '6867816', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2214, 'n_words': 453}