formatted_io5¶
Two models, A & B, that send/receive 3D mesh data as Ply meshes. Model A receives input from a file and then sends it’s output to model B. Model B receives input from model A and sends it’s output to a file.
C Version¶
Model Code:
1#include <stdio.h>
2// Include methods for input/output channels
3#include "YggInterface.h"
4
5int main(int argc, char *argv[]) {
6 // Initialize input/output channels
7 yggPlyInput_t in_channel = yggPlyInput("inputA");
8 yggPlyOutput_t out_channel = yggPlyOutput("outputA");
9
10 // Declare resulting variables and create buffer for received message
11 int flag = 1;
12 ply_t p = init_ply();
13
14 // Loop until there is no longer input or the queues are closed
15 while (flag >= 0) {
16
17 // Receive input from input channel
18 // If there is an error, the flag will be negative
19 // Otherwise, it is the size of the received message
20 flag = yggRecv(in_channel, &p);
21 if (flag < 0) {
22 printf("Model A: No more input.\n");
23 break;
24 }
25
26 // Print received message
27 printf("Model A: (%d verts, %d faces)\n",
28 nelements_ply(p, "v"), nelements_ply(p, "f"));
29 display_ply_indent(p, " ");
30
31 // Send output to output channel
32 // If there is an error, the flag will be negative
33 flag = yggSend(out_channel, p);
34 if (flag < 0) {
35 printf("Model A: Error sending output.\n");
36 break;
37 }
38
39 }
40
41 // Free dynamically allocated ply structure
42 free_ply(&p);
43
44 return 0;
45}
46
1#include <stdio.h>
2// Include methods for input/output channels
3#include "YggInterface.h"
4
5int main(int argc, char *argv[]) {
6 // Initialize input/output channels
7 yggPlyInput_t in_channel = yggPlyInput("inputB");
8 yggPlyOutput_t out_channel = yggPlyOutput("outputB");
9
10 // Declare resulting variables and create buffer for received message
11 int flag = 1;
12 ply_t p = init_ply();
13
14 // Loop until there is no longer input or the queues are closed
15 while (flag >= 0) {
16
17 // Receive input from input channel
18 // If there is an error, the flag will be negative
19 // Otherwise, it is the size of the received message
20 flag = yggRecv(in_channel, &p);
21 if (flag < 0) {
22 printf("Model B: No more input.\n");
23 break;
24 }
25
26 // Print received message
27 printf("Model B: (%d verts, %d faces)\n",
28 nelements_ply(p, "v"), nelements_ply(p, "f"));
29 display_ply_indent(p, " ");
30
31 // Send output to output channel
32 // If there is an error, the flag will be negative
33 flag = yggSend(out_channel, p);
34 if (flag < 0) {
35 printf("Model B: Error sending output.\n");
36 break;
37 }
38
39 }
40
41 // Free dynamically allocated ply structure
42 free_ply(&p);
43
44 return 0;
45}
46
Model YAML:
1models:
2 - name: c_modelA
3 language: c
4 args: ./src/formatted_io5_modelA.c
5 inputs: inputA
6 outputs: outputA
7
8 - name: c_modelB
9 language: c
10 args: ./src/formatted_io5_modelB.c
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.ply # Connection between file and model A input
18 output: inputA
19 filetype: ply
20 - input: outputB # Connection between model B output and file
21 output: ./output.ply
22 filetype: ply
C++ Version¶
Model Code:
1#include <iostream>
2// Include methods for input/output channels
3#include "YggInterface.hpp"
4
5int main(int argc, char *argv[]) {
6 // Initialize input/output channels
7 YggPlyInput in_channel("inputA");
8 YggPlyOutput out_channel("outputA");
9
10 // Declare resulting variables and create buffer for received message
11 int flag = 1;
12 rapidjson::Ply p;
13
14 // Loop until there is no longer input or the queues are closed
15 while (flag >= 0) {
16
17 // Receive input from input channel
18 // If there is an error, the flag will be negative
19 // Otherwise, it is the size of the received message
20 flag = in_channel.recv(1, &p);
21 if (flag < 0) {
22 std::cout << "Model A: No more input." << std::endl;
23 break;
24 }
25
26 // Print received message
27 printf("Model A: (%ld verts, %ld faces)\n",
28 p.count_elements("vertex"), p.count_elements("face"));
29 std::cerr << p << std::endl;
30
31 // Send output to output channel
32 // If there is an error, the flag will be negative
33 flag = out_channel.send(1, &p);
34 if (flag < 0) {
35 std::cout << "Model A: Error sending output." << std::endl;
36 break;
37 }
38
39 }
40
41 return 0;
42}
1#include <iostream>
2// Include methods for input/output channels
3#include "YggInterface.hpp"
4
5#define MYBUFSIZ 1000
6
7int main(int argc, char *argv[]) {
8 // Initialize input/output channels
9 YggPlyInput in_channel("inputB");
10 YggPlyOutput out_channel("outputB");
11
12 // Declare resulting variables and create buffer for received message
13 int flag = 1;
14 rapidjson::Ply p;
15
16 // Loop until there is no longer input or the queues are closed
17 while (flag >= 0) {
18
19 // Receive input from input channel
20 // If there is an error, the flag will be negative
21 // Otherwise, it is the size of the received message
22 flag = in_channel.recv(1, &p);
23 if (flag < 0) {
24 std::cout << "Model B: No more input." << std::endl;
25 break;
26 }
27
28 // Print received message
29 printf("Model B: (%ld verts, %ld faces)\n",
30 p.count_elements("vertex"), p.count_elements("face"));
31 std::cerr << p << std::endl;
32
33 // Send output to output channel
34 // If there is an error, the flag will be negative
35 flag = out_channel.send(1, &p);
36 if (flag < 0) {
37 std::cout << "Model B: Error sending output." << std::endl;
38 break;
39 }
40
41 }
42
43 return 0;
44}
Model YAML:
1models:
2 - name: cpp_modelA
3 language: c++
4 args: ./src/formatted_io5_modelA.cpp
5 inputs: inputA
6 outputs: outputA
7
8 - name: cpp_modelB
9 language: c++
10 args: ./src/formatted_io5_modelB.cpp
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.ply # Connection between file and model A input
18 output: inputA
19 filetype: ply
20 - input: outputB # Connection between model B output and file
21 output: ./output.ply
22 filetype: ply
Fortran Version¶
Model Code:
1program main
2 ! Include methods for input/output channels
3 use fygg
4
5 ! Declare resulting variables and create buffer for received message
6 logical :: flag = .true.
7 type(yggcomm) :: in_channel, out_channel
8 type(yggply) :: p
9 p = init_ply()
10
11 ! initialize input/output channels
12 in_channel = ygg_ply_input("inputA")
13 out_channel = ygg_ply_output("outputA")
14
15 ! Loop until there is no longer input or the queues are closed
16 do while (flag)
17
18 ! Receive input from input channel
19 ! If there is an error, the flag will be negative
20 ! Otherwise, it is the number of variables filled
21 flag = ygg_recv_var(in_channel, yggarg(p))
22 if (.not.flag) then
23 print *, "Model A: No more input."
24 exit
25 end if
26
27 ! Print received message
28 print *, "Model A: (", &
29 nelements_ply(p, "vertex"), " verts, ", &
30 nelements_ply(p, "face"), " faces)"
31 call display_ply_indent(p, " ")
32
33 ! Send output to output channel
34 ! If there is an error, the flag will be negative
35 flag = ygg_send_var(out_channel, yggarg(p))
36 if (.not.flag) then
37 print *, "Model A: Error sending output."
38 exit
39 end if
40
41 end do
42
43end program main
1program main
2 ! Include methods for input/output channels
3 use fygg
4
5 ! Declare resulting variables and create buffer for received message
6 logical :: flag = .true.
7 type(yggcomm) :: in_channel, out_channel
8 type(yggply) :: p
9 p = init_ply()
10
11 ! initialize input/output channels
12 in_channel = ygg_ply_input("inputB")
13 out_channel = ygg_ply_output("outputB")
14
15 ! Loop until there is no longer input or the queues are closed
16 do while (flag)
17
18 ! Receive input from input channel
19 ! If there is an error, the flag will be negative
20 ! Otherwise, it is the number of variables filled
21 flag = ygg_recv_var(in_channel, yggarg(p))
22 if (.not.flag) then
23 print *, "Model B: No more input."
24 exit
25 end if
26
27 ! Print received message
28 print *, "Model B: (", &
29 nelements_ply(p, "vertex"), " verts, ", &
30 nelements_ply(p, "face"), " faces)"
31 call display_ply_indent(p, " ")
32
33 ! Send output to output channel
34 ! If there is an error, the flag will be negative
35 flag = ygg_send_var(out_channel, yggarg(p))
36 if (.not.flag) then
37 print *, "Model B: Error sending output."
38 exit
39 end if
40
41 end do
42
43end program main
Model YAML:
1models:
2 - name: fortran_modelA
3 language: fortran
4 args: ./src/formatted_io5_modelA.f90
5 inputs: inputA
6 outputs: outputA
7
8 - name: fortran_modelB
9 language: fortran
10 args: ./src/formatted_io5_modelB.f90
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.ply # Connection between file and model A input
18 output: inputA
19 filetype: ply
20 - input: outputB # Connection between model B output and file
21 output: ./output.ply
22 filetype: ply
Julia Version¶
Model Code:
1# Import library for input/output channels
2using Yggdrasil
3using Printf
4
5# Initialize input/output channels
6in_channel = Yggdrasil.YggInterface("YggPlyInput", "inputA")
7out_channel = Yggdrasil.YggInterface("YggPlyOutput", "outputA")
8
9# Loop until there is no longer input or the queues are closed
10while true
11
12 # Receive input from input channel
13 # If there is an error, the flag will be false
14 flag, ply = in_channel.recv()
15 if (!flag)
16 println("Model A: No more input.")
17 break
18 end
19
20 # Print received message
21 println(ply)
22 # @printf("Model A: (%d verts, %d faces)\n",
23 # length(get(ply, "vertices")),
24 # length(get(ply, "faces")))
25
26 # Send output to output channel
27 # If there is an error, the flag will be false
28 flag = out_channel.send(ply)
29 if (!flag)
30 error("Model A: Error sending output.")
31 end
32
33end # while
1# Import library for input/output channels
2using Yggdrasil
3using Printf
4
5# Initialize input/output channels
6in_channel = Yggdrasil.YggInterface("YggPlyInput", "inputB")
7out_channel = Yggdrasil.YggInterface("YggPlyOutput", "outputB")
8
9# Loop until there is no longer input or the queues are closed
10while true
11
12 # Receive input from input channel
13 # If there is an error, the flag will be false
14 flag, ply = in_channel.recv()
15 if (!flag)
16 println("Model B: No more input.")
17 break
18 end
19
20 # Print received message
21 println(ply)
22 # @printf("Model B: (%d verts, %d faces)\n",
23 # length(get(ply, "vertices")),
24 # length(get(ply, "faces")))
25
26 # Send output to output channel
27 # If there is an error, the flag will be false
28 flag = out_channel.send(ply)
29 if (!flag)
30 error("Model B: Error sending output.")
31 end
32
33end # while
Model YAML:
1models:
2 - name: julia_modelA
3 language: julia
4 args: ./src/formatted_io5_modelA.jl
5 inputs: inputA
6 outputs: outputA
7
8 - name: julia_modelB
9 language: julia
10 args: ./src/formatted_io5_modelB.jl
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.ply # Connection between file and model A input
18 output: inputA
19 filetype: ply
20 - input: outputB # Connection between model B output and file
21 output: ./output.ply
22 filetype: ply
Matlab Version¶
Model Code:
1% Initialize input/output channels
2in_channel = YggInterface('YggPlyInput', 'inputA');
3out_channel = YggInterface('YggPlyOutput', 'outputA');
4
5flag = true;
6
7% Loop until there is no longer input or the queues are closed
8while flag
9
10 % Receive input from input channel
11 % If there is an error, the flag will be False.
12 [flag, ply] = in_channel.recv();
13 if (~flag)
14 disp('Model A: No more input.');
15 break;
16 end;
17
18 % Print received message
19 fprintf('Model A: (%d verts, %d faces)\n', ...
20 length(ply('vertices')), length(ply('faces')));
21 disp(ply);
22
23 % Send output to output channel
24 % If there is an error, the flag will be False
25 flag = out_channel.send(ply);
26 if (~flag)
27 error('Model A: Error sending output.');
28 break;
29 end;
30
31end;
1% Initialize input/output channels
2in_channel = YggInterface('YggPlyInput', 'inputB');
3out_channel = YggInterface('YggPlyOutput', 'outputB');
4
5flag = true;
6
7% Loop until there is no longer input or the queues are closed
8while flag
9
10 % Receive input from input channel
11 % If there is an error, the flag will be False.
12 [flag, ply] = in_channel.recv();
13 if (~flag)
14 disp('Model B: No more input.');
15 break;
16 end;
17
18 % Print received message
19 fprintf('Model B: (%d verts, %d faces)\n', ...
20 length(ply('vertices')), length(ply('faces')));
21 disp(ply);
22
23 % Send output to output channel
24 % If there is an error, the flag will be False
25 flag = out_channel.send(ply);
26 if (~flag)
27 error('Model B: Error sending output.');
28 break;
29 end;
30
31end;
Model YAML:
1models:
2 - name: matlab_modelA
3 language: matlab
4 args: ./src/formatted_io5_modelA.m
5 inputs: inputA
6 outputs: outputA
7
8 - name: matlab_modelB
9 language: matlab
10 args: ./src/formatted_io5_modelB.m
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.ply # Connection between file and model A input
18 output: inputA
19 filetype: ply
20 - input: outputB # Connection between model B output and file
21 output: ./output.ply
22 filetype: ply
Python Version¶
Model Code:
1import pprint
2# Import classes for input/output channels
3from yggdrasil.interface.YggInterface import (
4 YggPlyInput, YggPlyOutput)
5
6# Initialize input/output channels
7in_channel = YggPlyInput('inputA')
8out_channel = YggPlyOutput('outputA')
9
10# Loop until there is no longer input or the queues are closed
11while True:
12
13 # Receive input from input channel
14 # If there is an error, the flag will be False
15 flag, ply = in_channel.recv()
16 if not flag:
17 print("Model A: No more input.")
18 break
19
20 # Print received message
21 print('Model A: (%d verts, %d faces)' % (ply.nvert, ply.nface))
22 pprint.pprint(ply)
23
24 # Send output to output channel
25 # If there is an error, the flag will be False
26 flag = out_channel.send(ply)
27 if not flag:
28 raise RuntimeError("Model A: Error sending output.")
1import pprint
2# Import classes for input/output channels
3from yggdrasil.interface.YggInterface import (
4 YggPlyInput, YggPlyOutput)
5
6# Initialize input/output channels
7in_channel = YggPlyInput('inputB')
8out_channel = YggPlyOutput('outputB')
9
10# Loop until there is no longer input or the queues are closed
11while True:
12
13 # Receive input from input channel
14 # If there is an error, the flag will be False
15 flag, ply = in_channel.recv()
16 if not flag:
17 print("Model B: No more input.")
18 break
19
20 # Print received message
21 print('Model B: (%d verts, %d faces)' % (ply.nvert, ply.nface))
22 pprint.pprint(ply)
23
24 # Send output to output channel
25 # If there is an error, the flag will be False
26 flag = out_channel.send(ply)
27 if not flag:
28 raise RuntimeError("Model B: Error sending output.")
Model YAML:
1models:
2 - name: python_modelA
3 language: python
4 args: ./src/formatted_io5_modelA.py
5 inputs: inputA
6 outputs: outputA
7
8 - name: python_modelB
9 language: python
10 args: ./src/formatted_io5_modelB.py
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.ply # Connection between file and model A input
18 output: inputA
19 filetype: ply
20 - input: outputB # Connection between model B output and file
21 output: ./output.ply
22 filetype: ply
R Version¶
Model Code:
1# Import library for input/output
2library(yggdrasil)
3
4# Initialize input/output channels
5in_channel <- YggInterface('YggPlyInput', 'inputA')
6out_channel <- YggInterface('YggPlyOutput', 'outputA')
7
8# Loop until there is no longer input or the queues are closed
9while(TRUE) {
10
11 # Receive input from input channel
12 # If there is an error, the flag will be False
13 c(flag, ply) %<-% in_channel$recv()
14 if (!flag) {
15 print('Model A: No more input.')
16 break
17 }
18
19 # Print received message
20 fprintf('Model A: (%d verts, %d faces)',
21 length(ply[['vertices']]), length(ply[['faces']]))
22
23 # Send output to output channel
24 # If there is an error, the flag will be False
25 flag = out_channel$send(ply)
26 if (!flag) {
27 stop('Model A: Error sending output.')
28 }
29
30}
1# Import library for input/output
2library(yggdrasil)
3
4# Initialize input/output channels
5in_channel <- YggInterface('YggPlyInput', 'inputB')
6out_channel <- YggInterface('YggPlyOutput', 'outputB')
7
8# Loop until there is no longer input or the queues are closed
9while(TRUE) {
10
11 # Receive input from input channel
12 # If there is an error, the flag will be False
13 c(flag, ply) %<-% in_channel$recv()
14 if (!flag) {
15 print('Model B: No more input.')
16 break
17 }
18
19 # Print received message
20 fprintf('Model B: (%d verts, %d faces)',
21 length(ply[['vertices']]), length(ply[['faces']]))
22
23 # Send output to output channel
24 # If there is an error, the flag will be False
25 flag = out_channel$send(ply)
26 if (!flag) {
27 stop('Model B: Error sending output.')
28 }
29
30}
Model YAML:
1models:
2 - name: R_modelA
3 language: R
4 args: ./src/formatted_io5_modelA.R
5 inputs: inputA
6 outputs: outputA
7
8 - name: R_modelB
9 language: R
10 args: ./src/formatted_io5_modelB.R
11 inputs: inputB
12 outputs: outputB
13
14connections:
15 - input: outputA # Connection between model A output & model B input
16 output: inputB
17 - input: ./Input/input.ply # Connection between file and model A input
18 output: inputA
19 filetype: ply
20 - input: outputB # Connection between model B output and file
21 output: ./output.ply
22 filetype: ply