SAMSON Forum
    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • SAMSON Connect
    • Get SAMSON

    Solved visibility of elements in the visual model

    Modeling
    2
    5
    3443
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Haichao last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Stephane
        Stephane last edited by

        Hi Haichao,

        the alpha channel should work. Alpha blending is not activated by default, though, so you might have to activate it before calling the display functions (and deactivate after), e.g.:

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_DEPTH_TEST);
        
        SAMSON::displaySpheres(
          nPositions,
          positionData,
          radiusDataV,
          colorDataV,
          flagDataV);
        
        SAMSON::displayCylinders(
          nCylinders,
          nPositions,
          indexData,
          positionData,
          radiusDataV,
          capData,
          colorDataV,
          flagDataV
          );
        
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_BLEND);
        

        Hope this helps,

        Stephane

        1 Reply Last reply Reply Quote 0
        • H
          Haichao last edited by Haichao

          Hi @Stephane-Redon,
          Thank you for the quick reply! It works now with blending enabled, but I still did not reach my desired results. I want to render a pipe by combining the display of cylinder and sphere primitives (in that order). But at transparent locations, this gives me some artifacts as you can see in the attached image. Here it seems that the pipe is not “sealed” anymore. Any tips on that? Also on a related note, do you have a tutorial or example code on the displayTubes function? I did not find a documentation about it and I would like to know what every parameter is supposed to do.

          Thanks,
          Haichao

          0_1532026038763_SAMSON-Core_2018-07-19_14-32-55.png

          1 Reply Last reply Reply Quote 0
          • Stephane
            Stephane last edited by Stephane

            Hi @Haichao,

            I think you're encountering this because SAMSON does not yet handle order-independant transparency: if a transparent object is closer than a non-transparent object (and the depth channel is active), then it hides non-transparent objects that are rendered after, since these do not pass the depth test. If possible, transparent objects should thus be rendered last. Unfortunately, this is not always possible.

            By the way, the function displayLineSweptSpheres might be doing what you want, since it combines cylinders and spheres at the junctions of cylinders.

            The function displayTubes is for tubes with an elliptic section. Unfortunately, we do not have documentation for this yet as the API might change to simplify it. The shader generate strips of triangles, but this can be achieved with displayTriangles and if you want circular sections it's probably better to use cylinders (since they're ray-traced by the shader).

            Best,

            Stephane

            1 Reply Last reply Reply Quote 0
            • H
              Haichao last edited by

              This is already quite helpful, thank you!
              I will try and see if displayLineSweptSpheres solves the issue.
              I will post the solution when I've found it!
              Cheers,
              Haichao

              1 Reply Last reply Reply Quote 0
              • First post
                Last post