Search in sources :

Example 1 with IsSelectable

use of maspack.render.IsSelectable in project artisynth_core by artisynth.

the class GLColorSelector method processSelection.

@Override
public void processSelection(GL gl) {
    if (myTotalMaxQ == 0) {
        super.processSelection(gl);
        return;
    }
    flushQueries(myGl);
    HitRecord[] hits = null;
    for (int id : myQueryBuffer) {
        if (id != 0) {
            // subtract the 1 offset
            --id;
            if (hits == null) {
                hits = new HitRecord[myTotalMaxQ];
            }
            HitRecord rec = hits[id];
            if (rec == null) {
                rec = new HitRecord(0);
                hits[id] = rec;
            }
            rec.size++;
        }
    }
    myViewer.selectionEvent.setSelectedObjects(null);
    if (hits == null) {
        // then no queries were issued, so nothing to do ...
        myViewer.selectionEvent.setSelectedObjects(null);
    } else {
        int qid = 0;
        LinkedList<HitRecord> records = new LinkedList<HitRecord>();
        // int[] result = new int[1];
        Iterator<IsRenderable> it = myViewer.renderIterator();
        while (it.hasNext()) {
            IsRenderable r = it.next();
            if (r instanceof IsSelectable) {
                IsSelectable s = (IsSelectable) r;
                int numq = s.numSelectionQueriesNeeded();
                int nums = (numq >= 0 ? numq : 1);
                if (s.isSelectable()) {
                    for (int i = 0; i < nums; i++) {
                        HitRecord rec;
                        if ((rec = hits[qid + i]) != null) {
                            if (numq < 0) {
                                rec.objs.add(s);
                            } else {
                                s.getSelection(rec.objs, i);
                            }
                            if (rec.objs.size() > 0) {
                                records.add(rec);
                            }
                        }
                    }
                }
                qid += nums;
            }
        }
        Collections.sort(records);
        ArrayList<LinkedList<?>> selObjs = new ArrayList<>(records.size());
        for (int i = 0; i < records.size(); i++) {
            selObjs.add(records.get(i).objs);
        }
        myViewer.selectionEvent.setSelectedObjects(selObjs);
    }
    super.processSelection(gl);
}
Also used : IsRenderable(maspack.render.IsRenderable) IsSelectable(maspack.render.IsSelectable) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 2 with IsSelectable

use of maspack.render.IsSelectable in project artisynth_core by artisynth.

the class GLOcclusionSelector method processSelection.

@Override
public void processSelection(GL gl) {
    if (myTotalMaxQ == 0) {
        super.processSelection(gl);
        return;
    }
    // finish remaining queries
    flushQueries((GL2GL3) gl);
    // re-enable depth buffer
    myViewer.setDepthEnabled(savedDepth);
    if (myGLQueryTotal == 0) {
        // then no queries were issued, so nothing to do ...
        myViewer.setSelected(null);
    } else {
        int qid = 0;
        LinkedList<HitRecord> records = new LinkedList<HitRecord>();
        Iterator<IsRenderable> it = myViewer.renderIterator();
        while (it.hasNext()) {
            IsRenderable r = it.next();
            if (r instanceof IsSelectable) {
                IsSelectable s = (IsSelectable) r;
                int numq = s.numSelectionQueriesNeeded();
                int nums = (numq >= 0 ? numq : 1);
                if (s.isSelectable()) {
                    for (int i = 0; i < nums; i++) {
                        if (myQuerySamples[qid + i] > 0) {
                            HitRecord rec = new HitRecord(myQuerySamples[qid + i]);
                            if (numq < 0) {
                                rec.objs.add(s);
                            } else {
                                s.getSelection(rec.objs, i);
                            }
                            if (rec.objs.size() > 0) {
                                records.add(rec);
                            }
                        }
                    }
                }
                qid += nums;
            }
        }
        Collections.sort(records);
        ArrayList<LinkedList<?>> selObjs = new ArrayList<>(records.size());
        for (int i = 0; i < records.size(); i++) {
            selObjs.add(records.get(i).objs);
        }
        myViewer.setSelected(selObjs);
    }
    // delete queries
    ((GL2GL3) myGl).glDeleteQueries(myGLQueries.length, myGLQueries, 0);
    myGLQueries = null;
    myGLQueryIds = null;
    super.processSelection(gl);
}
Also used : IsRenderable(maspack.render.IsRenderable) IsSelectable(maspack.render.IsSelectable) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) GL2GL3(com.jogamp.opengl.GL2GL3)

Aggregations

ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 IsRenderable (maspack.render.IsRenderable)2 IsSelectable (maspack.render.IsSelectable)2 GL2GL3 (com.jogamp.opengl.GL2GL3)1