static Bool
dstring_ensure_space (DString *ds, int size)
{
    if (ds->alloc_size < size) {
        int   re_size = MAX_VAL (ds->alloc_size * 2, size);
        void *re_ptr = realloc (ds->val, re_size);
        if (UNLIKELY (!re_ptr))
            return FALSE;
        ds->val = re_ptr;
        ds->alloc_size = re_size;
    }

    return TRUE;
}
예제 #2
0
CMP_FN MAX_CMP(const Pixel_t * a, const Pixel_t * b) {
	return MAX_VAL(a) - MAX_VAL(b);
}
예제 #3
0
파일: vrep.cpp 프로젝트: Johan944/Need4Stek
int main(int argc, char* argv[])
{
	if (TIMER_RESOLUTION_IN_MS>0)
	{
		TIMECAPS tc;
		UINT wTimerRes;
		if (timeGetDevCaps(&tc,sizeof(TIMECAPS))==TIMERR_NOERROR) 
		{
			wTimerRes=MIN_VAL(MAX_VAL(tc.wPeriodMin,TIMER_RESOLUTION_IN_MS),tc.wPeriodMax);
			timeBeginPeriod(wTimerRes); 
		}
	}

	char curDirAndFile[1024];
	GetModuleFileName(NULL,curDirAndFile,1023);
	PathRemoveFileSpec(curDirAndFile);
	std::string currentDirAndPath(curDirAndFile);
	std::string temp(currentDirAndPath);
	temp+="\\v_rep.dll";
	LIBRARY lib=loadVrepLibrary(temp.c_str());
	bool wasRunning=false;
	if (lib!=NULL)
	{
		if (getVrepProcAddresses(lib)!=0)
		{
			int guiItems=sim_gui_all;
			for (int i=1;i<argc;i++)
			{
				std::string arg(argv[i]);
				if (arg[0]=='-')
				{
					if (arg.length()>=2)
					{
						if (arg[1]=='h')
							guiItems=sim_gui_headless;
						if (arg[1]=='s')
						{
							autoStart=true;
							simStopDelay=0;
							unsigned int p=2;
							while (arg.length()>p)
							{
								simStopDelay*=10;
								if ((arg[p]>='0')&&(arg[p]<='9'))
									simStopDelay+=arg[p]-'0';
								else
								{
									simStopDelay=0;
									break;
								}
								p++;
							}
						}
						if (arg[1]=='q')
							autoQuit=true;
						if ((arg[1]=='a')&&(arg.length()>2))
						{
							std::string tmp;
							tmp.assign(arg.begin()+2,arg.end());
							simSetStringParameter(sim_stringparam_additional_addonscript_firstscene,tmp.c_str()); // normally, never call API functions before simRunSimulator!!
						}
						if ((arg[1]=='b')&&(arg.length()>2))
						{
							std::string tmp;
							tmp.assign(arg.begin()+2,arg.end());
							simSetStringParameter(sim_stringparam_additional_addonscript,tmp.c_str()); // normally, never call API functions before simRunSimulator!!
						}
						if ((arg[1]=='g')&&(arg.length()>2))
						{
							static int cnt=0;
							std::string tmp;
							tmp.assign(arg.begin()+2,arg.end());
							if (cnt<9)
								simSetStringParameter(sim_stringparam_app_arg1+cnt,tmp.c_str()); // normally, never call API functions before simRunSimulator!!
							cnt++;
						}
					}
				}
				else
				{
					if (sceneOrModelOrUiToLoad.length()==0)
						sceneOrModelOrUiToLoad=arg;
				}
			}

			if (simRunSimulator("V-REP",guiItems,simulatorInit,simulatorLoop,simulatorDeinit)!=1)
				printf("Failed initializing and running V-REP\n");
			else
				wasRunning=true;
		}
		else
			printf("Error: could not find all required functions in v_rep.dll\n");
		unloadVrepLibrary(lib);
	}
	else
		printf("Error: could not find or correctly load v_rep.dll\n");
	if (!wasRunning)
		getchar();
	return(0);
}
예제 #4
0
파일: csngen.c 프로젝트: Firstyear/ds
static int 
_csngen_adjust_local_time (CSNGen *gen, time_t cur_time)
{
    extern int config_get_ignore_time_skew(void);
    int ignore_time_skew = config_get_ignore_time_skew();
    time_t time_diff = cur_time - gen->state.sampled_time;

    if (time_diff == 0) {
        /* This is a no op - _csngen_adjust_local_time should never be called
           in this case, because there is nothing to adjust - but just return
           here to protect ourselves
        */
        return CSN_SUCCESS;
    }
    else if (time_diff > 0)
    {
        time_t ts_before = CSN_CALC_TSTAMP(gen);
        time_t ts_after = 0;
        if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
            time_t new_time = CSN_CALC_TSTAMP(gen);
            slapi_log_err(SLAPI_LOG_REPL, "_csngen_adjust_local_time",
                             "gen state before %08lx%04x:%ld:%ld:%ld\n",
                             new_time, gen->state.seq_num,
                             gen->state.sampled_time,
                             gen->state.local_offset,
                             gen->state.remote_offset);
        }

        gen->state.sampled_time = cur_time;
        if (time_diff > gen->state.local_offset)
            gen->state.local_offset = 0;
        else
            gen->state.local_offset = gen->state.local_offset - time_diff;

        /* only reset the seq_num if the new timestamp part of the CSN
           is going to be greater than the old one - if they are the
           same after the above adjustment (which can happen if
           csngen_adjust_time has to store the offset in the
           local_offset field) we must not allow the CSN to regress or
           generate duplicate numbers */
        ts_after = CSN_CALC_TSTAMP(gen);
        if (ts_after > ts_before) {
            gen->state.seq_num = 0; /* only reset if new time > old time */
        }

        if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
            time_t new_time = CSN_CALC_TSTAMP(gen);
            slapi_log_err(SLAPI_LOG_REPL, "_csngen_adjust_local_time",
                             "gen state after %08lx%04x:%ld:%ld:%ld\n",
                             new_time, gen->state.seq_num,
                             gen->state.sampled_time,
                             gen->state.local_offset,
                             gen->state.remote_offset);
        }
        return CSN_SUCCESS;
    }
    else   /* time was turned back */
    {
        if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
            time_t new_time = CSN_CALC_TSTAMP(gen);
            slapi_log_err(SLAPI_LOG_REPL, "_csngen_adjust_local_time",
                             "gen state back before %08lx%04x:%ld:%ld:%ld\n",
                             new_time, gen->state.seq_num,
                             gen->state.sampled_time,
                             gen->state.local_offset,
                             gen->state.remote_offset);
        }

        if (!ignore_time_skew && (labs (time_diff) > CSN_MAX_TIME_ADJUST))
        {
            slapi_log_err(SLAPI_LOG_ERR, "_csngen_adjust_local_time",
                             "Adjustment limit exceeded; value - %ld, limit - %d\n",
                             labs (time_diff), CSN_MAX_TIME_ADJUST);
            return CSN_LIMIT_EXCEEDED;
        }    

        gen->state.sampled_time = cur_time;
        gen->state.local_offset = MAX_VAL (gen->state.local_offset, labs (time_diff));
        gen->state.seq_num = 0;

        if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
            time_t new_time = CSN_CALC_TSTAMP(gen);
            slapi_log_err(SLAPI_LOG_REPL, "_csngen_adjust_local_time",
                             "gen state back after %08lx%04x:%ld:%ld:%ld\n",
                             new_time, gen->state.seq_num,
                             gen->state.sampled_time,
                             gen->state.local_offset,
                             gen->state.remote_offset);
        }

        return CSN_SUCCESS;
    }
}
예제 #5
0
/*=================================================== Test body ========================== */
static int fmaNormMask(void)
{
    /* Some Variables */
    int nx, ny, n, n4, it, ir, nr, nerr=0, coi, step, step4;
    int xoff, yoff, roiw, roih, nerrt[9];
    CvSize size;
    AtsRandState state1, state2, state3, state4;
    IplImage *A_8uC1, *A_8sC1, *A_32fC1, *B_8uC1, *B_8sC1, *B_32fC1;
    IplImage *A_8uC3, *A_8sC3, *A_32fC3, *B_8uC3, *B_8sC3, *B_32fC3;
    IplImage *mask;
    IplROI   r, rm;
    double norm, testnorm, err;
    double Mask_density, d1, d2;

    trsiRead( &Min_Image_Width,  "1", "Minimal image width" );
    trsiRead( &Max_Image_Width, "32", "Maximal image width" );
    trsiRead( &Max_ROI_Offset,   "8", "Maximal ROI offset" );
    trsdRead( &Mask_density,   "0.5", "Mask density (0 - 1)" );

    if( Min_Image_Width < 1 )               Min_Image_Width = 1;
    if( Max_Image_Width < Min_Image_Width ) Max_Image_Width = Min_Image_Width;
    if( Max_ROI_Offset  < 0 )               Max_ROI_Offset  = 0;
    if( Mask_density    < 0.0 )             Mask_density    = 0.0;

    if( Mask_density >= 1.0 ) { d1 = 2.0; d2 = 4.0; }
    else                      { d1 = 0.0; d2 = 1.0/(1.0-Mask_density); }
    if(d2>256.0) d2=256.0;

    atsRandInit( &state1, MIN_VAL(IPL_DEPTH_8U),  MAX_VAL(IPL_DEPTH_8U),  13 );
    atsRandInit( &state2, MIN_VAL(IPL_DEPTH_8S),  MAX_VAL(IPL_DEPTH_8S),  14 );
    atsRandInit( &state3, MIN_VAL(IPL_DEPTH_32F), MAX_VAL(IPL_DEPTH_32F), 15 );
    atsRandInit( &state4, d1, d2, 16 );

    for( it=0; it<9; it++ ) nerrt[it] = 0;

/*  Image size cycle starts ________________________ */
    for( nx = Min_Image_Width; nx<=Max_Image_Width; nx++ )
    {
        ny = nx;
        /*if(nx>1)ny=(int)(0.7*nx);           // Non-square images test */
        size.width  = nx;  size.height = ny;

        /* Initial images allocating & random filling */
        A_8uC1  = cvCreateImage( size, IPL_DEPTH_8U,  1 );
        A_8sC1  = cvCreateImage( size, IPL_DEPTH_8S,  1 );
        A_32fC1 = cvCreateImage( size, IPL_DEPTH_32F, 1 );

        B_8uC1  = cvCreateImage( size, IPL_DEPTH_8U,  1 );
        B_8sC1  = cvCreateImage( size, IPL_DEPTH_8S,  1 );
        B_32fC1 = cvCreateImage( size, IPL_DEPTH_32F, 1 );

        A_8uC3  = cvCreateImage( size, IPL_DEPTH_8U,  3 );
        A_8sC3  = cvCreateImage( size, IPL_DEPTH_8S,  3 );
        A_32fC3 = cvCreateImage( size, IPL_DEPTH_32F, 3 );

        B_8uC3  = cvCreateImage( size, IPL_DEPTH_8U,  3 );
        B_8sC3  = cvCreateImage( size, IPL_DEPTH_8S,  3 );
        B_32fC3 = cvCreateImage( size, IPL_DEPTH_32F, 3 );

        mask  = cvCreateImage( size, IPL_DEPTH_8U,  1 );

        step = A_8uC1->widthStep;  step4 = (A_32fC1->widthStep)/4;
        n = ny*step;  n4 = ny*step4;

        atsbRand8u ( &state1, (uchar*)A_8uC1->imageData,  n );
        atsbRand8s ( &state2, A_8sC1->imageData,  n );
        atsbRand32f( &state3, (float*)A_32fC1->imageData, n4);

        atsbRand8u ( &state1, (uchar*)B_8uC1->imageData,  n );
        atsbRand8s ( &state2, B_8sC1->imageData,  n );
        atsbRand32f( &state3, (float*)B_32fC1->imageData, n4);

        atsbRand8u ( &state4, (uchar*)mask->imageData,  n );
        for(ir=0; ir<n; ir++) if((mask->imageData)[ir]>1) (mask->imageData)[ir]=1;
        (mask->imageData)[0] = 1;

        step = A_8uC3->widthStep;  step4 = (A_32fC3->widthStep)/4;
        n = ny*step;  n4 = ny*step4;

        atsbRand8u ( &state1, (uchar*)A_8uC3->imageData,  n );
        atsbRand8s ( &state2, A_8sC3->imageData,  n );
        atsbRand32f( &state3, (float*)A_32fC3->imageData, n4);

        atsbRand8u ( &state1, (uchar*)B_8uC3->imageData,  n );
        atsbRand8s ( &state2, B_8sC3->imageData,  n );
        atsbRand32f( &state3, (float*)B_32fC3->imageData, n4);

        nr = (ny-1)/2>Max_ROI_Offset ? Max_ROI_Offset : (ny-1)/2;

        A_8uC1->roi = A_8sC1->roi = A_32fC1->roi = 
        A_8uC3->roi = A_8sC3->roi = A_32fC3->roi = 
        B_8uC1->roi = B_8sC1->roi = B_32fC1->roi = 
        B_8uC3->roi = B_8sC3->roi = B_32fC3->roi = &r;

        for( ir = 0; ir<=nr; ir++) /* ROI size cycle starts ----------------- */
        {
            /* IPL ROI structures filling */
            xoff = ir/11;
            yoff = ir;
            roiw = nx - (int)(1.2*xoff);
            roih = ny - (int)(1.5*yoff);
            r.xOffset = xoff;
            r.yOffset = yoff;
            r.width   = roiw;
            r.height  = roih;

            rm = r;
            rm.coi = 0;
            mask->roi = &rm;

/*  T E S T I N G  */
            for(it = 0; it<9; it++)
            {
                IplImage* B;

                r.coi = 0;

                //if( it >= 3 )
                //    continue;

                B = it<3 ? NULL : B_8uC1;
                A_8uC1->maskROI = B_8uC1->maskROI = NULL;
                norm     =   cvNormMask( A_8uC1, B, mask, cvlType[it] );
                testnorm = TestNormMask( A_8uC1, B, mask, cvlType[it] );
                err = fabs((norm-testnorm)/testnorm);
                if( err > EPS )
                {
                    nerrt[it]++;
                    printf(" 8uC1  %d norm fail:  %f  %f\n", it+1, norm, testnorm);
                }

                B = it<3 ? NULL : B_8sC1;
                A_8sC1->maskROI = B_8sC1->maskROI = NULL;
                norm     =   cvNormMask( A_8sC1, B, mask, cvlType[it] );
                testnorm = TestNormMask( A_8sC1, B, mask, cvlType[it] );
                err = fabs((norm-testnorm)/testnorm);
                if( err > EPS )
                {
                    nerrt[it]++;
                    printf(" 8sC1  %d norm fail:  %f  %f\n", it+1, norm, testnorm);
                }

                B = it<3 ? NULL : B_32fC1;
                A_32fC1->maskROI = B_32fC1->maskROI = NULL;
                norm     =   cvNormMask( A_32fC1, B, mask, cvlType[it] );
                testnorm = TestNormMask( A_32fC1, B, mask, cvlType[it] );
                err = fabs((norm-testnorm)/testnorm);
                if( err > FEPS )
                {
                    nerrt[it]++;
                    printf(" 32fC1 %d norm fail:  %f  %f\n", it+1, norm, testnorm);
                }

                    B = it<3 ? NULL : B_8uC3;
                    for( coi=1; coi<4; coi++ )
                    {
                        r.coi   = coi;
                        A_8uC3->maskROI = B_8uC3->maskROI = NULL;
                        norm     =   cvNormMask( A_8uC3, B, mask, cvlType[it] );
                        testnorm = TestNormMask( A_8uC3, B, mask, cvlType[it] );
                        err     = fabs((norm-testnorm)/testnorm);
                        if( err > EPS )
                        {
                            nerrt[it]++;
                            printf(" 8uC3  %d norm fail:  %f  %f,  coi = %d\n", it+1, norm, testnorm, coi);
                        }
                    }

                    B = it<3 ? NULL : B_8sC3;
                    for( coi=1; coi<4; coi++ )
                    {
                        r.coi = coi;
                        A_8sC3->maskROI = B_8sC3->maskROI = NULL;
                        norm     =   cvNormMask( A_8sC3, B, mask, cvlType[it] );
                        testnorm = TestNormMask( A_8sC3, B, mask, cvlType[it] );
                        err = fabs((norm-testnorm)/testnorm);
                        if( err > EPS )
                        {
                            nerrt[it]++;
                            printf(" 8sC3  %d norm fail:  %f  %f,  coi = %d\n", it+1, norm, testnorm, coi);
                        }
                    }

                    B = it<3 ? NULL : B_32fC3;
                    for( coi=1; coi<4; coi++ )
                    {
                        r.coi = coi;
                        A_32fC3->maskROI = B_32fC3->maskROI = NULL;
                        norm     =   cvNormMask( A_32fC3, B, mask, cvlType[it] );
                        testnorm = TestNormMask( A_32fC3, B, mask, cvlType[it] );
                        err = fabs((norm-testnorm)/testnorm);
                        if( err > FEPS )
                        {
                            nerrt[it]++;
                            printf(" 32fC3 %d norm fail:  %f  %f,  coi = %d\n", it+1, norm, testnorm, coi);
                        }
                    }
            } /* norm type */

            for( it=0; it<9; it++ ) nerr += nerrt[it];
        } /* ROI */

        A_8uC1->roi = A_8sC1->roi = A_32fC1->roi = 
        A_8uC3->roi = A_8sC3->roi = A_32fC3->roi = 
        B_8uC1->roi = B_8sC1->roi = B_32fC1->roi = 
        B_8uC3->roi = B_8sC3->roi = B_32fC3->roi = 0;

        mask->roi = 0;

        A_8uC1->maskROI = A_8sC1->maskROI = A_32fC1->maskROI = 
        A_8uC3->maskROI = A_8sC3->maskROI = A_32fC3->maskROI = 
        B_8uC1->maskROI = B_8sC1->maskROI = B_32fC1->maskROI = 
        B_8uC3->maskROI = B_8sC3->maskROI = B_32fC3->maskROI = 0;

        mask->maskROI = 0;

        cvReleaseImage( &A_8uC1  );
        cvReleaseImage( &A_8sC1  );
        cvReleaseImage( &A_32fC1 );
        cvReleaseImage( &B_8uC1  );
        cvReleaseImage( &B_8sC1  );
        cvReleaseImage( &B_32fC1 );
        cvReleaseImage( &A_8uC3  );
        cvReleaseImage( &A_8sC3  );
        cvReleaseImage( &A_32fC3 );
        cvReleaseImage( &B_8uC3  );
        cvReleaseImage( &B_8sC3  );
        cvReleaseImage( &B_32fC3 );
        cvReleaseImage( &mask    );
    } /* Nx */

/*trsWrite (TW_RUN|TW_CON|TW_SUM," %d norm  %s%s flavor  fail:  %g %g\n",
          it+1, f1, f2, norm, testnorm);*/

    if(nerr) return trsResult( TRS_FAIL, "Algorithm test has passed. %d errors.", nerr );
    else    return trsResult( TRS_OK, "Algorithm test has passed successfully" );

} /* fmaNorm */
예제 #6
0
static
struct descriptor_set listen_on_ifaces(const char* hostnames,
				struct clientinfo* clntinfo) {
	char* part =0, *portdel =0;
	char* hostnames2;
	size_t hostnames2size;
	int offset, port, shandle, i;
	struct descriptor_set d_set;

	offset = 0;
	clntinfo->boundsocket_niface = 0;
	FD_ZERO(&d_set.set);
	d_set.maxfd = 0;

	/* we have to make the string suitable for quotstrtok by appending a
	 * WHITESPACE character */
	hostnames2size = strlen(hostnames) + 2;
	hostnames2 = (char*) malloc(hostnames2size);
	enough_mem(hostnames2);
	snprintf(hostnames2, hostnames2size, "%s ", hostnames);

	while ((part = quotstrtok(hostnames2, WHITESPACES, &offset))) {
		/* do some counting */
		clntinfo->boundsocket_niface++;
		free(part);
	}
	clntinfo->boundsocket_list =
		(int*) malloc(sizeof(int) * clntinfo->boundsocket_niface);
	enough_mem(clntinfo->boundsocket_list);

	offset = 0; i = 0;
	while ((part = quotstrtok(hostnames2, WHITESPACES, &offset))) {
		portdel = strchr(part, ':');
		if (!portdel) {
			jlog(3, "Invalid IP/Port specification: %s", part);
			free(part);
			continue;
		}
		*portdel = (char) 0;
		errno = 0;
		port = strtol(portdel+1, (char**) 0, 10);
		if (errno || port > 65535 || port <= 0) {
			jlog(4, "Invalid port specification: %s. "
			   "Using default value %d", portdel, DEFAULTBINDPORT);
			port = DEFAULTBINDPORT;
		}
		portdel = (char*) 0;

		jlog(9, "binding to %s, port %d", part, port);

		shandle = bindport(part, port);
		free(part);
		part = (char*) 0;
		if (shandle < 0) {
			jlog(8, "Could not bind: %s", strerror(errno));
			free(hostnames2);
			FD_ZERO(&d_set.set);
			d_set.maxfd = -1;
			return d_set;
		}
		FD_SET(shandle, &d_set.set);
		d_set.maxfd = MAX_VAL(d_set.maxfd, shandle);
		clntinfo->boundsocket_list[ i++ ] = shandle;
	}
	free(hostnames2);
	hostnames2 = (char*) 0;

	if (clntinfo->boundsocket_niface == 0) {
		jlog(2, "No interfaces found to bind to");
		FD_ZERO(&d_set.set);
		d_set.maxfd = -1;
		return d_set;
	}

	return d_set;
}