Archicad C++ API
About Archicad add-on development using the C++ API.

PGPOLYEXT data type

Danny Sparks-Cousins
Contributor
Hi all,

I want to use some of the geometry functions;

Geometry::PGPolyAreaExt
Geometry::PGPolyPositionExt

To find area & polygon position status for two polygons.

I have the 2 polygons as type Polygon2Ddata. Can anyone explain how to convert from Polygon2Ddata to PGPOLYEXT type?

Any ideas would be appreciated.

Cheers,
Danny
5 REPLIES 5
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi Danny,

Here's a short example code for you to convert Polygon2Ddata to PGPOLYEXT:
GSErrCode Convert_Polygon2DData_To_PGPOLYEXT (const Geometry::Polygon2DData& 	polygon2DData, 
																Geometry::PGPOLYEXT*			pgPOLYEXT) 
{ 
	if (&polygon2DData == NULL) 
		return ErrParam; 
 
	BNZeroMemory (pgPOLYEXT, sizeof (Geometry::PGPOLYEXT)); 
 
	// here comes a little bit ugly cast 
	pgPOLYEXT->data = reinterpret_cast<GSPtr> (const_cast<Geometry::Polygon2DData*> (&polygon2DData)); 
 
	// Perhaps you need to set some other attributes too: 
	//  pgPOLYEXT->status.isSameDirEdgeLegal = polygon2DData.status.isSameDirEdgeLegal; 
	//  pgPOLYEXT->epsilon = SMALLEPS * 8; 
	//  pgPOLYEXT->minVertexDist = 3 * pgPOLYEXT->epsilon; 
 
	return NoError; 
} 
 
/* --------------- Usage example: -------------------------- */ 
 
Geometry::Polygon2DData 	polygon2DData;
Geometry::PGPOLYEXT 		pgPOLYEXT;
 
Convert_Polygon2DData_To_PGPOLYEXT (polygon2DData, &pgPOLYEXT);


Sorry, I've never tried that, but it seems correct.

Regards,
Tibi
Danny Sparks-Cousins
Contributor
Excellent - thanks Tibor
Danny Sparks-Cousins
Contributor
OK - I havent quite got my head around how to use the PGPOLYEXT data and functions.

I have a need to perform some operations on two existing zones - from the documentation it looks like the following functions would work well for what I need;

PGPolyUnionExt to combine two different zone polygons
PGPolyIntersectionExt to intersect two different zone polygons
PGCoordInPolyExt to check if a point is within a zone polygon
PGPolyAreaExt to calculate the area of the PGPoly results

I am having trouble doing anything with PGPOLYEXT data at all though. I tried Tibor's example to convert a simple Polygon2DData to PGPOLYEXT but still couldnt get actual results even from PGPolyAreaExt.

Am I on the right track in using this data type and these functions for what I want to achieve with the zone polygon data? If anyone has some thoughts and ideas to step me through that would be greatly appreciated - or even some very simple example using polygon data and PGPOLYEXT data functions?

Thanks,
Danny
Danny Sparks-Cousins
Contributor
Bump.

Does anyone have any thoughts about this, or used the PGPOLYEXT functions?
Tibor Lorantfy
Graphisoft Alumni
Graphisoft Alumni
Hi,

if you want to get the area from your Polygon2DData, you don't have to convert it! Sorry if I was misleading.

You can use the following function:
double Geometry::GetPolygon2DDataArea (const Polygon2DData& polygon2DData, bool isPolyLine = false);
For example:
double area = Geometry::GetPolygon2DDataArea (myPolygon2DData);
To find more geometry functions with Polygon2DData see the Polygon2DData.h header file in the DevKit's Support\Modules\Geometry\ folder.

Regards,
Tibi