// findHLines.cpp
// Mavis example code, by Robin Hewitt, 2005
//
// Example program for using H-Lines. Uses locateHLines() and nextLine()
// methods.
//
// This example program gets travel distance (distance the camera moves
// between frames) as console input. In a robotics implementation, travel
// distance would either come from sensor data or by moving the camera a
// predetermined distance.

#include <stdio.h>
#include <windows.h>
#include "../maviscomm.h"

int  getDist();
void getHLines(int, LOCATEHLINESPROC, NEXTLINEPROC);

int main(int argc, char** argv)
{
   HINSTANCE         mavisdll         = NULL;
   LOCATEHLINESPROC  procLocateHLines = NULL;
   NEXTLINEPROC      procNextLine     = NULL;
   HLineMetadata_t   hlinesMetadata;
   int               d;

   // load the dll and get the procedure addresses
   mavisdll = LoadLibrary("mavisclient.dll");
   if(!mavisdll)
   {
      fprintf(stderr, "Can't load mavisclient.dll");
      return -1;
   }
   procLocateHLines = (LOCATEHLINESPROC)GetProcAddress(mavisdll, LOCATEHLINESPROC_NAME);
   procNextLine     = (NEXTLINEPROC)GetProcAddress(mavisdll, NEXTLINEPROC_NAME);

   // initiate H-Lines sequence
   procLocateHLines(d=0, HL_UNORDERED, &hlinesMetadata);

   // process H-Lines until quit message received
   while(1)
   {
      d = getDist();
      if(d) getHLines(d, procLocateHLines, procNextLine);
      else break;
   }

   // cleanup
   if(mavisdll) FreeLibrary(mavisdll);

   return 0;
}

// get user input for travel distance
int getDist()
{
   char buf[500];

   printf(
      "\nEnter mm traveled then press <Enter>.\n"
      "To quit, enter 0 or non-numeric input followed by <Enter>.\n"
   );
   fscanf(stdin, "%s", buf);

   return atoi(buf);
}

// execute one H-Line iteration and retrieve the computed 3D line data
void getHLines(
   int d,
   LOCATEHLINESPROC procLocateHLines,
   NEXTLINEPROC procNextLine)
{
   HLineMetadata_t   hlinesMetadata;

   procLocateHLines(d, HL_DISTANCE_LO2HI, &hlinesMetadata);
   printf("d = %d, %d lines computed\n", d, hlinesMetadata.nLines);
   for(int i=0; i<hlinesMetadata.nLines; i++)
   {
      HLine_t hline;
      procNextLine(&hline);
      double estDist = (hline.distance.lo + hline.distance.hi) / 2;
      printf("\t%d. distance = %.3g mm\n", (i+1), estDist);
   }
}
Home | Mavis | H-Lines