<commit_before>/**
* @file   Multiresolution-SRS3D.cxx
* @author <NAME> <<EMAIL>>
* @date   Wed Mar 11 14:55:33 2015
* 
* @brief  Example for 3D SRS using handcrafted segmentation 
* 
* 
*/

#include <stdio.h>
#include <iostream>

#include "ArgumentParser.h"

#include "SRSConfig.h"
#include "HierarchicalSRSImageToImageFilter.h"
#include "Graph.h"
#include "FastGraph.h"
#include "BaseLabel.h"
#include "Metrics.h"
#include "Potential-Registration-Unary.h"
#include "Potential-Registration-Pairwise.h"
#include "Potential-Segmentation-Unary.h"
#include "Potential-Coherence-Pairwise.h"
#include "Potential-Segmentation-Pairwise.h"
#include "Log.h"
#include "Preprocessing.h"
#include "TransformationUtils.h"



using namespace std;
using namespace SRS;
using namespace itk;


bool (*realProgressCallbackFunc)(int progress);
bool MyProgressCallback(int progress) {
  return realProgressCallbackFunc(progress);
}


//////////////////////////////////////////////////
// The main registration algorithm entry function
//////////////////////////////////////////////////
EXTERN_C __declspec(dllexport) wchar_t* __cdecl DoRegistration(
  int             sourceSizeX,
  int             sourceSizeY,   
  int             sourceSizeZ,
  double          sourceResX,
  double          sourceResY,
  double          sourceResZ,
  unsigned short* sourcePixels,
  int             sourceModality,
  double          sourceSlope,
  double          sourceIntercept,
  int             targetSizeX,
  int             targetSizeY,
  int             targetSizeZ,
  double          targetResX,
  double          targetResY,
  double          targetResZ,
  unsigned short* targetPixels,
  int             targetModality,
  double          targetSlope,
  double          targetIntercept,
  double*         rigidAlignment,
  double          voiOriginX,
  double          voiOriginY,
  double          voiOriginZ,
  double          voiExtentX,
  double          voiExtentY,
  double          voiExtentZ,
  int             numOptionalArguments,
  wchar_t**       optionalArguments,
  int*            fieldSizeX,
  int*            fieldSizeY,
  int*            fieldSizeZ,
  double*         fieldResX,
  double*         fieldResY,
  double*         fieldResZ,
  double*         fieldOriginX,
  double*         fieldOriginY,
  double*         fieldOriginZ,
  float**         fieldVectors,
  bool            (*progressCallbackFunc)(int progress)
  )
{
  const bool DEFORM_ATLAS_IMAGE = false;
  const bool WRITE_IMAGES_OUT = false;
  // re-route the progress callback
  realProgressCallbackFunc = progressCallbackFunc;

  int progress = 0;
  realProgressCallbackFunc(progress);


  std::ofstream out("C:\\Users\\jstrasse\\Desktop\\out.txt");
  std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
  std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!

  

  SRSConfig::Pointer filterConfig = SRSConfig::New();
  filterConfig->parseFile("C:\\_SmartSeg\\srsConfigs.txt");

  progress = 3;
  realProgressCallbackFunc(progress);

  if (filterConfig->logFileName!=""){
    mylog.setCachedLogging();
  }

  progress = 5;
  realProgressCallbackFunc(progress);<commit_msg>added reading of optional arguments<commit_after>/**
* @file   Multiresolution-SRS3D.cxx
* @author <NAME> <<EMAIL>>
* @date   Wed Mar 11 14:55:33 2015
* 
* @brief  Example for 3D SRS using handcrafted segmentation 
* 
* 
*/

#include <stdio.h>
#include <iostream>

#include "ArgumentParser.h"

#include "SRSConfig.h"
#include "HierarchicalSRSImageToImageFilter.h"
#include "Graph.h"
#include "FastGraph.h"
#include "BaseLabel.h"
#include "Metrics.h"
#include "Potential-Registration-Unary.h"
#include "Potential-Registration-Pairwise.h"
#include "Potential-Segmentation-Unary.h"
#include "Potential-Coherence-Pairwise.h"
#include "Potential-Segmentation-Pairwise.h"
#include "Log.h"
#include "Preprocessing.h"
#include "TransformationUtils.h"



using namespace std;
using namespace SRS;
using namespace itk;


bool (*realProgressCallbackFunc)(int progress);
bool MyProgressCallback(int progress) {
  return realProgressCallbackFunc(progress);
}


//////////////////////////////////////////////////
// The main registration algorithm entry function
//////////////////////////////////////////////////
EXTERN_C __declspec(dllexport) wchar_t* __cdecl DoRegistration(
  int             sourceSizeX,
  int             sourceSizeY,   
  int             sourceSizeZ,
  double          sourceResX,
  double          sourceResY,
  double          sourceResZ,
  unsigned short* sourcePixels,
  int             sourceModality,
  double          sourceSlope,
  double          sourceIntercept,
  int             targetSizeX,
  int             targetSizeY,
  int             targetSizeZ,
  double          targetResX,
  double          targetResY,
  double          targetResZ,
  unsigned short* targetPixels,
  int             targetModality,
  double          targetSlope,
  double          targetIntercept,
  double*         rigidAlignment,
  double          voiOriginX,
  double          voiOriginY,
  double          voiOriginZ,
  double          voiExtentX,
  double          voiExtentY,
  double          voiExtentZ,
  int             numOptionalArguments,
  wchar_t**       optionalArguments,
  int*            fieldSizeX,
  int*            fieldSizeY,
  int*            fieldSizeZ,
  double*         fieldResX,
  double*         fieldResY,
  double*         fieldResZ,
  double*         fieldOriginX,
  double*         fieldOriginY,
  double*         fieldOriginZ,
  float**         fieldVectors,
  bool            (*progressCallbackFunc)(int progress)
  )
{
  const bool DEFORM_ATLAS_IMAGE = false;
  const bool WRITE_IMAGES_OUT = false;
  // re-route the progress callback
  realProgressCallbackFunc = progressCallbackFunc;

  int progress = 0;
  realProgressCallbackFunc(progress);


  std::ofstream out("C:\\Users\\jstrasse\\Desktop\\out.txt");
  std::streambuf *coutbuf = std::cout.rdbuf(); //save old buf
  std::cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!

  

  SRSConfig::Pointer filterConfig = SRSConfig::New();
  filterConfig->parseFile("C:\\_SmartSeg\\srsConfigs.txt");

  progress = 3;
  realProgressCallbackFunc(progress);

  //read optional arguments
  wstring firstString(optionalArguments[1]);
  string atlasDir(firstString.begin(), firstString.end());

  wstring secondString(optionalArguments[3]);
  string targetDir(secondString.begin(), secondString.end());

  //string atlasDir = "C:\\_Patients\\patientRomExpertCaseCut\\ECI053801";
  //string targetDir = "C:\\_Patients\\patientRomExpertCaseCut\\ECI054005";

  LOG<<"ATLAS DIR: " + atlasDir<<std::endl;
  LOG<<"TARGET DIR: " + targetDir<<std::endl;

  filterConfig->atlasLandmarkFilename = atlasDir + "\\landmarks.txt";
  filterConfig->targetLandmarkFilename = targetDir + "\\landmarks.txt";
  if (true) {
    LOG<<"Mask Image: " + atlasDir + "\\iMask.vtk"<<std::endl;
    filterConfig->atlasMaskFilename = atlasDir + "\\iMask.vtk";
  } else {
    LOG<<"NO MASK IMAGE"<<std::endl;
  }




  if (filterConfig->logFileName!=""){
    mylog.setCachedLogging();
  }

  progress = 5;
  realProgressCallbackFunc(progress);
{'fraction_non_alphanumeric': 0.1298265249020705, 'fraction_numerical': 0.006715165081141578, 'mean_word_length': 2.6087834427057044, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3752298', 'n_tokens_mistral': 2252, 'n_tokens_neox': 2161, 'n_words': 465}