[3773] | 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> |
---|
[3981] | 12 | #include <vtkImageSlice.h> |
---|
[3773] | 13 | #include <vtkImageActor.h> |
---|
| 14 | #include <vtkImageMapper3D.h> |
---|
[3981] | 15 | #include <vtkImageResliceMapper.h> |
---|
| 16 | #include <vtkImageSliceMapper.h> |
---|
[3773] | 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: |
---|
[4604] | 34 | enum InterpType { |
---|
| 35 | INTERP_NEAREST, |
---|
| 36 | INTERP_LINEAR, |
---|
| 37 | INTERP_CUBIC |
---|
| 38 | }; |
---|
| 39 | |
---|
[3773] | 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 | |
---|
[4604] | 54 | virtual void setAspect(double aspect); |
---|
| 55 | |
---|
[3773] | 56 | void updateColorMap() |
---|
| 57 | { |
---|
| 58 | setColorMap(_colorMap); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | void setColorMap(ColorMap *cmap); |
---|
| 62 | |
---|
| 63 | ColorMap *getColorMap() |
---|
| 64 | { |
---|
| 65 | return _colorMap; |
---|
| 66 | } |
---|
| 67 | |
---|
[4783] | 68 | void setSlicePlane(double normal[3], double origin[3]) |
---|
| 69 | { |
---|
| 70 | setSliceFollowsCamera(false); |
---|
| 71 | |
---|
| 72 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
| 73 | vtkImageResliceMapper *resliceMapper = vtkImageResliceMapper::SafeDownCast(mapper); |
---|
| 74 | if (resliceMapper != NULL) { |
---|
| 75 | vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New(); |
---|
| 76 | plane->SetNormal(normal); |
---|
| 77 | plane->SetOrigin(origin); |
---|
| 78 | resliceMapper->SetSlicePlane(plane); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | void setSliceFollowsCamera(bool state) |
---|
| 83 | { |
---|
| 84 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
| 85 | if (mapper != NULL) { |
---|
| 86 | mapper->SetSliceFacesCamera(state ? 1 : 0); |
---|
| 87 | mapper->SetSliceAtFocalPoint(state ? 1 : 0); |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void setJumpToNearestSlice(bool state) |
---|
| 92 | { |
---|
| 93 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
| 94 | vtkImageResliceMapper *resliceMapper = vtkImageResliceMapper::SafeDownCast(mapper); |
---|
| 95 | if (resliceMapper != NULL) { |
---|
| 96 | resliceMapper->SetJumpToNearestSlice(state ? 1 : 0); |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | |
---|
[3773] | 100 | void setExtents(int extent[6]) |
---|
| 101 | { |
---|
| 102 | vtkImageActor *actor = getImageActor(); |
---|
| 103 | if (actor == NULL) |
---|
| 104 | return; |
---|
| 105 | |
---|
| 106 | actor->SetDisplayExtent(extent); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | void setZSlice(int z) |
---|
| 110 | { |
---|
| 111 | vtkImageActor *actor = getImageActor(); |
---|
| 112 | if (actor == NULL) |
---|
| 113 | return; |
---|
| 114 | |
---|
[3961] | 115 | TRACE("before slice # %d, (%d,%d), whole z: (%d,%d)", |
---|
[3773] | 116 | actor->GetSliceNumber(), actor->GetSliceNumberMin(), actor->GetSliceNumberMax(), |
---|
| 117 | actor->GetZSlice(), actor->GetWholeZMin(), actor->GetWholeZMax()); |
---|
| 118 | |
---|
| 119 | actor->SetZSlice(z); |
---|
[3961] | 120 | |
---|
| 121 | TRACE("after slice # %d, (%d,%d), whole z: (%d,%d)", |
---|
| 122 | actor->GetSliceNumber(), actor->GetSliceNumberMin(), actor->GetSliceNumberMax(), |
---|
| 123 | actor->GetZSlice(), actor->GetWholeZMin(), actor->GetWholeZMax()); |
---|
[3773] | 124 | } |
---|
| 125 | |
---|
[4604] | 126 | void setUseWindowLevel(bool state) |
---|
| 127 | { |
---|
| 128 | vtkImageProperty *property = getImageProperty(); |
---|
| 129 | if (property == NULL) |
---|
| 130 | return; |
---|
| 131 | |
---|
| 132 | property->SetUseLookupTableScalarRange((state ? 0 : 1)); |
---|
| 133 | } |
---|
| 134 | |
---|
[3991] | 135 | double getWindow() |
---|
| 136 | { |
---|
| 137 | vtkImageProperty *property = getImageProperty(); |
---|
| 138 | if (property == NULL) |
---|
| 139 | return 0.0; |
---|
| 140 | |
---|
| 141 | return property->GetColorWindow(); |
---|
| 142 | } |
---|
| 143 | |
---|
[3773] | 144 | void setWindow(double window) |
---|
| 145 | { |
---|
| 146 | vtkImageProperty *property = getImageProperty(); |
---|
| 147 | if (property == NULL) |
---|
| 148 | return; |
---|
| 149 | |
---|
| 150 | property->SetColorWindow(window); |
---|
[4604] | 151 | property->UseLookupTableScalarRangeOff(); |
---|
[3773] | 152 | } |
---|
| 153 | |
---|
[3991] | 154 | double getLevel() |
---|
| 155 | { |
---|
| 156 | vtkImageProperty *property = getImageProperty(); |
---|
| 157 | if (property == NULL) |
---|
| 158 | return 0.0; |
---|
| 159 | |
---|
| 160 | return property->GetColorLevel(); |
---|
| 161 | } |
---|
| 162 | |
---|
[3773] | 163 | void setLevel(double level) |
---|
| 164 | { |
---|
| 165 | vtkImageProperty *property = getImageProperty(); |
---|
| 166 | if (property == NULL) |
---|
| 167 | return; |
---|
| 168 | |
---|
| 169 | property->SetColorLevel(level); |
---|
[4604] | 170 | property->UseLookupTableScalarRangeOff(); |
---|
[3773] | 171 | } |
---|
| 172 | |
---|
| 173 | void setBacking(bool state) |
---|
| 174 | { |
---|
| 175 | vtkImageProperty *property = getImageProperty(); |
---|
| 176 | if (property == NULL) |
---|
| 177 | return; |
---|
| 178 | |
---|
| 179 | property->SetBacking((state ? 1 : 0)); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | void setBorder(bool state) |
---|
| 183 | { |
---|
| 184 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
| 185 | if (mapper == NULL) |
---|
| 186 | return; |
---|
| 187 | |
---|
| 188 | mapper->SetBorder((state ? 1 : 0)); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | void setBackground(bool state) |
---|
| 192 | { |
---|
| 193 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
| 194 | if (mapper == NULL) |
---|
| 195 | return; |
---|
| 196 | |
---|
| 197 | mapper->SetBackground((state ? 1 : 0)); |
---|
| 198 | } |
---|
| 199 | |
---|
[4604] | 200 | void setInterpolationType(InterpType type) |
---|
| 201 | { |
---|
| 202 | vtkImageProperty *property = getImageProperty(); |
---|
| 203 | if (property == NULL) |
---|
| 204 | return; |
---|
| 205 | |
---|
| 206 | switch (type) { |
---|
| 207 | case INTERP_NEAREST: |
---|
| 208 | property->SetInterpolationTypeToNearest(); |
---|
| 209 | break; |
---|
| 210 | case INTERP_LINEAR: |
---|
| 211 | property->SetInterpolationTypeToLinear(); |
---|
| 212 | break; |
---|
| 213 | case INTERP_CUBIC: |
---|
| 214 | property->SetInterpolationTypeToCubic(); |
---|
| 215 | break; |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | |
---|
[3773] | 219 | private: |
---|
| 220 | virtual void update(); |
---|
| 221 | |
---|
| 222 | vtkImageProperty *getImageProperty() |
---|
| 223 | { |
---|
[3981] | 224 | if (getImageSlice() != NULL) { |
---|
| 225 | return getImageSlice()->GetProperty(); |
---|
[3773] | 226 | } else { |
---|
| 227 | return NULL; |
---|
| 228 | } |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | vtkImageMapper3D *getImageMapper() |
---|
| 232 | { |
---|
[3981] | 233 | if (getImageSlice() != NULL) { |
---|
| 234 | return getImageSlice()->GetMapper(); |
---|
[3773] | 235 | } else { |
---|
| 236 | return NULL; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | |
---|
[3981] | 240 | vtkImageResliceMapper *getImageResliceMapper() |
---|
| 241 | { |
---|
| 242 | if (getImageSlice() != NULL) { |
---|
| 243 | return vtkImageResliceMapper::SafeDownCast(getImageSlice()->GetMapper()); |
---|
| 244 | } else { |
---|
| 245 | return NULL; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | vtkImageSliceMapper *getImageSliceMapper() |
---|
| 250 | { |
---|
| 251 | if (getImageSlice() != NULL) { |
---|
| 252 | return vtkImageSliceMapper::SafeDownCast(getImageSlice()->GetMapper()); |
---|
| 253 | } else { |
---|
| 254 | return NULL; |
---|
| 255 | } |
---|
| 256 | } |
---|
| 257 | |
---|
[3773] | 258 | ColorMap *_colorMap; |
---|
| 259 | |
---|
| 260 | vtkSmartPointer<vtkLookupTable> _lut; |
---|
| 261 | }; |
---|
| 262 | |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | #endif |
---|