案例位置:examples/Cuda/QtGUI/Qt_Connection
功能介绍:该案例展示了场景图中节点的连接关系。如下图所示,场景图中Target节点有输入节点和输出节点。为了方便叙述,将节点标号为①②③④。
DEF_NODE_PORTS(T, name, desc)
DEF_NODE_PORT(T, name, desc)
DEF_INSTANCE_IN(T, name, desc);
案例说明:案例中Target节点定义了三个输入接口,其中Source A(s)运行多个节点接入、Source B只允许一个节点接入、Data是只允许指定数据输入。
接下来介绍案例的实现过程:
class Data : public Object {
public:
Data() {};
~Data() override {};
};
class SourceA : public Node
{
DECLARE_CLASS(SourceA);
public:
SourceA() {
};
~SourceA() override {};
DEF_INSTANCE_OUT(Data, Data, "Output");
protected:
void resetStates() {};
};
IMPLEMENT_CLASS(SourceA);
class SourceB : public Node
{
DECLARE_CLASS(SourceB);
public:
SourceB() {
};
~SourceB() override {};
DEF_INSTANCE_OUT(Data, Data, "Output");
protected:
void resetStates() {};
};
IMPLEMENT_CLASS(SourceB);
class Target : public Node
{
DECLARE_CLASS(Target);
public:
Target() {
};
~Target() override {};
DEF_NODE_PORTS(SourceA, SourceA, "");
DEF_NODE_PORT(SourceB, SourceB, "");
DEF_INSTANCE_IN(Data, Data, "Input");
protected:
void resetStates() {};
};
IMPLEMENT_CLASS(Target);
int main()
{
std::shared_ptr<SceneGraph> scn = std::make_shared<SceneGraph>();
auto source1 = scn->addNode(std::make_shared<SourceA>());
source1->setName("s1");
auto source2 = scn->addNode(std::make_shared<SourceA>());
source2->setName("s2");
auto source3 = scn->addNode(std::make_shared<SourceB>());
source3->setName("s3");
auto target1 = scn->addNode(std::make_shared<Target>());
target1->setName("t1");
source1->connect(target1->importSourceAs());
source2->connect(target1->importSourceAs());
source3->connect(target1->importSourceB());
source1->outData()->connect(target1->inData());
QtApp app;
app.setSceneGraph(scn);
app.initialize(1366, 800);
app.mainLoop();
return 0;
}