void avtDatasetToDatasetFilter::PreExecute(void) { avtDatasetToDataObjectFilter::PreExecute(); avtDataAttributes &atts = GetInput()->GetInfo().GetAttributes(); if (switchVariables) { InputSetActiveVariable(activeVariable); } else if (atts.ValidActiveVariable() && atts.GetVariableName() != pipelineVariable) { if (AutomaticallyMakePipelineVariableActive()) InputSetActiveVariable(pipelineVariable); } }
avtImage_p avtVolumeFilter::RenderImage(avtImage_p opaque_image, const WindowAttributes &window) { if (atts.GetRendererType() == VolumeAttributes::RayCastingSLIVR){ return RenderImageRaycastingSLIVR(opaque_image,window); } // // We need to create a dummy pipeline with the volume renderer that we // can force to execute within our "Execute". Start with the source. // avtSourceFromAVTDataset termsrc(GetTypedInput()); // // Set up the volume renderer. // avtRayTracer *software = new avtRayTracer; software->SetInput(termsrc.GetOutput()); software->InsertOpaqueImage(opaque_image); software->SetRayCastingSLIVR(false); unsigned char vtf[4*256]; atts.GetTransferFunction(vtf); avtOpacityMap om(256); if ((atts.GetRendererType() == VolumeAttributes::RayCasting) && (atts.GetSampling() == VolumeAttributes::Trilinear)) om.SetTable(vtf, 256, atts.GetOpacityAttenuation()*2.0 - 1.0, atts.GetRendererSamples()); else om.SetTable(vtf, 256, atts.GetOpacityAttenuation()); double actualRange[2]; bool artificialMin = atts.GetUseColorVarMin(); bool artificialMax = atts.GetUseColorVarMax(); if (!artificialMin || !artificialMax) { GetDataExtents(actualRange, primaryVariable); UnifyMinMax(actualRange, 2); } double range[2]; range[0] = (artificialMin ? atts.GetColorVarMin() : actualRange[0]); range[1] = (artificialMax ? atts.GetColorVarMax() : actualRange[1]); if (atts.GetScaling() == VolumeAttributes::Log) { if (artificialMin) if (range[0] > 0) range[0] = log10(range[0]); if (artificialMax) if (range[1] > 0) range[1] = log10(range[1]); } else if (atts.GetScaling() == VolumeAttributes::Skew) { if (artificialMin) { double newMin = vtkSkewValue(range[0], range[0], range[1], atts.GetSkewFactor()); range[0] = newMin; } if (artificialMax) { double newMax = vtkSkewValue(range[1], range[0], range[1], atts.GetSkewFactor()); range[1] = newMax; } } om.SetMin(range[0]); om.SetMax(range[1]); if (atts.GetRendererType() == VolumeAttributes::RayCastingIntegration) { if (!artificialMin) range[0] = 0.; if (!artificialMax) { /* Don't need this code, because the rays will be in depth ... 0->1. double bounds[6]; GetSpatialExtents(bounds); UnifyMinMax(bounds, 6); double diag = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) + (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) + (bounds[5]-bounds[4])*(bounds[5]-bounds[4])); range[1] = (actualRange[1]*diag) / 2.; */ range[1] = (actualRange[1]) / 4.; } } // // Determine which variables to use and tell the ray function. // VarList vl; avtDataset_p input = GetTypedInput(); avtDatasetExaminer::GetVariableList(input, vl); int primIndex = -1; int opacIndex = -1; int gradIndex = -1; int count = 0; char gradName[128]; const char *gradvar = atts.GetOpacityVariable().c_str(); if (strcmp(gradvar, "default") == 0) gradvar = primaryVariable; // This name is explicitly sent to the avtGradientExpression in // the avtVolumePlot. SNPRINTF(gradName, 128, "_%s_gradient", gradvar); for (int i = 0 ; i < vl.nvars ; i++) { if ((strstr(vl.varnames[i].c_str(), "vtk") != NULL) && (strstr(vl.varnames[i].c_str(), "avt") != NULL)) continue; if (vl.varnames[i] == primaryVariable) { primIndex = count; } if (vl.varnames[i] == atts.GetOpacityVariable()) { opacIndex = count; } if (vl.varnames[i] == gradName) { gradIndex = count; } count += vl.varsizes[i]; } if (primIndex == -1) { if (vl.nvars <= 0) { debug1 << "Could not locate primary variable " << primaryVariable << ", assuming that we are running " << "in parallel and have more processors than domains." << endl; } else { EXCEPTION1(InvalidVariableException, primaryVariable); } } if (opacIndex == -1) { if (atts.GetOpacityVariable() == "default") { opacIndex = primIndex; } else if (vl.nvars <= 0) { debug1 << "Could not locate opacity variable " << atts.GetOpacityVariable().c_str() << ", assuming that we " << "are running in parallel and have more processors " << "than domains." << endl; } else { EXCEPTION1(InvalidVariableException,atts.GetOpacityVariable()); } } if ( atts.GetRendererType() != VolumeAttributes::RayCastingIntegration && atts.GetLightingFlag() && gradIndex == -1) { if (vl.nvars <= 0) { debug1 << "Could not locate gradient variable, assuming that we " << "are running in parallel and have more processors " << "than domains." << endl; } else { EXCEPTION1(InvalidVariableException,gradName); } } int newPrimIndex = UnifyMaximumValue(primIndex); if (primIndex >= 0 && newPrimIndex != primIndex) { // // We shouldn't ever have different orderings for our variables. // EXCEPTION1(InvalidVariableException, primaryVariable); } primIndex = newPrimIndex; int newOpacIndex = UnifyMaximumValue(opacIndex); if (opacIndex >= 0 && newOpacIndex != opacIndex) { // // We shouldn't ever have different orderings for our variables. // EXCEPTION1(InvalidVariableException, atts.GetOpacityVariable()); } opacIndex = newOpacIndex; int newGradIndex = UnifyMaximumValue(gradIndex); if (gradIndex >= 0 && newGradIndex != gradIndex) { // // We shouldn't ever have different orderings for our variables. // EXCEPTION1(InvalidVariableException, gradName); } gradIndex = newGradIndex; // // Set up lighting // avtFlatLighting fl; avtLightingModel *lm = &fl; double gradMax = 0.0, lightingPower = 1.0; if (atts.GetLowGradientLightingReduction() != VolumeAttributes::Off) { gradMax = atts.GetLowGradientLightingClampValue(); if (atts.GetLowGradientLightingClampFlag() == false) { double gradRange[2] = {0,0}; GetDataExtents(gradRange, gradName); gradMax = gradRange[1]; } switch (atts.GetLowGradientLightingReduction()) { case VolumeAttributes::Lowest: lightingPower = 1./16.; break; case VolumeAttributes::Lower: lightingPower = 1./8.; break; case VolumeAttributes::Low: lightingPower = 1./4.; break; case VolumeAttributes::Medium: lightingPower = 1./2.; break; case VolumeAttributes::High: lightingPower = 1.; break; case VolumeAttributes::Higher: lightingPower = 2.; break; case VolumeAttributes::Highest: lightingPower = 4.; break; default: break; } } avtPhong phong(gradMax, lightingPower); if (atts.GetLightingFlag()) { lm = &phong; } else { lm = &fl; } avtOpacityMap *om2 = NULL; if (primIndex == opacIndex) { // Note that we are forcing the color variables range onto the // opacity variable. om2 = &om; } else { om2 = new avtOpacityMap(256); om2->SetTable(vtf, 256, atts.GetOpacityAttenuation()); double range[2]; bool artificialMin = atts.GetUseOpacityVarMin(); bool artificialMax = atts.GetUseOpacityVarMax(); if (!artificialMin || !artificialMax) { InputSetActiveVariable(atts.GetOpacityVariable().c_str()); avtDatasetExaminer::GetDataExtents(input, range); UnifyMinMax(range, 2); InputSetActiveVariable(primaryVariable); } range[0] = (artificialMin ? atts.GetOpacityVarMin() : range[0]); range[1] = (artificialMax ? atts.GetOpacityVarMax() : range[1]); om2->SetMin(range[0]); om2->SetMax(range[1]); // LEAK!! } avtCompositeRF *compositeRF = new avtCompositeRF(lm, &om, om2); if (atts.GetRendererType() == VolumeAttributes::RayCasting && atts.GetSampling() == VolumeAttributes::Trilinear){ compositeRF->SetTrilinearSampling(true); double *matProp = atts.GetMaterialProperties(); double materialPropArray[4]; materialPropArray[0] = matProp[0]; materialPropArray[1] = matProp[1]; materialPropArray[2] = matProp[2]; materialPropArray[3] = matProp[3]; compositeRF->SetMaterial(materialPropArray); } else compositeRF->SetTrilinearSampling(false); avtIntegrationRF *integrateRF = new avtIntegrationRF(lm); compositeRF->SetColorVariableIndex(primIndex); compositeRF->SetOpacityVariableIndex(opacIndex); if (atts.GetLightingFlag()) compositeRF->SetGradientVariableIndex(gradIndex); integrateRF->SetPrimaryVariableIndex(primIndex); integrateRF->SetRange(range[0], range[1]); if (atts.GetSampling() == VolumeAttributes::KernelBased) { software->SetKernelBasedSampling(true); compositeRF->SetWeightVariableIndex(count); } if (atts.GetRendererType() == VolumeAttributes::RayCasting && atts.GetSampling() == VolumeAttributes::Trilinear) software->SetTrilinear(true); else software->SetTrilinear(false); if (atts.GetRendererType() == VolumeAttributes::RayCastingIntegration) software->SetRayFunction(integrateRF); else software->SetRayFunction(compositeRF); software->SetSamplesPerRay(atts.GetSamplesPerRay()); const int *size = window.GetSize(); software->SetScreen(size[0], size[1]); const View3DAttributes &view = window.GetView3D(); avtViewInfo vi; CreateViewInfoFromViewAttributes(vi, view); avtDataObject_p inputData = GetInput(); int width_,height_,depth_; if (GetLogicalBounds(inputData, width_,height_,depth_)) { // if we have logical bounds, compute the slices automatically double viewDirection[3]; int numSlices; viewDirection[0] = (view.GetViewNormal()[0] > 0)? view.GetViewNormal()[0]: -view.GetViewNormal()[0]; viewDirection[1] = (view.GetViewNormal()[1] > 0)? view.GetViewNormal()[1]: -view.GetViewNormal()[1]; viewDirection[2] = (view.GetViewNormal()[2] > 0)? view.GetViewNormal()[2]: -view.GetViewNormal()[2]; numSlices = (width_*viewDirection[0] + height_*viewDirection[1] + depth_*viewDirection[2]) * atts.GetRendererSamples(); if (atts.GetRendererType() == VolumeAttributes::RayCasting && atts.GetSampling() == VolumeAttributes::Trilinear) software->SetSamplesPerRay(numSlices); } software->SetView(vi); if (atts.GetRendererType() == VolumeAttributes::RayCastingIntegration) { integrateRF->SetDistance(view.GetFarPlane()-view.GetNearPlane()); integrateRF->SetWindowSize(size[0], size[1]); } double view_dir[3]; view_dir[0] = vi.focus[0] - vi.camera[0]; view_dir[1] = vi.focus[1] - vi.camera[1]; view_dir[2] = vi.focus[2] - vi.camera[2]; double mag = sqrt(view_dir[0]*view_dir[0] + view_dir[1]*view_dir[1] + view_dir[2]*view_dir[2]); if (mag != 0.) // only 0 if focus and camera are the same { view_dir[0] /= mag; view_dir[1] /= mag; view_dir[2] /= mag; } lm->SetViewDirection(view_dir); lm->SetViewUp(vi.viewUp); lm->SetLightInfo(window.GetLights()); const RenderingAttributes &render_atts = window.GetRenderAtts(); if (render_atts.GetSpecularFlag()) { lm->SetSpecularInfo(render_atts.GetSpecularFlag(), render_atts.GetSpecularCoeff(), render_atts.GetSpecularPower()); } // // Set the volume renderer's background color and mode from the // window attributes. // software->SetBackgroundMode(window.GetBackgroundMode()); software->SetBackgroundColor(window.GetBackground()); software->SetGradientBackgroundColors(window.GetGradBG1(), window.GetGradBG2()); // // We have to set up a sample point "arbitrator" to allow small cells // to be included in the final picture. // avtOpacityMapSamplePointArbitrator arb(om2, opacIndex); avtRay::SetArbitrator(&arb); // // Do the funny business to force an update. // avtDataObject_p dob = software->GetOutput(); dob->Update(GetGeneralContract()); if (atts.GetRendererType() == VolumeAttributes::RayCastingIntegration) integrateRF->OutputRawValues("integration.data"); // // Free up some memory and clean up. // delete software; avtRay::SetArbitrator(NULL); delete compositeRF; delete integrateRF; // // Copy the output of the volume renderer to our output. // avtImage_p output; CopyTo(output, dob); return output; }