Motive 2.0 beta is Now Available

Check out the Release notes and the 2.0 Wiki

Motive Batch Processor

From NaturalPoint Product Documentation Ver 1.10
Jump to: navigation, search
Back to the Main PageBack to Motive Documentation

Introduction[edit]



  • MotiveBatch.png
  • Motive Batch Processor

The Motive Batch Processor is a separate stand-alone Windows application, built on the new NMotive scripting and programming API, that can be utilized to process a set of Motive Take files via IronPython or C# scripts. While the Batch Processor includes some example script files, it is primarily designed to utilize user-authored scripts. Motive Batch Processor can also be launched from the Project pane toolbar.

Initial functionality includes scripting access to file I/O, trajectorization, high-level Take processing using many of Motive's existing editing tools, and data export. Upcoming versions will provide access to track, channel, and frame-level information, for creating cleanup and labeling tools based on individual marker reconstruction data.

Motive Batch Processor Scripts make use of the NMotive .NET class library, and you can also utilize the NMotive classes to write .NET programs and IronPython scripts that run outside of this application. The NMotive assembly is installed in the Global Assembly Cache and also located in the assemblies sub-directory of the Motive install directory. For example, the default location for the assembly included in the 64-bit Motive installer is:


C:\Program Files\OptiTrack\Motive\assemblies\x64

The full source code for the Motive Batch Processor is also installed with Motive, at:

C:\Program Files\OptiTrack\Motive\MotiveBatchProcessor\src


You are welcome to use the source code as a starting point to build your own applications on the NMotive framework.


Use[edit]



  • Motive Batch Processor

Requirements

  • A batch processor script using the NMotive API. (C# or IronPython)
  • Take files that will be processed.

Info2.png

There is a known stall issue with IronPython versions 2.7.6 or higher. Please use IronPython 2.7.5 instead.


Steps

  1. Launch the Motive Batch Processor. It can be launched from either the start menu, Motive install directory, or from the Project pane in Motive.
  2. First, select and load a Batch Processor Script. Sample scripts for various pipelines can be found in the [Motive Directory]\MotiveBatchProcessor\ExampleScripts\ folder.
  3. Load the captured Takes (TAK) that will be processed using the imported scripts.
  4. Click Process Takes to batch process the Take files.

Class Reference[edit]



Motive Batch Processor

A class reference in Microsoft compiled HTML (.chm) format can be found in the Help sub-directory of the Motive install directory. The default location for the help file (in the 64-bit Motive installer) is:

C:\Program Files\OptiTrack\Motive\Help\NMotiveAPI.chm



C# Scripts[edit]



The Motive Batch Processor can run C# and IronPython scripts. Below is an overview of the C# script format, as well as an example script.

C# Script Format

A valid Batch Processor C# script file must contain a single class implementing the ItakeProcessingScript interface. This interface defines a single function:

Result ProcessTake( Take t, ProgressIndicator progress ).

Result, Take, and ProgressIndicator are all classes defined in the NMotive namespace. The Take object t is an instance of the NMotive Take class. It is the take being processed. The progress object is an instance of the NMotive ProgressIndicator and allows the script to update the Batch Processor UI with progress and messages. The general format of a Batch Processor C# script is:

   using NMotive;
   // any other using statements
   public class MyCSharpScript : ITakeProcessingScript
   {
      public Result ProcessTake(Take t, ProgressIndicator progress)
      {
         Result scriptResult;
         // Script processing code here
         progress.SetMessage(“Done processing take “ + t.Name);
         progress.SetProgress( 100 );
         return scriptResult;
      }
   }

C# Example

The following is an example of a C# Batch Processor script that exports a take to C3D format.

   using System;
   using NMotive;
   using System.IO;

   public class C3DExportScript : ItakeProcessingScript
   {
      public Result ProcessTake(Take t, ProgressIndicator progress)
      {		
         // Create the name of the C3D file. The name will be the same as the 
         // take file name, but with a .c3d extension.
         string c3dFileName =   
            Path.GetFullPath(Path.GetFileNameWithoutExtension(t.FileName) + ".c3d");

         // Create the C3D exporter object (from the NMotive class library)
         // and ensure that the exported 3D data uses MotionBuilder 
         // compatible axes.
         C3DExporter exporter = new C3DExporter();
         exporter.SetAxisMotionBuilderCompatible();

         // Finally perform the export and return the result of the result of the 
         // export. The last argument to the Export function is a bool indicating
         // whether or not we wish to overwrite any existing file. True means
         // overwrite it if it already exists.
         Result exportResult = exporter.Export(t, c3dFileName, true);
         return exportResult;
      }
   }

Note that your C# script file must have a '.cs' extension.


IronPython Scripts[edit]



IronPython is an implementation of the Python programming language that can use the .NET libraries and Python libraries. The batch processor can execute valid IronPython scripts in addition to C# scripts.

IronPython Script Format

Your IronPython script file must import the clr module and reference the NMotive assembly. In addition, it must contain the following function:

def ProcessTake(Take t, ProgressIndicator progress)

The following illustrates a typical IronPython script format.

   #import sys and clr modules
   import sys
   import clr

   # Add a reference to the NMotive assembly
   clr.AddReference("NMotive")
   # Import everything from sys and NMotive.
   from System import *
   from NMotive import *

   # Define the ProcessTake function.
   def ProcessTake(take, progress):
      # Take processing code here
      .
      .
      .
      # return result object

IronPython Script Example

The following is an example IronPython Batch Processor script that first performs a trim tails operation followed by a filtering/smoothing operation. If both operations succeed, the resulting take is saved.

   import sys
   import clr

   # Add a reference to the NMotive assembly
   clr.AddReference("NMotive")

   # Import everything from System and NMotive.
   from System import *
   from NMotive import *

   # Define out ProcessTake function
   def ProcessTake(take, progress):
      # Messages set with the ProgressIndicator SetMessage
      # function appear on the batch processor UI below the
      # status bar.
      progress.SetMessage('Triming tails...')
      # Create an NMotive TrimTails object, set desired
      # properties and apply the trimming operation by
      # invoking the Process function.
      tailTrimming = TrimTails()
      tailTrimming.Automatic = True
      tailTrimming.LeadingTrimSize = 4
      tailTrimming.TrailingTrimSize = 4
      trimResult = tailTrimming.Process(take)
      # If the trimming operation did not succeed we
      # do not continue with filtering and saving the
      # take file. We just exit the function by returning
      # the result of the trimming operation.
      if not trimResult.Success:
         return trimResult
    
      # Now apply the filter.
      progress.SetMessage('Filtering...')
      filtering = Filter()
      filtering.CutOffFrequency = 8 # Hz
      filteringResult = filtering.Process(take)

      # If filtering fails do not save the take. Just return.
      if not filteringResult.Success:
         return filteringResult

      # trimming and filtering operations are successful. Save
      # the take file and return the result of the file save.
      fileSaveResult = take.Save()
      if fileSaveResult != FileResult.ResultOK:
         return Result(false, 'File save failed')

      return Result(true, '')

Back to Top