Eigen::Matrix4f CollarLinesRegistrationPipeline::registerTwoGrids(const PolarGridOfClouds &source, const PolarGridOfClouds &target, const Eigen::Matrix4f &initial_transformation, int &iterations, float &error) { iterations = 0; Termination termination(pipeline_params.minIterations, pipeline_params.maxIterations, pipeline_params.maxTimeSpent, pipeline_params.significantErrorDeviation, pipeline_params.targetError); Eigen::Matrix4f transformation = initial_transformation; while(!termination()) { LineCloud source_line_cloud(source, pipeline_params.linesPerCellGenerated, pipeline_params.linesPerCellPreserved, pipeline_params.preservedFactorOfLinesBy); LineCloud target_line_cloud(target, pipeline_params.linesPerCellGenerated, pipeline_params.linesPerCellPreserved, pipeline_params.preservedFactorOfLinesBy); CollarLinesRegistration icl_fitting(source_line_cloud, target_line_cloud, registration_params, transformation); for(int sampling_it = 0; (sampling_it < pipeline_params.iterationsPerSampling) && !termination(); sampling_it++) { error = icl_fitting.refine(); termination.addNewError(error); iterations++; } transformation = icl_fitting.getTransformation(); } return transformation; }
int main( int argc, char* argv[] ) { //! [Creating a Convolutional code] //! [Creating a Convolutional code structure] //! [Creating a trellis] /* We are creating a trellis structure with 1 input bit. The constraint length is 4, which means there are 3 registers associated with the input bit. There are two output bits, the first one with generator 4 (in octal) associated with the input bit. */ fec::Trellis trellis({4}, {{013, 017}}, {015}); //! [Creating a trellis] /* The trellis is used to create a code structure. We specify that one bloc will conatins 1024 branches before being terminated. */ auto options = fec::Convolutional::Options(trellis, 1024); options.termination(fec::Convolutional::Tail); options.algorithm(fec::Approximate); //! [Creating a Convolutional code structure] /* A code is created and ready to operate */ std::unique_ptr<fec::Codec> codec(new fec::Convolutional(options)); //! [Creating a Convolutional code] std::cout << per(codec, 3.0) << std::endl; return 0; }
static void AntiSVN(char *targetDir) { targetDir = makeFullPath(targetDir); if(!ForceMode) { cout("%s\n", targetDir); cout("ANTI-SVN PROCEED? [Any/ESC]\n"); if(clearGetKey() == 0x1b) termination(1); cout("GO!\n"); } for(; ; ) { autoList_t *dirs = lssDirs(targetDir); char *dir; uint index; int found = 0; foreach(dirs, dir, index) { if( !_stricmp(".svn", getLocal(dir)) || !_stricmp("_svn", getLocal(dir)) ) { coExecute_x(xcout("RD /S /Q \"%s\"", dir)); found = 1; } } releaseDim(dirs, 1); if(!found) break; coSleep(1000); } memFree(targetDir); }
void SmallWorld::update() { if (!finished) { if (bugs[0].isFinished()) { evaluate(); bug1 = bugs[0]; bug2 = bugs[1]; // chech if termination is satisfied if (termination()) { cout << "end bugs life simulation up." << endl; finished = true; } else { // do crossover or mutation breed(); // reproduction initBox2d(); } } else { box2d.update(); // add force every 0.5s if (steps > 0 && steps % 15 == 0) { for (int i = 0; i < bugs.size(); i++) { bugs[i].update(); } } steps++; } } }
int main(int argc, char *argv[]) { /* Program Variable Define & Initialization */ int sockfd,numbytes; //socket file discriptor struct addrinfo hints, *servinfo, *p; int rv,choice,len; char ch; FILE *fp,*fo; char s[INET6_ADDRSTRLEN]; //hold the ipaddress // if no command line argument supplied if (argc != 2) { fprintf(stderr,"usage: client hostname\n"); exit(1); //just exit } memset(&hints, 0, sizeof hints); // fill memmory with a constant byte and returns a pointer to the memmory area hints hints.ai_family = AF_UNSPEC; // allow IpV4 or IpV6 adderess domain hints.ai_socktype = SOCK_STREAM; // fo socket stream // getaddrinfo()= returns a list of address structure. /* Given node(NULL) and service(Port), which identify an Internet host and a service, getaddrinfo() returns one or more addrinfo structures, each of which contains an Internet address that can be specified in a call to bind or connect */ // argv[1]= return 1 ipaddress if ((rv = getaddrinfo(argv[1], PORT, &hints, &servinfo)) != 0) { fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); return 1; } //socket is to create an endpoint for communcation. // servinfo->ai_family argument select the protocol family which will be used for communcation............. // servinfo->ai_socktype, type of socket................................................................... // servinfo->ai_protocol specify the particular to be used with socket..................................... if (sockfd = socket(servinfo->ai_family, servinfo->ai_socktype,servinfo->ai_protocol)){ perror("client: socket"); } /* inet_ntop - convert IPv4 and IPv6 addresses from binary to text form their_addr.ss_family This argument shall specify the family of the address. This can be AF_INET [IP6] [Option Start] or AF_INET6. [Option End] */ /* get_in_addr((struct sockaddr *)&their_addr argument points to a buffer holding an IPv4 address if the af argument is AF_INET, [IP6] [Option Start] or an IPv6 address if the af argument is AF_INET6; [Option End] the address must be in network byte order */ /* s,argument points to a buffer where the function stores the resulting text string; it shall not be NULL.*/ /* sizeof(s) argument specifies the size of this buffer, which shall be large enough to hold the text string (INET_ADDRSTRLEN characters for IPv4, [IP6] [Option Start] INET6_ADDRSTRLEN characters for IPv6). [Option End] */ inet_ntop(servinfo->ai_family, get_in_addr((struct sockaddr *)servinfo->ai_addr),s, sizeof(s)); printf("client: connecting to: %s\n", s); /* The connect() system call connects the socket referred to by the file descriptor sockfd to the address specified by addr. The addrlen argument specifies the size of addr. The format of the address in addr is determined by the address space of the socket sockfd; */ /* If the connection or binding succeeds, zero is returned. On error, -1 is returned, and errno is set appropriately. */ if (connect(sockfd, servinfo->ai_addr, servinfo->ai_addrlen) == -1){ close(sockfd); perror("client: connect"); return 0; } freeaddrinfo(servinfo); while(1) { printf("\n *****************************************************\n"); printf(" Enter your choice:\n"); printf(" For uploading: 1\n For downloading: 2\n For delete: 3\n For exit: 4\n "); scanf("%d",&choice); switch(choice) { case 1: send(sockfd,"1",1,0); video_uploading(sockfd,fp); break; case 2: send(sockfd,"2",1,0); video_downloading(sockfd,fo); break; case 3: send(sockfd,"3",1,0); video_delete(sockfd,fp); break; case 4: send(sockfd,"4",1,0); termination(sockfd,s); exit(1); break; default: printf("wrong choice"); break; } } close(sockfd); return 0; }
int main(int argc, char *argv[]){ printf("Preparing...\n"); //Sound preparing wav_get_info(SOUND,&info); sound_dev_prepare(DEVICE, &(info.dev), info.fmt.sample_rate, info.fmt.channels); queue_init(&s_queue, info.dev.buff_size_bytes); //Done //Some usefull info about wav-file #ifdef WAV_INFO printf("File Name: %s\n Chunk ID: %s\n Data Size: %u\n RIFF type: %s\n Chunk ID: %s\n Fmt Data Size: %d\n Comression code: 0x%04x\n Channels: %u\n Sample Rate: %u\n Average Bytes Per Second: %u\n Block Align: %u\n Significant Bytes Per Second: %u\n Chunk ID: %s\n Data Size: %u\n",SOUND,info.riff.id, info.riff.data_size,info.riff.type, info.fmt.id, info.fmt.data_size, info.fmt.compression, info.fmt.channels, info.fmt.sample_rate, info.fmt.av_bps, info.fmt.block_align, info.fmt.sign_bps, info.data.id, info.data.size); #endif //Let's play some music! struct reader_t reader_info; int time; if (argc == 3){ sscanf(argv[1],"%u",&reader_info.start_sound); sscanf(argv[2],"%u",&time); } else { reader_info.start_sound = 0; time = 1; } reader_info.start_frame = (reader_info.start_sound * FPS) / 1000; reader_info.sound_offset = info.data.offset; reader_info.sound_buff_size = info.dev.buff_size_bytes; pthread_create(&r_th, NULL, reader, &(reader_info)); struct timeval time1; struct timezone tz; int fps_timeout = 1000000000 / FPS; memset(&tz, 0, sizeof(tz)); struct timespec timeout; timeout.tv_sec = 0; timeout.tv_nsec = 0; struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; while(buffer_ready == FALSE) wait(&tv); struct packet_t *s_buff, *v_buff; sound_buff = (*(queue_pop(&s_queue))).data; s_buff = queue_pop_next(&s_queue); video_buff = (*(queue_pop(&v_queue))).data; v_buff = queue_pop_next(&s_queue); pthread_create(&s_th, NULL, sound_thread, &(info.dev)); pthread_create(&v_th, NULL, video_thread, NULL); printf("Threads started...\n"); while(v_ready == FALSE) wait(&tv); //----------------------* KICKER int frames = 0; int rc = 0; printf("Ready to play...\n"); int no_skip = 0; for(int i = 0; i < ((time * FPS )/ 1000); ++i){ pthread_cond_signal(&s_cond); pthread_cond_signal(&v_cond); v_buff = queue_pop_next(&v_queue); gettimeofday(&time1, &tz); pthread_mutex_lock(&k_mutex); timeout.tv_nsec = fps_timeout*1000; add_timespec(&timeout, &time1); rc = pthread_cond_timedwait(&k_cond, &k_mutex, (const struct timespec *restrict)&timeout); pthread_mutex_unlock(&k_mutex); if (rc == 0){ sound_buff = (*s_buff).data; pthread_cond_signal(&s_cond); queue_skip(&s_queue,1); frames = (s_buff->timestamp / 1000) - (v_buff->timestamp / 1000); printf("DEBUG: S: %ld V: %ld\n",s_buff->timestamp / 1000,v_buff->timestamp / 1000); if (frames > 0){ queue_skip(&v_queue,frames); printf("DEBUG: Skip frames: %d\n",frames); } else if (frames < 0) { printf("DEBUG: No skip: %d\n",-frames); no_skip = -frames; } s_buff = queue_pop_next(&s_queue); } video_buff = (*v_buff).data; if (no_skip > 0){ --no_skip; } else { queue_skip(&v_queue,1); } } pthread_cond_signal(&s_cond); printf("THE END\n"); //---------------------------* KICKER END termination(); return 0; }