HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUI/GUI_PolySoupBox.h
/*
* Copyright (c) 2024
* Side Effects Software Inc. All rights reserved.
*
* Redistribution and use of Houdini Development Kit samples in source and
* binary forms, with or without modification, are permitted provided that the
* following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* COMMENTS:
* Adds a display option for the bounding box and another for the
* barycenter of the entire polysoup. This hook only renders additional
* decorations. It does not draw the surface itself.
*/
#ifndef __GUI_PolySoupBox__
#define __GUI_PolySoupBox__
namespace HDK_Sample
{
/// The primitive render hook which creates GUI_PolySoupBox objects.
class GUI_PolySoupBoxHook : public GUI_PrimitiveHook
{
public:
GUI_PolySoupBoxHook();
~GUI_PolySoupBoxHook() override;
/// This is called when a new GR_Primitive is required for a polysoup.
/// In this case, the hook is augmenting the rendering of the polysoup by
/// drawing a bounding box and a centroid around it.
GR_Primitive *createPrimitive(const GT_PrimitiveHandle &gt_prim,
const GEO_Primitive *geo_prim,
const GR_RenderInfo *info,
const char *cache_name,
GR_PrimAcceptResult &processed) override;
};
/// Primitive object that is created by GUI_PolySoupBoxHook whenever a
/// polysoup primitive is found. This object can be persistent between
/// renders, though display flag changes or navigating though SOPs can cause
/// it to be deleted and recreated later.
class GUI_PolySoupBox : public GR_Primitive
{
public:
GUI_PolySoupBox(const GR_RenderInfo *info,
const char *cache_name,
const GEO_Primitive *prim);
~GUI_PolySoupBox() override;
const char *className() const override { return "GUI_PolySoupBox"; }
/// See if the primitive can be consumed by this GR_Primitive. Only
/// primitives from the same detail will ever be passed in. If the
/// primitive hook specifies GUI_HOOK_COLLECT_PRIMITIVES then it is
/// possible to have this called more than once for different GR_Primitives.
/// A GR_Primitive that collects multiple GT or GEO primitives is
/// responsible for keeping track of them (in a list, table, tree, etc).
int geo_type,
const GT_PrimitiveHandle &ph,
const GEO_Primitive *prim) override;
/// Called whenever the parent detail is changed, draw modes are changed,
/// selection is changed, or certain volatile display options are changed
/// (such as level of detail).
void update(RE_RenderContext r,
const GT_PrimitiveHandle &primh,
const GR_UpdateParms &p) override;
/// For this primitive hook, which only renders decorations, the render
/// methods do nothing, allowing the native Houdini code to do the work.
/// @{
GR_RenderMode render_mode,
GR_DrawParms dp) override;
int renderPick(RE_RenderContext r,
const GR_DisplayOption *opt,
unsigned int pick_type,
GR_PickStyle pick_style,
bool has_pick_map) override;
/// @}
/// Called when decoration 'decor' is required to be rendered.
void renderDecoration(RE_RenderContext r,
const GR_DecorationParms &p) override;
private:
void renderBBox(RE_Render *r,
const GR_DisplayOption *opts);
void renderBary(RE_Render *r,
const GR_DisplayOption *opts);
RE_Geometry *myGeometry;
};
} // End HDK_Sample namespace.
#endif