17 #define GPU_INFO MITK_INFO("mapper.vr")
18 #define GPU_WARN MITK_WARN("mapper.vr")
19 #define GPU_ERROR MITK_ERROR("mapper.vr")
21 #include <vtkAutoInit.h>
40 #include <vtkProperty.h>
42 #include <vtkAssembly.h>
43 #include <vtkColorTransferFunction.h>
44 #include <vtkFiniteDifferenceGradientEstimator.h>
45 #include <vtkImageData.h>
46 #include <vtkImageResample.h>
47 #include <vtkImageWriter.h>
48 #include <vtkImplicitPlaneWidget.h>
49 #include <vtkLODProp3D.h>
50 #include <vtkPiecewiseFunction.h>
52 #include <vtkRenderWindow.h>
53 #include <vtkRenderWindowInteractor.h>
54 #include <vtkVolume.h>
55 #include <vtkVolumeProperty.h>
56 #include <vtkVolumeRayCastCompositeFunction.h>
57 #include <vtkVolumeRayCastMIPFunction.h>
58 #include <vtkVolumeTextureMapper2D.h>
60 #include <vtkCubeSource.h>
61 #include <vtkPolyDataMapper.h>
64 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
71 #include "vtkOpenGLGPUVolumeRayCastMapper.h"
97 GPU_INFO <<
"initializing gpu-slicing-vr (vtkMitkOpenGLVolumeTextureMapper3D)";
116 ls->
m_MapperGPU->SetInputConnection(this->m_UnitSpacingImageFilter->GetOutputPort());
135 int numThreads = ls->
m_MapperCPU->GetNumberOfThreads();
137 GPU_INFO <<
"initializing cpu-raycast-vr (vtkFixedPointVolumeRayCastMapper) (" << numThreads <<
" threads)";
158 ls->
m_MapperCPU->SetInputConnection(m_UnitSpacingImageFilter->GetOutputPort());
169 GPU_INFO <<
"deinitializing gpu-slicing-vr";
187 GPU_INFO <<
"deinitializing cpu-raycast-vr";
198 m_commonInitialized =
false;
208 if (m_commonInitialized)
212 m_UnitSpacingImageFilter->SetOutputSpacing(1.0, 1.0, 1.0);
214 CreateDefaultTransferFunctions();
216 m_commonInitialized =
true;
221 if (!m_commonInitialized)
224 m_commonInitialized =
false;
254 if (inputData == NULL)
263 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
264 if (IsRAYEnabled(renderer))
268 if (!InitRAY(renderer))
270 GPU_WARN <<
"hardware renderer can't initialize ... falling back to software renderer";
276 if (IsGPUEnabled(renderer))
280 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
283 if (!InitGPU(renderer))
285 GPU_WARN <<
"hardware renderer can't initialize ... falling back to software renderer";
294 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
303 if (!IsRenderable(renderer))
308 m_VolumeNULL->VisibilityOff();
314 InitVtkMapper(renderer);
319 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
320 if (ls->m_rayInitialized)
321 return ls->m_VolumeRAY;
332 if (!IsRenderable(renderer))
336 InitVtkMapper(renderer);
340 m_UnitSpacingImageFilter->SetInputData(inputData);
345 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
346 if (ls->m_rayInitialized)
348 GenerateDataRAY(renderer);
355 GenerateDataGPU(renderer);
359 GenerateDataCPU(renderer);
363 UpdateTransferFunctions(renderer);
370 bool useCompression =
false;
371 GetDataNode()->GetBoolProperty(
"volumerendering.gpu.usetexturecompression", useCompression, renderer);
372 ls->
m_MapperGPU->SetUseCompressedTexture(useCompression);
382 if (GetDataNode()->GetFloatProperty(
"volumerendering.gpu.ambient", value, renderer))
384 if (GetDataNode()->GetFloatProperty(
"volumerendering.gpu.diffuse", value, renderer))
386 if (GetDataNode()->GetFloatProperty(
"volumerendering.gpu.specular", value, renderer))
388 if (GetDataNode()->GetFloatProperty(
"volumerendering.gpu.specular.power", value, renderer))
399 if (IsLODEnabled(renderer) && nextLod == 0)
413 if (IsMIPEnabled(renderer))
421 if (GetDataNode()->GetFloatProperty(
"volumerendering.cpu.ambient", value, renderer))
423 if (GetDataNode()->GetFloatProperty(
"volumerendering.cpu.diffuse", value, renderer))
425 if (GetDataNode()->GetFloatProperty(
"volumerendering.cpu.specular", value, renderer))
427 if (GetDataNode()->GetFloatProperty(
"volumerendering.cpu.specular.power", value, renderer))
435 m_DefaultOpacityTransferFunction->AddPoint(0.0, 0.0);
436 m_DefaultOpacityTransferFunction->AddPoint(255.0, 0.8);
437 m_DefaultOpacityTransferFunction->ClampingOn();
440 m_DefaultGradientTransferFunction->AddPoint(0.0, 0.0);
441 m_DefaultGradientTransferFunction->AddPoint(255.0, 0.8);
442 m_DefaultGradientTransferFunction->ClampingOn();
445 m_DefaultColorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
446 m_DefaultColorTransferFunction->AddRGBPoint(127.5, 1, 1, 0.0);
447 m_DefaultColorTransferFunction->AddRGBPoint(255.0, 0.8, 0.2, 0);
448 m_DefaultColorTransferFunction->ClampingOn();
451 m_BinaryOpacityTransferFunction->AddPoint(0, 0.0);
452 m_BinaryOpacityTransferFunction->AddPoint(1, 1.0);
455 m_BinaryGradientTransferFunction->AddPoint(0.0, 1.0);
464 vtkPiecewiseFunction *opacityTransferFunction = m_DefaultOpacityTransferFunction;
465 vtkPiecewiseFunction *gradientTransferFunction = m_DefaultGradientTransferFunction;
466 vtkColorTransferFunction *colorTransferFunction = m_DefaultColorTransferFunction;
468 bool isBinary =
false;
470 GetDataNode()->GetBoolProperty(
"binary", isBinary, renderer);
474 opacityTransferFunction = m_BinaryOpacityTransferFunction;
475 gradientTransferFunction = m_BinaryGradientTransferFunction;
476 colorTransferFunction = m_BinaryColorTransferFunction;
478 colorTransferFunction->RemoveAllPoints();
480 if (!GetDataNode()->GetColor(rgb, renderer))
481 rgb[0] = rgb[1] = rgb[2] = 1;
482 colorTransferFunction->AddRGBPoint(0, rgb[0], rgb[1], rgb[2]);
483 colorTransferFunction->Modified();
490 if (transferFunctionProp)
492 opacityTransferFunction = transferFunctionProp->
GetValue()->GetScalarOpacityFunction();
493 gradientTransferFunction = transferFunctionProp->
GetValue()->GetGradientOpacityFunction();
494 colorTransferFunction = transferFunctionProp->
GetValue()->GetColorTransferFunction();
506 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
508 if (ls->m_rayInitialized)
510 ls->m_VolumePropertyRAY->SetColor(colorTransferFunction);
511 ls->m_VolumePropertyRAY->SetScalarOpacity(opacityTransferFunction);
512 ls->m_VolumePropertyRAY->SetGradientOpacity(gradientTransferFunction);
550 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
570 if (image.IsNotNull() && image->IsInitialized())
572 if ((overwrite) || (node->
GetProperty(
"levelwindow", renderer) == NULL))
577 levWinProp->SetLevelWindow(levelwindow);
578 node->
SetProperty(
"levelwindow", levWinProp, renderer);
581 if ((overwrite) || (node->
GetProperty(
"TransferFunction", renderer) == NULL))
586 tfInit->SetTransferFunctionMode(0);
591 Superclass::SetDefaultProperties(node, renderer, overwrite);
597 return GetDataNode()->GetBoolProperty(
"volumerendering.uselod", value, renderer) && value;
603 return GetDataNode()->GetBoolProperty(
"volumerendering.usemip", value, renderer) && value;
610 return ls->
m_gpuSupported && GetDataNode()->GetBoolProperty(
"volumerendering.usegpu", value, renderer) && value;
614 #if ((VTK_MAJOR_VERSION > 5) || ((VTK_MAJOR_VERSION == 5) && (VTK_MINOR_VERSION >= 6)))
618 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
620 if (ls->m_rayInitialized)
621 return ls->m_raySupported;
623 ls->m_VtkRenderWindow = renderer->
GetVtkRenderer()->GetRenderWindow();
625 GPU_INFO <<
"initializing gpu-raycast-vr (vtkOpenGLGPUVolumeRayCastMapper)";
628 ls->m_MapperRAY->SetAutoAdjustSampleDistances(0);
629 ls->m_MapperRAY->SetSampleDistance(1.0);
632 ls->m_VolumePropertyRAY->ShadeOn();
633 ls->m_VolumePropertyRAY->SetAmbient(0.25f);
634 ls->m_VolumePropertyRAY->SetDiffuse(0.50f);
635 ls->m_VolumePropertyRAY->SetSpecular(0.40f);
636 ls->m_VolumePropertyRAY->SetSpecularPower(16.0f);
637 ls->m_VolumePropertyRAY->SetInterpolationTypeToLinear();
640 ls->m_VolumeRAY->SetMapper(ls->m_MapperRAY);
641 ls->m_VolumeRAY->SetProperty(ls->m_VolumePropertyRAY);
642 ls->m_VolumeRAY->VisibilityOn();
644 ls->m_MapperRAY->SetInputConnection(this->m_UnitSpacingImageFilter->GetOutputPort());
646 ls->m_raySupported = ls->m_MapperRAY->IsRenderSupported(renderer->
GetRenderWindow(), ls->m_VolumePropertyRAY);
648 ls->m_rayInitialized =
true;
649 return ls->m_raySupported;
654 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
656 if (ls->m_rayInitialized)
658 GPU_INFO <<
"deinitializing gpu-raycast-vr";
660 ls->m_MapperRAY = NULL;
661 ls->m_VolumePropertyRAY = NULL;
666 ls->m_VolumeRAY->ReleaseGraphicsResources(renderer->
GetVtkRenderer()->GetRenderWindow());
667 ls->m_VolumeRAY = NULL;
668 ls->m_rayInitialized =
false;
674 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
677 ls->m_MapperRAY->SetImageSampleDistance(4.0);
679 ls->m_MapperRAY->SetImageSampleDistance(1.0);
682 if (IsMIPEnabled(renderer))
683 ls->m_MapperRAY->SetBlendModeToMaximumIntensity();
685 ls->m_MapperRAY->SetBlendModeToComposite();
690 if (GetDataNode()->GetFloatProperty(
"volumerendering.ray.ambient", value, renderer))
691 ls->m_VolumePropertyRAY->SetAmbient(value);
692 if (GetDataNode()->GetFloatProperty(
"volumerendering.ray.diffuse", value, renderer))
693 ls->m_VolumePropertyRAY->SetDiffuse(value);
694 if (GetDataNode()->GetFloatProperty(
"volumerendering.ray.specular", value, renderer))
695 ls->m_VolumePropertyRAY->SetSpecular(value);
696 if (GetDataNode()->GetFloatProperty(
"volumerendering.ray.specular.power", value, renderer))
697 ls->m_VolumePropertyRAY->SetSpecularPower(value);
703 LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
705 return ls->m_raySupported && GetDataNode()->GetBoolProperty(
"volumerendering.useray", value, renderer) && value;
virtual vtkProp * GetVtkProp(mitk::BaseRenderer *renderer) override
The TransferFunctionProperty class Property class for the mitk::TransferFunction. ...
vtkRenderWindow * m_VtkRenderWindow
vtkSmartPointer< vtkMitkVolumeTextureMapper3D > m_MapperGPU
virtual mitk::TransferFunction::Pointer GetValue() const
virtual void ApplyProperties(vtkActor *actor, mitk::BaseRenderer *renderer) override
Apply color and opacity properties read from the PropertyList.
bool IsRAYEnabled(BaseRenderer *renderer=NULL)
vtkSmartPointer< vtkVolumeProperty > m_VolumePropertyGPU
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL)
Organizes the rendering process.
bool GetBoolProperty(const char *propertyKey, bool &boolValue, const mitk::BaseRenderer *renderer=nullptr) const
Convenience access method for bool properties (instances of BoolProperty)
virtual vtkImageData * GetVtkImageData(int t=0, int n=0)
Get a volume at a specific time t of channel n as a vtkImageData.
vtkSmartPointer< vtkVolume > m_VolumeGPU
BaseData * GetData() const
Get the data object (instance of BaseData, e.g., an Image) managed by this DataNode.
void InitVtkMapper(mitk::BaseRenderer *renderer)
virtual bool IsLODEnabled(BaseRenderer *renderer=NULL) const override
mitk::BaseProperty * GetProperty(const char *propertyKey, const mitk::BaseRenderer *renderer=nullptr) const
Get the property (instance of BaseProperty) with key propertyKey from the PropertyList of the rendere...
void DeinitGPU(mitk::BaseRenderer *renderer)
virtual void GenerateDataForRenderer(mitk::BaseRenderer *renderer) override
Generate the data needed for rendering into renderer.
The LevelWindow class Class to store level/window values.
void GenerateDataGPU(mitk::BaseRenderer *renderer)
void InitCPU(mitk::BaseRenderer *renderer)
virtual void MitkRenderVolumetricGeometry(BaseRenderer *renderer)
Checks visibility and renders volumes.
void AddProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr, bool overwrite=false)
Add the property (instance of BaseProperty) if it does not exist (or always ifoverwrite istrue) with ...
virtual const mitk::Image * GetInput()
vtkSmartPointer< vtkVolumeProperty > m_VolumePropertyCPU
static RenderingManager * GetInstance()
bool IsRenderable(mitk::BaseRenderer *renderer)
Image class for storing images.
bool InitGPU(mitk::BaseRenderer *renderer)
void SetAuto(const Image *image, bool tryPicTags=true, bool guessByCentralSlice=true, unsigned selectedComponent=0)
sets level/window to optimize the contrast of the given Image
void GenerateDataCPU(mitk::BaseRenderer *renderer)
void UpdateTransferFunctions(mitk::BaseRenderer *renderer)
int GetNextLOD(BaseRenderer *renderer)
void DeinitCPU(mitk::BaseRenderer *renderer)
bool IsMIPEnabled(BaseRenderer *renderer=NULL)
virtual bool IsInitialized() const
Check whether the data has been initialized, i.e., at least the Geometry and other header data has be...
void CreateDefaultTransferFunctions()
void SetProperty(const char *propertyKey, BaseProperty *property, const mitk::BaseRenderer *renderer=nullptr)
Set the property (instance of BaseProperty) with key propertyKey in the PropertyList of the renderer ...
virtual void MitkRenderVolumetricGeometry(mitk::BaseRenderer *renderer) override
Checks visibility and renders volumes.
static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer=NULL, bool overwrite=false)
virtual DataNode * GetDataNode() const
Get the DataNode containing the data to map. Method only returns valid DataNode Pointer if the mapper...
vtkSmartPointer< vtkVolume > m_VolumeCPU
vtkRenderer * GetVtkRenderer() const
bool GetVisibility(bool &visible, const mitk::BaseRenderer *renderer, const char *propertyKey="visible") const
Convenience access method for visibility properties (instances of BoolProperty with property-key "vis...
bool IsGPUEnabled(BaseRenderer *renderer=NULL)
vtkRenderWindow * GetRenderWindow() const
Access the RenderWindow into which this renderer renders.
Class for nodes of the DataTree.
virtual ~GPUVolumeMapper3D()
vtkSmartPointer< vtkFixedPointVolumeRayCastMapper > m_MapperCPU
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.