Fade2.5D Documentation pages v2.16.7
Delaunay Features
GEOM_FADE25D::PolygonClipper Class Reference

The PolygonClipper class handles polygon repair operations. More...

#include <PolygonClipper.h>

Public Member Functions

 PolygonClipper (const std::vector< Segment2 > &vSegments, double collapseDist)
 Constructs a PolygonClipper object. More...
 
 ~PolygonClipper ()
 Destructor for the PolygonClipper class.
 
void getOuterSegments_CCW (std::vector< Segment2 > &vOuterSegments_CCW) const
 Retrieves the outermost segments of the polygon in counter-clockwise direction. More...
 
PolygonTreegetPolygonTree ()
 Returnes the PolygonTree structure. More...
 
void getSegments_regionOriented (std::vector< Segment2 > &vSegments_regionOriented) const
 Retrieves the inner and outer polygon segments oriented by region. More...
 
void show (const std::string &name, const Color &matColor=Color(CYELLOW, 0, true), const Color airColor=Color(CWHITE, 0, false)) const
 Visualizes the polygon regions as a .PDF or PostScript file. More...
 
void show (Visualizer2 *pVis, const Color &matColor=Color(CYELLOW, 0, true), const Color airColor=Color(CWHITE, 0, false)) const
 Visualizes the polygon regions as a .PDF or PostScript file. More...
 

Detailed Description

The PolygonClipper class handles polygon repair operations.

Left: A damaged poloyon. right: It's repaired result.

This class processes a set of polygon segments. After optionally removing ultra-short segments, it resolves self-intersections and provides methods to retrieve the layers of the repaired polygon.

See also
clipPolygon() A free function to trim an input polygon to a specified domain.

Constructor & Destructor Documentation

◆ PolygonClipper()

GEOM_FADE25D::PolygonClipper::PolygonClipper ( const std::vector< Segment2 > &  vSegments,
double  collapseDist 
)

Constructor: Initializes the clipper with a set of segments representing polygon edges and a collapse distance used to eliminate near-degenerate edges.

Parameters
vSegmentsA vector containing possibly intersecting polygon edges with no specific order or orientation.
collapseDistA threshold distance: Use a positive value to collapse edges shorter than this distance, -1 to automatically determine a tiny value for collapseDist based on the numeric uncertainty of the given coordinates, or 0 to retain all edges.

Member Function Documentation

◆ getOuterSegments_CCW()

void GEOM_FADE25D::PolygonClipper::getOuterSegments_CCW ( std::vector< Segment2 > &  vOuterSegments_CCW) const

This method fills the provided vector with the polygon's outer boundary segments, ordered and oriented in counter-clockwise (CCW) direction around the enclosed area. Segments inside this outer polygon, if any, are ignored.

An input polygon on the left and its outer hull on the right side

Details:

  • The returned polygon is "traversed from the outside", meaning the largest possible polygon is returned, rather than splitting a non-simple polygon into multiple parts.
  • The input polygon may consist of multiple connected components, and in this case, more than one polygon is stored in the output vector. Due to the counterclockwise orientation of the segments, this output is still suitable as input for Fade_2D::createZone(ConstraintGraph2*,ZoneLocation,bool).
  • If you need individual polygons for each connected component, you may retrieve the root node of the PolygonTree using getPolygonTree(), and then query its first-layer children (layer 0), which represent the individual connected components of the outermost layer.
Parameters
vOuterSegments_CCWA vector to be filled with the CCW-oriented outer boundary segments.
See also
C++ example: Polygon repair
C++ example: Analyzing polygon layers

◆ getPolygonTree()

PolygonTree* GEOM_FADE25D::PolygonClipper::getPolygonTree ( )
A nested polygon on the left, and the corresponding PolygonTree on the right

This method returns a pointer to a PolygonTree object. This object represents the root node of the hierarchical PolygonTree structure for the repaired polygon. The structure can be analyzed layer by layer.

Returns
A pointer to the root node of the PolygonTree.

◆ getSegments_regionOriented()

void GEOM_FADE25D::PolygonClipper::getSegments_regionOriented ( std::vector< Segment2 > &  vSegments_regionOriented) const

This method returns all layers of the polygon, oriented in a counter-clockwise direction around their adjacent inside regions. This way, the result is suitable as input for Fade_2D::createConstraint() and for subsequent creation of a Zone2.

An input polygon on the left, and the regions of the repaired polygon on the right
Parameters
vSegments_regionOrientedA vector to be filled with the region-oriented segments.

Key details

  • Even-odd rule: The outermost layer (layer 0) of the polygon defines a transition from empty space to filled area (from 'air' to 'material'), while the subsequent layer (layer 1) indicates holes (a transition back to 'air'). More generally, as we move from outside to inside, the polygon layers signify alternating transitions between air and material. Even layers represent borders from air to material, while odd layers represent borders to holes within that material. Consequently, even layers are oriented counter-clockwise, while odd layers are clockwise.
  • Largest possible shapes: The polygons form the largest possible shapes instead of splitting non-simple polygons into multiple parts.
  • Single output vector: All polygons are stored in the same output vector. Due to their counterclockwise orientation around inside regions, they are suited for Zone2 creation.
  • Individual polygons If you need individual polygons, you can retrieve the root node of the PolygonTree using getPolygonTree() and query it layer-by-layer. Each layer corresponds to one layer of the polygon, from outside to inside.
See also
C++ Example: Correctly creating a Zone2
C++ Example: Repairing a polygon

◆ show() [1/2]

void GEOM_FADE25D::PolygonClipper::show ( const std::string &  name,
const Color matColor = Color(CYELLOW, 0, true),
const Color  airColor = Color(CWHITE, 0, false) 
) const

Generates a visualization of the polygon regions and saves it as a .PDF or PostScript file, depending on the file extension provided.

Parameters
nameThe output filename. Use .pdf or .ps as the file extension.
matColorThe color used for the 'material' regions. Default is yellow.
airColorThe color used for the 'air' regions. Default is white (transparent).

◆ show() [2/2]

void GEOM_FADE25D::PolygonClipper::show ( Visualizer2 pVis,
const Color matColor = Color(CYELLOW, 0, true),
const Color  airColor = Color(CWHITE, 0, false) 
) const

Visualizes the polygon regions using a Visualizer2 object (PDF or PostScript file).

Parameters
pVisA pointer to a Visualizer2 object.
matColorThe color used for the 'material' regions. Default is yellow.
airColorThe color used for the 'air' regions. Default is white (transparent).

The documentation for this class was generated from the following file: