<commit_before>/*++++++++++++++++++++INCLUDES+and+Definitions++++++++++++++++++++++++*/

#include <vigra/matlab.hxx>
#include <vigra/labelimage.hxx>
#include <vigra/labelvolume.hxx>
#include <vigra/matlab_FLEXTYPE.hxx>


//this could be a typedef but if you want outType to be the same type as inType then you can just
//set outType to T


using namespace vigra;
using namespace matlab;



//#define RN_DEBUG
#define cP3_(a, b , c) cP3<a, b, c>::value
template <class T>
void vigraMain(matlab::OutputArray outputs, matlab::InputArray inputs){

    /***************************************************************************************************
    **              INIT PART                                                                         **
    ***************************************************************************************************/
    typedef UInt32 OutputType
    MultiArrayView<3,T>     in3D        =       inputs.getMultiArray<3,T>(0, Required());
    BasicImageView<T>       in          =       makeBasicImageView(in3D.bindOuter(0));
    int                     numOfDim    =       inputs.getDimOfInput(0, Required());

    int                     v2Dconn[2]  =       {8, 4};
    int                     v3Dconn[2]  =       {26, 6};
    int                     connectivity=       inputs.getScalarVals2D3D<int>("conn", v_default(8,26,numOfDim),
                                                                                    v2Dconn, v2Dconn+2,
                                                                                    v3Dconn, v3Dconn+2,
                                                                                    numOfDim);
    /*{
        if(numOfDim == 2 && connectivity!= 8 && connectivity != 4)
            mexErrMsgTxt("Connectivity for 2D data must be 8 or 4");
        else if(numOfDim == 3 && connectivity!= 26 && connectivity != 6)
            mexErrMsgTxt("Connectivity for 3D data must be 26 or 6");
    }*/


    bool                    hasBackground;
    T                       backgroundValue = inputs.getScalar<T>("backgroundValue", v_optional(hasBackground));

    MultiArrayView<3,outputType>     out3D           = outputs.createMultiArray      <3,outputType>   (0, v_required(), in3D.shape());
    BasicImageView<outputType>       out(out3D.data(), in3D.shape(0), in3D.shape(1));

    int                     max_region_label = (hasBackground == true)? 1: 0;

    /***************************************************************************************************
    **              CODE PART                                                                         **
    ****************************************************************************************************/
    #ifdef RN_DEBUG
    mexPrintf("---%d---%d---%d---", max_region_label, numOfDim, connectivity);
    #endif
    switch(cantorPair(hasBackground , numOfDim, connectivity)){
        //cP is the templated version o f the cantorPair function first value is Dimension of Inputimage, second the connectivity setting
        //Code is basically the code on the VIGRA-reference page
        case cP3_(0, IMAG, 8):
            #ifdef RN_DEBUG
            mexWarnMsgTxt("0, IMAG, 8");
            #endif
            max_region_label = labelImage(srcImageRange(in), destImage(out), true);
            break;
        case cP3_(0, IMAG, 4):
            #ifdef RN_DEBUG
            mexWarnMsgTxt("0, IMAG, 4");
            #endif
            max_region_label = labelImage(srcImageRange(in), destImage(out), false);
            break;
        case cP3_(0, VOLUME, 6):
            #ifdef RN_DEBUG<commit_msg>minor bug fix<commit_after>/*++++++++++++++++++++INCLUDES+and+Definitions++++++++++++++++++++++++*/

#include <vigra/matlab.hxx>
#include <vigra/labelimage.hxx>
#include <vigra/labelvolume.hxx>
#include <vigra/matlab_FLEXTYPE.hxx>


//this could be a typedef but if you want outType to be the same type as inType then you can just
//set outType to T


using namespace vigra;
using namespace matlab;



//#define RN_DEBUG
#define cP3_(a, b , c) cP3<a, b, c>::value
template <class T>
void vigraMain(matlab::OutputArray outputs, matlab::InputArray inputs){

    /***************************************************************************************************
    **              INIT PART                                                                         **
    ***************************************************************************************************/
    typedef UInt32 OutputType;
    MultiArrayView<3,T>     in3D        =       inputs.getMultiArray<3,T>(0, v_required());
    BasicImageView<T>       in          =       makeBasicImageView(in3D.bindOuter(0));
    int                     numOfDim    =       inputs.getDimOfInput(0, v_required());

    int                     v2Dconn[2]  =       {8, 4};
    int                     v3Dconn[2]  =       {26, 6};
    int                     connectivity=       inputs.getScalarVals2D3D<int>("conn", v_default(8,26,numOfDim),
                                                                                    v2Dconn, v2Dconn+2,
                                                                                    v3Dconn, v3Dconn+2,
                                                                                    numOfDim);
    /*{
        if(numOfDim == 2 && connectivity!= 8 && connectivity != 4)
            mexErrMsgTxt("Connectivity for 2D data must be 8 or 4");
        else if(numOfDim == 3 && connectivity!= 26 && connectivity != 6)
            mexErrMsgTxt("Connectivity for 3D data must be 26 or 6");
    }*/


    bool                    hasBackground;
    T                       backgroundValue = inputs.getScalar<T>("backgroundValue", v_optional(hasBackground));

    MultiArrayView<3,OutputType>     out3D           = outputs.createMultiArray      <3,OutputType>   (0, v_required(), in3D.shape());
    BasicImageView<OutputType>       out(out3D.data(), in3D.shape(0), in3D.shape(1));

    int                     max_region_label = (hasBackground == true)? 1: 0;

    /***************************************************************************************************
    **              CODE PART                                                                         **
    ****************************************************************************************************/
    #ifdef RN_DEBUG
    mexPrintf("---%d---%d---%d---", max_region_label, numOfDim, connectivity);
    #endif
    switch(cantorPair(hasBackground , numOfDim, connectivity)){
        //cP is the templated version o f the cantorPair function first value is Dimension of Inputimage, second the connectivity setting
        //Code is basically the code on the VIGRA-reference page
        case cP3_(0, IMAG, 8):
            #ifdef RN_DEBUG
            mexWarnMsgTxt("0, IMAG, 8");
            #endif
            max_region_label = labelImage(srcImageRange(in), destImage(out), true);
            break;
        case cP3_(0, IMAG, 4):
            #ifdef RN_DEBUG
            mexWarnMsgTxt("0, IMAG, 4");
            #endif
            max_region_label = labelImage(srcImageRange(in), destImage(out), false);
            break;
        case cP3_(0, VOLUME, 6):
            #ifdef RN_DEBUG
{'fraction_non_alphanumeric': 0.21041809458533242, 'fraction_numerical': 0.019191226867717615, 'mean_word_length': 1.8466640655481856, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4809967', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1809, 'n_words': 443}