Package ar.renderers

Examples of ar.renderers.ParallelRenderer


    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

  public TransferDisplay(Aggregates<?> aggregates, Transfer<?,?> transfer) {
    this(aggregates, new AffineTransform(), transfer);
  }

  public TransferDisplay(Aggregates<?> aggregates, AffineTransform rendererd, Transfer<?,?> transfer) {
    this(aggregates, rendererd, transfer, new ParallelRenderer());
  }
View Full Code Here

    //canvas space and through the glyphset.  The two big options are to divide
    //the canvas into regions or divide the glyphset into subsets.
    //The ParalleGlyph renderer is the highest performance BUT requires
    // the glyphset to be partitionable and requires an "Aggregate Reduction" function
    // to combine results from different glyph subsets.
    Renderer r = new ParallelRenderer();

    //The Aggregator is used to combine values from multiple glyphs into a value for a single
    //aggregate bin.  The 'Count' aggregator simply counts how many glyphs fell into the bin.
    Aggregator<Object,Integer> aggregator = new Numbers.Count<Object>();
   

    //The transfer function is used to convert one set of aggregates into another.
    //In the end, an image is a set of aggreagates where the value in each bin is a color.
    Transfer<Number, Color> transfer = new  Numbers.Interpolate<>(new Color(255,0,0,25), new Color(255,0,0,255));


    //Selector associates the glyphs individual bins. 
    //The geometry type matters (and thus is a type-parameter) because it determines which test to use
    Selector<Rectangle2D> selector = TouchesPixel.make(dataset);

   
    //Drive the rendering "by-hand"  (ie, not using any of the swing tools)
    //We must first define a display surface's size, shape and zoom characteristics
    //At the end, a simple buffered image is produced.
    int width = 800;
    int height = 800;
    AffineTransform vt = Util.zoomFit(dataset.bounds(), width, height);
    Aggregates<Integer> aggregates = r.aggregate(dataset, selector, aggregator, vt, width, height);
    Transfer.Specialized<Number,Color> specializedTransfer = transfer.specialize(aggregates);
    Aggregates<Color> colors = r.transfer(aggregates, specializedTransfer);
   
    //Make a final image (if the aggregates are colors)
    @SuppressWarnings("unused"//Unused because its just a demo of how to do it
    BufferedImage image = AggregateUtils.asImage(colors, width, height, Color.white);
   
View Full Code Here

      System.exit(-2);
    }
   
    Aggregator<Object,Integer> aggregator = new Numbers.Count<Object>();
     
    Renderer render = new ParallelRenderer();
    Glyphset<Rectangle2D, Color> glyphs = new MemMapList<Rectangle2D, Color>(
          new File(source),
          new ToRect(size, size, false, 0, 1),
          new Constant<Indexed,Color>(Color.red));
    glyphs.bounds(); //Force bounds calc to only happen once...hopefully
   
    Selector<Rectangle2D> selector = TouchesPixel.make(glyphs);

    try {
      for (int i=0; i< widths.length; i++) {
        int width = Integer.parseInt(widths[i]);
        int height = Integer.parseInt(heights[i]);
        System.out.printf("Processing %s at %dx%d\n", source, width, height);
        AffineTransform ivt = Util.zoomFit(glyphs.bounds(), width, height).createInverse();
        Aggregates<Integer> aggs = render.aggregate(glyphs, selector, aggregator, ivt, width, height);
        String filepart = String.format("%dx%d", width, height);
        String filename = String.format(outPattern, filepart);
        System.out.printf("\t Writing to %s\n", filename);
        if (filename.endsWith("csv")) {
          AggregatesToCSV.export(aggs, new File(filename));
        } else {
          //Transfer<Number, Color> t = new Numbers.FixedInterpolate(Color.white, Color.red, 0, 25);
          //Transfer<Number, Color> t = new Advise.DrawDark(Color.black, Color.white, 5);;
          //Transfer<Number, Color> t = new Numbers.Interpolate<>(new Color(255,0,0,38), Color.red);
          Transfer<Number, Color> t = new Advise.Clipwarn<>(Color.BLACK, Color.BLACK, new Numbers.FixedInterpolate<>(Color.white, Color.red, 0, 25.5), 20);
          Transfer.Specialized<Number, Color> ts = t.specialize(aggs);
          Aggregates<Color> colors = render.transfer(aggs, ts);
          BufferedImage img = AggregateUtils.asImage(colors, width, height, Color.white);
          Util.writeImage(img, new File(filename));
        }
        System.out.printf("\t Done!\n");
      }
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);
   
    ContourAggregates<Double> ct = (ContourAggregates<Double>) new ParallelRenderer().transfer(magnitudes, contour);

   
   
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
View Full Code Here

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

TOP

Related Classes of ar.renderers.ParallelRenderer

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.