/* OdysseyMultiBoard.c Multi-Odyssey system processing demo with equal processing load. Note: Each buffer grabbed is processed with all the processor boards. This means that when each processing board is fast enough, the frame rate should be the camera frame rate times the number of processor boards. Display can be the limiting factor for speed. Comment MdispSelect() if needed. The grab system is the one specified by MilConfig default values. It should be the first Odyssey and have the grab module. The types of the processing systems are specified below. */ /* Headers. */ #include #include // Number of processing systems. #define PROCESSOR_NB_MAX 8 #define USE_GRAB_SYSTEM_AS_PROCESSOR M_YES #define PROCESSOR_SYSTEM_TYPE M_SYSTEM_ODYSSEY // Number of processing buffers. #define BUFFER_PER_PROCESSOR 2 #define BUFFER_NUMBER_MAX (PROCESSOR_NB_MAX*BUFFER_PER_PROCESSOR) #define BUFFER_SCALE 1.0 // Number of grab buffers. #define BUFFER_PER_DIGITIZER 2 // Annotation string length. #define MAX_STRING_LENGHT 80 // Print debug statement. #define DEBUG M_NO /* ************************************************************************ */ /* This example performs double buffered grab with real time processing with */ /* multiple systems. */ /* Main function. */ void main(void) { MIL_ID MilApplication; MIL_ID MilSystem ; MIL_ID MilDigitizer ; MIL_ID MilDisplay ; MIL_ID MilImageDisp ; MIL_ID GrabBufId[BUFFER_PER_DIGITIZER]; MIL_ID ProcSysId[PROCESSOR_NB_MAX]; MIL_ID ProcBufId[BUFFER_NUMBER_MAX]; MIL_ID CurrentProcSrcBufId, CurrentProcDstBufId; long GrabIndex = 0, n, m; long NbProc = 0, NbGrab =0, NbSystem = 0; double Time = 0.0; char Text[MAX_STRING_LENGHT]; long SizeX, SizeY, SizeBand; /* MIL application allocation. */ MappAlloc(M_DEFAULT, &MilApplication); /* Allocations on the default grab system. */ MsysAlloc("M_DEFAULT", M_DEFAULT, M_DEFAULT, &MilSystem); MdispAlloc(MilSystem, M_DEV0, "M_DEFAULT", M_DEFAULT, &MilDisplay); MdigAlloc(MilSystem, M_DEV0, "M_DEFAULT", M_DEFAULT, &MilDigitizer); /* Inquire digitizer size. */ SizeBand = (long)(MdigInquire(MilDigitizer, M_SIZE_BAND, M_NULL)); SizeX = (long)(MdigInquire(MilDigitizer, M_SIZE_X, M_NULL)*BUFFER_SCALE); SizeY = (long)(MdigInquire(MilDigitizer, M_SIZE_Y, M_NULL)*BUFFER_SCALE); /* Allocate 1 display buffer, clear and display it. */ MbufAllocColor(MilSystem, SizeBand, SizeX, SizeY, 8L+M_UNSIGNED, M_IMAGE+M_GRAB+M_DISP, &MilImageDisp); MbufClear(MilImageDisp, 0x0); MdispSelect(MilDisplay, MilImageDisp); /* Allocate grab buffers. */ for (n=0; n< BUFFER_PER_DIGITIZER; n++) { MbufAllocColor(MilSystem, SizeBand, SizeX, SizeY, 8L+M_UNSIGNED, M_IMAGE+M_GRAB, &GrabBufId[n]); } /* Decide whether to use the grab system to process. */ NbSystem = 0; if (USE_GRAB_SYSTEM_AS_PROCESSOR) { ProcSysId[0] = MilSystem; NbSystem++; } /* Allocate and order the processing systems. */ for (n = 0, m = NbSystem; n < (PROCESSOR_NB_MAX-m); n++) { MappControl(M_ERROR, M_PRINT_DISABLE); MsysAlloc(PROCESSOR_SYSTEM_TYPE, n, M_DEFAULT, &ProcSysId[NbSystem]); MappControl(M_ERROR, M_PRINT_ENABLE); /* Count the processing system. */ if (ProcSysId[NbSystem]) NbSystem++; } /* Allocate and order the processing buffers alternating the target system. */ for (n = 0; n < (NbSystem*BUFFER_PER_PROCESSOR); n++) { MbufAllocColor(ProcSysId[n%NbSystem], SizeBand, SizeX, SizeY, 8L+M_UNSIGNED, M_IMAGE+M_PROC, &ProcBufId[n]); } /* Grab continuously on display at the specified scale. */ MdigControl(MilDigitizer, M_GRAB_SCALE, BUFFER_SCALE); MdigGrabContinuous(MilDigitizer,MilImageDisp); /* Print a message. */ printf("\n MULTI BOARDS PROCESSING:\n\n %ld system(s) allocated.\n\n", NbSystem); printf(" Press to start processing.\n\n"); getch(); /* Halt continuous grab. */ MdigHalt(MilDigitizer); /* Put the digitizer in asynchronous mode. */ MdigControl(MilDigitizer, M_GRAB_MODE, M_ASYNCHRONOUS); /* Grab the first buffer. */ NbGrab = 0; MdigGrab(MilDigitizer, GrabBufId[NbGrab++]); /* Process one buffer while grabbing the other. */ NbProc = 0; while( !kbhit() ) { /* Grab one buffer while processing the other. */ MdigGrab(MilDigitizer, GrabBufId[NbGrab % BUFFER_PER_DIGITIZER]); #if DEBUG printf("grab index = %ld.\n", NbGrab % BUFFER_PER_DIGITIZER); #endif DEBUG /* Synchronize and start the timer. */ if (NbProc == 0) MappTimer(M_TIMER_RESET+M_SYNCHRONOUS, M_NULL); /* Process each image with all the processors. To have each frame processed only once by one processor in round robin fashion, just comment out the following for(...) statement. */ for (n=0; n to end.\n\n"); getch(); /* Free allocations. */ for (n = 0; n < (NbSystem*BUFFER_PER_PROCESSOR); n++) MbufFree(ProcBufId[n]); for (n = 0; n < NbSystem; n++) { if ((ProcSysId[n]) && (!((n == 0) && USE_GRAB_SYSTEM_AS_PROCESSOR))) MsysFree(ProcSysId[n]); } for (n=0; n < BUFFER_PER_DIGITIZER; n++) { MbufFree(GrabBufId[n]); } MbufFree(MilImageDisp); MdispFree(MilDisplay); MdigFree(MilDigitizer); MsysFree(MilSystem); MappFree(MilApplication); }