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);
}
}
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);
}
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);
}
}
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());
}
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());
}
Aggregations