formatted_io6 Example — cis_interface 0.3.0 documentation

# formatted_io6 Example

## Python Version

Model Code:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    import pprint
    # Import classes for input/output channels
    from cis_interface.interface.CisInterface import (
        CisObjInput, CisObjOutput)

    # Initialize input/output channels
    in_channel = CisObjInput('inputA')
    out_channel = CisObjOutput('outputA')

    # Loop until there is no longer input or the queues are closed
    while True:

        # Receive input from input channel
        # If there is an error, the flag will be False
        flag, obj = in_channel.recv()
        if not flag:
            print("Model A: No more input.")
            break

        # Print received message
        print('Model A: (%d verts, %d faces)' % (obj.nvert, obj.nface))
        pprint.pprint(obj)

        # Send output to output channel
        # If there is an error, the flag will be False
        flag = out_channel.send(obj)
        if not flag:
            print("Model A: Error sending output.")
            break

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    import pprint
    # Import classes for input/output channels
    from cis_interface.interface.CisInterface import (
        CisObjInput, CisObjOutput)

    # Initialize input/output channels
    in_channel = CisObjInput('inputB')
    out_channel = CisObjOutput('outputB')

    # Loop until there is no longer input or the queues are closed
    while True:

        # Receive input from input channel
        # If there is an error, the flag will be False
        flag, obj = in_channel.recv()
        if not flag:
            print("Model B: No more input.")
            break

        # Print received message
        print('Model B: (%d verts, %d faces)' % (obj.nvert, obj.nface))
        pprint.pprint(obj)

        # Send output to output channel
        # If there is an error, the flag will be False
        flag = out_channel.send(obj)
        if not flag:
            print("Model B: Error sending output.")
            break

Model YAML:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    models:
      - name: python_modelA
        language: python
        args: ./src/formatted_io6_modelA.py
        inputs: inputA
        outputs: outputA

      - name: python_modelB
        language: python
        args: ./src/formatted_io6_modelB.py
        inputs: inputB
        outputs: outputB

    connections:
      - input: outputA  # Connection between model A output & model B input
        output: inputB
      - input: ./Input/input.obj  # Connection between file and model A input
        output: inputA
        filetype: obj
      - input: outputB  # Connection between model B output and file
        output: ./output.obj
        filetype: obj

## C++ Version

Model Code:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    #include <iostream>
    // Include methods for input/output channels
    #include "CisInterface.hpp"

    int main(int argc, char *argv[]) {
      // Initialize input/output channels
      CisObjInput in_channel("inputA");
      CisObjOutput out_channel("outputA");

      // Declare resulting variables and create buffer for received message
      int flag = 1;
      obj_t p = init_obj();

      // Loop until there is no longer input or the queues are closed
      while (flag >= 0) {

        // Receive input from input channel
        // If there is an error, the flag will be negative
        // Otherwise, it is the size of the received message
        flag = in_channel.recv(1, &p);
        if (flag < 0) {
          std::cout << "Model A: No more input." << std::endl;
          break;
        }

        // Print received message
        printf("Model A: (%d verts, %d faces)\n", p.nvert, p.nface);
        int i, j;
        printf("  Vertices:\n");
        for (i = 0; i < p.nvert; i++) {
          printf("   %f, %f, %f\n",
    	     p.vertices[i][0], p.vertices[i][1], p.vertices[i][2]);
        }
        printf("  Faces:\n");
        for (i = 0; i < p.nface; i++) {
          printf("   %d, %d, %d\n",
    	     p.faces[i][0], p.faces[i][1], p.faces[i][2]);
        }

        // Send output to output channel
        // If there is an error, the flag will be negative
        flag = out_channel.send(1, p);
        if (flag < 0) {
          std::cout << "Model A: Error sending output." << std::endl;
          break;
        }

      }

      // Free dynamically allocated structure
      free_obj(&p);

      return 0;
    }

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    #include <iostream>
    // Include methods for input/output channels
    #include "CisInterface.hpp"

    #define MYBUFSIZ 1000

    int main(int argc, char *argv[]) {
      // Initialize input/output channels
      CisObjInput in_channel("inputB");
      CisObjOutput out_channel("outputB");

      // Declare resulting variables and create buffer for received message
      int flag = 1;
      obj_t p = init_obj();

      // Loop until there is no longer input or the queues are closed
      while (flag >= 0) {

        // Receive input from input channel
        // If there is an error, the flag will be negative
        // Otherwise, it is the size of the received message
        flag = in_channel.recv(1, &p);
        if (flag < 0) {
          std::cout << "Model B: No more input." << std::endl;
          break;
        }

        // Print received message
        printf("Model B: (%d verts, %d faces)\n", p.nvert, p.nface);
        int i, j;
        printf("  Vertices:\n");
        for (i = 0; i < p.nvert; i++) {
          printf("   %f, %f, %f\n",
    	     p.vertices[i][0], p.vertices[i][1], p.vertices[i][2]);
        }
        printf("  Faces:\n");
        for (i = 0; i < p.nface; i++) {
          printf("   %d, %d, %d\n",
    	     p.faces[i][0], p.faces[i][1], p.faces[i][2]);
        }

        // Send output to output channel
        // If there is an error, the flag will be negative
        flag = out_channel.send(1, p);
        if (flag < 0) {
          std::cout << "Model B: Error sending output." << std::endl;
          break;
        }

      }

      // Free dynamically allocated structure
      free_obj(&p);

      return 0;
    }

Model YAML:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    models:
      - name: cpp_modelA
        language: c++
        args: ./src/formatted_io6_modelA.cpp
        inputs: inputA
        outputs: outputA

      - name: cpp_modelB
        language: c++
        args: ./src/formatted_io6_modelB.cpp
        inputs: inputB
        outputs: outputB

    connections:
      - input: outputA  # Connection between model A output & model B input
        output: inputB
      - input: ./Input/input.obj  # Connection between file and model A input
        output: inputA
        filetype: obj
      - input: outputB  # Connection between model B output and file
        output: ./output.obj
        filetype: obj

## C Version

Model Code:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    #include <stdio.h>
    // Include methods for input/output channels
    #include "CisInterface.h"

    int main(int argc, char *argv[]) {
      // Initialize input/output channels
      cisObjInput_t in_channel = cisObjInput("inputA");
      cisObjOutput_t out_channel = cisObjOutput("outputA");

      // Declare resulting variables and create buffer for received message
      int flag = 1;
      obj_t p = init_obj();

      // Loop until there is no longer input or the queues are closed
      while (flag >= 0) {

        // Receive input from input channel
        // If there is an error, the flag will be negative
        // Otherwise, it is the size of the received message
        flag = cisRecv(in_channel, &p);
        if (flag < 0) {
          printf("Model A: No more input.\n");
          break;
        }

        // Print received message
        printf("Model A: (%d verts, %d faces)\n", p.nvert, p.nface);
        int i;
        printf("  Vertices:\n");
        for (i = 0; i < p.nvert; i++) {
          printf("   %f, %f, %f\n",
    	     p.vertices[i][0], p.vertices[i][1], p.vertices[i][2]);
        }
        printf("  Faces:\n");
        for (i = 0; i < p.nface; i++) {
          printf("   %d, %d, %d\n",
    	     p.faces[i][0], p.faces[i][1], p.faces[i][2]);
        }

        // Send output to output channel
        // If there is an error, the flag will be negative
        flag = cisSend(out_channel, p);
        if (flag < 0) {
          printf("Model A: Error sending output.\n");
          break;
        }

      }

      // Free dynamically allocated obj structure
      free_obj(&p);

      return 0;
    }

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    #include <stdio.h>
    // Include methods for input/output channels
    #include "CisInterface.h"

    int main(int argc, char *argv[]) {
      // Initialize input/output channels
      cisObjInput_t in_channel = cisObjInput("inputB");
      cisObjOutput_t out_channel = cisObjOutput("outputB");

      // Declare resulting variables and create buffer for received message
      int flag = 1;
      obj_t p = init_obj();

      // Loop until there is no longer input or the queues are closed
      while (flag >= 0) {

        // Receive input from input channel
        // If there is an error, the flag will be negative
        // Otherwise, it is the size of the received message
        flag = cisRecv(in_channel, &p);
        if (flag < 0) {
          printf("Model B: No more input.\n");
          break;
        }

        // Print received message
        printf("Model B: (%d verts, %d faces)\n", p.nvert, p.nface);
        int i;
        printf("  Vertices:\n");
        for (i = 0; i < p.nvert; i++) {
          printf("   %f, %f, %f\n",
    	     p.vertices[i][0], p.vertices[i][1], p.vertices[i][2]);
        }
        printf("  Faces:\n");
        for (i = 0; i < p.nface; i++) {
          printf("   %d, %d, %d\n",
    	     p.faces[i][0], p.faces[i][1], p.faces[i][2]);
        }

        // Send output to output channel
        // If there is an error, the flag will be negative
        flag = cisSend(out_channel, p);
        if (flag < 0) {
          printf("Model B: Error sending output.\n");
          break;
        }

      }

      // Free dynamically allocated obj structure
      free_obj(&p);

      return 0;
    }

Model YAML:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    models:
      - name: c_modelA
        language: c
        args: ./src/formatted_io6_modelA.c
        inputs: inputA
        outputs: outputA

      - name: c_modelB
        language: c
        args: ./src/formatted_io6_modelB.c
        inputs: inputB
        outputs: outputB

    connections:
      - input: outputA  # Connection between model A output & model B input
        output: inputB
      - input: ./Input/input.obj  # Connection between file and model A input
        output: inputA
        filetype: obj
      - input: outputB  # Connection between model B output and file
        output: ./output.obj
        filetype: obj

## Matlab Version

Model Code:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    % Initialize input/output channels
    in_channel = CisInterface('CisObjInput', 'inputA');
    out_channel = CisInterface('CisObjOutput', 'outputA');

    flag = true;

    % Loop until there is no longer input or the queues are closed
    while flag

      % Receive input from input channel
      % If there is an error, the flag will be False.
      [flag, obj] = in_channel.recv();
      if (~flag)
        disp('Model A: No more input.');
        break;
      end;

      % Print received message
      fprintf('Model A: (%d verts, %d faces)\n', obj.nvert, obj.nface);
      fprintf('  Vertices:\n');
      for i = 1:obj.nvert
        fprintf('   %f, %f, %f\n', ...
    	    obj['vertices'][i][0], obj['vertices'][i][1], obj['vertices'][i][2]);
      end;
      fprintf('  Faces:\n');
      for i = 1:obj.nface
        fprintf('   %d, %d, %d\n', ...
    	    obj['faces'][i][0], obj['faces'][i][1], obj['faces'][i][2]);
      end;

      % Send output to output channel
      % If there is an error, the flag will be False
      flag = out_channel.send(obj);
      if (~flag)
        disp('Model A: Error sending output.');
        break;
      end;

    end;

    exit(0);

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    % Initialize input/output channels
    in_channel = CisInterface('CisObjInput', 'inputB');
    out_channel = CisInterface('CisObjOutput', 'outputB');

    flag = true;

    % Loop until there is no longer input or the queues are closed
    while flag

      % Receive input from input channel
      % If there is an error, the flag will be False.
      [flag, obj] = in_channel.recv();
      if (~flag)
        disp('Model B: No more input.');
        break;
      end;

      % Print received message
      fprintf('Model B: (%d verts, %d faces)\n', obj.nvert, obj.nface);
      fprintf('  Vertices:\n');
      for i = 1:obj.nvert
        fprintf('   %f, %f, %f\n', ...
    	    obj['vertices'][i][0], obj['vertices'][i][1], obj['vertices'][i][2]);
      end;
      fprintf('  Faces:\n');
      for i = 1:obj.nface
        fprintf('   %d, %d, %d\n', ...
    	    obj['faces'][i][0], obj['faces'][i][1], obj['faces'][i][2]);
      end;

      % Send output to output channel
      % If there is an error, the flag will be False
      flag = out_channel.send(obj);
      if (~flag)
        disp('Model B: Error sending output.');
        break;
      end;

    end;

    exit(0);

Model YAML:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    models:
      - name: matlab_modelA
        language: matlab
        args: ./src/formatted_io6_modelA.m
        inputs: inputA
        outputs: outputA

      - name: matlab_modelB
        language: matlab
        args: ./src/formatted_io6_modelB.m
        inputs: inputB
        outputs: outputB

    connections:
      - input: outputA  # Connection between model A output & model B input
        output: inputB
      - input: ./Input/input.obj  # Connection between file and model A input
        output: inputA
        filetype: obj
      - input: outputB  # Connection between model B output and file
        output: ./output.obj
        filetype: obj