Пример #1
0
BOX PIXROW::bounding_box() const { 
  INT16 i;
  INT16 y_coord;
  INT16 min_x = MAX_INT16 - 1;
  INT16 min_y = MAX_INT16 - 1;
  INT16 max_x = -MAX_INT16 + 1;
  INT16 max_y = -MAX_INT16 + 1;

  for (i = 0; i < row_count; i++) {
    y_coord = row_offset + i;
    if (min[i] <= max[i]) {
      if (y_coord < min_y)
        min_y = y_coord;
      if (y_coord + 1 > max_y)
        max_y = y_coord + 1;
      if (min[i] < min_x)
        min_x = min[i];
      if (max[i] + 1 > max_x)
        max_x = max[i] + 1;
    }
  }
  if (min_x > max_x || min_y > max_y)
    return BOX ();
  else
    return BOX (ICOORD (min_x, min_y), ICOORD (max_x, max_y));
}
Пример #2
0
static void cover_clues(struct dlx *solver, const char clues[81], int (*fn)(struct dlx *, struct column *), int dir) {
  for (int n = 0; n < 81; n++) {
    int i = (dir > 0) ? n : 80-n;

    if (clues[i] == '.') continue;

    solver->solution[i] = clues[i];

    int r = 1 + i / 9;
    int c = 1 + i % 9;
    int d = clues[i] - '0';
    int b = BOX(r, c);

    if (dir > 0) {
      fn(solver, &solver->cols[P(r, c)]);
      fn(solver, &solver->cols[C(c, d)]);
      fn(solver, &solver->cols[R(r, d)]);
      fn(solver, &solver->cols[B(b, d)]);
    } else {
      fn(solver, &solver->cols[B(b, d)]);
      fn(solver, &solver->cols[R(r, d)]);
      fn(solver, &solver->cols[C(c, d)]);
      fn(solver, &solver->cols[P(r, c)]);
    }
  }
}
Пример #3
0
WINDOW display_clip_image(WERD *word,                //word to be processed
                          IMAGE &bin_image,          //whole image
                          PIXROW_LIST *pixrow_list,  //pixrows built
                          BOX &pix_box               //box of subimage
                         ) {
  WINDOW clip_window;            //window for debug
  BOX word_box = word->bounding_box ();
  int border = word_box.height () / 2;
  BOX display_box = word_box;

  display_box.move_bottom_edge (-border);
  display_box.move_top_edge (border);
  display_box.move_left_edge (-border);
  display_box.move_right_edge (border);
  display_box -= BOX (ICOORD (0, 0 - BUG_OFFSET),
    ICOORD (bin_image.get_xsize (),
    bin_image.get_ysize () - BUG_OFFSET));

  pgeditor_msg ("Creating Clip window...");
  clip_window =
    create_window ("Clipped Blobs",
    SCROLLINGWIN,
    editor_word_xpos, editor_word_ypos,
    3 * (word_box.width () + 2 * border),
    3 * (word_box.height () + 2 * border),
  //window width,height
                                 // xmin, xmax
    display_box.left (), display_box.right (),
    display_box.bottom () - BUG_OFFSET,
    display_box.top () - BUG_OFFSET,
  // ymin, ymax
    TRUE, FALSE, FALSE, TRUE);   // down event & key only
  pgeditor_msg ("Creating Clip window...Done");

  clear_view_surface(clip_window); 
  show_sub_image (&bin_image,
    display_box.left (),
    display_box.bottom (),
    display_box.width (),
    display_box.height (),
    clip_window,
    display_box.left (), display_box.bottom () - BUG_OFFSET);

  word->plot (clip_window, RED);
  word_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE);
  pix_box.plot (clip_window, INT_HOLLOW, TRUE, BLUE, BLUE);
  plot_pixrows(pixrow_list, clip_window); 
  overlap_picture_ops(TRUE); 
  return clip_window;
}
Пример #4
0
void mkrows(struct dlx *solver) {
  int r, c, d;
  int nextnode = 0;
  int colnums[4];
  for (r = 1; r <= 9; r++) {
    for (c = 1; c <= 9; c++) {
      for (d = 1; d <= 9; d++) {
        colnums[0] = P(r, c);
        colnums[1] = R(r, d);
        colnums[2] = C(c, d);
        colnums[3] = B(BOX(r, c), d);
        mkrow(solver, colnums, nextnode);
        nextnode += 4;
      }
    }
  }
}
Пример #5
0
Game::Game()
	//: mWindow(sf::VideoMode(800, 600), "SFML Application")
	: mWindow(sf::VideoMode::getDesktopMode(), "SFML Application", sf::Style::Fullscreen)
	, paused(false)
{
	TimePerFrame = sf::seconds(1.f / 60.f);

	mWindow.setMouseCursorVisible(false);

	int boxCount = 500;
	for (int i = 0; i < boxCount; ++i)
	{
		boxes.push_back(BOX(new Box(RND::Int(1,25))));
	}

	texture.loadFromFile("resources/textures/face.png");

	for (auto& i : boxes)
	{
		reset(*i);
		//i->shape.setTexture(&texture);
	}
}
Пример #6
0
bool CMSWindow::Create(int LeftUpX, int LeftUpY, int Width, int Height, int bitsPerPixel, char *title, int arbMultisampleFormat, bool arbMultisampleSupported, bool Antialiasing, int AntialiasingMode)
{
	//Initializing global strings
	LoadString(hInstance, IdTitle, AppTitle, MAX_LOADSTRING);
	LoadString(hInstance, IdApp, AppWindowClass, MAX_LOADSTRING);
	Register();

	// Realizar la inicialización de la aplicación:
	if (!InitInstance ())
		return FALSE;

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IdApp));

	//**************************************************************//
	// Initialize Common Controls
	INITCOMMONCONTROLSEX icex;					// Initialize Windows Common Controls
	
	// Load the ToolTip class from the DLL
	icex.dwSize = sizeof(icex);
	icex.dwICC  = ICC_BAR_CLASSES;				// For Tooltips
	
	if(!InitCommonControlsEx(&icex))
		BOX("InitCommonControlEx() failed.");

	CreateRenderingContext();
	if(!IsDeviceContextOK() || !IsRenderingContextOK())
	{
		Destroy();
		return FALSE;
	}

	Visible = TRUE;						/// Set Visible To True

	//Reshape(45.0f);

	return TRUE;						// Window Creating Was A Success
}
Пример #7
0
BOOL8 read_next_box(FILE* box_file,  //
                    BOX *box,
                    char *ch) {
  char buff[256];                //boxfile read buffer
  char *buffptr = buff;
  STRING box_filename;
  static INT16 line = 0;
  INT32 x_min;
  INT32 y_min;
  INT32 x_max;
  INT32 y_max;
  INT32 count = 0;

  while (!feof (box_file)) {
    fgets (buff, sizeof (buff) - 1, box_file);
    line++;

    /* Check for blank lines in box file */
    for (buffptr = buff; isspace (*buffptr); buffptr++)
      ;
    if (*buffptr != '\0') {
      count =
        sscanf (buff,
        "%c " INT32FORMAT " " INT32FORMAT " " INT32FORMAT " "
        INT32FORMAT, ch, &x_min, &y_min, &x_max, &y_max);
      if (count != 5) {
        tprintf ("Box file format error on line %i ignored\n", line);
      }
      else {
        *box = BOX (ICOORD (x_min, y_min), ICOORD (x_max, y_max));
        return TRUE;             //read a box ok
      }
    }
  }
  return FALSE;                  //EOF
}
Пример #8
0
void char_clip_word(                            //
                    WERD *word,                 //word to be processed
                    IMAGE &bin_image,           //whole image
                    PIXROW_LIST *&pixrow_list,  //pixrows built
                    IMAGELINE *&imlines,        //lines cut from image
                    BOX &pix_box                //box defining imlines
                   ) {
  BOX word_box = word->bounding_box ();
  PBLOB_LIST *blob_list;
  PBLOB_IT blob_it;
  PIXROW_IT pixrow_it;
  INT16 pix_offset;              //Y pos of pixrow[0]
  INT16 row_height;              //No of pix rows
  INT16 imlines_x_offset;
  PIXROW *prev;
  PIXROW *next;
  PIXROW *current;
  BOOL8 changed;                 //still improving
  BOOL8 just_changed;            //still improving
  INT16 iteration_count = 0;
  INT16 foreground_colour;

  if (word->flag (W_INVERSE))
    foreground_colour = 1;
  else
    foreground_colour = 0;

  /* Define region for max pixrow expansion */
  pix_box = word_box;
  pix_box.move_bottom_edge (-pix_word_margin);
  pix_box.move_top_edge (pix_word_margin);
  pix_box.move_left_edge (-pix_word_margin);
  pix_box.move_right_edge (pix_word_margin);
  pix_box -= BOX (ICOORD (0, 0 + BUG_OFFSET),
    ICOORD (bin_image.get_xsize (),
    bin_image.get_ysize () - BUG_OFFSET));

  /* Generate pixrows list */

  pix_offset = pix_box.bottom ();
  row_height = pix_box.height ();
  blob_list = word->blob_list ();
  blob_it.set_to_list (blob_list);

  pixrow_list = new PIXROW_LIST;
  pixrow_it.set_to_list (pixrow_list);

  for (blob_it.mark_cycle_pt (); !blob_it.cycled_list (); blob_it.forward ()) {
    PIXROW *row = new PIXROW (pix_offset, row_height, blob_it.data ());
    ASSERT_HOST (!row->
      bad_box (bin_image.get_xsize (), bin_image.get_ysize ()));
    pixrow_it.add_after_then_move (row);
  }

  imlines = generate_imlines (bin_image, pix_box);

  /* Contract pixrows - shrink min and max back to black pixels */

  imlines_x_offset = pix_box.left ();

  pixrow_it.move_to_first ();
  for (pixrow_it.mark_cycle_pt ();
  !pixrow_it.cycled_list (); pixrow_it.forward ()) {
    ASSERT_HOST (!pixrow_it.data ()->
      bad_box (bin_image.get_xsize (), bin_image.get_ysize ()));
    pixrow_it.data ()->contract (imlines, imlines_x_offset,
      foreground_colour);
    ASSERT_HOST (!pixrow_it.data ()->
      bad_box (bin_image.get_xsize (), bin_image.get_ysize ()));
  }

  /* Expand pixrows iteratively 1 pixel at a time */
  do {
    changed = FALSE;
    pixrow_it.move_to_first ();
    prev = NULL;
    current = NULL;
    next = pixrow_it.data ();
    for (pixrow_it.mark_cycle_pt ();
    !pixrow_it.cycled_list (); pixrow_it.forward ()) {
      prev = current;
      current = next;
      if (pixrow_it.at_last ())
        next = NULL;
      else
        next = pixrow_it.data_relative (1);
      just_changed = current->extend (imlines, pix_box, prev, next,
        foreground_colour);
      ASSERT_HOST (!current->
        bad_box (bin_image.get_xsize (),
        bin_image.get_ysize ()));
      changed = changed || just_changed;
    }
    iteration_count++;
  }
  while (changed);
}
Пример #9
0
//
//===========================================================================

const byte ioidFeed  = 0;
const byte ioidFines = 1;
const byte ioidGrits = 2;

static IOAreaRec HydroCycloneIOAreaList[] =
  {{"Cyclone Feed",      "Feed"      , ioidFeed , LIO_In0 ,  nc_MLnk, 1, 1,            0, 0.0F},
   {"",                  "I"         , ioidFeed , LIO_In ,  nc_MLnk, 1, 1,            0, 0.0F},
   {"Cyclone Overflow",  "Fines"     , ioidFines, LIO_Out0,  nc_MLnk, 1, 1,            0, 0.0F},
   {"Cyclone Underflow", "Grits"     , ioidGrits, LIO_Out1,  nc_MLnk, 1, 1, dwIOIsBuffer, 0.0F}, //Out.Out"},
   {NULL}};
           
long Drw_HydroCyclone[] = { DD_Poly, -8,4, -8,12, 8,12, 8,4, 4,-12, -4,-12, -8,4, 8,4,
                           DD_Poly, BOX(-4,12, 8,4),
                           DD_End };

//--------------------------------------------------------------------------

IMPLEMENT_MODELUNIT(HydroCyclone, "HydroCyc", "", Drw_HydroCyclone, "HC", TOC_ALL|TOC_GRP_SIZEDST|TOC_USER,
                    "Hydro Cyclone", "") 
HydroCyclone::HydroCyclone(pTagObjClass pClass_, pchar TagIn, pTaggedObject pAttach, TagObjAttachment eAttach) :
  MdlNode(pClass_, TagIn, pAttach, eAttach),
  PartCrv("Partition", "PartCrv", this, TOA_Embedded),
  Feed("Feed", this, TOA_Embedded)//,
  {
  AttachClassInfo(nc_Process, HydroCycloneIOAreaList);
  Ore2Grit = 0.2;
  Liq2Grit = 0.5;
  ByePass2Grits = 0.0;
Пример #10
0
void BLOBNBOX::chop(                        //chop blobs
                    BLOBNBOX_IT *start_it,  //location of this
                    BLOBNBOX_IT *end_it,    //iterator
                    FCOORD rotation,        //for landscape
                    float xheight           //of line
                   ) {
  INT16 blobcount;               //no of blobs
  BLOBNBOX *newblob;             //fake blob
  BLOBNBOX *blob;                //current blob
  INT16 blobindex;               //number of chop
  INT16 leftx;                   //left edge of blob
  float blobwidth;               //width of each
  float rightx;                  //right edge to scan
  float ymin, ymax;              //limits of new blob
  float test_ymin, test_ymax;    //limits of part blob
  ICOORD bl, tr;                 //corners of box
  BLOBNBOX_IT blob_it;           //blob iterator

                                 //get no of chops
  blobcount = (INT16) floor (box.width () / xheight);
  if (blobcount > 1 && (blob_ptr != NULL || cblob_ptr != NULL)) {
                                 //width of each
    blobwidth = (float) (box.width () + 1) / blobcount;
    for (blobindex = blobcount - 1, rightx = box.right ();
    blobindex >= 0; blobindex--, rightx -= blobwidth) {
      ymin = (float) MAX_INT32;
      ymax = (float) -MAX_INT32;
      blob_it = *start_it;
      do {
        blob = blob_it.data ();
        if (blob->blob_ptr != NULL)
          find_blob_limits (blob->blob_ptr, rightx - blobwidth, rightx,
            rotation, test_ymin, test_ymax);
        else
          find_cblob_vlimits (blob->cblob_ptr, rightx - blobwidth,
            rightx,
            /*rotation, */ test_ymin, test_ymax);
        blob_it.forward ();
        if (test_ymin < ymin)
          ymin = test_ymin;
        if (test_ymax > ymax)
          ymax = test_ymax;
      }
      while (blob != end_it->data ());
      if (ymin < ymax) {
        leftx = (INT16) floor (rightx - blobwidth);
        if (leftx < box.left ())
          leftx = box.left ();   //clip to real box
        bl = ICOORD (leftx, (INT16) floor (ymin));
        tr = ICOORD ((INT16) ceil (rightx), (INT16) ceil (ymax));
        if (blobindex == 0)
          box = BOX (bl, tr);    //change box
        else {
          newblob = new BLOBNBOX;
                                 //box is all it has
          newblob->box = BOX (bl, tr);
                                 //stay on current
          end_it->add_after_stay_put (newblob);
        }
      }
    }
  }
}
Пример #11
0
// ImageList_Destroy() the return value
// refresh on WM_THEMECHANGED
static HIMAGELIST CreateRadioImages(COLORREF clrBk, COLORREF clrText)
{
	/* draw bitmap */
	HDC hdcScreen = GetDC(NULL);
	if (hdcScreen == NULL)
		return NULL;

	HIMAGELIST himl = NULL;
	HDC hdc = CreateCompatibleDC(NULL); /* compatible to screen */
	if (hdc != NULL) {
		SIZE size = { GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON) };
		RECT rc;
		SetRect(&rc, 0, 0, 2 * size.cx, size.cy);
		HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, rc.right, rc.bottom);
		if (hbm != NULL) {
			HBITMAP hbmPrev = (HBITMAP)SelectObject(hdc, hbm);
			if (hbmPrev != NULL) { /* error on select? */
				HTHEME hTheme = OpenThemeData(NULL, L"Button");
				SetRect(&rc, 0, 0, size.cx, size.cy);
				/* unchecked */
				if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL, &rc, NULL)) {
					/* checked */
					OffsetRect(&rc, size.cx, 0);
					if (!DrawThemeBackground(hTheme, hdc, BP_RADIOBUTTON, RBS_CHECKEDNORMAL, &rc, NULL))
						himl = ImageList_Create(size.cx, size.cy, ILC_COLOR32 | ILC_MASK, 3, 0);
				}
				CloseThemeData(hTheme);

				/* the classic way */
				if (himl == NULL) {
					RECT rcRadio;
					HBRUSH hbrBk = CreateSolidBrush(clrBk);
					if (hbrBk != NULL) {
						FillRect(hdc, &rc, hbrBk);
						DeleteObject(hbrBk);
						HDC hdcMono = CreateCompatibleDC(hdc);
						if (hdcMono != NULL) {
							HBITMAP hbmMono = CreateBitmap(rc.right, rc.bottom, 1, 1, NULL);
							if (hbmMono != NULL) {
								HBITMAP hbmPrevMono = (HBITMAP)SelectObject(hdcMono, hbmMono);
								if (hbmPrevMono != NULL) { /* error on select? */
									/* draws a black-and-white mask (see docs)
									 * we need to colorize it using BitBlt with text and background color */
									COLORREF clrPrevText = SetTextColor(hdc, clrText);
									COLORREF clrPrevBk = SetBkColor(hdc, clrBk);
									/* check mark is slightly smaller than icon size */
									SetRect(&rcRadio, 0, 0, GetSystemMetrics(SM_CXMENUCHECK), GetSystemMetrics(SM_CYMENUCHECK));
									if (rcRadio.right > size.cx) rcRadio.right = size.cx;
									if (rcRadio.bottom > size.cy) rcRadio.bottom = size.cy;
									SetRect(&rc, ((size.cx - rcRadio.right) / 2) + 1, ((size.cy - rcRadio.bottom) / 2) + 1, rcRadio.right + 1, rcRadio.bottom + 1);
									/* unchecked */
									if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) { /* white back */
										if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_FLAT)) {
											if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY | NOMIRRORBITMAP)) {
												/* checked */
												OffsetRect(&rc, size.cx, 0);
												if (BitBlt(hdcMono, 0, 0, rcRadio.right, rcRadio.bottom, NULL, 0, 0, WHITENESS)) {/* white back */
													if (DrawFrameControl(hdcMono, &rcRadio, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_FLAT | DFCS_CHECKED)) {
														if (BitBlt(hdc, rc.left, rc.top, rcRadio.right, rcRadio.bottom, hdcMono, 0, 0, SRCCOPY | NOMIRRORBITMAP))
															himl = ImageList_Create(size.cx, size.cy, ILC_COLOR | ILC_MASK, 3, 0);
													}
													else BOX("second DrawFrameControl() failed");
												}
												else BOX("second BitBlt() failed");
											}
											else BOX("intermediate BitBlt() failed");
										}
										else BOX("DrawFrameControl() failed");
									}
									else BOX("first BitBlt() failed");
									/* restore */
									SetBkColor(hdc, clrPrevBk);
									SetTextColor(hdc, clrPrevText);
									SelectObject(hdcMono, hbmPrevMono);
								}
								else BOX("hbmPrevMono == NULL");
								DeleteObject(hbmMono);
							}
							else BOX("hbmMono == NULL");
							DeleteDC(hdcMono);
						}
						else BOX("hdcMono == NULL");
					}
				}
				SelectObject(hdc, hbmPrev);
				/* create imagelist */
				if (himl != NULL) {
					if (himl == NULL) BOX("img list create failed");
					if (himl != NULL) if (ImageList_AddMasked(himl, hbm, clrBk) == -1) BOX("add failed");
				}
				else BOX("Win9x: drawing code not reached");
			}
			DeleteObject(hbm);
		}
		DeleteDC(hdc);
	}
	ReleaseDC(NULL, hdcScreen);
	return himl;
}