| MIL 10 User Guide
| Customize Help

Fixturing offset



See also
Availability
Not available in MIL-Lite

Available in MIL

When fixturing, you might need to offset the relative coordinate system from the reference location of the object to analyze or process. There are different ways to apply an offset:

  • If using a model occurrence to displace the relative coordinate system, you can offset the reference location of the model to the required location prior to searching for occurrences of it.

  • If using McalFixture() to move the relative coordinate system, regardless of how you pass the reference location, you can use a fixturing offset object.

Moving the reference location prior to searching

If using a model occurrence to displace the relative coordinate system and you need to apply an offset from the occurrence's center, you can move the reference location of the model so that the returned location of each occurrence is at the required offset from the occurrence.

To move the reference location of a pattern matching model, use MpatSetCenter(). To move the reference location of a Model Finder model, use MmodControl() with M_REFERENCE_X, M_REFERENCE_Y, and M_REFERENCE_ANGLE.

For example, to move the reference location of a model and then place the relative coordinate system at the reference location of a model occurrence:

/* Set up phase. */

/* Set the model reference location
   (model 0 in Model Finder context ModContextId). */
MmodControl(ModContextId, 0, M_REFERENCE_X, ReferenceX);
MmodControl(ModContextId, 0, M_REFERENCE_Y, ReferenceY);
MmodControl(ModContextId, 0, M_REFERENCE_ANGLE, ReferenceAngle);

/* Critical loop. */
while (!Stop)
   {
   /* Acquire image. */
   /* ... */

   /* Find the model in GrabbedImageId. */
   MmodFind(ModContextId, GrabbedImageId, ModResultId);
   
   /* Loop on all model occurences. */
   MmodGetResult(ModResultId, M_GENERAL, M_NUMBER+M_TYPE_MIL_INT, &Number);

   for (ResultIndex = 0; ResultIndex < Number; ResultIndex++)
      {
      /* Move the relative coordinate system to the reference location
         of the found model. */
      McalFixture(GrabbedImageId, M_NULL, M_MOVE_RELATIVE, M_RESULT_MOD, 
                  ModResultId, ResultIndex,
                  M_DEFAULT, M_DEFAULT, M_DEFAULT);

      /* Do some processing. */
      /* ... */
      }
   }

Note that moving the relative coordinate system using this technique can result in the returned locations being far from the actual occurrences of the model. This might not be ideal when using the locations not only to place the relative coordinate system, but also to, for example, draw the locations of the occurrences.

Using a fixturing offset object

When using McalFixture() to move the relative coordinate system, you can use a fixturing offset object to apply a preestablished offset to the specified reference location of an object. A fixturing offset object is a container that stores a positional and angular offset. If using a model occurrence to displace the relative coordinate system, a fixturing offset object offers the advantage of keeping the model's reference location at its original location, while specifying an offset for the relative coordinate system.

You can use the following steps to allocate and set up a fixturing offset object:

  • Allocate a fixturing offset object using McalAlloc() with M_FIXTURING_OFFSET.

  • In a training image, ensure that the relative coordinate system is at a required location in the image; if it isn't, move it using McalRelativeOrigin() or McalSetCoordinateSystem().Typically, you would place the relative coordinate system at the required offset from the reference location of the object to analyze or process.

  • Establish a location in the training image that has the required positional and angular offset from the relative coordinate system. This is typically the reference location of the object in the training image.

  • Call McalFixture() with M_LEARN_OFFSET, the fixturing offset object, and the established location. MIL will learn the positional and angular offset that the established location has from the relative coordinate system, and saves it in the fixturing offset object.

The following image offers a visual representation of the above steps:

For example, to move the relative coordinate system to a preestablished offset from the reference location of a model occurrence:

/* Set up phase. */

/* Optionally, move the relative coordinate system at the required 
   location in the image. 
   No need to move if relative is already at the required location. */
if (MoveRelativeInTrainingImage)
   {
   McalRelativeOrigin(TrainingImageId, 
                      TrainingX, TrainingY, 0, TrainingAngle,
                      M_DEFAULT);
   }
                      
/* Find the model contained in Model Finder context ContextId
   in the training image. */
MmodFind(ModContextId, TrainingImageId, ModResultId);

/* Make sure the model is found. */
/* ... */

/* Learn the location of the model reference location in the
   relative coordinate system of the training image. */
McalFixture(M_NULL, FixturingOffsetId, M_LEARN_OFFSET, M_RESULT_MOD,
            ModResultId, 0, /* Model finder result and occurrence index. */
            M_DEFAULT, M_DEFAULT, M_DEFAULT);

/* Critical loop. */
while (!Stop)
   {
   /* Acquire image. */
   /* ... */

   /* Find the model in GrabbedImageId. */
   MmodFind(ModContextId, GrabbedImageId, ModResultId);
  
   /* Make sure the model is found. */
   /* ... */

   /* Move the relative coordinate system of GrabbedImageId, 
      with the learned offset,
      according to the location of the occurrence of the model. */
   McalFixture(GrabbedImageId, FixturingOffsetId, M_MOVE_RELATIVE, M_RESULT_MOD,
               ModResultId, 0, /* Model finder result and occurrence index. */
               M_DEFAULT, M_DEFAULT, M_DEFAULT);

   /* Do some processing. */
   /* ... */
   }

Establishing the positional and angular offset for the fixturing offset object

As mentioned above, to establish the positional and angular offset for the fixturing offset object, you must first move the relative coordinate system to its required target location in a training image. Then, you must specify the reference location in the training image that has the required positional and angular offset from the relative coordinate system. There are several ways of specifying the reference location:

  • You can define a Model Finder or Pattern Matching model in the training image, and then pass the Model Finder context and model index or the Pattern Matching model to McalFixture(). MIL will extract the offset of the reference location of the model from the relative coordinate system of the training image.

  • You can search for a Model Finder or Pattern Matching model in the training image, and then pass the Model Finder/Pattern Matching result buffer and model occurrence index to McalFixture(). MIL will extract the offset of the model occurrence from the relative coordinate system of the training image.

  • You can pass the training image and a preestablished position and angle in this image to McalFixture(). MIL will extract the offset of the preestablished position and angle from the relative coordinate system of the training image.

  • You can pass the identifier of a Metrology result buffer and the index of a Metrology reference frame feature to McalFixture(). MIL will extract the offset and angle of the reference frame feature from the Metrology result buffer.

/* First way to learn a fixturing offset. */

/* Define models. */
/* ... */

/* Learn the offset from a Pattern Matching model or from a Model Finder model. */
McalFixture(M_NULL, FixturingOffset1Id, M_LEARN_OFFSET, M_MODEL_PAT, 
            PatModelId, ImageModelDefinitionId,
            M_DEFAULT, M_DEFAULT, M_DEFAULT);
McalFixture(M_NULL, FixturingOffset2Id, M_LEARN_OFFSET, M_MODEL_MOD, 
            ModContextId, 0, /* Model finder context and model index. */ 
            M_DEFAULT, M_DEFAULT, M_DEFAULT);

/* Second way to learn a fixturing offset. */

/* Find the models in a training image. */
/* ... */

/* Learn the offset from a Pattern Matching result or from a Model Finder result. */
McalFixture(M_NULL, FixturingOffset3Id, M_LEARN_OFFSET, M_RESULT_PAT, 
            PatResultId, 0, /* Pattern matching result and occurrence index. */
            M_DEFAULT, M_DEFAULT, M_DEFAULT);
McalFixture(M_NULL, FixturingOffset4Id, M_LEARN_OFFSET, M_RESULT_MOD, 
            ModResultId, 0, /* Model finder result and occurrence index. */
            M_DEFAULT, M_DEFAULT, M_DEFAULT);

/* Third way to learn a fixturing offset. */

/* Learn the offset from a preestabilished position and angle
   expressed in the relative coordinate system of ImageId. */
McalFixture(M_NULL, FixturingOffset5Id, M_LEARN_OFFSET, M_POINT_AND_ANGLE, 
            ImageId, X, Y, Angle, M_DEFAULT);

To ensure that the appropriate offset has been established, you can draw a line from the current origin of the relative coordinate system to the position that must have been passed to establish the offset. To do so, use McalDraw() with the fixturing offset object and M_DRAW_FIXTURING_OFFSET. This also draws a small arrow at this position, which illustrates the angle that must have been passed.