Hi,
I would like to change the visibility of single spheres, which are rendered with the displaySpheres function. In between are cylinders that are rendered with the displayCylinders function.
Here is sample code where a skeleton tube of a protein is displayed:
SBNodeIndexer residues;
SAMSON::getActiveDocument()->getNodes(residues, SBNode::IsType(SBNode::Residue));
unsigned int nPositions = 0;
std::vector<SBAtom*> caAtoms;
SB_FOR(SBNode* r, residues) {
SBResidue* residue = static_cast<SBResidue*>(r);
SBNodeIndexer atoms;
residue->getNodes(atoms, SBNode::IsType(SBNode::Atom));
SB_FOR(SBNode* a, atoms) {
SBAtom* atom = static_cast<SBAtom*>(a);
if (atom->getName() == "CA") {
nPositions++;
caAtoms.push_back(atom);
}
}
}
unsigned int nCylinders = nPositions - 1;
unsigned int nIndices = 2 * nCylinders;
unsigned int* indexData = new unsigned int[nIndices];
float *positionData = new float[3 * nPositions];
float *radiusDataV = new float[nPositions];
unsigned int *capData = new unsigned int[nPositions];
float *colorDataV = new float[4 * nPositions];
unsigned int *flagDataV = new unsigned int[nPositions];
int i = 0;
for (auto ca : caAtoms) {
positionData[3 * i + 0] = ca->getPosition().v[0].getValue();
positionData[3 * i + 1] = ca->getPosition().v[1].getValue();
positionData[3 * i + 2] = ca->getPosition().v[2].getValue();
radiusDataV[i] = 40;
flagDataV[i] = 0;
capData[i] = 1;
colorDataV[4 * i + 0] = 0.8;
colorDataV[4 * i + 1] = 0.5;
colorDataV[4 * i + 2] = 0;
colorDataV[4 * i + 3] = 1;
i++;
}
for (int j = 0; j < caAtoms.size(); j++) {
indexData[2 * j] = j;
indexData[2 * j + 1] = j + 1;
}
SAMSON::displaySpheres(
nPositions,
positionData,
radiusDataV,
colorDataV,
flagDataV);
SAMSON::displayCylinders(
nCylinders,
nPositions,
indexData,
positionData,
radiusDataV,
capData,
colorDataV,
flagDataV
);
Let’s say I would like to make some spheres and its connected cylinders invisible. I tried the alpha channel, but this seems to have no effect. What's the best way to do this, preferably without having to re-initialize the indexData array every time the visibility has changed?
Cheers,
Haichao