Example #1
0
void NewButton::setArmed(bool newArmed)
	{
	if(newArmed&&!isArmed)
		{
		/* Arm the button: */
		savedBorderType=getBorderType();
		savedBackgroundColor=backgroundColor;
		SingleChildContainer::setBorderType(savedBorderType!=Widget::LOWERED?Widget::LOWERED:Widget::RAISED); // Need to use base class method here
		SingleChildContainer::setBackgroundColor(armedBackgroundColor); // Need to use base class method here
		if(child!=0)
			child->setBackgroundColor(armedBackgroundColor);
		
		isArmed=true;
		}
	else if(!newArmed&&isArmed)
		{
		/* Disarm the button: */
		SingleChildContainer::setBorderType(savedBorderType); // Need to use base class method here
		SingleChildContainer::setBackgroundColor(savedBackgroundColor); // Need to use base class method here
		if(child!=0)
			child->setBackgroundColor(savedBackgroundColor);
		
		isArmed=false;
		}
	
	/* Call the arm callbacks: */
	ArmCallbackData cbData(this,isArmed);
	armCallbacks.call(&cbData);
	}
void
MapArea::initBorder(void)
      // Regenerates the boundary and refreshes border on the screen
{
   switch(getBorderType())
   {
      case GMapArea::NO_BORDER:
      case GMapArea::XOR_BORDER:
      case GMapArea::SOLID_BORDER:
	 ma_generatePieces();
	 repaintBorder();
	 break;
      case GMapArea::SHADOW_IN_BORDER:
	 for(int i=0;i<gmap_area->border_width;i++)
	    shadow_pattern[i]=-(100-100*(i+1)/gmap_area->border_width);
	 ma_generatePieces();
	 repaintBorder();
	 break;
      case GMapArea::SHADOW_OUT_BORDER:
	 for(int i=0;i<gmap_area->border_width;i++)
	    shadow_pattern[i]=100-100*(i+1)/gmap_area->border_width;
	 ma_generatePieces();
	 repaintBorder();
	 break;
      case GMapArea::SHADOW_EIN_BORDER:
	 for(int i=0;i<gmap_area->border_width;i++) shadow_pattern[i]=0;
	 shadow_pattern[0]=-100;
	 shadow_pattern[gmap_area->border_width-1]=100;
   	 ma_generatePieces();
	 repaintBorder();
	 break;
      case GMapArea::SHADOW_EOUT_BORDER:
	 for(int i=0;i<gmap_area->border_width;i++) shadow_pattern[i]=0;
	 shadow_pattern[0]=100;
	 shadow_pattern[gmap_area->border_width-1]=-100;
   	 ma_generatePieces();
	 repaintBorder();
	 break;
      default:
	 G_THROW(ERR_MSG("MapArea.unknown_border_type"));
   }
}
Example #3
0
bool ContourFlip::update()
{
  //if (!ImageNode::update()) return false;
  if (!Contour::update()) return false;

  // TBD get dirtiness of in to see if flip map needs to be recomputed
  
  if (!isDirty(this, 23)) { return true;}

  cv::Mat to_flip = getImage("to_flip");
  if (to_flip.empty()) {
    VLOG(2) << name << " in is empty";
    return false;
  }
  
  cv::Mat flipped = cv::Mat(to_flip.size(), to_flip.type());
 
  bool valid;
  bool is_dirty;
  cv::Mat in = getImage("in", valid, is_dirty, 51);
  
  if (is_dirty) 
  {
  
  LOG(INFO) << "contour flip updating " << is_dirty;
  cv::Mat dist = cv::Mat(to_flip.size(), to_flip.type());

  const int wd = dist.cols;
  const int ht = dist.rows;

  // This is very slow for dense contours, maybe make
  // scale option that will process the image at a lower resolution 
  // then upscale the off_x,off_y for the remap
  for (int y = 0; y < ht; y++) {
  for (int x = 0; x < wd; x++) {

  float min_dist = 1e9;
  cv::Point2f min_closest;

  int count = 0;
  // TBD just find the nearest contour point for now, don't worry about long segment
  // or the actual normal of the segment - just flip the pixel on the nearest point
  for (int i = 0; i < contours0.size(); i++) {  
  for (int j = 0; j < contours0[i].size(); j++) { 
  
    cv::Point2f v = contours0[i][j]; 
    cv::Point2f w = contours0[i][ (j+1) % contours0[i].size() ]; 
    //const float dx = (contours0[i][j].x - x); 
    //const float dy = (contours0[i][j].y - y);
    //const float cur_dist = fabs(dx) + fabs(dy); 
    //const float cur_dist = sqrt(dx*dx + dy*dy);
    cv::Point2f closest;
    const float cur_dist = minimum_distance( v, w, cv::Point2f(x, y), closest ); 
    if (cur_dist < min_dist) {
      min_dist = cur_dist;
      min_closest = closest;
    }
    count++;
  }}

  if ( (x == 0) && ( y == 0) ) setSignal("count", count);

  // TBD make a reflection effect instead of straight rolling over the edges?
  const int src_x = ((x + (int) ( 2 * (min_closest.x - x) ) ) + wd) % wd; 
  const int src_y = ((y + (int) ( 2 * (min_closest.y - y) ) ) + ht) % ht;
 
  // TBD this could be a map for remap and if the in image doesn't change it will
  // be more efficient
  //flipped.at<cv::Vec4b>(y, x) = to_flip.at<cv::Vec4b>(src_y, src_x);
  off_x.at<float>(y, x) = src_x - x;
  off_y.at<float>(y, x) = src_y - y;
  //LOG_FIRST_N(INFO,20) << src_x << " " << x << ", " << src_y << " " << y;
  dist.at<cv::Vec4b>(y, x) = cv::Scalar::all(min_dist); // % 255);
  }}

  cv::Mat dist_x = base_x + (off_x); //_scaled - offsetx * scalex);
  cv::Mat dist_y = base_y + (off_y); //_scaled - offsety * scaley);

  cv::convertMaps(dist_x, dist_y, dist_xy16, dist_int, CV_16SC2, true);
  
  setImage("dist", dist);

  {
    cv::Mat dist_xy8;
    cv::Mat dist_xy16_temp;
    cv::convertMaps(off_x, off_y, dist_xy16_temp, dist_int, CV_16SC2, true);
    dist_xy16_temp.convertTo(dist_xy8, CV_8UC2, getSignal("map_scale"));
    cv::Mat mapx = cv::Mat( Config::inst()->getImSize(), CV_8UC4, cv::Scalar(0,0,0,0));
    cv::Mat mapy = cv::Mat( Config::inst()->getImSize(), CV_8UC4, cv::Scalar(0,0,0,0));

    int chx[] = {0,0, 0,1, 0,2};
    mixChannels(&dist_xy8, 1, &mapx, 1, chx, 3 );
    int chy[] = {1,0, 1,1, 1,2};
    mixChannels(&dist_xy8, 1, &mapy, 1, chy, 3 );

    setImage("mapx", mapx);
    setImage("mapy", mapy);
  }

  }
  
 
  if (!dist_xy16.empty()) 
    cv::remap(to_flip, flipped, dist_xy16, cv::Mat(), getModeType(), getBorderType());

  setImage("flipped", flipped);

  return true;
}