| 12 | using namespace CGraph; |
| 13 | |
| 14 | void tutorial_region() { |
| 15 | CStatus status; |
| 16 | GPipelinePtr pipeline = GPipelineFactory::create(); |
| 17 | GElementPtr a, b_region, c = nullptr; |
| 18 | |
| 19 | GElementPtr b1, b2, b3, b4 = nullptr; |
| 20 | b1 = pipeline->createGNode<MyNode1>(GNodeInfo({}, "nodeB1", 1)); // 创建名为nodeB1的node信息 |
| 21 | b2 = pipeline->createGNode<MyNode2>(GNodeInfo({b1}, "nodeB2", 2)); // 创建名为nodeB2且自循环2次的node信息 |
| 22 | b3 = pipeline->createGNode<MyNode1>(GNodeInfo({b1}, "nodeB3", 1)); |
| 23 | b4 = pipeline->createGNode<MyNode1>(GNodeInfo({b2, b3}, "nodeB4", 1)); |
| 24 | |
| 25 | b_region = pipeline->createGGroup<GRegion>({b1, b2, b3, b4}); // 将 b1、b2、b3、b4 注册入b_region中 |
| 26 | if (nullptr == b_region) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | status += pipeline->registerGElement<MyNode1>(&a, {}, "nodeA", 1); |
| 31 | status += pipeline->registerGElement<GRegion>(&b_region, {a}, "regionB", 2); // 将名为regionB,依赖a执行且自循环2次的region信息,注册入pipeline中 |
| 32 | status += pipeline->registerGElement<MyNode2>(&c, {b_region}, "nodeC", 1); |
| 33 | if (!status.isOK()) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | status = pipeline->process(); |
| 38 | CGRAPH_ECHO("pipeline process status is : [%d]", status.getCode()); |
| 39 | |
| 40 | /** |
| 41 | * 如果想查看pipeline内部,各部分(element)的运行耗时情况, |
| 42 | * 请调用 perf()方法,并且将输出的内容(不包含node内部的打印信息), |
| 43 | * 复制到 https://dreampuf.github.io/GraphvizOnline/ 查看效果 |
| 44 | * 具体字段解释,请参考函数头文件备注信息 |
| 45 | */ |
| 46 | // pipeline->perf(); |
| 47 | |
| 48 | GPipelineFactory::remove(pipeline); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | int main () { |