------------------------------------------------------------------------------
| 401 | |
| 402 | //------------------------------------------------------------------------------ |
| 403 | void vtkOSPRayVolumeMapperNode::UpdateTransferFunction( |
| 404 | RTW::Backend* backend, vtkVolume* vol, double* dataRange) |
| 405 | { |
| 406 | if (backend == nullptr) |
| 407 | return; |
| 408 | vtkVolumeProperty* volProperty = vol->GetProperty(); |
| 409 | vtkColorTransferFunction* colorTF = volProperty->GetRGBTransferFunction(0); |
| 410 | vtkPiecewiseFunction* scalarTF = volProperty->GetScalarOpacity(0); |
| 411 | |
| 412 | this->TFVals.resize(this->NumColors * 3); |
| 413 | this->TFOVals.resize(this->NumColors); |
| 414 | double tfRangeD[2]; |
| 415 | // prefer transfer function's range |
| 416 | colorTF->GetRange(tfRangeD); |
| 417 | // but use data's range if we can and we have to |
| 418 | if (dataRange && (dataRange[1] > dataRange[0]) && (tfRangeD[1] <= tfRangeD[0])) |
| 419 | { |
| 420 | tfRangeD[0] = dataRange[0]; |
| 421 | tfRangeD[1] = dataRange[1]; |
| 422 | } |
| 423 | osp::vec2f tfRange = { float(tfRangeD[0]), float(tfRangeD[1]) }; |
| 424 | scalarTF->GetTable(tfRangeD[0], tfRangeD[1], this->NumColors, &this->TFOVals[0]); |
| 425 | colorTF->GetTable(tfRangeD[0], tfRangeD[1], this->NumColors, &this->TFVals[0]); |
| 426 | |
| 427 | ospRelease(this->TransferFunction); |
| 428 | this->TransferFunction = ospNewTransferFunction("piecewiseLinear"); |
| 429 | |
| 430 | OSPData colorData = ospNewCopyData1D(&this->TFVals[0], OSP_VEC3F, this->NumColors); |
| 431 | ospCommit(colorData); |
| 432 | ospSetObject(this->TransferFunction, "color", colorData); |
| 433 | |
| 434 | #if OSPRAY_VERSION_MAJOR < 3 |
| 435 | ospSetVec2f(this->TransferFunction, "valueRange", tfRange.x, tfRange.y); |
| 436 | #else |
| 437 | ospSetBox1f(this->TransferFunction, "value", tfRange.x, tfRange.y); |
| 438 | #endif |
| 439 | |
| 440 | OSPData tfAlphaData = ospNewCopyData1D(&this->TFOVals[0], OSP_FLOAT, this->NumColors); |
| 441 | ospCommit(tfAlphaData); |
| 442 | ospSetObject(this->TransferFunction, "opacity", tfAlphaData); |
| 443 | |
| 444 | ospCommit(this->TransferFunction); |
| 445 | ospRelease(colorData); |
| 446 | ospRelease(tfAlphaData); |
| 447 | |
| 448 | vtkContourValues* contours = volProperty->GetIsoSurfaceValues(); |
| 449 | this->IsoColors.clear(); |
| 450 | if (contours) |
| 451 | { |
| 452 | this->IsoColors.reserve(4 * contours->GetNumberOfContours()); |
| 453 | double* p = contours->GetValues(); |
| 454 | for (auto i = 0; i < contours->GetNumberOfContours(); ++i) |
| 455 | { |
| 456 | double* ncol = colorTF->GetColor(p[i]); |
| 457 | this->IsoColors.push_back(ncol[0]); |
| 458 | this->IsoColors.push_back(ncol[1]); |
| 459 | this->IsoColors.push_back(ncol[2]); |
| 460 | this->IsoColors.push_back(scalarTF->GetValue(p[i])); |
no test coverage detected