CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxThresholdPreview.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 #include "cxThresholdPreview.h"
34 #include <vtkVolume.h>
35 #include <vtkVolumeProperty.h>
36 #include "cxImageTF3D.h"
37 #include "cxImageLUT2D.h"
38 #include "cxVolumetricRep.h"
39 #include "cxImage.h"
40 
41 
42 namespace cx
43 {
44 
48 
50  mShadingOn_original(false)
51 {
52 }
53 
54 void ThresholdPreview::revertTransferFunctions()
55 {
56  if (!mModifiedImage)
57  return;
58 
59  mModifiedImage->setLookupTable2D(mTF2D_original);
60  mModifiedImage->setTransferFunctions3D(mTF3D_original);
61  mModifiedImage->setShadingOn(mShadingOn_original);
62 
63  mModifiedImage->setInterpolationTypeToLinear();
64 
65  mTF3D_original.reset();
66  mTF2D_original.reset();
67  mModifiedImage.reset();
68 }
69 
70 
71 void ThresholdPreview::setPreview(ImagePtr image, double lower)
72 {
73  if (!image)
74  return;
75 
76  this->setPreview(image, Eigen::Vector2d(lower, image->getMax()));
77 }
78 
87 void ThresholdPreview::setPreview(ImagePtr image, const Eigen::Vector2d& threshold)
88 {
89  if (!image)
90  return;
91 
92  if (image!=mModifiedImage)
93  this->removePreview();
94 
95  this->storeOriginalTransferfunctions(image);
96  image->resetTransferFunctions();
97 
98  ImageTF3DPtr tf3D = image->getTransferFunctions3D();
99 
100  double lower = threshold[0];
101  double upper = threshold[1];
102 
103  ColorMap colors;
104  colors[lower] = Qt::green;
105  colors[image->getMax()] = Qt::green;
106  tf3D->resetColor(colors);
107 
108  IntIntMap opacity;
109  opacity[lower - 1] = 0;
110  opacity[lower] = image->getMaxAlphaValue();
111  opacity[upper] = image->getMaxAlphaValue();
112  opacity[upper + 1] = 0;
113  tf3D->resetAlpha(opacity);
114 
115  image->setShadingOn(true);
116 
117  ImageLUT2DPtr lut2D = image->getLookupTable2D();
118  colors.clear();
119  colors[lower] = Qt::green;
120  colors[image->getMax()] = Qt::green;
121  lut2D->resetColor(colors);
122  lut2D->setLLR(lower);
123 
124  //Remove VTK linear interpolation
125  mModifiedImage->setInterpolationTypeToNearest();
126 }
127 
129 {
130 // std::cout << "ThresholdPreview::removePreview " << std::endl;
131  this->revertTransferFunctions();
132 }
133 
134 void ThresholdPreview::storeOriginalTransferfunctions(ImagePtr image)
135 {
136  if (!mModifiedImage)
137  {
138  mModifiedImage = image;
139  mTF3D_original = image->getTransferFunctions3D()->createCopy();
140  mTF2D_original = image->getLookupTable2D()->createCopy();
141  mShadingOn_original = image->getShadingOn();
142  }
143 }
144 
145 }
std::map< int, QColor > ColorMap
Definition: cxImageTFData.h:55
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
boost::shared_ptr< class ImageLUT2D > ImageLUT2DPtr
std::map< int, int > IntIntMap
Definition: cxImageTFData.h:54
void setPreview(ImagePtr image, double lower)
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr