Example #1
0
void CalcFullViewWindowSize( LPRECT lpWindowRect, LPRECT lpFileRect,
                              LFIXED FileRate, int npix, int nlin, int x,
                              int y, BOOL fHasRulers, BOOL fClipToImage )
/************************************************************************/
{
int dx, dy, sx, sy, rs, iImageWidth, iImageHeight, iWidth, iHeight;
LFIXED DispRate;
int minsize;

// normal window - to goal is to size the window to fit the view
// If FileRate == 0 or 1, then we make the window as big as possible
// for the FileRect provided.  If FileRate != 0, then we make the
// the window as big as possible to fit the image at that FileRate.
// If the fClipToImage flag and FileRate == 0, then we do not let
// the FileRate go over 100%.  This is used for a caller who wants
// to display the image pixel for pixel, if possible.
if (x < 0 || y < 0)
	GetDocumentPosition(&x, &y);

dx = 2 * GetSystemMetrics(SM_CXFRAME);
dy = GetSystemMetrics(SM_CYCAPTION) + (2*GetSystemMetrics(SM_CYFRAME)) - 1;

// get size of scrollbars and rulers for use later
GetScrollBarSize(&sx, &sy);
rs = GetRulerSize();

// determine maximum area for window to occupy
if (IsIconic(PictPubApp.Get_hWndAstral()))
    *lpWindowRect = rClient;
else
    GetClientRect(PictPubApp.Get_hClientAstral(), lpWindowRect);
lpWindowRect->top = y;
lpWindowRect->left = x;
lpWindowRect->right -= dx;
lpWindowRect->bottom -= (dy + GetSystemMetrics(SM_CYFRAME));

// start with this maximum Client Area size
minsize = MIN_WINDOW_SIZE+rs;
iWidth = RectWidth(lpWindowRect);
if ( iWidth < minsize )
    iWidth = minsize;
iHeight = RectHeight(lpWindowRect);
if ( iHeight < minsize )
    iHeight = minsize;

// If we already have a FileRate, calculate new size of window
// based on the image size
if (FileRate > TINYRATE)
    {
    // calculate size of area for total image at this
    // FileRate
    DispRate = FGET(FUNITY, FileRate);
    iImageWidth = FMUL(npix, DispRate);
    iImageHeight = FMUL(nlin, DispRate);

    // add in additional space for rulers if necessary
    if (fHasRulers)
        {
        iImageWidth += rs;
        iImageHeight += rs;
        }
    if (iImageWidth > iWidth && iImageHeight < iHeight)
        iImageHeight += sy;
    if (iImageHeight > iHeight && iImageWidth < iWidth)
        iImageWidth += sx;

    // see if we don't need the total width
    // otherwise, use the maximum
    if (iImageWidth < iWidth)
        iWidth = iImageWidth;
    // see if we don't need the total height
    // otherwise, use the maximum
    if (iImageHeight < iHeight)
        iHeight = iImageHeight;
    }
// if we have no FileRate, then somebody wants a specific
// FileRect, figure out how big the window needs to be and
// whether we need rulers
else
    {
    // get width and height of area to be displayed
    iImageWidth = RectWidth(lpFileRect);
    iImageHeight = RectHeight(lpFileRect);

    // reduce the maximum area if we have rulers
    if (fHasRulers)
        {
        iWidth -= rs;
        iHeight -= rs;
        }

    // reduce the maximum area if we need scrollbars
    if (lpFileRect->left != 0 ||
        lpFileRect->right != npix-1 ||
        lpFileRect->top != 0 ||
        lpFileRect->bottom != nlin-1)
        {
        iWidth -= sx;
        iHeight -= sy;
        }

    // scale maximum client area size (not including rulers and
    // scrollbars) to fit aspect ratio of FileRect
    DispRate = ScaleToFit(&iWidth, &iHeight, iImageWidth, iImageHeight);

    // if caller wants to clip to hires to achieve 100% view,
    // clip.  But only if hires is smaller
    if (iImageWidth <= iWidth && iImageHeight <= iHeight && fClipToImage)
        {
        iWidth = iImageWidth;
        iHeight = iImageHeight;
        }

    // add ruler size back into client area
    if (fHasRulers)
        {
        iWidth += rs;
        iHeight += rs;
        }

    // add scrollbar size back into client area
    if (lpFileRect->left != 0 ||
        lpFileRect->right != npix-1 ||
        lpFileRect->top != 0 ||
        lpFileRect->bottom != nlin-1)
        {
        iWidth += sx;
        iHeight += sy;
        }
    }
// Calculate new window size based on iWidth and iHeight */
lpWindowRect->right = lpWindowRect->left + iWidth + dx - 1;
lpWindowRect->bottom = lpWindowRect->top + iHeight + dy - 1;
}
void CoreferenceDocumentNumeric::Initialize(
  const CoreferenceDictionary &dictionary,
  CoreferenceDocument* instance,
  bool add_gold_mentions) {
  Clear();

  // True if document is a conversation.
  conversation_ = instance->is_conversation();

  // Temporary dictionary to hold coreference span names.
  std::map<std::string, int> span_names;
  sentences_.resize(instance->GetNumSentences());
  for (int i = 0; i < instance->GetNumSentences(); ++i) {
    CoreferenceSentence *sentence_instance = instance->GetSentence(i);
    CoreferenceSentenceNumeric *sentence = new CoreferenceSentenceNumeric;
    sentence->Initialize(dictionary, sentence_instance, add_gold_mentions,
                         &span_names);
    sentences_[i] = sentence;
  }

  ComputeGlobalWordPositions(instance);

  // Compute coreference information.
  Alphabet coreference_labels;
  for (int i = 0; i < instance->GetNumSentences(); ++i) {
    CoreferenceSentence *sentence_instance = instance->GetSentence(i);
    const std::vector<NamedSpan*> &coreference_spans =
      sentence_instance->GetCoreferenceSpans();
    for (int k = 0; k < coreference_spans.size(); ++k) {
      const std::string &label = coreference_spans[k]->name();
      int id = coreference_labels.Insert(label);
      int start = GetDocumentPosition(i, coreference_spans[k]->start());
      int end = GetDocumentPosition(i, coreference_spans[k]->end());
      NumericSpan *span = new NumericSpan(start, end, id);
      coreference_spans_.push_back(span);
    }
  }

  // Compute mention information.
  // Note: mentions are owned by CoreferenceSentenceNumeric.
  // TODO(atm): maybe copy the sentences' mentions?
  mentions_.clear();
  Alphabet mention_speakers;
  Alphabet mention_head_strings;
  Alphabet mention_phrase_strings;
  Alphabet mention_word_strings;
  for (int i = 0; i < sentences_.size(); ++i) {
    CoreferenceSentenceNumeric *sentence = sentences_[i];
    const vector<Mention*> &mentions = sentence->GetMentions();
    mentions_.insert(mentions_.end(), mentions.begin(),
                     mentions.end());
    for (int j = 0; j < mentions.size(); ++j) {
      int offset = GetDocumentPosition(i, 0);
      mentions[j]->set_offset(offset);
      //LOG(INFO) << "Sentence " << i << " -> Offset " << offset;

      int sentence_index = -1;
      int word_sentence_index = -1;
      // Pass offset+1 since the sentence starts with a special symbol which
      // is not accounted for in the document global positions.
      FindSentencePosition(offset + 1, &sentence_index, &word_sentence_index);
      mentions[j]->set_sentence_index(sentence_index);
      //LOG(INFO) << "* Sentence " << sentence_index
      //          << " Word " << word_sentence_index;
      CHECK_EQ(word_sentence_index, 1); // First word in the sentence.
      //int start = GetDocumentPosition(i, mentions[j]->start());
      //int end = GetDocumentPosition(i, mentions[j]->end());
      //mentions[j]->set_head_index(mentions[j]->head_index()
      //                            - mentions[j]->start() + start);
      //mentions[j]->set_global_start(start);
      //mentions[j]->set_global_end(end);

      // Set head and phrase string IDs.
      CoreferenceSentence *sentence_instance =
        instance->GetSentence(sentence_index);

      std::string speaker;
      mentions[j]->GetSpeaker(sentence_instance, &speaker);
      int speaker_id = mention_speakers.Insert(speaker);
      mentions[j]->set_speaker_id(speaker_id);

      std::string phrase_string;
      mentions[j]->GetPhraseString(sentence_instance, &phrase_string);
      int phrase_string_id = mention_phrase_strings.Insert(phrase_string);
      mentions[j]->set_phrase_string_id(phrase_string_id);

      std::string head_string;
      mentions[j]->GetHeadString(sentence_instance, &head_string);
      int head_string_id = mention_head_strings.Insert(head_string);
      mentions[j]->set_head_string_id(head_string_id);

      std::vector<int> all_word_string_ids;
      for (int k = mentions[j]->start(); k <= mentions[j]->end(); ++k) {
        const std::string &word_string = sentence_instance->GetForm(k);
        int word_string_id = mention_word_strings.Insert(word_string);
        all_word_string_ids.push_back(word_string_id);
      }
      mentions[j]->set_all_word_string_ids(all_word_string_ids);
    }
  }

  ComputeEntityClusters();

#if 1
  LOG(INFO) << "Found " << coreference_spans_.size()
    << " gold mentions organized into "
    << coreference_labels.size() << " entities.";
  LOG(INFO) << "Total mentions: " << mentions_.size();
#endif

  // GenerateMentions()?
}