1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
2 | /* |
---|
3 | * Copyright (C) 2004-2013 HUBzero Foundation, LLC |
---|
4 | * |
---|
5 | * Author: Leif Delgass <ldelgass@purdue.edu> |
---|
6 | */ |
---|
7 | |
---|
8 | #ifndef VTKVIS_IMAGE_H |
---|
9 | #define VTKVIS_IMAGE_H |
---|
10 | |
---|
11 | #include <vtkSmartPointer.h> |
---|
12 | #include <vtkImageSlice.h> |
---|
13 | #include <vtkImageActor.h> |
---|
14 | #include <vtkImageMapper3D.h> |
---|
15 | #include <vtkImageResliceMapper.h> |
---|
16 | #include <vtkImageSliceMapper.h> |
---|
17 | #include <vtkLookupTable.h> |
---|
18 | #include <vtkPlaneCollection.h> |
---|
19 | |
---|
20 | #include "ColorMap.h" |
---|
21 | #include "GraphicsObject.h" |
---|
22 | #include "DataSet.h" |
---|
23 | #include "Trace.h" |
---|
24 | |
---|
25 | namespace VtkVis { |
---|
26 | |
---|
27 | /** |
---|
28 | * \brief Image Slicer |
---|
29 | * |
---|
30 | */ |
---|
31 | class Image : public GraphicsObject |
---|
32 | { |
---|
33 | public: |
---|
34 | enum InterpType { |
---|
35 | INTERP_NEAREST, |
---|
36 | INTERP_LINEAR, |
---|
37 | INTERP_CUBIC |
---|
38 | }; |
---|
39 | |
---|
40 | Image(); |
---|
41 | virtual ~Image(); |
---|
42 | |
---|
43 | virtual const char *getClassName() const |
---|
44 | { |
---|
45 | return "Image"; |
---|
46 | } |
---|
47 | |
---|
48 | virtual void initProp(); |
---|
49 | |
---|
50 | virtual void setColor(float color[3]); |
---|
51 | |
---|
52 | virtual void setClippingPlanes(vtkPlaneCollection *planes); |
---|
53 | |
---|
54 | virtual void setAspect(double aspect); |
---|
55 | |
---|
56 | void updateColorMap() |
---|
57 | { |
---|
58 | setColorMap(_colorMap); |
---|
59 | } |
---|
60 | |
---|
61 | void setColorMap(ColorMap *cmap); |
---|
62 | |
---|
63 | ColorMap *getColorMap() |
---|
64 | { |
---|
65 | return _colorMap; |
---|
66 | } |
---|
67 | |
---|
68 | void setExtents(int extent[6]) |
---|
69 | { |
---|
70 | vtkImageActor *actor = getImageActor(); |
---|
71 | if (actor == NULL) |
---|
72 | return; |
---|
73 | |
---|
74 | actor->SetDisplayExtent(extent); |
---|
75 | } |
---|
76 | |
---|
77 | void setZSlice(int z) |
---|
78 | { |
---|
79 | vtkImageActor *actor = getImageActor(); |
---|
80 | if (actor == NULL) |
---|
81 | return; |
---|
82 | |
---|
83 | TRACE("before slice # %d, (%d,%d), whole z: (%d,%d)", |
---|
84 | actor->GetSliceNumber(), actor->GetSliceNumberMin(), actor->GetSliceNumberMax(), |
---|
85 | actor->GetZSlice(), actor->GetWholeZMin(), actor->GetWholeZMax()); |
---|
86 | |
---|
87 | actor->SetZSlice(z); |
---|
88 | |
---|
89 | TRACE("after slice # %d, (%d,%d), whole z: (%d,%d)", |
---|
90 | actor->GetSliceNumber(), actor->GetSliceNumberMin(), actor->GetSliceNumberMax(), |
---|
91 | actor->GetZSlice(), actor->GetWholeZMin(), actor->GetWholeZMax()); |
---|
92 | } |
---|
93 | |
---|
94 | void setUseWindowLevel(bool state) |
---|
95 | { |
---|
96 | vtkImageProperty *property = getImageProperty(); |
---|
97 | if (property == NULL) |
---|
98 | return; |
---|
99 | |
---|
100 | property->SetUseLookupTableScalarRange((state ? 0 : 1)); |
---|
101 | } |
---|
102 | |
---|
103 | double getWindow() |
---|
104 | { |
---|
105 | vtkImageProperty *property = getImageProperty(); |
---|
106 | if (property == NULL) |
---|
107 | return 0.0; |
---|
108 | |
---|
109 | return property->GetColorWindow(); |
---|
110 | } |
---|
111 | |
---|
112 | void setWindow(double window) |
---|
113 | { |
---|
114 | vtkImageProperty *property = getImageProperty(); |
---|
115 | if (property == NULL) |
---|
116 | return; |
---|
117 | |
---|
118 | property->SetColorWindow(window); |
---|
119 | property->UseLookupTableScalarRangeOff(); |
---|
120 | } |
---|
121 | |
---|
122 | double getLevel() |
---|
123 | { |
---|
124 | vtkImageProperty *property = getImageProperty(); |
---|
125 | if (property == NULL) |
---|
126 | return 0.0; |
---|
127 | |
---|
128 | return property->GetColorLevel(); |
---|
129 | } |
---|
130 | |
---|
131 | void setLevel(double level) |
---|
132 | { |
---|
133 | vtkImageProperty *property = getImageProperty(); |
---|
134 | if (property == NULL) |
---|
135 | return; |
---|
136 | |
---|
137 | property->SetColorLevel(level); |
---|
138 | property->UseLookupTableScalarRangeOff(); |
---|
139 | } |
---|
140 | |
---|
141 | void setBacking(bool state) |
---|
142 | { |
---|
143 | vtkImageProperty *property = getImageProperty(); |
---|
144 | if (property == NULL) |
---|
145 | return; |
---|
146 | |
---|
147 | property->SetBacking((state ? 1 : 0)); |
---|
148 | } |
---|
149 | |
---|
150 | void setBorder(bool state) |
---|
151 | { |
---|
152 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
153 | if (mapper == NULL) |
---|
154 | return; |
---|
155 | |
---|
156 | mapper->SetBorder((state ? 1 : 0)); |
---|
157 | } |
---|
158 | |
---|
159 | void setBackground(bool state) |
---|
160 | { |
---|
161 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
162 | if (mapper == NULL) |
---|
163 | return; |
---|
164 | |
---|
165 | mapper->SetBackground((state ? 1 : 0)); |
---|
166 | } |
---|
167 | |
---|
168 | void setInterpolationType(InterpType type) |
---|
169 | { |
---|
170 | vtkImageProperty *property = getImageProperty(); |
---|
171 | if (property == NULL) |
---|
172 | return; |
---|
173 | |
---|
174 | switch (type) { |
---|
175 | case INTERP_NEAREST: |
---|
176 | property->SetInterpolationTypeToNearest(); |
---|
177 | break; |
---|
178 | case INTERP_LINEAR: |
---|
179 | property->SetInterpolationTypeToLinear(); |
---|
180 | break; |
---|
181 | case INTERP_CUBIC: |
---|
182 | property->SetInterpolationTypeToCubic(); |
---|
183 | break; |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | private: |
---|
188 | virtual void update(); |
---|
189 | |
---|
190 | vtkImageProperty *getImageProperty() |
---|
191 | { |
---|
192 | if (getImageSlice() != NULL) { |
---|
193 | return getImageSlice()->GetProperty(); |
---|
194 | } else { |
---|
195 | return NULL; |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | vtkImageMapper3D *getImageMapper() |
---|
200 | { |
---|
201 | if (getImageSlice() != NULL) { |
---|
202 | return getImageSlice()->GetMapper(); |
---|
203 | } else { |
---|
204 | return NULL; |
---|
205 | } |
---|
206 | } |
---|
207 | |
---|
208 | vtkImageResliceMapper *getImageResliceMapper() |
---|
209 | { |
---|
210 | if (getImageSlice() != NULL) { |
---|
211 | return vtkImageResliceMapper::SafeDownCast(getImageSlice()->GetMapper()); |
---|
212 | } else { |
---|
213 | return NULL; |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | vtkImageSliceMapper *getImageSliceMapper() |
---|
218 | { |
---|
219 | if (getImageSlice() != NULL) { |
---|
220 | return vtkImageSliceMapper::SafeDownCast(getImageSlice()->GetMapper()); |
---|
221 | } else { |
---|
222 | return NULL; |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | ColorMap *_colorMap; |
---|
227 | |
---|
228 | vtkSmartPointer<vtkLookupTable> _lut; |
---|
229 | }; |
---|
230 | |
---|
231 | } |
---|
232 | |
---|
233 | #endif |
---|