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. C / C++ / MFC
  4. Extracting array of POINTs from a CRgn

Extracting array of POINTs from a CRgn

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
12 Posts 5 Posters 0 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.
  • J Offline
    J Offline
    Jonnie White
    wrote on last edited by
    #1

    Dear fellow programmers! I would like to retrieve an array of POINTs describing the edge of a existing region. There is a CRgn function CreatePolygonRgn() which takes an array of POINTs and creates a CRgn. Is there a function to retrieve the POINTs again? Please help: I've used up at least a whole redwood on google searches. Thanks, Jonnie

    E L J S 4 Replies Last reply
    0
    • J Jonnie White

      Dear fellow programmers! I would like to retrieve an array of POINTs describing the edge of a existing region. There is a CRgn function CreatePolygonRgn() which takes an array of POINTs and creates a CRgn. Is there a function to retrieve the POINTs again? Please help: I've used up at least a whole redwood on google searches. Thanks, Jonnie

      E Offline
      E Offline
      Eytukan
      wrote on last edited by
      #2

      My guess:

      CRgn::GetRegionData->RGNDATA->RGNDATAHEADER

      You can get the points from rcbound from the below structure

      typedef struct _RGNDATAHEADER {
      DWORD dwSize;
      DWORD iType;
      DWORD nCount;
      DWORD nRgnSize;
      RECT rcBound;
      } RGNDATAHEADER, *PRGNDATAHEADER;

      MSDN[^] ADDED: oops, there's a better function: CRgn::GetRgnBox[^]

      He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

      J 1 Reply Last reply
      0
      • E Eytukan

        My guess:

        CRgn::GetRegionData->RGNDATA->RGNDATAHEADER

        You can get the points from rcbound from the below structure

        typedef struct _RGNDATAHEADER {
        DWORD dwSize;
        DWORD iType;
        DWORD nCount;
        DWORD nRgnSize;
        RECT rcBound;
        } RGNDATAHEADER, *PRGNDATAHEADER;

        MSDN[^] ADDED: oops, there's a better function: CRgn::GetRgnBox[^]

        He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

        J Offline
        J Offline
        Jonnie White
        wrote on last edited by
        #3

        Thank you VuNic for the quick reply. If my CRgn is not a rectangle, however, this will not solve my problem. I suppose I could navigate through all RECTs in the RGNDATA struct, creating one POINT for each corner. However, 1) I was hoping there was a function which does this for me and 2) I suspect it is not as easy as it sounds (what if it's a complex region?). So, I am still hoping for a solution, e.g. a GetPointsFromRegion(CRgn* pRgn, POINT* pPoints, BYTE* pTypes, int& nCount) function. Greetings, Jonnie

        modified on Friday, March 6, 2009 10:18 AM

        E 1 Reply Last reply
        0
        • J Jonnie White

          Dear fellow programmers! I would like to retrieve an array of POINTs describing the edge of a existing region. There is a CRgn function CreatePolygonRgn() which takes an array of POINTs and creates a CRgn. Is there a function to retrieve the POINTs again? Please help: I've used up at least a whole redwood on google searches. Thanks, Jonnie

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

          GetRegionData() can give you RECT structures that CRgn consists of as well as a bounding rectangle. CRgn does not consist of points so you can retrieve them only by taking them from RECT structures, and not retrieving those you've passed to CreatePolygonRgn(). To get points is not possible because if you have points (0,1) (0,3) (0,4) the line (0,1)-(0,4) would be the edge of the region but (0,3) would be lost. To get edging points from RECT structures is trivial but they do not have to match what you've passed to CreatePolygonRgn() at all.

          J 1 Reply Last reply
          0
          • J Jonnie White

            Thank you VuNic for the quick reply. If my CRgn is not a rectangle, however, this will not solve my problem. I suppose I could navigate through all RECTs in the RGNDATA struct, creating one POINT for each corner. However, 1) I was hoping there was a function which does this for me and 2) I suspect it is not as easy as it sounds (what if it's a complex region?). So, I am still hoping for a solution, e.g. a GetPointsFromRegion(CRgn* pRgn, POINT* pPoints, BYTE* pTypes, int& nCount) function. Greetings, Jonnie

            modified on Friday, March 6, 2009 10:18 AM

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            I found these "keywords" //--- copy points to original structure --- ::CopyMemory((LPBYTE)dwOffsetAddr, lpPointsFx, nPtBufSize); Here: http://www.codeproject.com/KB/graphics/TTPolygon.aspx?display=PrintAll[^] You may check that one. I'm not very sure though.

            He never answers anyone who replies to him. I've taken to calling him a retard, which is not fair to retards everywhere.-Christian Graus

            1 Reply Last reply
            0
            • L Lost User

              GetRegionData() can give you RECT structures that CRgn consists of as well as a bounding rectangle. CRgn does not consist of points so you can retrieve them only by taking them from RECT structures, and not retrieving those you've passed to CreatePolygonRgn(). To get points is not possible because if you have points (0,1) (0,3) (0,4) the line (0,1)-(0,4) would be the edge of the region but (0,3) would be lost. To get edging points from RECT structures is trivial but they do not have to match what you've passed to CreatePolygonRgn() at all.

              J Offline
              J Offline
              Jonnie White
              wrote on last edited by
              #6

              Thanks for the clear explanation Aleksandar. I will try implementing my own GetPointsFromRegion() function using the RECT structures. Greetings, Jonnie p.s. I'm surprised this isn't implemented in the CDC or CRgn classes though.

              L 1 Reply Last reply
              0
              • J Jonnie White

                Thanks for the clear explanation Aleksandar. I will try implementing my own GetPointsFromRegion() function using the RECT structures. Greetings, Jonnie p.s. I'm surprised this isn't implemented in the CDC or CRgn classes though.

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

                CRgn does not have to be rectangular, if it has rounded corners or is elliptical, the edge points do not have too much sense to be extracted the same way it is the case for those rectangular. However, the math definition of region is then quite puzzling :). A square that can be a circle :) Since we have GetRegionData for rectangular one, getting points from it is really not a problem. Why didn't they make a function for points? The points are not sufficient to define a way a region is really drawn. We could ask why they didn't make a function to extract edges then the same way. Both points and edges and more can be easily obtained from RECT structures.

                modified on Friday, March 6, 2009 12:12 PM

                J 1 Reply Last reply
                0
                • J Jonnie White

                  Dear fellow programmers! I would like to retrieve an array of POINTs describing the edge of a existing region. There is a CRgn function CreatePolygonRgn() which takes an array of POINTs and creates a CRgn. Is there a function to retrieve the POINTs again? Please help: I've used up at least a whole redwood on google searches. Thanks, Jonnie

                  J Offline
                  J Offline
                  Jonathan Davies
                  wrote on last edited by
                  #8

                  If CRgn is actually a number of rectangles, perhaps the nearest you will get is to use FrameRgn to draw a border round the region (or a off-screen copy of the region) in some colour. Then look for something to give you the all pixels/points of that colour starting from a point on the region.

                  J 1 Reply Last reply
                  0
                  • L Lost User

                    CRgn does not have to be rectangular, if it has rounded corners or is elliptical, the edge points do not have too much sense to be extracted the same way it is the case for those rectangular. However, the math definition of region is then quite puzzling :). A square that can be a circle :) Since we have GetRegionData for rectangular one, getting points from it is really not a problem. Why didn't they make a function for points? The points are not sufficient to define a way a region is really drawn. We could ask why they didn't make a function to extract edges then the same way. Both points and edges and more can be easily obtained from RECT structures.

                    modified on Friday, March 6, 2009 12:12 PM

                    J Offline
                    J Offline
                    Jonnie White
                    wrote on last edited by
                    #9

                    Well - calculating the edge of the region from the RECTs is proving not quite so trivial (imagine a region in the shape of a rainbow or a four leaf clover ;-)). The RECTs are ordered top to bottom, left to right. The algorithm to figure that out is more than I can manage tonight. I'll be back, as the Austrians say. Jonnie

                    L 1 Reply Last reply
                    0
                    • J Jonnie White

                      Well - calculating the edge of the region from the RECTs is proving not quite so trivial (imagine a region in the shape of a rainbow or a four leaf clover ;-)). The RECTs are ordered top to bottom, left to right. The algorithm to figure that out is more than I can manage tonight. I'll be back, as the Austrians say. Jonnie

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

                      Neither is getting precise all edge points from a mixed rounded or elliptical region :) Maybe Egyptian 22/7 might help there, if a circle is small enough :)

                      1 Reply Last reply
                      0
                      • J Jonathan Davies

                        If CRgn is actually a number of rectangles, perhaps the nearest you will get is to use FrameRgn to draw a border round the region (or a off-screen copy of the region) in some colour. Then look for something to give you the all pixels/points of that colour starting from a point on the region.

                        J Offline
                        J Offline
                        Jonnie White
                        wrote on last edited by
                        #11

                        Thanks Jonathan. If I can't figure out a way using the GetRegionData() method, I may well follow up on your suggestion. Greetings, Jonnie

                        1 Reply Last reply
                        0
                        • J Jonnie White

                          Dear fellow programmers! I would like to retrieve an array of POINTs describing the edge of a existing region. There is a CRgn function CreatePolygonRgn() which takes an array of POINTs and creates a CRgn. Is there a function to retrieve the POINTs again? Please help: I've used up at least a whole redwood on google searches. Thanks, Jonnie

                          S Offline
                          S Offline
                          Stuart Dootson
                          wrote on last edited by
                          #12

                          CRgn has the GetRgnBox method, which gives you the bounding box of the region. Iterate over all the points in the bounding box, calling the PtInRegion for each. The points which return true are in the region, so add them to a list of the points in the region. Job done!

                          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                          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