<commit_before>function ROIpack(svgdoc, callback, viewer) {
    this.callback = callback;
    this.svgroi = svgdoc.getElementsByTagName("svg")[0];
    this.svgroi.id = "svgroi";
    //document.getElementById("hiderois").appendChild(this.svgroi);
    this.rois = $(this.svgroi).find("path");
    this.rois.each(function() { this.removeAttribute("filter"); });
    var geoms = {left:new THREE.Geometry(), right:new THREE.Geometry()};
    geoms.left.dynamic = true;
    geoms.right.dynamic = true;
    var verts = {};
    var labels = [];
    var colors = 1;
    $(this.svgroi).find("#roilabels text").each(function() {
        var name = $(this).text();
        var el = document.createElement("p");
        var pt = viewer.remap($(this).data("ptidx"));
        var color = new THREE.Color(colors++);
        var ptdat = viewer.getVert(pt);
        verts[pt] = ptdat.norm;
        geoms[ptdat.name].vertices.push(ptdat.norm);
        geoms[ptdat.name].colors.push(color);

        el.setAttribute("data-ptidx", pt);
        el.setAttribute("data-ptcolor", color.getHex());
        el.className = "roilabel";
        el.innerHTML = name;
        labels.push(el);
    });
    $(this.svgroi).find("#roilabels").remove();
    $(this.svgroi).find("defs").remove();
    this.vertices = verts;
    this.particlemat = new THREE.ParticleBasicMaterial({
        size:2, 
        vertexColors:THREE.VertexColors, 
        depthTest:true,
        sizeAttenuation:false, 
        opacity:1.0
    });
    this.particles = {
        left: new THREE.ParticleSystem(geoms.left, this.particlemat),
        right: new THREE.ParticleSystem(geoms.right, this.particlemat)
    };
    this.particles.left.dynamic = true;
    this.particles.right.dynamic = true;
    viewer.pivot.left.back.add(this.particles.left);
    viewer.pivot.right.back.add(this.particles.right);

    this.labels = $(labels);
    $("#roilabels").append(this.labels);

    var w = this.svgroi.getAttribute("width");
    var h = this.svgroi.getAttribute("height");
    this.aspect = w / h;
    this.svgroi.setAttribute("viewBox", "0 0 "+w+" "+h);

    var gl = viewer.renderer.context;
    var height = Math.min(5120, gl.getParameter(gl.MAX_TEXTURE_SIZE)) / this.aspect;
    this.setHeight(height);
    
    this._updatemove = true;
    this._updatemix = true;
    this.setLabels = function() {
        if (this._updatemove) {
            this.move(viewer);
            this._updatemove = false;
        }
        if (this._updatemix) {
            this.setMix(viewer);
            this._updatemix = false;
        }
    }.bind(this);
    this.canvas = document.createElement("canvas");
}
ROIpack.prototype = {
    setHeight: function(height) {
        this.height = height;
        this.width = this.height * this.aspect;
        this.svgroi.setAttribute("width", this.width);
        this.svgroi.setAttribute("height", this.height);
        this._shadowtex = new ShadowTex(Math.ceil(this.width), Math.ceil(this.height), 4);
    }, 
    update: function(renderer) {
        var fo = "fill-opacity:"+$("#roi_fillalpha").slider("option", "value");
        var lo = "stroke-opacity:"+$("#roi_linealpha").slider("option", "value");
        var fc = "fill:"+$("#roi_fillcolor").attr("value");
        var lc = "stroke:"+$("#roi_linecolor").attr("value");
        var lw = "stroke-width:"+$("#roi_linewidth").slider("option", "value") + "px";
        var sw = parseInt($("#roi_shadowalpha").slider("option", "value"));

        this.rois.attr("style", [fo, lo, fc, lc, lw].join(";"));
        var svg_xml = (new XMLSerializer()).serializeToString(this.svgroi);

        if (sw > 0) {
            var sc = "stroke:"+$("#roi_shadowcolor").val();
            this.rois.attr("style", [sc, fc, fo, lo, lw].join(";"));
            var shadow_xml = (new XMLSerializer()).serializeToString(this.svgroi);

            canvg(this.canvas, shadow_xml, {
                ignoreMouse:true, 
                ignoreAnimation:true,
                ignoreClear:false,
                renderCallback: function() {
                    this._shadowtex.setRadius(sw/4);
                    var tex = this._shadowtex.blur(renderer, new THREE.Texture(this.canvas));
                    canvg(this.canvas, svg_xml, {
                        ignoreMouse:true,
                        ignoreAnimation:true,
                        renderCallback: function() {
                            var tex = this._shadowtex.overlay(renderer, new THREE.Texture(this.canvas));
                            this.callback(tex);
                        }.bind(this)
                    });
                }.bind(this)
            });

        } else {
            canvg(this.canvas, svg_xml, {
                ignoreMouse:true,
                ignoreAnimation:true,
                renderCallback:function() {
                    var tex = new THREE.Texture(this.canvas);
                    tex.needsUpdate = true;
                    tex.premultiplyAlpha = true;<commit_msg>Fix the black rois due to missing elements<commit_after>function ROIpack(svgdoc, callback, viewer) {
    this.callback = callback;
    this.svgroi = svgdoc.getElementsByTagName("svg")[0];
    this.svgroi.id = "svgroi";
    //document.getElementById("hiderois").appendChild(this.svgroi);
    this.rois = $(this.svgroi).find("path");
    this.rois.each(function() { this.removeAttribute("filter"); });
    var geoms = {left:new THREE.Geometry(), right:new THREE.Geometry()};
    geoms.left.dynamic = true;
    geoms.right.dynamic = true;
    var verts = {};
    var labels = [];
    var colors = 1;
    $(this.svgroi).find("#roilabels text").each(function() {
        var name = $(this).text();
        var el = document.createElement("p");
        var pt = viewer.remap($(this).data("ptidx"));
        var color = new THREE.Color(colors++);
        var ptdat = viewer.getVert(pt);
        verts[pt] = ptdat.norm;
        geoms[ptdat.name].vertices.push(ptdat.norm);
        geoms[ptdat.name].colors.push(color);

        el.setAttribute("data-ptidx", pt);
        el.setAttribute("data-ptcolor", color.getHex());
        el.className = "roilabel";
        el.innerHTML = name;
        labels.push(el);
    });
    $(this.svgroi).find("#roilabels").remove();
    $(this.svgroi).find("defs").remove();
    this.vertices = verts;
    this.particlemat = new THREE.ParticleBasicMaterial({
        size:2, 
        vertexColors:THREE.VertexColors, 
        depthTest:true,
        sizeAttenuation:false, 
        opacity:1.0
    });
    this.particles = {
        left: new THREE.ParticleSystem(geoms.left, this.particlemat),
        right: new THREE.ParticleSystem(geoms.right, this.particlemat)
    };
    this.particles.left.dynamic = true;
    this.particles.right.dynamic = true;
    viewer.pivot.left.back.add(this.particles.left);
    viewer.pivot.right.back.add(this.particles.right);

    this.labels = $(labels);
    $("#roilabels").append(this.labels);

    var w = this.svgroi.getAttribute("width");
    var h = this.svgroi.getAttribute("height");
    this.aspect = w / h;
    this.svgroi.setAttribute("viewBox", "0 0 "+w+" "+h);

    var gl = viewer.renderer.context;
    var height = Math.min(4096, gl.getParameter(gl.MAX_TEXTURE_SIZE)) / this.aspect;
    this.setHeight(height);
    
    this._updatemove = true;
    this._updatemix = true;
    this.setLabels = function() {
        if (this._updatemove) {
            this.move(viewer);
            this._updatemove = false;
        }
        if (this._updatemix) {
            this.setMix(viewer);
            this._updatemix = false;
        }
    }.bind(this);
    this.canvas = document.createElement("canvas");
}
ROIpack.prototype = {
    setHeight: function(height) {
        this.height = height;
        this.width = this.height * this.aspect;
        this.svgroi.setAttribute("width", this.width);
        this.svgroi.setAttribute("height", this.height);
        this._shadowtex = new ShadowTex(Math.ceil(this.width), Math.ceil(this.height), 4);
    }, 
    update: function(renderer) {
        var fo = $("#roi_fillalpha").length > 0 ? $("#roi_fillalpha").slider("option", "value") : 0;
        var lo = $("#roi_linealpha").length > 0 ? $("#roi_linealpha").slider("option", "value") : 1;
        var fc = $("#roi_fillcolor").length > 0 ? $("#roi_fillcolor").attr("value") : "#000";
        var lc = $("#roi_linecolor").length > 0 ? $("#roi_linecolor").attr("value") : "#FFF";
        var lw = $("#roi_linewidth").length > 0 ? $("#roi_linewidth").slider("option", "value") : 3;
        var sw = $("#roi_shadowalpha").length > 0 ? $("#roi_shadowalpha").slider("option", "value") : 5 ;
        fo = "fill-opacity:" + fo;
        lo = "stroke-opacity:" + lo;
        fc = "fill:" + fc;
        lc = "stroke:" + lc;
        lw = "stroke-width:" + lw + "px";
        sw = parseInt(sw);

        this.rois.attr("style", [fo, lo, fc, lc, lw].join(";"));
        var svg_xml = (new XMLSerializer()).serializeToString(this.svgroi);

        if (sw > 0) {
            var sc = $("#roi_shadowcolor").length > 0 ? $("#roi_shadowcolor").val() : "#000";
            sc = "stroke:" + sc;
            this.rois.attr("style", [sc, fc, fo, lo, lw].join(";"));
            var shadow_xml = (new XMLSerializer()).serializeToString(this.svgroi);

            canvg(this.canvas, shadow_xml, {
                ignoreMouse:true, 
                ignoreAnimation:true,
                ignoreClear:false,
                renderCallback: function() {
                    this._shadowtex.setRadius(sw/4);
                    var tex = this._shadowtex.blur(renderer, new THREE.Texture(this.canvas));
                    canvg(this.canvas, svg_xml, {
                        ignoreMouse:true,
                        ignoreAnimation:true,
                        renderCallback: function() {
                            var tex = this._shadowtex.overlay(renderer, new THREE.Texture(this.canvas));
                            this.callback(tex);
                        }.bind(this)
                    });
                }.bind(this)
            });

        } else {
            canvg(this.canvas, svg_xml, {
                ignoreMouse:true,
                ignoreAnimation:true,
                renderCallback:function() {
                    var tex = new THREE.Texture(this.canvas);
                    tex.needsUpdate = true;
                    tex.premultiplyAlpha = true;
{'fraction_non_alphanumeric': 0.15882635882635882, 'fraction_numerical': 0.004329004329004329, 'mean_word_length': 2.2155892360037117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '4650839', 'n_tokens_mistral': 3302, 'n_tokens_neox': 3178, 'n_words': 535}