home processing download documents tutorial python tutorial gallery source about
 Tutorials (back to the list of tutorials)

Panelization Examples

     Panelization Example4

The following example shows panelization with tubed surfaces. A tube surface below is created with 3 control points in u direction and the surface is closed in u direction.
The sample input file used in the example is below.

surface4.3dm

import processing.opengl.*;
import igeo.*;

size(480, 360, IG.GL);

IG.open("surface4.3dm");
ISurface[] surfaces = IG.surfaces();

for (ISurface surf : surfaces) {

  int unum = 20, vnum=20;
  double uinc = 1.0/unum, vinc = 1.0/vnum;
  for (int i=0; i < unum; i++) {
    for (int j=0; j < vnum; j++) {
      IVec pt1 = surf.pt(i*uinc, j*vinc);
      IVec pt2 = surf.pt((i+1)*uinc, j*vinc);
      IVec pt3 = surf.pt((i+1)*uinc, (j+1)*vinc);
      IVec pt4 = surf.pt(i*uinc, (j+1)*vinc);

      double depth = 2.0;
      IVec pt1d = surf.pt(i*uinc, j*vinc, depth);
      IVec pt2d = surf.pt((i+1)*uinc, j*vinc, depth);
      IVec pt3d = surf.pt((i+1)*uinc, (j+1)*vinc, depth);
      
      IVec[][] cpts1 = new IVec[3][2];
      cpts1[0][0] = pt1;
      cpts1[1][0] = pt2;
      cpts1[2][0] = pt3;
      cpts1[0][1] = pt1d;
      cpts1[1][1] = pt2d;
      cpts1[2][1] = pt3d;

      // u degree 2 (curve), v degree 1 (straight)
      // true for closing surface in u direction
      new ISurface(cpts1, 2, 1, true, false);
    }
  }
  surf.del();
}

In the following code, one tube surface is divided into 4 surfaces connecting the curved profile and the rectangular profile.

import processing.opengl.*;
import igeo.*;

size(480, 360, IG.GL);

IG.open("surface4.3dm");
ISurface[] surfaces = IG.surfaces();

for (ISurface surf : surfaces) {

  int unum = 20, vnum=20;
  double uinc = 1.0/unum, vinc = 1.0/vnum;
  for (int i=0; i < unum; i++) {
    for (int j=0; j < vnum; j++) {
      IVec pt1 = surf.pt(i*uinc, j*vinc);
      IVec pt2 = surf.pt((i+1)*uinc, j*vinc);
      IVec pt3 = surf.pt((i+1)*uinc, (j+1)*vinc);
      IVec pt4 = surf.pt(i*uinc, (j+1)*vinc);

      double depth = -2.0;
      IVec pt1d = surf.pt(i*uinc, j*vinc, depth);
      IVec pt2d = surf.pt((i+1)*uinc, j*vinc, depth);
      IVec pt3d = surf.pt((i+1)*uinc, (j+1)*vinc, depth);

      IVec pt1m = pt1d.mid(pt2d);
      IVec pt2m = pt2d.mid(pt3d);
      IVec pt3m = pt3d.mid(pt1d);

      // side surface 1
      IVec[][] cpts2 = new IVec[3][2];
      cpts2[0][0]=pt1; 
      cpts2[1][0]=pt1.mid(pt4); 
      cpts2[2][0]=pt4;
      cpts2[0][1] = pt1m; 
      cpts2[1][1] = pt1d; 
      cpts2[2][1] = pt3m;
      new ISurface(cpts2, 2, 1);

      // side surface 2
      IVec[][] cpts3 = new IVec[3][2];
      cpts3[0][0] = pt3; 
      cpts3[1][0] = pt3.mid(pt2); 
      cpts3[2][0] = pt2;
      cpts3[0][1] = pt2m; 
      cpts3[1][1] = pt2d; 
      cpts3[2][1] = pt1m;
      new ISurface(cpts3, 2, 1);

      // side surface 3
      IVec[][] cpts4 = new IVec[3][2];
      cpts4[0][0] = pt4; 
      cpts4[1][0] = pt4.mid(pt3); 
      cpts4[2][0] = pt3;
      cpts4[0][1] = pt3m; 
      cpts4[1][1] = pt3d; 
      cpts4[2][1] = pt2m;
      new ISurface(cpts4, 2, 1);

      // side filling triangle
      new ISurface(pt1m, pt2, pt1);
    }
  }
  surf.del();
}

Then the depths of tubular surfaces are randomized.

import processing.opengl.*;
import igeo.*;

size(480, 360, IG.GL);

IG.open("surface4.3dm");
ISurface[] surfaces = IG.surfaces();

for (ISurface surf : surfaces) {

  int unum = 20, vnum=20;
  double uinc = 1.0/unum, vinc = 1.0/vnum;
  for (int i=0; i < unum; i++) {
    for (int j=0; j < vnum; j++) {
      IVec pt1 = surf.pt(i*uinc, j*vinc);
      IVec pt2 = surf.pt((i+1)*uinc, j*vinc);
      IVec pt3 = surf.pt((i+1)*uinc, (j+1)*vinc);
      IVec pt4 = surf.pt(i*uinc, (j+1)*vinc);

      double depth = IRandom.get(-5,5);
      double dratio = (depth+5)/10;

      IVec pt1d = surf.pt(i*uinc, j*vinc, depth);
      IVec pt2d = surf.pt((i+1)*uinc, j*vinc, depth);
      IVec pt3d = surf.pt((i+1)*uinc, (j+1)*vinc, depth);

      IVec pt1m = pt1d.mid(pt2d);
      IVec pt2m = pt2d.mid(pt3d);
      IVec pt3m = pt3d.mid(pt1d);

      IVec[][] cpts2 = new IVec[3][2];
      cpts2[0][0] = pt1; 
      cpts2[1][0] = pt1.mid(pt4); 
      cpts2[2][0] = pt4;
      cpts2[0][1] = pt1m; 
      cpts2[1][1] = pt1d; 
      cpts2[2][1] = pt3m;
      new ISurface(cpts2, 2, 1).clr(dratio/3+0.1,0.1,0.1);

      IVec[][] cpts3 = new IVec[3][2];
      cpts3[0][0] = pt3; 
      cpts3[1][0] = pt3.mid(pt2); 
      cpts3[2][0] = pt2;
      cpts3[0][1] = pt2m; 
      cpts3[1][1] = pt2d; 
      cpts3[2][1] = pt1m;
      new ISurface(cpts3, 2, 1).clr(dratio/3+0.1,0.1,0.1);

      IVec[][] cpts4 = new IVec[3][2];
      cpts4[0][0] = pt4; 
      cpts4[1][0] = pt4.mid(pt3); 
      cpts4[2][0] = pt3;
      cpts4[0][1] = pt3m; 
      cpts4[1][1] = pt3d; 
      cpts4[2][1] = pt2m;
      new ISurface(cpts4, 2, 1).clr(dratio/3+0.1,0.1,0.1);

      new ISurface(pt1m, pt2, pt1).clr(dratio/3+0.1,0.1,0.1);
    }
  }
  surf.del();
}


(back to the list of tutorials)

HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java / Python)
GALLERY
SOURCE CODE(GitHub)
ABOUT