Ejemplo n.º 1
0
void *_MemoryShrinkForSure(PyMOLGlobals * G, void *ptr, unsigned int size, int group_id,
                           int block_id MD_FILE_LINE_Decl)
{
  /* no checking done */

  if((group_id < 0) || (!SettingGetGlobal_b(G, cSetting_cache_memory)))
    return (ReallocForSure(ptr, size)); /* NOTE: fatal if new ptr is larger than old... */
  {
    register CMemoryCache *I = G->MemoryCache;
    register MemoryCacheRec *rec = &I->Cache[group_id][block_id];

    if(ptr != rec->ptr)
      printf("Error: Memory Cache Mismatch 2 %d %d\n", group_id, block_id);
    if(!rec->ptr) {             /* not currently cache-allocated... this should never happen */
      rec->size = size;
      rec->ptr = mrealloc(ptr, size);
    } else if(rec->size < size) {
      rec->ptr = MemoryReallocForSureSafe(ptr, size, rec->size);
      rec->size = size;
    } else {                    /* expanding size...should never happen... this should never happen */
      rec->size = size;
      rec->ptr = mrealloc(ptr, size);
    }
    return (rec->ptr);
  }
}
Ejemplo n.º 2
0
Rep *RepLabelNew(CoordSet * cs, int state)
{
  PyMOLGlobals *G = cs->State.G;
  ObjectMolecule *obj;
  int a, a1, vFlag, c1;
  float *v, *v0, *vc;
  float *lab_pos;
  int *l;
  int label_color;
  LabPosType *lp = NULL;
  Pickable *rp = NULL;
  AtomInfoType *ai;
  OOAlloc(G, RepLabel);

  obj = cs->Obj;
  vFlag = false;
  if(obj->RepVisCache[cRepLabel])
    for(a = 0; a < cs->NIndex; a++) {
      if(obj->AtomInfo[cs->IdxToAtm[a]].visRep[cRepLabel]) {
        vFlag = true;
        break;
      }
    }
  if(!vFlag) {
    OOFreeP(I);
    return (NULL);              /* skip if no label are visible */
  }

  label_color = SettingGet_i(G, cs->Setting, obj->Obj.Setting, cSetting_label_color);
  RepInit(G, &I->R);

  obj = cs->Obj;
  I->R.fRender = (void (*)(struct Rep *, RenderInfo *)) RepLabelRender;
  I->R.fFree = (void (*)(struct Rep *)) RepLabelFree;
  I->R.fRecolor = NULL;
  I->R.obj = (CObject *) obj;
  I->R.cs = cs;
  I->R.context.object = (void *) obj;
  I->R.context.state = state;

  /* raytracing primitives */

  I->L = Alloc(int, cs->NIndex);
  ErrChkPtr(G, I->L);
  I->V = (float *) mmalloc(sizeof(float) * cs->NIndex * 9);
  ErrChkPtr(G, I->V);

  I->OutlineColor =
    SettingGet_i(G, cs->Setting, obj->Obj.Setting, cSetting_label_outline_color);

  lab_pos = SettingGet_3fv(G, cs->Setting, obj->Obj.Setting, cSetting_label_position);

  if(SettingGet_f(G, cs->Setting, obj->Obj.Setting, cSetting_pickable)) {
    I->R.P = Alloc(Pickable, cs->NIndex + 1);
    ErrChkPtr(G, I->R.P);
    rp = I->R.P + 1;            /* skip first record! */
  }

  I->N = 0;

  v = I->V;
  l = I->L;
  for(a = 0; a < cs->NIndex; a++) {
    a1 = cs->IdxToAtm[a];
    ai = obj->AtomInfo + a1;
    if(cs->LabPos) {
      lp = cs->LabPos + a;
    }
    if(ai->visRep[cRepLabel] && (ai->label)) {
      int at_label_color;
      AtomInfoGetSetting_color(G, ai, cSetting_label_color, label_color, &at_label_color);

      /*
         float at_label_pos = lab_pos;

         AtomInfoGetSetting_3fv(G, ai, cSetting_label_position, 
         label_pos, &at_label_pos);
       */

      I->N++;
      if((at_label_color >= 0) ||
         (at_label_color == cColorFront) || (at_label_color == cColorBack))
        c1 = at_label_color;
      else
        c1 = *(cs->Color + a);
      vc = ColorGet(G, c1);     /* save new color */
      *(v++) = *(vc++);
      *(v++) = *(vc++);
      *(v++) = *(vc++);
      v0 = cs->Coord + 3 * a;
      *(v++) = *(v0++);
      *(v++) = *(v0++);
      *(v++) = *(v0++);
      if(lp) {
        switch (lp->mode) {
        case 1:                /* local absolute positioning, global relative */
          add3f(lp->offset, v - 3, v - 3);
          copy3f(lab_pos, v);
          break;
        default:
          copy3f(lab_pos, v);
          break;
        }
      } else {
        copy3f(lab_pos, v);
      }

      v += 3;
      if(rp) {
        rp->index = a1;
        rp->bond = cPickableLabel;      /* label indicator */
        rp++;
      }
      *(l++) = ai->label;
    }
  }

  if(I->N) {
    I->V = ReallocForSure(I->V, float, (v - I->V));
    I->L = ReallocForSure(I->L, int, (l - I->L));
    if(rp) {
      I->R.P = ReallocForSure(I->R.P, Pickable, (rp - I->R.P));
      I->R.P[0].index = I->N;   /* unnec? */
    }
  } else {