// GIVEN AN IMAGE, SLOPE INFORMATION, AND A PATCHSIZE, PUTS A SEQUENCE OF // REAL OBJECTS AND THEIR REFLECTED REGIONS IN outvector AS ARC_Pair's int getReflections( const cv::Mat& frame, const cv::Size& patchSize, std::list<ARC_Pair>& outlist, const std::vector<cv::Point2f>& gft ) { cv::Mat sourceCopy; if( !frame.data ) { std::cout << "Image couldn't be loaded\n"; exit( EXIT_FAILURE ); } frame.copyTo( sourceCopy ); cvtColor( sourceCopy, sourceCopy, CV_RGB2GRAY, 1 ); cv::equalizeHist( sourceCopy, sourceCopy ); std::vector<cv::Point> points; cv::Rect frame_rect( cv::Point(0, 0), frame.size() ); for( std::vector<cv::Point2f>::const_iterator it=gft.begin(); it!=gft.end(); ++it ) { cv::Mat sourceCopy2 = frame.clone(); cv::Rect a, b; double nsigma; // Get Rect A a = cv::Rect( *it-( .5*cv::Point2f( patchSize ) ), patchSize ) & frame_rect; if( a.width==0 || a.height==0 ) continue; // Get Rect B and nsigma b = findBestMatchLocation( sourceCopy2, a, &nsigma, cv::Mat() ); // Create ARC_Pair bool err; ARC_Pair pair( *it, b, nsigma, sourceCopy2, &err ); // Add to list if( !err ) outlist.push_back( pair ); } return outlist.size(); }
void cTextField::draw(){ if(!visible) return; static const sf::Color hiliteClr = {127,127,127}, ipClr = {92, 92, 92}; inWindow->setActive(); rectangle outline = frame; outline.inset(-2,-2); fill_rect(*inWindow, outline, sf::Color::White); frame_rect(*inWindow, outline, sf::Color::Black); std::string contents = getText(); TextStyle style; style.font = FONT_PLAIN; style.pointSize = 12; style.colour = sf::Color::Black; style.lineHeight = 16; size_t ip_offset = 0; hilite_t hilite = {insertionPoint, selectionPoint}; if(selectionPoint < insertionPoint) std::swap(hilite.first,hilite.second); if(haveFocus && contents.length() >= 1 && changeMade) { text_rect = frame; text_rect.inset(2,2); // Determine which line the insertion and selection points are on clip_rect(*inWindow, {0,0,0,0}); // To prevent drawing hilite_t tmp_hilite = hilite; // Manipulate this to ensure that there is a hilited area std::string dummy_str = contents + " "; if(tmp_hilite.first >= tmp_hilite.second) tmp_hilite.second = tmp_hilite.first + 1; std::vector<rectangle> rects = draw_string_hilite(*inWindow, text_rect, dummy_str, style, {tmp_hilite}, {0,0,0}); if(!rects.empty()) { // We only care about the first and last rects. Furthermore, we only really need one point location ip_pos = rects[0].centre(), sp_pos = rects[rects.size() - 1].centre(); if(selectionPoint < insertionPoint) std::swap(ip_pos, sp_pos); // Prioritize selection point being visible. If possible, also keep insertion point visible. // We do this by first ensuring the insertion point is visible, then doing the same // for the selection point. while(!ip_pos.in(frame)) { text_rect.offset(0,-14); ip_pos.y -= 14; sp_pos.y -= 14; } while(!sp_pos.in(frame)) { int shift = selectionPoint < insertionPoint ? 14 : -14; text_rect.offset(0,shift); ip_pos.y += shift; sp_pos.y += shift; } } undo_clip(*inWindow); changeMade = false; } clip_rect(*inWindow, frame); ip_col = ip_row = -1; if(haveFocus) { snippets = draw_string_sel(*inWindow, text_rect, contents, style, {hilite}, hiliteClr); int iSnippet = -1, sum = 0; ip_offset = insertionPoint; for(size_t i = 0; i < snippets.size(); i++) { size_t snippet_len = snippets[i].text.length(); sum += snippet_len; if(sum >= insertionPoint) { iSnippet = i; break; } ip_offset -= snippet_len; } std::string pre_ip = iSnippet >= 0 ? snippets[iSnippet].text.substr(0, ip_offset) : ""; ip_offset = string_length(pre_ip, style); if(ip_timer.getElapsedTime().asMilliseconds() < 500) { // printf("Blink on (%d); ", ip_timer.getElapsedTime().asMilliseconds()); rectangle ipRect = {0, 0, 15, 1}; if(iSnippet >= 0) ipRect.offset(snippets[iSnippet].at.x + ip_offset, snippets[iSnippet].at.y + 1); else ipRect.offset(frame.topLeft()), ipRect.offset(3,2); fill_rect(*inWindow, ipRect, ipClr); } else if(ip_timer.getElapsedTime().asMilliseconds() > 1000) { // printf("Blink off (%d); ", ip_timer.getElapsedTime().asMilliseconds()); ip_timer.restart(); } // Record it so that we can calculate up/down arrow key results ip_col = ip_offset; ip_row = iSnippet; } else { rectangle text_rect = frame; text_rect.inset(2,2); win_draw_string(*inWindow, text_rect, contents, eTextMode::WRAP, style); } undo_clip(*inWindow); }