We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › Geomerative library help
Page Index Toggle Pages: 1
Geomerative library help (Read 1885 times)
Geomerative library help
Oct 4th, 2008, 4:07am
 
ok so I am very new at this (as you will see by looking at my code) so any help would be great.  what I am trying to do is import a svg and draw it to the screen.  then change the segment length to deform the svg and draw that to the screen. then combine the deformed and non-deformed svg and draw that to the screen. then deform the combined svg the same way as the original svg was deformed then draw that to the screen.

here is the code I have most of which I cobbled together from the tutorials (of which I could only get the first 12 to run but that is another story)

import processing.opengl.*;
import geomerative.*;
import processing.xml.*;

RSVG svgLoader;
RGroup app;
RGroup yama;
RPolygon appPoly;
RPolygon orgPoly;

RGroup polyGrp;
RGroup polyGrp2;
RGroup polyGrpOrg;
float pointSeparation ;

 size(800, 600, OPENGL);
 smooth();
 g.smooth = true;
 
 // VERY IMPORTANT: Allways initialize the library before using it
 RGeomerative.init(this);

 svgLoader = new RSVG();
 app = svgLoader.toGroup("apple.svg");
 app.centerIn(g);
 svgLoader = new RSVG();
 yama = svgLoader.toGroup("yamaha.svg");
 yama.centerIn(g);
 
 background(255);
 pointSeparation = 200;
 frameRate(4);
 
  polyGrpOrg = app.toPolygonGroup();
  polyGrp = app.toPolygonGroup();
 
  // draw svg as imported
  pushMatrix();
  RGeomerative.ignoreStyles();
       translate(width*.25, height*.25);
       stroke(200, 150,150,150);
       fill ( 150,50);
     scale(.5);
     app.draw();
   popMatrix();
   
// draw svg with SegmentLength transformantation  
   pushMatrix();
     translate(width*.75, height*.25);
     RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
     RCommand.setSegmentLength(pointSeparation);
     polyGrp = app.toPolygonGroup();
     RGeomerative.ignoreStyles();
     stroke(200, 150,150,150);
     fill ( 150,50);
      scale(.5);
       polyGrp.draw();
   popMatrix();

// combine first svg with transformed svg with addGroup and draw    
  pushMatrix();
     translate(width*.25, height*.75);
     RGeomerative.ignoreStyles();
     stroke(200, 150,150,150);
     fill ( 150,50);
    polyGrpOrg.addGroup(polyGrp);
    scale(.5);
    polyGrpOrg.draw();
    polyGrp = polyGrpOrg.toPolygonGroup();
  popMatrix();

// transform svg addGroup with SegmentLength
//this is what I can not get to work
  pushMatrix();
     translate(width*.75, height*.75);
     new RCommand();
     svgLoader = new RSVG();
     polyGrp2 = svgLoader.toGroup(polyGrpOrg);
    polyGrp2.centerIn(g);
     RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
     RCommand.setSegmentLength(pointSeparation);
     polyGrp2 = polyGrp.toPolygonGroup();
     RGeomerative.ignoreStyles();
     stroke(200, 150,150,150);
     fill ( 150,50);
      scale(.5);
       polyGrp2.draw();
   popMatrix();
 
Re: Geomerative library help
Reply #1 - Oct 7th, 2008, 5:17pm
 
Hi,

This version of Geomerative wasn't still ready for public use, that's why some of the tutorials are not working and the API for doing some simple things is quite complex and not consistent.  And I haven't yet sorted out some of the problems with processing-148 + OPENGL, so I wouldn't recommend this version yet.
I should have added a note to the website, since it was publicly available, that was my bad, sorry!

Anyway, I don't understand very well what you mean with "combining" the groups.

From the main description you wrote of what you are trying to do.  The beginning of the script should look something like this:

Code:

RSVG svgLoader;
RGroup app, app_deformed, combined, combined_deformed;

// Initialize the lib
RGeomerative.init(this);

// Parameters for deformation
pointSeparation = 200;

// Load the original shape
svgLoader = new RSVG();
app = svgLoader.toGroup("apple.svg");
app.centerIn(g); // this centers the shape in the screen

// Create the deformed group
RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
RCommand.setSegmentLength(pointSeparation);
app_deformed = app.toPolygonGroup(); // this deforms the shape by polygonizing it

// Create the combined group
combined = new RGroup(app); // this makes a copy of the original shape that you loaded
combined.addGroup(app_deformed);

// Create the combined deformed group
RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
RCommand.setSegmentLength(pointSeparation);
combined_deformed = combined.toPolygonGroup();

// Then you should go on and draw the different shapes that you have created as you did in your script...



There might be some mistakes in the code, cannot try it out here.  Let me know if this works for you or if it helps at all.

ricard
Re: Geomerative library help
Reply #2 - Mar 22nd, 2010, 12:00pm
 
I have a question about the proper way to do something.
I'm using geomerative essentially to check for mousing over of an SVG image.  I'm trying to follow the code in Tutorial 23: Contains and I'm having some problems.  I am doing things a little bit differently than the tutorial so that's probably where my problem is but I'd be greatful for any help anybody can offer.

So what I'm doing differently than the tutorial is how I'm printing the SVG's.  In the tutorial this is done only once with Code:
RG.shape(grp); 

and in my case I'm calling RG.shape() many times to print the same image over and over in a line like so (the yellow pentagons specifically) (I can't post active links yet apparently.  Sorry for the text i722.photobucket.com/albums/ww228/askeeve/Picture2.png)

What I'm trying to accomplish is detect when the mouse is over a particular pentagon and change its color.  I'm doing this checking at the same time as I'm calling RG.shape() like so.
Code:
 
RG.init(this);
RG.setPolygonizer(RG.ADAPTATIVE);
pent = RG.loadShape("icon.svg");
...
RG.shape(pent, lastX, papersYzero-50, 50, 50);
drawPopUp();
...
void drawPopUp() {
 RPoint p = new RPoint(mouseX, mouseY);
 if (pent.contains(p)) {
   print("HOVERING!!!\n");
 }
}


What am I doing wrong?
Re: Geomerative library help
Reply #3 - Mar 25th, 2010, 10:19am
 
If you want to detect on which pentagon it is, you must have several pentagons at different positions.

I would create an array of shapes where each shape would be a new pentagon, and then I would translate each of these to the position you want.

Here's an example:

Quote:
import processing.xml.*;
import geomerative.*;

// Declare the objects we are going to use, so that they are accesible from setu
p() and from draw()

RShape[] grps = new RShape[10];

void setup(){
  // Initilaize the sketch
  size(600,400);
  smooth();
  
  // VERY IMPORTANT: Allways initialize the library in the setup
  RG.init(this);
  RG.ignoreStyles(true);

  // Choice of colors
  background(255);
  fill(255, 102, 0);
  stroke(0);
  
  for (int i=0; i<grps.length; i++) {
    grps[i] = RG.getStar(0, 0, 20, 40, 5);
    grps[i].translate(map(i, 0, grps.length-1, 100, width-100), height/2);
  }
}

void draw(){
  // Clean frame
  background(255);
  
  strokeWeight(3);
  
  for (int i=0; i<grps.length; i++) {
    if (grps[i].contains(mouseX, mouseY)) {
      stroke(0);
    } else {
      stroke(0, 100);
      
    }
    
    RG.shape(grps[i]);
  }
}

Page Index Toggle Pages: 1