Problems with .dxf output

Hi,

I've created a small application to translate pixel values from an image into a 3D landscape (taking r,g,b values as x,y,z coordinates), which I'm then exporting as a .dxf, before converting it to a .stl file (in Rhino) and printing it.

The code has worked pretty well for simple objects but with added complexity, it seems to only save some of the object. Any ideas as to why? Is there any way to export directly to .stl?

Here's my code:

    import peasy.*;
    import processing.dxf.*;
    import java.util.Map;
    import processing.opengl.*;
    PVector[] myBoxes;
    PeasyCam cam;
    boolean record;
    PImage img;
    ArrayList pixelArrayList;
    int count = 0;
    int ycount = 0;
    int xcount = 0;
    int step = 10;
    void setup() {
      //  img = loadImage("P_test.jpg");
      img = loadImage("E00411514.jpg");

      size(1080, 720, P3D);
      cam = new PeasyCam(this, 100);
      cam.setMinimumDistance(50);
      cam.setMaximumDistance(10000);


      //void DrawObject

      img.loadPixels();            
      //  myBoxes=new PVector[img.width*img.height]

      background(0);
      //  directionalLight(255, 255, 255, 1, 1, -1);
      //  directionalLight(127, 127, 127, -1, -1, 1);  
      pixelArrayList = new ArrayList();
      int myIndex=0;
      for (int y = 0; y < img.height; y+=step) {
        for (int x = 0; x < img.width; x+=step) {
          myIndex=y*img.width+x;

          int red = (int)red(img.pixels[myIndex]);
          int green = (int)green(img.pixels[myIndex]);
          int blue = (int)blue(img.pixels[myIndex]);
          // amplify
          //      red = (int)(red/10)+(int)(red/2)/(int)(red/PI);
          //      green = (int)(green/10)+(int)(green/2)/(int)(green/PI);
          //      blue = (int)(blue/10)+(int)(blue/2)/(int)(blue/PI);

          HashMap <String, Integer> hm = new HashMap <String, Integer>();
          hm.put("x", x);
          hm.put("y", y);
          hm.put("r", red);
          hm.put("g", green);
          hm.put("b", blue);
          ycount++;
          count++;
          pixelArrayList.add(hm);
          //      println(hm);
        }
        xcount++;
        ycount = 0;
      }
      //  rotateY(mouseX*1.0f/width*TWO_PI);
      //  rotateX(mouseY*1.0f/height*TWO_PI);

      //  for (int i = 0; i < pixelArrayList.size(); i+=10) {
      //    translate (1, 1, 0);
      //    HashMap <String, Integer> hm = (HashMap <String, Integer>) pixelArrayList.get(i);
      //    box(hm.get("r"), hm.get("g"), hm.get("b"));
      //  }
    }

    void draw() {
      background(50, 124, 149);


      for (int i = 0; i < pixelArrayList.size(); i++) {

        HashMap <String, Integer> hm = (HashMap <String, Integer>) pixelArrayList.get(i);
        int zscale = (int)hm.get("r")*(int)hm.get("g")*(int)hm.get("b");
        int x = (int)hm.get("x");
        int y = (int)hm.get("y");
        int r = 255-((int)hm.get("r"));
        int g = 255-((int)hm.get("g"));
        int b = 255-((int)hm.get("b"));

        pushMatrix();
        translate(x, y, 0);
        fill(172, 105, 57);
        //    fill((int)hm.get("r"), (int)hm.get("g"), (int)hm.get("b"));
        //    println(x, y);
        //sphereDetail(8);
        //noStroke();
        box(r, g, b);
        scale(0.1, 0.1, 0.1);
        popMatrix();
      } 
      //  rotateY(mouseX*1.0f/width*TWO_PI);
      //  rotateX(mouseY*1.0f/height*TWO_PI);

      if (record) {
        beginRaw(DXF, "output.dxf");
      }

      // Do all your drawing here
      if (record) {
        endRaw();
        exit();
      }
    }

    void keyPressed() {
      // Use a key press so that it doesn't make a million files
      if (key == 'r') {
        record = true;
      }
    }

It returns a model like this in the java window: Screen Shot 2014-05-02 at 11.29.21

but a .dxf file like this (at least this is how it opens in Rhino.

Screen Shot 2014-05-02 at 11.30.56

it seems like it just takes part of the model.

Thanks - any help much appreciated.

Tagged:

Answers

  • Apologies, I realise I haven't annotated this and it's a bit messy. Let me know if there's any confusion.

  • Lines 98 to 106, it looks like you start to record after having done the drawing, and you stop the record immediately after. I don't even understand how you can have anything in your file.

Sign In or Register to comment.