17 |
18 | true
19 | true
20 | false
21 | false
22 |
23 |
24 |
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/java/io/github/deltacv/papervision/plugin/project/PaperVisionProject.java:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.plugin.project;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.JsonElement;
5 |
6 | public class PaperVisionProject {
7 |
8 | public long timestamp;
9 | public String path;
10 | public String name;
11 | public JsonElement json;
12 |
13 | private static final Gson gson = new Gson();
14 |
15 | public PaperVisionProject(long timestamp, String path, String name, JsonElement json) {
16 | this.timestamp = timestamp;
17 | this.path = path;
18 | this.name = name;
19 | this.json = json;
20 | }
21 |
22 | public static PaperVisionProject fromJson(String jsonString) {
23 | return gson.fromJson(jsonString, PaperVisionProject.class);
24 | }
25 |
26 | public String toJson() {
27 | return gson.toJson(this);
28 | }
29 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/java/io/github/deltacv/papervision/plugin/project/recovery/RecoveredProject.java:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.plugin.project.recovery;
2 |
3 | import com.google.gson.Gson;
4 | import io.github.deltacv.papervision.plugin.project.PaperVisionProject;
5 |
6 | public class RecoveredProject {
7 | public String originalProjectPath;
8 | public long date;
9 | public String hash;
10 | public PaperVisionProject project;
11 |
12 | private static final Gson gson = new Gson();
13 |
14 | public RecoveredProject(String originalProjectPath, long date, String hash, PaperVisionProject project) {
15 | this.originalProjectPath = originalProjectPath;
16 | this.date = date;
17 | this.hash = hash;
18 | this.project = project;
19 | }
20 |
21 | public String toJson() {
22 | return gson.toJson(this);
23 | }
24 |
25 | @Override
26 | public String toString() {
27 | return "RecoveredProject{" +
28 | "path='" + originalProjectPath + '\'' +
29 | ", date=" + date +
30 | ", hash='" + hash + '\'' +
31 | '}';
32 | }
33 |
34 | public static RecoveredProject fromJson(String json) {
35 | return gson.fromJson(json, RecoveredProject.class);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/java/io/github/deltacv/papervision/plugin/project/recovery/RecoveryDaemonClientMain.java:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.plugin.project.recovery;
2 |
3 | import org.java_websocket.client.WebSocketClient;
4 | import org.java_websocket.handshake.ServerHandshake;
5 | import org.slf4j.Logger;
6 | import org.slf4j.LoggerFactory;
7 |
8 | import java.net.URI;
9 | import java.net.URISyntaxException;
10 | import java.nio.file.Files;
11 | import java.nio.file.Path;
12 | import java.nio.file.Paths;
13 |
14 | public class RecoveryDaemonClientMain extends WebSocketClient {
15 |
16 | public static final int MAX_CONNECTION_ATTEMPTS_BEFORE_EXITING = 3;
17 |
18 | public static final Logger logger = LoggerFactory.getLogger(RecoveryDaemonClientMain.class);
19 |
20 | public RecoveryDaemonClientMain(int port) throws URISyntaxException {
21 | super(new URI("ws://127.0.0.1:" + port));
22 | }
23 |
24 | @Override
25 | public void onOpen(ServerHandshake handshakedata) {
26 | logger.info("Connected to recovery daemon server at port {}", uri.getPort());
27 | }
28 |
29 | @Override
30 | public void onMessage(String message) {
31 | try {
32 | RecoveryData recoveryData = RecoveryData.deserialize(message);
33 | Path recoveryPath = Paths.get(recoveryData.recoveryFolderPath);
34 |
35 | if (!Files.exists(recoveryPath)) {
36 | Files.createDirectories(recoveryPath);
37 | }
38 |
39 | Path recoveryFilePath = recoveryPath.resolve(recoveryData.recoveryFileName);
40 | Files.write(recoveryFilePath, recoveryData.projectData.toJson().getBytes());
41 | } catch (Exception e) {
42 | logger.error("Failed to save recovery data", e);
43 | }
44 | }
45 |
46 | @Override
47 | public void onClose(int code, String reason, boolean remote) {
48 | }
49 |
50 | @Override
51 | public void onError(Exception ex) {
52 | }
53 |
54 | public static void main(String[] args) {
55 | int port = args.length > 0 ? Integer.parseInt(args[0]) : 17112;
56 |
57 | RecoveryDaemonClientMain client = null;
58 | int connectionAttempts = 0;
59 |
60 | try {
61 | while(!Thread.interrupted()) {
62 | if(connectionAttempts >= MAX_CONNECTION_ATTEMPTS_BEFORE_EXITING) {
63 | logger.warn("Failed to connect to recovery daemon after " + MAX_CONNECTION_ATTEMPTS_BEFORE_EXITING + " attempts. Exiting...");
64 | System.exit(0);
65 | }
66 |
67 | if(client == null || client.isClosed()) {
68 | client = new RecoveryDaemonClientMain(port);
69 | client.connect();
70 | connectionAttempts += 1;
71 | }
72 |
73 | Thread.sleep(100);
74 | }
75 | } catch (URISyntaxException e) {
76 | throw new RuntimeException(e);
77 | } catch(InterruptedException ignored) { }
78 | }
79 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/java/io/github/deltacv/papervision/plugin/project/recovery/RecoveryData.java:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.plugin.project.recovery;
2 |
3 | import com.google.gson.Gson;
4 |
5 | public class RecoveryData {
6 |
7 | public String recoveryFolderPath;
8 | public String recoveryFileName;
9 | public RecoveredProject projectData;
10 |
11 | private static final Gson gson = new Gson();
12 |
13 | public RecoveryData(String recoveryFolderPath, String recoveryFileName, RecoveredProject projectData) {
14 | this.recoveryFolderPath = recoveryFolderPath;
15 | this.recoveryFileName = recoveryFileName;
16 | this.projectData = projectData;
17 | }
18 |
19 | public static String serialize(RecoveryData data) {
20 | return gson.toJson(data);
21 | }
22 |
23 | public static RecoveryData deserialize(String json) {
24 | return gson.fromJson(json, RecoveryData.class);
25 | }
26 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/eocvsim/PaperVisionDefaultPipeline.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.eocvsim
20 |
21 | import com.github.serivesmejia.eocvsim.util.loggerForThis
22 | import com.qualcomm.robotcore.eventloop.opmode.Disabled
23 | import io.github.deltacv.eocvsim.pipeline.StreamableOpenCvPipeline
24 | import org.firstinspires.ftc.robotcore.external.Telemetry
25 | import org.opencv.core.Mat
26 | import org.opencv.core.MatOfByte
27 | import org.opencv.core.Scalar
28 | import org.opencv.core.Size
29 | import org.opencv.imgcodecs.Imgcodecs
30 | import org.opencv.imgproc.Imgproc
31 | import org.openftc.easyopencv.OpenCvPipeline
32 |
33 | @Disabled
34 | class PaperVisionDefaultPipeline(
35 | val telemetry: Telemetry
36 | ) : StreamableOpenCvPipeline() {
37 |
38 | val logger by loggerForThis()
39 |
40 | lateinit var drawMat: Mat
41 |
42 | override fun init(mat: Mat) {
43 | drawMat = Mat(mat.size(), mat.type())
44 | drawMat.setTo(Scalar(0.0, 0.0, 0.0, 0.0))
45 |
46 | try {
47 | val bytes = PaperVisionDefaultPipeline::class.java.getResourceAsStream("/ico/ico_ezv.png")!!.use {
48 | it.readBytes()
49 | }
50 |
51 | val logoBytes = MatOfByte(*bytes)
52 | val logoMat = Imgcodecs.imdecode(logoBytes, Imgcodecs.IMREAD_UNCHANGED)
53 | logoBytes.release()
54 |
55 | Imgproc.cvtColor(logoMat, logoMat, Imgproc.COLOR_BGR2RGBA)
56 |
57 | Imgproc.resize(logoMat, logoMat, Size(logoMat.size().width / 2, logoMat.size().width / 2))
58 |
59 | // Draw the logo centered
60 | val x = (drawMat.width() - logoMat.width()) / 2
61 | val y = (drawMat.height() - logoMat.height()) / 2
62 |
63 | val roi = drawMat.submat(y, y + logoMat.height(), x, x + logoMat.width())
64 | logoMat.copyTo(roi)
65 |
66 | logoMat.release()
67 | } catch(e: Exception) {
68 | logger.warn("Failed to load logo", e)
69 | }
70 | }
71 |
72 | override fun processFrame(input: Mat): Mat {
73 | telemetry.addLine("Making computer vision accessible to everyone")
74 | telemetry.update()
75 |
76 | streamFrame(0, input, null)
77 |
78 | return drawMat
79 | }
80 |
81 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/eocvsim/SinglePipelineCompiler.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.eocvsim
20 |
21 | import com.github.serivesmejia.eocvsim.util.ReflectUtil
22 | import org.codehaus.janino.JavaSourceClassLoader
23 | import org.codehaus.janino.SimpleCompiler
24 | import org.openftc.easyopencv.OpenCvPipeline
25 | import java.util.*
26 | import javax.tools.*
27 |
28 |
29 | object SinglePipelineCompiler {
30 |
31 | /**
32 | * Takes source code and returns a compiled pipeline class
33 | */
34 | @Suppress("UNCHECKED_CAST")
35 | fun compilePipeline(pipelineName: String, pipelineSource: String): Class {
36 | // Create a SimpleCompiler instance
37 | val compiler = SimpleCompiler()
38 |
39 | // Set the source code
40 | compiler.cook(pipelineSource)
41 |
42 | val clazz = compiler.classLoader.loadClass(pipelineName)
43 |
44 | require(ReflectUtil.hasSuperclass(clazz, OpenCvPipeline::class.java)) {
45 | "Pipeline class must extend OpenCvPipeline"
46 | }
47 |
48 | return clazz as Class
49 | }
50 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/gui/eocvsim/NewProjectPanel.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.plugin.gui.eocvsim
2 |
3 | import com.github.serivesmejia.eocvsim.util.extension.removeFromEnd
4 | import com.github.serivesmejia.eocvsim.util.loggerForThis
5 | import io.github.deltacv.papervision.plugin.gui.eocvsim.dialog.PaperVisionDialogFactory
6 | import io.github.deltacv.papervision.plugin.project.PaperVisionProjectManager
7 | import java.awt.Dimension
8 | import java.awt.GridBagConstraints
9 | import java.awt.GridBagLayout
10 | import java.awt.Insets
11 | import java.awt.Window
12 | import javax.swing.Box
13 | import javax.swing.BoxLayout
14 | import javax.swing.JButton
15 | import javax.swing.JFileChooser
16 | import javax.swing.JFrame
17 | import javax.swing.JOptionPane
18 | import javax.swing.JPanel
19 | import javax.swing.SwingUtilities
20 | import javax.swing.filechooser.FileNameExtensionFilter
21 |
22 | class NewProjectPanel(
23 | val projectManager: PaperVisionProjectManager,
24 | val ancestor: Window
25 | ) : JPanel() {
26 |
27 | val logger by loggerForThis()
28 |
29 | val newProjectBtt = JButton("New Project")
30 |
31 | val importProjectBtt = JButton("Import Project")
32 |
33 | init {
34 | layout = GridBagLayout()
35 |
36 | newProjectBtt.addActionListener {
37 | projectManager.newProjectAsk(ancestor)
38 | }
39 |
40 | add(newProjectBtt, GridBagConstraints().apply {
41 | gridx = 0
42 | gridy = 0
43 | })
44 |
45 | importProjectBtt.addActionListener {
46 | projectManager.importProjectAsk(ancestor)
47 | }
48 |
49 | add(importProjectBtt, GridBagConstraints().apply {
50 | gridx = 1
51 | gridy = 0
52 | })
53 | }
54 |
55 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/gui/eocvsim/ProjectTreeCellRenderer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.gui.eocvsim
20 |
21 | import io.github.deltacv.papervision.plugin.project.PaperVisionProjectTree
22 | import java.awt.Component
23 | import javax.swing.JTree
24 | import javax.swing.UIManager
25 | import javax.swing.tree.DefaultMutableTreeNode
26 | import javax.swing.tree.DefaultTreeCellRenderer
27 |
28 | class ProjectTreeCellRenderer: DefaultTreeCellRenderer() {
29 |
30 | override fun getTreeCellRendererComponent(tree: JTree, value: Any, selected: Boolean, expanded: Boolean, leaf: Boolean, row: Int, hasFocus: Boolean): Component {
31 | val component = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus)
32 |
33 | if(value is DefaultMutableTreeNode) {
34 | val node = value.userObject
35 |
36 | if(node is PaperVisionProjectTree.ProjectTreeNode.Project) {
37 | icon = UIManager.getIcon("FileView.fileIcon")
38 | } else if(node is PaperVisionProjectTree.ProjectTreeNode.Folder) {
39 | icon = UIManager.getIcon("FileView.directoryIcon")
40 | }
41 | }
42 |
43 | return component
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/gui/eocvsim/dialog/PaperVisionDialogFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.gui.eocvsim.dialog
20 |
21 | import io.github.deltacv.papervision.plugin.project.recovery.RecoveredProject
22 | import java.awt.Dialog
23 | import java.awt.Window
24 | import javax.swing.JDialog
25 | import javax.swing.JFrame
26 | import javax.swing.JPanel
27 | import javax.swing.SwingUtilities
28 |
29 | object PaperVisionDialogFactory {
30 |
31 | fun displayNewProjectDialog(parent: Window, projects: List, groups: List, name: String? = null, callback: (String?, String) -> Unit) {
32 | val panel = CreateNewProjectPanel(projects, groups, name, callback)
33 | displayDialog("${if(name == null) "New" else "Import"} Project", panel, parent)
34 | }
35 |
36 | fun displayProjectRecoveryDialog(parent: Window, recoveredProjects: List, callback: (List) -> Unit) {
37 | val panel = ProjectRecoveryPanel(recoveredProjects, callback)
38 | displayDialog("Recover PaperVision Projects", panel, parent)
39 | }
40 |
41 | private fun displayDialog(title: String, panel: JPanel, parent: Window) {
42 | SwingUtilities.invokeLater {
43 | val dialog = JDialog(parent, title, Dialog.ModalityType.APPLICATION_MODAL)
44 |
45 | dialog.add(panel)
46 | dialog.pack()
47 | dialog.setLocationRelativeTo(null)
48 |
49 | dialog.isVisible = true
50 | }
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/gui/imgui/CloseConfirmWindow.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.gui.imgui
20 |
21 | import imgui.ImGui
22 | import imgui.flag.ImGuiWindowFlags
23 | import io.github.deltacv.mai18n.tr
24 | import io.github.deltacv.papervision.gui.util.Window
25 | import io.github.deltacv.papervision.util.flags
26 |
27 | class CloseConfirmWindow(
28 | val callback: (Action) -> Unit
29 | ) : Window() {
30 | enum class Action {
31 | YES,
32 | NO,
33 | CANCEL
34 | }
35 |
36 | override var title = "win_confirm"
37 | override val windowFlags = flags(
38 | ImGuiWindowFlags.NoResize,
39 | ImGuiWindowFlags.NoMove,
40 | ImGuiWindowFlags.NoCollapse
41 | )
42 |
43 | override val isModal = true
44 |
45 | override fun onEnable() {
46 | focus = true
47 | }
48 |
49 | override fun drawContents() {
50 | ImGui.text(tr("mis_savebefore_exit"))
51 | ImGui.separator()
52 |
53 | if(ImGui.button(tr("mis_save"))) {
54 | callback(Action.YES)
55 | ImGui.closeCurrentPopup()
56 | }
57 | ImGui.sameLine()
58 | if(ImGui.button(tr("mis_discard"))) {
59 | callback(Action.NO)
60 | ImGui.closeCurrentPopup()
61 | }
62 | ImGui.sameLine()
63 | if(ImGui.button(tr("mis_cancel"))) {
64 | callback(Action.CANCEL)
65 | ImGui.closeCurrentPopup()
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/gui/imgui/EasyVisionIntroWindow.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.gui.imgui
20 |
21 | import imgui.ImGui
22 | import imgui.flag.ImGuiWindowFlags
23 | import io.github.deltacv.papervision.gui.util.Window
24 | import io.github.deltacv.papervision.util.flags
25 |
26 | class EasyVisionIntroWindow : Window() {
27 | override var title = "Welcome!"
28 |
29 | override val windowFlags = flags(
30 | ImGuiWindowFlags.NoResize,
31 | ImGuiWindowFlags.NoMove,
32 | ImGuiWindowFlags.NoCollapse
33 | )
34 |
35 | private var isFirstDraw = true
36 |
37 | override fun onEnable() {
38 | centerWindow()
39 | focus = true
40 | isFirstDraw = true
41 | }
42 |
43 | override fun drawContents() {
44 | // Recenter the window on the second draw
45 | if (!isFirstDraw) {
46 | centerWindow()
47 | } else {
48 | isFirstDraw = false
49 | }
50 |
51 | ImGui.text("Welcome to EasyVision!")
52 | ImGui.separator()
53 | }
54 |
55 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/eocvsim/NoOpEngineImageStreamer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.ipc.eocvsim
20 |
21 | import io.github.deltacv.eocvsim.stream.ImageStreamer
22 | import org.opencv.core.Mat
23 |
24 | object NoOpEngineImageStreamer : ImageStreamer {
25 | override fun sendFrame(id: Int, image: Mat, cvtCode: Int?) {
26 | // no-op
27 | }
28 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/eocvsim/StreamableNoReflectOpenCvPipelineInstantiator.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.plugin.ipc.eocvsim
2 |
3 | import io.github.deltacv.eocvsim.pipeline.StreamableOpenCvPipeline
4 | import com.github.serivesmejia.eocvsim.pipeline.instantiator.DefaultPipelineInstantiator
5 | import com.github.serivesmejia.eocvsim.pipeline.instantiator.PipelineInstantiator
6 | import io.github.deltacv.eocvsim.stream.ImageStreamer
7 | import io.github.deltacv.eocvsim.virtualreflect.jvm.JvmVirtualReflection
8 | import org.firstinspires.ftc.robotcore.external.Telemetry
9 | import org.openftc.easyopencv.OpenCvPipeline
10 |
11 | class StreamableNoReflectOpenCvPipelineInstantiator(
12 | val imageStreamer: ImageStreamer
13 | ) : PipelineInstantiator {
14 |
15 | override fun instantiate(clazz: Class<*>, telemetry: Telemetry) =
16 | DefaultPipelineInstantiator.instantiate(clazz, telemetry).apply {
17 | if(this is StreamableOpenCvPipeline) {
18 | this.streamer = imageStreamer
19 | }
20 | }
21 |
22 | override fun virtualReflectOf(pipeline: OpenCvPipeline) = JvmVirtualReflection
23 |
24 | override fun variableTunerTarget(pipeline: OpenCvPipeline) = Any()
25 |
26 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/message/EOCVSimMessages.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.ipc.message
20 |
21 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessageBase
22 |
23 | data class InputSourceData(
24 | var name: String,
25 | var type: InputSourceType,
26 | var timestamp: Long
27 | )
28 | enum class InputSourceType {
29 | IMAGE, CAMERA, VIDEO
30 | }
31 |
32 | class GetInputSourcesMessage : PaperVisionEngineMessageBase()
33 |
34 | class GetCurrentInputSourceMessage : PaperVisionEngineMessageBase()
35 |
36 | class SetInputSourceMessage(
37 | var inputSource: String
38 | ) : PaperVisionEngineMessageBase()
39 |
40 | class OpenCreateInputSourceMessage(
41 | var sourceType: InputSourceType
42 | ) : PaperVisionEngineMessageBase()
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/message/ListenerMessages.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.ipc.message
20 |
21 | import com.google.gson.JsonElement
22 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessageBase
23 |
24 | // LISTENERS FOR EOCV-SIM
25 |
26 | class EditorChangeMessage(
27 | val json: JsonElement
28 | ) : PaperVisionEngineMessageBase()
29 |
30 | // LISTENERS FOR PAPERVISION
31 |
32 | class InputSourceListChangeListenerMessage : PaperVisionEngineMessageBase(persistent = true)
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/message/ProjectMessages.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.ipc.message
20 |
21 | import com.google.gson.JsonElement
22 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessage
23 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessageBase
24 |
25 | class GetCurrentProjectMessage : PaperVisionEngineMessageBase()
26 |
27 | class DiscardCurrentRecoveryMessage : PaperVisionEngineMessageBase()
28 |
29 | class SaveCurrentProjectMessage(
30 | var json: JsonElement
31 | ) : PaperVisionEngineMessageBase()
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/message/response/EOCVSimResponses.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.ipc.message.response
20 |
21 | import io.github.deltacv.papervision.engine.client.response.OkResponse
22 | import io.github.deltacv.papervision.plugin.ipc.message.InputSourceData
23 |
24 | class InputSourcesListResponse(
25 | var sources: Array
26 | ) : OkResponse()
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/serialization/IpcGson.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.ipc.serialization
20 |
21 | import com.google.gson.GsonBuilder
22 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessage
23 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessageResponse
24 |
25 | object IpcGson {
26 | object IpcMessageAdapter : PolymorphicAdapter("message", IpcGson::class.java.classLoader)
27 | object IpcMessageResponseAdapter : PolymorphicAdapter("messageResponse", IpcGson::class.java.classLoader)
28 |
29 | val gson = GsonBuilder()
30 | .registerTypeHierarchyAdapter(PaperVisionEngineMessage::class.java, IpcMessageAdapter)
31 | .registerTypeHierarchyAdapter(PaperVisionEngineMessageResponse::class.java, IpcMessageResponseAdapter)
32 | .create()
33 | }
34 |
35 | val ipcGson = IpcGson.gson
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/kotlin/io/github/deltacv/papervision/plugin/ipc/serialization/PolymorphicAdapter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.plugin.ipc.serialization
20 |
21 | import com.google.gson.Gson
22 | import com.google.gson.JsonDeserializationContext
23 | import com.google.gson.JsonDeserializer
24 | import com.google.gson.JsonElement
25 | import com.google.gson.JsonObject
26 | import com.google.gson.JsonSerializationContext
27 | import com.google.gson.JsonSerializer
28 | import java.lang.reflect.Type
29 | import kotlin.jvm.java
30 |
31 | private val gson = Gson()
32 |
33 | open class PolymorphicAdapter(
34 | val name: String,
35 | val classloader: ClassLoader = PolymorphicAdapter::class.java.classLoader
36 | ) : JsonSerializer, JsonDeserializer {
37 |
38 | override fun serialize(src: T, typeOfSrc: Type, context: JsonSerializationContext): JsonElement {
39 | val obj = JsonObject()
40 |
41 | obj.addProperty("${name}Class", src!!::class.java.name)
42 | obj.add(name, gson.toJsonTree(src))
43 |
44 | return obj
45 | }
46 |
47 | @Suppress("UNCHECKED_CAST")
48 | override fun deserialize(json: JsonElement, typeOfT: Type, context: JsonDeserializationContext): T {
49 | val className = json.asJsonObject.get("${name}Class").asString
50 |
51 | val clazz = classloader.loadClass(className)
52 |
53 | return gson.fromJson(json.asJsonObject.get(name), clazz) as T
54 | }
55 |
56 | }
--------------------------------------------------------------------------------
/EOCVSimPlugin/src/main/plugin.toml:
--------------------------------------------------------------------------------
1 | name = "PaperVision"
2 | author = "deltacv"
3 | author-email = "dev@deltacv.org"
4 | # This will be replaced by Gradle using the artifact version
5 | version = "{{version}}"
6 | description = "Create your custom OpenCV algorithms using a user-friendly node editor interface, inspired by Blender and Unreal Engine blueprints! Quickly prototype your vision using live previews as you edit. "
7 |
8 | min-api-version = "4.0.0"
9 |
10 | super-access = true
11 | super-access-reason = "PaperVision requires your permision to fully support all features related to rendering user interaction and filesystem access."
12 |
13 | main = "io.github.deltacv.papervision.plugin.PaperVisionEOCVSimPlugin"
--------------------------------------------------------------------------------
/LwjglPlatform/Standalone/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'org.jetbrains.kotlin.jvm'
3 | }
4 |
5 | apply from: '../../build.common.gradle'
6 |
7 | dependencies {
8 | implementation project(":LwjglPlatform")
9 |
10 | implementation "org.jetbrains.kotlin:kotlin-stdlib"
11 |
12 | implementation "ch.qos.logback:logback-classic:$logback_classic_version"
13 | }
14 |
15 | task(runEv, dependsOn: 'classes', type: JavaExec) {
16 | main = 'io.github.deltacv.papervision.platform.lwjgl.AppMain'
17 | classpath = sourceSets.main.runtimeClasspath
18 |
19 | if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {
20 | jvmArgs += ['-XstartOnFirstThread', '-Djava.awt.headless=true']
21 | }
22 | }
23 |
24 | tasks.withType(Jar) {
25 | manifest {
26 | attributes['Main-Class'] = 'io.github.deltacv.papervision.platform.lwjgl.AppMain'
27 | }
28 | }
--------------------------------------------------------------------------------
/LwjglPlatform/Standalone/src/main/kotlin/io/github/deltacv/papervision/platform/lwjgl/AppMain.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | @file:JvmName("AppMain")
20 | package io.github.deltacv.papervision.platform.lwjgl
21 |
22 | import imgui.app.Application
23 |
24 | fun main() {
25 | Application.launch(PaperVisionApp(showWelcomeWindow = true))
26 | }
--------------------------------------------------------------------------------
/LwjglPlatform/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'org.jetbrains.kotlin.jvm'
3 | id 'signing'
4 | id "com.vanniktech.maven.publish"
5 | }
6 |
7 | apply from: '../build.common.gradle'
8 |
9 | dependencies {
10 | api project(":PaperVision")
11 |
12 | compileOnly "org.jetbrains.kotlin:kotlin-stdlib"
13 |
14 | api "io.github.spair:imgui-java-app:$imgui_version"
15 |
16 | implementation platform('org.lwjgl:lwjgl-bom:3.3.4')
17 | implementation "org.lwjgl:lwjgl-stb"
18 | implementation "org.lwjgl:lwjgl-nfd"
19 |
20 | ['natives-linux', 'natives-windows', 'natives-macos', 'natives-macos-arm64'].each {
21 | implementation "org.lwjgl:lwjgl-stb::$it"
22 | implementation "org.lwjgl:lwjgl-nfd::$it"
23 | }
24 |
25 | implementation "org.slf4j:slf4j-api:$slf4j_version"
26 | }
27 |
--------------------------------------------------------------------------------
/LwjglPlatform/src/main/kotlin/io/github/deltacv/papervision/platform/lwjgl/glfw/GlfwKeys.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform.lwjgl.glfw
20 |
21 | import io.github.deltacv.papervision.platform.PlatformKeys
22 | import org.lwjgl.glfw.GLFW.*
23 |
24 | object GlfwKeys : PlatformKeys {
25 |
26 | val isMac = System.getProperty("os.name").contains("Mac")
27 |
28 | override val ArrowUp = glfwGetKeyScancode(GLFW_KEY_UP) //111
29 | override val ArrowDown = glfwGetKeyScancode(GLFW_KEY_DOWN)// 116
30 | override val ArrowLeft = glfwGetKeyScancode(GLFW_KEY_LEFT) // 113
31 | override val ArrowRight = glfwGetKeyScancode(GLFW_KEY_RIGHT) //114
32 |
33 | override val Escape = glfwGetKeyScancode(GLFW_KEY_ESCAPE) //9
34 | override val Spacebar = glfwGetKeyScancode(GLFW_KEY_SPACE) //65
35 | override val Delete = glfwGetKeyScancode(GLFW_KEY_DELETE) //119
36 |
37 | override val LeftShift = glfwGetKeyScancode(GLFW_KEY_LEFT_SHIFT) //50
38 | override val RightShift = glfwGetKeyScancode(GLFW_KEY_RIGHT_SHIFT) //62
39 |
40 | override val LeftControl = glfwGetKeyScancode(GLFW_KEY_LEFT_CONTROL) //37
41 | override val RightControl = glfwGetKeyScancode(GLFW_KEY_RIGHT_SHIFT) //105
42 |
43 | override val LeftSuper = glfwGetKeyScancode(GLFW_KEY_LEFT_SUPER) //133
44 | override val RightSuper = glfwGetKeyScancode(GLFW_KEY_RIGHT_SUPER) //134
45 |
46 | override val NativeLeftSuper by lazy {
47 | if(isMac) glfwGetKeyScancode(GLFW_KEY_LEFT_SUPER) else glfwGetKeyScancode(GLFW_KEY_LEFT_CONTROL)
48 | }
49 | override val NativeRightSuper by lazy {
50 | if(isMac) glfwGetKeyScancode(GLFW_KEY_RIGHT_SUPER) else glfwGetKeyScancode(GLFW_KEY_RIGHT_CONTROL)
51 | }
52 |
53 | override val Z = glfwGetKeyScancode(GLFW_KEY_Z) //44
54 | override val Y = glfwGetKeyScancode(GLFW_KEY_Y) //52
55 | override val X = glfwGetKeyScancode(GLFW_KEY_X) //45
56 | override val C = glfwGetKeyScancode(GLFW_KEY_C) //46
57 | override val V = glfwGetKeyScancode(GLFW_KEY_V) //47
58 | }
--------------------------------------------------------------------------------
/LwjglPlatform/src/main/kotlin/io/github/deltacv/papervision/platform/lwjgl/util/IOUtil.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform.lwjgl.util
20 |
21 | import org.lwjgl.BufferUtils
22 | import org.lwjgl.system.MemoryUtil
23 | import java.io.IOException
24 | import java.nio.Buffer
25 | import java.nio.ByteBuffer
26 | import java.nio.channels.Channels
27 | import java.nio.file.Files
28 | import java.nio.file.Paths
29 |
30 | object IOUtil {
31 |
32 | private fun resizeBuffer(buffer: ByteBuffer, newCapacity: Int): ByteBuffer {
33 | val newBuffer = BufferUtils.createByteBuffer(newCapacity)
34 | buffer.flip()
35 | newBuffer.put(buffer)
36 | return newBuffer
37 | }
38 |
39 | /**
40 | * Reads the specified resource and returns the raw data as a ByteBuffer.
41 | *
42 | * @param resource the resource to read
43 | * @param bufferSize the initial buffer size
44 | *
45 | * @return the resource data
46 | *
47 | * @throws IOException if an IO error occurs
48 | */
49 | @Throws(IOException::class)
50 | fun ioResourceToByteBuffer(resource: String, bufferSize: Int): ByteBuffer {
51 | var buffer: ByteBuffer
52 | val path = Paths.get(resource)
53 | if (Files.isReadable(path)) {
54 | Files.newByteChannel(path).use { fc ->
55 | buffer = BufferUtils.createByteBuffer(fc.size().toInt() + 1)
56 | while (fc.read(buffer) != -1) {
57 | }
58 | }
59 | } else {
60 | IOUtil::class.java.getResourceAsStream(resource)!!.use { source ->
61 | Channels.newChannel(source).use { rbc ->
62 | buffer = BufferUtils.createByteBuffer(bufferSize)
63 | while (true) {
64 | val bytes = rbc.read(buffer)
65 | if (bytes == -1) {
66 | break
67 | }
68 | if (buffer.remaining() == 0) {
69 | buffer = resizeBuffer(buffer, buffer.capacity() * 3 / 2) // 50%
70 | }
71 | }
72 | }
73 | }
74 | }
75 | (buffer as Buffer).flip()
76 | return MemoryUtil.memSlice(buffer)
77 | }
78 | }
79 |
80 |
--------------------------------------------------------------------------------
/LwjglPlatform/src/main/kotlin/io/github/deltacv/papervision/platform/lwjgl/util/Image.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform.lwjgl.util
20 |
21 | import org.lwjgl.stb.STBImage.*
22 | import org.lwjgl.system.MemoryStack
23 | import java.awt.image.BufferedImage
24 | import java.awt.image.DataBufferInt
25 | import java.nio.ByteBuffer
26 |
27 | fun loadImageFromResource(resourcePath: String): ImageData {
28 | val imgBuffer = try {
29 | IOUtil.ioResourceToByteBuffer(resourcePath, 8 * 1024)
30 | } catch(e: Exception) {
31 | throw RuntimeException("Exception while loading image $resourcePath", e)
32 | }
33 |
34 | var image: ImageData? = null
35 |
36 | MemoryStack.stackPush().use {
37 | val comp = it.mallocInt(1)
38 | val w = it.mallocInt(1)
39 | val h = it.mallocInt(1)
40 |
41 | val img = stbi_load_from_memory(imgBuffer, w, h, comp, 4)
42 | ?: throw RuntimeException("Failed to load image $resourcePath due to ${stbi_failure_reason()}")
43 |
44 | image = ImageData(img, w.get(), h.get())
45 | }
46 |
47 | return image!!
48 | }
49 |
50 | data class ImageData(val buffer: ByteBuffer, val width: Int, val height: Int)
51 |
52 | fun ImageData.toBufferedImage(): BufferedImage {
53 | val image = BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)
54 | val pixels = (image.raster.dataBuffer as DataBufferInt).data
55 |
56 | buffer.rewind()
57 |
58 | for(i in 0 until width * height) {
59 | val r = buffer.get().toInt() and 0xFF
60 | val g = buffer.get().toInt() and 0xFF
61 | val b = buffer.get().toInt() and 0xFF
62 | val a = buffer.get().toInt() and 0xFF
63 |
64 | pixels[i] = (a shl 24) or (r shl 16) or (g shl 8) or b
65 | }
66 |
67 | return image
68 | }
--------------------------------------------------------------------------------
/LwjglPlatform/src/main/resources/logback.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 | [%d{HH:mm:ss}] [%thread/%level]: [%class{0}] %msg%n
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/PaperVision/NodeAnnotationProcessor/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'org.jetbrains.kotlin.jvm'
3 | }
4 |
5 | apply from: '../../build.common.gradle'
6 |
7 | dependencies {
8 | implementation 'com.google.devtools.ksp:symbol-processing-api:2.0.20-1.0.24'
9 | implementation "com.squareup:kotlinpoet:1.18.1"
10 |
11 | implementation project(":Shared")
12 | }
--------------------------------------------------------------------------------
/PaperVision/NodeAnnotationProcessor/src/main/kotlin/io/github/deltacv/papervision/annotation/PaperNodeAnnotationProcessorProvider.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.annotation
20 |
21 | import com.google.devtools.ksp.processing.SymbolProcessor
22 | import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
23 | import com.google.devtools.ksp.processing.SymbolProcessorProvider
24 |
25 | class PaperNodeAnnotationProcessorProvider : SymbolProcessorProvider {
26 | override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
27 | return PaperNodeAnnotationProcessor(environment)
28 | }
29 | }
--------------------------------------------------------------------------------
/PaperVision/NodeAnnotationProcessor/src/main/resources/META-INF/services/com.google.devtools.ksp.processing.SymbolProcessorProvider:
--------------------------------------------------------------------------------
1 | io.github.deltacv.papervision.annotation.PaperNodeAnnotationProcessorProvider
--------------------------------------------------------------------------------
/PaperVision/build.gradle:
--------------------------------------------------------------------------------
1 | import java.nio.file.Paths
2 | import java.time.LocalDateTime
3 | import java.time.format.DateTimeFormatter
4 |
5 | plugins {
6 | id 'com.google.devtools.ksp' version '2.0.20-1.0.24'
7 | id 'org.jetbrains.kotlin.jvm'
8 | id 'signing'
9 | id "com.vanniktech.maven.publish"
10 | }
11 |
12 | apply from: '../build.common.gradle'
13 |
14 | dependencies {
15 | compileOnly "org.jetbrains.kotlin:kotlin-stdlib"
16 | implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
17 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version"
18 |
19 | compileOnly "io.github.spair:imgui-java-binding:$imgui_version" // platforms should add the "implementation" they need
20 |
21 | api "org.slf4j:slf4j-api:$slf4j_version"
22 |
23 | api 'org.deltacv:mai18n:1.1.5'
24 |
25 | implementation "org.java-websocket:Java-WebSocket:1.5.2"
26 |
27 | implementation "com.google.code.gson:gson:$gson_version"
28 | implementation "io.github.classgraph:classgraph:$classgraph_version"
29 |
30 | implementation 'ome:turbojpeg:8.0.0'
31 |
32 | api project(":Shared")
33 | ksp project(":PaperVision:NodeAnnotationProcessor")
34 | }
35 |
36 | ksp {
37 | arg("paperNodeClassesMetadataPackage", "io.github.deltacv.papervision.node")
38 | arg("paperNodeClassesMetadataClassName", "PaperNodeClassesMetadata")
39 | }
40 |
41 | tasks.register('writeBuildClassJava') {
42 | String date = DateTimeFormatter.ofPattern("yyyy-M-d hh:mm:ss").format(LocalDateTime.now())
43 |
44 | File versionFile = Paths.get(
45 | projectDir.absolutePath, 'src', 'main', 'kotlin',
46 | 'io', 'github', 'deltacv', 'papervision', 'Build.kt'
47 | ).toFile()
48 |
49 | versionFile.delete()
50 |
51 | versionFile << "package io.github.deltacv.papervision\n" +
52 | "\n" +
53 | "/*\n" +
54 | " * Autogenerated file! Do not manually edit this file, as\n" +
55 | " * it is regenerated any time the build task is run.\n" +
56 | " *\n" +
57 | " * Based from PhotonVision PhotonVersion generator task\n" +
58 | " */\n" +
59 | "@Suppress(\"UNUSED\")\n" +
60 | "object Build {\n" +
61 | " const val VERSION_STRING = \"$version\";\n" +
62 | " const val STANDARD_VERSION_STRING = \"$standardVersion\";\n" +
63 | " const val BUILD_DATE = \"$date\";\n" +
64 | " const val IS_DEV = ${version.contains("dev")};\n" +
65 | "}"
66 | }
67 |
68 | build.dependsOn writeBuildClassJava
69 |
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/action/Action.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.action
20 |
21 | import io.github.deltacv.papervision.id.DrawableIdElementBase
22 | import io.github.deltacv.papervision.id.IdElementContainerStack
23 | import io.github.deltacv.papervision.util.loggerForThis
24 |
25 | abstract class Action(
26 | val executeOnEnable: Boolean = true
27 | ) : DrawableIdElementBase() {
28 | override val idElementContainer = IdElementContainerStack.threadStack.peekNonNull()
29 |
30 | val logger by loggerForThis()
31 |
32 | override fun enable() {
33 | if(!idElementContainer.stackPointerFollowing) {
34 | logger.info("Forking after pointer")
35 | idElementContainer.fork()
36 | }
37 | super.enable()
38 | }
39 |
40 | override fun onEnable() {
41 | if(executeOnEnable) {
42 | execute()
43 | }
44 | }
45 |
46 | override fun draw() {}
47 |
48 | abstract fun undo()
49 | abstract fun execute()
50 | }
51 |
52 | class RootAction : Action(
53 | executeOnEnable = false
54 | ) {
55 | override fun undo() {}
56 |
57 | override fun execute() {
58 | logger.info("Root action executed")
59 | idElementContainer.pushforwardIfNonNull()
60 | }
61 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/action/editor/AttributeActions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.action.editor
20 |
21 | import io.github.deltacv.papervision.action.Action
22 | import io.github.deltacv.papervision.node.Link
23 |
24 | class CreateLinkAction(
25 | val link: Link
26 | ) : Action() {
27 | override fun undo() {
28 | link.delete()
29 | }
30 |
31 | override fun execute() {
32 | link.associatedAction = this
33 | if(link.isEnabled) return
34 |
35 | if(link.hasEnabled) {
36 | link.restore()
37 | } else {
38 | link.enable()
39 | }
40 | }
41 | }
42 |
43 | class DeleteLinksAction(
44 | val links: List
45 | ) : Action() {
46 | override fun undo() {
47 | links.forEach {
48 | if(it.isEnabled) return
49 | it.enable()
50 | }
51 | }
52 |
53 | override fun execute() {
54 | links.forEach {
55 | it.delete()
56 | }
57 | }
58 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/action/editor/NodeActions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.action.editor
20 |
21 | import io.github.deltacv.papervision.action.Action
22 | import io.github.deltacv.papervision.node.Node
23 |
24 | class CreateNodesAction(
25 | val nodes: List>
26 | ) : Action() {
27 |
28 | constructor(node: Node<*>) : this(listOf(node))
29 |
30 | override fun undo() {
31 | for(node in nodes) {
32 | if(node.isEnabled) {
33 | node.delete()
34 | }
35 | }
36 | }
37 |
38 | override fun execute() {
39 | for(node in nodes) {
40 | if(node.isEnabled) continue
41 |
42 | if(node.hasEnabled) {
43 | node.restore()
44 | } else {
45 | node.enable()
46 | }
47 | }
48 | }
49 | }
50 |
51 | class DeleteNodesAction(
52 | val nodes: List>
53 | ) : Action() {
54 | override fun undo() {
55 | nodes.forEach {
56 | if(it.isEnabled) return
57 |
58 | if(it.hasEnabled) {
59 | it.restore()
60 | } else {
61 | it.enable()
62 | }
63 | }
64 | }
65 |
66 | override fun execute() {
67 | nodes.forEach {
68 | it.delete()
69 | }
70 | }
71 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/attribute/math/DoubleAttribute.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.attribute.math
20 |
21 | import imgui.ImGui
22 | import imgui.type.ImDouble
23 | import imgui.type.ImFloat
24 | import io.github.deltacv.papervision.PaperVision
25 | import io.github.deltacv.papervision.attribute.AttributeMode
26 | import io.github.deltacv.papervision.attribute.AttributeType
27 | import io.github.deltacv.papervision.attribute.TypedAttribute
28 | import io.github.deltacv.papervision.codegen.CodeGen
29 | import io.github.deltacv.papervision.codegen.GenValue
30 | import io.github.deltacv.papervision.gui.FontAwesomeIcons
31 | import io.github.deltacv.papervision.util.Range2d
32 |
33 | class DoubleAttribute(
34 | override val mode: AttributeMode,
35 | override var variableName: String? = null
36 | ) : TypedAttribute(Companion) {
37 |
38 | companion object: AttributeType {
39 | override val icon = FontAwesomeIcons.SquareRootAlt
40 |
41 | override fun new(mode: AttributeMode, variableName: String) = DoubleAttribute(mode, variableName)
42 | }
43 |
44 | val value = ImDouble()
45 | private val sliderValue = ImFloat()
46 |
47 | private val sliderId by PaperVision.miscIds.nextId()
48 |
49 | private var range: Range2d? = null
50 |
51 | override fun drawAttribute() {
52 | super.drawAttribute()
53 | checkChange()
54 |
55 | if(!hasLink && mode == AttributeMode.INPUT) {
56 | sameLineIfNeeded()
57 |
58 | ImGui.pushItemWidth(110.0f)
59 |
60 | if(range == null) {
61 | ImGui.inputDouble("", value)
62 | } else {
63 | ImGui.sliderFloat("###$sliderId", sliderValue.data, range!!.min.toFloat(), range!!.max.toFloat())
64 | value.set(sliderValue.get().toDouble())
65 | }
66 |
67 | ImGui.popItemWidth()
68 | }
69 | }
70 |
71 | fun sliderMode(range: Range2d) {
72 | this.range = range
73 | }
74 |
75 | fun normalMode() {
76 | this.range = null
77 | }
78 |
79 | override fun thisGet() = value.get()
80 |
81 | override fun value(current: CodeGen.Current) = value(
82 | current, "a Double", GenValue.Double(value.get())
83 | ) { it is GenValue.Double }
84 |
85 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/attribute/vision/structs/PointsAttribute.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.attribute.vision.structs
20 |
21 | import io.github.deltacv.papervision.attribute.AttributeMode
22 | import io.github.deltacv.papervision.attribute.AttributeType
23 | import io.github.deltacv.papervision.attribute.TypedAttribute
24 | import io.github.deltacv.papervision.codegen.CodeGen
25 | import io.github.deltacv.papervision.codegen.GenValue
26 | import io.github.deltacv.papervision.gui.FontAwesomeIcons
27 | import io.github.deltacv.papervision.gui.style.hexColor
28 | import io.github.deltacv.papervision.gui.style.rgbaColor
29 |
30 | class PointsAttribute (
31 | override val mode: AttributeMode,
32 | override var variableName: String? = null
33 | ) : TypedAttribute(PointsAttribute) {
34 |
35 | companion object : AttributeType {
36 | override val icon = FontAwesomeIcons.BezierCurve
37 |
38 | override val styleColor = rgbaColor(253, 216, 53, 180)
39 | override val styleHoveredColor = rgbaColor(253, 216, 53, 255)
40 |
41 | override val listStyleColor = rgbaColor(253, 216, 53, 140)
42 | override val listStyleHoveredColor = rgbaColor(253, 216, 53, 255)
43 |
44 | override fun new(mode: AttributeMode, variableName: String) = PointsAttribute(mode, variableName)
45 | }
46 |
47 | override fun value(current: CodeGen.Current) = value(
48 | current, "a Points"
49 | ) { it is GenValue.GPoints.RuntimePoints }
50 |
51 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/attribute/vision/structs/RectAttribute.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.attribute.vision.structs
20 |
21 | import io.github.deltacv.papervision.attribute.AttributeMode
22 | import io.github.deltacv.papervision.attribute.AttributeType
23 | import io.github.deltacv.papervision.attribute.TypedAttribute
24 | import io.github.deltacv.papervision.codegen.CodeGen
25 | import io.github.deltacv.papervision.codegen.GenValue
26 | import io.github.deltacv.papervision.gui.FontAwesomeIcons
27 | import io.github.deltacv.papervision.gui.style.rgbaColor
28 |
29 | class RectAttribute (
30 | override val mode: AttributeMode,
31 | override var variableName: String? = null
32 | ) : TypedAttribute(Companion) {
33 |
34 | companion object : AttributeType {
35 | override val icon = FontAwesomeIcons.Square
36 |
37 | override val styleColor = rgbaColor(253, 216, 53, 180)
38 | override val styleHoveredColor = rgbaColor(253, 216, 53, 255)
39 |
40 | override val listStyleColor = rgbaColor(253, 216, 53, 140)
41 | override val listStyleHoveredColor = rgbaColor(253, 216, 53, 255)
42 |
43 | override fun new(mode: AttributeMode, variableName: String) = RectAttribute(mode, variableName)
44 | }
45 |
46 | override fun value(current: CodeGen.Current) = value(
47 | current, "a Rect"
48 | ) { it is GenValue.GRect.RuntimeRect }
49 |
50 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/attribute/vision/structs/RotatedRectAttribute.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.attribute.vision.structs
20 |
21 | import io.github.deltacv.papervision.attribute.AttributeMode
22 | import io.github.deltacv.papervision.attribute.AttributeType
23 | import io.github.deltacv.papervision.attribute.TypedAttribute
24 | import io.github.deltacv.papervision.codegen.CodeGen
25 | import io.github.deltacv.papervision.codegen.GenValue
26 | import io.github.deltacv.papervision.gui.FontAwesomeIcons
27 | import io.github.deltacv.papervision.gui.style.rgbaColor
28 |
29 | class RotatedRectAttribute (
30 | override val mode: AttributeMode,
31 | override var variableName: String? = null
32 | ) : TypedAttribute(Companion) {
33 |
34 | companion object : AttributeType {
35 | override val icon = FontAwesomeIcons.VectorSquare
36 |
37 | override val styleColor = rgbaColor(253, 216, 53, 180)
38 | override val styleHoveredColor = rgbaColor(253, 216, 53, 255)
39 |
40 | override val listStyleColor = rgbaColor(253, 216, 53, 140)
41 | override val listStyleHoveredColor = rgbaColor(253, 216, 53, 255)
42 |
43 | override fun new(mode: AttributeMode, variableName: String) = RotatedRectAttribute(mode, variableName)
44 | }
45 |
46 | override fun value(current: CodeGen.Current) = value(
47 | current, "a Rotated Rect"
48 | ) { it is GenValue.GRect.Rotated.RuntimeRotatedRect }
49 |
50 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/Csv.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen
20 |
21 | import io.github.deltacv.papervision.codegen.build.Type
22 | import io.github.deltacv.papervision.codegen.build.Value
23 |
24 | fun Array.csv(): String {
25 | val builder = StringBuilder()
26 |
27 | for((i, parameter) in this.withIndex()) {
28 | builder.append(parameter)
29 |
30 | if(i < this.size - 1) {
31 | builder.append(", ")
32 | }
33 | }
34 |
35 | return builder.toString()
36 | }
37 |
38 | fun Array.csv(): String {
39 | val stringArray = this.map { it.value!! }.toTypedArray()
40 | return stringArray.csv()
41 | }
42 |
43 | fun Array.csv(): String {
44 | val stringArray = this.map { it.shortNameWithGenerics }.toTypedArray()
45 | return stringArray.csv()
46 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/GenNode.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen
20 |
21 | import io.github.deltacv.papervision.attribute.Attribute
22 | import io.github.deltacv.papervision.util.loggerForThis
23 | import java.util.logging.Logger
24 |
25 | interface GenNode : Generator {
26 |
27 | val genOptions: CodeGenOptions
28 | var lastGenSession: S?
29 |
30 | fun propagate(current: CodeGen.Current)
31 |
32 | fun receivePropagation(current: CodeGen.Current) {
33 | genCodeIfNecessary(current)
34 | }
35 |
36 | /**
37 | * Generates code if there's not a session in the current CodeGen
38 | * Automatically propagates to all the nodes attached to the output
39 | * attributes after genCode finishes. Called by default on onPropagateReceive()
40 | */
41 | @Suppress("UNCHECKED_CAST")
42 | fun genCodeIfNecessary(current: CodeGen.Current) {
43 | val logger = loggerForThis().value
44 |
45 | val codeGen = current.codeGen
46 |
47 | if(genOptions.genAtTheEnd && codeGen.stage != CodeGen.Stage.END_GEN) {
48 | if(!codeGen.endingNodes.contains(this)) {
49 | logger.info("Marked node $this as an ending node")
50 | codeGen.endingNodes.add(this)
51 | }
52 |
53 | return
54 | }
55 |
56 | val session = codeGen.sessions[this]
57 |
58 | if(session == null) {
59 | // prevents duplicate code in weird edge cases
60 | // (it's so hard to consider and test every possibility with nodes...)
61 | if(!codeGen.busyNodes.contains(this)) {
62 | codeGen.busyNodes.add(this)
63 |
64 | logger.info("Generating code for node $this")
65 |
66 | lastGenSession = genCode(current)
67 | codeGen.sessions[this] = lastGenSession!!
68 |
69 | codeGen.busyNodes.remove(this)
70 |
71 | logger.info("DONE generating code for node $this")
72 |
73 | propagate(current)
74 | }
75 | } else {
76 | lastGenSession = session as S
77 | }
78 | }
79 |
80 | fun getOutputValueOf(current: CodeGen.Current, attrib: Attribute): GenValue
81 |
82 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/Generator.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen
20 |
21 | interface Generator {
22 | fun genCode(current: CodeGen.Current): S
23 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/GeneratorsGenNode.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen
20 |
21 | import io.github.deltacv.papervision.codegen.language.Language
22 |
23 | interface GeneratorsGenNode : GenNode {
24 | val generators: Map>
25 |
26 | fun map(language: Language, generator: Generator) = Pair(language, generator)
27 |
28 | override fun genCode(current: CodeGen.Current): S {
29 | val generator = generators[current.language] ?: throw NoSuchElementException("No generator found for language ${current.language.javaClass.simpleName} at node ${this::class.simpleName}")
30 | lastGenSession = generator.genCode(current)
31 |
32 | return lastGenSession!!
33 | }
34 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/Type.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build
20 |
21 | import io.github.deltacv.papervision.codegen.csv
22 |
23 | open class Type(
24 | val className: String,
25 | open val packagePath: String = "",
26 | val generics: Array? = null,
27 |
28 | open val actualImport: Type? = null,
29 | val isArray: Boolean = false
30 | ) {
31 |
32 | companion object {
33 | val NONE = Type("", "")
34 | }
35 |
36 | val hasGenerics get() = !generics.isNullOrEmpty()
37 |
38 | open val shouldImport get() = className != packagePath
39 |
40 | val shortNameWithGenerics get() =
41 | if(generics != null)
42 | "$className<${generics.csv()}>"
43 | else className
44 |
45 | override fun toString() = "Type(className=$className, packagePath=$packagePath, actualImport=$actualImport, isArray=$isArray)"
46 |
47 | }
48 |
49 | private val typeCache = mutableMapOf, Type>()
50 |
51 | val Any.genType: Type get() = this::class.java.genType
52 |
53 | val Class<*>.genType: Type get() {
54 | if(!typeCache.containsKey(this)) {
55 | typeCache[this] = Type(simpleName, getPackage()?.name ?: "")
56 | }
57 |
58 | return typeCache[this]!!
59 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/Value.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build
20 |
21 | val String.v get() = ConValue(genType, this)
22 | val Number.v get() = toString().v
23 |
24 | abstract class Value {
25 |
26 | abstract val type: Type
27 | abstract val value: String?
28 |
29 | private val internalImports = mutableListOf()
30 | val imports get() = internalImports as List
31 |
32 | protected fun processImports() {
33 | // avoid adding imports for primitive types
34 | if(type.shouldImport) {
35 | additionalImports(type)
36 | }
37 |
38 | if(type.generics != null) {
39 | for(genericType in type.generics!!) {
40 | if(genericType.shouldImport) {
41 | additionalImports(genericType)
42 | }
43 | }
44 | }
45 | }
46 |
47 | fun additionalImports(vararg imports: Type) {
48 | internalImports.addAll(imports)
49 | }
50 |
51 | fun additionalImports(vararg imports: Value) {
52 | for(import in imports) {
53 | internalImports.addAll(import.imports)
54 | }
55 | }
56 | }
57 |
58 | open class ConValue(override val type: Type, override val value: String?): Value() {
59 | init {
60 | processImports()
61 | }
62 | }
63 |
64 | class Condition(booleanType: Type, condition: String) : ConValue(booleanType, condition)
65 | class Operation(numberType: Type, operation: String) : ConValue(numberType, operation)
66 |
67 | open class Variable(val name: String, val variableValue: Value) : ConValue(variableValue.type, name) {
68 |
69 | constructor(type: Type, name: String) : this(name, ConValue(type, name))
70 |
71 | init {
72 | additionalImports(*variableValue.imports.toTypedArray())
73 | }
74 |
75 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/type/CPythonOpenCvTypes.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build.type
20 |
21 | import io.github.deltacv.papervision.codegen.build.ConValue
22 |
23 | object CPythonOpenCvTypes {
24 | object cv2 : CPythonType("cv2") {
25 | val RETR_LIST = ConValue(this, "cv2.RETR_LIST").apply {
26 | additionalImports(this)
27 | }
28 |
29 | val RETR_EXTERNAL = ConValue(this, "cv2.RETR_EXTERNAL").apply {
30 | additionalImports(this)
31 | }
32 |
33 | val CHAIN_APPROX_SIMPLE = ConValue(this, "cv2.CHAIN_APPROX_SIMPLE").apply {
34 | additionalImports(this)
35 | }
36 |
37 | val MORPH_RECT = ConValue(this, "cv2.MORPH_RECT").apply {
38 | additionalImports(this)
39 | }
40 |
41 | val contourArea = ConValue(this, "cv2.contourArea").apply {
42 | additionalImports(this)
43 | }
44 | }
45 |
46 | val np = CPythonType("numpy", null, "np")
47 |
48 | val npArray = object: CPythonType("np.ndarray") {
49 | override var actualImport = np
50 | }
51 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/type/CPythonType.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build.type
20 |
21 | import io.github.deltacv.papervision.codegen.build.Type
22 |
23 | open class CPythonType(
24 | val module: String,
25 | val name: String? = null,
26 | val alias: String? = null
27 | ) : Type(alias ?: name ?: module, module) {
28 | override val shouldImport = true
29 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/type/JavaTypes.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build.type
20 |
21 | import io.github.deltacv.papervision.codegen.build.Type
22 |
23 | object JavaTypes {
24 |
25 | val String = Type("String", "java.lang")
26 |
27 | val Math = object: Type("Math", "java.lang") {
28 | override val shouldImport = false
29 | }
30 |
31 | fun Set(elementType: Type) = Type(
32 | "Set", "java.util",
33 | arrayOf(elementType)
34 | )
35 |
36 | fun ArrayList(elementType: Type) = Type(
37 | "ArrayList", "java.util",
38 | arrayOf(elementType)
39 | )
40 |
41 | fun HashMap(key: Type, value: Type) = Type(
42 | "HashMap", "java.util",
43 | arrayOf(key, value)
44 | )
45 |
46 | class Map(key: Type, value: Type) : Type(
47 | "Map", "java.util",
48 | arrayOf(key, value)
49 | ) {
50 | class Entry(key: Type, value: Type) : Type(
51 | "Map.Entry", "java.util",
52 | arrayOf(key, value)
53 | )
54 | }
55 |
56 | fun List(elementType: Type) = Type(
57 | "List", "java.util",
58 | arrayOf(elementType)
59 | )
60 |
61 | val Collections = Type("Collections", "java.util")
62 |
63 | val LabelAnnotation = Type("Label", "io.github.deltacv.eocvsim.virtualreflect.jvm")
64 |
65 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/type/JvmOpenCvTypes.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build.type
20 |
21 | import io.github.deltacv.papervision.codegen.build.ConValue
22 | import io.github.deltacv.papervision.codegen.build.Type
23 |
24 | object JvmOpenCvTypes {
25 |
26 | val OpenCvPipeline = Type("OpenCvPipeline", "org.openftc.easyopencv")
27 | val StreamableOpenCvPipeline = Type("StreamableOpenCvPipeline", "io.github.deltacv.eocvsim.pipeline")
28 |
29 | object Imgproc : Type("Imgproc", "org.opencv.imgproc") {
30 | val RETR_LIST = ConValue(StandardTypes.cint, "Imgproc.RETR_LIST").apply {
31 | additionalImports(this)
32 | }
33 |
34 | val RETR_EXTERNAL = ConValue(StandardTypes.cint, "Imgproc.RETR_EXTERNAL").apply {
35 | additionalImports(this)
36 | }
37 |
38 | val CHAIN_APPROX_SIMPLE = ConValue(StandardTypes.cint, "Imgproc.CHAIN_APPROX_SIMPLE").apply {
39 | additionalImports(this)
40 | }
41 |
42 | val MORPH_RECT = ConValue(StandardTypes.cint, "Imgproc.MORPH_RECT").apply {
43 | additionalImports(this)
44 | }
45 | }
46 |
47 | object CvType : Type("CvType", "org.opencv.core")
48 |
49 | val Core = Type("Core", "org.opencv.core")
50 |
51 | val Mat = Type("Mat", "org.opencv.core")
52 | val MatOfInt = Type("MatOfInt", "org.opencv.core")
53 | val MatOfPoint = Type("MatOfPoint", "org.opencv.core")
54 | val MatOfPoint2f = Type("MatOfPoint2f", "org.opencv.core")
55 |
56 | val Size = Type("Size", "org.opencv.core")
57 | val Scalar = Type("Scalar", "org.opencv.core")
58 |
59 | val Rect = Type("Rect", "org.opencv.core")
60 | val RotatedRect = Type("RotatedRect", "org.opencv.core")
61 |
62 | val Point = Type("Point", "org.opencv.core")
63 |
64 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/type/KotlinTypes.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build.type
20 |
21 | import io.github.deltacv.papervision.codegen.build.Type
22 |
23 | object KotlinTypes {
24 |
25 | val Boolean = Type("Boolean", "Boolean")
26 |
27 | val Int = Type("Int", "Int")
28 | val Long = Type("Long", "Long")
29 | val Float = Type("Float", "Float")
30 | val Double = Type("Double", "Double")
31 |
32 | val Unit = Type("Unit", "kotlin")
33 |
34 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/build/type/StandardTypes.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.build.type
20 |
21 | import io.github.deltacv.papervision.codegen.build.Type
22 |
23 | object StandardTypes {
24 |
25 | val cboolean = Type("boolean", "boolean")
26 |
27 | val cint = Type("int", "int")
28 | val clong = Type("long", "long")
29 | val cfloat = Type("float", "float")
30 | val cdouble = Type("double", "double")
31 |
32 | val cvoid = Type("void", "void")
33 |
34 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/dsl/CodeGenContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.dsl
20 |
21 | import io.github.deltacv.papervision.codegen.*
22 | import io.github.deltacv.papervision.codegen.build.*
23 |
24 | class CodeGenContext(val codeGen: CodeGen) : LanguageContext(codeGen.language) {
25 |
26 | val isForPreviz get() = codeGen.isForPreviz
27 |
28 | fun enum(name: String, vararg values: String) {
29 | codeGen.classStartScope.enumClass(name, *values)
30 | }
31 |
32 | fun init(block: ScopeContext.() -> Unit) {
33 | codeGen.initScope(block)
34 | }
35 |
36 | fun processFrame(block: ScopeContext.() -> Unit) {
37 | codeGen.processFrameScope(block)
38 | }
39 |
40 | fun onViewportTapped(block: ScopeContext.() -> Unit) {
41 | codeGen.viewportTappedScope(block)
42 | }
43 |
44 | fun public(variable: Variable, label: String? = null) =
45 | codeGen.classStartScope.instanceVariable(Visibility.PUBLIC, variable, label)
46 |
47 | fun private(variable: Variable) =
48 | codeGen.classStartScope.instanceVariable(Visibility.PRIVATE, variable, null)
49 |
50 | fun protected(variable: Variable) =
51 | codeGen.classStartScope.instanceVariable(Visibility.PROTECTED, variable, null)
52 |
53 | private var isFirstGroup = true
54 |
55 | fun group(scope: Scope = codeGen.classStartScope, block: () -> Unit) {
56 | if(!isFirstGroup) {
57 | scope.newLineIfNotBlank()
58 | }
59 | isFirstGroup = false
60 |
61 | block()
62 | }
63 |
64 | fun uniqueVariable(name: String, value: Value) = variable(tryName(name), value)
65 |
66 | fun tryName(name: String) = codeGen.classStartScope.tryName(name)
67 |
68 | operator fun String.invoke(
69 | vis: Visibility, returnType: Type,
70 | vararg parameters: Parameter,
71 | isStatic: Boolean = false, isFinal: Boolean = false, isOverride: Boolean = true,
72 | scopeBlock: ScopeContext.() -> Unit
73 | ) {
74 | val s = Scope(2, codeGen.language)
75 | scopeBlock(s.context)
76 |
77 | codeGen.classEndScope.method(
78 | vis, returnType, this, s, *parameters,
79 | isStatic = isStatic, isFinal = isFinal, isOverride = isOverride
80 | )
81 | }
82 |
83 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/dsl/GeneratorContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.dsl
20 |
21 | import io.github.deltacv.papervision.codegen.CodeGen
22 | import io.github.deltacv.papervision.codegen.CodeGenSession
23 | import io.github.deltacv.papervision.codegen.Generator
24 | import io.github.deltacv.papervision.codegen.language.Language
25 |
26 | class GeneratorContext(val current: CodeGen.Current)
27 |
28 | fun generator(init: GeneratorContext.() -> S) =
29 | object: Generator {
30 | override fun genCode(current: CodeGen.Current) = init(GeneratorContext(current))
31 | }
32 |
33 | fun generatorFor(language: Language, init: GeneratorContext.() -> S) =
34 | language to generator(init)
35 |
36 | fun generatorFor(vararg languages: Language, init: GeneratorContext.() -> S) =
37 | languages.map { it to generator(init) }.toMap()
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/dsl/GeneratorsContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.dsl
20 |
21 | import io.github.deltacv.papervision.codegen.CodeGenSession
22 | import io.github.deltacv.papervision.codegen.Generator
23 | import io.github.deltacv.papervision.codegen.language.Language
24 |
25 | class GeneratorsContext {
26 | val generators = mutableMapOf>()
27 |
28 | fun generatorFor(language: Language, init: GeneratorContext.() -> S) = generatorFor(language, init).apply { generators[first] = second }
29 | fun generatorFor(vararg languages: Language, init: GeneratorContext.() -> S) = generatorFor(*languages, init = init).apply { forEach { generators[it.key] = it.value } }
30 |
31 | fun generatorFor(language: Language, generator: Generator) = generators.put(language, generator)
32 | fun generatorFor(vararg languages: Language, generator: Generator) = languages.forEach { generators[it] = generator }
33 | }
34 |
35 | fun generatorsBuilder(init: GeneratorsContext.() -> Unit) = GeneratorsContext().run {
36 | init()
37 | generators
38 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/dsl/TargetsContext.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.dsl
20 |
21 | import io.github.deltacv.papervision.codegen.CodeGen
22 | import io.github.deltacv.papervision.codegen.build.Type
23 | import io.github.deltacv.papervision.codegen.build.Value
24 | import io.github.deltacv.papervision.codegen.build.Variable
25 | import io.github.deltacv.papervision.codegen.build.type.JavaTypes
26 | import io.github.deltacv.papervision.codegen.build.type.JvmOpenCvTypes
27 | import io.github.deltacv.papervision.codegen.vision.enableTargets
28 |
29 | class TargetsContext(context: LanguageContext) {
30 | val rectTargets = context.run {
31 | Variable("rectTargets", JavaTypes.HashMap(JavaTypes.String, JvmOpenCvTypes.Rect).new())
32 | }
33 | val rotRectTargets = context.run {
34 | Variable("rotRectTarget", JavaTypes.HashMap(JavaTypes.String, JvmOpenCvTypes.RotatedRect).new())
35 | }
36 |
37 | fun ScopeContext.addRectTarget(label: Value, rect: Value) {
38 | "addRectTarget"(label, rect)
39 | }
40 |
41 | fun ScopeContext.addRotRectTarget(label: Value, rect: Value) {
42 | "addRotRectTarget"(label, rect)
43 | }
44 |
45 | fun ScopeContext.clearTargets() {
46 | "clearTargets"()
47 | }
48 | }
49 |
50 | fun CodeGen.Current.targets(enableTargetsIfNeeded: Boolean = true, block: TargetsContext.() -> T): T {
51 | if(enableTargetsIfNeeded) {
52 | enableTargets()
53 | }
54 |
55 | return block(TargetsContext(codeGen.context))
56 | }
57 |
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/codegen/language/jvm/JavaLanguage.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.codegen.language.jvm
20 |
21 | import io.github.deltacv.papervision.codegen.language.LanguageBase
22 |
23 | object JavaLanguage : LanguageBase()
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/engine/bridge/NoOpPaperVisionEngineBridge.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.engine.bridge
20 |
21 | import io.github.deltacv.papervision.engine.client.PaperVisionEngineClient
22 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessage
23 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessageResponse
24 | import io.github.deltacv.papervision.util.event.PaperVisionEventHandler
25 | import java.util.concurrent.ArrayBlockingQueue
26 |
27 | object NoOpPaperVisionEngineBridge : PaperVisionEngineBridge {
28 | override val isConnected: Boolean
29 | get() = false
30 |
31 | override val onClientProcess = PaperVisionEventHandler("LocalPaperVisionEngineBridge-OnClientProcess")
32 | override val processedBinaryMessagesHashes = ArrayBlockingQueue(1)
33 |
34 | override fun connectClient(client: PaperVisionEngineClient) {
35 | // No-op
36 | }
37 |
38 | override fun terminate(client: PaperVisionEngineClient) {
39 | // No-op
40 | }
41 |
42 | override fun broadcastBytes(bytes: ByteArray) {
43 | // No-op
44 | }
45 |
46 | override fun sendMessage(client: PaperVisionEngineClient, message: PaperVisionEngineMessage) {
47 | // No-op
48 | }
49 |
50 | override fun acceptResponse(response: PaperVisionEngineMessageResponse) {
51 | // No-op
52 | }
53 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/engine/bridge/PaperVisionEngineBridge.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.engine.bridge
20 |
21 | import io.github.deltacv.papervision.engine.client.PaperVisionEngineClient
22 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessage
23 | import io.github.deltacv.papervision.engine.message.PaperVisionEngineMessageResponse
24 | import io.github.deltacv.papervision.util.event.PaperVisionEventHandler
25 | import java.util.concurrent.ArrayBlockingQueue
26 |
27 | interface PaperVisionEngineBridge {
28 | val isConnected: Boolean
29 |
30 | val onClientProcess: PaperVisionEventHandler
31 | val processedBinaryMessagesHashes: ArrayBlockingQueue
32 |
33 | fun connectClient(client: PaperVisionEngineClient)
34 | fun terminate(client: PaperVisionEngineClient)
35 |
36 | fun broadcastBytes(bytes: ByteArray)
37 |
38 | fun sendMessage(client: PaperVisionEngineClient, message: PaperVisionEngineMessage)
39 | fun acceptResponse(response: PaperVisionEngineMessageResponse)
40 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/engine/client/ByteMessageReceiver.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.engine.client
2 |
3 | typealias Handler = (Int, String, ByteArray) -> Unit
4 |
5 | abstract class ByteMessageReceiver {
6 |
7 | private val handlers = mutableListOf()
8 |
9 | fun callHandlers(id: Int, tag: String, bytes: ByteArray) {
10 | handlers.forEach { handler ->
11 | handler(id, tag, bytes)
12 | }
13 | }
14 |
15 | open fun addHandler(tag: String, handler: Handler) {
16 | handlers.add(handler)
17 | }
18 |
19 | open fun removeHandler(handlerInstance: Handler) {
20 | handlers.remove(handlerInstance)
21 | }
22 |
23 | open fun stop() { }
24 |
25 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/exception/GenException.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.exception
20 |
21 | import io.github.deltacv.papervision.attribute.Attribute
22 | import io.github.deltacv.papervision.node.Node
23 |
24 | class NodeGenException(val node: Node<*>, override val message: String) : RuntimeException(message)
25 |
26 | class AttributeGenException(val attribute: Attribute, override val message: String) : RuntimeException(message)
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/ToastWindow.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.gui
2 |
3 | import imgui.ImGui
4 | import imgui.ImVec2
5 | import imgui.flag.ImGuiWindowFlags
6 | import io.github.deltacv.mai18n.tr
7 | import io.github.deltacv.papervision.gui.util.Window
8 | import io.github.deltacv.papervision.util.ElapsedTime
9 | import io.github.deltacv.papervision.util.flags
10 |
11 | class ToastWindow(
12 | val message: String,
13 | val durationSeconds: Double = 5.0,
14 | val font: Font? = null
15 | ) : Window() {
16 | override var title = "toast"
17 |
18 | override val windowFlags = flags(
19 | ImGuiWindowFlags.NoTitleBar,
20 | ImGuiWindowFlags.NoResize,
21 | ImGuiWindowFlags.NoMove,
22 | ImGuiWindowFlags.NoScrollbar,
23 | )
24 |
25 | val timer = ElapsedTime()
26 |
27 | override fun onEnable() {
28 | super.onEnable()
29 | timer.reset()
30 |
31 | for(window in idElementContainer.inmutable) {
32 | if(window is ToastWindow && window != this) {
33 | window.delete()
34 | }
35 | }
36 |
37 | firstDraw = true
38 | }
39 |
40 | private var firstDraw = true
41 |
42 | override fun drawContents() {
43 | if(font != null) {
44 | ImGui.pushFont(font.imfont)
45 | }
46 |
47 | val currentSize = if(firstDraw) {
48 | ImVec2(
49 | ImGui.calcTextSize(tr(message)).x + 10,
50 | ImGui.calcTextSize(tr(message)).y + 10
51 | )
52 | } else size
53 |
54 | position = ImVec2(
55 | ImGui.getMainViewport().centerX - currentSize.x / 2,
56 | ImGui.getMainViewport().sizeY - currentSize.y - 20
57 | )
58 |
59 | ImGui.text(tr(message))
60 |
61 | if(font != null) {
62 | ImGui.popFont()
63 | }
64 |
65 | if(timer.seconds > durationSeconds) {
66 | delete()
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/eocvsim/ImageDisplay.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.gui.eocvsim
20 |
21 | import imgui.ImGui
22 | import io.github.deltacv.papervision.id.IdElement
23 | import io.github.deltacv.papervision.id.IdElementContainerStack
24 | import io.github.deltacv.papervision.engine.previz.PipelineStream
25 |
26 | class ImageDisplay(
27 | var pipelineStream: PipelineStream
28 | ) : IdElement {
29 | override val id by IdElementContainerStack.threadStack.peekNonNull().nextId(this)
30 |
31 | fun drawStream() {
32 | pipelineStream.textureOf(id)?.draw()
33 |
34 | if (ImGui.isItemHovered() && ImGui.isMouseDoubleClicked(0)) {
35 | if(pipelineStream.status == PipelineStream.Status.MINIMIZED) {
36 | pipelineStream.maximize()
37 | } else {
38 | pipelineStream.minimize()
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/eocvsim/ImageDisplayNode.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.gui.eocvsim
20 |
21 | import imgui.ImGui
22 | import imgui.extension.imnodes.ImNodes
23 | import imgui.extension.imnodes.flag.ImNodesCol
24 | import io.github.deltacv.papervision.attribute.Attribute
25 | import io.github.deltacv.papervision.attribute.EmptyInputAttribute
26 | import io.github.deltacv.papervision.attribute.vision.MatAttribute
27 | import io.github.deltacv.papervision.codegen.CodeGen
28 | import io.github.deltacv.papervision.codegen.NoSession
29 | import io.github.deltacv.papervision.id.IdElementContainerStack
30 | import io.github.deltacv.papervision.node.Category
31 | import io.github.deltacv.papervision.node.DrawNode
32 | import io.github.deltacv.papervision.node.PaperNode
33 | import io.github.deltacv.papervision.serialization.data.SerializeIgnore
34 |
35 | @PaperNode(
36 | name = "nod_previewdisplay",
37 | category = Category.HIGH_LEVEL_CV,
38 | showInList = false
39 | )
40 | @SerializeIgnore
41 | class ImageDisplayNode(
42 | val imageDisplay: ImageDisplay
43 | ) : DrawNode(joinActionStack = false) {
44 |
45 | val input = EmptyInputAttribute(this)
46 |
47 | override fun drawNode() {
48 | ImNodes.pushColorStyle(ImNodesCol.Pin, MatAttribute.styleColor)
49 | ImNodes.pushColorStyle(ImNodesCol.PinHovered, MatAttribute.styleHoveredColor)
50 |
51 | ImNodes.beginInputAttribute(input.id)
52 | ImNodes.endInputAttribute()
53 |
54 | ImNodes.popColorStyle()
55 | ImNodes.popColorStyle()
56 |
57 | ImGui.sameLine()
58 |
59 | imageDisplay.drawStream()
60 | }
61 |
62 | override fun delete() {
63 | super.delete()
64 | input.delete()
65 | }
66 |
67 | override fun genCode(current: CodeGen.Current) = NoSession
68 |
69 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/eocvsim/ImageDisplayWindow.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.gui.eocvsim
20 |
21 | import imgui.ImGui
22 | import imgui.flag.ImGuiWindowFlags
23 | import io.github.deltacv.mai18n.tr
24 | import io.github.deltacv.papervision.engine.previz.PipelineStream
25 | import io.github.deltacv.papervision.gui.util.Window
26 | import io.github.deltacv.papervision.util.flags
27 |
28 | class ImageDisplayWindow(
29 | val imageDisplay: ImageDisplay
30 | ) : Window() {
31 | override var title = "Preview"
32 |
33 | override val windowFlags = flags(
34 | ImGuiWindowFlags.AlwaysAutoResize,
35 | ImGuiWindowFlags.NoMove,
36 | ImGuiWindowFlags.NoCollapse
37 | )
38 |
39 | override fun drawContents() {
40 | imageDisplay.drawStream()
41 |
42 | val pipelineStream = imageDisplay.pipelineStream
43 |
44 | val buttonText = if(pipelineStream.status == PipelineStream.Status.MINIMIZED) {
45 | "Maximize"
46 | } else {
47 | "Minimize"
48 | }
49 |
50 | if (ImGui.button(buttonText)) {
51 | if(pipelineStream.status == PipelineStream.Status.MINIMIZED) {
52 | pipelineStream.maximize()
53 | } else {
54 | pipelineStream.minimize()
55 | }
56 | }
57 |
58 | ImGui.sameLine()
59 |
60 | val statusText = if(pipelineStream.isAtOfflineTexture(imageDisplay.id))
61 | "mis_loading"
62 | else "mis_runningok"
63 |
64 | ImGui.text(tr(statusText))
65 | }
66 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/style/ImNodesStyle.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.gui.style
20 |
21 | import imgui.extension.imnodes.ImNodes
22 | import imgui.extension.imnodes.flag.ImNodesCol
23 |
24 | interface ImNodesStyle : ImNodesStyleTemplate {
25 | override fun apply() {
26 | ImNodes.pushColorStyle(ImNodesCol.NodeBackground, nodeBackground)
27 | ImNodes.pushColorStyle(ImNodesCol.NodeBackgroundHovered, nodeBackgroundHovered)
28 | ImNodes.pushColorStyle(ImNodesCol.NodeBackgroundSelected, nodeBackgroundSelected)
29 | ImNodes.pushColorStyle(ImNodesCol.NodeOutline, nodeOutline)
30 |
31 | ImNodes.pushColorStyle(ImNodesCol.TitleBar, titleBar)
32 | ImNodes.pushColorStyle(ImNodesCol.TitleBarHovered, titleBarHovered)
33 | ImNodes.pushColorStyle(ImNodesCol.TitleBarSelected, titleBarSelected)
34 |
35 | ImNodes.pushColorStyle(ImNodesCol.Link, link)
36 | ImNodes.pushColorStyle(ImNodesCol.LinkHovered, linkHovered)
37 | ImNodes.pushColorStyle(ImNodesCol.LinkSelected, linkSelected)
38 |
39 | ImNodes.pushColorStyle(ImNodesCol.Pin, pin)
40 | ImNodes.pushColorStyle(ImNodesCol.PinHovered, pinHovered)
41 |
42 | ImNodes.pushColorStyle(ImNodesCol.BoxSelector, boxSelector)
43 | ImNodes.pushColorStyle(ImNodesCol.BoxSelectorOutline, boxSelectorOutline)
44 | }
45 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/style/imnodes/ImNodesDarkStyle.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.gui.style.imnodes
20 |
21 | import io.github.deltacv.papervision.gui.style.ImNodesStyle
22 | import io.github.deltacv.papervision.gui.style.rgbaColor
23 |
24 | object ImNodesDarkStyle : ImNodesStyle {
25 | override val nodeBackground = rgbaColor(50, 50, 50, 255)
26 | override val nodeBackgroundHovered = rgbaColor(75, 75, 75, 255)
27 | override val nodeBackgroundSelected = rgbaColor(75, 75, 75, 255)
28 | override val nodeOutline = rgbaColor(100, 100, 100, 255)
29 |
30 | override val titleBar = rgbaColor(41, 74, 122, 255)
31 | override val titleBarHovered = rgbaColor(66, 150, 250, 255)
32 | override val titleBarSelected = rgbaColor(66, 150, 250, 255)
33 |
34 | override val link = rgbaColor(61, 133, 224, 200)
35 | override val linkHovered = rgbaColor(66, 150, 250, 255)
36 | override val linkSelected = rgbaColor(66, 150, 250, 255)
37 |
38 | override val pin = rgbaColor(53, 150, 250, 180)
39 | override val pinHovered = rgbaColor(53, 150, 250, 255)
40 |
41 | override val boxSelector = rgbaColor(61, 133, 224, 30)
42 | override val boxSelectorOutline = rgbaColor(61, 133, 224, 150)
43 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/util/ExtraWidgets.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.gui.util
20 |
21 | import imgui.ImGui
22 | import imgui.flag.ImGuiMouseButton
23 | import imgui.type.ImInt
24 |
25 | object ExtraWidgets {
26 |
27 | fun rangeSliders(min: Int, max: Int,
28 | minValue: ImInt, maxValue: ImInt,
29 | minId: Int, maxId: Int,
30 | width: Float = 110f) {
31 | ImGui.pushItemWidth(width)
32 | ImGui.sliderInt("###$minId", minValue.data, min, max)
33 |
34 | ImGui.sameLine()
35 |
36 | ImGui.sliderInt("###$maxId", maxValue.data, min, max)
37 | ImGui.popItemWidth()
38 |
39 | val mn = minValue.get()
40 | val mx = maxValue.get()
41 |
42 | if(mn > mx) {
43 | minValue.set(mx)
44 | }
45 | if(mx < mn) {
46 | maxValue.set(mn)
47 | }
48 | }
49 |
50 | private val valuesStringCache = mutableMapOf, Array>()
51 |
52 | fun > enumCombo(values: Array, currentItem: ImInt): T {
53 | val clazz = values[0]::class.java
54 |
55 | val valuesStrings = if (valuesStringCache.containsKey(clazz)) {
56 | valuesStringCache[clazz]!!
57 | } else {
58 | val v = values.map {
59 | it.name
60 | }.toTypedArray()
61 | valuesStringCache[clazz] = v
62 |
63 | v
64 | }
65 |
66 | ImGui.combo("", currentItem, valuesStrings)
67 |
68 | return values[currentItem.get()]
69 | }
70 |
71 | fun toggleButton(label: String, currentState: Boolean): Boolean {
72 | ImGui.button(label)
73 |
74 | return if(ImGui.isItemClicked(ImGuiMouseButton.Left)) {
75 | !currentState
76 | } else currentState
77 | }
78 |
79 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/gui/util/SysUtil.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.gui.util
2 |
3 | import java.lang.management.ManagementFactory
4 |
5 | enum class OperatingSystem {
6 | WINDOWS,
7 | LINUX,
8 | MACOS,
9 | UNKNOWN
10 | }
11 |
12 | val OS: OperatingSystem get() {
13 | val osName = System.getProperty("os.name").lowercase()
14 |
15 | return when {
16 | osName.contains("win") -> OperatingSystem.WINDOWS
17 | osName.contains("nux") -> OperatingSystem.LINUX
18 | osName.contains("mac") || osName.contains("darwin") -> OperatingSystem.MACOS
19 | else -> OperatingSystem.UNKNOWN
20 | }
21 | }
22 |
23 | enum class SystemArchitecture {
24 | X86,
25 | X86_64,
26 | ARMv7,
27 | ARMv8,
28 | UNKNOWN
29 | }
30 |
31 | val ARCH: SystemArchitecture get() {
32 | val arch = System.getProperty("os.arch")
33 |
34 | return when {
35 | arch.contains("amd64") || arch.contains("x86_64") -> SystemArchitecture.X86_64
36 | arch.contains("x86") || arch.contains("i38") -> SystemArchitecture.X86
37 | arch.contains("arm64") || arch.contains("aarch") -> SystemArchitecture.ARMv8
38 | arch.contains("arm") -> SystemArchitecture.ARMv7
39 | else -> SystemArchitecture.UNKNOWN
40 | }
41 | }
42 |
43 | fun getMemoryUsageMB(): Long {
44 | val mb = 1024 * 1024
45 | return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / mb
46 | }
47 |
48 | fun getProcessCPULoad(): Double {
49 | val osBean = ManagementFactory.getOperatingSystemMXBean() as com.sun.management.OperatingSystemMXBean
50 | return osBean.processCpuLoad
51 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/id/IdElement.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.id
20 |
21 | object NoneIdElement : IdElement {
22 | override val id = 0xDAFC
23 | }
24 |
25 | interface IdElement {
26 | val id: Int
27 | }
28 |
29 | interface DrawableIdElement : IdElement {
30 |
31 | fun draw()
32 |
33 | fun delete()
34 |
35 | fun restore()
36 |
37 | fun onEnable() { }
38 |
39 | fun enable()
40 |
41 | fun pollChange(): Boolean
42 |
43 | }
44 |
45 | @Suppress("UNCHECKED_CAST")
46 | abstract class DrawableIdElementBase> : DrawableIdElement {
47 |
48 | abstract val idElementContainer: IdElementContainer
49 |
50 | var hasEnabled = false
51 | private set
52 |
53 | val isEnabled get() = idElementContainer.has(id, this as T)
54 |
55 | open val requestedId: Int? = null
56 |
57 | private var internalId: Int? = null
58 |
59 | override val id: Int get() {
60 | if(internalId == null) {
61 | enable()
62 | }
63 |
64 | return internalId!!
65 | }
66 |
67 | override fun enable() {
68 | if(internalId == null || !idElementContainer.has(id, this as T)) {
69 | internalId = provideId()
70 | onEnable()
71 | hasEnabled = true
72 | }
73 | }
74 |
75 | protected open fun provideId() =
76 | if(requestedId == null) {
77 | idElementContainer.nextId(this as T).value
78 | } else idElementContainer.requestId(this as T, requestedId!!).value
79 |
80 | override fun delete() {
81 | idElementContainer.removeId(id)
82 | }
83 |
84 | override fun restore() {
85 | idElementContainer[id] = this as T
86 | }
87 |
88 | override fun pollChange() = false
89 |
90 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/io/Util.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.io
20 |
21 | import java.io.File
22 | import java.io.InputStream
23 | import java.nio.file.Files
24 | import java.nio.file.StandardCopyOption
25 |
26 | import java.awt.image.BufferedImage
27 |
28 | import java.awt.Image
29 | import java.awt.image.DataBufferByte
30 | import javax.imageio.ImageIO
31 |
32 | fun copyToFile(inp: InputStream, file: File, replaceIfExisting: Boolean = true) {
33 | if(file.exists() && !replaceIfExisting) return
34 |
35 | Files.copy(inp, file.toPath(), StandardCopyOption.REPLACE_EXISTING)
36 | }
37 |
38 | fun copyToTempFile(inp: InputStream, name: String, replaceIfExisting: Boolean = true): File {
39 | val tmpDir = System.getProperty("java.io.tmpdir")
40 | val tempFile = File(tmpDir + File.separator + name)
41 |
42 | copyToFile(inp, tempFile, replaceIfExisting)
43 |
44 | return tempFile
45 | }
46 |
47 | val String.fileExtension: String? get() {
48 | return if(contains(".")) {
49 | substring(lastIndexOf(".") + 1)
50 | } else {
51 | null
52 | }
53 | }
54 |
55 | fun resourceToString(resourcePath: String): String {
56 | val stream = KeyManager::class.java.getResourceAsStream(resourcePath)!!
57 | return stream.bufferedReader().use { it.readText() }
58 | }
59 |
60 | fun bufferedImageFromResource(resourcePath: String): BufferedImage = ImageIO.read(
61 | KeyManager::class.java.getResourceAsStream(resourcePath)!!
62 | )
63 |
64 | fun BufferedImage.bytes(): ByteArray = (raster.dataBuffer as DataBufferByte).data
65 |
66 | fun BufferedImage.scaleToFit(newWidth: Int, newHeight: Int): BufferedImage {
67 | val scalex = newWidth.toDouble() / width
68 | val scaley = newHeight.toDouble() / height
69 | val scale = scalex.coerceAtMost(scaley)
70 |
71 | val w = (width * scale).toInt()
72 | val h = (height * scale).toInt()
73 |
74 | val tmp = getScaledInstance(w, h, Image.SCALE_SMOOTH)
75 |
76 | val resized = BufferedImage(w, h, type)
77 | val g2d = resized.createGraphics()
78 |
79 | g2d.drawImage(tmp, 0, 0, null)
80 | g2d.dispose()
81 |
82 | tmp.flush()
83 |
84 | return resized
85 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/io/turbojpeg/TJLoader.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.io.turbojpeg
2 |
3 | import java.io.File
4 | import java.io.IOException
5 | import java.nio.file.Files
6 | import java.nio.file.StandardCopyOption
7 | import java.util.*
8 |
9 | object TJLoader {
10 | fun load() {
11 | // get os and arch
12 | val os = System.getProperty("os.name").lowercase(Locale.getDefault())
13 | val arch = System.getProperty("os.arch").lowercase(Locale.getDefault())
14 |
15 | var libPath: String? = null
16 |
17 | if (os.contains("win")) {
18 | if (arch.contains("64")) {
19 | libPath = "/META-INF/lib/windows_64/turbojpeg.dll"
20 | } else {
21 | libPath = "/META-INF/lib/windows_32/turbojpeg.dll"
22 | }
23 | } else if (os.contains("linux")) {
24 | if (arch.contains("64")) {
25 | libPath = "/META-INF/lib/linux_64/libturbojpeg.so"
26 | } else {
27 | libPath = "/META-INF/lib/linux_32/libturbojpeg.so"
28 | }
29 | } else if (os.contains("mac") || os.contains("darwin")) {
30 | if (arch.contains("64")) {
31 | libPath = "/META-INF/lib/osx_64/libturbojpeg.dylib"
32 | } else if (arch.contains("ppc")) {
33 | libPath = "/META-INF/lib/osx_ppc/libturbojpeg.dylib"
34 | } else {
35 | libPath = "/META-INF/lib/osx_32/libturbojpeg.dylib"
36 | }
37 | }
38 |
39 | if (libPath == null) {
40 | throw RuntimeException("Unsupported OS/Arch: " + os + " " + arch)
41 | }
42 |
43 | loadFromResource(libPath)
44 | }
45 |
46 | private fun loadFromResource(resource: String) {
47 | try {
48 | TJLoader::class.java.getResourceAsStream(resource).use { res ->
49 | if (res == null) {
50 | throw RuntimeException("Native lib not found: " + resource)
51 | }
52 | // Crear archivo temporal
53 | val tempFile = File.createTempFile("libturbojpeg", getFileExtension(resource))
54 | tempFile.deleteOnExit() // Eliminar después de ejecución
55 |
56 | // Copiar contenido
57 | Files.copy(res, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
58 |
59 | // Cargar la biblioteca
60 | System.load(tempFile.getAbsolutePath())
61 | }
62 | } catch (e: IOException) {
63 | throw RuntimeException(e)
64 | }
65 | }
66 |
67 |
68 | private fun getFileExtension(path: String): String {
69 | if (path.endsWith(".dll")) return ".dll"
70 | if (path.endsWith(".so")) return ".so"
71 | if (path.endsWith(".dylib")) return ".dylib"
72 | return ""
73 | }
74 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/node/FlagsNode.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.node
2 |
3 | import io.github.deltacv.papervision.serialization.data.SerializeData
4 |
5 | @PaperNode(
6 | name = "Flags",
7 | description = "A node that holds flags",
8 | category = Category.MISC,
9 | showInList = false
10 | )
11 | class FlagsNode : InvisibleNode() {
12 |
13 | override val requestedId = 171
14 |
15 | @SerializeData
16 | val flags = mutableMapOf()
17 |
18 | @SerializeData
19 | val numFlags = mutableMapOf()
20 |
21 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/node/InvisibleNode.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.node
20 |
21 | import imgui.extension.imnodes.ImNodes
22 | import imgui.extension.imnodes.flag.ImNodesCol
23 | import io.github.deltacv.papervision.codegen.CodeGen
24 | import io.github.deltacv.papervision.codegen.NoSession
25 | import io.github.deltacv.papervision.gui.style.rgbaColor
26 | import io.github.deltacv.papervision.serialization.data.SerializeIgnore
27 |
28 | @SerializeIgnore
29 | open class InvisibleNode : Node(allowDelete = false) {
30 |
31 | private val invisibleColor = rgbaColor(0, 0, 0, 0)
32 |
33 | override fun draw() {
34 | ImNodes.pushColorStyle(ImNodesCol.NodeOutline, invisibleColor)
35 | ImNodes.pushColorStyle(ImNodesCol.TitleBar, invisibleColor)
36 | ImNodes.pushColorStyle(ImNodesCol.TitleBarHovered, invisibleColor)
37 | ImNodes.pushColorStyle(ImNodesCol.TitleBarSelected, invisibleColor)
38 | ImNodes.pushColorStyle(ImNodesCol.NodeBackground, invisibleColor)
39 | ImNodes.pushColorStyle(ImNodesCol.NodeBackgroundHovered, invisibleColor)
40 | ImNodes.pushColorStyle(ImNodesCol.NodeBackgroundSelected, invisibleColor)
41 |
42 | ImNodes.beginNode(id)
43 | ImNodes.endNode()
44 |
45 | repeat(7) {
46 | ImNodes.popColorStyle()
47 | }
48 | }
49 |
50 | override fun genCode(current: CodeGen.Current) = NoSession
51 |
52 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/node/NodeRegistry.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.node
20 |
21 | import io.github.deltacv.papervision.gui.CategorizedNodes
22 | import io.github.deltacv.papervision.util.hasSuperclass
23 |
24 | @Suppress("UNCHECKED_CAST")
25 | object NodeRegistry {
26 |
27 | val nodes: CategorizedNodes = mutableMapOf()
28 |
29 | init {
30 | // Register nodes from metadata generated by KSP - NodeAnnotationProcessor
31 | fromMetadataClasslist(PaperNodeClassesMetadata.classList)
32 | }
33 |
34 | fun fromMetadataClasslist(classList: List) {
35 | for (className in classList) {
36 | val clazz = NodeRegistry::class.java.classLoader.loadClass(className)
37 | val regAnnotation = clazz.getDeclaredAnnotation(PaperNode::class.java)
38 |
39 | if (clazz.hasSuperclass(Node::class.java)) {
40 | val nodeClazz = clazz as Class>
41 | registerNode(nodeClazz, regAnnotation.category)
42 | }
43 | }
44 | }
45 |
46 | fun registerNode(nodeClass: Class>, category: Category) {
47 | val list = nodes[category]
48 |
49 | val mutableNodes = nodes as MutableMap
50 |
51 | if (list == null) {
52 | mutableNodes[category] = mutableListOf(nodeClass)
53 | } else {
54 | list.add(nodeClass)
55 | }
56 | }
57 |
58 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/node/code/CodeSnippetNode.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.node.code
20 |
21 | import io.github.deltacv.papervision.codegen.CodeGen
22 | import io.github.deltacv.papervision.codegen.CodeGenSession
23 | import io.github.deltacv.papervision.node.Category
24 | import io.github.deltacv.papervision.node.DrawNode
25 | import io.github.deltacv.papervision.node.PaperNode
26 |
27 | /* @PaperNode(
28 | name = "nod_codesnippet",
29 | category = Category.CODE,
30 | description = "A user-written snippet of Java code that will be inlined in the final pipeline, with configurable parameters and outputs."
31 | ) */
32 | class CodeSnippetNode : DrawNode() {
33 |
34 | override fun drawNode() {
35 |
36 | }
37 |
38 | override fun genCode(current: CodeGen.Current): Session {
39 | TODO("Not yet implemented")
40 | }
41 |
42 | class Session : CodeGenSession {
43 |
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/node/math/SumIntegerNode.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.node.math
20 |
21 | import io.github.deltacv.papervision.attribute.Attribute
22 | import io.github.deltacv.papervision.node.DrawNode
23 | import io.github.deltacv.papervision.attribute.math.IntAttribute
24 | import io.github.deltacv.papervision.attribute.misc.ListAttribute
25 | import io.github.deltacv.papervision.codegen.CodeGen
26 | import io.github.deltacv.papervision.codegen.CodeGenSession
27 | import io.github.deltacv.papervision.codegen.GenValue
28 | import io.github.deltacv.papervision.node.PaperNode
29 | import io.github.deltacv.papervision.node.Category
30 |
31 | /*
32 | @PaperNode(
33 | name = "nod_sumintegers",
34 | category = Category.MATH,
35 | description = "Sums a list of integers and outputs the result"
36 | )*/
37 | class SumIntegerNode : DrawNode() {
38 |
39 | val numbers = ListAttribute(INPUT, IntAttribute, "$[att_numbers]")
40 | val result = IntAttribute(OUTPUT, "$[att_result]")
41 |
42 | override fun onEnable() {
43 | + numbers
44 | + result
45 | }
46 |
47 | override fun genCode(current: CodeGen.Current) = current {
48 | val session = Session()
49 |
50 | session
51 | }
52 |
53 | override fun getOutputValueOf(current: CodeGen.Current, attrib: Attribute): GenValue {
54 | genCodeIfNecessary(current)
55 |
56 | if(attrib == result) {
57 | return lastGenSession!!.result
58 | }
59 |
60 | noValue(attrib)
61 | }
62 |
63 | class Session : CodeGenSession {
64 | lateinit var result: GenValue.Int
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/node/vision/ColorSpace.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.node.vision
20 |
21 | enum class ColorSpace(val channels: Int, val channelNames: Array) {
22 | RGBA(4, arrayOf("R", "G", "B", "A")),
23 | RGB(3, arrayOf("R", "G", "B")),
24 | BGR(3, arrayOf("B", "G", "R")),
25 | HSV(3, arrayOf("H", "S", "V")),
26 | YCrCb(3, arrayOf("Y", "Cr", "Cb")),
27 | LAB(3, arrayOf("L", "a", "b")),
28 | GRAY(1, arrayOf("Gray"))
29 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/platform/PlatformConfig.kt:
--------------------------------------------------------------------------------
1 | package io.github.deltacv.papervision.platform
2 |
3 | import com.google.gson.GsonBuilder
4 | import io.github.deltacv.papervision.util.loggerForThis
5 | import java.io.File
6 |
7 | class PaperVisionConfig {
8 | @JvmField
9 | var lang = "en"
10 |
11 | @JvmField
12 | var shouldAskForLang = true
13 | }
14 |
15 | abstract class PlatformConfig {
16 | var fields = PaperVisionConfig()
17 |
18 | abstract fun load()
19 | abstract fun save()
20 | }
21 |
22 | val defaultConfigPath = System.getProperty("user.home") + File.separator + ".papervision" + File.separator + "config.json"
23 |
24 | class DefaultFilePlatformConfig : FilePlatformConfig(defaultConfigPath) {
25 | init {
26 | File(defaultConfigPath).parentFile.mkdirs()
27 | }
28 | }
29 |
30 | open class FilePlatformConfig(
31 | val path: String
32 | ) : PlatformConfig() {
33 |
34 | val gson = GsonBuilder().setPrettyPrinting().create()
35 | val file = File(path)
36 |
37 | val logger by loggerForThis()
38 |
39 | init {
40 | Runtime.getRuntime().addShutdownHook(Thread {
41 | save()
42 | })
43 | }
44 |
45 | override fun load() {
46 | if(!file.exists()) {
47 | save()
48 | return
49 | }
50 |
51 | logger.info("Loading config from $path")
52 | fields = gson.fromJson(file.readText(), PaperVisionConfig::class.java)
53 | }
54 |
55 | override fun save() {
56 | logger.info("Saving config to $path")
57 | file.writeText(gson.toJson(fields))
58 | }
59 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/platform/PlatformKeys.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform
20 |
21 | interface PlatformKeys {
22 | val ArrowUp: Int
23 | val ArrowDown: Int
24 | val ArrowLeft: Int
25 | val ArrowRight: Int
26 |
27 | val Escape: Int
28 | val Spacebar: Int
29 | val Delete: Int
30 |
31 | val LeftShift: Int
32 | val RightShift: Int
33 |
34 | val LeftControl: Int
35 | val RightControl: Int
36 |
37 | val LeftSuper: Int
38 | val RightSuper: Int
39 |
40 | val NativeLeftSuper: Int
41 | val NativeRightSuper: Int
42 |
43 | val Z: Int
44 | val Y: Int
45 | val X: Int
46 | val C: Int
47 | val V: Int
48 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/platform/PlatformSetup.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform
20 |
21 | import io.github.deltacv.papervision.engine.bridge.PaperVisionEngineBridge
22 | import io.github.deltacv.papervision.engine.client.ByteMessageReceiver
23 |
24 | class PlatformSetup(val name: String) {
25 | var window: PlatformWindow? = null
26 | var textureFactory: PlatformTextureFactory? = null
27 |
28 | var keys: PlatformKeys? = null
29 |
30 | var showWelcomeWindow = false
31 |
32 | var engineBridge: PaperVisionEngineBridge? = null
33 | var previzByteMessageReceiverProvider: (() -> ByteMessageReceiver)? = null
34 |
35 | var config: PlatformConfig = DefaultFilePlatformConfig()
36 | }
37 |
38 | data class PlatformSetupCallback(val name: String, val block: PlatformSetup.() -> Unit) {
39 | fun setup(): PlatformSetup {
40 | val setup = PlatformSetup(name)
41 | setup.block()
42 | return setup
43 | }
44 | }
45 |
46 | fun platformSetup(name: String, block: PlatformSetup.() -> Unit) = PlatformSetupCallback(name, block)
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/platform/PlatformTexture.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform
20 |
21 | import imgui.ImGui
22 | import io.github.deltacv.papervision.id.DrawableIdElementBase
23 | import io.github.deltacv.papervision.id.IdElementContainer
24 | import io.github.deltacv.papervision.id.IdElementContainerStack
25 | import io.github.deltacv.papervision.io.TextureProcessorQueue
26 | import java.nio.ByteBuffer
27 | import java.util.concurrent.Executor
28 | import java.util.concurrent.Executors
29 |
30 | abstract class PlatformTexture : DrawableIdElementBase() {
31 |
32 | override val idElementContainer = IdElementContainerStack.threadStack.peekNonNull()
33 |
34 | val textureProcessorQueue = IdElementContainerStack.threadStack.peekSingleNonNull()
35 |
36 | abstract val width: Int
37 | abstract val height: Int
38 |
39 | abstract val textureId: Long
40 |
41 | abstract fun set(bytes: ByteArray, colorSpace: ColorSpace = ColorSpace.RGB)
42 | abstract fun set(bytes: ByteBuffer, colorSpace: ColorSpace = ColorSpace.RGB)
43 |
44 | abstract fun setJpeg(bytes: ByteArray)
45 | abstract fun setJpeg(bytes: ByteBuffer)
46 |
47 | override fun draw() {
48 | ImGui.image(textureId, width.toFloat(), height.toFloat())
49 | }
50 |
51 | override fun restore() {
52 | throw UnsupportedOperationException("Cannot restore texture after it has been deleted")
53 | }
54 |
55 | }
56 |
57 | interface PlatformTextureFactory {
58 | fun create(width: Int, height: Int, bytes: ByteArray, colorSpace: ColorSpace = ColorSpace.RGB): PlatformTexture
59 |
60 | fun create(width: Int, height: Int, bytes: ByteBuffer, colorSpace: ColorSpace = ColorSpace.RGB): PlatformTexture
61 |
62 | fun create(resource: String): PlatformTexture
63 |
64 | fun createFromJpegBytes(bytes: ByteBuffer): PlatformTexture
65 | }
66 |
67 | enum class ColorSpace(val channels: Int) {
68 | RGB(3), RGBA(4), BGR(3), BGRA(4)
69 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/platform/PlatformWindow.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform
20 |
21 | import imgui.ImVec2
22 |
23 | data class PlatformFileFilter(
24 | val name: String,
25 | val extensions: List
26 | )
27 |
28 | enum class PlatformFileChooserResult {
29 | CANCELLED,
30 | OK
31 | }
32 |
33 | interface PlatformWindow {
34 |
35 | var title: String
36 | var icon: String
37 |
38 | val size: ImVec2
39 |
40 | var visible: Boolean
41 |
42 | var maximized: Boolean
43 |
44 | var focus: Boolean
45 |
46 | fun requestFocus()
47 |
48 | fun saveFileDialog(content: ByteArray, defaultName: String = "", vararg platformFileFilter: PlatformFileFilter): PlatformFileChooserResult
49 |
50 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/platform/animation/PlatformTextureAnimation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform.animation
20 |
21 | import io.github.deltacv.papervision.id.IdElementContainer
22 | import io.github.deltacv.papervision.platform.ColorSpace
23 | import io.github.deltacv.papervision.platform.PlatformTexture
24 | import java.lang.UnsupportedOperationException
25 | import java.nio.ByteBuffer
26 |
27 | abstract class PlatformTextureAnimation : PlatformTexture() {
28 |
29 | abstract var frame: Int
30 |
31 | abstract var isActive: Boolean
32 |
33 | override val id by animations.nextId()
34 |
35 | var isPaused: Boolean
36 | get() = !isActive
37 | set(value) {
38 | isActive = !value
39 | }
40 |
41 | abstract fun next()
42 |
43 | abstract fun update()
44 |
45 | override fun draw() {
46 | update()
47 | super.draw()
48 | }
49 |
50 | override fun set(bytes: ByteArray, colorSpace: ColorSpace) =
51 | throw UnsupportedOperationException("set() is not supported on animations")
52 |
53 | override fun set(bytes: ByteBuffer, colorSpace: ColorSpace) =
54 | throw UnsupportedOperationException("set() is not supported on animations")
55 |
56 | override fun setJpeg(bytes: ByteArray) =
57 | throw UnsupportedOperationException("setJpeg() is not supported on animations")
58 |
59 | override fun setJpeg(bytes: ByteBuffer) =
60 | throw UnsupportedOperationException("setJpeg() is not supported on animations")
61 |
62 | companion object {
63 | val animations = IdElementContainer()
64 | }
65 |
66 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/platform/animation/TimedTextureAnimation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.platform.animation
20 |
21 | import io.github.deltacv.papervision.platform.PlatformTexture
22 | import io.github.deltacv.papervision.util.ElapsedTime
23 | import java.nio.ByteBuffer
24 |
25 | class TimedTextureAnimation(
26 | val fps: Double,
27 | val textures: Array
28 | ): PlatformTextureAnimation() {
29 |
30 | override var frame = 0
31 | private var halfFrames = 0.0
32 |
33 | override var isActive = true
34 |
35 | private val deltaTimer = ElapsedTime()
36 |
37 | override fun next() {
38 | frame += 1
39 |
40 | if(frame >= textures.size) {
41 | frame = 0
42 | }
43 | }
44 |
45 | override fun update() {
46 | if(isActive) {
47 | halfFrames += fps * deltaTimer.seconds
48 |
49 | frame = halfFrames.toInt()
50 |
51 | if(frame >= textures.size) {
52 | halfFrames -= frame
53 | frame = 0
54 | }
55 | }
56 |
57 | deltaTimer.reset()
58 | }
59 |
60 | override val width: Int get() = textures[frame].width
61 | override val height: Int get() = textures[frame].height
62 |
63 | override val textureId: Long get() = textures[frame].textureId
64 |
65 | override fun delete() {
66 | for(texture in textures) {
67 | texture.delete()
68 | }
69 | isActive = false
70 | }
71 |
72 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/serialization/PaperVisionData.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.serialization
20 |
21 | import imgui.ImVec2
22 |
23 | abstract class AttributeSerializationData {
24 | open var id: Int = 0
25 | }
26 |
27 | class BasicAttribData(id: Int) : AttributeSerializationData() {
28 | init {
29 | this.id = id
30 | }
31 |
32 | constructor(): this(0)
33 | }
34 |
35 | abstract class NodeSerializationData {
36 | open var id: Int = 0
37 | open var nodePos: ImVec2 = ImVec2(0f, 0f)
38 | }
39 |
40 | class BasicNodeData(
41 | id: Int,
42 | nodePos: ImVec2
43 | ) : NodeSerializationData() {
44 |
45 | init {
46 | this.id = id
47 | this.nodePos = nodePos
48 | }
49 |
50 | constructor() : this(0, ImVec2(0f, 0f))
51 |
52 | }
53 |
54 | data class LinkSerializationData(
55 | var from: Int,
56 | var to: Int
57 | ) {
58 | constructor() : this(0, 0)
59 | }
60 |
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/serialization/data/DataSerializable.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.serialization.data
20 |
21 | interface DataSerializable {
22 | val shouldSerialize: Boolean
23 | get() = true
24 |
25 | fun serialize(): D
26 | fun deserialize(data: D)
27 | }
--------------------------------------------------------------------------------
/PaperVision/src/main/kotlin/io/github/deltacv/papervision/serialization/data/DataSerializer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * PaperVision
3 | * Copyright (C) 2024 Sebastian Erives, deltacv
4 |
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 |
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 |
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 |
19 | package io.github.deltacv.papervision.serialization.data
20 |
21 | import com.google.gson.*
22 | import com.google.gson.reflect.TypeToken
23 | import io.github.deltacv.papervision.serialization.data.adapter.DataSerializableAdapter
24 | import io.github.deltacv.papervision.serialization.data.adapter.SerializeIgnoreExclusionStrategy
25 |
26 | object DataSerializer {
27 |
28 | val gson = GsonBuilder()
29 | .registerTypeHierarchyAdapter(DataSerializable::class.java, DataSerializableAdapter)
30 | .addSerializationExclusionStrategy(SerializeIgnoreExclusionStrategy)
31 | .create()
32 |
33 | val type = object : TypeToken