NgonBase Class Reference

#include <lib_ngon.h>

Public Member Functions

Bool CopyTo (NgonBase *dst)
 
Bool Write (HyperFile *hf)
 
Bool Read (HyperFile *hf, Int32 id, Int32 level)
 
Bool Translate (VariableChanged *vc)
 
Bool Changed (PolygonObject *op)
 
UChar GetEdgeStates (Int32 id) const
 
Int32 GetCount () const
 
PgonGetNgons ()
 
Bool Resize (Int32 cnt)
 
Int32 FindPolygon (Int32 id, Int32 l=-1) const
 
Bool CompactPgons ()
 
void CheckPoints (PolygonObject *op)
 
void UpdateNgons (PolygonObject *op)
 
Bool ResetPoints (PolygonObject *op)
 
void SetFlags (Int32 flgs)
 
Int32 GetFlags () const
 
Int32 GetDirtyCount () const
 
void Dirty ()
 
void InitMap ()
 
void FreeMap ()
 
Bool Remove (Int32 id, Bool force)
 
Bool ToSelect (BaseSelect *pSelect, Int32 mode)
 
void GetCenter (Int32 id, const CPolygon *vadr, const Vector *padr, Vector *ip, Vector *in)
 
Bool RemapEdge (Int32 oedge, Int32 *nedges, Int32 ncnt)
 
Bool Create (UInt32 *nedges, Int32 ncnt)
 
Bool RemapPolygon (Int32 oply, Int32 nply)
 
Bool Copy (Pgon *src, Pgon *dst)
 
Bool Validate (PolygonObject *op)
 
Bool IsValidNgon (Pgon *pgon, const CPolygon *vadr)
 
Int32 BuildNgon (Int32 *inner, Int32 *outer, Int32 icnt, Int32 ocnt, const CPolygon *vadr, const Vector *padr)
 
Int32 BuildNgonFromPolys (Int32 *polys, Int32 *outer, Int32 pcnt, Int32 ocnt, const CPolygon *vadr, const Vector *padr)
 
Bool Verify (const CPolygon *vadr, Int32 vcnt, UInt32 flags, Pgon *pgon=nullptr)
 
PgonAllocNgon (Int32 edge_cnt)
 
void FreeNgon (Pgon *&pgon)
 
Bool SetNgon (Int32 index, Pgon *src)
 
Bool SetNgon (Int32 index, UInt32 *edges, Int32 edge_cnt)
 

Static Public Member Functions

static NgonBaseAlloc ()
 
static void Free (NgonBase *&p)
 

Private Member Functions

 NgonBase ()
 
 ~NgonBase ()
 

Private Attributes

NgonCache * m_pNgonBase
 

Friends

class ModelingKernelBase
 

Constructor & Destructor Documentation

◆ NgonBase()

NgonBase ( )
private

◆ ~NgonBase()

~NgonBase ( )
private

Member Function Documentation

◆ Alloc()

static NgonBase* Alloc ( )
static

Allocates a N-gon base instance. Destroy the allocated N-gon base instance with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Note
Normally this function is not needed, since the PolygonObject manages its own NgonBase.
Returns
The allocated N-gon base instance, or nullptr if the allocation failed.

◆ Free()

static void Free ( NgonBase *&  p)
static

Destructs N-gon base instances allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]pThe N-gon base instance to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ CopyTo()

Bool CopyTo ( NgonBase dst)

Copies the N-gon data to another NgonBase.

Parameters
[in]dstThe destination N-gon base.
Returns
true if successful, otherwise false.

◆ Write()

Bool Write ( HyperFile hf)

Private.

◆ Read()

Bool Read ( HyperFile hf,
Int32  id,
Int32  level 
)

Private.

◆ Translate()

Bool Translate ( VariableChanged vc)

Private.

◆ Changed()

Bool Changed ( PolygonObject op)

Private.

◆ GetEdgeStates()

UChar GetEdgeStates ( Int32  id) const

Retrieves the edge states for the polygon id.
.

Parameters
[in]idA polygon ID.
Returns
The edge state flags: PGONEDGE

◆ GetCount()

Int32 GetCount ( ) const

Retrieves the number of N-gons.

Returns
The N-gon count.

◆ GetNgons()

Pgon* GetNgons ( )

Retrieves the array of Pgon data.

Returns
The N-gon array.

◆ Resize()

Bool Resize ( Int32  cnt)

Resizes the Pgon data array.

Parameters
[in]cntThe new N-gon count.
Returns
true if successful, otherwise false.

◆ FindPolygon()

Int32 FindPolygon ( Int32  id,
Int32  l = -1 
) const

Searches for polygon index id in all N-gons.

Parameters
[in]idA polygon ID.
[in]lPrivate.
Returns
The found N-gon id, or NOTOK if the polygon was not found in any N-gon.

◆ CompactPgons()

Bool CompactPgons ( )

Compacts the Pgon array, removing any dead (empty) Pgon.

Returns
true if successful, otherwise false.

◆ CheckPoints()

void CheckPoints ( PolygonObject op)

Checks the point of polygon object op to see if any N-gons need updating, e.g. if the point coordinates were changed from any N-gon.
Usually this should be managed manually. This function is normally used for backwards compatibility with older code that does not change N-gons (e.g. XL7, R8 plugins).

See also
UpdateNgons() because this can change the object if an update is needed.
Parameters
[in]opA polygon object. The caller owns the pointed object.

◆ UpdateNgons()

void UpdateNgons ( PolygonObject op)

Updates any dirty N-gons.
This changes the polygon object and retriangulates any N-gons that need updating. If CheckPoints() is called then this does not need to be called, since it is called if any changes were made.

Parameters
[in]opA polygon object. The caller owns the pointed object.

◆ ResetPoints()

Bool ResetPoints ( PolygonObject op)

Resets the internal tracking data for the N-gons for the current point coordinates.

Parameters
[in]opA polygon object. The caller owns the pointed object.
Returns
true if successful, otherwise false.

◆ SetFlags()

void SetFlags ( Int32  flgs)

Sets the flags.

Note
Generally the forced "ignore" for the internal checks are used if modifying the N-gon data and needing to call functions that send changed messages to the object, such as adding a tag or resizing the object.
They are mainly a time saver since running N-gon checks takes time.
Parameters
[in]flgsThe new flags: NGON_FLAG

◆ GetFlags()

Int32 GetFlags ( ) const

Gets the flags.

Returns
The current flags: NGON_FLAG

◆ GetDirtyCount()

Int32 GetDirtyCount ( ) const

Retrieves the dirty count.

Returns
The dirty count.

◆ Dirty()

void Dirty ( )

Makes the internal N-gon tables dirty. Usually this is not needed and InitMap() should be called once changes are completed to update the N-gon tables.

◆ InitMap()

void InitMap ( )

Forces the internal N-gon table data to be rebuilt. This must be called if any changes are made to the N-gon data.
This should always be called before any update message is sent to the polygon object when changes are completed.

◆ FreeMap()

void FreeMap ( )

Private.

◆ Remove()

Bool Remove ( Int32  id,
Bool  force 
)

Removes the n-gon id from the array.

Parameters
[in]idThe ID of the N-gon to remove.
[in]forceIf true then CompactPgons() is called. Usually it is faster to remove the N-gons then compact the array at the end.
Returns
true if successful, otherwise false.

◆ ToSelect()

Bool ToSelect ( BaseSelect pSelect,
Int32  mode 
)

Generates a BaseSelect containing information about the N-gons.

Parameters
[out]pSelectThe selection to fill. The caller owns the pointed selection.
[in]modeThe mode: NGON_TOSELECTION
Returns
true if successful, otherwise false.

◆ GetCenter()

void GetCenter ( Int32  id,
const CPolygon vadr,
const Vector padr,
Vector ip,
Vector in 
)

Gets the center of the N-gon id.

Parameters
[in]idAn N-gon ID.
[in]vadrThe polygons array. The caller owns the pointed array.
[in]padrThe points array. The caller owns the pointed array.
[out]ipAssigned the center point.
[out]inAssigned the normal vector.

◆ RemapEdge()

Bool RemapEdge ( Int32  oedge,
Int32 nedges,
Int32  ncnt 
)

Private.

◆ Create()

Bool Create ( UInt32 nedges,
Int32  ncnt 
)

Create a new N-gon (appends to the N-gon array) from the edge array passed. Set the marker bits for the segment end and no edges.

Parameters
[in]nedgesThe new edge array. The caller owns the pointed array.
[in]ncntThe edge array size.
Returns
true if successful, otherwise false.

◆ RemapPolygon()

Bool RemapPolygon ( Int32  oply,
Int32  nply 
)

Searches the N-gons for oply and remaps this to nply.

Parameters
[in]oplyThe old polygon ID.
[in]nplyThe new polygon ID.
Returns
true if successful, otherwise false.

◆ Copy()

Bool Copy ( Pgon src,
Pgon dst 
)

Copes a Pgon.

Note
The memory allocation for the Pgon objects uses its own internal memory manager and cannot be allocated using the Cinema 4D memory allocation calls. The function will fail if dst is not within the allocated space of the NgonBase.
Parameters
[in]srcThe source Pgon. The caller owns the pointed Pgon.
[in]dstThe destination Pgon. The caller owns the pointed Pgon.
Returns
true if successful, otherwise false.

◆ Validate()

Bool Validate ( PolygonObject op)

Checks if the N-gons are valid. If they are not then any invalid ones are removed.

Note
Usually not needed. This function is used internally to check for N-gons that get damaged if the polygons are modified without updating the N-gons.
Parameters
[in]opA polygon object. The caller owns the pointed polygon object.
Returns
true if successful, otherwise false.

◆ IsValidNgon()

Bool IsValidNgon ( Pgon pgon,
const CPolygon vadr 
)

Runs a simple sanity check on the N-gon passed to check if its points link together consistently.

Parameters
[in]pgonThe polygon array. The caller owns the pointed array.
[in]vadrThe points array. The caller owns the pointed array.
Returns
The N-gon to validate.

◆ BuildNgon()

Int32 BuildNgon ( Int32 inner,
Int32 outer,
Int32  icnt,
Int32  ocnt,
const CPolygon vadr,
const Vector padr 
)

Helper function to build an N-gon from a list of edges.
The arrays inner and outer can be nullptr, but not both of them at the same time.

Parameters
[in]innerAn array of internal (hidden) edges indices. The caller owns the pointed array.
If only this is specified the function finds the main outline itself based on the hidden edges, this will also include any holes in the N-gon.
[in]outerAn array of the outline of the N-gon. Use the internal mark (PGONEDGE_ENDSEGMENT) to mark segments in the N-gon outline. The caller owns the pointed array.
[in]icntThe size of the inner array.
[in]ocntThe size of the outer array.
[out]vadrThe polygons array. The caller owns the pointed array.
[out]padrThe points array. The caller owns the pointed array.
Returns
The index of the added N-gon, or NOTOK if the operation failed.

◆ BuildNgonFromPolys()

Int32 BuildNgonFromPolys ( Int32 polys,
Int32 outer,
Int32  pcnt,
Int32  ocnt,
const CPolygon vadr,
const Vector padr 
)

Helper function to build an N-gon from a list of polygons and outer edges.

Parameters
[in]polysAn array of polygons that form the N-gon.
[in]outerAn array of the outline of the N-gon. The caller owns the pointed array.
Use the internal mark (PGONEDGE_ENDSEGMENT) to mark segments in the N-gon outline.
[in]pcntThe size of the polys array.
[in]ocntThe size of the outer array.
[in]vadrThe polygons array. The caller owns the pointed array.
[in]padrThe points array. The caller owns the pointed array.
Returns
The index of the added N-gon, or NOTOK if the operation failed.

◆ Verify()

Bool Verify ( const CPolygon vadr,
Int32  vcnt,
UInt32  flags,
Pgon pgon = nullptr 
)

Verifies N-gons.

Parameters
[in]vadrA pointer to the polygon array. This can be obtained with PolygonObject::GetPolygonR(). The caller owns the pointed array.
[in]vcntThe total number of polygons in the polygon array. This can be obtained with PolygonObject::GetPolygonCount().
[in]flagsThe flags: NGON_VERIFY_FLAG
[in]pgonA pointer to a N-gon to verify it or nullptr to verify all N-gons.
Returns
true if N-gons are valid, false if there are illegal N-gons.

◆ AllocNgon()

Pgon* AllocNgon ( Int32  edge_cnt)

Allocates an N-gon. Destroy the allocated N-gon with FreeNgon().

Parameters
[in]edge_cntThe number of edges of the N-gon.
Returns
The allocated N-gon, or nullptr if the allocation failed.

◆ FreeNgon()

void FreeNgon ( Pgon *&  pgon)

Destructs N-gons allocated with AllocNgon().

Parameters
[in,out]pgonThe N-gon to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ SetNgon() [1/2]

Bool SetNgon ( Int32  index,
Pgon src 
)

Sets the N-gon specified by index to src.

Parameters
[in]indexThe index of the N-gon to set.
[in]srcThe new N-gon data.
Returns
true if successful, otherwise false.

◆ SetNgon() [2/2]

Bool SetNgon ( Int32  index,
UInt32 edges,
Int32  edge_cnt 
)

Sets the N-gon specified by index and the edge array edges.

Parameters
[in]indexThe index of the N-gon to set.
[in]edgesThe pointer to the edges array. The caller owns the pointed array.
[in]edge_cntThe number of edges, size of the edges array.
Returns
true if successful, otherwise false.

Friends And Related Function Documentation

◆ ModelingKernelBase

friend class ModelingKernelBase
friend

Member Data Documentation

◆ m_pNgonBase

NgonCache* m_pNgonBase
private