Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Drawing IZOLINES of temperature  (Read 758 times)
0 Members and 1 Guest are viewing this topic.
Offline poonury

Junior Newbie





« Posted 2012-10-29 21:19:22 »

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.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
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?
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #1 - Posted 2012-10-29 21:29:55 »

Hi

Maybe you can compute iso-contours in the fragment shader too.

Offline poonury

Junior Newbie





« Reply #2 - Posted 2012-10-29 21:39:17 »

I tried but i havent neighbour pixels.

When I calculate it without neigbours but by function calculating my color. I tried obtain izo by 10 degrees it doted or all black, or line is to width.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2012-10-29 21:41:03 »

Do it in two passes and you'll have access to neighboring pixels in the second pass. You can't have each pixel depend on what's being put into neighboring pixels or you'll get a paradox. =S

Myomyomyo.
Offline poonury

Junior Newbie





« Reply #4 - Posted 2012-10-29 21:45:36 »

Hmm i agree with you but how i can write somthing like that?

1  
2  
3  
4  
5  
6  
7  
8  
9  
gl.glVertexAttrib1f(vs_fTempAtribute, (float) t1.getValueInNode( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[0]));
gl.glVertex2d(  Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[0] ).m_position.x,
                Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[0] ).m_position.y);
gl.glVertexAttrib1f(vs_fTempAtribute, (float) t1.getValueInNode( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[1]));
gl.glVertex2d(  Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[1] ).m_position.x,
                Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[1] ).m_position.y);
gl.glVertexAttrib1f(vs_fTempAtribute, (float) t1.getValueInNode( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[2]));
gl.glVertex2d(  Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[2] ).m_position.x,
               Resources.mesh.getVertex( Resources.mesh.getFace( Resources.mesh.getArea(dAreaCounter).getFaceNr(dFaceCounter) ).m_dwVertex[2] ).m_position.y);


First i put in shader a temperature and it calculate color. Where put second step? On this same vertices? I do not imagine that Sad
Offline theagentd
« Reply #5 - Posted 2012-10-29 22:23:45 »

Render what you're currently doing directly to a texture using a framebuffer object (FBO). That way you'll have the data easily accessible later. Then render (using just a single fullscreen quad) this texture to the screen (back buffer) using a different shader that finds your edges or whatever and adds them to the screen. This is called post-processing a rendered image and is pretty much what you're doing on the CPU right now, am I right?

Myomyomyo.
Offline poonury

Junior Newbie





« Reply #6 - Posted 2012-10-29 22:34:43 »

In the code is not as easy as in theory ;( I can't imagine how ... I need to sleep mayby tomorrow will be better.
Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #7 - Posted 2012-10-30 00:56:42 »

You can use FBObject to implement theagentd's suggestion.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (91 views)
2013-05-17 21:29:12

alaslipknot (100 views)
2013-05-16 21:24:48

gouessej (130 views)
2013-05-16 00:53:38

gouessej (125 views)
2013-05-16 00:17:58

theagentd (136 views)
2013-05-15 15:01:13

theagentd (123 views)
2013-05-15 15:00:54

StreetDoggy (165 views)
2013-05-14 15:56:26

kutucuk (187 views)
2013-05-12 17:10:36

kutucuk (190 views)
2013-05-12 15:36:09

UnluckyDevil (196 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.217 seconds with 21 queries.