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(); } }
void LightEditor::alphaBetaSliderValueChanged() { // Get alpha value in [-180, 180] degrees. float alpha = -180.0f + float(alphaSlider.value() - alphaSlider.minimum()) / float(alphaSlider.maximum() - alphaSlider.minimum()) * 360.0f; // Get beta value in [-90, 90] degrees. float beta = -90.0f + float(betaSlider.value() - betaSlider.minimum()) / float(betaSlider.maximum() - betaSlider.minimum()) * 180.0f; // Compute unit vector. float lightX = cos(alpha * M_PI/180.0f) * cos(beta * M_PI/180.0f); float lightY = sin(alpha * M_PI/180.0f) * cos(beta * M_PI/180.0f); float lightZ = sin(beta * M_PI/180.0f); // Update OSPRay light direction. ospSet3f(light, "direction", lightX, lightY, lightZ); // Commit and emit signal. ospCommit(light); emit lightChanged(); }
void Instance::finalize(Model *model) { xfm.l.vx = getParam3f("xfm.l.vx",vec3f(1.f,0.f,0.f)); xfm.l.vy = getParam3f("xfm.l.vy",vec3f(0.f,1.f,0.f)); xfm.l.vz = getParam3f("xfm.l.vz",vec3f(0.f,0.f,1.f)); xfm.p = getParam3f("xfm.p",vec3f(0.f,0.f,0.f)); instancedScene = (Model *)getParamObject("model", nullptr); assert(instancedScene); if (!instancedScene->embreeSceneHandle) { instancedScene->commit(); } RTCGeometry embreeGeom = rtcNewGeometry(ispc_embreeDevice(),RTC_GEOMETRY_TYPE_INSTANCE); embreeGeomID = rtcAttachGeometry(model->embreeSceneHandle,embreeGeom); rtcSetGeometryInstancedScene(embreeGeom,instancedScene->embreeSceneHandle); const box3f b = instancedScene->bounds; if (b.empty()) { // for now, let's just issue a warning since not all ospray // geometries do properly set the boudning box yet. as soon as // this gets fixed we will actually switch to reporting an error static WarnOnce warning("creating an instance to a model that does not" " have a valid bounding box. epsilons for" " ray offsets may be wrong"); } const vec3f v000(b.lower.x,b.lower.y,b.lower.z); const vec3f v001(b.upper.x,b.lower.y,b.lower.z); const vec3f v010(b.lower.x,b.upper.y,b.lower.z); const vec3f v011(b.upper.x,b.upper.y,b.lower.z); const vec3f v100(b.lower.x,b.lower.y,b.upper.z); const vec3f v101(b.upper.x,b.lower.y,b.upper.z); const vec3f v110(b.lower.x,b.upper.y,b.upper.z); const vec3f v111(b.upper.x,b.upper.y,b.upper.z); bounds = empty; bounds.extend(xfmPoint(xfm,v000)); bounds.extend(xfmPoint(xfm,v001)); bounds.extend(xfmPoint(xfm,v010)); bounds.extend(xfmPoint(xfm,v011)); bounds.extend(xfmPoint(xfm,v100)); bounds.extend(xfmPoint(xfm,v101)); bounds.extend(xfmPoint(xfm,v110)); bounds.extend(xfmPoint(xfm,v111)); rtcSetGeometryTransform(embreeGeom,0,RTC_FORMAT_FLOAT3X4_COLUMN_MAJOR,&xfm); rtcCommitGeometry(embreeGeom); rtcReleaseGeometry(embreeGeom); AffineSpace3f rcp_xfm = rcp(xfm); areaPDF.resize(instancedScene->geometry.size()); ispc::InstanceGeometry_set(getIE(), (ispc::AffineSpace3f&)xfm, (ispc::AffineSpace3f&)rcp_xfm, instancedScene->getIE(), &areaPDF[0]); for (auto volume : instancedScene->volume) { ospSet3f((OSPObject)volume.ptr, "xfm.l.vx", xfm.l.vx.x, xfm.l.vx.y, xfm.l.vx.z); ospSet3f((OSPObject)volume.ptr, "xfm.l.vy", xfm.l.vy.x, xfm.l.vy.y, xfm.l.vy.z); ospSet3f((OSPObject)volume.ptr, "xfm.l.vz", xfm.l.vz.x, xfm.l.vz.y, xfm.l.vz.z); ospSet3f((OSPObject)volume.ptr, "xfm.p", xfm.p.x, xfm.p.y, xfm.p.z); } }