GR/GR_BaryCenter.C

/*
 * Copyright (c) 2013
 *      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.
 *
 *----------------------------------------------------------------------------
 */

#include <UT/UT_DSOVersion.h>

#include <RE/RE_Render.h>

#include <GEO/GEO_Primitive.h>

#include <GU/GU_Detail.h>
#include <GU/GU_PrimGroupClosure.h>

#include <GR/GR_Detail.h>
#include <GR/GR_RenderHook.h>
#include <GR/GR_RenderTable.h>

namespace HDK_Sample {
class GR_BaryCenter : public GR_RenderHook
{
public:
    GR_BaryCenter() {}
    virtual ~GR_BaryCenter() {}

    virtual void renderWire(GU_Detail *gdp,
                        RE_Render &ren,
                        const GR_AttribOffset &ptinfo,
                        const GR_DisplayOption *dopt,
                        float lod,
                        const GU_PrimGroupClosure *hidden_geometry);

    virtual void renderShaded(GU_Detail *gdp,
                        RE_Render &ren,
                        const GR_AttribOffset &ptinfo,
                        const GR_DisplayOption *dopt,
                        float lod,
                        const GU_PrimGroupClosure *hidden_geometry);

    virtual const char *getName() const { return "GR_BaryCenter"; }
};
} // End HDK_Sample namespace
using namespace HDK_Sample;

void
GR_BaryCenter::renderWire(GU_Detail *gdp,
                    RE_Render &ren,
                    const GR_AttribOffset & /*ptinfo*/,
                    const GR_DisplayOption * /*dopt*/,
                    float /*lod*/,
                    const GU_PrimGroupClosure *hidden_geometry)
{
    int                  i, nprim;
    GEO_Primitive       *prim;
    UT_Vector3           v3;

    ren.beginPoint();
    
    nprim = gdp->primitives().entries();
    for (i = 0; i < nprim; i++)
    {
        prim = gdp->primitives()(i);

        // Ignore hidden geomtry.
        if (hidden_geometry && hidden_geometry->containsPrim(prim))
            continue;

        v3 = prim->baryCenter();
        ren.vertex3DW(v3.x(), v3.y(), v3.z());
    }

    ren.endPoint();
}

void
GR_BaryCenter::renderShaded(GU_Detail *gdp,
                    RE_Render &ren,
                    const GR_AttribOffset &ptinfo,
                    const GR_DisplayOption *dopt,
                    float lod,
                    const GU_PrimGroupClosure *hidden_geometry)
{
    // We don't want to light the points as they have no normals.
    GR_Detail::toggleLightShading(ren, 0);
    renderWire(gdp, ren, ptinfo, dopt, lod, hidden_geometry);
    GR_Detail::toggleLightShading(ren, 1);
}

void
newRenderHook(GR_RenderTable *table)
{
    GR_BaryCenter *hook = new GR_BaryCenter;
    
    table->addHook(hook, GR_RENDER_HOOK_VERSION);
}

Generated on Mon Jan 28 00:45:38 2013 for HDK by  doxygen 1.5.9