示例#1
0
// Manage the selection list when there is a new current point selected
void imodSelectionNewCurPoint(ImodView *vi, Imod *imod, Iindex indSave, 
                              int controlDown)
{
  Iindex *indp;
  bool contourless;

  // If ctrl-select, then manage selection list
  if (controlDown) {
    contourless = indSave.object >= 0 && !vi->imod->obj[indSave.object].contsize && 
      vi->imod->obj[indSave.object].meshsize;
    
    // First add previous point if list is empty
    if (!ilistSize(vi->selectionList) && (indSave.contour >= 0 || contourless))
      imodSelectionListAdd(vi, indSave);
    
    // If point not on list, add it.  If point is on list, then remove
    // it and pop current point back to last item on list
    if (imodSelectionListQuery(vi, imod->cindex.object, imod->cindex.contour) < -1) {
      imodSelectionListAdd(vi, imod->cindex);
    } else {
      imodSelectionListRemove(vi, imod->cindex.object, imod->cindex.contour);
      if (ilistSize(vi->selectionList)) {
        indp = (Iindex *)ilistItem(vi->selectionList, ilistSize(vi->selectionList) - 1); 
        imod->cindex = *indp;
      }
    }
  } else

    // But if Ctrl not down, clear out the list
    imodSelectionListClear(vi);
}
示例#2
0
文件: iimage.c 项目: imod-mirror/IMOD
/*!
 * Returns the open ImodImageFile that has [fp] as its {fp} member.
 */
ImodImageFile *iiLookupFileFromFP(FILE *fp)
{
  ImodImageFile **listPtr;
  int i = findFileInList(NULL, fp);
  if (i < 0)
    return NULL;
  listPtr = (ImodImageFile **)ilistItem(sOpenedFiles, i);
  return *listPtr;
}
示例#3
0
void ImodvOlist::nameChanged(const QString &str)
{
  IobjGroup *group = (IobjGroup *)ilistItem(Imodv->imod->groupList, 
                                            Imodv->imod->curObjGroup);
  if (!group)
    return;
  strncpy(&group->name[0], LATIN1(str), OBJGRP_STRSIZE);
  group->name[OBJGRP_STRSIZE - 1] = 0x00;
}
示例#4
0
文件: iimage.c 项目: imod-mirror/IMOD
/*
 * Find a file either by its iiFile or its fp entry 
 */
static int findFileInList(ImodImageFile *iiFile, FILE *fp)
{
  int i;
  ImodImageFile **listPtr;
  for (i = 0; i < ilistSize(sOpenedFiles); i++) {
    listPtr = (ImodImageFile **)ilistItem(sOpenedFiles, i);
    if ((iiFile && *listPtr == iiFile) || (fp && (*listPtr)->fp == fp)) {
      return i;
    }
  }
  return -1;
}
示例#5
0
// If object-contour is on selection list, return point number; otherwise -2
// If co < 0, simply tests whether object is on selection list
int imodSelectionListQuery(ImodView *vi, int ob, int co)
{
  Iindex *index;
  int i;

  for (i = 0; i < ilistSize(vi->selectionList); i++) {
    index = (Iindex *)ilistItem(vi->selectionList, i);
    if (index->object == ob && (index->contour == co || co < 0)) {
      imodTrace('S', "Query returns %d", index->point);
      return index->point;
    }
  }
  return -2;
}
示例#6
0
// Remove the given obj, cont from the selection list if it is on it
void imodSelectionListRemove(ImodView *vi, int ob, int co)
{
  Iindex *index;
  int i;

  for (i = 0; i < ilistSize(vi->selectionList); i++) {
    index = (Iindex *)ilistItem(vi->selectionList, i);
    if (index->object == ob && index->contour == co) {
      ilistRemove(vi->selectionList, i);
      imodTrace('S', "Removing item %d, leaves %d", i, ilistSize(vi->selectionList));
      return;
    }
  }
}
示例#7
0
/*
 * Returns 1 if all contours in the remnant list are on selection list
 */
int VertBufManager::checkSelectedAreRemnants(VertBufData *vbd, int obNum)
{
  Iindex *index;
  if (Imodv->imod->cindex.object == obNum && Imodv->imod->cindex.contour >= 0 &&
      !numberInList(Imodv->imod->cindex.contour, vbd->remnantIndList, vbd->numRemnant, 0))
    return 0;
  for (int i = 0; i < ilistSize(Imodv->vi->selectionList); i++) {
    index = (Iindex *)ilistItem(Imodv->vi->selectionList, i);
    if (index->object == obNum && index->contour >= 0 &&
        !numberInList(index->contour, vbd->remnantIndList, vbd->numRemnant, 0))
      return 0;
  }
  return 1;
}
示例#8
0
void ImodvOlist::toggleGroupSlot(int ob)
{
  int index;
  bool state;
  IobjGroup *group = (IobjGroup *)ilistItem(Imodv->imod->groupList, 
                                            Imodv->imod->curObjGroup);
  if (!group)
    return;
  index = objGroupLookup(group, ob);
  state = groupButtons[ob]->isChecked();
  if (state && index < 0)
    objGroupAppend(group, ob);
  else if (!state && index >= 0)
    ilistRemove(group->objList, index);
}
示例#9
0
/*
 * Set Angles clicked for table, set the angles from the current row
 */
void AngleDialog::setAnglesClicked()
{
    int row = mTable->currentRow();
    Ilist *saved = mApp->getSavedList();
    SavedDefocus *item;
    QString str;
    if (row < 0 || row >= ilistSize(saved))
        return;
    item = (SavedDefocus *)ilistItem(saved, row);
    str.sprintf("%.2f",item->lAngle);
    mLowAngleEdit->setText(str);
    str.sprintf("%.2f",item->hAngle);
    mHighAngleEdit->setText(str);
    qApp->processEvents();
    anglesSet(0);
}
示例#10
0
文件: iimage.c 项目: imod-mirror/IMOD
/*!
 * Reopen a file that has already been opened and analyzed.  Returns 1 if the file is
 * already open or 2 for other errors.
 */
int  iiReopen(ImodImageFile *inFile)
{
  IIFileCheckFunction *checkFunc;
  int i;

  if (!inFile)
    return -1;
  if (inFile->fp)
    return 1;
  if (!inFile->fmode[0])
    strncpy(inFile->fmode, "rb+", 3);
  if (inFile->reopen) {
    if ((*inFile->reopen)(inFile))
      return 2;
    inFile->state = IISTATE_READY;
    addToOpenedList(inFile);
    return 0;
  }

  inFile->fp = fopen(inFile->filename, inFile->fmode);
  if (!inFile->fp)
    return 2;

  /* Add back to opened list: failure is not an error because FP-based programs don't
     use iiReopen */
  addToOpenedList(inFile);

  if (inFile->state != IISTATE_NOTINIT) {
    inFile->state = IISTATE_READY;
    return 0;
  }

  /* If the file is not initted yet, treat it as unknown and deal with from scratch */
  inFile->format = IIFILE_UNKNOWN;
  for (i = 0; i < ilistSize(sCheckList); i++) {
    checkFunc = (IIFileCheckFunction *)ilistItem(sCheckList, i);
    if (!(*checkFunc)(inFile)) {
      inFile->state = IISTATE_READY;
      return 0;
    }
  }
  return -1;
}
示例#11
0
/*
 * Update all the entries in the table
 */
void AngleDialog::updateTable()
{
    Ilist *saved = mApp->getSavedList();
    SavedDefocus *item;
    QString str;
    int row, j;
    for (row = 0; row < ilistSize(saved); row++) {

        // Add a row if needed
        if (row + 1 > mTable->rowCount()) {
            mTable->insertRow(row);
            mTable->setRowHeight(row, mTable->fontMetrics().height() + 3);
            for (j = 0; j < 4; j++) {
                QTableWidgetItem *witem = new QTableWidgetItem();
                witem->setTextAlignment(Qt::AlignRight);
                mTable->setItem(row, j, witem);
            }
        }

        // Load the data
        item = (SavedDefocus *)ilistItem(saved, row);
        str.sprintf("%.2f", item->lAngle);
        mTable->item(row,0)->setText(str);
        str.sprintf("%.2f", item->hAngle);
        mTable->item(row,1)->setText(str);
        str.sprintf("%.2f", (item->lAngle + item->hAngle) / 2.);
        mTable->item(row,2)->setText(str);
        str.sprintf("%.2f", item->defocus);
        mTable->item(row,3)->setText(str);
    }

    // Get rid of extra rows (hope it deletes the items)
    for (j = mTable->rowCount() - 1; j >= row; j--)
        mTable->removeRow(j);
    mDeleteButton->setEnabled(row > 0);
    mReturnButton->setEnabled(row > 0);
    mToFileButton->setEnabled(row > 0);
    if (mTable->currentRow() < 0 && mTable->rowCount())
        mTable->setCurrentCell(0, 0);
}
示例#12
0
/*
 * Adds one item to the defocus list, keeping the list in order and
 * and avoiding duplicate starting and ending view numbers
 */
void addItemToDefocusList(Ilist *lstSaved, SavedDefocus toSave)
{
  SavedDefocus *item;
  int i, matchInd = -1, insertInd = 0;

  // Look for match or place to insert
  for (i = 0; i < ilistSize(lstSaved); i++) {
    item = (SavedDefocus *)ilistItem(lstSaved, i);
    if (item->startingSlice == toSave.startingSlice &&
        item->endingSlice == toSave.endingSlice) {
      matchInd = i;
      *item = toSave;
      break;
    }
    if (item->lAngle + item->hAngle <= toSave.lAngle + toSave.hAngle)
      insertInd = i + 1;
  }

  // If no match, now insert
  if (matchInd < 0 && ilistInsert(lstSaved, &toSave, insertInd))
    exitError("Failed to add item to list of angles and defocuses");
}
示例#13
0
// Add an item to the selection list
void imodSelectionListAdd(ImodView *vi, Iindex newIndex)
{
  int multiObject = 1;    // Placekeeper for possible argument/preference
  Iindex *index;
  int i;

  // Clear list if a different object is given and multiobject not allowed
  if (ilistSize(vi->selectionList) && !multiObject) {
    index = (Iindex *)ilistFirst(vi->selectionList);
    if (index->object != newIndex.object)
      imodSelectionListClear(vi);
  }

  // create list if it does not exist
  if (!vi->selectionList) {
    vi->selectionList = ilistNew(sizeof(Iindex), 4);
    if (!vi->selectionList) 
      return;    // ERROR
  }

  // Look through list to see if contour is already there and update point
  for (i = 0; i < ilistSize(vi->selectionList); i++) {
    index = (Iindex *)ilistItem(vi->selectionList, i);
    if (index->object == newIndex.object && 
        index->contour == newIndex.contour) {
      index->point = newIndex.point;
      imodTrace('S', "update %d %d %d", newIndex.object, newIndex.contour,
        newIndex.point);
      return;
    }
  }

  // Add index to list
  imodTrace('S', "adding %d %d %d", newIndex.object, newIndex.contour, newIndex.point);
  ilistAppend(vi->selectionList, &newIndex);
  dumpSelectionList(vi);
}
示例#14
0
文件: iimage.c 项目: imod-mirror/IMOD
/*!
 * Tries to open an image file with name [filename] and with the fopen mode 
 * [mode] (e.g. "rb"), using the file format check functions on the list.
 * If [filename] is NULL or an empty string, then it assigns stdin to the file
 * pointer.  Returns NULL for error; it and all checking routines should call 
 * b3dError with their error strings.
 */
ImodImageFile *iiOpen(const char *filename, const char *mode)
{
  ImodImageFile *ofile;
  IIFileCheckFunction *checkFunc;
  int i, err = 0;

  /* If the mode contains w for a new file, call the open routine for a default file */
  if (strstr(mode, "w"))
    return iiOpenNew(filename, mode, IIFILE_DEFAULT);

  if ((ofile = iiNew()) == NULL) 
    return NULL;
  if (filename && filename[0])
    ofile->fp = fopen(filename, mode);
  else
    ofile->fp = stdin;

  if (ofile->fp == NULL || initCheckList()) {
    b3dError(stderr, "ERROR: iiOpen - Opening file %s\n", filename);
    iiDelete(ofile);
    return(NULL);
  }
  ofile->format = IIFILE_UNKNOWN;
  ofile->filename = strdup(filename);
  strncpy(ofile->fmode, mode, 3);
    
  /* Try to open the file with each of the check functions in turn 
   * until one succeeds
   */
  for (i = 0; i < ilistSize(sCheckList); i++) {
    checkFunc = (IIFileCheckFunction *)ilistItem(sCheckList, i);

    /* If file was closed and couldn't reopen, bail out */
    if (ofile->fp == NULL) {
      b3dError(stderr, "ERROR: iiOpen - %s could not be reopened\n", filename);
      break;
    }

    if (!(err = (*checkFunc)(ofile))) {
      if (ofile->numVolumes > 1 && !sAllowMultiVolume) {
        b3dError(stderr, "ERROR: iiOpen - %s is an HDF file with multiple volumes and "
                 "cannot be opened by this program or with current options to the "
                 "program\n", filename);
      } else {
        ofile->state = IISTATE_READY;
        if (!addToOpenedList(ofile))
          return ofile;
      }
      iiDelete(ofile);
      return NULL;
    }
    
    if (err != IIERR_NOT_FORMAT)
      break;
  }
  
  if (err == IIERR_NOT_FORMAT)
    b3dError(stderr, "ERROR: iiOpen - %s has unknown format.\n", filename);
  iiDelete(ofile);
  return NULL;
}
示例#15
0
void ImodvOlist::updateGroups(ImodvApp *a)
{
  IobjGroup *group;
  int i, ob, numGroups = ilistSize(a->imod->groupList);
  int curGrp = a->imod->curObjGroup;
  int *objs;
  bool *states;
  bool showChgd = false;
  QString str;
  diaSetSpinMMVal(mGroupSpin, 0, numGroups, curGrp + 1);
  str.sprintf("/%d", numGroups);
  mNumberLabel->setText(str);
  mNameEdit->setEnabled(curGrp >= 0);
  for (i = 1; i < OBJLIST_NUMBUTTONS; i++)
    mButtons[i]->setEnabled(curGrp >= 0);
  if (curGrp < 0) {
    if (grouping) {
      mFrame->hide();
      for (ob = 0; ob < numOolistButtons; ob++)
        groupButtons[ob]->hide();
      mFrame->show();
      adjustFrameSize();
    }
    grouping = false;
    return;
  }
  if (!grouping) {
    mFrame->hide();
    for (ob = 0; ob < numOolistButtons; ob++)
      groupButtons[ob]->show();
    mFrame->show();
    adjustFrameSize();
  }
  grouping = true;

  group = (IobjGroup *)ilistItem(a->imod->groupList, curGrp);
  if (!group)
    return;
  mNameEdit->setText(group->name);
  states = (bool *)malloc(sizeof(bool) * numOolistButtons);
  if (!states)
    return;
  for (ob = 0; ob < numOolistButtons; ob++)
    states[ob] = false;
  objs = (int *)ilistFirst(group->objList);
  if (objs) {
    for (i = 0; i < ilistSize(group->objList); i++)
      if (objs[i] >= 0 && objs[i] < numOolistButtons)
        states[objs[i]] = true;
  }
  for (ob = 0; ob < numOolistButtons; ob++) {
    if (ob < a->imod->objsize) {
      diaSetChecked(groupButtons[ob], states[ob]);
      if (groupButtons[ob]->isHidden()) {
        groupButtons[ob]->show();
        showChgd = true;
      }
    } else if (!groupButtons[ob]->isHidden()) {
      groupButtons[ob]->hide();
      showChgd = true;
    }
  }
  free(states);
  if (showChgd)
    adjustFrameSize();
}
示例#16
0
/*
 * Analyzes the list of angular ranges and defocuses to see if the view
 * numbers are correct, using the nz tilt angles in angles (which can be NULL
 * if there are no tilt angles).  If it detects that the views are low by one,
 * it will adjust them.  If there are other inconsistencies, it returns 1.
 */
int checkAndFixDefocusList(Ilist *list, float *angles, int nz, int defVersion)
{
  SavedDefocus *item;
  int allEqual = 1, allOffByOne = 1, numEmpty = 0;
  int minStart = 10000, maxEnd = -100;
  int i, k, start, end, startAmbig, endAmbig;
  float tol = 0.02f;
  for (k = 0; k < ilistSize(list); k++) {
    item = (SavedDefocus *)ilistItem(list, k);
    minStart = B3DMIN(minStart, item->startingSlice);
    maxEnd = B3DMAX(maxEnd, item->endingSlice);
    startAmbig = 0;
    endAmbig = 0;
    if (nz == 1 || !angles) {
      start = 0;
      end = 0;
      /*printf("item %d  start %d end %d low %f high %f  has to start %d "
             "end %d\n", k, item->startingSlice, item->endingSlice,
             item->lAngle, item->hAngle, start, end);*/
    } else {
      start = -1;
      end = -1;

      // Find first and last slice whose angle is within the range
      for (i = 0; i < nz; i++) {

        if (item->lAngle - tol < angles[i] && angles[i] < item->hAngle + tol) {
          if (start < 0)
            start = i;
          end = i;
        }

        // But also see if there could be ambiguity about an angle near one
        // end of the range, provided this is not a single-image range
        if (!fabs(item->hAngle - item->lAngle) < tol) {
          if (fabs((double)(item->lAngle - angles[i])) < 1.01 * tol) {
            if (angles[0] <= angles[nz - 1])
              startAmbig = 1;
            else
              endAmbig = 1;
            /*printf("Angle %d, %f ambiguous to low angle %f, start %d end %d\n"
               ,i, angles[i], item->lAngle, startAmbig, endAmbig);*/
          }
          if (fabs((double)(item->hAngle - angles[i])) < 1.01 * tol) {
            if (angles[0] <= angles[nz - 1])
              endAmbig = 1;
            else
              startAmbig = 1;
            /*printf("Angle %d, %f ambiguous to high angle %f, start %d end %d\n"
              ,i, angles[i], item->hAngle, startAmbig, endAmbig);*/
          }
        }
      }
      /*printf("item %d  start %d end %d low %f high %f  implied start %d "
             "end %d\n", k, item->startingSlice, item->endingSlice,
             item->lAngle, item->hAngle, start, end);*/

      // If can't find, skip this one, count how many times this happens
      // This used to guarantee it thought they were off by 1!  
      if (start < 0 || end < 0) {
        numEmpty++;
        continue;
      }
    }
    if ((start != item->startingSlice && !startAmbig) ||
        (end != item->endingSlice && !endAmbig))
      allEqual = 0;
    if ((start != item->startingSlice + 1 && !startAmbig) ||
        (end != item->endingSlice + 1 && !endAmbig))
      allOffByOne = 0;
  }

  // If we didn't find out anything, see if min and max are at least
  // consistent with the bug, and go ahead and adjust
  if (allEqual && allOffByOne && minStart == -1 && maxEnd < nz - 1)
    allEqual = 0;

  // Adjust them all if all off by one as far as we can tell, for old data
  if ((!allEqual || allOffByOne) && defVersion < 2) {
    printf("View numbers in defocus file appear to be low by 1;\n"
           "  adding 1 to correct for old Ctfplotter bug\n");
    for (k = 0; k < ilistSize(list); k++) {
      item = (SavedDefocus *)ilistItem(list, k);
      item->startingSlice++;
      item->endingSlice++;
    }
  }
  if ((!allEqual && allOffByOne && defVersion < 2) || (allEqual && !allOffByOne))
    return 0;
  return 1;
}
示例#17
0
void ImodvOlist::actionButtonClicked(int which)
{
  Imod *imod = Imodv->imod;
  IobjGroup *group, *ogroup;
  int ob, index, changed = 1;

  if (which != OBJGRP_NEW && which != OBJGRP_DELETE) {
    group = (IobjGroup *)ilistItem(imod->groupList, imod->curObjGroup);
    if (!group)
      return;
  }

  switch (which) {
  case OBJGRP_NEW:
    imodvRegisterModelChg();
    group = objGroupListExpand(&imod->groupList);
    if (!group)
      break;
    ogroup = (IobjGroup *)ilistItem(imod->groupList, imod->curObjGroup);
    if (ogroup)
      group->objList = ilistDup(ogroup->objList);
    imod->curObjGroup = ilistSize(imod->groupList) - 1;
    updateGroups(Imodv);
    break;

  case OBJGRP_DELETE:
    if (imod->curObjGroup < 0)
      return;
    imodvRegisterModelChg();
    if (objGroupListRemove(imod->groupList, imod->curObjGroup))
      break;
    imod->curObjGroup = B3DMIN(B3DMAX(0, imod->curObjGroup - 1),
                               ilistSize(imod->groupList) - 1);
    updateGroups(Imodv);
    break;

  case OBJGRP_CLEAR:
    imodvRegisterModelChg();
    ilistTruncate(group->objList, 0);
    updateGroups(Imodv);
    break;

  case OBJGRP_ADDALL:
    imodvRegisterModelChg();
    if (group->objList)
      ilistTruncate(group->objList, 0);
    for (ob = 0; ob < imod->objsize; ob++)
      if (objGroupAppend(group, ob))
        return;
    updateGroups(Imodv);
    break;

  case OBJGRP_SWAP:
    imodvRegisterModelChg();
    for (ob = 0; ob < imod->objsize; ob++) {
      index = objGroupLookup(group, ob);
      if (index >= 0)
        ilistRemove(group->objList, index);
      else
        if (objGroupAppend(group, ob))
          return;
    }
    updateGroups(Imodv);
    break;

  case OBJGRP_TURNON:
  case OBJGRP_TURNOFF:
  case OBJGRP_OTHERSON:
  case OBJGRP_OTHERSOFF:
    changed = 0;
    for (ob = 0; ob < imod->objsize; ob++) {
      index = objGroupLookup(group, ob);
      if (((index >= 0 && which == OBJGRP_TURNON) || 
           (index < 0 && which == OBJGRP_OTHERSON)) && 
          iobjOff(imod->obj[ob].flags)) {
        imodvRegisterObjectChg(ob);
        imod->obj[ob].flags &= ~IMOD_OBJFLAG_OFF;
        changed = 1;
      } else if (((index >= 0 && which == OBJGRP_TURNOFF) ||
                  (index < 0 && which == OBJGRP_OTHERSOFF)) &&
                 !iobjOff(imod->obj[ob].flags)) {
        imodvRegisterObjectChg(ob);
        imod->obj[ob].flags |= IMOD_OBJFLAG_OFF;
        changed = 1;
      }
    }
    imodvDraw(Imodv);
    imodvDrawImodImages();
    imodvObjedNewView();
    break;

  }
  if (changed)
    imodvFinishChgUnit();
}