All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.powsybl.gse.map.BranchGraphicIndex Maven / Gradle / Ivy

There is a newer version: 1.8.0
Show newest version
/**
 * Copyright (c) 2018, RTE (http://www.rte-france.com)
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package com.powsybl.gse.map;

import com.github.davidmoten.rtree.RTree;
import com.github.davidmoten.rtree.geometry.Geometry;
import org.apache.commons.lang3.time.StopWatch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collection;
import java.util.Objects;

/**
 * @author Geoffroy Jamgotchian 
 */
public final class BranchGraphicIndex {

    private static final Logger LOGGER = LoggerFactory.getLogger(BranchGraphicIndex.class);

    private final RTree tree;

    private BranchGraphicIndex(RTree tree) {
        this.tree = Objects.requireNonNull(tree);
    }

    public static BranchGraphicIndex build(Collection segmentGroups) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        RTree tree = RTree.star().maxChildren(6).create();

        for (BranchGraphic segmentGroup : segmentGroups) {
            tree = tree.add(segmentGroup, segmentGroup.getBoundingBox());
        }

        LOGGER.info("Line branches R-tree built in {} ms", stopWatch.getTime());

        return new BranchGraphicIndex(tree);
    }

    public RTree getTree() {
        return tree;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy