tLine generate_draw_line(cv::Mat& image, const tPoint& prev) { tLine line(DRAW, prev, prev); tPoint pos = line.start; // Get initial direction Direction dir = find_direction(image, line.start); // Mark current position as visited image.at<uchar>(pos.y, pos.x) = BLACK; if(dir == NONE) { return line; } // Keep moving while there are white pixels in the direction of movement while(valid_direction(image, pos, dir)) { pos = increment_position(dir, pos); image.at<uchar>(pos.y, pos.x) = BLACK; } line.end = pos; return line; }
// called when we decided this is the packet that should be sent out void tcp_stream_t::accept_packet(packet_t *packet, const layer_t *tcplay) { const tcphdr &hdr = reinterpret_cast<const tcphdr &>(*tcplay->data()); const layer_t *next = packet->next(tcplay); if (d_direction == direction_unknown) find_direction(packet, tcplay); size_t psize = 0; if (next) psize = next->size(); assert(!next || (packet->next(next) == NULL && next->type() == layer_data)); // assume we are the last if (psize && (hdr.th_flags & TH_SYN)) { // if this ever happens in a legal case, please send me the pcap listener()->accept_error(packet, "tcp-payload in syn-packet"); return; } seq_nr_t seq = htonl(hdr.th_seq); int32_t packetloss = seq.d_val - d_next_seq.d_val; int32_t overlap = -packetloss; if (psize) { // we have content if (overlap > 0) { listener()->debug_packet(packet, "packet has %d bytes overlap out of %zu bytes total", overlap, psize); if ((uint32_t)overlap > psize) packet->add_layer(layer_data, next->end(), next->end()); else packet->add_layer(layer_data, next->begin() + overlap, next->end()); } seq.d_val += psize; } if (hdr.th_flags & TH_SYN) ++seq.d_val; if (hdr.th_flags & TH_FIN) ++seq.d_val; // this is undocumented, but needed?? // we don't have packetloss if we have a reset-packet, or with packet-overlap if (packetloss < 0 || (hdr.th_flags & TH_RST)) packetloss = 0; if (seq > d_next_seq) d_next_seq = seq; listener()->accept_tcp(packet, packetloss, this); if (hdr.th_flags & (TH_FIN|TH_RST)) { d_have_accepted_end = true; if (!d_have_sent_end) { listener()->end_of_stream(this); d_have_sent_end = true; } } check_delayed(); }
int monkey_direction(int response, float *sacval) { int monkey_direction; int direction; if(fabs(sacval[0]) > fabs(sacval[1])) direction = find_direction(sacval[0] * afc_s.abssac[0]); else direction = find_direction(sacval[1] * afc_s.abssac[1]); switch(direction){ case JONRIGHT: switch(response){ case CORRECT: monkey_direction = JONRIGHT; break; case WRONG: monkey_direction = JONLEFT; break; default: monkey_direction = FOUL; break; } break; case JONLEFT: switch(response){ case CORRECT: monkey_direction = JONLEFT; break; case WRONG: monkey_direction = JONRIGHT; break; default: monkey_direction = FOUL; break; } break; } return(monkey_direction); }
void performance_string(float expval, int response, int state, char **s1, char **s2, float sacval) { static int laststate=NORMAL_LOOP, counter=0; char c, *temp; int direction, ambig_direction; static float lastexpval=-999; char buf[100]; direction = find_direction(expval); ambig_direction = find_direction(sacval); if(*((*s1))==NULL) /* if s1 has been nullified(cleared) then point to first element */ counter = 0; if(counter+9 > PERF_STRING_LENGTH){ /* s2 becomes s1 and s1 points to a cleared string */ temp = *s2; *s2 = *s1; *s1 = temp; nullify(*s1, PERF_STRING_LENGTH); counter=0; /* just clears s1 to a string of NULLS */ } if(lastexpval != (expval = fabsf(expval)) ){ /* if the value of the cue has changed then print it */ sprintf(buf, "%4.2f", expval); strcat(*s1, buf); /*j where *s1 is a pointer to a pointer*/ counter += strlen(buf); lastexpval = expval; } /* if( (state == CORRECTION_LOOP) && (laststate != CORRECTION_LOOP ) )bgc*/ switch (direction){ case JONLEFT: if(fabs(afc_s.sacval[1]) > fabs(afc_s.sacval[0])) c = 'U'; else c = 'L'; break; case JONRIGHT: if(fabs(afc_s.sacval[1]) > fabs(afc_s.sacval[0])) c = 'D'; else c = 'R'; break; case AMBIGUOUS: c = 'a'; break; } *((*s1)+counter++) = c; if ( (direction == AMBIGUOUS) ){ /*j sacval is opposite to val of stim*/ switch(ambig_direction){ case JONLEFT: c = 'R'; break; case JONRIGHT: c = 'L'; break; } *((*s1)+counter++) = c; } switch (response){ case CORRECT: c = '#'; break; case WRONG: c = 'x'; break; case FOUL: c = 'o'; break; } *((*s1)+counter++) = c; if( (state == CORRECTION_LOOP)) *((*s1)+counter++) = '!'; /* else if( (state == NORMAL_LOOP) && (laststate != NORMAL_LOOP) ) *(*s1+counter++) = '@';*/ else *((*s1)+counter++) = ' '; laststate = state; }