Skip to content

Commit

Permalink
Merge pull request #141 from TeamPictonode/notgull/fix-options
Browse files Browse the repository at this point in the history
Fix node options
  • Loading branch information
notgull committed May 3, 2023
2 parents 6e396a2 + 8ba5a9b commit 980f421
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
17 changes: 15 additions & 2 deletions backend/ontario-web/ontario_web/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class NodeTemplate(Generic[T, M]):
# Metadata for the node.
__metadata: M

__mapNamesToInputs: Dict[int, str]
__mapNamesToOutputs: Dict[int, str]

def __init__(
Expand All @@ -275,6 +276,7 @@ def __init__(
self.__inputs = inputs
self.__outputs = outputs
self.__metadata = metadata
self.__mapNamesToInputs = {}
self.__mapNamesToOutputs = {}

def getMetadata(self) -> M:
Expand Down Expand Up @@ -307,9 +309,15 @@ def process(self, inputs: List[Link[T, M]], metadata: M) -> List[T]:

return self.__onProcess(inputs, metadata)

def insertNamedInput(self, name: str, index: int):
self.__mapNamesToInputs[index] = name

def insertNamedOutput(self, name: str, index: int):
self.__mapNamesToOutputs[index] = name

def getNamedInput(self, index: int) -> Optional[str]:
return self.__mapNamesToInputs.get(index, None)

def getNamedOutput(self, index: int) -> Optional[str]:
return self.__mapNamesToOutputs.get(index, None)

Expand Down Expand Up @@ -484,8 +492,13 @@ def hydrate(self):

# Process the node.
print(f"Links are {self.__inputs}")
for link in self.__inputs:
link.getValue()
for i, link in enumerate(self.__inputs):
name = self.__templateTable.getTemplate(
self.__template).getNamedInput(i)
if name is not None and name in self.__values:
link.setValue(self.__values[name])
else:
link.getValue()
template = self.__templateTable.getTemplate(self.__template)
outputs = template.process(self.__inputs, self.__metadata)
# print(f"Called hydrate, got {outputs}")
Expand Down
13 changes: 11 additions & 2 deletions backend/ontario-web/ontario_web/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,15 @@ def composite(args, meta):
)
table.addTemplate("Invert", invertNode)

def brightContrast(args, meta):
return [load(args[0], meta).brightness_contrast(
args[1].getValue(),
args[2].getValue()
)]

# Adjust brightness/contrast
brightContNode = nodes.NodeTemplate(
lambda args, meta: [
load(args[0], meta).brightness_contrast(args[1], args[2])],
brightContrast,
[
nodes.LinkTemplate(None, None, None),
nodes.LinkTemplate(None, None, "brightness"),
Expand All @@ -153,6 +158,8 @@ def composite(args, meta):
],
None
)
brightContNode.insertNamedInput("brightness", 1)
brightContNode.insertNamedInput("contrast", 2)
table.addTemplate("BrightCont", brightContNode)

guassBlur = nodes.NodeTemplate(
Expand All @@ -168,6 +175,8 @@ def composite(args, meta):
],
None
)
guassBlur.insertNamedInput("std_dev_x", 1)
guassBlur.insertNamedInput("std_dev_y", 2)
table.addTemplate("GaussBlur", guassBlur)

return table
27 changes: 27 additions & 0 deletions frontend/pictonode-web/src/app/NodeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default defineComponent({
editor: new Editor() as Editor,
viewPlugin: new ViewPlugin() as ViewPlugin,
engine: new Engine(true) as Engine,
lastOptions: {},
pipelineId: undefined as number | undefined,
}),
computed: {
Expand Down Expand Up @@ -109,6 +110,8 @@ export default defineComponent({
setForceUpdate(this.onUpdate);
},
mounted() {
this.compareOptions();
const fetchThisPipeline = this.$route.params.pipelineId;
let pipeId = undefined;
if (fetchThisPipeline) {
Expand All @@ -130,6 +133,30 @@ export default defineComponent({
return n;
},
getOptions() {
const options: Record<string, any> = {};
for (const node of this.editor.nodes) {
if (node.options) {
const specs: Record<string, any> = {};
for (const [name, option] of node.options) {
specs[name] = option.value;
}
options[node.id] = specs;
}
}
return options;
},
compareOptions() {
const options = this.getOptions();
if (JSON.stringify(options) !== JSON.stringify(this.lastOptions)) {
this.lastOptions = options;
this.onUpdate();
}
setTimeout(() => this.compareOptions(), 2000);
},
setPipeline(pipeline: any) {
// @ts-ignore
installPipeline(this.editor, pipeline);
Expand Down
11 changes: 11 additions & 0 deletions frontend/pictonode-web/src/components/nodes/NodeData/Arrow.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- copied from baklavajs -->
<template>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6 1.41-1.41z" />
</svg>
</template>
18 changes: 17 additions & 1 deletion frontend/pictonode-web/src/components/nodes/getPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,20 @@ export default function getPipeline(editor: Editor): SerializedPipeline {
// Take the integer part of node.id to get the id of the node.
// This is because node.id is a string of the form "node_<id>".
const node_id = getNodeId(node);
const values = ValueTracker.get_instance().get_value(node.id);

if (node.type === "BrightCont") {
values["brightness"] = node.options.get("Brightness")?.value;
values["contrast"] = node.options.get("Contrast")?.value;
} else if (node.type === "GaussBlur") {
values["std_dev_x"] = node.options.get("X")?.value;
values["std_dev_y"] = node.options.get("Y")?.value;
}

const result: SerializedNode = {
id: node_id,
template: node.type,
values: ValueTracker.get_instance().get_value(node.id),
values,
metadata: {
// @ts-ignore
x: node.position.x,
Expand Down Expand Up @@ -102,6 +111,13 @@ export function installPipeline(
node_id: newNode.id,
});
}
if (node.template === "BrightCont") {
newNode.options.get("Brightness")!.value = node.values.brightness;
newNode.options.get("Contrast")!.value = node.values.contrast;
} else if (node.template === "GaussBlur") {
newNode.options.get("X")!.value = node.values.std_dev_x;
newNode.options.get("Y")!.value = node.values.std_dev_y;
}

// @ts-ignore
newNode.position.x = node.metadata.x;
Expand Down

0 comments on commit 980f421

Please sign in to comment.