Hello everybody!
I stuck with my problem.
PROBLEM:
- very slow algorithm
- no idea how to improve it
- any existing algorithm in Java/ JOGL?
HOW I DO:
I use shader to calculate izolines of temperature and i obtain for example this:
http://imageshack.us/photo/my-images/26/izoline.png
now i must to draw in JOGL black lines on color edges. I read all pixels from GL buffer.
public BufferedImage toImage(GL gl, int w, int h)
{
gl.glReadBuffer(GL.GL_FRONT); // or GL.GL_BACK
ByteBuffer glBB = ByteBuffer.allocate(3 * w * h);
gl.glReadPixels(0, 0, w, h, GL.GL_BGR, GL.GL_BYTE, glBB);
BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
int[] bd = ((DataBufferInt) bi.getRaster().getDataBuffer()).getData();
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
int b = 2 * glBB.get();
int g = 2 * glBB.get();
int r = 2 * glBB.get();
bd[(h - y - 1) * w + x] = (r << 16) | (g << 8) | b | 0xFF000000;
}
}
return bi;
}
But trying find edge pixel by pixel is soooo long in time. Like this:
BufferedImage bi = toImage(m_gl, Resources.dCanvasWidth, Resources.dCanvasHeight);
for(int i=0; i< 20; ++i)
{
System.out.println( i );
for(int i1=0; i1< bi.getData().getHeight()-1; ++i1)
{
int[] buff1;
int[] buff2;
buff1 = bi.getData().getPixel(i, i1, (int[]) null );
buff2 = bi.getData().getPixel(i, i1, (int[]) null );
if( !Arrays.equals(buff1, buff2) )
{
m_gl.glDrawPixels(i, i1,GL.GL_RGB, GL.GL_INT, blackPixel);
m_gl.glFlush();
}
}
Can somebody help me solve this problem?