9.10.12

the code for exporting contour to pdf in processing

import blobDetection.*;
import peasy.*;
PeasyCam cam;
import processing.pdf.*;
boolean record = false;


PImage img;

float levels = 35;                    // number of contours
float factor = 1;                     // scale factor
float elevation = 55;                 // total height of the 3d model

float colorStart =  0;                // Starting degree of color range in HSB Mode (0-360)
float colorRange =  100;              // color range / can also be negative

// Array of BlobDetection Instances
BlobDetection[] theBlobDetection = new BlobDetection[int(levels)];

void setup() {
  size(1000,800,P3D);  
  img = loadImage("dsa.gif");           // heightmap (about 250×250px)
  cam = new PeasyCam(this,200);
  colorMode(HSB,360,100,100);

  //Computing Blobs with different thresholds 
  for (int i=0 ; i<levels ; i++) {
    theBlobDetection[i] = new BlobDetection(img.width, img.height);
    theBlobDetection[i].setThreshold(i/levels);
    theBlobDetection[i].computeBlobs(img.pixels);
  }
}

void draw() {
if (record) {
beginRaw(PDF, "save_file_name.pdf");
}{ 
  background(0);
  translate(-img.width*factor/2,-img.height*factor/2);

  for (int i=0 ; i<levels ; i++) {
    translate(0,0,elevation/levels);
    drawContours(i);
  }
}
void drawContours(int i) {
  Blob b;
  EdgeVertex eA,eB;

  for (int n=0 ; n<theBlobDetection[i].getBlobNb() ; n++) {
    b=theBlobDetection[i].getBlob(n);
    if (b!=null) {
      stroke((i/levels*colorRange)+colorStart,0,100);      // coloring the contours

      for (int m=0;m<b.getEdgeNb();m++) {
        eA = b.getEdgeVertexA(m);
        eB = b.getEdgeVertexB(m);
        if (eA !=null && eB !=null)
          line(
          eA.x*img.width*factor, eA.y*img.height*factor, 
          eB.x*img.width*factor, eB.y*img.height*factor 
            );
      }
    }
  }
}
}
if (record) {
endRaw();
record = false;
}
}
void keyPressed() {

record = true;
}
}


the code for exporting contour to pdf in processing
but it seems it have error

No comments:

Post a Comment