Search in sources :

Example 81 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TreeJPanel method paintComponent.

@Override
protected void paintComponent(final Graphics g) {
    super.paintComponent(g);
    setBackground(Color.WHITE);
    // Group is not set
    if (guiModel.getTreeAdapter() == null) {
        return;
    }
    final Graphics2D graphics2D = (Graphics2D) g;
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.scale(zoomFactor, zoomFactor);
    try {
        final DistributionRegion distributionRegion = guiModel.getTreeAdapter().getRootNode();
        regions.clear();
        if (distributionRegion == null) {
            logger.error("Got null root node");
            return;
        }
        final int maxChildren = distributionRegion.getThisAndChildRegions().stream().mapToInt(r -> r.getDirectChildren().size()).max().orElse(0);
        // Fake position to calculate the real width
        rootPosX = 100000;
        createDistribtionRegionComponents(distributionRegion, maxChildren);
        calculateRootNodeXPos();
        final BoundingBox drawBox = drawDistributionRegion(graphics2D);
        updateComponentSize(drawBox);
    } catch (BBoxDBException e) {
        logger.error("Got an exception", e);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) BBoxDBException(org.bboxdb.misc.BBoxDBException) Graphics2D(java.awt.Graphics2D)

Example 82 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TreeJPanel method calculateRootNodeXPos.

/**
 * Calculate the root node X position
 */
protected void calculateRootNodeXPos() {
    if (regions.isEmpty()) {
        return;
    }
    BoundingBox minBoundingBox = BoundingBox.FULL_SPACE;
    for (DistributionRegionComponent component : regions) {
        minBoundingBox = BoundingBox.getCoveringBox(component.getBoundingBox(), minBoundingBox);
    }
    final double rootCoordinateLow = regions.get(0).getBoundingBox().getCoordinateLow(0);
    final double bboxCoordinateLow = minBoundingBox.getCoordinateLow(0);
    final int rootOffsetBBox = (int) (rootCoordinateLow - bboxCoordinateLow) + PADDING_LEFT_RIGHT;
    final int rootOffsetWindowSize = (int) ((getVisibleRect().getWidth() - DistributionRegionComponent.WIDTH) / 2);
    // If the screen is bigger as the bounding box, use the screen width
    rootPosX = Math.max(rootOffsetBBox, rootOffsetWindowSize);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) DistributionRegionComponent(org.bboxdb.tools.gui.DistributionRegionComponent)

Example 83 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class CreateInitialPartitioning method run.

@Override
public void run() {
    final TupleFileReader tupleFile = new TupleFileReader(filename, format);
    final List<BoundingBox> samples = new ArrayList<>();
    tupleFile.addTupleListener(t -> {
        final BoundingBox polygonBoundingBox = t.getBoundingBox();
        samples.add(polygonBoundingBox);
    });
    try {
        tupleFile.processFile();
        final SpacePartitioner spacePartitioner = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(distributionGroup);
        final DistributionRegionAdapter adapter = ZookeeperClientFactory.getZookeeperClient().getDistributionRegionAdapter();
        while (getActiveRegions(spacePartitioner).size() < partitions) {
            logger.info("We have now {} of {} active partitons, executing split", getActiveRegions(spacePartitioner).size() < partitions);
            final List<DistributionRegion> activeRegions = getActiveRegions(spacePartitioner);
            final DistributionRegion regionToSplit = ListHelper.getElementRandom(activeRegions);
            logger.info("Splitting region {}", regionToSplit.getRegionId());
            final List<DistributionRegion> destination = spacePartitioner.splitRegion(regionToSplit, samples);
            spacePartitioner.splitComplete(regionToSplit, destination);
        }
        // Prevent merging of nodes
        for (DistributionRegion region : spacePartitioner.getRootNode().getAllChildren()) {
            adapter.setMergingSupported(region, false);
        }
    } catch (Exception e) {
        logger.error("Got an exception", e);
        System.exit(-1);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleFileReader(org.bboxdb.tools.TupleFileReader) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) ZookeeperNotFoundException(org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner)

Example 84 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testTPCHLineitemRangeTupleBuilder.

/**
 * Test the tpch range tuple builder
 * @throws ParseException
 */
@Test
public void testTPCHLineitemRangeTupleBuilder() throws ParseException {
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.TPCH_LINEITEM_RANGE);
    final Tuple tuple = tupleBuilder.buildTuple("1", TPCH_LINEITEM_TEST_LINE);
    Assert.assertTrue(tuple != null);
    Assert.assertEquals(Integer.toString(1), tuple.getKey());
    final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd");
    final Date shipDateTime = dateParser.parse("1993-12-04");
    final Date receiptDateTime = dateParser.parse("1994-01-01");
    final double doubleShipDateTime = (double) shipDateTime.getTime();
    final double doublereceiptDateTime = (double) receiptDateTime.getTime();
    final BoundingBox exptectedBox = new BoundingBox(doubleShipDateTime, doublereceiptDateTime);
    Assert.assertEquals(exptectedBox, tuple.getBoundingBox());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) SimpleDateFormat(java.text.SimpleDateFormat) Tuple(org.bboxdb.storage.entity.Tuple) Date(java.util.Date) Test(org.junit.Test)

Example 85 with BoundingBox

use of org.bboxdb.commons.math.BoundingBox in project bboxdb by jnidzwetzki.

the class TestTupleBuilder method testTPCHOrderPointTupleBuilder.

/**
 * Test the tpch range tuple builder
 * @throws ParseException
 */
@Test
public void testTPCHOrderPointTupleBuilder() throws ParseException {
    final TupleBuilder tupleBuilder = TupleBuilderFactory.getBuilderForFormat(TupleBuilderFactory.Name.TPCH_ORDER_POINT);
    final Tuple tuple = tupleBuilder.buildTuple("1", TPCH_ORDER_TEST_LINE);
    Assert.assertTrue(tuple != null);
    Assert.assertEquals(Integer.toString(1), tuple.getKey());
    final SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-mm-dd");
    final Date orderDate = dateParser.parse("1996-01-02");
    final double doubleOrder = (double) orderDate.getTime();
    final BoundingBox expectedBox = new BoundingBox(doubleOrder, doubleOrder);
    Assert.assertEquals(expectedBox, tuple.getBoundingBox());
}
Also used : TupleBuilder(org.bboxdb.tools.converter.tuple.TupleBuilder) BoundingBox(org.bboxdb.commons.math.BoundingBox) SimpleDateFormat(java.text.SimpleDateFormat) Tuple(org.bboxdb.storage.entity.Tuple) Date(java.util.Date) Test(org.junit.Test)

Aggregations

BoundingBox (org.bboxdb.commons.math.BoundingBox)194 Test (org.junit.Test)113 Tuple (org.bboxdb.storage.entity.Tuple)61 ArrayList (java.util.ArrayList)25 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)24 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)23 BBoxDBException (org.bboxdb.misc.BBoxDBException)22 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)20 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)16 List (java.util.List)15 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)13 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)13 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)13 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)12 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)11 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)11 IOException (java.io.IOException)10 Date (java.util.Date)10 DoubleInterval (org.bboxdb.commons.math.DoubleInterval)10 SpatialIndexReadOperator (org.bboxdb.storage.queryprocessor.operator.SpatialIndexReadOperator)10