Ejemplo n.º 1
0
    void Geometry::postCommit(RenderContext &)
    {
      auto ospGeometry = valueAs<OSPGeometry>();

      if (hasChild("material") && !hasChild("materialList")) {
        // XXX FIXME never happens
        ospSetMaterial(ospGeometry, child("material").valueAs<OSPMaterial>());
      }

      auto materialListNode = child("materialList").nodeAs<MaterialList>();
      const auto &materialList = materialListNode->nodes;
      if (!materialList.empty()) {
        std::vector<OSPObject> mats;
        for (auto mat : materialList) {
          auto m = mat->valueAs<OSPObject>();
          if (m)
            mats.push_back(m);
        }
        auto ospMaterialList = ospNewData(mats.size(), OSP_OBJECT, mats.data());
        ospCommit(ospMaterialList);
        ospSetData(valueAs<OSPObject>(), "materialList", ospMaterialList);
        ospRelease(ospMaterialList);
      }

      ospCommit(ospGeometry);
    }
Ejemplo n.º 2
0
void VolumeViewer::addGeometry(std::string filename)
{
  // For now we assume PLY geometry files. Later we can support other geometry formats.

  // Get filename if not specified.
  if(filename.empty())
    filename = QFileDialog::getOpenFileName(this, tr("Load geometry"), ".", "Geometry files (*.ply *.dds)").toStdString();

  if(filename.empty())
    return;

  // Attempt to load the geometry through the TriangleMeshFile loader.
  OSPGeometry triangleMesh = ospNewGeometry("trianglemesh");

  // If successful, commit the triangle mesh and add it to all models.
  if(TriangleMeshFile::importTriangleMesh(filename, triangleMesh) != NULL) {

    // For now: if this is a DDS geometry, assume it is a horizon and its color should be mapped through the first volume's transfer function.
    if(QString(filename.c_str()).endsWith(".dds") && modelStates.size() > 0 && modelStates[0].volumes.size() > 0) {

      OSPMaterial material = ospNewMaterial(renderer, "default");
      ospSet3f(material, "Kd", 1,1,1);
      ospSetObject(material, "volume", modelStates[0].volumes[0]);
      ospCommit(material);

      ospSetMaterial(triangleMesh, material);
    }

    ospCommit(triangleMesh);

    // Create an instance of the geometry and add the instance to the main model(s)--this prevents the geometry
    // from being rebuilt every time the main model is committed (e.g. when slices / isosurfaces are manipulated)
    OSPModel modelInstance = ospNewModel();
    ospAddGeometry(modelInstance, triangleMesh);
    ospCommit(modelInstance);

    ospcommon::affine3f xfm = ospcommon::one;
    OSPGeometry triangleMeshInstance = ospNewInstance(modelInstance, (osp::affine3f&)xfm);
    ospCommit(triangleMeshInstance);

    for(size_t i=0; i<modelStates.size(); i++) {
      ospAddGeometry(modelStates[i].model, triangleMeshInstance);
      ospCommit(modelStates[i].model);
    }

    // Force render.
    render();
  }
}