├── .gitattributes
├── .gitignore
├── FlowProjects
└── domainReduce.flow
├── NodeEditorPro.sln
├── NodeEditorPro
├── DefaultStyle.json
├── Halcon2105.props
├── NodeEditorPro.vcxproj
├── NodeEditorPro.vcxproj.filters
├── examples
│ ├── calculator
│ │ ├── AdditionModel.hpp
│ │ ├── CMakeLists.txt
│ │ ├── Converters.cpp
│ │ ├── Converters.hpp
│ │ ├── DecimalData.hpp
│ │ ├── DivisionModel.hpp
│ │ ├── IntegerData.hpp
│ │ ├── MathNodes.hpp
│ │ ├── MathOperationDataModel.cpp
│ │ ├── MathOperationDataModel.hpp
│ │ ├── ModuloModel.cpp
│ │ ├── ModuloModel.hpp
│ │ ├── MultiplicationModel.hpp
│ │ ├── NumberDisplayDataModel.cpp
│ │ ├── NumberDisplayDataModel.hpp
│ │ ├── NumberSourceDataModel.cpp
│ │ ├── NumberSourceDataModel.hpp
│ │ └── SubtractionModel.hpp
│ ├── halcon
│ │ ├── HImageDLSegmentModel.cpp
│ │ ├── HImageDLSegmentModel.hpp
│ │ ├── HImageData.hpp
│ │ ├── HImageFolderModel.cpp
│ │ ├── HImageFolderModel.hpp
│ │ ├── HImageLoaderModel.cpp
│ │ ├── HImageLoaderModel.hpp
│ │ ├── HImageRGB2GrayModel.cpp
│ │ ├── HImageRGB2GrayModel.hpp
│ │ ├── HImageReduceDomainModel.cpp
│ │ ├── HImageReduceDomainModel.hpp
│ │ ├── HImageShowModel.cpp
│ │ ├── HImageShowModel.hpp
│ │ ├── HImageSplitChanelModel.cpp
│ │ ├── HImageSplitChanelModel.hpp
│ │ ├── HImageThresholdModel.cpp
│ │ ├── HImageThresholdModel.hpp
│ │ ├── HImageViewWidget.cpp
│ │ ├── HImageViewWidget.hpp
│ │ ├── HObjectData.hpp
│ │ ├── HRegionConnectModel.cpp
│ │ ├── HRegionConnectModel.hpp
│ │ ├── HRegionData.hpp
│ │ ├── HRegionDifferenceModel.cpp
│ │ ├── HRegionDifferenceModel.hpp
│ │ ├── HRegionFillUpShapeModel.cpp
│ │ ├── HRegionFillUpShapeModel.hpp
│ │ ├── HRegionOpenCircleModel.cpp
│ │ ├── HRegionOpenCircleModel.hpp
│ │ ├── HRegionSelectModel.cpp
│ │ ├── HRegionSelectModel.hpp
│ │ ├── HRegionSelectShapeStdModel.cpp
│ │ ├── HRegionSelectShapeStdModel.hpp
│ │ ├── HRegionShapeTransModel.cpp
│ │ ├── HRegionShapeTransModel.hpp
│ │ ├── HRegionUnionModel.cpp
│ │ ├── HRegionUnionModel.hpp
│ │ └── HalconNodes.hpp
│ └── images
│ │ ├── ImageLoaderModel.cpp
│ │ ├── ImageLoaderModel.hpp
│ │ ├── ImageShowModel.cpp
│ │ ├── ImageShowModel.hpp
│ │ ├── PixmapData.hpp
│ │ ├── VisionFlowWidget.cpp
│ │ ├── VisionFlowWidget.hpp
│ │ └── main.cpp
├── halcon20.11_x64_cpp.props
├── include
│ └── nodes
│ │ ├── Compiler.hpp
│ │ ├── Connection.hpp
│ │ ├── ConnectionGeometry.hpp
│ │ ├── ConnectionGraphicsObject.hpp
│ │ ├── ConnectionState.hpp
│ │ ├── ConnectionStyle.hpp
│ │ ├── DataModelRegistry.hpp
│ │ ├── Export.hpp
│ │ ├── FlowScene.hpp
│ │ ├── FlowView.hpp
│ │ ├── FlowViewStyle.hpp
│ │ ├── Node.hpp
│ │ ├── NodeData.hpp
│ │ ├── NodeDataModel.hpp
│ │ ├── NodeGeometry.hpp
│ │ ├── NodeGraphicsObject.hpp
│ │ ├── NodePainterDelegate.hpp
│ │ ├── NodeState.hpp
│ │ ├── NodeStyle.hpp
│ │ ├── OperatingSystem.hpp
│ │ ├── PortType.hpp
│ │ ├── QStringStdHash.hpp
│ │ ├── QUuidStdHash.hpp
│ │ ├── Serializable.hpp
│ │ ├── Style.hpp
│ │ ├── StyleCollection.hpp
│ │ ├── TypeConverter.hpp
│ │ └── memory.hpp
├── resources
│ ├── DefaultStyle - 副本.json
│ ├── DefaultStyle.json
│ ├── convert.png
│ ├── logo.png
│ └── resources.qrc
├── showcase
│ ├── ReduceDomain.gif
│ ├── ReduceDomain.mp4
│ ├── draw_shape_view.png
│ ├── reduceNode.png
│ ├── selectBallTest.png
│ ├── selectRegionNode.png
│ ├── showcase1.gif
│ ├── showcase2.mp4
│ ├── showcase3.gif
│ ├── showcase4.gif
│ ├── showcase5.png
│ └── showcase6.mp4
└── src
│ ├── Connection.cpp
│ ├── ConnectionBlurEffect.cpp
│ ├── ConnectionBlurEffect.hpp
│ ├── ConnectionGeometry.cpp
│ ├── ConnectionGraphicsObject.cpp
│ ├── ConnectionPainter.cpp
│ ├── ConnectionPainter.hpp
│ ├── ConnectionState.cpp
│ ├── ConnectionStyle.cpp
│ ├── DataModelRegistry.cpp
│ ├── FlowScene.cpp
│ ├── FlowView.cpp
│ ├── FlowViewStyle.cpp
│ ├── Node.cpp
│ ├── NodeConnectionInteraction.cpp
│ ├── NodeConnectionInteraction.hpp
│ ├── NodeDataModel.cpp
│ ├── NodeGeometry.cpp
│ ├── NodeGraphicsObject.cpp
│ ├── NodePainter.cpp
│ ├── NodePainter.hpp
│ ├── NodeState.cpp
│ ├── NodeStyle.cpp
│ ├── Properties.cpp
│ ├── Properties.hpp
│ ├── QDataStreamPhaser.cpp
│ ├── QDataStreamPhaser.hpp
│ ├── QJsonParser.cpp
│ ├── QJsonParser.hpp
│ └── StyleCollection.cpp
├── README.md
└── ShapeDrawer
├── DrawShapeView.cpp
├── DrawShapeView.hpp
├── DrawViewParams.h
├── ShapeControlItem.cpp
├── ShapeControlItem.h
├── ShapeItemBase.cpp
├── ShapeItemBase.h
├── ShapeItemLine.cpp
├── ShapeItemLine.h
├── ShapeItemPolygon.cpp
├── ShapeItemPolygon.h
├── ShapeItemRect1.cpp
├── ShapeItemRect1.h
├── ShapeItemRect2.cpp
└── ShapeItemRect2.h
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/NodeEditorPro.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.3.32825.248
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "NodeEditorPro", "NodeEditorPro\NodeEditorPro.vcxproj", "{4911AD57-2763-4EDF-9C7C-2E197137BE8B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {4911AD57-2763-4EDF-9C7C-2E197137BE8B}.Debug|x64.ActiveCfg = Debug|x64
15 | {4911AD57-2763-4EDF-9C7C-2E197137BE8B}.Debug|x64.Build.0 = Debug|x64
16 | {4911AD57-2763-4EDF-9C7C-2E197137BE8B}.Release|x64.ActiveCfg = Release|x64
17 | {4911AD57-2763-4EDF-9C7C-2E197137BE8B}.Release|x64.Build.0 = Release|x64
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {26A3A5F1-B946-441D-97D3-C988346DDEF3}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/NodeEditorPro/Halcon2105.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | E:\CodeDeps\Halcon2105Cpp\include;E:\CodeDeps\Halcon2105Cpp\include\halconcpp;E:\CodeDeps\Halcon2105Cpp\;%(AdditionalIncludeDirectories)
9 |
10 |
11 | E:\CodeDeps\Halcon2105Cpp\lib;%(AdditionalLibraryDirectories)
12 | halconcpp.lib;halcon.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/AdditionModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include
6 |
7 | #include "NodeDataModel.hpp"
8 |
9 | #include "MathOperationDataModel.hpp"
10 | #include "DecimalData.hpp"
11 |
12 | /// The model dictates the number of inputs and outputs for the Node.
13 | /// In this example it has no logic.
14 | class AdditionModel : public MathOperationDataModel
15 | {
16 | public:
17 |
18 | virtual
19 | ~AdditionModel() {}
20 |
21 | public:
22 |
23 | QString
24 | caption() const override
25 | {
26 | return QStringLiteral("加法");
27 | }
28 |
29 | QString
30 | name() const override
31 | {
32 | return QStringLiteral("加法");
33 | }
34 |
35 | private:
36 |
37 | void
38 | compute() override
39 | {
40 | PortIndex const outPortIndex = 0;
41 |
42 | auto n1 = _number1.lock();
43 | auto n2 = _number2.lock();
44 |
45 | if (n1 && n2)
46 | {
47 | modelValidationState = NodeValidationState::Valid;
48 | modelValidationError = QString();
49 | _result = std::make_shared(n1->number() +
50 | n2->number());
51 | }
52 | else
53 | {
54 | modelValidationState = NodeValidationState::Warning;
55 | modelValidationError = QStringLiteral("未连接或运行失败!");
56 | _result.reset();
57 | }
58 |
59 | Q_EMIT dataUpdated(outPortIndex);
60 | }
61 | };
62 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | file(GLOB_RECURSE CPPS ./*.cpp )
2 |
3 | add_executable(calculator ${CPPS})
4 |
5 | target_link_libraries(calculator nodes)
6 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/Converters.cpp:
--------------------------------------------------------------------------------
1 | #include "Converters.hpp"
2 |
3 | #include
4 |
5 | #include "DecimalData.hpp"
6 | #include "IntegerData.hpp"
7 |
8 |
9 | std::shared_ptr
10 | DecimalToIntegerConverter::
11 | operator()(std::shared_ptr data)
12 | {
13 | auto numberData =
14 | std::dynamic_pointer_cast(data);
15 |
16 | if (numberData)
17 | {
18 | _integer = std::make_shared(numberData->number());
19 | }
20 | else
21 | {
22 | _integer.reset();
23 | }
24 |
25 | return _integer;
26 | }
27 |
28 |
29 | std::shared_ptr
30 | IntegerToDecimalConverter::
31 | operator()(std::shared_ptr data)
32 | {
33 | auto numberData =
34 | std::dynamic_pointer_cast(data);
35 |
36 | if (numberData)
37 | {
38 | _decimal = std::make_shared(numberData->number());
39 | }
40 | else
41 | {
42 | _decimal.reset();
43 | }
44 |
45 | return _decimal;
46 | }
47 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/Converters.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "DecimalData.hpp"
4 | #include "IntegerData.hpp"
5 |
6 | using QtNodes::PortType;
7 | using QtNodes::PortIndex;
8 | using QtNodes::NodeData;
9 | using QtNodes::NodeDataType;
10 | using QtNodes::NodeDataModel;
11 |
12 | class DecimalData;
13 | class IntegerData;
14 |
15 |
16 | class DecimalToIntegerConverter
17 | {
18 |
19 | public:
20 |
21 | std::shared_ptr
22 | operator()(std::shared_ptr data);
23 |
24 | private:
25 |
26 | std::shared_ptr _integer;
27 | };
28 |
29 |
30 | class IntegerToDecimalConverter
31 | {
32 |
33 | public:
34 |
35 | std::shared_ptr
36 | operator()(std::shared_ptr data);
37 |
38 | private:
39 |
40 | std::shared_ptr _decimal;
41 | };
42 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/DecimalData.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "NodeDataModel.hpp"
4 |
5 | using QtNodes::NodeDataType;
6 | using QtNodes::NodeData;
7 |
8 | /// The class can potentially incapsulate any user data which
9 | /// need to be transferred within the Node Editor graph
10 | class DecimalData : public NodeData
11 | {
12 | public:
13 |
14 | DecimalData()
15 | : _number(0.0)
16 | {}
17 |
18 | DecimalData(double const number)
19 | : _number(number)
20 | {}
21 |
22 | NodeDataType type() const override
23 | {
24 | return NodeDataType{ "decimal",
25 | QStringLiteral("浮点数") };
26 | }
27 |
28 | double number() const
29 | {
30 | return _number;
31 | }
32 |
33 | QString numberAsText() const
34 | {
35 | return QString::number(_number, 'f');
36 | }
37 |
38 | private:
39 |
40 | double _number;
41 | };
42 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/DivisionModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #include "NodeDataModel.hpp"
7 |
8 | #include "MathOperationDataModel.hpp"
9 |
10 | #include "DecimalData.hpp"
11 |
12 | /// The model dictates the number of inputs and outputs for the Node.
13 | /// In this example it has no logic.
14 | class DivisionModel : public MathOperationDataModel
15 | {
16 | public:
17 |
18 | virtual
19 | ~DivisionModel() {}
20 |
21 | public:
22 | QString
23 | caption() const override
24 | {
25 | return QStringLiteral("除法");
26 | }
27 |
28 | bool
29 | portCaptionVisible(PortType portType, PortIndex portIndex) const override
30 | {
31 | Q_UNUSED(portType); Q_UNUSED(portIndex);
32 | return true;
33 | }
34 |
35 | QString
36 | portCaption(PortType portType, PortIndex portIndex) const override
37 | {
38 | switch (portType)
39 | {
40 | case PortType::In:
41 | if (portIndex == 0)
42 | return QStringLiteral("除数");
43 | else if (portIndex == 1)
44 | return QStringLiteral("被除数");
45 |
46 | break;
47 |
48 | case PortType::Out:
49 | return QStringLiteral("结果");
50 |
51 | default:
52 | break;
53 | }
54 | return QString();
55 | }
56 |
57 | QString
58 | name() const override
59 | {
60 | return QStringLiteral("除法");
61 | }
62 |
63 | private:
64 |
65 | void
66 | compute() override
67 | {
68 | PortIndex const outPortIndex = 0;
69 |
70 | auto n1 = _number1.lock();
71 | auto n2 = _number2.lock();
72 |
73 | if (n2 && (n2->number() == 0.0))
74 | {
75 | modelValidationState = NodeValidationState::Error;
76 | modelValidationError = QStringLiteral("被除数无法为0!");
77 | _result.reset();
78 | }
79 | else if (n1 && n2)
80 | {
81 | modelValidationState = NodeValidationState::Valid;
82 | modelValidationError = QString();
83 | _result = std::make_shared(n1->number() /
84 | n2->number());
85 | }
86 | else
87 | {
88 | modelValidationState = NodeValidationState::Warning;
89 | modelValidationError = QStringLiteral("未连接或运行失败!");
90 | _result.reset();
91 | }
92 |
93 | Q_EMIT dataUpdated(outPortIndex);
94 | }
95 | };
96 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/IntegerData.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "NodeDataModel.hpp"
4 |
5 | using QtNodes::NodeDataType;
6 | using QtNodes::NodeData;
7 |
8 | /// The class can potentially incapsulate any user data which
9 | /// need to be transferred within the Node Editor graph
10 | class IntegerData : public NodeData
11 | {
12 | public:
13 |
14 | IntegerData()
15 | : _number(0.0)
16 | {}
17 |
18 | IntegerData(int const number)
19 | : _number(number)
20 | {}
21 |
22 | NodeDataType type() const override
23 | {
24 | return NodeDataType{ "integer",
25 | QStringLiteral("整数") };
26 | }
27 |
28 | int number() const
29 | {
30 | return _number;
31 | }
32 |
33 | QString numberAsText() const
34 | {
35 | return QString::number(_number);
36 | }
37 |
38 | private:
39 |
40 | int _number;
41 | };
42 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/MathNodes.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | //math nodes
4 | #include "calculator/AdditionModel.hpp"
5 | #include "calculator/DivisionModel.hpp"
6 | #include "calculator/MultiplicationModel.hpp"
7 | #include "calculator/SubtractionModel.hpp"
8 | #include "calculator/NumberSourceDataModel.hpp"
9 | #include "calculator/NumberDisplayDataModel.hpp"
10 |
11 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/MathOperationDataModel.cpp:
--------------------------------------------------------------------------------
1 | #include "MathOperationDataModel.hpp"
2 |
3 | #include "DecimalData.hpp"
4 |
5 | unsigned int
6 | MathOperationDataModel::
7 | nPorts(PortType portType) const
8 | {
9 | unsigned int result;
10 |
11 | if (portType == PortType::In)
12 | result = 2;
13 | else
14 | result = 1;
15 |
16 | return result;
17 | }
18 |
19 |
20 | NodeDataType
21 | MathOperationDataModel::
22 | dataType(PortType, PortIndex) const
23 | {
24 | return DecimalData().type();
25 | }
26 |
27 |
28 | std::shared_ptr
29 | MathOperationDataModel::
30 | outData(PortIndex)
31 | {
32 | return std::static_pointer_cast(_result);
33 | }
34 |
35 |
36 | void
37 | MathOperationDataModel::
38 | setInData(std::shared_ptr data, PortIndex portIndex)
39 | {
40 | auto numberData =
41 | std::dynamic_pointer_cast(data);
42 |
43 | if (portIndex == 0)
44 | {
45 | _number1 = numberData;
46 | }
47 | else
48 | {
49 | _number2 = numberData;
50 | }
51 | compute();
52 | }
53 |
54 | NodeValidationState
55 | MathOperationDataModel::
56 | validationState() const
57 | {
58 | return modelValidationState;
59 | }
60 |
61 |
62 | QString
63 | MathOperationDataModel::
64 | validationMessage() const
65 | {
66 | return modelValidationError;
67 | }
68 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/MathOperationDataModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #include "NodeDataModel.hpp"
8 |
9 | #include
10 |
11 | class DecimalData;
12 |
13 | using QtNodes::PortType;
14 | using QtNodes::PortIndex;
15 | using QtNodes::NodeData;
16 | using QtNodes::NodeDataType;
17 | using QtNodes::NodeDataModel;
18 | using QtNodes::NodeValidationState;
19 |
20 | /// The model dictates the number of inputs and outputs for the Node.
21 | /// In this example it has no logic.
22 | class MathOperationDataModel : public NodeDataModel
23 | {
24 | Q_OBJECT
25 |
26 | public:
27 |
28 | virtual
29 | ~MathOperationDataModel() {}
30 |
31 | public:
32 |
33 | unsigned int
34 | nPorts(PortType portType) const override;
35 |
36 | NodeDataType
37 | dataType(PortType portType,
38 | PortIndex portIndex) const override;
39 |
40 | std::shared_ptr
41 | outData(PortIndex port) override;
42 |
43 | void
44 | setInData(std::shared_ptr data, PortIndex portIndex) override;
45 |
46 | QWidget*
47 | embeddedWidget() override { return nullptr; }
48 |
49 | NodeValidationState
50 | validationState() const override;
51 |
52 | QString
53 | validationMessage() const override;
54 |
55 | protected:
56 |
57 | virtual void
58 | compute() = 0;
59 |
60 | protected:
61 |
62 | std::weak_ptr _number1;
63 | std::weak_ptr _number2;
64 |
65 | std::shared_ptr _result;
66 |
67 | NodeValidationState modelValidationState = NodeValidationState::Warning;
68 | QString modelValidationError = QStringLiteral("未连接或运行失败!");
69 | };
70 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/ModuloModel.cpp:
--------------------------------------------------------------------------------
1 | #include "ModuloModel.hpp"
2 |
3 | #include
4 |
5 | #include "IntegerData.hpp"
6 |
7 | QJsonObject
8 | ModuloModel::
9 | save() const
10 | {
11 | QJsonObject modelJson;
12 |
13 | modelJson["name"] = name();
14 |
15 | return modelJson;
16 | }
17 |
18 |
19 | unsigned int
20 | ModuloModel::
21 | nPorts(PortType portType) const
22 | {
23 | unsigned int result = 1;
24 |
25 | switch (portType)
26 | {
27 | case PortType::In:
28 | result = 2;
29 | break;
30 |
31 | case PortType::Out:
32 | result = 1;
33 |
34 | default:
35 | break;
36 | }
37 |
38 | return result;
39 | }
40 |
41 |
42 | NodeDataType
43 | ModuloModel::
44 | dataType(PortType, PortIndex) const
45 | {
46 | return IntegerData().type();
47 | }
48 |
49 |
50 | std::shared_ptr
51 | ModuloModel::
52 | outData(PortIndex)
53 | {
54 | return _result;
55 | }
56 |
57 |
58 | void
59 | ModuloModel::
60 | setInData(std::shared_ptr data, PortIndex portIndex)
61 | {
62 | auto numberData =
63 | std::dynamic_pointer_cast(data);
64 |
65 | if (portIndex == 0)
66 | {
67 | _number1 = numberData;
68 | }
69 | else
70 | {
71 | _number2 = numberData;
72 | }
73 |
74 | {
75 | PortIndex const outPortIndex = 0;
76 |
77 | auto n1 = _number1.lock();
78 | auto n2 = _number2.lock();
79 |
80 | if (n2 && (n2->number() == 0.0))
81 | {
82 | modelValidationState = NodeValidationState::Error;
83 | modelValidationError = QStringLiteral("Division by zero error");
84 | _result.reset();
85 | }
86 | else if (n1 && n2)
87 | {
88 | modelValidationState = NodeValidationState::Valid;
89 | modelValidationError = QString();
90 | _result = std::make_shared(n1->number() %
91 | n2->number());
92 | }
93 | else
94 | {
95 | modelValidationState = NodeValidationState::Warning;
96 | modelValidationError = QStringLiteral("Missing or incorrect inputs");
97 | _result.reset();
98 | }
99 |
100 | Q_EMIT dataUpdated(outPortIndex);
101 | }
102 | }
103 |
104 |
105 | NodeValidationState
106 | ModuloModel::
107 | validationState() const
108 | {
109 | return modelValidationState;
110 | }
111 |
112 |
113 | QString
114 | ModuloModel::
115 | validationMessage() const
116 | {
117 | return modelValidationError;
118 | }
119 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/ModuloModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #include "NodeDataModel.hpp"
7 |
8 | #include
9 |
10 | using QtNodes::PortType;
11 | using QtNodes::PortIndex;
12 | using QtNodes::NodeData;
13 | using QtNodes::NodeDataType;
14 | using QtNodes::NodeDataModel;
15 | using QtNodes::NodeValidationState;
16 |
17 | class IntegerData;
18 |
19 | class ModuloModel
20 | : public NodeDataModel
21 | {
22 | Q_OBJECT
23 |
24 | public:
25 | ModuloModel() = default;
26 |
27 | virtual
28 | ~ModuloModel() = default;
29 |
30 | public:
31 |
32 | QString
33 | caption() const override
34 | {
35 | return QStringLiteral("求模");
36 | }
37 |
38 | bool
39 | captionVisible() const override
40 | {
41 | return true;
42 | }
43 |
44 | bool
45 | portCaptionVisible(PortType, PortIndex) const override
46 | {
47 | return true;
48 | }
49 |
50 | QString
51 | portCaption(PortType portType, PortIndex portIndex) const override
52 | {
53 | switch (portType)
54 | {
55 | case PortType::In:
56 | if (portIndex == 0)
57 | return QStringLiteral("求模数");
58 | else if (portIndex == 1)
59 | return QStringLiteral("被模数");
60 |
61 | break;
62 |
63 | case PortType::Out:
64 | return QStringLiteral("结果");
65 |
66 | default:
67 | break;
68 | }
69 | return QString();
70 | }
71 |
72 | QString
73 | name() const override
74 | {
75 | return QStringLiteral("求模");
76 | }
77 |
78 | public:
79 |
80 | QJsonObject
81 | save() const override;
82 |
83 | public:
84 |
85 | unsigned int
86 | nPorts(PortType portType) const override;
87 |
88 | NodeDataType
89 | dataType(PortType portType, PortIndex portIndex) const override;
90 |
91 | std::shared_ptr
92 | outData(PortIndex port) override;
93 |
94 | void
95 | setInData(std::shared_ptr, int) override;
96 |
97 | QWidget*
98 | embeddedWidget() override { return nullptr; }
99 |
100 | NodeValidationState
101 | validationState() const override;
102 |
103 | QString
104 | validationMessage() const override;
105 |
106 | private:
107 |
108 | std::weak_ptr _number1;
109 | std::weak_ptr _number2;
110 |
111 | std::shared_ptr _result;
112 |
113 | NodeValidationState modelValidationState = NodeValidationState::Warning;
114 | QString modelValidationError = QStringLiteral("未连接或运行失败!");
115 | };
116 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/MultiplicationModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #include "NodeDataModel.hpp"
7 |
8 | #include "MathOperationDataModel.hpp"
9 |
10 | #include "DecimalData.hpp"
11 |
12 | /// The model dictates the number of inputs and outputs for the Node.
13 | /// In this example it has no logic.
14 | class MultiplicationModel : public MathOperationDataModel
15 | {
16 | public:
17 |
18 | virtual
19 | ~MultiplicationModel() {}
20 |
21 | public:
22 |
23 | QString
24 | caption() const override
25 | {
26 | return QStringLiteral("乘法");
27 | }
28 |
29 | QString
30 | name() const override
31 | {
32 | return QStringLiteral("乘法");
33 | }
34 |
35 | private:
36 |
37 | void
38 | compute() override
39 | {
40 | PortIndex const outPortIndex = 0;
41 |
42 | auto n1 = _number1.lock();
43 | auto n2 = _number2.lock();
44 |
45 | if (n1 && n2)
46 | {
47 | modelValidationState = NodeValidationState::Valid;
48 | modelValidationError = QString();
49 | _result = std::make_shared(n1->number() *
50 | n2->number());
51 | }
52 | else
53 | {
54 | modelValidationState = NodeValidationState::Warning;
55 | modelValidationError = QStringLiteral("未连接或输入错误!");
56 | _result.reset();
57 | }
58 |
59 | Q_EMIT dataUpdated(outPortIndex);
60 | }
61 | };
62 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/NumberDisplayDataModel.cpp:
--------------------------------------------------------------------------------
1 | #include "NumberDisplayDataModel.hpp"
2 |
3 | #include "DecimalData.hpp"
4 |
5 | #include
6 |
7 | NumberDisplayDataModel::
8 | NumberDisplayDataModel()
9 | : _label{nullptr}
10 | {
11 | }
12 |
13 |
14 | unsigned int
15 | NumberDisplayDataModel::
16 | nPorts(PortType portType) const
17 | {
18 | unsigned int result = 1;
19 |
20 | switch (portType)
21 | {
22 | case PortType::In:
23 | result = 1;
24 | break;
25 |
26 | case PortType::Out:
27 | result = 0;
28 |
29 | default:
30 | break;
31 | }
32 |
33 | return result;
34 | }
35 |
36 |
37 | NodeDataType
38 | NumberDisplayDataModel::
39 | dataType(PortType, PortIndex) const
40 | {
41 | return DecimalData().type();
42 | }
43 |
44 |
45 | std::shared_ptr
46 | NumberDisplayDataModel::
47 | outData(PortIndex)
48 | {
49 | std::shared_ptr ptr;
50 | return ptr;
51 | }
52 |
53 |
54 | void
55 | NumberDisplayDataModel::
56 | setInData(std::shared_ptr data, int)
57 | {
58 | auto numberData = std::dynamic_pointer_cast(data);
59 |
60 | if (numberData)
61 | {
62 | modelValidationState = NodeValidationState::Valid;
63 | modelValidationError = QString();
64 | _label->setText(numberData->numberAsText());
65 | }
66 | else
67 | {
68 | modelValidationState = NodeValidationState::Warning;
69 | modelValidationError = QStringLiteral("Missing or incorrect inputs");
70 | _label->clear();
71 | }
72 |
73 | _label->adjustSize();
74 | }
75 |
76 | QWidget*
77 | NumberDisplayDataModel::
78 | embeddedWidget()
79 | {
80 | if (!_label)
81 | {
82 | _label = new QLabel();
83 | _label->setMargin(3);
84 | }
85 |
86 | return _label;
87 | }
88 |
89 | NodeValidationState
90 | NumberDisplayDataModel::
91 | validationState() const
92 | {
93 | return modelValidationState;
94 | }
95 |
96 |
97 | QString
98 | NumberDisplayDataModel::
99 | validationMessage() const
100 | {
101 | return modelValidationError;
102 | }
103 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/NumberDisplayDataModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "NodeDataModel.hpp"
6 |
7 | #include
8 |
9 | using QtNodes::PortType;
10 | using QtNodes::PortIndex;
11 | using QtNodes::NodeData;
12 | using QtNodes::NodeDataType;
13 | using QtNodes::NodeDataModel;
14 | using QtNodes::NodeValidationState;
15 |
16 | class QLabel;
17 |
18 | /// The model dictates the number of inputs and outputs for the Node.
19 | /// In this example it has no logic.
20 | class NumberDisplayDataModel : public NodeDataModel
21 | {
22 | Q_OBJECT
23 |
24 | public:
25 | NumberDisplayDataModel();
26 |
27 | virtual
28 | ~NumberDisplayDataModel() {}
29 |
30 | public:
31 |
32 | QString
33 | caption() const override
34 | {
35 | return QStringLiteral("数字显示");
36 | }
37 |
38 | bool
39 | captionVisible() const override
40 | {
41 | return true;
42 | }
43 |
44 | QString
45 | name() const override
46 | {
47 | return QStringLiteral("数字显示");
48 | }
49 |
50 | public:
51 |
52 | unsigned int
53 | nPorts(PortType portType) const override;
54 |
55 | NodeDataType
56 | dataType(PortType portType,
57 | PortIndex portIndex) const override;
58 |
59 | std::shared_ptr
60 | outData(PortIndex port) override;
61 |
62 | void
63 | setInData(std::shared_ptr data, int) override;
64 |
65 | QWidget*
66 | embeddedWidget() override;
67 |
68 | NodeValidationState
69 | validationState() const override;
70 |
71 | QString
72 | validationMessage() const override;
73 |
74 | private:
75 |
76 | NodeValidationState modelValidationState = NodeValidationState::Warning;
77 | QString modelValidationError = QStringLiteral("未连接或运算失败!");
78 |
79 | QLabel* _label;
80 | };
81 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/NumberSourceDataModel.cpp:
--------------------------------------------------------------------------------
1 | #include "NumberSourceDataModel.hpp"
2 |
3 | #include "DecimalData.hpp"
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | NumberSourceDataModel::
10 | NumberSourceDataModel()
11 | : _lineEdit{ nullptr }
12 | {
13 | }
14 |
15 |
16 | QJsonObject
17 | NumberSourceDataModel::
18 | save() const
19 | {
20 | QJsonObject modelJson = NodeDataModel::save();
21 |
22 | if (_number)
23 | modelJson["number"] = QString::number(_number->number());
24 |
25 | return modelJson;
26 | }
27 |
28 |
29 | void
30 | NumberSourceDataModel::
31 | restore(QJsonObject const& p)
32 | {
33 | QJsonValue v = p["number"];
34 |
35 | if (!v.isUndefined())
36 | {
37 | QString strNum = v.toString();
38 |
39 | bool ok;
40 | double d = strNum.toDouble(&ok);
41 | if (ok)
42 | {
43 | _number = std::make_shared(d);
44 | _lineEdit->setText(strNum);
45 | }
46 | }
47 | }
48 |
49 | unsigned int
50 | NumberSourceDataModel::
51 | nPorts(PortType portType) const
52 | {
53 | unsigned int result = 1;
54 |
55 | switch (portType)
56 | {
57 | case PortType::In:
58 | result = 0;
59 | break;
60 |
61 | case PortType::Out:
62 | result = 1;
63 |
64 | default:
65 | break;
66 | }
67 |
68 | return result;
69 | }
70 |
71 |
72 | void
73 | NumberSourceDataModel::
74 | onTextEdited(QString const& string)
75 | {
76 | Q_UNUSED(string);
77 |
78 | bool ok = false;
79 |
80 | double number = _lineEdit->text().toDouble(&ok);
81 |
82 | if (ok)
83 | {
84 | _number = std::make_shared(number);
85 |
86 | Q_EMIT dataUpdated(0);
87 | }
88 | else
89 | {
90 | Q_EMIT dataInvalidated(0);
91 | }
92 | }
93 |
94 |
95 | NodeDataType
96 | NumberSourceDataModel::
97 | dataType(PortType, PortIndex) const
98 | {
99 | return DecimalData().type();
100 | }
101 |
102 |
103 | std::shared_ptr
104 | NumberSourceDataModel::
105 | outData(PortIndex)
106 | {
107 | return _number;
108 | }
109 |
110 |
111 | QWidget*
112 | NumberSourceDataModel::
113 | embeddedWidget()
114 | {
115 | if (!_lineEdit)
116 | {
117 | _lineEdit = new QLineEdit();
118 |
119 | _lineEdit->setValidator(new QDoubleValidator());
120 | _lineEdit->setMaximumSize(_lineEdit->sizeHint());
121 |
122 | connect(_lineEdit, &QLineEdit::textChanged,
123 | this, &NumberSourceDataModel::onTextEdited);
124 |
125 | _lineEdit->setText("0.0");
126 | }
127 |
128 | return _lineEdit;
129 | }
130 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/NumberSourceDataModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "NodeDataModel.hpp"
6 |
7 | #include
8 |
9 | class DecimalData;
10 |
11 | using QtNodes::PortType;
12 | using QtNodes::PortIndex;
13 | using QtNodes::NodeData;
14 | using QtNodes::NodeDataType;
15 | using QtNodes::NodeDataModel;
16 | using QtNodes::NodeValidationState;
17 |
18 | class QLineEdit;
19 |
20 | /// The model dictates the number of inputs and outputs for the Node.
21 | /// In this example it has no logic.
22 | class NumberSourceDataModel
23 | : public NodeDataModel
24 | {
25 | Q_OBJECT
26 |
27 | public:
28 | NumberSourceDataModel();
29 |
30 | virtual
31 | ~NumberSourceDataModel() {}
32 |
33 | public:
34 |
35 | QString
36 | caption() const override
37 | {
38 | return QStringLiteral("数字输入");
39 | }
40 |
41 | bool
42 | captionVisible() const override
43 | {
44 | return true;
45 | }
46 |
47 | QString
48 | name() const override
49 | {
50 | return QStringLiteral("数字输入");
51 | }
52 |
53 | public:
54 |
55 | QJsonObject
56 | save() const override;
57 |
58 | void
59 | restore(QJsonObject const& p) override;
60 |
61 | public:
62 |
63 | unsigned int
64 | nPorts(PortType portType) const override;
65 |
66 | NodeDataType
67 | dataType(PortType portType, PortIndex portIndex) const override;
68 |
69 | std::shared_ptr
70 | outData(PortIndex port) override;
71 |
72 | void
73 | setInData(std::shared_ptr, int) override
74 | { }
75 |
76 | QWidget*
77 | embeddedWidget() override;
78 |
79 | private Q_SLOTS:
80 |
81 | void
82 | onTextEdited(QString const& string);
83 |
84 | private:
85 |
86 | std::shared_ptr _number;
87 |
88 | QLineEdit* _lineEdit;
89 | };
90 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/calculator/SubtractionModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | #include "NodeDataModel.hpp"
7 |
8 | #include "MathOperationDataModel.hpp"
9 |
10 | #include "DecimalData.hpp"
11 |
12 | /// The model dictates the number of inputs and outputs for the Node.
13 | /// In this example it has no logic.
14 | class SubtractionModel : public MathOperationDataModel
15 | {
16 | public:
17 |
18 | virtual
19 | ~SubtractionModel() {}
20 |
21 | public:
22 |
23 | QString
24 | caption() const override
25 | {
26 | return QStringLiteral("减法节点");
27 | }
28 |
29 | virtual bool
30 | portCaptionVisible(PortType portType, PortIndex portIndex) const override
31 | {
32 | Q_UNUSED(portType); Q_UNUSED(portIndex);
33 | return true;
34 | }
35 |
36 | virtual QString
37 | portCaption(PortType portType, PortIndex portIndex) const override
38 | {
39 | switch (portType)
40 | {
41 | case PortType::In:
42 | if (portIndex == 0)
43 | return QStringLiteral("减数");
44 | else if (portIndex == 1)
45 | return QStringLiteral("被减数");
46 |
47 | break;
48 |
49 | case PortType::Out:
50 | return QStringLiteral("结果");
51 |
52 | default:
53 | break;
54 | }
55 | return QString();
56 | }
57 |
58 | QString
59 | name() const override
60 | {
61 | return QStringLiteral("减法");
62 | }
63 |
64 | private:
65 |
66 | void
67 | compute() override
68 | {
69 | PortIndex const outPortIndex = 0;
70 |
71 | auto n1 = _number1.lock();
72 | auto n2 = _number2.lock();
73 |
74 | if (n1 && n2)
75 | {
76 | modelValidationState = NodeValidationState::Valid;
77 | modelValidationError = QString();
78 | _result = std::make_shared(n1->number() -
79 | n2->number());
80 | }
81 | else
82 | {
83 | modelValidationState = NodeValidationState::Warning;
84 | modelValidationError = QStringLiteral("缺失节点或运行失败!");
85 | _result.reset();
86 | }
87 |
88 | Q_EMIT dataUpdated(outPortIndex);
89 | }
90 | };
91 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageDLSegmentModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HImageDLSegmentModel.hpp"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "HRegionData.hpp"
9 | #include "DrawShapeView.hpp"
10 | #include "halconcpp/HalconCpp.h"
11 | #include "QJsonParser.hpp"
12 | using namespace HalconCpp;
13 |
14 |
15 | HImageDLSegmentModel::HImageDLSegmentModel()
16 | {
17 | m_hImage = std::make_shared();
18 | m_result = std::make_shared();
19 | btn_select_model = new QPushButton(QStringLiteral("选择模型"));
20 |
21 | connect(DrawShapeView::getInst(), SIGNAL(RegionFinished(RegionPixmapData)),
22 | this, SLOT(OnNewRegionData(RegionPixmapData)));
23 |
24 | connect(btn_select_model, &QPushButton::clicked, [=]()
25 | {
26 | dl_path.clear();
27 | dl_path =
28 | QFileDialog::getOpenFileName(nullptr,
29 | tr("Select Dl Model"),
30 | QDir::homePath(),
31 | tr("File (*.hdl)"));
32 | if (dl_path == "")
33 | {
34 | return;
35 | }
36 | readDlModel(dl_path);
37 | });
38 | }
39 |
40 | bool HImageDLSegmentModel::RunTask()
41 | {
42 | PortIndex const outPortIndex = 0;
43 | try
44 | {
45 |
46 | modelValidationState = NodeValidationState::Valid;
47 | modelValidationError = QString();
48 | }
49 | catch (...)
50 | {
51 | modelValidationState = NodeValidationState::Warning;
52 | modelValidationError = QStringLiteral("缺失或运行失败!");
53 | }
54 |
55 | return true;
56 | }
57 |
58 | void HImageDLSegmentModel::OnNewRegionData(ShapeDataStruct _data)
59 | {
60 | //if (!DrawShapeView::getInst()->getDrawFlag())
61 | //{
62 | // return;
63 | //}
64 | RunTask();
65 | }
66 |
67 | unsigned int HImageDLSegmentModel::
68 | nPorts(PortType portType) const
69 | {
70 | unsigned int result = 1;
71 |
72 | switch (portType)
73 | {
74 | case PortType::In:
75 | result = 1;
76 | break;
77 | case PortType::Out:
78 | result = 1;
79 | default:
80 | break;
81 | }
82 |
83 | return result;
84 | }
85 |
86 | NodeValidationState HImageDLSegmentModel::validationState() const
87 | {
88 | return modelValidationState;
89 | }
90 |
91 | QString HImageDLSegmentModel::validationMessage() const
92 | {
93 | return modelValidationError;
94 | }
95 |
96 | QJsonObject HImageDLSegmentModel::save() const
97 | {
98 | QJsonObject result = NodeDataModel::save();
99 | result.insert("dl_path", dl_path);
100 | return result;
101 | }
102 |
103 | void HImageDLSegmentModel::restore(QJsonObject const& _json)
104 | {
105 | dl_path = _json.value("dl_path").toString();
106 | }
107 |
108 | void HImageDLSegmentModel::readDlModel(QString modelFileName)
109 | {
110 | m_dl_model = new HDlModel();
111 | m_dl_model->ReadDlModel(modelFileName.toStdString().c_str());
112 | image_dimensions = m_dl_model->GetDlModelParam("image_dimensions");
113 | class_ids = m_dl_model->GetDlModelParam("class_ids");
114 | m_dl_model->SetDlModelParam("batch_size", 1);
115 | }
116 |
117 | NodeDataType
118 | HImageDLSegmentModel::dataType(PortType port_type, PortIndex port_index) const
119 | {
120 | if (port_type == PortType::In)
121 | {
122 | switch (port_index)
123 | {
124 | case 0:
125 | return HImageData().type();
126 | break;
127 | }
128 | }
129 | else
130 | {
131 | switch (port_index)
132 | {
133 | case 0:
134 | return HRegionData().type();
135 | break;
136 | }
137 | }
138 | return HImageData().type();
139 | }
140 |
141 | void HImageDLSegmentModel::
142 | setInData(std::shared_ptr data, int portIndex)
143 | {
144 | auto hImageData =
145 | std::dynamic_pointer_cast(data);
146 | if (hImageData == nullptr)
147 | {
148 | return;
149 | }
150 | switch (portIndex)
151 | {
152 | case 0:
153 | m_hImage->setHImage(*hImageData->hImage());
154 | break;
155 | default:
156 | break;
157 | }
158 | RunTask();
159 | }
160 |
161 | std::shared_ptr
162 | HImageDLSegmentModel::
163 | outData(PortIndex)
164 | {
165 | return std::dynamic_pointer_cast(m_result);
166 | }
167 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageDLSegmentModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "DataModelRegistry.hpp"
9 | #include "NodeDataModel.hpp"
10 | #include "halconcpp/HalconCpp.h"
11 | #include "HImageData.hpp"
12 | #include "HRegionData.hpp"
13 | #include "HImageViewWidget.hpp"
14 | #include "DrawShapeView.hpp"
15 |
16 | using QtNodes::PortType;
17 | using QtNodes::PortIndex;
18 | using QtNodes::NodeData;
19 | using QtNodes::NodeDataType;
20 | using QtNodes::NodeDataModel;
21 | using QtNodes::NodeValidationState;
22 | using namespace HalconCpp;
23 | /**
24 | * \brief halcon 图像rgb2gray节点
25 | */
26 | class HImageDLSegmentModel :public NodeDataModel
27 | {
28 | Q_OBJECT
29 | public:
30 | HImageDLSegmentModel();
31 | virtual ~HImageDLSegmentModel() {}
32 |
33 | public:
34 | QString caption() const override
35 | {
36 | return QStringLiteral("语义分割");
37 | }
38 | QString name() const override
39 | {
40 | return QStringLiteral("语义分割");
41 | }
42 | virtual QString modelName() const
43 | {
44 | return QStringLiteral("语义分割");
45 | }
46 | unsigned int
47 | nPorts(PortType portType) const override;
48 |
49 | NodeDataType
50 | dataType(PortType portType, PortIndex portIndex) const override;
51 |
52 | std::shared_ptr
53 | outData(PortIndex port) override;
54 |
55 | void
56 | setInData(std::shared_ptr, int) override;
57 |
58 | QWidget*
59 | embeddedWidget() override { return btn_select_model; }
60 |
61 | bool
62 | resizable() const override { return false; }
63 | NodeValidationState
64 | validationState() const override;
65 | QString
66 | validationMessage() const override;
67 | QJsonObject save() const override;
68 | void restore(QJsonObject const&) override;
69 | void readDlModel(QString modelFileName);
70 | protected:
71 | bool RunTask();
72 |
73 | public slots:
74 | void OnNewRegionData(ShapeDataStruct _data);
75 | public:
76 | NodeValidationState modelValidationState = NodeValidationState::Warning;
77 | QString modelValidationError = QStringLiteral("图片输入未连接!");
78 | private:
79 | QString dl_path;
80 | QPushButton* btn_select_model;
81 | HDlModel* m_dl_model;
82 | HTuple image_dimensions;
83 | HTuple class_ids;
84 | HTuple valid_thres = 0.7;
85 | std::shared_ptr m_hImage;
86 | std::shared_ptr m_result;
87 | };
88 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageData.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "NodeDataModel.hpp"
6 | #include "halconcpp/HalconCpp.h"
7 |
8 | using QtNodes::NodeData;
9 | using QtNodes::NodeDataType;
10 | using namespace HalconCpp;
11 |
12 | class HImageData :public NodeData
13 | {
14 | public:
15 | HImageData()
16 | {
17 | m_himage = HImage();
18 | }
19 | HImageData(HImage& h_image)
20 | {
21 | if (h_image.IsInitialized())
22 | {
23 | m_himage = h_image;
24 | }
25 | }
26 | virtual ~HImageData()
27 | {
28 |
29 | }
30 | NodeDataType type() const override
31 | {
32 | return { "HImage","Img" };
33 | }
34 | HImage* hImage() { return &m_himage; }
35 | void setHImage(HImage const& _img)
36 | {
37 | if (!_img.IsInitialized())
38 | {
39 | return;
40 | }
41 | m_himage = _img;
42 | }
43 | private:
44 | HImage m_himage;
45 | };
46 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageFolderModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include "DataModelRegistry.hpp"
11 | #include "NodeDataModel.hpp"
12 | #include "halconcpp/HalconCpp.h"
13 | #include "HImageData.hpp"
14 | #include "HImageViewWidget.hpp"
15 |
16 | using QtNodes::PortType;
17 | using QtNodes::PortIndex;
18 | using QtNodes::NodeData;
19 | using QtNodes::NodeDataType;
20 | using QtNodes::NodeDataModel;
21 | using QtNodes::NodeValidationState;
22 | using namespace HalconCpp;
23 | /**
24 | * \brief halcon 图像输入节点
25 | */
26 | class HImageFolderModel :public NodeDataModel
27 | {
28 | Q_OBJECT
29 | public:
30 | HImageFolderModel();
31 | virtual ~HImageFolderModel() {}
32 | public:
33 | QString caption() const override
34 | {
35 | return QStringLiteral("图像目录输入");
36 | }
37 | QString name() const override
38 | {
39 | return QStringLiteral("图像目录输入");
40 | }
41 | virtual QString modelName() const
42 | {
43 | return QStringLiteral("图像目录输入");
44 | }
45 | unsigned int
46 | nPorts(PortType portType) const override;
47 |
48 | NodeDataType
49 | dataType(PortType portType, PortIndex portIndex) const override;
50 |
51 | std::shared_ptr
52 | outData(PortIndex port) override;
53 |
54 | void
55 | setInData(std::shared_ptr, int) override
56 | { }
57 |
58 | QWidget*
59 | embeddedWidget() override { return m_paraWidget; }
60 |
61 | bool
62 | resizable() const override { return false; }
63 | QJsonObject save() const override;
64 | void restore(QJsonObject const&) override;
65 | void loadImageFolder(QString path, int index = 0);
66 | protected:
67 | bool eventFilter(QObject* watched, QEvent* event) override;
68 | private:
69 | QString folderPath;
70 | std::shared_ptr< HImageData> m_hImageData;
71 | QWidget* m_paraWidget;
72 | QVBoxLayout* m_host;
73 | QHBoxLayout* m_h_host;
74 | QPushButton* btn_selectFolder;
75 | QPushButton* btn_last;
76 | QPushButton* btn_next;
77 | HImageViewWidget* m_image_view;
78 | HTuple fileListStr;
79 | HTuple imgListStr;
80 | HImage tmpImg;
81 | int curIndex = 0;
82 | int imageCounst = 0;
83 | };
84 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageLoaderModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HImageLoaderModel.hpp"
2 | #include
3 | #include
4 | #include
5 |
6 | HImageLoaderModel::HImageLoaderModel()
7 | {
8 | m_image_view = new HImageViewWidget();
9 | m_image_view->installEventFilter(this);
10 | m_image_view->resize(200, 200);
11 | m_hImageData = std::make_shared();
12 | }
13 |
14 | unsigned int HImageLoaderModel::nPorts(PortType portType) const
15 | {
16 | unsigned int result = 1;
17 |
18 | switch (portType)
19 | {
20 | case PortType::In:
21 | result = 0;
22 | break;
23 |
24 | case PortType::Out:
25 | result = 1;
26 |
27 | default:
28 | break;
29 | }
30 |
31 | return result;
32 | }
33 |
34 | QJsonObject HImageLoaderModel::save() const
35 | {
36 | QJsonObject modelJson = NodeDataModel::save();
37 | if (m_hImageData)
38 | {
39 | HTuple* R, * G, * B;
40 | HTuple width, height;
41 | int chanels = m_hImageData->hImage()->CountChannels();
42 | m_hImageData->hImage()->GetImageSize(&width, &height);
43 | modelJson.insert("width", width.D());
44 | modelJson.insert("height", height.D());
45 | modelJson.insert("chanels", chanels);
46 | modelJson.insert("imageName", imageName);
47 | }
48 |
49 | return modelJson;
50 | }
51 |
52 | void HImageLoaderModel::restore(QJsonObject const& p)
53 | {
54 | imageName = p["imageName"].toString();
55 | loadImage(imageName);
56 | }
57 |
58 | void HImageLoaderModel::loadImage(QString fileName)
59 | {
60 | if (fileName == "")
61 | {
62 | return;
63 | }
64 | HImage tmpImg;
65 | tmpImg.ReadImage(fileName.toStdString().c_str());
66 | m_hImageData->setHImage(tmpImg);
67 | m_image_view->showImage(*m_hImageData->hImage());
68 | }
69 |
70 | bool HImageLoaderModel::eventFilter(QObject* object, QEvent* event)
71 | {
72 | if (object == m_image_view)
73 | {
74 | if (event->type() == QEvent::MouseButtonPress)
75 | {
76 | imageName =
77 | QFileDialog::getOpenFileName(nullptr,
78 | tr("Open Image"),
79 | QDir::homePath(),
80 | tr("Image Files (*.png *.jpg *.bmp)"));
81 | if (imageName == "")
82 | {
83 | return false;
84 | }
85 |
86 | loadImage(imageName);
87 |
88 | Q_EMIT dataUpdated(0);
89 |
90 | return true;
91 | }
92 | else if (event->type() == QEvent::Resize)
93 | {
94 |
95 | }
96 | }
97 |
98 | return false;
99 | }
100 |
101 | NodeDataType
102 | HImageLoaderModel::dataType(PortType, PortIndex) const
103 | {
104 | return HImageData().type();
105 | }
106 | std::shared_ptr
107 | HImageLoaderModel::
108 | outData(PortIndex)
109 | {
110 | return std::dynamic_pointer_cast(m_hImageData);
111 | }
112 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageLoaderModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "DataModelRegistry.hpp"
8 | #include "NodeDataModel.hpp"
9 | #include "halconcpp/HalconCpp.h"
10 | #include "HImageData.hpp"
11 | #include "HImageViewWidget.hpp"
12 |
13 | using QtNodes::PortType;
14 | using QtNodes::PortIndex;
15 | using QtNodes::NodeData;
16 | using QtNodes::NodeDataType;
17 | using QtNodes::NodeDataModel;
18 | using QtNodes::NodeValidationState;
19 | using namespace HalconCpp;
20 | /**
21 | * \brief halcon 图像输入节点
22 | */
23 | class HImageLoaderModel :public NodeDataModel
24 | {
25 | Q_OBJECT
26 | public:
27 | HImageLoaderModel();
28 | virtual ~HImageLoaderModel() {}
29 | public:
30 | QString caption() const override
31 | {
32 | return QStringLiteral("图像输入");
33 | }
34 | QString name() const override
35 | {
36 | return QStringLiteral("图像输入");
37 | }
38 | virtual QString modelName() const
39 | {
40 | return QStringLiteral("图像输入");
41 | }
42 | unsigned int
43 | nPorts(PortType portType) const override;
44 |
45 | NodeDataType
46 | dataType(PortType portType, PortIndex portIndex) const override;
47 |
48 | std::shared_ptr
49 | outData(PortIndex port) override;
50 |
51 | void
52 | setInData(std::shared_ptr, int) override
53 | { }
54 |
55 | QWidget*
56 | embeddedWidget() override { return m_image_view; }
57 |
58 | bool
59 | resizable() const override { return false; }
60 | QJsonObject save() const override;
61 | void restore(QJsonObject const&) override;
62 | void loadImage(QString fileName);
63 | protected:
64 | bool eventFilter(QObject* watched, QEvent* event) override;
65 | private:
66 | QString imageName;
67 | std::shared_ptr< HImageData> m_hImageData;
68 | HImageViewWidget* m_image_view;
69 |
70 | };
71 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageRGB2GrayModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HImageRGB2GrayModel.hpp"
2 | #include
3 |
4 | #include "halconcpp/HalconCpp.h"
5 |
6 | using namespace HalconCpp;
7 |
8 | HImageRGB2GrayModel::HImageRGB2GrayModel()
9 | {
10 | m_hImage = std::make_shared();
11 | }
12 |
13 | bool HImageRGB2GrayModel::RunTask()
14 | {
15 | Q_EMIT computingStarted();
16 | PortIndex const outPortIndex = 0;
17 | try
18 | {
19 | HTuple imgChanels = m_hImage->hImage()->CountChannels();
20 | if (imgChanels == 3)
21 | {
22 | HImage tmp_img = m_hImage->hImage()->Rgb3ToGray(*m_hImage->hImage(), *m_hImage->hImage());
23 | m_hImage->setHImage(tmp_img);
24 | tmp_img.Clear();
25 | }
26 | modelValidationState = NodeValidationState::Valid;
27 | modelValidationError = QString();
28 | }
29 | catch (...)
30 | {
31 | modelValidationState = NodeValidationState::Warning;
32 | modelValidationError = QStringLiteral("缺失或运行失败!");
33 | }
34 |
35 | Q_EMIT dataUpdated(outPortIndex);
36 | Q_EMIT computingFinished();
37 | return true;
38 | }
39 |
40 | unsigned int HImageRGB2GrayModel::
41 | nPorts(PortType portType) const
42 | {
43 | unsigned int result = 1;
44 |
45 | switch (portType)
46 | {
47 | case PortType::In:
48 | result = 1;
49 | break;
50 |
51 | case PortType::Out:
52 | result = 1;
53 |
54 | default:
55 | break;
56 | }
57 |
58 | return result;
59 | }
60 |
61 | NodeValidationState HImageRGB2GrayModel::validationState() const
62 | {
63 | return modelValidationState;
64 | }
65 |
66 | QString HImageRGB2GrayModel::validationMessage() const
67 | {
68 | return modelValidationError;
69 | }
70 |
71 | NodeDataType
72 | HImageRGB2GrayModel::dataType(PortType, PortIndex) const
73 | {
74 | return HImageData().type();
75 | }
76 |
77 | void HImageRGB2GrayModel::
78 | setInData(std::shared_ptr data, int portIndex)
79 | {
80 | auto hImageData =
81 | std::dynamic_pointer_cast(data);
82 | if (hImageData == nullptr)
83 | {
84 | return;
85 | }
86 | switch (portIndex)
87 | {
88 | case 0:
89 | m_hImage->setHImage(*hImageData->hImage());
90 | break;
91 | default:
92 | break;
93 | }
94 | RunTask();
95 | }
96 |
97 | std::shared_ptr
98 | HImageRGB2GrayModel::
99 | outData(PortIndex)
100 | {
101 | return std::dynamic_pointer_cast(m_hImage);
102 | }
103 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageRGB2GrayModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "DataModelRegistry.hpp"
8 | #include "NodeDataModel.hpp"
9 | #include "halconcpp/HalconCpp.h"
10 | #include "HImageData.hpp"
11 | #include "HImageViewWidget.hpp"
12 |
13 | using QtNodes::PortType;
14 | using QtNodes::PortIndex;
15 | using QtNodes::NodeData;
16 | using QtNodes::NodeDataType;
17 | using QtNodes::NodeDataModel;
18 | using QtNodes::NodeValidationState;
19 | using namespace HalconCpp;
20 | /**
21 | * \brief halcon 图像rgb2gray节点
22 | */
23 | class HImageRGB2GrayModel :public NodeDataModel
24 | {
25 | Q_OBJECT
26 | public:
27 | HImageRGB2GrayModel();
28 | virtual ~HImageRGB2GrayModel() {}
29 |
30 | public:
31 | QString caption() const override
32 | {
33 | return QStringLiteral("图像转灰度");
34 | }
35 | QString name() const override
36 | {
37 | return QStringLiteral("图像转灰度");
38 | }
39 | virtual QString modelName() const
40 | {
41 | return QStringLiteral("图像转灰度");
42 | }
43 | unsigned int
44 | nPorts(PortType portType) const override;
45 |
46 | NodeDataType
47 | dataType(PortType portType, PortIndex portIndex) const override;
48 |
49 | std::shared_ptr
50 | outData(PortIndex port) override;
51 |
52 | void
53 | setInData(std::shared_ptr, int) override;
54 |
55 | QWidget*
56 | embeddedWidget() override { return Q_NULLPTR; }
57 |
58 | bool
59 | resizable() const override { return false; }
60 | NodeValidationState
61 | validationState() const override;
62 | QString
63 | validationMessage() const override;
64 | protected:
65 | bool RunTask();
66 |
67 | public:
68 | NodeValidationState modelValidationState = NodeValidationState::Warning;
69 | QString modelValidationError = QStringLiteral("图片输入未连接!");
70 | private:
71 | std::shared_ptr m_hImage;
72 |
73 | };
74 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageReduceDomainModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HImageReduceDomainModel.hpp"
2 |
3 | #include
4 | #include
5 | #include "DrawShapeView.hpp"
6 | #include "halconcpp/HalconCpp.h"
7 | #include "QJsonParser.hpp"
8 | using namespace HalconCpp;
9 |
10 |
11 | HImageReduceDomainModel::HImageReduceDomainModel()
12 | {
13 | m_hImage = std::make_shared();
14 | m_result = std::make_shared();
15 | btn_drawReg = new QPushButton(QStringLiteral("绘制区域"));
16 | m_region_data = std::make_shared();
17 | m_domain.GenEmptyRegion();
18 |
19 | connect(DrawShapeView::getInst(), SIGNAL(RegionComform(ShapeDataStruct)),
20 | this, SLOT(OnNewRegionData(ShapeDataStruct)));
21 |
22 | connect(btn_drawReg, &QPushButton::clicked, [=]()
23 | {
24 | QPixmap tmpPix;
25 | HImageViewWidget::HImageToQPixmap(*m_hImage->hImage(), tmpPix);
26 | DrawShapeView::getInst()->FitShowImage(tmpPix, *m_region_data);
27 | });
28 | }
29 |
30 | bool HImageReduceDomainModel::RunTask()
31 | {
32 | //Q_EMIT computingStarted();
33 | PortIndex const outPortIndex = 0;
34 | try
35 | {
36 | if ((int)m_region_data->shapePolygon.size() > 0)
37 | {
38 | HImage tmpImage;
39 | HalconCpp::ReduceDomain(*m_hImage->hImage(), m_domain, &tmpImage);
40 | m_result->setHImage(tmpImage);
41 | }
42 | else
43 | {
44 | m_result->setHImage(*m_hImage->hImage());
45 | }
46 | modelValidationState = NodeValidationState::Valid;
47 | modelValidationError = QString();
48 | }
49 | catch (...)
50 | {
51 | modelValidationState = NodeValidationState::Warning;
52 | modelValidationError = QStringLiteral("缺失或运行失败!");
53 | }
54 |
55 | Q_EMIT dataUpdated(outPortIndex);
56 | return true;
57 | }
58 |
59 | void HImageReduceDomainModel::OnNewRegionData(ShapeDataStruct _data)
60 | {
61 | *m_region_data = std::move(_data);
62 | m_domain = DrawShapeView::GetHRegionFromData(*m_region_data);
63 |
64 | RunTask();
65 | }
66 |
67 | unsigned int HImageReduceDomainModel::
68 | nPorts(PortType portType) const
69 | {
70 | unsigned int result = 1;
71 |
72 | switch (portType)
73 | {
74 | case PortType::In:
75 | result = 1;
76 | break;
77 |
78 | case PortType::Out:
79 | result = 1;
80 |
81 | default:
82 | break;
83 | }
84 |
85 | return result;
86 | }
87 |
88 | NodeValidationState HImageReduceDomainModel::validationState() const
89 | {
90 | return modelValidationState;
91 | }
92 |
93 | QString HImageReduceDomainModel::validationMessage() const
94 | {
95 | return modelValidationError;
96 | }
97 |
98 | QJsonObject HImageReduceDomainModel::save() const
99 | {
100 | QJsonObject result = NodeDataModel::save();
101 | result.insert("m_region_data", QJsonConvert::convertToJson(*m_region_data));
102 | return result;
103 | }
104 |
105 | void HImageReduceDomainModel::restore(QJsonObject const& _json)
106 | {
107 | QJsonConvert::convertFromJson(_json.value("m_region_data").toObject(), *m_region_data);
108 | m_domain = DrawShapeView::GetHRegionFromData(*m_region_data);
109 | }
110 |
111 | NodeDataType
112 | HImageReduceDomainModel::dataType(PortType, PortIndex) const
113 | {
114 | return HImageData().type();
115 | }
116 |
117 | void HImageReduceDomainModel::
118 | setInData(std::shared_ptr data, int portIndex)
119 | {
120 | auto hImageData =
121 | std::dynamic_pointer_cast(data);
122 | if (hImageData == nullptr)
123 | {
124 | return;
125 | }
126 | switch (portIndex)
127 | {
128 | case 0:
129 | m_hImage->setHImage(*hImageData->hImage());
130 | break;
131 | default:
132 | break;
133 | }
134 | RunTask();
135 | }
136 |
137 | std::shared_ptr
138 | HImageReduceDomainModel::
139 | outData(PortIndex)
140 | {
141 | return std::dynamic_pointer_cast(m_result);
142 | }
143 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageReduceDomainModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "DataModelRegistry.hpp"
9 | #include "NodeDataModel.hpp"
10 | #include "halconcpp/HalconCpp.h"
11 | #include "HImageData.hpp"
12 | #include "HImageViewWidget.hpp"
13 | #include "DrawShapeView.hpp"
14 |
15 | using QtNodes::PortType;
16 | using QtNodes::PortIndex;
17 | using QtNodes::NodeData;
18 | using QtNodes::NodeDataType;
19 | using QtNodes::NodeDataModel;
20 | using QtNodes::NodeValidationState;
21 | using namespace HalconCpp;
22 | /**
23 | * \brief halcon 图像rgb2gray节点
24 | */
25 | class HImageReduceDomainModel :public NodeDataModel
26 | {
27 | Q_OBJECT
28 | public:
29 | HImageReduceDomainModel();
30 | virtual ~HImageReduceDomainModel() {}
31 |
32 | public:
33 | QString caption() const override
34 | {
35 | return QStringLiteral("选区掩膜");
36 | }
37 | QString name() const override
38 | {
39 | return QStringLiteral("选区掩膜");
40 | }
41 | virtual QString modelName() const
42 | {
43 | return QStringLiteral("选区掩膜");
44 | }
45 | unsigned int
46 | nPorts(PortType portType) const override;
47 |
48 | NodeDataType
49 | dataType(PortType portType, PortIndex portIndex) const override;
50 |
51 | std::shared_ptr
52 | outData(PortIndex port) override;
53 |
54 | void
55 | setInData(std::shared_ptr, int) override;
56 |
57 | QWidget*
58 | embeddedWidget() override { return btn_drawReg; }
59 |
60 | bool
61 | resizable() const override { return false; }
62 | NodeValidationState
63 | validationState() const override;
64 | QString
65 | validationMessage() const override;
66 | QJsonObject save() const override;
67 | void restore(QJsonObject const&) override;
68 | protected:
69 | bool RunTask();
70 |
71 | public slots:
72 | void OnNewRegionData(ShapeDataStruct _data);
73 | public:
74 | NodeValidationState modelValidationState = NodeValidationState::Warning;
75 | QString modelValidationError = QStringLiteral("图片输入未连接!");
76 | private:
77 | //HWindow* h_window;
78 | QPushButton* btn_drawReg;
79 | HRegion m_domain;
80 | std::shared_ptr m_region_data;
81 | std::shared_ptr m_hImage;
82 | std::shared_ptr m_result;
83 | };
84 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageShowModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HImageShowModel.hpp"
2 | #include
3 | #include
4 | #include
5 |
6 | HImageShowModel::HImageShowModel()
7 | {
8 | m_image_view = new HImageViewWidget();
9 | m_image_view->installEventFilter(this);
10 | m_image_view->resize(200, 200);
11 | m_hImage = std::make_shared();
12 | m_hRegion = std::make_shared();
13 | #ifdef SHOWHALCON_OBJ
14 | h_window = new HWindow(0, 0, 512, 512, nullptr, "visible", "");
15 | #endif
16 |
17 | }
18 |
19 | bool HImageShowModel::RunTask()
20 | {
21 | PortIndex const outPortIndex = 0;
22 |
23 | try
24 | {
25 | m_image_view->showImage(*m_hImage->hImage());
26 | modelValidationState = NodeValidationState::Valid;
27 | modelValidationError = QString();
28 |
29 | }
30 | catch (...)
31 | {
32 | modelValidationState = NodeValidationState::Warning;
33 | modelValidationError = QStringLiteral("缺失或运行失败!");
34 | }
35 |
36 | Q_EMIT dataUpdated(outPortIndex);
37 |
38 | return true;
39 | }
40 |
41 | unsigned int HImageShowModel::
42 | nPorts(PortType portType) const
43 | {
44 | unsigned int result = 1;
45 |
46 | switch (portType)
47 | {
48 | case PortType::In:
49 | result = 2;
50 | break;
51 |
52 | case PortType::Out:
53 | result = 2;
54 |
55 | default:
56 | break;
57 | }
58 |
59 | return result;
60 | }
61 |
62 | NodeValidationState HImageShowModel::validationState() const
63 | {
64 | return modelValidationState;
65 | }
66 |
67 | QString HImageShowModel::validationMessage() const
68 | {
69 | return modelValidationError;
70 | }
71 |
72 | bool HImageShowModel::eventFilter(QObject* object, QEvent* event)
73 | {
74 |
75 | return false;
76 | }
77 |
78 | NodeDataType
79 | HImageShowModel::dataType(PortType, PortIndex index) const
80 | {
81 | switch (index)
82 | {
83 | case 0:
84 | return HImageData().type();
85 | break;
86 | case 1:
87 | return HRegionData().type();
88 | break;
89 | }
90 | return HImageData().type();
91 | }
92 |
93 | void HImageShowModel::
94 | setInData(std::shared_ptr data, int portIndex)
95 | {
96 | if (data == nullptr)
97 | {
98 | return;
99 | }
100 | if (data->type() == m_hImage->type())
101 | {
102 | auto dataPtr = std::dynamic_pointer_cast(data);
103 | if (!dataPtr->hImage()->IsInitialized())
104 | {
105 | return;
106 | }
107 | m_hImage->setHImage(*dataPtr->hImage());
108 | #ifdef SHOWHALCON_OBJ
109 | h_window->ClearWindow();
110 | h_window->SetPart(HTuple(0), HTuple(0), m_hImage->hImage()->Height(), m_hImage->hImage()->Width());
111 | HTuple chanels = m_hImage->hImage()->CountChannels();
112 | if (chanels == 1)
113 | {
114 | h_window->DispImage(*m_hImage->hImage());
115 | }
116 | else
117 | {
118 | h_window->DispColor(*m_hImage->hImage());
119 | }
120 | #endif
121 | }
122 | else if (data->type() == m_hRegion->type())
123 | {
124 | auto dataPtr = std::dynamic_pointer_cast(data);
125 | if (!dataPtr->hRegion()->IsInitialized())
126 | {
127 | return;
128 | }
129 | m_hRegion->setHRegion(*dataPtr->hRegion());
130 | m_hRegion->setSize(dataPtr->getSize());
131 |
132 | HImage tmpImg = m_hRegion->hRegion()->RegionToBin(255, 0,
133 | m_hRegion->getSize().width(), m_hRegion->getSize().height());
134 | m_hImage->setHImage(tmpImg);
135 | }
136 | RunTask();
137 | }
138 |
139 | std::shared_ptr
140 | HImageShowModel::
141 | outData(PortIndex index)
142 | {
143 | switch (index)
144 | {
145 | case 0:
146 | return std::dynamic_pointer_cast(m_hImage);
147 | break;
148 | case 1:
149 | return std::dynamic_pointer_cast(m_hRegion);
150 | break;
151 | }
152 | return std::dynamic_pointer_cast(m_hImage);
153 | }
154 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageShowModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "DataModelRegistry.hpp"
8 | #include "NodeDataModel.hpp"
9 | #include "halconcpp/HalconCpp.h"
10 | #include "HImageData.hpp"
11 | #include "HRegionData.hpp"
12 | #include "HImageViewWidget.hpp"
13 |
14 | using QtNodes::PortType;
15 | using QtNodes::PortIndex;
16 | using QtNodes::NodeData;
17 | using QtNodes::NodeDataType;
18 | using QtNodes::NodeDataModel;
19 | using QtNodes::NodeValidationState;
20 | using namespace HalconCpp;
21 |
22 | //#define SHOWHALCON_OBJ
23 |
24 | /**
25 | * \brief halcon 图像输入节点
26 | */
27 | class HImageShowModel :public NodeDataModel
28 | {
29 | Q_OBJECT
30 | public:
31 | HImageShowModel();
32 | virtual ~HImageShowModel() {}
33 |
34 | public:
35 | QString caption() const override
36 | {
37 | return QStringLiteral("图像显示");
38 | }
39 | QString name() const override
40 | {
41 | return QStringLiteral("图像显示");
42 | }
43 | virtual QString modelName() const
44 | {
45 | return QStringLiteral("图像显示");
46 | }
47 | unsigned int
48 | nPorts(PortType portType) const override;
49 |
50 | NodeDataType
51 | dataType(PortType portType, PortIndex portIndex) const override;
52 |
53 | std::shared_ptr
54 | outData(PortIndex port) override;
55 |
56 | void
57 | setInData(std::shared_ptr, int) override;
58 |
59 | QWidget*
60 | embeddedWidget() override { return m_image_view; }
61 |
62 | bool
63 | resizable() const override { return true; }
64 | NodeValidationState
65 | validationState() const override;
66 | QString
67 | validationMessage() const override;
68 | protected:
69 | bool RunTask();
70 | bool eventFilter(QObject* watched, QEvent* event) override;
71 | public:
72 | NodeValidationState modelValidationState = NodeValidationState::Warning;
73 | QString modelValidationError = QStringLiteral("图片输入未连接!");
74 | private:
75 | #ifdef SHOWHALCON_OBJ
76 | HWindow* h_window;
77 | #endif
78 |
79 | std::shared_ptr m_hImage;
80 | std::shared_ptr m_hRegion;
81 | HImageViewWidget* m_image_view;
82 | };
83 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageSplitChanelModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HImageSplitChanelModel.hpp"
2 |
3 | #include
4 |
5 | #include "halconcpp/HalconCpp.h"
6 |
7 | using namespace HalconCpp;
8 |
9 | HImageSplitChanelModel::HImageSplitChanelModel()
10 | {
11 | m_hImage = std::make_shared();
12 | }
13 |
14 | bool HImageSplitChanelModel::RunTask()
15 | {
16 |
17 | auto img1 = m_hImage.lock();
18 | try
19 | {
20 | if (img1)
21 | {
22 | HTuple imgChanels = img1->hImage()->CountChannels();
23 | if (imgChanels == 3)
24 | {
25 | HImage chanR, chanG, chanB;
26 | Decompose3(*img1->hImage(), &chanR, &chanG, &chanB);
27 | if (m_resultR == nullptr)
28 | {
29 | m_resultR = std::make_shared(chanR);
30 | }
31 | if (m_resultG == nullptr)
32 | {
33 | m_resultG = std::make_shared(chanG);
34 | }
35 | if (m_resultB == nullptr)
36 | {
37 | m_resultB = std::make_shared(chanB);
38 | }
39 | m_resultR->setHImage(chanR);
40 | m_resultG->setHImage(chanG);
41 | m_resultB->setHImage(chanB);
42 | }
43 | else if (imgChanels == 1)
44 | {
45 | m_resultR = std::shared_ptr(m_hImage);
46 | m_resultG = std::shared_ptr(m_hImage);
47 | m_resultB = std::shared_ptr(m_hImage);
48 | }
49 | modelValidationState = NodeValidationState::Valid;
50 | modelValidationError = QString();
51 | }
52 | }
53 | catch (...)
54 | {
55 | modelValidationState = NodeValidationState::Warning;
56 | modelValidationError = QStringLiteral("缺失或运行失败!");
57 | m_resultR.reset();
58 | m_resultG.reset();
59 | m_resultB.reset();
60 | }
61 |
62 | Q_EMIT dataUpdated((PortIndex)0);
63 | Q_EMIT dataUpdated((PortIndex)1);
64 | Q_EMIT dataUpdated((PortIndex)2);
65 |
66 | return true;
67 | }
68 |
69 | unsigned int HImageSplitChanelModel::
70 | nPorts(PortType portType) const
71 | {
72 | unsigned int result = 1;
73 |
74 | switch (portType)
75 | {
76 | case PortType::In:
77 | result = 1;
78 | break;
79 |
80 | case PortType::Out:
81 | result = 3;
82 |
83 | default:
84 | break;
85 | }
86 |
87 | return result;
88 | }
89 |
90 | NodeValidationState HImageSplitChanelModel::validationState() const
91 | {
92 | return modelValidationState;
93 | }
94 |
95 | QString HImageSplitChanelModel::validationMessage() const
96 | {
97 | return modelValidationError;
98 | }
99 |
100 | NodeDataType
101 | HImageSplitChanelModel::dataType(PortType, PortIndex) const
102 | {
103 | return HImageData().type();
104 | }
105 |
106 | void HImageSplitChanelModel::
107 | setInData(std::shared_ptr data, int portIndex)
108 | {
109 | auto hImageData =
110 | std::dynamic_pointer_cast(data);
111 |
112 | switch (portIndex)
113 | {
114 | case 0:
115 | m_hImage = hImageData;
116 | break;
117 | default:
118 | break;
119 | }
120 | RunTask();
121 | }
122 |
123 | std::shared_ptr
124 | HImageSplitChanelModel::
125 | outData(PortIndex index)
126 | {
127 |
128 | if (index == 0)
129 | {
130 | return std::static_pointer_cast(m_resultR);
131 | }
132 | else if (index == 1)
133 | {
134 | return std::static_pointer_cast(m_resultG);
135 | }
136 | else
137 | {
138 | return std::static_pointer_cast(m_resultB);
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageSplitChanelModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "DataModelRegistry.hpp"
8 | #include "NodeDataModel.hpp"
9 | #include "halconcpp/HalconCpp.h"
10 | #include "HImageData.hpp"
11 | #include "HImageViewWidget.hpp"
12 |
13 | using QtNodes::PortType;
14 | using QtNodes::PortIndex;
15 | using QtNodes::NodeData;
16 | using QtNodes::NodeDataType;
17 | using QtNodes::NodeDataModel;
18 | using QtNodes::NodeValidationState;
19 | using namespace HalconCpp;
20 | /**
21 | * \brief halcon 图像rgb2gray节点
22 | */
23 | class HImageSplitChanelModel :public NodeDataModel
24 | {
25 | Q_OBJECT
26 | public:
27 | HImageSplitChanelModel();
28 | virtual ~HImageSplitChanelModel() {}
29 |
30 | public:
31 | QString caption() const override
32 | {
33 | return QStringLiteral("SplitChanel");
34 | }
35 | QString name() const override
36 | {
37 | return QStringLiteral("图像通道拆分");
38 | }
39 | virtual QString modelName() const
40 | {
41 | return QStringLiteral("通道拆分");
42 | }
43 | unsigned int
44 | nPorts(PortType portType) const override;
45 |
46 | NodeDataType
47 | dataType(PortType portType, PortIndex portIndex) const override;
48 |
49 | std::shared_ptr
50 | outData(PortIndex port) override;
51 |
52 | void
53 | setInData(std::shared_ptr, int) override;
54 |
55 | QWidget*
56 | embeddedWidget() override { return Q_NULLPTR; }
57 |
58 | bool
59 | resizable() const override { return true; }
60 | NodeValidationState
61 | validationState() const override;
62 | QString
63 | validationMessage() const override;
64 | protected:
65 | bool RunTask();
66 |
67 | public:
68 | NodeValidationState modelValidationState = NodeValidationState::Warning;
69 | QString modelValidationError = QStringLiteral("图片输入未连接!");
70 | private:
71 | std::weak_ptr m_hImage;
72 | std::shared_ptr m_resultR;
73 | std::shared_ptr m_resultG;
74 | std::shared_ptr m_resultB;
75 | };
76 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageThresholdModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "DataModelRegistry.hpp"
8 | #include "NodeDataModel.hpp"
9 | #include "halconcpp/HalconCpp.h"
10 | #include "HImageData.hpp"
11 | #include "HRegionData.hpp"
12 | #include "HImageViewWidget.hpp"
13 |
14 | using QtNodes::PortType;
15 | using QtNodes::PortIndex;
16 | using QtNodes::NodeData;
17 | using QtNodes::NodeDataType;
18 | using QtNodes::NodeDataModel;
19 | using QtNodes::NodeValidationState;
20 | using namespace HalconCpp;
21 | /**
22 | * \brief halcon 图像rgb2gray节点
23 | */
24 | class HImageThresholdModel :public NodeDataModel
25 | {
26 | Q_OBJECT
27 | public:
28 | HImageThresholdModel();
29 | virtual ~HImageThresholdModel() = default;
30 |
31 | public:
32 | QString caption() const override
33 | {
34 | return QStringLiteral("二值化节点");
35 | }
36 | QString name() const override
37 | {
38 | return QStringLiteral("二值化节点");
39 | }
40 | virtual QString modelName() const
41 | {
42 | return QStringLiteral("二值化节点");
43 | }
44 | unsigned int
45 | nPorts(PortType portType) const override;
46 |
47 | NodeDataType
48 | dataType(PortType portType, PortIndex portIndex) const override;
49 |
50 | std::shared_ptr
51 | outData(PortIndex port) override;
52 |
53 | void
54 | setInData(std::shared_ptr, int) override;
55 |
56 | QWidget*
57 | embeddedWidget() override { return m_widget; }
58 |
59 | bool
60 | resizable() const override { return true; }
61 | NodeValidationState
62 | validationState() const override;
63 | QString
64 | validationMessage() const override;
65 |
66 | QJsonObject save() const override;
67 |
68 | void restore(QJsonObject const&) override;
69 |
70 | protected:
71 | bool RunTask();
72 | bool eventFilter(QObject* watched, QEvent* event) override;
73 | public:
74 | NodeValidationState modelValidationState = NodeValidationState::Warning;
75 | QString modelValidationError = QStringLiteral("图片输入未连接!");
76 | private:
77 | std::shared_ptr m_hImage;
78 | std::shared_ptr m_domain;
79 | std::shared_ptr m_result;
80 | QSlider* m_minGraySlider;
81 | QSlider* m_maxGraySlider;
82 | QWidget* m_widget;
83 | };
84 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HImageViewWidget.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "halconcpp/HalconCpp.h"
9 | using namespace HalconCpp;
10 |
11 | class HImageViewWidget
12 | :public QLabel
13 | {
14 | public:
15 | HImageViewWidget(QWidget* parent = Q_NULLPTR);
16 | virtual ~HImageViewWidget() {}
17 | void showImage(HImage const& _himg);
18 | public:
19 | static void HImageToQPixmap(HImage const& _img, QPixmap& tar_img);
20 | static bool QImage2HImage(QImage& from, HalconCpp::HImage& to);
21 | static void QPixmapToHRegion(QPixmap const& _pix, HRegion& tar_img);
22 | protected:
23 | void paintEvent(QPaintEvent* event) override;
24 | private:
25 | HImage cur_image;
26 | QPixmap* cur_pixmap;
27 | // 实例化画家对象,this指定的是绘图设备
28 | QPainter painter;
29 | };
30 |
31 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HObjectData.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "NodeDataModel.hpp"
6 | #include "halconcpp/HalconCpp.h"
7 |
8 | using QtNodes::NodeData;
9 | using QtNodes::NodeDataType;
10 | using namespace HalconCpp;
11 |
12 | class HObjecData :public NodeData
13 | {
14 | public:
15 | HObjecData()
16 | {
17 | m_hObject = HObject();
18 | }
19 | HObjecData(HObject& _obj)
20 | {
21 | if (_obj.IsInitialized())
22 | {
23 | m_hObject = _obj;
24 | }
25 | }
26 | virtual ~HObjecData()
27 | {
28 |
29 | }
30 | NodeDataType type() const override
31 | {
32 | return { "HObject","data" };
33 | }
34 |
35 | HObject* hObject() { return &m_hObject; }
36 |
37 | void setObject(HObject const& _obj)
38 | {
39 | if (!_obj.IsInitialized())
40 | {
41 | return;
42 | }
43 | m_hObject = _obj;
44 | }
45 | private:
46 | HObject m_hObject;
47 | };
48 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HRegionConnectModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HRegionConnectModel.hpp"
2 | #include
3 |
4 | #include "halconcpp/HalconCpp.h"
5 |
6 | using namespace HalconCpp;
7 |
8 | HRegionConnectModel::HRegionConnectModel()
9 | {
10 | m_InRegion = std::make_shared();
11 | m_result = std::make_shared();
12 |
13 | }
14 |
15 | bool HRegionConnectModel::RunTask()
16 | {
17 | PortIndex const outPortIndex = 0;
18 | if (m_InRegion->hRegion() == nullptr)
19 | {
20 | return false;
21 | }
22 | try
23 | {
24 | m_result->setHRegion(m_InRegion->hRegion()->Connection());
25 |
26 | m_result->setSize(m_InRegion->getSize());
27 |
28 | modelValidationState = NodeValidationState::Valid;
29 | modelValidationError = QString();
30 | }
31 | catch (...)
32 | {
33 | modelValidationState = NodeValidationState::Warning;
34 | modelValidationError = QStringLiteral("缺失或运行失败!");
35 | }
36 |
37 | Q_EMIT dataUpdated(outPortIndex);
38 |
39 | return true;
40 | }
41 |
42 | bool HRegionConnectModel::eventFilter(QObject* watched, QEvent* event)
43 | {
44 |
45 | return false;
46 | }
47 |
48 | unsigned int HRegionConnectModel::
49 | nPorts(PortType portType) const
50 | {
51 | unsigned int result = 1;
52 |
53 | switch (portType)
54 | {
55 | case PortType::In:
56 | result = 1;
57 | break;
58 |
59 | case PortType::Out:
60 | result = 1;
61 |
62 | default:
63 | break;
64 | }
65 |
66 | return result;
67 | }
68 |
69 | NodeValidationState HRegionConnectModel::validationState() const
70 | {
71 | return modelValidationState;
72 | }
73 |
74 | QString HRegionConnectModel::validationMessage() const
75 | {
76 | return modelValidationError;
77 | }
78 |
79 | NodeDataType
80 | HRegionConnectModel::dataType(PortType, PortIndex) const
81 | {
82 | return HRegionData().type();
83 | }
84 |
85 | void HRegionConnectModel::
86 | setInData(std::shared_ptr data, int portIndex)
87 | {
88 | auto hRegionData =
89 | std::dynamic_pointer_cast(data);
90 | if (hRegionData == nullptr)
91 | {
92 | return;
93 | }
94 | switch (portIndex)
95 | {
96 | case 0:
97 | m_InRegion->setHRegion(*hRegionData->hRegion());
98 | m_InRegion->setSize(hRegionData->getSize());
99 | break;
100 | default:
101 | break;
102 | }
103 | RunTask();
104 | }
105 |
106 | std::shared_ptr
107 | HRegionConnectModel::
108 | outData(PortIndex index)
109 | {
110 | switch (index)
111 | {
112 | case 0:
113 | return std::dynamic_pointer_cast(m_result);
114 | break;
115 | case 1:
116 | break;
117 | default:
118 | break;
119 | }
120 | return std::dynamic_pointer_cast(m_result);
121 | }
122 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HRegionConnectModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "DataModelRegistry.hpp"
9 | #include "NodeDataModel.hpp"
10 | #include "halconcpp/HalconCpp.h"
11 | #include "HImageData.hpp"
12 | #include "HRegionData.hpp"
13 | #include "HImageViewWidget.hpp"
14 |
15 | using QtNodes::PortType;
16 | using QtNodes::PortIndex;
17 | using QtNodes::NodeData;
18 | using QtNodes::NodeDataType;
19 | using QtNodes::NodeDataModel;
20 | using QtNodes::NodeValidationState;
21 | using namespace HalconCpp;
22 | /**
23 | * \brief halcon 图像rgb2gray节点
24 | */
25 | class HRegionConnectModel :public NodeDataModel
26 | {
27 | Q_OBJECT
28 | public:
29 | HRegionConnectModel();
30 | virtual ~HRegionConnectModel() {}
31 |
32 | public:
33 | QString caption() const override
34 | {
35 | return QStringLiteral("非联通区域");
36 | }
37 | QString name() const override
38 | {
39 | return QStringLiteral("非联通区域");
40 | }
41 | virtual QString modelName() const
42 | {
43 | return QStringLiteral("非联通区域");
44 | }
45 | unsigned int
46 | nPorts(PortType portType) const override;
47 |
48 | NodeDataType
49 | dataType(PortType portType, PortIndex portIndex) const override;
50 |
51 | std::shared_ptr
52 | outData(PortIndex port) override;
53 |
54 | void
55 | setInData(std::shared_ptr, int) override;
56 |
57 | QWidget*
58 | embeddedWidget() override { return nullptr; }
59 |
60 | bool
61 | resizable() const override { return false; }
62 | NodeValidationState
63 | validationState() const override;
64 | QString
65 | validationMessage() const override;
66 |
67 | protected:
68 | bool RunTask();
69 | bool eventFilter(QObject* watched, QEvent* event) override;
70 | public:
71 | NodeValidationState modelValidationState = NodeValidationState::Warning;
72 | QString modelValidationError = QStringLiteral("区域输入未连接!");
73 | private:
74 | std::shared_ptr m_InRegion;
75 | std::shared_ptr m_result;
76 | };
77 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HRegionData.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "NodeDataModel.hpp"
6 | #include "halconcpp/HalconCpp.h"
7 |
8 | using QtNodes::NodeData;
9 | using QtNodes::NodeDataType;
10 | using namespace HalconCpp;
11 |
12 | class HRegionData :public NodeData
13 | {
14 | public:
15 | HRegionData()
16 | {
17 | m_hRegion = HRegion();
18 | }
19 | HRegionData(HRegion& _hregion)
20 | {
21 | if (_hregion.IsInitialized())
22 | {
23 | m_hRegion = _hregion;
24 | }
25 | }
26 | virtual ~HRegionData()
27 | {
28 |
29 | }
30 | NodeDataType type() const override
31 | {
32 | return { "HRegion","Region" };
33 | }
34 | HRegion* hRegion() { return &m_hRegion; }
35 | void setHRegion(HRegion const& _hregion)
36 | {
37 | if (!_hregion.IsInitialized())
38 | {
39 | return;
40 | }
41 | m_hRegion = _hregion;
42 | }
43 | QSize getSize()
44 | {
45 | return m_size;
46 | }
47 | void setSize(QSize const& _size)
48 | {
49 | m_size = _size;
50 | }
51 | private:
52 | HRegion m_hRegion;
53 | QSize m_size;
54 | };
55 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HRegionDifferenceModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HRegionDifferenceModel.hpp"
2 | #include
3 |
4 | #include "halconcpp/HalconCpp.h"
5 |
6 | using namespace HalconCpp;
7 |
8 | HRegionDifferenceModel::HRegionDifferenceModel()
9 | {
10 | m_InRegion = std::make_shared();
11 | m_result = std::make_shared();
12 | m_InRegionDiv = std::make_shared();
13 |
14 | }
15 |
16 | QString HRegionDifferenceModel::portCaption(PortType port, PortIndex port_index) const
17 | {
18 | if (port == PortType::In)
19 | {
20 | switch (port_index)
21 | {
22 | case 0:
23 | return "Ori";
24 | break;
25 | case 1:
26 | return "Div";
27 | break;
28 | }
29 | }
30 | else if (port == PortType::Out)
31 | {
32 | switch (port_index)
33 | {
34 | case 0:
35 | return "Res";
36 | break;
37 | }
38 | }
39 |
40 | return HRegionDifferenceModel::portCaption(port, port_index);
41 | }
42 |
43 | bool HRegionDifferenceModel::RunTask()
44 | {
45 | PortIndex const outPortIndex = 0;
46 | if (m_InRegion->hRegion() == nullptr)
47 | {
48 | return false;
49 | }
50 | try
51 | {
52 | HalconCpp::Difference(*m_InRegion->hRegion(), *m_InRegionDiv->hRegion(), m_result->hRegion());
53 |
54 | m_result->setSize(m_InRegion->getSize());
55 |
56 | modelValidationState = NodeValidationState::Valid;
57 | modelValidationError = QString();
58 | }
59 | catch (...)
60 | {
61 | modelValidationState = NodeValidationState::Warning;
62 | modelValidationError = QStringLiteral("缺失或运行失败!");
63 | }
64 |
65 | Q_EMIT dataUpdated(outPortIndex);
66 |
67 | return true;
68 | }
69 |
70 | bool HRegionDifferenceModel::eventFilter(QObject* watched, QEvent* event)
71 | {
72 |
73 | return false;
74 | }
75 |
76 | unsigned int HRegionDifferenceModel::
77 | nPorts(PortType portType) const
78 | {
79 | unsigned int result = 1;
80 |
81 | switch (portType)
82 | {
83 | case PortType::In:
84 | result = 2;
85 | break;
86 |
87 | case PortType::Out:
88 | result = 1;
89 |
90 | default:
91 | break;
92 | }
93 |
94 | return result;
95 | }
96 |
97 | NodeValidationState HRegionDifferenceModel::validationState() const
98 | {
99 | return modelValidationState;
100 | }
101 |
102 | QString HRegionDifferenceModel::validationMessage() const
103 | {
104 | return modelValidationError;
105 | }
106 |
107 | NodeDataType
108 | HRegionDifferenceModel::dataType(PortType, PortIndex) const
109 | {
110 | return HRegionData().type();
111 | }
112 |
113 | void HRegionDifferenceModel::
114 | setInData(std::shared_ptr data, int portIndex)
115 | {
116 | auto hRegionData =
117 | std::dynamic_pointer_cast(data);
118 | if (hRegionData == nullptr)
119 | {
120 | return;
121 | }
122 | switch (portIndex)
123 | {
124 | case 0:
125 | m_InRegion->setHRegion(*hRegionData->hRegion());
126 | m_InRegion->setSize(hRegionData->getSize());
127 | break;
128 | case 1:
129 | m_InRegionDiv->setHRegion(*hRegionData->hRegion());
130 | m_InRegionDiv->setSize(hRegionData->getSize());
131 | break;
132 | default:
133 | break;
134 | }
135 | RunTask();
136 | }
137 |
138 | std::shared_ptr
139 | HRegionDifferenceModel::
140 | outData(PortIndex index)
141 | {
142 | switch (index)
143 | {
144 | case 0:
145 | return std::dynamic_pointer_cast(m_result);
146 | break;
147 | case 1:
148 | break;
149 | default:
150 | break;
151 | }
152 | return std::dynamic_pointer_cast(m_result);
153 | }
154 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HRegionDifferenceModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "DataModelRegistry.hpp"
9 | #include "NodeDataModel.hpp"
10 | #include "halconcpp/HalconCpp.h"
11 | #include "HImageData.hpp"
12 | #include "HRegionData.hpp"
13 | #include "HImageViewWidget.hpp"
14 |
15 | using QtNodes::PortType;
16 | using QtNodes::PortIndex;
17 | using QtNodes::NodeData;
18 | using QtNodes::NodeDataType;
19 | using QtNodes::NodeDataModel;
20 | using QtNodes::NodeValidationState;
21 | using namespace HalconCpp;
22 | /**
23 | * \brief halcon 图像rgb2gray节点
24 | */
25 | class HRegionDifferenceModel :public NodeDataModel
26 | {
27 | Q_OBJECT
28 | public:
29 | HRegionDifferenceModel();
30 | virtual ~HRegionDifferenceModel() {}
31 |
32 | public:
33 | QString caption() const override
34 | {
35 | return QStringLiteral("相减区域");
36 | }
37 | QString name() const override
38 | {
39 | return QStringLiteral("相减区域");
40 | }
41 | virtual QString modelName() const
42 | {
43 | return QStringLiteral("相减区域");
44 | }
45 | unsigned int
46 | nPorts(PortType portType) const override;
47 |
48 | NodeDataType
49 | dataType(PortType portType, PortIndex portIndex) const override;
50 |
51 | std::shared_ptr
52 | outData(PortIndex port) override;
53 |
54 | void
55 | setInData(std::shared_ptr, int) override;
56 |
57 | QWidget*
58 | embeddedWidget() override { return nullptr; }
59 |
60 | bool
61 | resizable() const override { return false; }
62 | NodeValidationState
63 | validationState() const override;
64 | QString
65 | validationMessage() const override;
66 | bool portCaptionVisible(PortType, PortIndex) const override { return true; }
67 | QString portCaption(PortType, PortIndex) const override;
68 | protected:
69 | bool RunTask();
70 | bool eventFilter(QObject* watched, QEvent* event) override;
71 | public:
72 | NodeValidationState modelValidationState = NodeValidationState::Warning;
73 | QString modelValidationError = QStringLiteral("区域输入未连接!");
74 | private:
75 | std::shared_ptr m_InRegion;
76 | std::shared_ptr m_InRegionDiv;
77 | std::shared_ptr m_result;
78 | };
79 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HRegionFillUpShapeModel.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "DataModelRegistry.hpp"
12 | #include "NodeDataModel.hpp"
13 | #include "halconcpp/HalconCpp.h"
14 | #include "HRegionData.hpp"
15 | #include "HImageViewWidget.hpp"
16 |
17 | using QtNodes::PortType;
18 | using QtNodes::PortIndex;
19 | using QtNodes::NodeData;
20 | using QtNodes::NodeDataType;
21 | using QtNodes::NodeDataModel;
22 | using QtNodes::NodeValidationState;
23 | using namespace HalconCpp;
24 | /**
25 | * \brief halcon 图像rgb2gray节点
26 | */
27 | class HRegionFillUpShapeModel :public NodeDataModel
28 | {
29 | Q_OBJECT
30 | public:
31 | HRegionFillUpShapeModel();
32 | virtual ~HRegionFillUpShapeModel() {}
33 |
34 | public:
35 | QString caption() const override
36 | {
37 | return QStringLiteral("填充区域");
38 | }
39 | QString name() const override
40 | {
41 | return QStringLiteral("填充区域");
42 | }
43 | virtual QString modelName() const
44 | {
45 | return QStringLiteral("填充区域");
46 | }
47 | unsigned int
48 | nPorts(PortType portType) const override;
49 |
50 | NodeDataType
51 | dataType(PortType portType, PortIndex portIndex) const override;
52 |
53 | std::shared_ptr
54 | outData(PortIndex port) override;
55 |
56 | void
57 | setInData(std::shared_ptr, int) override;
58 |
59 | QWidget*
60 | embeddedWidget() override { return m_widget; }
61 |
62 | bool
63 | resizable() const override { return false; }
64 | NodeValidationState
65 | validationState() const override;
66 | QString
67 | validationMessage() const override;
68 | QJsonObject save() const override;
69 |
70 | void restore(QJsonObject const&) override;
71 | protected:
72 | bool RunTask();
73 |
74 | public:
75 | NodeValidationState modelValidationState = NodeValidationState::Warning;
76 | QString modelValidationError = QStringLiteral("图片输入未连接!");
77 | private:
78 | QString m_feature;
79 | double m_minval = 0.0;
80 | double m_maxval = 100.0;
81 | std::shared_ptr m_hRegion;
82 | std::shared_ptr m_result;
83 | QWidget* m_widget;
84 | QVBoxLayout* m_host;
85 | QComboBox* m_combo_feature;
86 | QLineEdit* m_minvalEdit;
87 | QLineEdit* m_maxvalEdit;
88 | };
89 |
--------------------------------------------------------------------------------
/NodeEditorPro/examples/halcon/HRegionOpenCircleModel.cpp:
--------------------------------------------------------------------------------
1 | #include "HRegionOpenCircleModel.hpp"
2 | #include