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 {
void RepWireBondRenderImmediate(CoordSet * cs, RenderInfo * info) { /* performance optimized, so it does not support the following: - anything other than opengl - display of bond valences - per-bond & per-atom properties, including color and line-width - half-bonds - helper settings such as cartoon_side_chain_helper - suppression of long bonds - color ramps - atom picking - display lists - transparency */ PyMOLGlobals *G = cs->State.G; if(info->ray || info->pick || (!(G->HaveGUI && G->ValidContext))) return; else { int active = false; ObjectMolecule *obj = cs->Obj; float line_width, line_width_setting = SettingGet_f(G, cs->Setting, obj->Obj.Setting, cSetting_line_width); line_width = SceneGetDynamicLineWidth(info, line_width_setting); if(info->width_scale_flag) glLineWidth(line_width * info->width_scale); else glLineWidth(line_width); SceneResetNormal(G, true); if(!info->line_lighting) glDisable(GL_LIGHTING); glBegin(GL_LINES); { int a; int nBond = obj->NBond; BondType *bd = obj->Bond; AtomInfoType *ai = obj->AtomInfo; int *atm2idx = cs->AtmToIdx; int discreteFlag = obj->DiscreteFlag; int last_color = -9; float *coord = cs->Coord; const float _pt5 = 0.5F; for(a = 0; a < nBond; a++) { int b1 = bd->index[0]; int b2 = bd->index[1]; AtomInfoType *ai1, *ai2; bd++; if(GET_BIT((ai1 = ai + b1)->visRep,cRepLine) && GET_BIT((ai2 = ai + b2)->visRep,cRepLine)) { int a1, a2; active = true; if(discreteFlag) { /* not optimized */ if((cs == obj->DiscreteCSet[b1]) && (cs == obj->DiscreteCSet[b2])) { a1 = obj->DiscreteAtmToIdx[b1]; a2 = obj->DiscreteAtmToIdx[b2]; } else { a1 = -1; a2 = -1; } } else { a1 = atm2idx[b1]; a2 = atm2idx[b2]; } if((a1 >= 0) && (a2 >= 0)) { int c1 = ai1->color; int c2 = ai2->color; float *v1 = coord + 3 * a1; float *v2 = coord + 3 * a2; if(c1 == c2) { /* same colors -> one line */ if(c1 != last_color) { last_color = c1; glColor3fv(ColorGet(G, c1)); } glVertex3fv(v1); glVertex3fv(v2); /* we done */ } else { /* different colors -> two lines */ float avg[3]; avg[0] = (v1[0] + v2[0]) * _pt5; avg[1] = (v1[1] + v2[1]) * _pt5; avg[2] = (v1[2] + v2[2]) * _pt5; if(c1 != last_color) { last_color = c1; glColor3fv(ColorGet(G, c1)); } glVertex3fv(v1); glVertex3fv(avg); if(c2 != last_color) { last_color = c2; glColor3fv(ColorGet(G, c2)); } glVertex3fv(avg); glVertex3fv(v2); } } } } } glEnd(); glEnable(GL_LIGHTING); if(!active) cs->Active[cRepLine] = false; } }