// Compute the Chebyshev coefficients of a given CharSamp
bool FeatureChebyshev::ComputeChebyshevCoefficients(CharSamp *char_samp,
                                                    float *features) {
  if (char_samp->NormBottom() <= 0) {
    return false;
  }
  unsigned char *raw_data = char_samp->RawData();
  int stride = char_samp->Stride();
  // compute the height of the word
  int word_hgt = (255 * (char_samp->Top() + char_samp->Height()) /
                  char_samp->NormBottom());
  // compute left & right profiles
  vector<float> left_profile(word_hgt, 0.0);
  vector<float> right_profile(word_hgt, 0.0);
  unsigned char *line_data = raw_data;
  for (int y = 0; y < char_samp->Height(); y++, line_data += stride) {
    int min_x = char_samp->Width();
    int max_x = -1;
    for (int x = 0; x < char_samp->Width(); x++) {
      if (line_data[x] == 0) {
        UpdateRange(x, &min_x, &max_x);
      }
    }
    left_profile[char_samp->Top() + y] =
        1.0 * (min_x == char_samp->Width() ? 0 : (min_x + 1)) /
        char_samp->Width();
    right_profile[char_samp->Top() + y] =
        1.0 * (max_x == -1 ? 0 : char_samp->Width() - max_x) /
        char_samp->Width();
  }

  // compute top and bottom profiles
  vector<float> top_profile(char_samp->Width(), 0);
  vector<float> bottom_profile(char_samp->Width(), 0);
  for (int x = 0; x < char_samp->Width(); x++) {
    int min_y = word_hgt;
    int max_y = -1;
    line_data = raw_data;
    for (int y = 0; y < char_samp->Height(); y++, line_data += stride) {
      if (line_data[x] == 0) {
        UpdateRange(y + char_samp->Top(), &min_y, &max_y);
      }
    }
    top_profile[x] = 1.0 * (min_y == word_hgt ? 0 : (min_y + 1)) / word_hgt;
    bottom_profile[x] = 1.0 * (max_y == -1 ? 0 : (word_hgt - max_y)) / word_hgt;
  }

  // compute the chebyshev coefficients of each profile
  ChebyshevCoefficients(left_profile, kChebychevCoefficientCnt, features);
  ChebyshevCoefficients(top_profile, kChebychevCoefficientCnt,
                        features + kChebychevCoefficientCnt);
  ChebyshevCoefficients(right_profile, kChebychevCoefficientCnt,
                        features + (2 * kChebychevCoefficientCnt));
  ChebyshevCoefficients(bottom_profile, kChebychevCoefficientCnt,
                        features + (3 * kChebychevCoefficientCnt));
  return true;
}
Esempio n. 2
0
// Gets the properties for a grapheme string, combining properties for
// multiple characters in a meaningful way where possible.
// Returns false if no valid match was found in the unicharset.
// NOTE that script_id, mirror, and other_case refer to this unicharset on
// return and will need translation if the target unicharset is different.
bool UNICHARSET::GetStrProperties(const char* utf8_str,
                                  UNICHAR_PROPERTIES* props) const {
  props->Init();
  props->SetRangesEmpty();
  int total_unicodes = 0;
  GenericVector<UNICHAR_ID> encoding;
  if (!encode_string(utf8_str, true, &encoding, NULL, NULL))
    return false;  // Some part was invalid.
  for (int i = 0; i < encoding.size(); ++i) {
    int id = encoding[i];
    const UNICHAR_PROPERTIES& src_props = unichars[id].properties;
    // Logical OR all the bools.
    if (src_props.isalpha) props->isalpha = true;
    if (src_props.islower) props->islower = true;
    if (src_props.isupper) props->isupper = true;
    if (src_props.isdigit) props->isdigit = true;
    if (src_props.ispunctuation) props->ispunctuation = true;
    if (src_props.isngram) props->isngram = true;
    if (src_props.enabled) props->enabled = true;
    // Min/max the tops/bottoms.
    UpdateRange(src_props.min_bottom, &props->min_bottom, &props->max_bottom);
    UpdateRange(src_props.max_bottom, &props->min_bottom, &props->max_bottom);
    UpdateRange(src_props.min_top, &props->min_top, &props->max_top);
    UpdateRange(src_props.max_top, &props->min_top, &props->max_top);
    float bearing = props->advance + src_props.bearing;
    if (total_unicodes == 0 || bearing < props->bearing) {
      props->bearing = bearing;
      props->bearing_sd = props->advance_sd + src_props.bearing_sd;
    }
    props->advance += src_props.advance;
    props->advance_sd += src_props.advance_sd;
    // With a single width, just use the widths stored in the unicharset.
    props->width = src_props.width;
    props->width_sd = src_props.width_sd;
    // Use the first script id, other_case, mirror, direction.
    // Note that these will need translation, except direction.
    if (total_unicodes == 0) {
      props->script_id = src_props.script_id;
      props->other_case = src_props.other_case;
      props->mirror = src_props.mirror;
      props->direction = src_props.direction;
    }
    // The normed string for the compound character is the concatenation of
    // the normed versions of the individual characters.
    props->normed += src_props.normed;
    ++total_unicodes;
  }
  if (total_unicodes > 1) {
    // Estimate the total widths from the advance - bearing.
    props->width = props->advance - props->bearing;
    props->width_sd = props->advance_sd + props->bearing_sd;
  }
  return total_unicodes > 0;
}
Esempio n. 3
0
// Expands the ranges with the ranges from the src properties.
void UNICHARSET::UNICHAR_PROPERTIES::ExpandRangesFrom(
    const UNICHAR_PROPERTIES& src) {
  UpdateRange(src.min_bottom, &min_bottom, &max_bottom);
  UpdateRange(src.max_bottom, &min_bottom, &max_bottom);
  UpdateRange(src.min_top, &min_top, &max_top);
  UpdateRange(src.max_top, &min_top, &max_top);
  UpdateRange(src.min_width, &min_width, &max_width);
  UpdateRange(src.max_width, &min_width, &max_width);
  UpdateRange(src.min_bearing, &min_bearing, &max_bearing);
  UpdateRange(src.max_bearing, &min_bearing, &max_bearing);
  UpdateRange(src.min_advance, &min_advance, &max_advance);
  UpdateRange(src.max_advance, &min_advance, &max_advance);
}
Esempio n. 4
0
void find_cblob_hlimits(                //get x limits
                        C_BLOB *blob,   //blob to search
                        float bottomy,  //y limits
                        float topy,
                        float &xmin,    //output x limits
                        float &xmax) {
  inT16 stepindex;               //current point
  ICOORD pos;                    //current coords
  ICOORD vec;                    //rotated step
  C_OUTLINE *outline;            //current outline
                                 //outlines
  C_OUTLINE_IT out_it = blob->out_list ();

  xmin = (float) MAX_INT32;
  xmax = (float) -MAX_INT32;
  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
    outline = out_it.data ();
    pos = outline->start_pos (); //get coords
    for (stepindex = 0; stepindex < outline->pathlength (); stepindex++) {
                                 //inside
      if (pos.y () >= bottomy && pos.y () <= topy) {
        UpdateRange(pos.x(), &xmin, &xmax);
      }
      vec = outline->step (stepindex);
      pos += vec;                //move to next
    }
  }
}
Esempio n. 5
0
void find_cblob_limits(                  //get y limits
                       C_BLOB *blob,     //blob to search
                       float leftx,      //x limits
                       float rightx,
                       FCOORD rotation,  //for landscape
                       float &ymin,      //output y limits
                       float &ymax) {
  inT16 stepindex;               //current point
  ICOORD pos;                    //current coords
  ICOORD vec;                    //rotated step
  C_OUTLINE *outline;            //current outline
                                 //outlines
  C_OUTLINE_IT out_it = blob->out_list ();

  ymin = (float) MAX_INT32;
  ymax = (float) -MAX_INT32;
  for (out_it.mark_cycle_pt (); !out_it.cycled_list (); out_it.forward ()) {
    outline = out_it.data ();
    pos = outline->start_pos (); //get coords
    pos.rotate (rotation);
    for (stepindex = 0; stepindex < outline->pathlength (); stepindex++) {
                                 //inside
      if (pos.x () >= leftx && pos.x () <= rightx) {
        UpdateRange(pos.y(), &ymin, &ymax);
      }
      vec = outline->step (stepindex);
      vec.rotate (rotation);
      pos += vec;                //move to next
    }
  }
}
_Item Equipable::EquipAmmo(_Item * NewAmmo)
{
    _Item OldAmmo = *m_AuxAmmoItem->GetData();

    if (m_AmmoBase = g_ItemBaseMgr->GetItem(NewAmmo->ItemTemplateID))
    {
        m_AmmoInstance = m_AmmoBase->GetAmmoInstance(NewAmmo->InstanceInfo);
		UpdateRange();
    }

    m_AuxAmmoItem->SetData(NewAmmo);

	m_Player->SaveAmmoChange(m_Slot, NewAmmo);

    if (m_AuxAmmoItem->GetItemTemplateID() < 0)
    {
        AddItemStateFlag(ITEM_STATE_NO_AMMO);
		AddItemStateFlag(ITEM_STATE_NO_TARGETING);
        AddItemStateFlag(ITEM_STATE_DISABLED);
    }
    else if (m_AuxEquipItem->GetItemState() & ITEM_STATE_NO_AMMO)
    {
        //TODO: Check activation requirements
        RemoveItemStateFlag(ITEM_STATE_NO_AMMO);
		RemoveItemStateFlag(ITEM_STATE_NO_TARGETING);

        /* If the item is read, remove the disabled flag aswell */
        if (m_ReadyTime < GetNet7TickCount())
        {
		    RemoveItemStateFlag(ITEM_STATE_DISABLED);
        }
    }

    return OldAmmo;
}
Esempio n. 7
0
//
// PostRebuild
//
void ICListBox::PostRebuild(ICListBox::Rebuild **rebuild)
{
    ASSERT(rebuild)
    ASSERT(*rebuild)

    Rebuild *r = *rebuild;

    UpdateRange();

    // Restore the top
    if (r->flags & Rebuild::TOP)
    {
        desiredTop = r->top;
        top = r->top;
    }

    // Restore selected item
    if (r->flags & Rebuild::SEL)
    {
        SetSelectedItem(r->sel.str);
    }

    delete r;
    r = NULL;
}
Esempio n. 8
0
//Checks the given sensor values and returns and array of bools.
bool Sensor::GetReading() {
	ReadRaw();
	UpdateRange();
	Normalise();
	toTileColour();
	return tileWhite;
}
Esempio n. 9
0
BOOL CRoiDlg::OnInitDialog()
{
   ASSERT(m_pDoc);
    CImage* image = m_pDoc->GetImage();
    const IppiRect*   roi = image->GetRoi();
    if (roi) {
        m_Roi.x = roi->x;
        m_Roi.y = roi->y;
        m_Roi.width  = roi->width ;
        m_Roi.height = roi->height;
    } else if (image->Width() > 8 && image->Height() > 8) {
        m_Roi.x = 8;
        m_Roi.y = 8;
        m_Roi.width  = image->Width()  - 16;
        m_Roi.height = image->Height() - 16;
    } else {
        m_Roi.x = 0;
        m_Roi.y = 0;
        m_Roi.width  = image->Width() ;
        m_Roi.height = image->Height();
    }
    m_ImageWidth  = image->Width() ;
    m_ImageHeight = image->Height();

   CDialog::OnInitDialog();

    UpdateRange();
   return TRUE;
}
Esempio n. 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 && 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 ();
        find_cblob_vlimits(blob->cblob_ptr, rightx - blobwidth,
                           rightx,
            /*rotation, */ test_ymin, test_ymax);
        blob_it.forward ();
        UpdateRange(test_ymin, test_ymax, &ymin, &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 = TBOX (bl, tr);    //change box
        else {
          newblob = new BLOBNBOX;
                                 //box is all it has
          newblob->box = TBOX (bl, tr);
                                 //stay on current
          newblob->base_char_top_ = tr.y();
          newblob->base_char_bottom_ = bl.y();
          end_it->add_after_stay_put (newblob);
        }
      }
    }
  }
}
Esempio n. 11
0
// Expands the ranges with the ranges from the src properties.
void UNICHARSET::UNICHAR_PROPERTIES::ExpandRangesFrom(
    const UNICHAR_PROPERTIES& src) {
  UpdateRange(src.min_bottom, &min_bottom, &max_bottom);
  UpdateRange(src.max_bottom, &min_bottom, &max_bottom);
  UpdateRange(src.min_top, &min_top, &max_top);
  UpdateRange(src.max_top, &min_top, &max_top);
  if (src.width_sd > width_sd) {
    width = src.width;
    width_sd = src.width_sd;
  }
  if (src.bearing_sd > bearing_sd) {
    bearing = src.bearing;
    bearing_sd = src.bearing_sd;
  }
  if (src.advance_sd > advance_sd) {
    advance = src.advance;
    advance_sd = src.advance_sd;
  }
}
Esempio n. 12
0
/**********************************************************************
 * blob_bounding_box
 *
 * Compute the bounding_box of a compound blob, define to be the
 * max coordinate value of the bounding boxes of all the top-level
 * outlines in the box.
 **********************************************************************/
void blob_bounding_box(const TBLOB *blob,         // blob to compute on.
                       TPOINT *topleft,           // bounding box.
                       TPOINT *botright) {
  register TESSLINE *outline;    // Current outline.

  if (blob == NULL || blob->outlines == NULL) {
    topleft->x = topleft->y = 0;
    *botright = *topleft;        // Default value.
  } else {
    outline = blob->outlines;
    *topleft = outline->topleft;
    *botright = outline->botright;
    for (outline = outline->next; outline != NULL; outline = outline->next) {
      UpdateRange(outline->topleft.x, outline->botright.x,
                  &topleft->x, &botright->x);
      UpdateRange(outline->botright.y, outline->topleft.y,
                  &botright->y, &topleft->y);
    }
  }
}
Esempio n. 13
0
// Given an initial estimate of line spacing (m_in) and the positions of each
// baseline, computes the line spacing of the block more accurately in m_out,
// and the corresponding intercept in c_out, and the number of spacings seen
// in index_delta. Returns the error of fit to the line spacing model.
// Uses a simple linear regression, but optimized the offset using the median.
double BaselineBlock::FitLineSpacingModel(
    const GenericVector<double>& positions, double m_in,
    double* m_out, double* c_out, int* index_delta) {
  if (m_in == 0.0f || positions.size() < 2) {
    *m_out = m_in;
    *c_out = 0.0;
    if (index_delta != NULL) *index_delta = 0;
    return 0.0;
  }
  GenericVector<double> offsets;
  // Get the offset (remainder) linespacing for each line and choose the median.
  for (int i = 0; i < positions.size(); ++i)
    offsets.push_back(fmod(positions[i], m_in));
  // Get the median offset.
  double median_offset = MedianOfCircularValues(m_in, &offsets);
  // Now fit a line to quantized line number and offset.
  LLSQ llsq;
  int min_index = MAX_INT32;
  int max_index = -MAX_INT32;
  for (int i = 0; i < positions.size(); ++i) {
    double y_pos = positions[i];
    int row_index = IntCastRounded((y_pos - median_offset) / m_in);
    UpdateRange(row_index, &min_index, &max_index);
    llsq.add(row_index, y_pos);
  }
  // Get the refined line spacing.
  *m_out = llsq.m();
  // Use the median offset rather than the mean.
  offsets.truncate(0);
  for (int i = 0; i < positions.size(); ++i)
    offsets.push_back(fmod(positions[i], *m_out));
  // Get the median offset.
  if (debug_level_ > 2) {
    for (int i = 0; i < offsets.size(); ++i)
      tprintf("%d: %g\n", i, offsets[i]);
  }
  *c_out = MedianOfCircularValues(*m_out, &offsets);
  if (debug_level_ > 1) {
    tprintf("Median offset = %g, compared to mean of %g.\n",
            *c_out, llsq.c(*m_out));
  }
  // Index_delta is the number of hypothesized line gaps present.
  if (index_delta != NULL)
    *index_delta = max_index - min_index;
  // Use the regression model's intercept to compute the error, as it may be
  // a full line-spacing in disagreement with the median.
  double rms_error = llsq.rms(*m_out, llsq.c(*m_out));
  if (debug_level_ > 1) {
    tprintf("Linespacing of y=%g x + %g improved to %g x + %g, rms=%g\n",
            m_in, median_offset, *m_out, *c_out, rms_error);
  }
  return rms_error;
}
Esempio n. 14
0
OP_STATUS
DOM_WindowSelection::IsCollapsed(BOOL &is_collapsed)
{
	RETURN_IF_ERROR(UpdateRange());

	if (range)
		is_collapsed = range->IsCollapsed();
	else
		is_collapsed = TRUE;

	return OpStatus::OK;
}
Esempio n. 15
0
// create a union of a number of arbitrary pix
Pix *CubeLineSegmenter::Pixa2Pix(Pixa *pixa, Box **dest_box,
                                 int start_pix, int pix_cnt) {
  // compute union_box
  int min_x = INT_MAX,
    max_x = INT_MIN,
    min_y = INT_MAX,
    max_y = INT_MIN;

  for (int pix_idx = start_pix; pix_idx < (start_pix + pix_cnt); pix_idx++) {
    Box *pix_box = pixa->boxa->box[pix_idx];

    UpdateRange(pix_box->x, pix_box->x + pix_box->w, &min_x, &max_x);
    UpdateRange(pix_box->y, pix_box->y + pix_box->h, &min_y, &max_y);
  }

  (*dest_box) = boxCreate(min_x, min_y, max_x - min_x, max_y - min_y);
  if ((*dest_box) == NULL) {
    return NULL;
  }

  // create the union pix
  Pix *union_pix = pixCreate((*dest_box)->w, (*dest_box)->h, img_->d);
  if (union_pix == NULL) {
    boxDestroy(dest_box);
    return NULL;
  }

  // create a pix corresponding to the union of all pixs
  // blt the src and dest pix
  for (int pix_idx = start_pix; pix_idx < (start_pix + pix_cnt); pix_idx++) {
    Box *pix_box = pixa->boxa->box[pix_idx];
    Pix *con_pix = pixa->pix[pix_idx];

    pixRasterop(union_pix,
                pix_box->x - (*dest_box)->x, pix_box->y - (*dest_box)->y,
                pix_box->w, pix_box->h, PIX_SRC | PIX_DST, con_pix, 0, 0);
  }

  return union_pix;
}
Esempio n. 16
0
// Computes the min and max cross product of the outline points with the
// given vec and returns the results in min_xp and max_xp. Geometrically
// this is the left and right edge of the outline perpendicular to the
// given direction, but to get the distance units correct, you would
// have to divide by the modulus of vec.
void TESSLINE::MinMaxCrossProduct(const TPOINT vec,
                                  int* min_xp, int* max_xp) const {
  *min_xp = MAX_INT32;
  *max_xp = MIN_INT32;
  EDGEPT* this_edge = loop;
  do {
    if (!this_edge->IsHidden() || !this_edge->prev->IsHidden()) {
      int product = CROSS(this_edge->pos, vec);
      UpdateRange(product, min_xp, max_xp);
    }
    this_edge = this_edge->next;
  } while (this_edge != loop);
}
Esempio n. 17
0
void CCannon::Init()
{
	gravity = weaponDef->myGravity==0 ? mapInfo->map.gravity : -(weaponDef->myGravity);
	highTrajectory = weaponDef->highTrajectory == 1;
	if(highTrajectory){
		maxPredict=projectileSpeed*2/-gravity;
		minPredict=projectileSpeed*1.41f/-gravity;
	} else {
		maxPredict=projectileSpeed*1.41f/-gravity;
	}
	CWeapon::Init();

	UpdateRange(range);
}
Esempio n. 18
0
//
// ICListBox::DrawSelf
//
void ICListBox::DrawSelf(PaintInfo &pi)
{
    // Sync vars with actual item count
    if (count != container->children.GetCount())
    {
        UpdateRange(FALSE);
    }

    // Reposition all controls
    if (reposition)
    {
        reposition = FALSE;

        SetupCellSize();
        UpdateRange(FALSE);
    }

    // Redraw background
    DrawCtrlBackground(pi, GetTexture());

    // Redraw frame
    DrawCtrlFrame(pi);
}
Esempio n. 19
0
OP_STATUS
DOM_WindowSelection::GetBoundaryNode(DOM_Node *&node, BOOL anchor)
{
	node = NULL;
	RETURN_IF_ERROR(UpdateRange());

	if (range)
	{
		DOM_Range::BoundaryPoint anchorBP, focusBP;
		GetAnchorAndFocus(anchorBP, focusBP);
		node = anchor ? anchorBP.node : focusBP.node;
	}

	return OpStatus::OK;
}
Esempio n. 20
0
OP_STATUS
DOM_WindowSelection::GetBoundaryOffset(unsigned &offset, BOOL anchor)
{
	offset = 0;
	RETURN_IF_ERROR(UpdateRange());

	if (range)
	{
		DOM_Range::BoundaryPoint anchorBP, focusBP;
		GetAnchorAndFocus(anchorBP, focusBP);
		offset = anchor ? anchorBP.offset : focusBP.offset;
	}

	return OpStatus::OK;
}
Esempio n. 21
0
// Sets up displacement_modes_ with the top few modes of the perpendicular
// distance of each blob from the given direction vector, after rounding.
void BaselineRow::SetupBlobDisplacements(const FCOORD& direction) {
  // Set of perpendicular displacements of the blob bottoms from the required
  // baseline direction.
  GenericVector<double> perp_blob_dists;
  displacement_modes_.truncate(0);
  // Gather the skew-corrected position of every blob.
  double min_dist = MAX_FLOAT32;
  double max_dist = -MAX_FLOAT32;
  BLOBNBOX_IT blob_it(blobs_);
  bool debug = false;
  for (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {
    BLOBNBOX* blob = blob_it.data();
    const TBOX& box = blob->bounding_box();
#ifdef kDebugYCoord
    if (box.bottom() < kDebugYCoord && box.top() > kDebugYCoord) debug = true;
#endif
    FCOORD blob_pos((box.left() + box.right()) / 2.0f,
                    blob->baseline_position());
    double offset = direction * blob_pos;
    perp_blob_dists.push_back(offset);
    if (debug) {
      tprintf("Displacement %g for blob at:", offset);
      box.print();
    }
    UpdateRange(offset, &min_dist, &max_dist);
  }
  // Set up a histogram using disp_quant_factor_ as the bucket size.
  STATS dist_stats(IntCastRounded(min_dist / disp_quant_factor_),
                   IntCastRounded(max_dist / disp_quant_factor_) + 1);
  for (int i = 0; i < perp_blob_dists.size(); ++i) {
    dist_stats.add(IntCastRounded(perp_blob_dists[i] / disp_quant_factor_), 1);
  }
  GenericVector<KDPairInc<float, int> > scaled_modes;
  dist_stats.top_n_modes(kMaxDisplacementsModes, &scaled_modes);
  if (debug) {
    for (int i = 0; i < scaled_modes.size(); ++i) {
      tprintf("Top mode = %g * %d\n",
              scaled_modes[i].key * disp_quant_factor_, scaled_modes[i].data);
    }
  }
  for (int i = 0; i < scaled_modes.size(); ++i)
    displacement_modes_.push_back(disp_quant_factor_ * scaled_modes[i].key);
}
Esempio n. 22
0
//
// ICListBox::ICListBox
//
ICListBox::ICListBox(IControl *parent)
    : IControl(parent),
      listBoxStyle(0),
      selectedVar(NULL),
      indexVar(NULL),
      slider(NULL),
      itemConfig(NULL),
      sliderCfg(NULL),
      desiredTop(-1),
      reposition(FALSE),
      cellPad(2),
      updateVar(FALSE)
{
    // Default color
    SetColorGroup(IFace::data.cgClient);

    // Default styles
    controlStyle |= (STYLE_DROPSHADOW | STYLE_TABSTOP);

    // Default list bos styles
    listBoxStyle |= STYLE_VSLIDER;

    // Hook mouse click messages
    inputHook = TRUE;

    // Create container control
    container = new ListContainer(this);

    // Default sounds
    soundClick    = IFace::Sound::MENU_POPUP;
    soundDblClick = IFace::Sound::MENU_COMMAND;

    // Create local variables
    topVar = new IFaceVar(this, VarSys::CreateInteger(DynVarName("top"), 0, VarSys::DEFAULT, &top));
    VarSys::CreateInteger(DynVarName("count"), 0, VarSys::DEFAULT, &count);
    VarSys::CreateInteger(DynVarName("vis"), 0, VarSys::DEFAULT, &vis);

    // Update the range
    UpdateRange(TRUE);

    ClearSelected(FALSE);
}
Esempio n. 23
0
/* virtual */ ES_GetState
DOM_WindowSelection::GetName(OpAtom property_name, ES_Value *value, ES_Runtime *origining_runtime)
{
	switch (property_name)
	{
	case OP_ATOM_anchorNode:
	case OP_ATOM_focusNode:
		{
			DOM_Node *node;
			GET_FAILED_IF_ERROR(GetBoundaryNode(node, property_name == OP_ATOM_anchorNode));
			DOMSetObject(value, node);
		}
		return GET_SUCCESS;

	case OP_ATOM_anchorOffset:
	case OP_ATOM_focusOffset:
		{
			unsigned offset;
			GET_FAILED_IF_ERROR(GetBoundaryOffset(offset, property_name == OP_ATOM_anchorOffset));
			DOMSetNumber(value, offset);
		}
		return GET_SUCCESS;

	case OP_ATOM_isCollapsed:
		{
			BOOL is_collapsed;
			GET_FAILED_IF_ERROR(IsCollapsed(is_collapsed));
			DOMSetBoolean(value, is_collapsed);
		}
		return GET_SUCCESS;

	case OP_ATOM_rangeCount:
		GET_FAILED_IF_ERROR(UpdateRange());
		DOMSetNumber(value, range ? 1 : 0);
		return GET_SUCCESS;

	default:
		return GET_FAILED;
	}
}
Esempio n. 24
0
// Finds the sample for each font, class pair that has least maximum
// distance to all the other samples of the same font, class.
// OrganizeByFontAndClass must have been already called.
    void TrainingSampleSet::ComputeCanonicalSamples(const IntFeatureMap &map,
                                                    bool debug) {
        ASSERT_HOST(font_class_array_ != NULL);
        IntFeatureDist f_table;
        if (debug) tprintf("feature table size %d\n", map.sparse_size());
        f_table.Init(&map);
        int worst_s1 = 0;
        int worst_s2 = 0;
        double global_worst_dist = 0.0;
        // Compute distances independently for each font and char index.
        int font_size = font_id_map_.CompactSize();
        for (int font_index = 0; font_index < font_size; ++font_index) {
            int font_id = font_id_map_.CompactToSparse(font_index);
            for (int c = 0; c < unicharset_size_; ++c) {
                int samples_found = 0;
                FontClassInfo &fcinfo = (*font_class_array_)(font_index, c);
                if (fcinfo.samples.size() == 0 ||
                    (kTestChar >= 0 && c != kTestChar)) {
                    fcinfo.canonical_sample = -1;
                    fcinfo.canonical_dist = 0.0f;
                    if (debug) tprintf("Skipping class %d\n", c);
                    continue;
                }
                // The canonical sample will be the one with the min_max_dist, which
                // is the sample with the lowest maximum distance to all other samples.
                double min_max_dist = 2.0;
                // We keep track of the farthest apart pair (max_s1, max_s2) which
                // are max_max_dist apart, so we can see how bad the variability is.
                double max_max_dist = 0.0;
                int max_s1 = 0;
                int max_s2 = 0;
                fcinfo.canonical_sample = fcinfo.samples[0];
                fcinfo.canonical_dist = 0.0f;
                for (int i = 0; i < fcinfo.samples.size(); ++i) {
                    int s1 = fcinfo.samples[i];
                    const GenericVector <int> &features1 = samples_[s1]->indexed_features();
                    f_table.Set(features1, features1.size(), true);
                    double max_dist = 0.0;
                    // Run the full squared-order search for similar samples. It is still
                    // reasonably fast because f_table.FeatureDistance is fast, but we
                    // may have to reconsider if we start playing with too many samples
                    // of a single char/font.
                    for (int j = 0; j < fcinfo.samples.size(); ++j) {
                        int s2 = fcinfo.samples[j];
                        if (samples_[s2]->class_id() != c ||
                            samples_[s2]->font_id() != font_id ||
                            s2 == s1)
                            continue;
                        GenericVector <int> features2 = samples_[s2]->indexed_features();
                        double dist = f_table.FeatureDistance(features2);
                        if (dist > max_dist) {
                            max_dist = dist;
                            if (dist > max_max_dist) {
                                max_s1 = s1;
                                max_s2 = s2;
                            }
                        }
                    }
                    // Using Set(..., false) is far faster than re initializing, due to
                    // the sparseness of the feature space.
                    f_table.Set(features1, features1.size(), false);
                    samples_[s1]->set_max_dist(max_dist);
                    ++samples_found;
                    if (max_dist < min_max_dist) {
                        fcinfo.canonical_sample = s1;
                        fcinfo.canonical_dist = max_dist;
                    }
                    UpdateRange(max_dist, &min_max_dist, &max_max_dist);
                }
                if (max_max_dist > global_worst_dist) {
                    // Keep a record of the worst pair over all characters/fonts too.
                    global_worst_dist = max_max_dist;
                    worst_s1 = max_s1;
                    worst_s2 = max_s2;
                }
                if (debug) {
                    tprintf("Found %d samples of class %d=%s, font %d, "
                                    "dist range [%g, %g], worst pair= %s, %s\n",
                            samples_found, c, unicharset_.debug_str(c).string(),
                            font_index, min_max_dist, max_max_dist,
                            SampleToString(*samples_[max_s1]).string(),
                            SampleToString(*samples_[max_s2]).string());
                }
            }
        }
        if (debug) {
            tprintf("Global worst dist = %g, between sample %d and %d\n",
                    global_worst_dist, worst_s1, worst_s2);
            Pix *pix1 = DebugSample(unicharset_, samples_[worst_s1]);
            Pix *pix2 = DebugSample(unicharset_, samples_[worst_s2]);
            pixOr(pix1, pix1, pix2);
            pixWrite("worstpair.png", pix1, IFF_PNG);
            pixDestroy(&pix1);
            pixDestroy(&pix2);
        }
    }
Esempio n. 25
0
void SG_TextArea::SetVisibleLines(int numlns) {  // Depricated!
  texture[state].SetTextVisibleSize(numlns);
  UpdateRange();
}
Esempio n. 26
0
void SG_TextArea::SetVisibleSize(float xs, float ys) {
  texture[state].SetTextVisibleSize(ys, xs);
  UpdateRange();
}
Esempio n. 27
0
void SG_TextArea::SetFontSize(int sz) {
  texture[state].SetTextFontSize(sz);
  UpdateRange();
}
Esempio n. 28
0
void SG_TextArea::SetText(const string &mes) {
  message = mes;
  texture[state].SetText(message);
  UpdateRange();
}
Esempio n. 29
0
//This is for item stats that are part of the item
void Equipable::SetStats(bool Remove)
{
	int RemoveStat;

	if (Remove)
		RemoveStat = -1;
	else
		RemoveStat = 1;

	if (Remove)
	{
		for(int ID=0;ID<m_MaxID;ID++)
		{
			// Loop and remove all the Stats from the ship
			m_Player->m_Stats.DelStat(m_StatIDs[ID]);
		}
	}

	m_MaxID = 0;


    switch(m_Type)
    {
    case EQUIP_WEAPON:
        /* We dont have ammot at this point anyways */
		UpdateRange();

        /* Removes all of the itemstate flags */
        m_AuxEquipItem->SetItemState(m_AuxEquipItem->GetItemState() & 0xFFFFFF00);

        if (m_UsesAmmo && m_AuxAmmoItem->GetItemTemplateID() < 0)
        {
            AddItemStateFlag(ITEM_STATE_NO_AMMO);
			AddItemStateFlag(ITEM_STATE_NO_TARGETING);
		}

        break;

    case EQUIP_DEVICE:
		EquipDevice(!Remove);

        m_AuxEquipItem->SetTargetRange((float)m_ItemInstance.EffectRange);
        break;

    case EQUIP_SHIELD:
        {
			// Dont remove stats from the Stats YET
			if (!Remove)
			{
				// Set BaseValue Stats
				m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_SHIELD_RECHARGE, m_ItemInstance.ShieldRecharge, "ITEM_VALUE");
				m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_SHIELD, m_ItemInstance.ShieldCap, "ITEM_VALUE");
				// ----

				float StartValue = m_Player->GetShield() / (m_Player->m_Stats.GetStat(STAT_SHIELD) / m_Player->ShipIndex()->GetMaxShield());
				m_Player->ShipIndex()->SetMaxShield(m_Player->m_Stats.GetStat(STAT_SHIELD));

				if (StartValue > 1.0f)
				{
					StartValue = 1.0f;
				}

    			float ChargeRate = (m_Player->m_Stats.GetStat(STAT_SHIELD_RECHARGE) / m_Player->m_Stats.GetStat(STAT_SHIELD)) / 1000.0f;
				unsigned long EndTime = GetNet7TickCount() + (unsigned long)((1.0f - StartValue) / ChargeRate);

				m_Player->ShieldUpdate(EndTime, ChargeRate, StartValue);

				m_AuxEquipItem->SetTargetRange((float)m_ItemInstance.EffectRange);
			}
        }
        break;

    case EQUIP_REACTOR:
        {
			// Dont remove stats from the Stats YET
			if (!Remove)
			{
				// Set BaseValue Stats
				m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_ENERGY, m_ItemInstance.ReactorCap, "ITEM_VALUE");
				m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_ENERGY_RECHARGE, m_ItemInstance.ReactorRecharge, "ITEM_VALUE");
				// ----

				float MaxEnergy = m_Player->m_Stats.GetStat(STAT_ENERGY);
				float RechargeEnergy = m_Player->m_Stats.GetStat(STAT_ENERGY_RECHARGE);


				float StartValue = m_Player->GetEnergy() / (MaxEnergy / m_Player->ShipIndex()->GetMaxEnergy());
				m_Player->ShipIndex()->SetMaxEnergy(MaxEnergy);

				if (StartValue > 1.0f)
				{
					StartValue = 1.0f;
				}

				float ChargeRate = (RechargeEnergy / MaxEnergy) / 1000.0f;
				unsigned long EndTime = GetNet7TickCount() + (unsigned long)((1.0f - StartValue) / ChargeRate);

				m_Player->EnergyUpdate(EndTime, ChargeRate, StartValue);

				m_AuxEquipItem->SetTargetRange((float)m_ItemInstance.EffectRange);
			}
        }
        break;

    case EQUIP_ENGINE:
		float Speed = (float)m_ItemInstance.EngineSpeed;
		float Acceleration = 100.0f;

		// Dont remove stats from the Stats YET
		if (!Remove)
		{
			// Set BaseValue Stats
			m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_IMPULSE, Speed, "ITEM_VALUE");
			m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_WARP, (float)m_ItemInstance.EngineWarpSpeed, "ITEM_VALUE");
			m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_SIGNATURE, (float)m_ItemInstance.EngineSignature, "ITEM_VALUE");

			if (m_Player->m_Stats.GetStat(STAT_ACCELERATION) == 0)
			{
				m_StatIDs[m_MaxID++] = m_Player->m_Stats.SetStat(STAT_BASE_VALUE, STAT_ACCELERATION, Acceleration);
			}

			m_Player->ShipIndex()->CurrentStats.SetVisibility((s32)m_Player->m_Stats.GetStat(STAT_SIGNATURE));
			m_Player->ShipIndex()->CurrentStats.SetSpeed((s32)m_Player->m_Stats.GetStat(STAT_IMPULSE));
			m_Player->ShipIndex()->CurrentStats.SetWarpSpeed((s32)m_Player->m_Stats.GetStat(STAT_WARP));

			/* Should create a method for this in player */
			m_Player->ShipIndex()->SetMaxSpeed(m_Player->m_Stats.GetStat(STAT_IMPULSE));
			m_Player->ShipIndex()->SetMinSpeed(-m_Player->m_Stats.GetStat(STAT_IMPULSE)/2);
			m_Player->ShipIndex()->SetAcceleration(m_Player->m_Stats.GetStat(STAT_ACCELERATION));

			m_AuxEquipItem->SetTargetRange((float)m_ItemInstance.EffectRange);
		}

        break;
    }

	EquipEffects(RemoveStat);

	/* If this is an empty item, disable the slot */
    if (m_AuxEquipItem->GetItemTemplateID() < 0)
    {
        AddItemStateFlag(ITEM_STATE_DISABLED);
    }
}
Esempio n. 30
0
int FindEnds (StisInfo4 *sts, double length,
	double *v, short *qv, int nv,
	double crpix, double cdelt, int verbose,
	double *shift) {

/* arguments:
StisInfo4 *sts     i: calibration switches and info
double length      i: width of slit in spatial direction
double *v          i: array to be cross correlated with template of aperture
short *qv          i: data quality flags for v
int nv             i: size of v and qv arrays
double crpix       i: reference pixel in input data (zero indexed)
double cdelt       i: degrees per pixel
int verbose        i: print individual shifts?
double *shift      o: the shift, in pixels
*/

	int status;

	double scale;		/* arcseconds per pixel */
	double slit_end;	/* pixel location of end of slit */
	double sum;		/* for averaging the shifts */
	int nedges;		/* number of edges included in average */
	double locn0, locn;	/* estimated and actual location of an edge */
	double c7_shift;	/* shift in units of calstis7 pixels */
	double min_shift, max_shift;	/* min & max shifts */

	int FindEdge (StisInfo4 *,
		double *, short *, int, int, double, double *);

	scale = cdelt * ARCSEC_PER_DEGREE;

	/* Get the pixel location of the lower (or left) end of the slit. */
	slit_end = crpix - length / scale / 2.;

	/* Find each edge of the slit, and average the shifts. */
	sum = 0.;
	nedges = 0;

	/* lower edge of slit */
	locn0 = slit_end;
	if ((status = FindEdge (sts, v, qv, nv, LOW_TO_HIGH, locn0, &locn))) {
	    if (status == NO_GOOD_DATA)		/* not fatal yet */
		status = 0;
	    else
		return (status);		/* serious error */
	    if (verbose)
		printf ("         shift of lower edge is undetermined\n");
	} else {
	    nedges++;
	    sum += (locn - locn0);
	    if (verbose)
		printf ("         shift of lower edge is %.2f\n",
			(locn - locn0));
	    UpdateRange (nedges, locn - locn0, &min_shift, &max_shift);
	}

	/* upper edge of slit */
	locn0 = slit_end + length / scale;
	if ((status = FindEdge (sts, v, qv, nv, HIGH_TO_LOW, locn0, &locn))) {
	    if (status == NO_GOOD_DATA)
		status = 0;
	    else
		return (status);
	    if (verbose)
		printf ("         shift of upper edge is undetermined\n");
	} else {
	    nedges++;
	    sum += (locn - locn0);
	    if (verbose)
		printf ("         shift of upper edge is %.2f\n",
			(locn - locn0));
	    UpdateRange (nedges, locn - locn0, &min_shift, &max_shift);
	}

	if (CheckRange (nedges, min_shift, max_shift)) {
	    *shift = 0.;
	    return (NO_GOOD_DATA);
	}

	c7_shift = sum / (double)nedges;

	/* Convert the shift from calstis7 pixels to pixels in raw image. */
	*shift = c7_shift;

	return (0);
}