Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxVolumeProperty.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include "cxVolumeProperty.h"
13 
14 #include <vtkPiecewiseFunction.h>
15 #include <vtkColorTransferFunction.h>
16 #include <vtkVolumeProperty.h>
17 
18 #include "cxImage.h"
19 #include "cxImageTF3D.h"
20 
21 
22 namespace cx
23 {
24 
25 VolumeProperty::VolumeProperty() : QObject(),
26  mOpacityTransferFunction(vtkPiecewiseFunctionPtr::New()),
27  mColorTransferFunction(vtkColorTransferFunctionPtr::New()),
28  mVolumeProperty(vtkVolumePropertyPtr::New())
29 {
30  double maxVal = 255;
31  mOpacityTransferFunction->AddPoint(0.0, 0.0);
32  mOpacityTransferFunction->AddPoint(maxVal, 1.0);
33 
34  mColorTransferFunction->SetColorSpaceToRGB();
35  mColorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
36  mColorTransferFunction->AddRGBPoint(maxVal, 1.0, 1.0, 1.0);
37 
38  mVolumeProperty->SetColor(mColorTransferFunction);
39  mVolumeProperty->SetScalarOpacity(mOpacityTransferFunction);
40  mVolumeProperty->SetInterpolationTypeToLinear();
41 
42  // from snw
43  mVolumeProperty->ShadeOff();
44  mVolumeProperty->SetAmbient ( 0.2 );
45  mVolumeProperty->SetDiffuse ( 0.9 );
46  mVolumeProperty->SetSpecular ( 0.3 );
47  mVolumeProperty->SetSpecularPower ( 15.0 );
48  mVolumeProperty->SetScalarOpacityUnitDistance(0.8919);
49 }
50 
52 {
53  return mVolumeProperty;
54 }
55 
57 {
58  if (image==mImage)
59  {
60  return;
61  }
62 
63  if (mImage)
64  {
65  disconnect(mImage.get(), SIGNAL(vtkImageDataChanged()), this, SLOT(transferFunctionsChangedSlot()));
66  disconnect(mImage.get(), SIGNAL(transferFunctionsChanged()), this, SLOT(transferFunctionsChangedSlot()));
67  }
68 
69  mImage = image;
70 
71  if (mImage)
72  {
73  connect(mImage.get(), SIGNAL(vtkImageDataChanged()), this, SLOT(transferFunctionsChangedSlot()));
74  connect(mImage.get(), SIGNAL(transferFunctionsChanged()), this, SLOT(transferFunctionsChangedSlot()));
75  }
76 
77  this->transferFunctionsChangedSlot();
78 }
79 
80 void VolumeProperty::transferFunctionsChangedSlot()
81 {
82  if (!mImage)
83  return;
84 
85  mVolumeProperty->SetColor(mImage->getTransferFunctions3D()->getColorTF());
86  mVolumeProperty->SetScalarOpacity(mImage->getTransferFunctions3D()->getOpacityTF());
87  mVolumeProperty->SetShade(mImage->getShadingOn());
88 
89  mVolumeProperty->SetAmbient(mImage->getShadingAmbient());
90  mVolumeProperty->SetDiffuse(mImage->getShadingDiffuse());
91  mVolumeProperty->SetSpecular(mImage->getShadingSpecular());
92  mVolumeProperty->SetSpecularPower(mImage->getShadingSpecularPower());
93 
94  mVolumeProperty->SetInterpolationType(mImage->getInterpolationType());
95 }
96 
97 } // namespace cx
98 
99 
vtkSmartPointer< class vtkVolumeProperty > vtkVolumePropertyPtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
vtkSmartPointer< class vtkPiecewiseFunction > vtkPiecewiseFunctionPtr
vtkSmartPointer< class vtkColorTransferFunction > vtkColorTransferFunctionPtr
vtkVolumePropertyPtr getVolumeProperty()
void setImage(ImagePtr image)
Namespace for all CustusX production code.