Page 1 of 1

BBox.contains mit sehr vielen Entities

Posted: Tue Oct 22, 2019 11:17 pm
by RR88
Hallo.

Zunächst einmal mein Code in verkürzter Ausführung:

Code: Select all

var doc = new RDocument(new RMemoryStorage(), new RSpatialIndexNavel()),
    di = new RDocumentInterface(doc);

di.importFile(file);

var rects = [];
doc.queryAllEntities(false, false, RS.EntityPolyline).forEach(function (id) {
    rects.push(doc.queryEntity(id));
});

var all = doc.queryAllEntities(false, false, [RS.EntityCircle, RS.EntityBlockRef, RS.EntityEllipse, RS.EntityPolyline, RS.EntityHatch, RS.EntityText, RS.EntityLine, RS.EntityAttribute]);

rects.forEach(function (rect) {
    var bbA = rect.getBoundingBox().growXY(1e-5),
        childs = [];

    all.forEach(function (id) {
        var ent = doc.queryEntity(id),
            bbB = ent.getBoundingBox();

        if (bbA.contains(bbB)) {
            childs.push(ent);
        }
    });
});
all ist eine Array von etwa 35000 Entities. Die Ausführung des Scripts ist echt langsam.

Kann man das irgendwie mit builtin-Methoden beschleunigen? Ein AABB-Tree wollte ich jetzt nicht einbauen.

Wird der RSpatialIndexNavel überhaupt genutzt oder muss man da noch etwas zusätzlich aufrufen?

Re: BBox.contains mit sehr vielen Entities

Posted: Wed Oct 23, 2019 11:24 am
by CVH
Sorry for my reply in English.

Nice and very compact coding.

For how far my knowledge reaches:

With entities imported from a drawing 'file':
You are testing if any id in QList 'all' is fully inside
a slightly grown boundingbox arround
all polylines in the array 'rects'.

Further, I suspect that any that complies will be pushed to a sub-array of the 'rects' entry called 'childs'.

For one: Any poly will be a child of itselfs.
And two: 'rects' and 'rects.childs' are filled with entities in full with all there objects, methods and functions.
Storing only the ID might be sufficient.

And further: The sheer number of entities might be your biggest problem.

Lets say there are only about 2000 polys in the set of 35,000 entities.
That are 70 million iterations.

Lets presume only 'Math.PI/2' is calculated every iteration.
That alone would take about 3 seconds on my PC.

Regards,
CVH

Re: BBox.contains mit sehr vielen Entities

Posted: Wed Oct 23, 2019 4:01 pm
by andrew
Um den Spatial Index zu verwenden müssen die Entity IDs abgefragt werden über, z.B.:

Code: Select all

var ids = doc.queryContainedEntities(box);

Re: BBox.contains mit sehr vielen Entities

Posted: Wed Oct 23, 2019 7:01 pm
by RR88
@andrew Vielen Dank. Genau das habe ich gesucht.