Skip to content

Commit

Permalink
refeito samples para deixá-los mais simples
Browse files Browse the repository at this point in the history
  • Loading branch information
Piemontez committed Apr 30, 2024
1 parent ee375d6 commit cbdffde
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 107 deletions.
12 changes: 12 additions & 0 deletions src/core/utils/makeXYPosition.ts
@@ -0,0 +1,12 @@
import { XYPosition } from 'reactflow';
import { NodeSizes } from '../../core/config/sizes';

export const makeXYPosition = (gridX: number, gridY: number, padding?: number): XYPosition => {
if (padding === undefined) {
padding = NodeSizes.defaultWidth / 3;
}
return {
x: (NodeSizes.defaultWidth + padding) * gridX,
y: (NodeSizes.defaultHeight + padding) * gridY,
};
};
81 changes: 21 additions & 60 deletions src/plugins/opencvTemplates/morphology-samples.ts
Expand Up @@ -3,110 +3,71 @@ import { ClosingComponent } from '../opencv/morphology/ClosingComponent';
import { OpeningComponent } from '../opencv/morphology/OpeningComponent';
import { DilateComponent } from '../opencv/morphology/DilateComponent';
import { ErodeComponent } from '../opencv/morphology/ErodeComponent';
import { XYPosition } from 'reactflow';
import { CVKernelComponent } from '../opencv/inputs/CVKernelComponent';
import { CVVideoCaptureComponent } from '../opencv/inputs/CVVideoCaptureComponent';
import { NodeSizes } from '../../core/config/sizes';
import { CvtColorComponent } from '../opencv/conversors/CvtColorComponent';
import { CVFComponent } from '../../ide/types/component';
import { ProjectTemplate } from '../../core/types/project-template';
import { CVResizeComponent } from '../opencv/geometricTransformations';
import { useNodeStore } from '../../core/contexts/NodeStore';
import cv from 'opencv-ts';
import { ThresholdComponent } from '../opencv/segmentation/ThresholdComponent';
import { makeXYPosition } from '../../core/utils/makeXYPosition';

const group = 'OpenCV';

const makeXYPosition = (gridX: number, gridY: number, padding: number): XYPosition => {
return {
x: (NodeSizes.defaultWidth + padding) * gridX,
y: (NodeSizes.defaultHeight + padding) * gridY,
};
};

const MorphologySamplesAction: ProjectTemplate = {
group,
title: 'Morphology Samples',
action: () => {
const padding = NodeSizes.defaultWidth / 3;
let comp: typeof CVFComponent | null;
let pos;
let gridY = -2;

// Add Video
comp = useNodeStore.getState().getNodeType(CVVideoCaptureComponent.name);
let videoId = '';
if (comp) {
const pos = makeXYPosition(-4, 0, padding);
videoId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(-4, 0);
let videoId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 30 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.

// Add Kernel
comp = useNodeStore.getState().getNodeType(CVKernelComponent.name);
let kernelId = '';
if (comp) {
const pos = makeXYPosition(-2, 2, padding);
kernelId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(-2, 2);
let kernelId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 35 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.

// Add Resize
comp = useNodeStore.getState().getNodeType(CVResizeComponent.name);
let resizeId = '';
if (comp) {
const pos = makeXYPosition(-2, -1, padding);
resizeId = useNodeStore.getState().addNodeFromComponent(comp, pos, { dsize: new cv.Size(128, 128) }).id;
}
pos = makeXYPosition(-2, -1);
let resizeId = useNodeStore.getState().addNodeFromComponent(comp, pos, { dsize: new cv.Size(128, 128) }).id;

Check failure on line 40 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.

// Add Convert
comp = useNodeStore.getState().getNodeType(CvtColorComponent.name);
let cvtColorId = '';
if (comp) {
const pos = makeXYPosition(-2, 0, padding);
cvtColorId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(-2, 0);
let cvtColorId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 45 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.

// Add Threshold BIN
comp = useNodeStore.getState().getNodeType(ThresholdComponent.name);
let trash1 = '';
if (comp) {
const pos = makeXYPosition(-1, 0, padding);
trash1 = useNodeStore.getState().addNodeFromComponent(comp, pos, { thresh: 100, type: cv.THRESH_BINARY_INV }).id;
}
pos = makeXYPosition(0, gridY++);
let trash1 = useNodeStore.getState().addNodeFromComponent(comp, pos, { thresh: 100, type: cv.THRESH_BINARY_INV }).id;

Check failure on line 50 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.

// Add Erode
comp = useNodeStore.getState().getNodeType(ErodeComponent.name);
let erodeId = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
erodeId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
let erodeId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 54 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.
// Add Dilate
comp = useNodeStore.getState().getNodeType(DilateComponent.name);
let dilateId = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
dilateId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(0, gridY++);
let dilateId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 58 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.
// Add Oppening
comp = useNodeStore.getState().getNodeType(OpeningComponent.name);
let opId = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
opId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(0, gridY++);
let opId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 62 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.
// Add Clossi
comp = useNodeStore.getState().getNodeType(ClosingComponent.name);
let closeId = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
closeId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(0, gridY++);
let closeId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 66 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.
// Add Morph
comp = useNodeStore.getState().getNodeType(MorphologyExComponent.name);
let morphId = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
morphId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(0, gridY++);
let morphId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;

Check failure on line 70 in src/plugins/opencvTemplates/morphology-samples.ts

View workflow job for this annotation

GitHub Actions / app_publish

Argument of type 'typeof CVFComponent | null' is not assignable to parameter of type 'typeof CVFComponent'.

useNodeStore.getState().addEdge(videoId, resizeId, 'out', 'src1');
useNodeStore.getState().addEdge(resizeId, cvtColorId, 'out', 'src1');
Expand Down
63 changes: 16 additions & 47 deletions src/plugins/opencvTemplates/threshold-samples.tsx
@@ -1,83 +1,52 @@
import { XYPosition } from 'reactflow';
import { CVVideoCaptureComponent } from '../opencv/inputs/CVVideoCaptureComponent';
import { NodeSizes } from '../../core/config/sizes';
import { CvtColorComponent } from '../opencv/conversors/CvtColorComponent';
import { CVFComponent } from '../../ide/types/component';
import { ThresholdComponent } from '../opencv/segmentation/ThresholdComponent';
import { useNodeStore } from '../../core/contexts/NodeStore';
import { ProjectTemplate } from '../../core/types/project-template';
import { CVResizeComponent } from '../opencv/geometricTransformations';
import { makeXYPosition } from '../../core/utils/makeXYPosition';
import cv from 'opencv-ts';

const group = 'OpenCV';

const makeXYPosition = (gridX: number, gridY: number, padding: number): XYPosition => {
return {
x: (NodeSizes.defaultWidth + padding) * gridX,
y: (NodeSizes.defaultHeight + padding) * gridY,
};
};

const ThresholdSamplesAction: ProjectTemplate = {
group,
title: 'Threshold Samples',
action: () => {
const padding = NodeSizes.defaultWidth / 3;
let comp: typeof CVFComponent | null;
let gridY = -2;
let pos;

// Add Video
comp = useNodeStore.getState().getNodeType(CVVideoCaptureComponent.name);
let videoId = '';
if (comp) {
const pos = makeXYPosition(-3, 0, padding);
videoId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(-3, 0);
const videoId = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;

// Add Resize
comp = useNodeStore.getState().getNodeType(CVResizeComponent.name);
let resizeId = '';
if (comp) {
const pos = makeXYPosition(-1, -1, padding);
resizeId = useNodeStore.getState().addNodeFromComponent(comp, pos, { dsize: new cv.Size(128, 128) }).id;
}

pos = makeXYPosition(-1, -1);
const resizeId = useNodeStore.getState().addNodeFromComponent(comp!, pos, { dsize: new cv.Size(128, 128) }).id;
// Add Convert
comp = useNodeStore.getState().getNodeType(CvtColorComponent.name);
let cvtColorId = '';
if (comp) {
const pos = makeXYPosition(-1, 0, padding);
cvtColorId = useNodeStore.getState().addNodeFromComponent(comp, pos).id;
}
pos = makeXYPosition(-1, 0);
const cvtColorId = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;

// Add Threshold BIN
comp = useNodeStore.getState().getNodeType(ThresholdComponent.name);
let trash1 = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
trash1 = useNodeStore.getState().addNodeFromComponent(comp, pos, { thresh: 100, type: cv.THRESH_BINARY_INV }).id;
}
pos = makeXYPosition(0, -2);
const trash1 = useNodeStore.getState().addNodeFromComponent(comp!, pos, { thresh: 100, type: cv.THRESH_BINARY_INV }).id;
// Add Threshold TRUNC
comp = useNodeStore.getState().getNodeType(ThresholdComponent.name);
let trash2 = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
trash2 = useNodeStore.getState().addNodeFromComponent(comp, pos, { thresh: 100, type: cv.THRESH_TRUNC }).id;
}
pos = makeXYPosition(0, -1);
const trash2 = useNodeStore.getState().addNodeFromComponent(comp!, pos, { thresh: 100, type: cv.THRESH_TRUNC }).id;
// Add Threshold TOZERO
comp = useNodeStore.getState().getNodeType(ThresholdComponent.name);
let trash3 = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
trash3 = useNodeStore.getState().addNodeFromComponent(comp, pos, { thresh: 100, type: cv.THRESH_TOZERO }).id;
}
pos = makeXYPosition(0, -0);
const trash3 = useNodeStore.getState().addNodeFromComponent(comp!, pos, { thresh: 100, type: cv.THRESH_TOZERO }).id;
// Add Threshold OTSU
comp = useNodeStore.getState().getNodeType(ThresholdComponent.name);
let trash4 = '';
if (comp) {
const pos = makeXYPosition(0, gridY++, padding);
trash4 = useNodeStore.getState().addNodeFromComponent(comp, pos, { thresh: 100, type: cv.THRESH_OTSU }).id;
}
pos = makeXYPosition(0, 1);
const trash4 = useNodeStore.getState().addNodeFromComponent(comp!, pos, { thresh: 100, type: cv.THRESH_OTSU }).id;

useNodeStore.getState().addEdge(videoId, resizeId, 'out', 'src1');
useNodeStore.getState().addEdge(resizeId, cvtColorId, 'out', 'src1');
Expand Down

0 comments on commit cbdffde

Please sign in to comment.