Skip to content

Commit

Permalink
new release 0.62(32)
Browse files Browse the repository at this point in the history
  • Loading branch information
diwi committed Jul 17, 2017
1 parent 9fdfcf1 commit 911fb43
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 61 deletions.
91 changes: 40 additions & 51 deletions examples/OpticalFlow_MovieFluid/OpticalFlow_MovieFluid.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ public void update(DwFluid2D fluid) {
public void addDensityTexture_cam(DwFluid2D fluid, DwOpticalFlow opticalflow){
int[] pg_tex_handle = new int[1];

if( !pg_movie_a.getTexture().available() ) {
if( !pg_movie.getTexture().available() ) {
System.out.println("no tex");
return;
}

float mix = opticalflow.UPDATE_STEP > 1 ? 0.05f : 1.0f;

context.begin();
context.getGLTextureHandle(pg_movie_a, pg_tex_handle);
context.getGLTextureHandle(pg_movie, pg_tex_handle);
context.beginDraw(fluid.tex_density.dst);
DwGLSLProgram shader = context.createShader("data/addDensityCam.frag");
shader.begin();
Expand Down Expand Up @@ -184,30 +184,25 @@ public void addVelocityTexture(DwFluid2D fluid, DwOpticalFlow opticalflow){
// fluid stuff
int fluidgrid_scale = 1;
DwFluid2D fluid;
MyFluidData cb_fluid_data;


// buffer for the movie-image
PGraphics2D pg_movie_a, pg_movie_b;

// offscreen render-target

// render targets
PGraphics2D pg_movie;
PGraphics2D pg_temp;
PGraphics2D pg_oflow;

// Movie
Movie movie;
TimeLine timeline;

// font used for Timeline
PFont font;



// some state variables for the GUI/display
int BACKGROUND_COLOR = 0;
int BACKGROUND_COLOR = 0;
boolean DISPLAY_SOURCE = true;
boolean APPLY_GRAYSCALE = false;
boolean APPLY_BILATERAL = true;
int VELOCITY_LINES = 6;
boolean APPLY_GRAYSCALE = false;
boolean APPLY_BILATERAL = true;
int VELOCITY_LINES = 6;

boolean UPDATE_FLUID = true;

Expand All @@ -222,7 +217,7 @@ public void addVelocityTexture(DwFluid2D fluid, DwOpticalFlow opticalflow){

public void settings() {
size(view_w, view_h, P2D);
smooth(4);
smooth(8);
}

public void setup() {
Expand All @@ -236,46 +231,40 @@ public void setup() {

// optical flow object
opticalflow = new DwOpticalFlow(context, pg_movie_w, pg_movie_h);


// initial optical flow parameters
opticalflow.param.display_mode = 1;

// fluid sobject
// fluid object
fluid = new DwFluid2D(context, pg_movie_w, pg_movie_h, fluidgrid_scale);

// initial fluid parameters
fluid.param.dissipation_density = 0.95f;
fluid.param.dissipation_velocity = 0.90f;
fluid.param.dissipation_temperature = 0.70f;
fluid.param.vorticity = 0.30f;

// callback for adding fluid data
cb_fluid_data = new MyFluidData();
fluid.addCallback_FluiData(cb_fluid_data);
fluid.addCallback_FluiData(new MyFluidData());

pg_movie_a = (PGraphics2D) createGraphics(pg_movie_w, pg_movie_h, P2D);
pg_movie_a.noSmooth();
pg_movie_a.beginDraw();
pg_movie_a.background(0);
pg_movie_a.endDraw();
// init render targets
pg_movie = (PGraphics2D) createGraphics(pg_movie_w, pg_movie_h, P2D);
pg_movie.smooth(0);
pg_movie.beginDraw();
pg_movie.background(0);
pg_movie.endDraw();

pg_movie_b = (PGraphics2D) createGraphics(pg_movie_w, pg_movie_h, P2D);
pg_movie_b.noSmooth();
pg_temp = (PGraphics2D) createGraphics(pg_movie_w, pg_movie_h, P2D);
pg_temp.smooth(0);

pg_oflow = (PGraphics2D) createGraphics(pg_movie_w, pg_movie_h, P2D);
pg_oflow.smooth(4);

pg_oflow.smooth(0);

font = createFont("../data/SourceCodePro-Regular.ttf", 12);

// movie file is not contained in the library release
// to keep the file size small. please use one of your own videos instead.
movie = new Movie(this, "examples/data/Pulp_Fiction_Dance_Scene.mp4");
movie.loop();

// font for timeline
font = createFont("../data/SourceCodePro-Regular.ttf", 12);


timeline = new TimeLine(movie, 0, height-20, pg_movie_w, 20);

createGUI();
Expand Down Expand Up @@ -307,27 +296,27 @@ public void draw() {
}

// render to offscreenbuffer
pg_movie_a.beginDraw();
pg_movie_a.background(0);
pg_movie_a.imageMode(CENTER);
pg_movie_a.pushMatrix();
pg_movie_a.translate(pg_movie_w/2f, pg_movie_h/2f);
pg_movie_a.scale(0.95f);
pg_movie_a.image(movie, 0, 0, mov_w_fit, mov_h_fit);
pg_movie_a.popMatrix();
pg_movie_a.endDraw();
pg_movie.beginDraw();
pg_movie.background(0);
pg_movie.imageMode(CENTER);
pg_movie.pushMatrix();
pg_movie.translate(pg_movie_w/2f, pg_movie_h/2f);
pg_movie.scale(0.95f);
pg_movie.image(movie, 0, 0, mov_w_fit, mov_h_fit);
pg_movie.popMatrix();
pg_movie.endDraw();

// apply filters (not necessary)
if(APPLY_GRAYSCALE){
DwFilter.get(context).luminance.apply(pg_movie_a, pg_movie_a);
DwFilter.get(context).luminance.apply(pg_movie, pg_movie);
}
if(APPLY_BILATERAL){
DwFilter.get(context).bilateral.apply(pg_movie_a, pg_movie_b, 5, 0.10f, 4);
DwFilter.get(context).bilateral.apply(pg_movie, pg_temp, 5, 0.10f, 4);
swapCamBuffer();
}

// update Optical Flow
opticalflow.update(pg_movie_a);
opticalflow.update(pg_movie);
}

if(UPDATE_FLUID){
Expand All @@ -338,7 +327,7 @@ public void draw() {
pg_oflow.beginDraw();
pg_oflow.background(BACKGROUND_COLOR);
if(DISPLAY_SOURCE){
pg_oflow.image(pg_movie_a, 0, 0);
pg_oflow.image(pg_movie, 0, 0);
}
pg_oflow.endDraw();

Expand Down Expand Up @@ -372,9 +361,9 @@ public void draw() {


void swapCamBuffer(){
PGraphics2D tmp = pg_movie_a;
pg_movie_a = pg_movie_b;
pg_movie_b = tmp;
PGraphics2D tmp = pg_movie;
pg_movie = pg_temp;
pg_temp = tmp;
}


Expand Down
2 changes: 1 addition & 1 deletion src/com/thomasdiewald/pixelflow/java/DwPixelFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class DwPixelFlow{

static public class PixelFlowInfo{

static public final String version = "0.61";
static public final String version = "0.62";
static public final String name = "PixelFlow";
static public final String author = "Thomas Diewald";
static public final String web = "http://www.thomasdiewald.com";
Expand Down
3 changes: 2 additions & 1 deletion src/com/thomasdiewald/pixelflow/java/dwgl/DwGLSLProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ public void drawFullScreenPoints(int x, int y, int w, int h, int num_points){
// gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_SRC_ALPHA );
// gl.glBlendEquation(GL.GL_FUNC_ADD);


// gl.glEnable(GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
gl.glEnable(GL3.GL_PROGRAM_POINT_SIZE);
gl.glEnable(GL3.GL_VERTEX_PROGRAM_POINT_SIZE);
gl.glEnable(GL2ES1.GL_POINT_SPRITE);

gl.glDrawArrays(GL2ES2.GL_POINTS, 0, num_points);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,9 @@ public void computeOpticalFlow() {
// 2) gradients
filter.sobel.apply(frameCurr.frame, frameCurr.sobelH, Sobel.TYPE._3x3_HORZ);
filter.sobel.apply(frameCurr.frame, frameCurr.sobelV, Sobel.TYPE._3x3_VERT);

// 3) compute optical flow
if(UPDATE_STEP == 0){

} else {

if(UPDATE_STEP >= 1){
// 3) compute optical flow
context.beginDraw(frameCurr.velocity);
DwGLSLProgram shader = param.grayscale ? shader_OF_gray : shader_OF_rgba;
shader.begin();
Expand All @@ -185,11 +183,10 @@ public void computeOpticalFlow() {
filter.gaussblur.apply(frameCurr.velocity, frameCurr.velocity, frameCurr.tmp, param.blur_flow);

// 5) mix with previous velocity

DwGLTexture dst = frameCurr.velocity;
DwGLTexture srcA = framePrev.velocity;
DwGLTexture srcB = frameCurr.velocity;
float mix = Math.min(Math.max(param.temporal_smoothing, 0), 0.99999f);
float mix = Math.min(Math.max(param.temporal_smoothing, 0), 0.99f);
float[] madA = { mix, 0};
float[] madB = {1f - mix, 0};
filter.merge.apply(dst, srcA, srcB, madA, madB);
Expand All @@ -204,7 +201,7 @@ public void computeOpticalFlow() {



DwGLRenderSettingsCallback rcb = new DwGLRenderSettingsCallback() {
public DwGLRenderSettingsCallback rcb = new DwGLRenderSettingsCallback() {
@Override
public void set(DwPixelFlow context, int x, int y, int w, int h) {
context.gl.glEnable(GLES3.GL_BLEND);
Expand Down

0 comments on commit 911fb43

Please sign in to comment.