Fraxinus  16.5.0-fx-rc3
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxImageTF3D.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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 /*
35  * sscImageTF3D.cpp
36  *
37  * Created on: Jan 9, 2009
38  * Author: christiana
39  */
40 
41 #include "cxImageTF3D.h"
42 
43 #include <vector>
44 #include <vtkImageData.h>
45 #include <vtkWindowLevelLookupTable.h>
46 #include <vtkColorTransferFunction.h>
47 #include <vtkPiecewiseFunction.h>
48 #include <vtkVolumeProperty.h>
49 #include <QColor>
50 #include <QDomDocument>
51 #include <QStringList>
52 #include "cxVector3D.h"
53 
54 #include "vtkForwardDeclarations.h"
55 #include "cxImageTF3D.h"
56 
57 #include "cxTypeConversions.h"
58 
59 namespace cx
60 {
61 
63 {
64 }
65 
66 //void ImageTF3D::setInitialTFFromImage(vtkImageDataPtr base)
67 //{
68 // double smin = base->GetScalarRange()[0];
69 // double smax = base->GetScalarRange()[1];
70 // double srange = smax - smin;
71 
72 // // set a winlevel spanning the entire range
75 // // set llr/alpha with full transmission
78 
83 
85 // mOpacityMap.clear();
86 // this->addAlphaPoint(smin - 1, 0);
87 // this->addAlphaPoint(smin + 0.1 * srange, 255.0 * 0.1);
88 // this->addAlphaPoint(smin + 0.4 * srange, 255.0 * 0.5);
90 // this->addAlphaPoint(smax, 255);
91 
92 // mColorMap.clear();
93 // this->addColorPoint(smin, Qt::black);
94 // this->addColorPoint(smax, Qt::white);
95 //}
96 
98 {
99  this->refreshOpacityTF();
100  this->refreshColorTF();
102 }
103 
105 {
106  ImageTF3DPtr retval(new ImageTF3D());
107  retval->deepCopy(this);
108  return retval;
109 }
110 
112 {
113  if (!mOpacityTF)
114  {
115  mOpacityTF = vtkPiecewiseFunctionPtr::New();
116  this->refreshOpacityTF();
117  }
118  return mOpacityTF;
119 }
120 
122 {
123  if (!mColorTF)
124  {
125  mColorTF = vtkColorTransferFunctionPtr::New();
126  this->refreshColorTF();
127  }
128  return mColorTF;
129 }
130 
134 void ImageTF3D::refreshColorTF()
135 {
136  if (!mColorTF)
137  return;
138  this->fillColorTFFromMap(mColorTF);
139 }
140 
143 void ImageTF3D::refreshOpacityTF()
144 {
145  if (!mOpacityTF)
146  return;
147  this->fillOpacityTFFromMap(mOpacityTF);
148 }
149 
153 void ImageTF3D::buildOpacityMapFromLLRAlpha()
154 {
155  // REMOVED CA 2014-02-07 - TODO
156  double range = this->getWindow();
157  int smooth = (int) (0.1 * range);
158 
159  mOpacityMap.clear();
160 // this->addAlphaPoint(this->getScalarMin(), 0);
161 // if (this->getLLR() > this->getScalarMin())
162  this->addAlphaPoint(this->getLLR() - 1, 0);
163  this->addAlphaPoint(this->getLLR() + 1 * smooth, this->getAlpha() * 255 * 1 / 10);
164  this->addAlphaPoint(this->getLLR() + 4 * smooth, this->getAlpha() * 255 * 5 / 10);
165  this->addAlphaPoint(this->getLLR() + 10 * smooth, this->getAlpha() * 255);
166 // this->addAlphaPoint(this->getScalarMax(), this->getAlpha() * 255);
167 }
168 
169 }
void transferFunctionsChanged()
IntIntMap mOpacityMap
double getLLR() const
vtkColorTransferFunctionPtr getColorTF()
void fillOpacityTFFromMap(vtkPiecewiseFunctionPtr tf) const
vtkSmartPointer< class vtkPiecewiseFunction > vtkPiecewiseFunctionPtr
double getAlpha() const
vtkSmartPointer< class vtkColorTransferFunction > vtkColorTransferFunctionPtr
virtual void internalsHaveChanged()
Definition: cxImageTF3D.cpp:97
void addAlphaPoint(int alphaPosition, int alphaValue)
Add point to the opacity transfer function.
double getWindow() const
ImageTF3DPtr createCopy()
vtkPiecewiseFunctionPtr getOpacityTF()
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
void fillColorTFFromMap(vtkColorTransferFunctionPtr tf) const