int main( int argc, char *argv[] ) { lineCmdParamInvTrsf par; char *lineoptions; double time_init = _GetTime(); double time_exit; double clock_init = _GetClock(); double clock_exit; /* parameter initialization */ API_InitParam_invTrsf( &par ); /* parameter parsing */ if ( argc <= 1 ) API_ErrorParse_invTrsf( _BaseName( argv[0] ), (char*)NULL, 0 ); API_ParseParam_invTrsf( 1, argc, argv, &par ); /* API call */ lineoptions = _Array2Str( argc, argv ); if ( lineoptions == (char*)NULL ) API_ErrorParse_invTrsf( _BaseName( argv[0] ), "unable to translate command line options ...\n", 0 ); if( API_INTERMEDIARY_invTrsf( par.input_name, par.output_name, par.template_name, lineoptions, (char*)NULL ) != 1 ) { free( lineoptions ); API_ErrorParse_invTrsf( _BaseName( argv[0] ), "some error occurs during processing ...\n", -1 ); } free( lineoptions ); time_exit = _GetTime(); clock_exit = _GetClock(); if ( par.print_time ) { fprintf( stderr, "%s: elapsed (real) time = %f\n", _BaseName( argv[0] ), time_exit - time_init ); fprintf( stderr, "\t elapsed (user) time = %f (processors)\n", clock_exit - clock_init ); fprintf( stderr, "\t ratio (user)/(real) = %f\n", (clock_exit - clock_init)/(time_exit - time_init) ); } return( 1 ); }
void CPositionRotationAnimation::ToBitStream( NetBitStreamInterface& a_rBitStream, bool a_bResumeMode ) const { a_rBitStream.WriteBit ( a_bResumeMode ); if ( a_bResumeMode ) { unsigned long ulNow = _GetTime (); unsigned long ulElaspedTime = ulNow - m_ulStartTime; unsigned long ulTimeLeft = 0; if ( m_ulEndTime > ulNow ) { ulTimeLeft = m_ulEndTime - ulNow; } a_rBitStream.WriteCompressed ( ulElaspedTime ); a_rBitStream.WriteCompressed ( ulTimeLeft ); } else { a_rBitStream.WriteCompressed ( m_ulDuration ); } SPositionSync positionSync; positionSync.data.vecPosition = m_SourceValue.m_vecPosition; a_rBitStream.Write ( &positionSync ); SRotationRadiansSync rotationSync ( true ); //RPC function used floats when join time packet didn't, let's go for float rotationSync.data.vecRotation = m_SourceValue.m_vecRotation; a_rBitStream.Write ( &rotationSync ); positionSync.data.vecPosition = m_TargetValue.m_vecPosition; a_rBitStream.Write ( &positionSync ); a_rBitStream.WriteBit ( m_bDeltaRotationMode ); if ( m_bDeltaRotationMode ) { rotationSync.data.vecRotation = m_DeltaValue.m_vecRotation; //We serialize DELTA } else { rotationSync.data.vecRotation = m_TargetValue.m_vecRotation; } a_rBitStream.Write ( &rotationSync ); ////We write the string directly to allow new types without changing netcode (since integer values of enum might change) a_rBitStream.WriteString ( CEasingCurve::GetStringFromEasingType( m_easingCurve.GetType() ) ); double fEasingPeriod, fEasingAmplitude, fEasingOvershoot; m_easingCurve.GetParams ( fEasingPeriod, fEasingAmplitude, fEasingOvershoot ); a_rBitStream.Write ( fEasingPeriod ); a_rBitStream.Write ( fEasingAmplitude ); a_rBitStream.Write ( fEasingOvershoot ); }
int main( int argc, char *argv[] ) { lineCmdParamRegionalext par; vt_image *image, imres, imtmp, *imout, imbinary; char *lineoptions; u8 *resBuf = NULL; int i, v = 0; double time_init = _GetTime(); double time_exit; double clock_init = _GetClock(); double clock_exit; /* parameter initialization */ API_InitParam_regionalext( &par ); /* parameter parsing */ if ( argc <= 1 ) API_ErrorParse_regionalext( _BaseName( argv[0] ), (char*)NULL, 0 ); API_ParseParam_regionalext( 1, argc, argv, &par ); /* input image reading */ image = _VT_Inrimage( par.input_name ); if ( image == (vt_image*)NULL ) { API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to read input image ...\n", 0 ); } if ( par.input_inv == 1 ) VT_InverseImage( image ); if ( par.input_swap == 1 ) VT_SwapImage( image ); /* output image creation */ VT_Image( &imres ); VT_InitFromImage( &imres, image, par.output_name, image->type ); switch( image->type ) { default : case SCHAR : case UCHAR : case USHORT : case SSHORT : imres.type = image->type; break; case UINT : case FLOAT : case DOUBLE : imres.type = USHORT; break; } if ( VT_AllocImage( &imres ) != 1 ) { VT_FreeImage( image ); VT_Free( (void**)&image ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to allocate output image ...\n", 0 ); } /* API call */ lineoptions = _Array2Str( argc, argv ); if ( lineoptions == (char*)NULL ) API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to translate command line options ...\n", 0 ); if ( API_regionalext( image, &imres, lineoptions, (char*)NULL ) != 1 ) { free( lineoptions ); VT_FreeImage( &imres ); VT_FreeImage( image ); VT_Free( (void**)&image ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "some error occurs during processing ...\n", 0 ); } /* memory freeing */ free( lineoptions ); VT_FreeImage( image ); VT_Free( (void**)&image ); /* output difference image writing */ imout = &imres; if ( par.output_type != TYPE_UNKNOWN ) { VT_InitFromImage( &imtmp, &imres, par.output_name, par.output_type ); if ( VT_AllocImage( &imtmp ) != 1 ) { VT_FreeImage( &imres ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to allocate auxiliary image ...\n", 0 ); } if ( VT_CopyImage( &imres, &imtmp ) != 1 ) { VT_FreeImage( &imtmp ); VT_FreeImage( &imres ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to copy result image ...\n", 0 ); } VT_FreeImage( &imres ); imout = &imtmp; } if ( VT_WriteInrimage( imout ) == -1 ) { VT_FreeImage( imout ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to write output image ...\n", 0 ); } /* memory freeing */ VT_FreeImage( image ); VT_Free( (void**)&image ); /* binary image writing */ if ( par.heightmin <= 0.0 || par.heightmax < par.heightmin ) { if ( par.binary_output_name != (char*)NULL && par.binary_output_name[0] != '\0' ) { v = imres.dim.x * imres.dim.y * imres.dim.z; VT_Image( &imbinary ); VT_InitFromImage( &imbinary, &imres, par.binary_output_name, imres.type ); if ( par.binary_output_type != TYPE_UNKNOWN && par.binary_output_type != UCHAR ) { imbinary.type = par.binary_output_type; if ( VT_AllocImage( &imbinary ) != 1 ) { VT_FreeImage( &imres ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to allocate binary output image ...\n", 0 ); } VT_Threshold( &imres, &imbinary, 1.0 ); } else { imbinary.type = UCHAR; if ( VT_AllocImage( &imbinary ) != 1 ) { VT_FreeImage( &imres ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to allocate binary output image ...\n", 0 ); } resBuf = (u8*)imbinary.buf; switch ( imres.type ) { case SCHAR : { s8 *buf = (s8*)imres.buf; for (i=0; i<v; i++ ) resBuf[i] = ( buf[i] > 0 ) ? 255 : 0 ; } break; case UCHAR : { u8 *buf = (u8*)imres.buf; for (i=0; i<v; i++ ) resBuf[i] = ( buf[i] > 0 ) ? 255 : 0 ; } break; case SSHORT : { s16 *buf = (s16*)imres.buf; for (i=0; i<v; i++ ) resBuf[i] = ( buf[i] > 0 ) ? 255 : 0 ; } break; case USHORT : { u16 *buf = (u16*)imres.buf; for (i=0; i<v; i++ ) resBuf[i] = ( buf[i] > 0 ) ? 255 : 0 ; } break; default : VT_FreeImage( &imbinary ); VT_FreeImage( &imres ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "such output image type not handled yet ...\n", 0 ); } } if ( VT_WriteInrimage( &imbinary ) == -1 ) { VT_FreeImage( &imbinary ); VT_FreeImage( &imres ); API_ErrorParse_regionalext( _BaseName( argv[0] ), "unable to write output binary image ...\n", 0 ); } VT_FreeImage( &imbinary ); } } /* memory freeing */ VT_FreeImage( &imres ); time_exit = _GetTime(); clock_exit = _GetClock(); if ( par.print_time ) { fprintf( stderr, "%s: elapsed (real) time = %f\n", _BaseName( argv[0] ), time_exit - time_init ); fprintf( stderr, "\t elapsed (user) time = %f (processors)\n", clock_exit - clock_init ); fprintf( stderr, "\t ratio (user)/(real) = %f\n", (clock_exit - clock_init)/(time_exit - time_init) ); } return( 1 ); }
int main( int argc, char *argv[] ) { lineCmdParamExecTemplate par; bal_image image, imres; char *lineoptions; double time_init = _GetTime(); double time_exit; double clock_init = _GetClock(); double clock_exit; /* parameter initialization */ API_InitParam_execTemplate( &par ); /* parameter parsing */ if ( argc <= 1 ) API_ErrorParse_execTemplate( _BaseName( argv[0] ), (char*)NULL, 0 ); API_ParseParam_execTemplate( 1, argc, argv, &par ); /* input image reading */ BAL_InitImage( &image, NULL, 0, 0, 0, 0, UCHAR ); if ( BAL_ReadImage( &image, par.input_name, 0 ) != 1 ) { API_ErrorParse_execTemplate( _BaseName( argv[0] ), "unable to read input image ...\n", 0 ); } /* output image creation */ BAL_InitImage( &imres, par.output_name, image.ncols, image.nrows, image.nplanes, image.vdim, image.type ); if ( par.output_type != TYPE_UNKNOWN ) imres.type = par.output_type; if ( BAL_AllocImage( &imres ) != 1 ) { BAL_FreeImage( &image ); API_ErrorParse_execTemplate( _BaseName( argv[0] ), "unable to allocate output image ...\n", 0 ); } /* API call */ lineoptions = _Array2Str( argc, argv ); if ( lineoptions == (char*)NULL ) API_ErrorParse_execTemplate( _BaseName( argv[0] ), "unable to translate command line options ...\n", 0 ); if ( API_execTemplate( &image, &imres, lineoptions, (char*)NULL ) != 1 ) { free( lineoptions ); BAL_FreeImage( &imres ); BAL_FreeImage( &image ); API_ErrorParse_execTemplate( _BaseName( argv[0] ), "some error occurs during processing ...\n", -1 ); } free( lineoptions ); /* output image writing */ if ( BAL_WriteImage( &imres, par.output_name ) != 1 ) { BAL_FreeImage( &imres ); BAL_FreeImage( &image ); API_ErrorParse_execTemplate( _BaseName( argv[0] ), "unable to write output image ...\n", -1 ); } /* memory freeing */ BAL_FreeImage( &imres ); BAL_FreeImage( &image ); time_exit = _GetTime(); clock_exit = _GetClock(); if ( par.print_time ) { fprintf( stderr, "%s: elapsed (real) time = %f\n", _BaseName( argv[0] ), time_exit - time_init ); fprintf( stderr, "\t elapsed (user) time = %f (processors)\n", clock_exit - clock_init ); fprintf( stderr, "\t ratio (user)/(real) = %f\n", (clock_exit - clock_init)/(time_exit - time_init) ); } return( 1 ); }
int main( int argc, char* argv[] ) { void *bufferIn = (void*)NULL; void *bufferOut = (void*)NULL; int bufferDims[3] = {0,0,0}; int borderLengths[3] = {0,0,0}; typeFilteringCoefficients filter[3]; int fd; int bufferLength; int example; double time_init; double time_exit; double clock_init; double clock_exit; initFilteringCoefficients( &(filter[0]) ); initFilteringCoefficients( &(filter[1]) ); initFilteringCoefficients( &(filter[2]) ); /* * 2D image, example of use */ time_init = _GetTime(); clock_init = _GetClock(); /* * allocation of a 64 x 64 image */ example = 1; bufferLength = 4096; bufferIn = (void*)malloc( bufferLength * sizeof(unsigned char) ); if ( bufferIn == (void*)NULL ) { fprintf( stderr, " example #%d: allocation of first buffer failed.\n", example ); exit( 1 ); } bufferOut = (void*)malloc( bufferLength * sizeof(unsigned char) ); if ( bufferOut == (void*)NULL ) { fprintf( stderr, " example #%d: allocation of second buffer failed.\n", example ); exit( 1 ); } /* * reading the 2D image (raw data) */ fd = open( "images/square64x64.data", 0 ); { char *b = (char*)bufferIn; int toberead = bufferLength; int nbread = 0; while ( (toberead > 0) && ((nbread = read( fd, b, toberead )) > 0) ) { toberead -= nbread; b += nbread; } if ( toberead > 0 ) { fprintf( stderr, " example #%d: read %d bytes instead of %d.\n", example, (bufferLength- toberead), bufferLength ); exit( 1 ); } } close( fd ); /* * processing the 2D image */ bufferDims[0] = 64; bufferDims[1] = 64; bufferDims[2] = 1; if ( gradientMaxima2D( bufferIn, UCHAR, bufferOut, UCHAR, bufferDims, borderLengths, filter ) != 1 ) { fprintf( stderr, " example #%d: processing failed.\n", example ); exit( 1 ); } /* * writing the 2D image (raw data) */ fd = creat( "images/square64x64.tmp", 0644 ); if ( write( fd, bufferOut, bufferLength ) != bufferLength ) { fprintf( stderr, " example #%d: error in writing.\n", example ); exit( 1 ); } close( fd ); /* * */ fprintf( stderr, " example #%d: processing is complete.\n", example ); fprintf( stderr, " image/square64x64.tmp was written.\n"); free( bufferIn ); free( bufferOut ); time_exit = _GetTime(); clock_exit = _GetClock(); fprintf( stderr, " elapsed (real) time = %f\n", time_exit - time_init ); fprintf( stderr, " elapsed (user) time = %f (processors)\n", clock_exit - clock_init ); fprintf( stderr, " ratio (user)/(real) = %f\n", (clock_exit - clock_init)/(time_exit - time_init) ); /* * 3D image, example of use */ time_init = _GetTime(); clock_init = _GetClock(); /* * allocation of a 64 x 64 x 64 image */ example = 2; bufferLength = 262144; bufferIn = (void*)malloc( bufferLength * sizeof(unsigned char) ); if ( bufferIn == (void*)NULL ) { fprintf( stderr, " example #%d: allocation of first buffer failed.\n", example ); exit( 1 ); } bufferOut = (void*)malloc( bufferLength * sizeof(unsigned char) ); if ( bufferOut == (void*)NULL ) { fprintf( stderr, " example #%d: allocation of second buffer failed.\n", example ); exit( 1 ); } /* * reading the 3D image (raw data) */ fd = open( "images/disk64x64x64.data", 0 ); { char *b = (char*)bufferIn; int toberead = bufferLength; int nbread = 0; while ( (toberead > 0) && ((nbread = read( fd, b, toberead )) > 0) ) { toberead -= nbread; b += nbread; } if ( toberead > 0 ) { fprintf( stderr, " example #%d: read %d bytes instead of %d.\n", example, (bufferLength- toberead), bufferLength ); exit( 1 ); } } close( fd ); /* * processing the 3D image */ bufferDims[0] = 64; bufferDims[1] = 64; bufferDims[2] = 64; if ( gradientMaxima3D( bufferIn, UCHAR, bufferOut, UCHAR, bufferDims, borderLengths, filter ) != 1 ) { fprintf( stderr, " example #%d: processing failed.\n", example ); exit( 1 ); } /* * writing the 3D image (raw data) */ fd = creat( "images/disk64x64x64.tmp", 0644 ); if ( write( fd, bufferOut, bufferLength ) != bufferLength ) { fprintf( stderr, " example #%d: error in writing.\n", example ); exit( 1 ); } close( fd ); /* * */ fprintf( stderr, " example #%d: processing is complete.\n", example ); fprintf( stderr, " image/disk64x64x64.tmp was written.\n"); free( bufferIn ); free( bufferOut ); time_exit = _GetTime(); clock_exit = _GetClock(); fprintf( stderr, " elapsed (real) time = %f\n", time_exit - time_init ); fprintf( stderr, " elapsed (user) time = %f (processors)\n", clock_exit - clock_init ); fprintf( stderr, " ratio (user)/(real) = %f\n", (clock_exit - clock_init)/(time_exit - time_init) ); /* * 3D image, second example of use */ time_init = _GetTime(); clock_init = _GetClock(); /* * allocation of a 64 x 64 x 64 image */ example = 3; bufferLength = 262144; bufferIn = (void*)malloc( bufferLength * sizeof(unsigned char) ); if ( bufferIn == (void*)NULL ) { fprintf( stderr, " example #%d: allocation of first buffer failed.\n", example ); exit( 1 ); } bufferOut = (void*)malloc( bufferLength * sizeof(unsigned char) ); if ( bufferOut == (void*)NULL ) { fprintf( stderr, " example #%d: allocation of second buffer failed.\n", example ); exit( 1 ); } /* * reading the image */ fd = open( "images/mri64x64x64.data", 0 ); { char *b = (char*)bufferIn; int toberead = bufferLength; int nbread = 0; while ( (toberead > 0) && ((nbread = read( fd, b, toberead )) > 0) ) { toberead -= nbread; b += nbread; } if ( toberead > 0 ) { fprintf( stderr, " example #%d: read %d bytes instead of %d.\n", example, (bufferLength- toberead), bufferLength ); exit( 1 ); } } close( fd ); /* * processing */ bufferDims[0] = 64; bufferDims[1] = 64; bufferDims[2] = 64; /* * here it is better (even necessary) to add * points at both ends of lines when filetring. */ borderLengths[0] = 10; borderLengths[1] = 10; borderLengths[2] = 10; if (gradientMaxima3D( bufferIn, UCHAR, bufferOut, UCHAR, bufferDims, borderLengths, filter ) != 1 ) { fprintf( stderr, " example #%d: processing failed.\n", example ); exit( 1 ); } /* * writing */ fd = creat( "images/mri64x64x64.tmp", 0644 ); if ( write( fd, bufferOut, bufferLength ) != bufferLength ) { fprintf( stderr, " example #%d: error in writing.\n", example ); exit( 1 ); } close( fd ); /* * */ fprintf( stderr, " example #%d: processing is complete.\n", example ); fprintf( stderr, " image/mri64x64x64.tmp was written.\n"); free( bufferIn ); free( bufferOut ); time_exit = _GetTime(); clock_exit = _GetClock(); fprintf( stderr, " elapsed (real) time = %f\n", time_exit - time_init ); fprintf( stderr, " elapsed (user) time = %f (processors)\n", clock_exit - clock_init ); fprintf( stderr, " ratio (user)/(real) = %f\n", (clock_exit - clock_init)/(time_exit - time_init) ); /* * */ exit( 0 ); }