<commit_before>
/*jslint browser: true, node: true */
/*global bind, isString, papayaMain, deref, papayaParams */

"use strict";

var papaya = papaya || {};
papaya.viewer = papaya.viewer || {};


papaya.viewer.Atlas = papaya.viewer.Atlas || function (atlas) {
    this.name = null;
    this.transformedname = null;
    this.labels = [];
    this.atlasLabelData = atlas.labels;
    this.volume = new papaya.volume.Volume();
    this.displayColumns = null;
    this.returnLabels = null;
    this.transform = null;
    this.currentAtlas = null;
    this.maxLabels = 0;
    this.probabilistic = false;

    var loadableImage = papayaMain.findLoadableImage(atlas.labels.atlas.header.images.summaryimagefile);

    if ((loadableImage !== null) && (loadableImage.encode !== undefined)) {
        this.volume.readEncodedData(loadableImage.encode, bind(this, this.readFinished));
    } else if ((loadableImage !== null) && (loadableImage.url !== undefined)) {
        this.volume.readURL(loadableImage.url, bind(this, this.readFinished));
    }
};



papaya.viewer.Atlas.MAX_LABELS = 4;
papaya.viewer.Atlas.PROBABILISTIC = [ "probabalistic", "probabilistic", "statistic" ]; // typo is in FSL < 5.0.2
papaya.viewer.Atlas.LABEL_SPLIT_REGEX = /\.|:|,|\//;  // possible delimiters



papaya.viewer.Atlas.prototype.getLabelAtCoordinate = function (xLoc, yLoc, zLoc) {
    var xTrans, yTrans, zTrans, val;

    if (this.transform && (this.currentAtlas === this.transformedname)) {
        xTrans = ((xLoc * this.transform[0][0]) + (yLoc * this.transform[0][1]) + (zLoc * this.transform[0][2]) + (this.transform[0][3]));
        yTrans = ((xLoc * this.transform[1][0]) + (yLoc * this.transform[1][1]) + (zLoc * this.transform[1][2]) + (this.transform[1][3]));
        zTrans = ((xLoc * this.transform[2][0]) + (yLoc * this.transform[2][1]) + (zLoc * this.transform[2][2]) + (this.transform[2][3]));
    } else {
        xTrans = xLoc;
        yTrans = yLoc;
        zTrans = zLoc;
    }

    val = (this.volume.getVoxelAtCoordinate(xTrans, yTrans, zTrans, 0, true));

    if (this.probabilistic) {
        val -= 1;
    }

    return this.formatLabels(this.labels[val], this.returnLabels);
};



papaya.viewer.Atlas.prototype.readFinished = function () {
    this.parseTransform();
    this.parseLabels();
    this.parseDisplayColumns();
    this.maxLabels = this.findMaxLabelParts();
    this.currentAtlas = this.name;
    this.probabilistic = this.atlasLabelData.atlas.header.type
        && ((this.atlasLabelData.atlas.header.type.toLowerCase() === papaya.viewer.Atlas.PROBABILISTIC[0])
            || (this.atlasLabelData.atlas.header.type.toLowerCase() === papaya.viewer.Atlas.PROBABILISTIC[1])
            || (this.atlasLabelData.atlas.header.type.toLowerCase() === papaya.viewer.Atlas.PROBABILISTIC[2]));

    this.returnLabels = [];
    this.returnLabels.length = this.maxLabels;

    if (this.atlasLabelData.atlas.header.transformedname) {
        this.transformedname = this.atlasLabelData.atlas.header.transformedname;
    }

    this.name = this.atlasLabelData.atlas.header.name;

    var params = papayaParams.atlas;
    if (params) {
        if (params === this.transformedname) {
            this.currentAtlas = this.transformedname;
        }
    }
};



papaya.viewer.Atlas.prototype.parseDisplayColumns = function () {
    var index, columns, ctr;

    if (this.atlasLabelData.atlas.header.display) {  // uses "display" attribute
        this.displayColumns = [];
        index = 0;
        columns = this.atlasLabelData.atlas.header.display.split(papaya.viewer.Atlas.LABEL_SPLIT_REGEX);

        for (ctr = 0; ctr < columns.length; ctr += 1) {
            if (columns[ctr] === "*") {
                this.displayColumns[index] = ctr;<commit_msg>fixed issue with currentAtlas<commit_after>
/*jslint browser: true, node: true */
/*global bind, isString, papayaMain, deref, papayaParams */

"use strict";

var papaya = papaya || {};
papaya.viewer = papaya.viewer || {};


papaya.viewer.Atlas = papaya.viewer.Atlas || function (atlas) {
    this.name = null;
    this.transformedname = null;
    this.labels = [];
    this.atlasLabelData = atlas.labels;
    this.volume = new papaya.volume.Volume();
    this.displayColumns = null;
    this.returnLabels = null;
    this.transform = null;
    this.currentAtlas = null;
    this.maxLabels = 0;
    this.probabilistic = false;

    var loadableImage = papayaMain.findLoadableImage(atlas.labels.atlas.header.images.summaryimagefile);

    if ((loadableImage !== null) && (loadableImage.encode !== undefined)) {
        this.volume.readEncodedData(loadableImage.encode, bind(this, this.readFinished));
    } else if ((loadableImage !== null) && (loadableImage.url !== undefined)) {
        this.volume.readURL(loadableImage.url, bind(this, this.readFinished));
    }
};



papaya.viewer.Atlas.MAX_LABELS = 4;
papaya.viewer.Atlas.PROBABILISTIC = [ "probabalistic", "probabilistic", "statistic" ]; // typo is in FSL < 5.0.2
papaya.viewer.Atlas.LABEL_SPLIT_REGEX = /\.|:|,|\//;  // possible delimiters



papaya.viewer.Atlas.prototype.getLabelAtCoordinate = function (xLoc, yLoc, zLoc) {
    var xTrans, yTrans, zTrans, val;

    if (this.transform && (this.currentAtlas === this.transformedname)) {
        xTrans = ((xLoc * this.transform[0][0]) + (yLoc * this.transform[0][1]) + (zLoc * this.transform[0][2]) + (this.transform[0][3]));
        yTrans = ((xLoc * this.transform[1][0]) + (yLoc * this.transform[1][1]) + (zLoc * this.transform[1][2]) + (this.transform[1][3]));
        zTrans = ((xLoc * this.transform[2][0]) + (yLoc * this.transform[2][1]) + (zLoc * this.transform[2][2]) + (this.transform[2][3]));
    } else {
        xTrans = xLoc;
        yTrans = yLoc;
        zTrans = zLoc;
    }

    val = (this.volume.getVoxelAtCoordinate(xTrans, yTrans, zTrans, 0, true));

    if (this.probabilistic) {
        val -= 1;
    }

    return this.formatLabels(this.labels[val], this.returnLabels);
};



papaya.viewer.Atlas.prototype.readFinished = function () {
    this.parseTransform();
    this.parseLabels();
    this.parseDisplayColumns();
    this.maxLabels = this.findMaxLabelParts();
    this.probabilistic = this.atlasLabelData.atlas.header.type
        && ((this.atlasLabelData.atlas.header.type.toLowerCase() === papaya.viewer.Atlas.PROBABILISTIC[0])
            || (this.atlasLabelData.atlas.header.type.toLowerCase() === papaya.viewer.Atlas.PROBABILISTIC[1])
            || (this.atlasLabelData.atlas.header.type.toLowerCase() === papaya.viewer.Atlas.PROBABILISTIC[2]));

    this.returnLabels = [];
    this.returnLabels.length = this.maxLabels;

    if (this.atlasLabelData.atlas.header.transformedname) {
        this.transformedname = this.atlasLabelData.atlas.header.transformedname;
    }

    this.name = this.atlasLabelData.atlas.header.name;
    this.currentAtlas = this.name;

    var params = papayaParams.atlas;
    if (params) {
        if (params === this.transformedname) {
            this.currentAtlas = this.transformedname;
        }
    }
};



papaya.viewer.Atlas.prototype.parseDisplayColumns = function () {
    var index, columns, ctr;

    if (this.atlasLabelData.atlas.header.display) {  // uses "display" attribute
        this.displayColumns = [];
        index = 0;
        columns = this.atlasLabelData.atlas.header.display.split(papaya.viewer.Atlas.LABEL_SPLIT_REGEX);

        for (ctr = 0; ctr < columns.length; ctr += 1) {
            if (columns[ctr] === "*") {
                this.displayColumns[index] = ctr;
{'fraction_non_alphanumeric': 0.15788072417465387, 'fraction_numerical': 0.009850905218317359, 'mean_word_length': 3.2590702947845807, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '1644753', 'n_tokens_mistral': 2624, 'n_tokens_neox': 2568, 'n_words': 402}