BBox.contains mit sehr vielen Entities

Bitte benutzen Sie dieses Forum für Fragen, Kommentare und Probleme im Zusammenhang mit QCAD Professional

Moderators: andrew, Husky

Post Reply
RR88
Active Member
Posts: 29
Joined: Sun Apr 29, 2018 7:04 am
Location: Leinefelde

BBox.contains mit sehr vielen Entities

Post by RR88 » Tue Oct 22, 2019 11:17 pm

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?
Gentoo/Linux, QCad 3.20 Prof.

CVH
Premier Member
Posts: 284
Joined: Wed Sep 27, 2017 4:17 pm
Location: Belgium; Antwerp

Re: BBox.contains mit sehr vielen Entities

Post by CVH » Wed Oct 23, 2019 11:24 am

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
QCADpro 3.23.0.0 / win7pro 32 bit / 4GB / 1e generation i7 2.6Ghz / HDD GeForce GT 520

User avatar
andrew
Site Admin
Posts: 6360
Joined: Fri Mar 30, 2007 6:07 am

Re: BBox.contains mit sehr vielen Entities

Post by andrew » Wed Oct 23, 2019 4:01 pm

Um den Spatial Index zu verwenden müssen die Entity IDs abgefragt werden über, z.B.:

Code: Select all

var ids = doc.queryContainedEntities(box);

RR88
Active Member
Posts: 29
Joined: Sun Apr 29, 2018 7:04 am
Location: Leinefelde

Re: BBox.contains mit sehr vielen Entities

Post by RR88 » Wed Oct 23, 2019 7:01 pm

@andrew Vielen Dank. Genau das habe ich gesucht.
Gentoo/Linux, QCad 3.20 Prof.

Post Reply

Return to “QCAD Professional”