logic operation in boost polygon

Help!
I wrote this function to load the data point to a boost polygon.
typedef vector<polygon_data<int> > LayoutSet;
static void addPolygonData(LayoutSet &sets,int* points,int size){
polygon_data<int> poly_data;
vector<point_data<int> > poly_points(size);
for(int i=0;i<size;i++)
{
int x=i*2;
int y=x+1;
poly_points[i]=point_data<int>(points[x],points[y]);
}
poly_data.set(poly_points.begin(),poly_points.end());
sets.push_back(poly_data);
}
Then I load two sets of points
int p1[8]={1200 2400 1200 3600 4000 3600 4000 2400};
int p2[8]={1800 600 1800 4700 3500 4700 3500 600};
LayoutSet group_2;
LayoutSet group_1;
addPolygonData(group_1,p1,8);
addPolygonData(group_1,p2,8);
boost::polygon::assign(group_2,group_1[0] & group_1[1]); // Here I do the
logic operation & (AND)
vector<point_data<int> > pts;
pts.insert(pts.begin(),group_2[0].begin(),group[0].end());
for(size_t i=0;i

HxH wrote:
Help! I wrote this function to load the data point to a boost polygon.
typedef vector<polygon_data<int> > LayoutSet; static void addPolygonData(LayoutSet &sets,int* points,int size){ polygon_data<int> poly_data; vector<point_data<int> > poly_points(size); for(int i=0;i<size;i++) { int x=i*2; int y=x+1;
poly_points[i]=point_data<int>(points[x],points[y]); } poly_data.set(poly_points.begin(),poly_points.end()); sets.push_back(poly_data); } Then I load two sets of points int p1[8]={1200 2400 1200 3600 4000 3600 4000 2400}; int p2[8]={1800 600 1800 4700 3500 4700 3500 600}; LayoutSet group_2; LayoutSet group_1; addPolygonData(group_1,p1,8); addPolygonData(group_1,p2,8); boost::polygon::assign(group_2,group_1[0] & group_1[1]); // Here I do the logic operation & (AND)
vector<point_data<int> > pts; pts.insert(pts.begin(),group_2[0].begin(),group[0].end());
for(size_t i=0;i
Here is the result I get:
6484944,0 3500,600 3500,3600 1800,3600 1800,600 3,1 0,0 6484944,0
It doesn't look correct. It gives me a hard time to fix it. Any suggestions are welcome!!
You are passing 8 into the addPolygonData, but you should pass 4 instead. Inside the loop implemented in addPolygonData you iterate i from 0 to size and multiply i by 2 to index into the array. You are indexing past the end of the array and the polygons you passed to the AND operation contain arbitrary data, which is showing up in the result it seems. Boost.Polygon places no pre-conditions on input polygons. It views input data as a polygon using the positive winding rule and determines the winding based on whichever winding results in a positive area. I don't know what the arbitrary data passed to the AND operation was exactly, but I suspect that the output polygon is actually correct for the given input. I hope that helps! Regards, Luke

Thank you so much ! It helps me a lot. However, if I do an AND operation with two polygons that don't overlap each other, I will get segmentation fault. Originally I thought it would return all 0 to represent the empty set. I am trying to use the contains function to fix this problem but it seems like I have to get the points back from one of the polygon. Do you have any better suggestions? Thank you for your helps !! -- View this message in context: http://boost.2283326.n4.nabble.com/logic-operation-in-boost-polygon-tp351236... Sent from the Boost - Users mailing list archive at Nabble.com.

Hi! I'll first appologize if I don't perfect english expression, cause I'm a french guy. In fact i start using Boost since one week. I discover that the library has excellent features. I've a project wich is to create a SIP-like Voici Over IP(VOIP) protocol. The protocol must be a client/server protocol but voice transport must be client to client. Client to client communication must use UDP and client to server comunication must use TCP. The protocol is a binary protocol and not a text one. For the client side I'm asked to use QTNetwork and for the server i have to use Boost.Asio. I look for Boost tutorial and test several things. I'ave already develop the client side and clients can communicate each other via QT sockets. I also tested boost client and server and it works. But now i want to really set up my whole application. However when i try to establish a connxion between my client and my server, the connexion succeed, but neither client nor server can receive data from each other. For the test i put the client in a linux environnment (Fedora std) and the server is running on Windows where i use Visual studio to develop. I don't know if the problem comes from the difference between server and client OS. Then I'll will try to put both client and server in the same OS. But my application has to be portable and to run on linux and windows. Then my questions please, are the following: - How can I better do in order to make my client developped with QT, to communicate with my server developped with Boost.Asio? Do you guy ever encounter this issue? It's my first time to use Boost, and I don't know if there could be an incompatibility. - To transmit data, I set up a serializor/deserialazor, wich build a pakect (an object class) containing a header and a type of data(voice, video or text) to be sent over the network, and at the oder side we use the deserializor to acceess data in the packet. My send and receive functions should not know what is inside the packet, that should be a black box for them, and they have just to send and receive packets. The serializor/deserializor does the rest for the application. Client to client converxsation is done directely (DCC) but for the conference mode, the server should manage communication between clients in he conference(in a rom). Then please, i would like to know the best way in my server side where i'm using boost, to handle conference and multiple clients conferences. Which boost::tco socket fucntions are better to use regarding the situation? - Can you please give some advises to best way to realise my project using QT(client side) and Boost(server side) together? I'll would be really pleased if I had a example of tutorial about developping a boost TCP server which can manage multi clients connexion without care on which network library they are using. Thank a lot for your attention and your help.

HxH wrote:
Thank you so much ! It helps me a lot. However, if I do an AND operation with two polygons that don't overlap each other, I will get segmentation fault. Originally I thought it would return all 0 to represent the empty set. I am trying to use the contains function to fix this problem but it seems like I have to get the points back from one of the polygon. Do you have any better suggestions?
Thank you for your helps !!
pts.insert(pts.begin(),group_2[0].begin(),group[0].end());
If the result of the AND is empty the output vector of polygons is left empty. You are indexing into the empty vector group_2, which causes the segmentation fault.
pts.insert(pts.begin(),group_2[0].begin(),group[0].end());
I believe it will be faster for you to debug such problems yourself rather than ask the list. Regards, Luke
participants (3)
-
eugene ngontang
-
HxH
-
Simonson, Lucanus J