// Copyright (c) 2021 NVIDIA CORPORATION.  All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto.  Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#include <OgnRandomPointsDatabase.h>
#include <cstdlib>

// This is the implementation of the OGN node defined in OgnRandomPoints.ogn

namespace omni {
namespace graph {
namespace test {

class OgnRandomPoints
{
public:
    // Create an array of "pointCount" points at random locations within the bounding cube,
    // delineated by the corner points "minimum" and "maximum".
    static bool compute(OgnRandomPointsDatabase& db)
    {
        const auto& minimum = db.inputs.minimum();
        GfVec3f rangeSize = db.inputs.maximum() - minimum;

        // No points mean nothing to generate
        const auto& pointCount = db.inputs.pointCount();
        if (pointCount == 0)
        {
            return true;
        }
        auto& outputPoints = db.outputs.points();
        outputPoints.resize(pointCount);

        for (size_t i=0; i<pointCount; ++i)
        {
            outputPoints[i] = GfVec3f{
                minimum[0] + static_cast<float>(rand()) /( static_cast<float>(RAND_MAX/(rangeSize[0]))),
                minimum[1] + static_cast<float>(rand()) /( static_cast<float>(RAND_MAX/(rangeSize[1]))),
                minimum[2] + static_cast<float>(rand()) /( static_cast<float>(RAND_MAX/(rangeSize[2])))
            };
        }

        return true;
    }
};

REGISTER_OGN_NODE()

} // test
} // namespace graph
} // namespace omni
