Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. Boundary Fill function assistance needed [modified]

Boundary Fill function assistance needed [modified]

Scheduled Pinned Locked Moved Graphics
helpquestion
6 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 3375334
    wrote on last edited by
    #1

    Hello, i am trying to implement boudary function but i am trying to run it .. it just crashes on me with no reason...what am i doing wrong? i think there is a problem with getPixel part... please help

    void CtestopenglView::setPixel(GLint x, GLint y)
    {
    glBegin(GL_POINTS);
    glVertex2d(x, y);
    glEnd();
    }

    void CtestopenglView::getPixel(GLint x ,GLint y, GLint &color)
    {
    glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &color);
    }

    void CtestopenglView::boundFill(int x, int y, int fillColor, int borderColor)
    {
    int interiorColor;
    getPixel (x, y, interiorColor);
    if ((interiorColor != borderColor) && (interiorColor!= fillColor))
    {
    setPixel(x,y);
    boundFill(x + 1, y, fillColor, borderColor);
    boundFill(x - 1, y, fillColor, borderColor);
    boundFill(x, y + 1, fillColor, borderColor);
    boundFill(x, y - 1, fillColor, borderColor);
    }
    glFlush();
    }

    thank you

    modified on Thursday, March 5, 2009 11:41 PM

    T L S 3 Replies Last reply
    0
    • M Member 3375334

      Hello, i am trying to implement boudary function but i am trying to run it .. it just crashes on me with no reason...what am i doing wrong? i think there is a problem with getPixel part... please help

      void CtestopenglView::setPixel(GLint x, GLint y)
      {
      glBegin(GL_POINTS);
      glVertex2d(x, y);
      glEnd();
      }

      void CtestopenglView::getPixel(GLint x ,GLint y, GLint &color)
      {
      glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &color);
      }

      void CtestopenglView::boundFill(int x, int y, int fillColor, int borderColor)
      {
      int interiorColor;
      getPixel (x, y, interiorColor);
      if ((interiorColor != borderColor) && (interiorColor!= fillColor))
      {
      setPixel(x,y);
      boundFill(x + 1, y, fillColor, borderColor);
      boundFill(x - 1, y, fillColor, borderColor);
      boundFill(x, y + 1, fillColor, borderColor);
      boundFill(x, y - 1, fillColor, borderColor);
      }
      glFlush();
      }

      thank you

      modified on Thursday, March 5, 2009 11:41 PM

      T Offline
      T Offline
      Tim Craig
      wrote on last edited by
      #2

      Are you sure boundFill actually terminates properly. If it doesn't, you'll wind up the stack and crash or eventually hit the edge of the image and crash.

      "Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke

      M 1 Reply Last reply
      0
      • T Tim Craig

        Are you sure boundFill actually terminates properly. If it doesn't, you'll wind up the stack and crash or eventually hit the edge of the image and crash.

        "Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke

        M Offline
        M Offline
        Member 3375334
        wrote on last edited by
        #3

        when i tried running it ... it did crash i know there is a way to fill in the polygon using something like poligonmode... but i am not sure how to use that correctly.. what i am doing is using GL_LINES to draw a polygon and then need to fill it in. how can i do that if not based on that function or what changes should i make to the function itself.

        T 1 Reply Last reply
        0
        • M Member 3375334

          when i tried running it ... it did crash i know there is a way to fill in the polygon using something like poligonmode... but i am not sure how to use that correctly.. what i am doing is using GL_LINES to draw a polygon and then need to fill it in. how can i do that if not based on that function or what changes should i make to the function itself.

          T Offline
          T Offline
          Tim Craig
          wrote on last edited by
          #4

          If you want a filled polygon, why not just let OpenGL draw it as filled, which is the default. Start with glBegin(GL_POLYGON)...glColor..(), bunch of glVertex..() calls...glEnd(). Just be advised that the polygon has to be convex, it it's not, you need to break it until into as many convex polygons as needed.

          "Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke

          1 Reply Last reply
          0
          • M Member 3375334

            Hello, i am trying to implement boudary function but i am trying to run it .. it just crashes on me with no reason...what am i doing wrong? i think there is a problem with getPixel part... please help

            void CtestopenglView::setPixel(GLint x, GLint y)
            {
            glBegin(GL_POINTS);
            glVertex2d(x, y);
            glEnd();
            }

            void CtestopenglView::getPixel(GLint x ,GLint y, GLint &color)
            {
            glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &color);
            }

            void CtestopenglView::boundFill(int x, int y, int fillColor, int borderColor)
            {
            int interiorColor;
            getPixel (x, y, interiorColor);
            if ((interiorColor != borderColor) && (interiorColor!= fillColor))
            {
            setPixel(x,y);
            boundFill(x + 1, y, fillColor, borderColor);
            boundFill(x - 1, y, fillColor, borderColor);
            boundFill(x, y + 1, fillColor, borderColor);
            boundFill(x, y - 1, fillColor, borderColor);
            }
            glFlush();
            }

            thank you

            modified on Thursday, March 5, 2009 11:41 PM

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Hey, There doesn't seem to be any exit condition if you reach the edge of the image so you will be accessing memory you aren't meant to. Either that or you are overflowing the stack and boom!

            At university studying Software Engineering - if i say this line to girls i find they won't talk to me Dan

            1 Reply Last reply
            0
            • M Member 3375334

              Hello, i am trying to implement boudary function but i am trying to run it .. it just crashes on me with no reason...what am i doing wrong? i think there is a problem with getPixel part... please help

              void CtestopenglView::setPixel(GLint x, GLint y)
              {
              glBegin(GL_POINTS);
              glVertex2d(x, y);
              glEnd();
              }

              void CtestopenglView::getPixel(GLint x ,GLint y, GLint &color)
              {
              glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &color);
              }

              void CtestopenglView::boundFill(int x, int y, int fillColor, int borderColor)
              {
              int interiorColor;
              getPixel (x, y, interiorColor);
              if ((interiorColor != borderColor) && (interiorColor!= fillColor))
              {
              setPixel(x,y);
              boundFill(x + 1, y, fillColor, borderColor);
              boundFill(x - 1, y, fillColor, borderColor);
              boundFill(x, y + 1, fillColor, borderColor);
              boundFill(x, y - 1, fillColor, borderColor);
              }
              glFlush();
              }

              thank you

              modified on Thursday, March 5, 2009 11:41 PM

              S Offline
              S Offline
              supercat9
              wrote on last edited by
              #6

              If you are using recursion as shown, even if you're drawing a bounded shape, the maximum stack depth will be roughly equal to the number of pixels in the area to be filled. For shapes of non-trivial size, that's not going to work. Much better would be to add points to be drawn into a queue and then have a loop which takes a point from the queue, fills it, and queues up any neighbors that need filling. If you use that approach, the number of items in the queue will be limited to approximately twice the larger dimension of the shape you're filling. Performance with that approach won't be great, but it will work. Things may be improved considerably if each queue item is a horizontal line rather than just a point. The code will be more complicated, but if written properly it will run much faster. One caveat is that there won't be any nicely-defined limit on the required queue size. On the other hand, one could design the algorithm so that when the queue is nearly full, queue items that would generate too many more queue items simply get re-queued instead of being processed. Some care would be necessary to prevent 'deadlock' conditions, but I would expect that in practice things shouldn't be too bad.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups