Package ar

Examples of ar.Renderer


    final int seams;
    if (seamFactor != 0) {seams = (int) (width*seamFactor);}
    else {seams = perhapsSeams;}

   
    Renderer r = new ParallelRenderer();
    Aggregator<Object,Integer> aggregator = new Numbers.Count<Object>();
    Selector<Point2D> selector = TouchesPixel.make(dataset);


    AffineTransform vt = Util.zoomFit(dataset.bounds(), width, height);
    Aggregates<Integer> aggregates = r.aggregate(dataset, selector, aggregator, vt, width, height);

   
    Map<String, Transfer<Integer,Integer>> allCarvers = new HashMap<String, Transfer<Integer,Integer>>() {{
        put("incremental", new SeamCarving.CarveIncremental<>(new SeamCarving.LeftValue<Integer>(), Direction.V, 0,seams));
        put("sweep", new SeamCarving.CarveSweep<>(new SeamCarving.LeftValue<Integer>(), Direction.V, 0, seams));
View Full Code Here


public class Cartogram {

  public static void main(String[] args) throws Exception {
    Rectangle viewBounds = new Rectangle(0, 0, 1200,800);
    Renderer renderer = new ParallelRenderer();
   
   
    //Glyphset<Point2D, Character> populationSource = ar.app.components.sequentialComposer.OptionDataset.CENSUS_SYN_PEOPLE.dataset();
    final Glyphset<Point2D, CategoricalCounts<String>> populationSource = ar.app.components.sequentialComposer.OptionDataset.CENSUS_TRACTS.glyphset;
    System.out.println("Population glyphset loaded.");
   
    File statesSource = new File("../data/maps/USStates/");
    final Map<String, Shape> rawShapes = simplifyKeys(GeoJSONTools.flipY(GeoJSONTools.loadShapesJSON(statesSource, false)));
    rawShapes.remove("AK");
    rawShapes.remove("HI");
    final Glyphset<Shape, String> states = WrappedCollection.wrap(rawShapes.entrySet(), new Shaper.MapValue<String, Shape>(), new Valuer.MapKey<String, Shape>());
    System.out.println("State shapes loaded.");

    final AffineTransform viewTransform = Util.zoomFit(populationSource.bounds().createUnion(states.bounds()), viewBounds.width, viewBounds.height);

   
    final Aggregates<Integer> population = renderer.aggregate(populationSource, TouchesPixel.make(populationSource), new Numbers.Count<>(), viewTransform, viewBounds.width, viewBounds.height);
    final Aggregates<String> labels = renderer.aggregate(states, TouchesPixel.make(states), new General.Last<>(""), viewTransform, viewBounds.width, viewBounds.height);
    Aggregates<Pair<String,Integer>> pairs = CompositeWrapper.wrap(labels, population);
    System.out.println("Base aggregates created.\n");
   
   
    int step=100;
    //final Transfer.Specialized<Pair<String,Integer>,Pair<String,Integer>> smear = new General.Smear<>(EMPTY);
    //Aggregates<Pair<String,Integer>> smeared = renderer.transfer(pairs, smear);

    final Transfer<Integer, Color> colorPopulation =
        Seq.start(new General.ValuerTransfer<>(new MathValuers.Log<Integer>(10d), 0d))
        .then(new General.Replace<>(Double.NEGATIVE_INFINITY, 0d, 0d))
        .then(new Numbers.Interpolate<Double>(new Color(255,0,0,25), new Color(255,0,0,255)));

    final General.MapWrapper<String, Color> color2012= new General.MapWrapper<>(results2012, Color.gray)
    final General.MapWrapper<String, Color> color2008= new General.MapWrapper<>(results2008, Color.gray)
   
    for (int seams=0; seams<viewBounds.width; seams+=step) {
      System.out.println("Starting removing " + seams + " seams");

      //Transfer.Specialized<Pair<String,Integer>, Pair<String,Integer>> carver = new SeamCarving.CarveIncremental<>(new DeltaPair(), Direction.V, EMPTY, seams);
      Transfer.Specialized<Pair<String,Integer>, Pair<String,Integer>> carver = new SeamCarving.CarveSweep<>(new DeltaPair(), Direction.V, EMPTY, seams);
      Aggregates<Pair<String,Integer>> carved = renderer.transfer(pairs, carver);
      //carved = renderer.transfer(carved, new Borders(EMPTY));
     
      CompositeWrapper<String,Integer, ?> composite = CompositeWrapper.convert(carved, "", 0);
     
      Aggregates<Integer> carvedPop = composite.right();
      Aggregates<String> carvedStates = composite.left();
     
      Aggregates<Color> popImg = renderer.transfer(carvedPop, colorPopulation.specialize(carvedPop));
      Aggregates<Color> states2012 = renderer.transfer(carvedStates, color2012);
      Aggregates<Color> states2008 = renderer.transfer(carvedStates, color2008);
     
      Util.writeImage(AggregateUtils.asImage(popImg), new File(String.format("./testResults/seams/%d-seams-population.png",seams)));
      Util.writeImage(AggregateUtils.asImage(states2008), new File(String.format("./testResults/seams/%d-2008-seams-election.png",seams)));
      Util.writeImage(AggregateUtils.asImage(states2012), new File(String.format("./testResults/seams/%d-2012-seams-election.png",seams)));
      System.out.println("Completed export on " + seams + " seams\n");
View Full Code Here

    BufferedImage img = AggregateUtils.asImage(imgAggs, width, height, Color.white);
    return img;
  }
 
  public <G,V,A> void testWith(String test, Glyphset<G,V> glyphs, Aggregator<V,A> agg, Transfer<? super A,Color> tthrows Exception {
    Renderer r = new SerialRenderer();
    BufferedImage ref_img =image(r, glyphs, agg, t);
    Util.writeImage(ref_img, new File(String.format("./testResults/%s/ref.png", test)));   
   
    r = new SerialRenderer();
    BufferedImage ser_img = image(r, glyphs, agg, t);
View Full Code Here

            new Indexed.ToValue<Indexed,Character>(2),
            1, null);

   
   
    Renderer r = new ParallelRenderer();
    Aggregator<Object,Integer> aggregator = new Numbers.Count<Object>();
    Selector<Point2D> selector = TouchesPixel.make(dataset);

   
    final int width = 800;
    final int height = 800;
    AffineTransform vt = Util.zoomFit(dataset.bounds(), width, height);
    Aggregates<Integer> counts = r.aggregate(dataset, selector, aggregator, vt, width, height);
   
    //final ISOContours.Single.Specialized<Integer> contour = new ISOContours.Single.Specialized<>(5, true, counts);
    //final ISOContours.NContours.Specialized<Integer> contour = new ISOContours.NContours.Specialized<>(5, true, counts);
    //final ISOContours.SpacedContours.Specialized<Integer> contour = new ISOContours.SpacedContours.Specialized<>(0, 100, true, counts);
   
    Aggregates<Double> magnitudes = r.transfer(counts, new General.ValuerTransfer<>(new MathValuers.Log<>(10d, true), aggregator.identity().doubleValue()));
   
    //final ISOContours.Single.Specialized<Double> contour = new ISOContours.Single.Specialized<>(2d, false, magnitudes);
    final ISOContours.NContours.Specialized<Double> contour = new ISOContours.NContours.Specialized<>(3, true, magnitudes);
    //final ISOContours.SpacedContours.Specialized<Double> contour = new ISOContours.SpacedContours.Specialized<>(.5, 0d, false, magnitudes);
   
View Full Code Here

    Aggregator aggregator = source.defaultAggregator.aggregator();
    Glyphset glyphs = source.glyphset;
    Transfer transfer = OptionTransfer.toTransfer(source.defaultTransfers, null);
 
   
    Renderer render;
    if (rend.startsWith("PARALLEL")) {
      render = new ParallelRenderer();
    } else if (rend.startsWith("SERIAL")) {
      render = new SerialRenderer();
    } else {
      throw new IllegalArgumentException("Renderer type not known: " + rend);
    }
   
    AffineTransform vt = Util.zoomFit(glyphs.bounds(), width, height);
    Selector s = TouchesPixel.make(glyphs);
    long taskCount = cores * tasksPerThread;
   
    if (header) {
      System.out.println("source, elapse/avg agg, elapse/avg trans, iter num, width, height, renderer, cores, tasks (max)");
    }
   
    try {
      for (int i=0; i<iterations; i++) {
        long start = System.currentTimeMillis();
        Aggregates<Integer> aggs = render.aggregate(glyphs, s, aggregator, vt, width, height);
        long end = System.currentTimeMillis();
        long aggTime = end-start;

        start = System.currentTimeMillis();
        Transfer.Specialized<Number,Color> ts = transfer.specialize(aggs);
        Aggregates<Color> colors = render.transfer(aggs, ts);
        end = System.currentTimeMillis();
        long transTime = end-start;

        aggs.get(0, 0);
        colors.get(0, 0);
View Full Code Here

  @BeforeClass
  public static void load() throws Exception {
    Glyphset<Rectangle2D, Object> glyphs = GlyphsetUtils.autoLoad(new File("../data/circlepoints.csv"), .1, DynamicQuadTree.<Rectangle2D, Object>make());
    Selector<Rectangle2D> selector = TouchesPixel.make(glyphs);
    Renderer r = new ParallelRenderer();
    count = r.aggregate(glyphs, selector, new Numbers.Count<>(), Util.zoomFit(glyphs.bounds(), 10, 10), 10,10);
  }
View Full Code Here

public class SpreadTests {

  @Test
  public void testFullSquare() {
    Renderer r = new ParallelRenderer();
    Aggregator<Integer,Integer> combiner = new Numbers.Count<>();
    Aggregates<Integer> aggs = new RefFlatAggregates<Integer>(9,9,0);
    aggs.set(4, 4, 1);
   
    Spreader<Integer> spread4 = new General.Spread.UnitRectangle<>(4);
    General.Spread<Integer> transfer4 = new General.Spread<Integer>(spread4 , combiner);
    Specialized<Integer,Integer> s4 = transfer4.specialize(aggs);
   
    Aggregates<Integer> rslt = r.transfer(aggs, s4);
    for (int x=rslt.lowX(); x<rslt.highX(); x++){
      for (int y=rslt.lowY(); y<rslt.highY(); y++){
        assertThat(String.format("Failed at (%d, %d)",x,y), rslt.get(x,y), is(1));
      }
    }
View Full Code Here

    }
  }
   
  @Test
  public void testCenterSquare() {
    Renderer r = new ParallelRenderer();
    Aggregator<Integer,Integer> combiner = new Numbers.Count<>();
    Aggregates<Integer> aggs = new RefFlatAggregates<Integer>(9,9,0);
    aggs.set(4, 4, 1);
   
    Spreader<Integer> spread2 = new General.Spread.UnitRectangle<>(2);
    General.Spread<Integer> transfer2 = new General.Spread<Integer>(spread2, combiner);
    Specialized<Integer,Integer> s2 = transfer2.specialize(aggs);
    Aggregates<Integer> rslt = r.transfer(aggs, s2);
   
    assertThat(String.format("Failed at (%d, %d)", 0,0), rslt.get(0,0), is(0));
    assertThat(String.format("Failed at (%d, %d)", 3,3), rslt.get(3,3), is(1));
    assertThat(String.format("Failed at (%d, %d)", 3,5), rslt.get(3,5), is(1));
    assertThat(String.format("Failed at (%d, %d)", 3,6), rslt.get(3,6), is(1));
View Full Code Here

    assertThat(String.format("Failed at (%d, %d)", 8,8), rslt.get(8,8), is(0));
  }
 
  @Test
  public void testUnitCircle() {
    Renderer r = new ParallelRenderer();
    Aggregator<Integer,Integer> combiner = new Numbers.Count<>();
    Aggregates<Integer> aggs = new RefFlatAggregates<Integer>(9,9,0);
    aggs.set(4, 4, 1);
   
    Spreader<Integer> spread2 = new General.Spread.UnitCircle<>(4);
    General.Spread<Integer> transfer2 = new General.Spread<Integer>(spread2, combiner);
    Specialized<Integer,Integer> s2 = transfer2.specialize(aggs);
    Aggregates<Integer> rslt = r.transfer(aggs, s2);
   
    assertThat(String.format("Failed at (%d, %d)", 0,0), rslt.get(0,0), is(0));
    assertThat(String.format("Failed at (%d, %d)", 1,1), rslt.get(1,1), is(0));
    assertThat(String.format("Failed at (%d, %d)", 3,3), rslt.get(3,3), is(1));
    assertThat(String.format("Failed at (%d, %d)", 3,5), rslt.get(3,5), is(1));
View Full Code Here

    assertThat(String.format("Failed at (%d, %d)", 8,8), rslt.get(8,8), is(0));
  }
 
  @Test
  public void testValueCircle4() {
    Renderer r = new ParallelRenderer();
    Aggregator<Integer,Integer> combiner = new Numbers.Count<>();
    Aggregates<Integer> aggs = new RefFlatAggregates<Integer>(9,9,0);
    aggs.set(4, 4, 4);
   
    Spreader<Integer> spread2 = new General.Spread.ValueCircle<>();
    General.Spread<Integer> transfer2 = new General.Spread<Integer>(spread2, combiner);
    Specialized<Integer,Integer> s2 = transfer2.specialize(aggs);
    Aggregates<Integer> rslt = r.transfer(aggs, s2);
   
    assertThat(String.format("Failed at (%d, %d)", 0,0), rslt.get(0,0), is(0));
    assertThat(String.format("Failed at (%d, %d)", 1,1), rslt.get(1,1), is(0));
    assertThat(String.format("Failed at (%d, %d)", 3,3), rslt.get(3,3), is(4));
    assertThat(String.format("Failed at (%d, %d)", 3,5), rslt.get(3,5), is(4));
View Full Code Here

TOP

Related Classes of ar.Renderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.