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 <vtkImageActor.h> |
---|
13 | #include <vtkImageMapper3D.h> |
---|
14 | #include <vtkLookupTable.h> |
---|
15 | #include <vtkPlaneCollection.h> |
---|
16 | |
---|
17 | #include "ColorMap.h" |
---|
18 | #include "GraphicsObject.h" |
---|
19 | #include "DataSet.h" |
---|
20 | #include "Trace.h" |
---|
21 | |
---|
22 | namespace VtkVis { |
---|
23 | |
---|
24 | /** |
---|
25 | * \brief Image Slicer |
---|
26 | * |
---|
27 | */ |
---|
28 | class Image : public GraphicsObject |
---|
29 | { |
---|
30 | public: |
---|
31 | Image(); |
---|
32 | virtual ~Image(); |
---|
33 | |
---|
34 | virtual const char *getClassName() const |
---|
35 | { |
---|
36 | return "Image"; |
---|
37 | } |
---|
38 | |
---|
39 | virtual void initProp(); |
---|
40 | |
---|
41 | virtual void setColor(float color[3]); |
---|
42 | |
---|
43 | virtual void setClippingPlanes(vtkPlaneCollection *planes); |
---|
44 | |
---|
45 | void updateColorMap() |
---|
46 | { |
---|
47 | setColorMap(_colorMap); |
---|
48 | } |
---|
49 | |
---|
50 | void setColorMap(ColorMap *cmap); |
---|
51 | |
---|
52 | ColorMap *getColorMap() |
---|
53 | { |
---|
54 | return _colorMap; |
---|
55 | } |
---|
56 | |
---|
57 | void setExtents(int extent[6]) |
---|
58 | { |
---|
59 | vtkImageActor *actor = getImageActor(); |
---|
60 | if (actor == NULL) |
---|
61 | return; |
---|
62 | |
---|
63 | actor->SetDisplayExtent(extent); |
---|
64 | } |
---|
65 | |
---|
66 | void setZSlice(int z) |
---|
67 | { |
---|
68 | vtkImageActor *actor = getImageActor(); |
---|
69 | if (actor == NULL) |
---|
70 | return; |
---|
71 | |
---|
72 | TRACE("slice # %d, (%d,%d), whole z: (%d,%d)", |
---|
73 | actor->GetSliceNumber(), actor->GetSliceNumberMin(), actor->GetSliceNumberMax(), |
---|
74 | actor->GetZSlice(), actor->GetWholeZMin(), actor->GetWholeZMax()); |
---|
75 | |
---|
76 | actor->SetZSlice(z); |
---|
77 | } |
---|
78 | |
---|
79 | void setWindow(double window) |
---|
80 | { |
---|
81 | vtkImageProperty *property = getImageProperty(); |
---|
82 | if (property == NULL) |
---|
83 | return; |
---|
84 | |
---|
85 | property->SetColorWindow(window); |
---|
86 | } |
---|
87 | |
---|
88 | void setLevel(double level) |
---|
89 | { |
---|
90 | vtkImageProperty *property = getImageProperty(); |
---|
91 | if (property == NULL) |
---|
92 | return; |
---|
93 | |
---|
94 | property->SetColorLevel(level); |
---|
95 | } |
---|
96 | |
---|
97 | void setWindowAndLevel(double window, double level) |
---|
98 | { |
---|
99 | vtkImageProperty *property = getImageProperty(); |
---|
100 | if (property == NULL) |
---|
101 | return; |
---|
102 | |
---|
103 | property->SetColorWindow(window); |
---|
104 | property->SetColorLevel(level); |
---|
105 | } |
---|
106 | |
---|
107 | void setBacking(bool state) |
---|
108 | { |
---|
109 | vtkImageProperty *property = getImageProperty(); |
---|
110 | if (property == NULL) |
---|
111 | return; |
---|
112 | |
---|
113 | property->SetBacking((state ? 1 : 0)); |
---|
114 | } |
---|
115 | |
---|
116 | void setBorder(bool state) |
---|
117 | { |
---|
118 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
119 | if (mapper == NULL) |
---|
120 | return; |
---|
121 | |
---|
122 | mapper->SetBorder((state ? 1 : 0)); |
---|
123 | } |
---|
124 | |
---|
125 | void setBackground(bool state) |
---|
126 | { |
---|
127 | vtkImageMapper3D *mapper = getImageMapper(); |
---|
128 | if (mapper == NULL) |
---|
129 | return; |
---|
130 | |
---|
131 | mapper->SetBackground((state ? 1 : 0)); |
---|
132 | } |
---|
133 | |
---|
134 | private: |
---|
135 | virtual void update(); |
---|
136 | |
---|
137 | vtkImageProperty *getImageProperty() |
---|
138 | { |
---|
139 | if (getImageActor() != NULL) { |
---|
140 | return getImageActor()->GetProperty(); |
---|
141 | } else { |
---|
142 | return NULL; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | vtkImageMapper3D *getImageMapper() |
---|
147 | { |
---|
148 | if (getImageActor() != NULL) { |
---|
149 | return getImageActor()->GetMapper(); |
---|
150 | } else { |
---|
151 | return NULL; |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | ColorMap *_colorMap; |
---|
156 | |
---|
157 | vtkSmartPointer<vtkLookupTable> _lut; |
---|
158 | }; |
---|
159 | |
---|
160 | } |
---|
161 | |
---|
162 | #endif |
---|