Open Search
    ConvexHull Manual

    About

    The maxon::ConvexHullInterface allows to compute a convex polygon hull that encapsulates a given set of points in 3D space.

    ConvexHullInterface

    The maxon::ConvexHullInterface class provides only one function that can either accept a maxon::ConvexHullData argument or several arrays:

    The maxon::ConvexHullData structure contains these members:

    // This example creates a convex polygon hull around the given array of points.
    // The created polygon data is copied to a PolygonObject.
    // compute convex hull from the given array of points
    if (res < 0)
    return maxon::OK;
    // create the PolygonObject
    const Int32 polyCount = (Int32)hullData.faces.GetCount();
    const Int32 vertexCount = (Int32)hullData.vertices.GetCount();
    PolygonObject* const polyObject = PolygonObject::Alloc(vertexCount, polyCount);
    if (polyObject == nullptr)
    return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
    // set polygons
    CPolygon* const polygons = polyObject->GetPolygonW();
    Int32 polyCounter = 0;
    const maxon::ConvEdge* lastEdge;
    // loop over all faces
    for (Int32 faceIndex = 0; faceIndex < polyCount; faceIndex++)
    {
    const maxon::ConvEdge* currentEdge = &hullData.edges[hullData.faces[faceIndex]];
    lastEdge = currentEdge;
    const Int firstPoint = lastEdge->_start;
    // loop over all edges
    for (currentEdge = &hullData.edges[lastEdge->_nextEdgeOfFace];
    &hullData.edges[currentEdge->_nextEdgeOfFace] != &hullData.edges[hullData.faces[faceIndex]];
    currentEdge = &hullData.edges[currentEdge->_nextEdgeOfFace])
    {
    polygons[polyCounter] = CPolygon((Int32)firstPoint, (Int32)currentEdge->_start, (Int32)currentEdge->_end);
    polyCounter++;
    lastEdge = currentEdge;
    }
    }
    // set point positions
    Vector* const polyPoints = polyObject->GetPointW();
    for (Int32 pointIndex = 0; pointIndex < vertexCount; pointIndex++)
    polyPoints[pointIndex] = hullData.vertices[pointIndex];
    // insert polygon object into the scene
    polyObject->Message(MSG_UPDATE);
    doc->InsertObject(polyObject, nullptr, nullptr);
    Bool Message(Int32 type, void *data=nullptr)
    Definition: c4d_baselist.h:1458
    Vector * GetPointW()
    Definition: c4d_baseobject.h:1593
    Definition: c4d_baseobject.h:1765
    CPolygon * GetPolygonW()
    Definition: c4d_baseobject.h:1912
    static PolygonObject * Alloc(Int32 pcnt, Int32 vcnt)
    MAXON_ATTRIBUTE_FORCE_INLINE Int GetCount() const
    Definition: basearray.h:576
    static MAXON_METHOD Result< Float > ComputeConvexHull(const Block< const Vector > &vertices, Float shrink, Float shrinkClamp, BaseArray< Vector > &resultVertices, BaseArray< ConvEdge > &resultEdges, BaseArray< Int > &resultFaces)
    Py_UCS4 * res
    Definition: unicodeobject.h:1113
    maxon::Int32 Int32
    Definition: ge_sys_math.h:60
    maxon::Int Int
    Definition: ge_sys_math.h:64
    Float64 Float
    Definition: apibase.h:222
    return OK
    Definition: apibase.h:2747
    #define MSG_UPDATE
    Must be sent if the bounding box has to be recalculated. (Otherwise use MSG_CHANGE....
    Definition: c4d_baselist.h:359
    #define MAXON_SOURCE_LOCATION
    Definition: memoryallocationbase.h:67
    const char * doc
    Definition: pyerrors.h:226
    #define iferr_return
    Definition: resultbase.h:1521
    Represents a polygon that can be either a triangle or a quadrangle.
    Definition: c4d_baseobject.h:44
    Definition: convexhull.h:15
    Int _nextEdgeOfFace
    Definition: convexhull.h:21
    Int _end
    Definition: convexhull.h:20
    Int _start
    Definition: convexhull.h:19
    ConvexHullData struct is a datacontainer that represents a convex hull.
    Definition: convexhull.h:32
    BaseArray< Vector > vertices
    Vertex coordinates of the convex hull.
    Definition: convexhull.h:34
    BaseArray< Int > faces
    Faces of the convex hull. Each entry is an index into the "edges" array pointing to an edge of the fa...
    Definition: convexhull.h:40
    BaseArray< ConvEdge > edges
    Edges of the convex hull. For each edge there's also the reverse edge in the array.
    Definition: convexhull.h:37

    Further Reading