Tutorial 14 - Defaults

While most inputs are required to have default values it’s not strictly necessary to provide explicit values for those defaults. If a default is required and not specified then it will get a default value equal to an empty value. See the table at the bottom for what is considered an “empty” value for each type of attribute.

OgnTutorialDefaults.ogn

The ogn file shows the implementation of a node named “omni.graph.tutorials.Defaults”, which has sample inputs of several types without default values and matching outputs.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
{
    "Defaults": {
        "version": 1,
        "categories": "tutorials",
        "description": ["This is a tutorial node. It will move the values of inputs to corresponding outputs.",
                        "Inputs all have unspecified, and therefore empty, default values."
        ],
        "metadata":
        {
           "uiName": "Tutorial Node: Defaults"
        },
        "inputs": {
            "a_bool": {
                "type": "bool",
                "description": ["This is an attribute of type boolean"]
             },
            "a_half": {
                "type": "half",
                "description": ["This is an attribute of type 16 bit floating point"]
             },
            "a_int": {
                "type": "int",
                "description": ["This is an attribute of type 32 bit integer"]
             },
            "a_int64": {
                "type": "int64",
                "description": ["This is an attribute of type 64 bit integer"]
             },
            "a_float": {
                "type": "float",
                "description": ["This is an attribute of type 32 bit floating point"]
             },
            "a_double": {
                "type": "double",
                "description": ["This is an attribute of type 64 bit floating point"]
             },
             "a_string": {
                "type": "string",
                "description": ["This is an attribute of type string"]
            },
            "a_token": {
                "type": "token",
                "description": ["This is an attribute of type interned string with fast comparison and hashing"]
            },
            "a_uchar": {
               "type": "uchar",
               "description": ["This is an attribute of type unsigned 8 bit integer"]
           },
            "a_uint": {
               "type": "uint",
               "description": ["This is an attribute of type unsigned 32 bit integer"]
            },
            "a_uint64": {
                "type": "uint64",
                "description": ["This is an attribute of type unsigned 64 bit integer"]
            },
            "a_int2": {
                "type": "int[2]",
                "description": ["This is an attribute of type 2-tuple of integers"]
            },
            "a_matrix": {
                "type": "matrixd[2]",
                "description": ["This is an attribute of type 2x2 matrix"]
            },
            "a_array": {
                "type": "float[]",
                "description": ["This is an attribute of type array of floats"]
             }
        },
        "outputs": {
            "a_bool": {
                "type": "bool",
                "description": ["This is a computed attribute of type boolean"]
             },
            "a_half": {
                "type": "half",
                "description": ["This is a computed attribute of type 16 bit floating point"]
             },
            "a_int": {
                "type": "int",
                "description": ["This is a computed attribute of type 32 bit integer"]
             },
            "a_int64": {
                "type": "int64",
                "description": ["This is a computed attribute of type 64 bit integer"]
             },
            "a_float": {
                "type": "float",
                "description": ["This is a computed attribute of type 32 bit floating point"]
             },
            "a_double": {
                "type": "double",
                "description": ["This is a computed attribute of type 64 bit floating point"]
            },
            "a_string": {
                "type": "string",
                "description": ["This is a computed attribute of type string"]
            },
            "a_token": {
                "type": "token",
                "description": ["This is a computed attribute of type interned string with fast comparison and hashing"]
            },
            "a_uchar": {
                "type": "uchar",
                "description": ["This is a computed attribute of type unsigned 8 bit integer"]
            },
            "a_uint": {
                "type": "uint",
                "description": ["This is a computed attribute of type unsigned 32 bit integer"]
            },
            "a_uint64": {
                "type": "uint64",
                "description": ["This is a computed attribute of type unsigned 64 bit integer"]
            },
            "a_int2": {
                "type": "int[2]",
                "description": ["This is a computed attribute of type 2-tuple of integers"]
            },
            "a_matrix": {
                "type": "matrixd[2]",
                "description": ["This is a computed attribute of type 2x2 matrix"]
            },
            "a_array": {
                "type": "float[]",
                "description": ["This is a computed attribute of type array of floats"]
            }
        },
        "tests": [
            {
                "outputs:a_bool": false,
                "outputs:a_double": 0.0,
                "outputs:a_float": 0.0,
                "outputs:a_half": 0.0,
                "outputs:a_int": 0,
                "outputs:a_int64": 0,
                "outputs:a_string": "",
                "outputs:a_token": "",
                "outputs:a_uchar": 0,
                "outputs:a_uint": 0,
                "outputs:a_uint64": 0,
                "outputs:a_int2": [0, 0],
                "outputs:a_matrix": [[1.0, 0.0], [0.0, 1.0]],
                "outputs:a_array": []
            }
        ]
    }
}

OgnTutorialDefaults.cpp

The cpp file contains the implementation of the compute method, which copies the input values over to the corresponding outputs. All values should be the empty defaults.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) 2020, 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 <OgnTutorialDefaultsDatabase.h>

class OgnTutorialDefaults
{
public:
    static bool compute(OgnTutorialDefaultsDatabase& db)
    {
        // Simple values
        db.outputs.a_bool() = db.inputs.a_bool();
        db.outputs.a_half() = db.inputs.a_half();
        db.outputs.a_int() = db.inputs.a_int();
        db.outputs.a_int64() = db.inputs.a_int64();
        db.outputs.a_double() = db.inputs.a_double();
        db.outputs.a_float() = db.inputs.a_float();
        db.outputs.a_uchar() = db.inputs.a_uchar();
        db.outputs.a_uint() = db.inputs.a_uint();
        db.outputs.a_uint64() = db.inputs.a_uint64();
        db.outputs.a_token() = db.inputs.a_token();
        db.outputs.a_string() = db.inputs.a_string();

        // A few representative tuples
        db.outputs.a_int2() = db.inputs.a_int2();
        db.outputs.a_matrix() = db.inputs.a_matrix();

        // And an array
        db.outputs.a_array().resize(db.inputs.a_array().size());
        db.outputs.a_array() = db.inputs.a_array();

        return true;
    }
};

REGISTER_OGN_NODE()

Empty Values For Attribute Types

The empty values for each of the attribute types is defined below. Having no default specified in the .ogn file for any of them is equivalent to defining a default of the given value.

Type Name

Empty Default

bool

False

double

0.0

float

0.0

half

0.0

int

0

int64

0

string

“”

token

“”

uchar

0

uint

0

uint64

0

Note

All attributes that are array types have empty defaults equal to the empty array []

Note

All tuple types have empty defaults equal to a tuple of the correct count, each member containing the empty value for the base type. e.g. a float[2] will have empty default [0.0, 0.0], and a matrix[2] will have empty default [[0.0, 0.0], [0.0, 0.0]]