Search in sources :

Example 1 with TruthWave

use of nars.truth.TruthWave in project narchy by automenta.

the class BeliefTableChart method renderTable.

private void renderTable(Concept c, long minT, long maxT, long now, GL2 gl, TruthWave wave, boolean beliefOrGoal) {
    if (c == null)
        return;
    float nowX = xTime(minT, maxT, now);
    // Present axis line
    if ((now <= maxT) && (now >= minT)) {
        gl.glColor4f(1f, 1f, 1f, 0.5f);
        Draw.line(gl, nowX, 0, nowX, 1);
    // float nowLineWidth = 0.005f;
    // Draw.rect(gl, nowX - nowLineWidth / 2f, 0, nowLineWidth, 1);
    }
    /**
     * drawn "pixel" dimensions
     */
    renderWave(nowX, minT, maxT, gl, wave, beliefOrGoal);
    // draw projections
    if (projections > 0 && minT != maxT) {
        for (boolean freqOrExp : new boolean[] { true, false }) {
            TruthWave pwave = beliefOrGoal ? beliefProj : goalProj;
            // HACK dont show expectation for beliefs
            if (beliefOrGoal && !freqOrExp)
                continue;
            Colorize colorize;
            if (freqOrExp) {
                colorize = beliefOrGoal ? (ggl, frq, cnf) -> {
                    float a = 0.65f + 0.2f * cnf;
                    ggl.glColor4f(0.25f + 0.75f * cnf, 0.1f * (1f - cnf), 0, a);
                } : (ggl, frq, cnf) -> {
                    float a = 0.65f + 0.2f * cnf;
                    ggl.glColor4f(0.1f * (1f - cnf), 0.25f + 0.75f * cnf, 0, a);
                };
            } else {
                colorize = beliefOrGoal ? (ggl, frq, cnf) -> {
                    ggl.glColor4f(cnf, cnf / 2f, 0.25f, 0.85f);
                } : (ggl, frq, cnf) -> {
                    ggl.glColor4f(cnf / 2f, cnf, 0.25f, 0.85f);
                };
            }
            FloatFloatToFloatFunction y = freqOrExp ? (frq, cnf) -> frq : TruthFunctions::expectation;
            // HACK show goal freq in thinner line
            gl.glLineWidth((freqOrExp && !beliefOrGoal) ? 2f : 4f);
            renderWaveLine(nowX, minT, maxT, gl, pwave, y, colorize);
        }
    }
    float chSize = 0.1f;
    Truth bc = wave.current;
    if (bc != null) {
        float theta;
        float expectation = bc.expectation();
        float dTheta = (expectation - 0.5f) * angleSpeed;
        float conf = bc.conf();
        if (beliefOrGoal) {
            this.beliefTheta += dTheta;
            theta = beliefTheta;
            gl.glColor4f(1f, 0f, 0, 0.2f + 0.8f * conf);
            drawCrossHair(gl, nowX, chSize, bc.freq(), conf, theta);
        } else {
            this.goalTheta += dTheta;
            theta = goalTheta;
            // //freq
            // gl.glColor4f(0f, 1f, 0, 0.2f + 0.8f * conf);
            // drawCrossHair(gl, nowX, chSize, bc.freq(), conf, theta);
            // expectation
            gl.glColor4f(0f, 1f, 0, 0.2f + 0.8f * conf);
            drawCrossHair(gl, nowX, chSize, expectation, expectation, theta);
        }
    }
}
Also used : GL2(com.jogamp.opengl.GL2) DurService(nars.control.DurService) PushButton(spacegraph.space2d.widget.button.PushButton) BiFunction(java.util.function.BiFunction) Surface(spacegraph.space2d.Surface) ETERNAL(nars.time.Tense.ETERNAL) Draw(spacegraph.video.Draw) Util(jcog.Util) RectFloat2D(jcog.tree.rtree.rect.RectFloat2D) TruthWave(nars.truth.TruthWave) MetaFrame(spacegraph.space2d.widget.meta.MetaFrame) TruthFunctions(nars.truth.TruthFunctions) BeliefTable(nars.table.BeliefTable) Task(nars.Task) Truth(nars.truth.Truth) NAR(nars.NAR) Gridding(spacegraph.space2d.container.Gridding) Termed(nars.term.Termed) PI(java.lang.Math.PI) TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) Label(spacegraph.space2d.widget.text.Label) FloatFloatToFloatFunction(jcog.util.FloatFloatToFloatFunction) Term(nars.term.Term) FloatFloatToFloatFunction(jcog.util.FloatFloatToFloatFunction) TruthFunctions(nars.truth.TruthFunctions) TruthWave(nars.truth.TruthWave) Truth(nars.truth.Truth)

Example 2 with TruthWave

use of nars.truth.TruthWave in project narchy by automenta.

the class BeliefTableChart method draw.

protected void draw(Termed tt, Concept cc, GL2 gl, long minT, long maxT) {
    TruthWave beliefs = this.beliefs;
    // if (!beliefs.isEmpty()) {
    renderTable(cc, minT, maxT, now, gl, beliefs, true);
    // }
    TruthWave goals = this.goals;
    // if (!goals.isEmpty()) {
    renderTable(cc, minT, maxT, now, gl, goals, false);
    if (showTaskLinks) {
        gl.glLineWidth(1f);
        float nowX = xTime(minT, maxT, now);
        cc.tasklinks().forEach(tl -> {
            if (tl != null) {
                Task x = tl.get(nar);
                if ((x != null) && (x.isBeliefOrGoal())) {
                    long o = x.start();
                    float tlx = o == ETERNAL ? nowX : xTime(minT, maxT, o);
                    if (tlx > 0 && tlx < 1) {
                        float tly = x.freq();
                        float ii = 0.3f + 0.7f * x.conf();
                        gl.glColor4f(ii / 2f, 0, ii, 0.5f + tl.pri() * 0.5f);
                        float w = 0.05f;
                        float h = 0.05f;
                        Draw.rectStroke(gl, tlx - w / 2, tly - h / 2, w, h);
                    }
                }
            }
        });
    }
// gl.glLineWidth(1f);
// gl.glColor4f(1f, 1f, 1f, 0.3f);
// Draw.strokeRect(gl, 0, 0, gew, geh);
// Draw.strokeRect(gl, gew, 0, tew, teh);
}
Also used : Task(nars.Task) TruthWave(nars.truth.TruthWave)

Example 3 with TruthWave

use of nars.truth.TruthWave in project narchy by automenta.

the class BeliefTableChart method paintWidget.

@Override
protected void paintWidget(GL2 ggl, RectFloat2D bounds) {
    /*if (!redraw.compareAndSet(true, false)) {
            return;
        }*/
    // swapBuffers();
    // clear
    // clear(1f /*0.5f*/);
    Draw.bounds(ggl, bounds, (gl) -> {
        long minT, maxT;
        if (range != null) {
            minT = range[0];
            maxT = range[1];
        } else {
            // compute bounds from combined min/max of beliefs and goals so they align correctly
            minT = Long.MAX_VALUE;
            maxT = Long.MIN_VALUE;
            TruthWave b = this.beliefs;
            if (!b.isEmpty()) {
                long start = b.start();
                if (start != ETERNAL) {
                    minT = Math.min(start, minT);
                    maxT = Math.max(b.end(), maxT);
                }
            }
            TruthWave g = this.goals;
            if (!g.isEmpty()) {
                long start = g.start();
                if (start != ETERNAL) {
                    minT = Math.min(start, minT);
                    maxT = Math.max(g.end(), maxT);
                }
            }
            long[] newRange = rangeControl.apply(now, new long[] { minT, maxT });
            minT = newRange[0];
            maxT = newRange[1];
        }
        // background
        gl.glColor3f(0, 0, 0);
        Draw.rect(gl, 0, 0, 1, 1);
        gl.glLineWidth(1f);
        // border
        gl.glColor3f(0.5f, 0.5f, 0.5f);
        Draw.rectStroke(gl, 0, 0, 1, 1);
        // String currentTermString = termString;
        if (cc != null) {
            draw(term, cc, gl, minT, maxT);
            termString = cc.toString();
        } else {
            termString = term.toString();
        }
        label.text(termString);
    });
// gl.glColor4f(0.75f, 0.75f, 0.75f, 0.8f + 0.2f * cp);
// gl.glLineWidth(1);
// Draw.text(gl, termString, (1f/termString.length()) * (0.5f + 0.25f * cp), 1 / 2f, 1 / 2f, 0);
}
Also used : TruthWave(nars.truth.TruthWave)

Aggregations

TruthWave (nars.truth.TruthWave)3 Task (nars.Task)2 GL2 (com.jogamp.opengl.GL2)1 PI (java.lang.Math.PI)1 BiFunction (java.util.function.BiFunction)1 Util (jcog.Util)1 RectFloat2D (jcog.tree.rtree.rect.RectFloat2D)1 FloatFloatToFloatFunction (jcog.util.FloatFloatToFloatFunction)1 NAR (nars.NAR)1 Concept (nars.concept.Concept)1 TaskConcept (nars.concept.TaskConcept)1 DurService (nars.control.DurService)1 BeliefTable (nars.table.BeliefTable)1 Term (nars.term.Term)1 Termed (nars.term.Termed)1 ETERNAL (nars.time.Tense.ETERNAL)1 Truth (nars.truth.Truth)1 TruthFunctions (nars.truth.TruthFunctions)1 Surface (spacegraph.space2d.Surface)1 Gridding (spacegraph.space2d.container.Gridding)1