案例位置:examples/Cuda/QtGUI/Qt_Fields
功能介绍:该案例主要向用户展示如何创建一个节点和Field数据。Field是对基本数据类型的封装,从而实现节点以及模块之间的数据传递。
案例说明:案例中定义了一个Fields节点。节点中定义了以下数据:
其中,标量数据、矢量数据和枚举型数据可在Qt界面展示出来:
接下来介绍案例的实现过程:
class Fields : public Node
{
DECLARE_CLASS(Fields);
public:
Fields() {
this->varFloat()->setRange(0.01, 10.0f);
this->inFloatArray()->tagOptional(true);
};
~Fields() {};
DECLARE_ENUM(ENum,
Key0 = 0,
Key1 = 1);
public:
DEF_VAR(bool, Boolean, false, "Define a boolean field");
DEF_VAR(int, Int, 1, "Define an int");
DEF_VAR(float, Float, 1.0f, "Define a float field");
DEF_VAR(Vec3f, Vector, Vec3f(1.0f), "Define a vector field");
DEF_ENUM(ENum, Enum, ENum::Key0, "Define an enum");
DEF_ARRAY_IN(float, FloatArray, DeviceType::GPU, "Define a float array as input");
DEF_ARRAY_OUT(float, FloatArray, DeviceType::GPU, "Define a float array as output");
DEF_ARRAY_STATE(float, Value, DeviceType::GPU, "Define a float array as state");
protected:
void resetStates() {
std::cout << "resetStates() " << " is called " << std::endl;
}
};
IMPLEMENT_CLASS(Fields);
int main()
{
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
auto source1 = scn->addNode(std::make_shared<Fields>());
QtApp app;
app.setSceneGraph(scn);
app.initialize(1366, 800);
app.mainLoop();
return 0;
}