ViewportSelect Class Reference

#include <c4d_basedraw.h>

Detailed Description

This class is used to extract information from a viewport about which objects and object elements are visible at which pixels.
It is used internally for stuff like highlighting and modeling.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Private Member Functions

 ViewportSelect ()
 
 ~ViewportSelect ()
 

Alloc/Free

static ViewportSelectAlloc ()
 
static void Free (ViewportSelect *&p)
 

Pick Object

static Bool PickObject (BaseDraw *bd, BaseDocument *doc, Int32 x, Int32 y, Int32 rad, VIEWPORT_PICK_FLAGS flags, LassoSelection *ls, C4DObjectList *list, maxon::SquareMatrix4d *m=nullptr, Int32 *sampleLocation=nullptr)
 
static Bool PickObject (BaseDraw *bd, BaseDocument *doc, Int32 x, Int32 y, Int32 rad, Int32 &xr, Int32 &yr, Int32 &wr, Int32 &hr, const ViewportPixel *const *&pixels, VIEWPORT_PICK_FLAGS flags, LassoSelection *ls, C4DObjectList *list, maxon::SquareMatrix4d *m=nullptr, Int32 *sampleLocation=nullptr)
 
static Bool PickObject (BaseDraw *bd, BaseDocument *doc, Int32 x1, Int32 y1, Int32 x2, Int32 y2, Int32 &xr, Int32 &yr, Int32 &wr, Int32 &hr, const ViewportPixel *const *&pixels, VIEWPORT_PICK_FLAGS flags, LassoSelection *ls, C4DObjectList *list, maxon::SquareMatrix4d *m=nullptr, Int32 *sampleLocation=nullptr)
 

Show Hotspot

static void ShowHotspot (EditorWindow *bw, Int32 x, Int32 y, Int32 rad, Bool bRemove)
 
void ShowHotspot (EditorWindow *bw, Int32 x, Int32 y)
 
void SetBrushRadius (Int32 r)
 

Initialization

Bool Init (Int32 w, Int32 h, BaseDraw *bd, BaseObject *op, Int32 mode, Bool onlyvisible, VIEWPORTSELECTFLAGS flags=VIEWPORTSELECTFLAGS::NONE)
 
Bool Init (Int32 w, Int32 h, BaseDraw *bd, AtomArray *ar, Int32 mode, Bool onlyvisible, VIEWPORTSELECTFLAGS flags=VIEWPORTSELECTFLAGS::NONE)
 

Get Point/Polygon/Edge Viewport Pixel

const ViewportPixelGetPixelInfoPoint (Int32 x, Int32 y) const
 
const ViewportPixelGetPixelInfoPolygon (Int32 x, Int32 y) const
 
const ViewportPixelGetPixelInfoEdge (Int32 x, Int32 y) const
 
Bool GetPointPixelBuffer (const ViewportPixel *const *&pixelBuffer, Int32 *pixelCount=nullptr) const
 
Bool GetEdgePixelBuffer (const ViewportPixel *const *&pixelBuffer, Int32 *pixelCount=nullptr) const
 
Bool GetPolygonPixelBuffer (const ViewportPixel *const *&pixelBuffer, Int32 *pixelCount=nullptr) const
 
const ViewportPixelGetNearestPoint (BaseObject *op, Int32 &x, Int32 &y, Int32 maxrad=LIMIT< Int32 >::MAX, Bool onlyselected=false, Int32 *ignorelist=nullptr, Int32 ignorecnt=0) const
 
const ViewportPixelGetNearestPolygon (BaseObject *op, Int32 &x, Int32 &y, Int32 maxrad=LIMIT< Int32 >::MAX, Bool onlyselected=false, Int32 *ignorelist=nullptr, Int32 ignorecnt=0) const
 
const ViewportPixelGetNearestEdge (BaseObject *op, Int32 &x, Int32 &y, Int32 maxrad=LIMIT< Int32 >::MAX, Bool onlyselected=false, Int32 *ignorelist=nullptr, Int32 ignorecnt=0) const
 
Int32 GetPixelCount () const
 

Draw

Bool DrawPolygon (const Vector *p, Int32 ptcnt, Int32 i, BaseObject *op, Int32 onlyvisible=-1)
 
Bool DrawHandle (const Vector &p, Int32 i, BaseObject *op, Int32 onlyvisible=-1)
 

Miscellaneous

void ClearPixelInfo (Int32 x, Int32 y, UChar mask)
 
Bool GetCameraCoordinates (Float x, Float y, Float z, Vector &v) const
 

Constructor & Destructor Documentation

◆ ViewportSelect()

ViewportSelect ( )
private

◆ ~ViewportSelect()

~ViewportSelect ( )
private

Member Function Documentation

◆ Alloc()

static ViewportSelect* Alloc ( )
static

Allocates a viewport select. Destroy the allocated viewport select with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated viewport select, or nullptr if the allocation failed.

◆ Free()

static void Free ( ViewportSelect *&  p)
static

Destructs viewport selects allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]pThe viewport select to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ Init() [1/2]

Bool Init ( Int32  w,
Int32  h,
BaseDraw bd,
BaseObject op,
Int32  mode,
Bool  onlyvisible,
VIEWPORTSELECTFLAGS  flags = VIEWPORTSELECTFLAGS::NONE 
)

Initializes the viewport information for a single object. This has to be done before the pixel information can be retrieved. The width and height of the viewport have to be retrieved manually:

Int32 left, top, right, bottom, width, height
bd->GetFrame(&left, &top, &right, &bottom);
width = right - left + 1;
height = bottom - top + 1;
_Py_Identifier * right
Definition: unicodeobject.h:1026
maxon::Int32 Int32
Definition: ge_sys_math.h:60
unsigned long Py_ssize_t width
Definition: pycore_traceback.h:88
Parameters
[in]wThe width of the viewport in pixels.
[in]hThe height of the viewport in pixels.
[in]bdThe viewport base draw. The caller owns the pointed base draw.
[in]opThe object to get the information for. The caller owns the pointed object.
[in]modeThe editor mode: Mpoints, Mpolygons, Medges or Mpolyedgepoint.
[in]onlyvisibleIf true only visible elements are included.
[in]flagsThe flags: VIEWPORTSELECTFLAGS
Returns
true if the viewport select was successfully initialized, otherwise false.

◆ Init() [2/2]

Bool Init ( Int32  w,
Int32  h,
BaseDraw bd,
AtomArray ar,
Int32  mode,
Bool  onlyvisible,
VIEWPORTSELECTFLAGS  flags = VIEWPORTSELECTFLAGS::NONE 
)

Initializes the viewport information for multiple objects. This has to be done before the pixel information can be retrieved.

Int32 left, top, right, bottom, width, height
bd->GetFrame(&left, &top, &right, &bottom);
width = right - left + 1;
height = bottom - top + 1;
Parameters
[in]wThe width of the viewport in pixels.
[in]hThe height of the viewport in pixels.
[in]bdThe viewport base draw. The caller owns the pointed base draw.
[in]arAn atom array with objects to get the information for. The caller owns the pointed array.
Pass nullptr or an empty array to initialize an empty ViewportSelect, for instance to draw your own polygons or handles.
[in]modeThe editor mode: Mpoints, Mpolygons, Medges or Mpolyedgepoint.
[in]onlyvisibleIf true only visible elements are included.
[in]flagsThe flags: VIEWPORTSELECTFLAGS
Returns
true if the viewport select was successfully initialized, otherwise false.

◆ PickObject() [1/3]

static Bool PickObject ( BaseDraw bd,
BaseDocument doc,
Int32  x,
Int32  y,
Int32  rad,
VIEWPORT_PICK_FLAGS  flags,
LassoSelection ls,
C4DObjectList list,
maxon::SquareMatrix4d m = nullptr,
Int32 sampleLocation = nullptr 
)
static

Picks objects within the circle that is defined by x, y, and rad into the provided object list. Note that the screen origin is in the upper left corner, whereas the clip origin is in the lower left corner.

Parameters
[in]bdThe viewport base draw. The caller owns the pointed base draw.
[in]docThe document. The caller owns the pointed document.
[in]xThe X position of the picking circle within the viewport.
[in]yThe Y position of the picking circle within the viewport.
[in]radThe radius in pixels for the search.
[in]flagsThe flags: VIEWPORT_PICK_FLAGS
[in]lsAn optional lasso selection. The caller owns the pointed lasso selection.
[out]listThe picked object list to fill. The caller owns the pointed list.
[out]mThe projection matrix. A vector in OpenGL clipping space (-1,1) is the result of a vector in world space multiplied by this matrix.
[out]sampleLocationSample location inside the pixel (cast to DRAWPORT_SAMPLE_LOCATION).
Returns
true if objects were picked successfully, otherwise false.

◆ PickObject() [2/3]

static Bool PickObject ( BaseDraw bd,
BaseDocument doc,
Int32  x,
Int32  y,
Int32  rad,
Int32 xr,
Int32 yr,
Int32 wr,
Int32 hr,
const ViewportPixel *const *&  pixels,
VIEWPORT_PICK_FLAGS  flags,
LassoSelection ls,
C4DObjectList list,
maxon::SquareMatrix4d m = nullptr,
Int32 sampleLocation = nullptr 
)
static

Picks objects within the circle that is defined by x, y, and rad into the provided object list.

Note
xr, yr, wr and hr hold the region where the picking was done. It can be smaller than the originally defined region. (e.g. If the picking is done close to the view's border.) Note that the screen origin is in the upper left corner, whereas the clip origin is in the lower left corner.
Parameters
[in]bdThe viewport base draw. The caller owns the pointed base draw.
[in]docThe document. The caller owns the pointed document.
[in]xThe X position of the picking circle within the viewport.
[in]yThe Y position of the picking circle within the viewport.
[in]radThe radius in pixels for the search.
[out]xrIs assigned the X position of the rectangle where the picking was done.
[out]yrIs assigned the Y position of the rectangle where the picking was done.
[out]wrIs assigned the width of the rectangle where the picking was done.
[out]hrIs assigned the height of the rectangle where the picking was done.
[out]pixelsHolds an [wr * hr] array with the pixel information. For each array index this is a linked list. The array must be deleted by the caller when it is not needed anymore!
[in]flagsThe flags: VIEWPORT_PICK_FLAGS
[in]lsAn optional lasso selection. The caller owns the pointed lasso selection.
[out]listThe picked object list to fill. The caller owns the pointed list.
[out]mThe projection matrix. A vector in OpenGL clipping space (-1,1) is the result of a vector in world space multiplied by this matrix.
[out]sampleLocationSample location inside the pixel (cast to DRAWPORT_SAMPLE_LOCATION).
Returns
true if objects were picked successfully, otherwise false.

◆ PickObject() [3/3]

static Bool PickObject ( BaseDraw bd,
BaseDocument doc,
Int32  x1,
Int32  y1,
Int32  x2,
Int32  y2,
Int32 xr,
Int32 yr,
Int32 wr,
Int32 hr,
const ViewportPixel *const *&  pixels,
VIEWPORT_PICK_FLAGS  flags,
LassoSelection ls,
C4DObjectList list,
maxon::SquareMatrix4d m = nullptr,
Int32 sampleLocation = nullptr 
)
static

Picks objects within the rectangle that is defined by x1, y1, x2 and y2.

Note
VIEWPORT_PICK_FLAGS::ALLOW_OGL must be set. x1, y1, x2 and y2 are inclusive.
xr, yr, wr and hr hold the region where the picking was done. It can be smaller than the originally defined region. (e.g. If the picking is done close to the view's border.) Note that the screen origin is in the upper left corner, whereas the clip origin is in the lower left corner.
Parameters
[in]bdThe viewport base draw. The caller owns the pointed base draw.
[in]docThe document. The caller owns the pointed document.
[in]x1The X minimum position of the picking rectangle.
[in]y1The Y minimum position of the picking rectangle.
[in]x2The X maximum position of the picking rectangle.
[in]y2The Y maximum position of the picking rectangle.
[out]xrIs assigned the X position of the rectangle where the picking was done.
[out]yrIs assigned the Y position of the rectangle where the picking was done.
[out]wrIs assigned the width of the rectangle where the picking was done.
[out]hrIs assigned the height of the rectangle where the picking was done.
[out]pixelsHolds an [wr * hr] array with the pixel information. For each array index this is a linked list. The array must be deleted by the caller when it is not needed anymore!
[in]flagsThe flags: VIEWPORT_PICK_FLAGS
[in]lsAn optional lasso selection. The caller owns the pointed lasso selection.
[out]listThe picked object list to fill. The caller owns the pointed list.
[out]mThe projection matrix. A vector in OpenGL clipping space (-1,1) is the result of a vector in world space multiplied by this matrix.
[out]sampleLocationSample location inside the pixel (cast to DRAWPORT_SAMPLE_LOCATION).
Returns
true if objects were picked successfully, otherwise false.

◆ GetPixelInfoPoint()

const ViewportPixel* GetPixelInfoPoint ( Int32  x,
Int32  y 
) const

Retrieves point information at the pixel position (x,y).

Parameters
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
[in]yA Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
Returns
The retrieved point information, or nullptr if no information could be retrieved. The ViewportSelect instance owns the pointed viewport pixel..

◆ GetPixelInfoPolygon()

const ViewportPixel* GetPixelInfoPolygon ( Int32  x,
Int32  y 
) const

Retrieves polygon information at the pixel position (x,y).

Parameters
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
[in]yA Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
Returns
The retrieved polygon information, or nullptr if no information could be retrieved. The ViewportSelect instance owns the pointed viewport pixel..

◆ GetPixelInfoEdge()

const ViewportPixel* GetPixelInfoEdge ( Int32  x,
Int32  y 
) const

Retrieves edge information at the pixel position (x,y).

Parameters
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
[in]yA Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
Returns
The retrieved edge information, or nullptr if no information could be retrieved. The ViewportSelect instance owns the pointed viewport pixel..

◆ GetPointPixelBuffer()

Bool GetPointPixelBuffer ( const ViewportPixel *const *&  pixelBuffer,
Int32 pixelCount = nullptr 
) const

Retrieves point information buffer. Direct access to the buffer should always be bound by GetPixelCount().

Since
R19
Note
Direct browsing of the pixel buffers is always faster than by making a library call pixel per pixel.
Parameters
[out]pixelBufferThe address of the point pixel buffer. The ViewportSelect instance owns the pointed pixel buffer.
[out]pixelCountnullptr or valid address to write the point pixel buffer count.
Returns
true if the ViewportSelect was properly initialized and the point buffer is valid, otherwise false.

◆ GetEdgePixelBuffer()

Bool GetEdgePixelBuffer ( const ViewportPixel *const *&  pixelBuffer,
Int32 pixelCount = nullptr 
) const

Retrieves edge information buffer. Direct access to the buffer should always be bound by GetPixelCount().

Since
R19
Note
Direct browsing of the pixel buffers is always faster than by making a library call pixel per pixel.
Parameters
[out]pixelBufferThe address of the edge pixel buffer. The ViewportSelect instance owns the pointed pixel buffer.
[out]pixelCountnullptr or valid address to write the edge pixel buffer count.
Returns
true if the ViewportSelect was properly initialized and the edge buffer is valid, otherwise false.

◆ GetPolygonPixelBuffer()

Bool GetPolygonPixelBuffer ( const ViewportPixel *const *&  pixelBuffer,
Int32 pixelCount = nullptr 
) const

Retrieves polygon information buffer. Direct access to the buffer should always be bound by GetPixelCount().

Since
R19
Note
Direct browsing of the pixel buffers is always faster than by making a library call pixel per pixel.
Parameters
[out]pixelBufferThe address of the polygon pixel buffer. The ViewportSelect instance owns the pointed pixel buffer.
[out]pixelCountnullptr or valid address to write the polygon pixel buffer count.
Returns
true if the ViewportSelect was properly initialized and the polygon buffer is valid, otherwise false.

◆ GetNearestPoint()

const ViewportPixel* GetNearestPoint ( BaseObject op,
Int32 x,
Int32 y,
Int32  maxrad = LIMITInt32 >::MAX,
Bool  onlyselected = false,
Int32 ignorelist = nullptr,
Int32  ignorecnt = 0 
) const

Retrieves nearest point information at the pixel position (x,y).

Parameters
[in]opThe object to search for the closest element. The caller owns the pointed object.
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
If an element was found the reference is updated to reflect the X coordinate of the nearest point.
[in]yAn Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
If an element was found the reference is updated to reflect the Y coordinate of the nearest point.
[in]maxradA maximal radius for the search in pixels.
[in]onlyselectedIf true only selected elements are included in the search.
[in]ignorelistA list with points to ignore. The caller owns the pointed list.
[in]ignorecntThe number of points index in ignorelist.
Returns
The retrieved nearest point information, or nullptr if no information could be retrieved. The ViewportSelect instance owns the pointed viewport pixel..

◆ GetNearestPolygon()

const ViewportPixel* GetNearestPolygon ( BaseObject op,
Int32 x,
Int32 y,
Int32  maxrad = LIMITInt32 >::MAX,
Bool  onlyselected = false,
Int32 ignorelist = nullptr,
Int32  ignorecnt = 0 
) const

Retrieves nearest polygon information at the pixel position (x,y).

Parameters
[in]opThe object to search for the closest element. The caller owns the pointed object.
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
If an element was found the reference is updated to reflect the X coordinate of the nearest point.
[in]yAn Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
If an element was found the reference is updated to reflect the Y coordinate of the nearest point.
[in]maxradA maximal radius for the search in pixels.
[in]onlyselectedIf true only selected elements are included in the search.
[in]ignorelistA list with points to ignore. The caller owns the pointed list.
[in]ignorecntThe number of points index in ignorelist.
Returns
The retrieved nearest polygon information, or nullptr if no information could be retrieved. The ViewportSelect instance owns the pointed viewport pixel..

◆ GetNearestEdge()

const ViewportPixel* GetNearestEdge ( BaseObject op,
Int32 x,
Int32 y,
Int32  maxrad = LIMITInt32 >::MAX,
Bool  onlyselected = false,
Int32 ignorelist = nullptr,
Int32  ignorecnt = 0 
) const

Retrieves nearest edge information at the pixel position (x,y).

Parameters
[in]opThe object to search for the closest element. The caller owns the pointed object.
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
If an element was found the reference is updated to reflect the X coordinate of the nearest point.
[in]yAn Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
If an element was found the reference is updated to reflect the Y coordinate of the nearest point.
[in]maxradA maximal radius for the search in pixels.
[in]onlyselectedIf true only selected elements are included in the search.
[in]ignorelistA list with points to ignore. The caller owns the pointed list.
[in]ignorecntThe number of points index in ignorelist.
Returns
The retrieved nearest edge information, or nullptr if no information could be retrieved. The ViewportSelect instance owns the pointed viewport pixel..

◆ GetPixelCount()

Int32 GetPixelCount ( ) const

Returns the number of pixels in the pixel buffers fetched with GetPixelInfoPoint()/GetPixelInfoEdge()/GetPixelInfoPolygon().

Since
R19
Warning
Pixel array should never be indexed further than the pixel count.
Returns
The pixel count.

◆ DrawPolygon()

Bool DrawPolygon ( const Vector p,
Int32  ptcnt,
Int32  i,
BaseObject op,
Int32  onlyvisible = -1 
)

Draws a polygon into the internal pixel structure, so that pixels inside the polygon will be associated with i and op in the ViewportPixel retrieved.

Parameters
[in]pAn array of ptcnt points that make up the polygon. The caller owns the pointed array. Coordinates are in screen space.
[in]ptcntThe number of points in the polygon p.
[in]iThe polygon index to associate with the polygon.
[in]opThe object to associate with the polygon. The caller owns the pointed object.
[in]onlyvisibleIf true only visible parts of the polygon are drawn.
Returns
true if the polygon was successfully drawn, otherwise false.

◆ DrawHandle()

Bool DrawHandle ( const Vector p,
Int32  i,
BaseObject op,
Int32  onlyvisible = -1 
)

Draws a handle into the internal pixel structure, so that pixels inside the handle will be associated with i and op in the ViewportPixel retrieved.

Parameters
[in]pThe position of the handle. Coordinate is in screen space.
[in]iThe polygon index to associate with the handle.
[in]opThe object to associate with the handle. The caller owns the pointed object.
[in]onlyvisibleIf true only visible parts of the handle are drawn.
Returns
true if the handle was successfully drawn, otherwise false.

◆ ShowHotspot() [1/2]

static void ShowHotspot ( EditorWindow bw,
Int32  x,
Int32  y,
Int32  rad,
Bool  bRemove 
)
static

Private.

◆ ShowHotspot() [2/2]

void ShowHotspot ( EditorWindow bw,
Int32  x,
Int32  y 
)

Draws an XOR circle to the view bw at the pixel position (x,y). The radius is set by SetBrushRadius().

Parameters
[in]bwThe editor window to draw to. The caller owns the pointed EditorWindow.
[in]xThe X position of the XOR circle within the viewport. Must be 0 <= x < w, where w is the width given to Init().
[in]yThe Y position of the XOR circle within the viewport. Must be 0 <= y < h, where h is the height given to Init().

◆ SetBrushRadius()

void SetBrushRadius ( Int32  r)

Sets the radius size for ShowHotspot() to r.

Parameters
[in]rThe radius in pixels.

◆ ClearPixelInfo()

void ClearPixelInfo ( Int32  x,
Int32  y,
UChar  mask 
)

Deletes the pixel information at (x,y) according to mask.

Note
This is used for example in the live edge selection with "tolerant" deactivated to find out how many pixels of a certain edge was selected.
If an edge is determined under the cursor, the pixel counter is decremented and the edge information is deleted afterwards.
Parameters
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
[in]yA Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
[in]maskA bitfield of what to clear: VIEWPORT_CLEAR

◆ GetCameraCoordinates()

Bool GetCameraCoordinates ( Float  x,
Float  y,
Float  z,
Vector v 
) const

Converts the pixel position (x,y,z) to camera coordinates in v.

Note
This is not exactly the same as
v = bd->SC(Vector(x,y,z))
PyObject PyObject * v
Definition: abstract.h:297
PyObject * x
Definition: bytesobject.h:38
maxon::Vec3< maxon::Float64, 1 > Vector
Definition: ge_math.h:145
since inverted Z coordinates are used.
Parameters
[in]xAn X coordinate within the viewport. Must be 0 <= x < w, where w is the width given to Init().
[in]yA Y coordinate within the viewport. Must be 0 <= y < h, where h is the height given to Init().
[in]zA Z coordinate within the viewport.
[in]vIs assigned the calculated camera coordinate.
Returns
true if the pixel position was successfully converted, otherwise false.