Extracting array of POINTs from a CRgn
-
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
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, Jonniemodified on Friday, March 6, 2009 10:18 AM
-
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
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.
-
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, Jonniemodified on Friday, March 6, 2009 10:18 AM
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
-
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.
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. -
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.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
-
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
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.
-
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
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
-
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
-
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.
Thanks Jonathan. If I can't figure out a way using the GetRegionData() method, I may well follow up on your suggestion. Greetings, Jonnie
-
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
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