]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/BrushFilter.cpp
DFCH: Manualpaint + imageUndoRedo Big changes, new class for the management of the...
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualPaint / BrushFilter.cpp
1 #include "BrushFilter.h"
2
3 BrushFilter::BrushFilter() {
4         _brushsize = 1;
5         _brushform = 0; // 0 rectangle-box  ,   1 circle-sphere
6         _brushtool = 0; // 0 pencil         ,   1 fill
7 }
8
9 //---------------------------------------------------------------------------
10 BrushFilter::~BrushFilter() // virtual
11 {
12 }
13
14 //---------------------------------------------------------------------------
15 void BrushFilter::FindMinMaxBrush(int &minX, int &maxX, int &minY, int &maxY,
16                 int &minZ, int &maxZ, int &size) {
17         size = _brushsize - 1;
18         minX = _px - size;
19         maxX = _px + size;
20         minY = _py - size;
21         maxY = _py + size;
22         minZ = _pz - size;
23         maxZ = _pz + size;
24
25         if (_2D3D == 0) //2D
26                         {
27                 if (_direction == 0) // YZ
28                                 {
29                         minX = _px;
30                         maxX = _px;
31                 }
32                 if (_direction == 1) // XZ
33                                 {
34                         minY = _py;
35                         maxY = _py;
36                 }
37                 if (_direction == 2) // XY
38                                 {
39                         minZ = _pz;
40                         maxZ = _pz;
41                 }
42         }
43
44         if (_2D3D == 1) // 3D
45                         {
46         }
47
48         if (minX < _minX) {
49                 minX = _minX;
50         }
51
52         if (minY < _minY) {
53                 minY = _minY;
54         }
55
56         if (minZ < _minZ) {
57                 minZ = _minZ;
58         }
59
60         if (maxX > _maxX) {
61                 maxX = _maxX;
62         }
63
64         if (maxY > _maxY) {
65                 maxY = _maxY;
66         }
67
68         if (maxZ > _maxZ) {
69                 maxZ = _maxZ;
70         }
71
72         //--
73         SetGeneralMinMax(minX, maxX, minY, maxY, minZ, maxZ);
74 }
75
76 //---------------------------------------------------------------------------
77 void BrushFilter::Run() // virtual
78 {
79         if (_image != NULL)
80         {
81                 float value = (float) _graylevel;
82                 int i, j, k;
83
84                 int size;
85                 int minX, maxX, minY, maxY, minZ, maxZ;
86                 FindMinMaxBrush(minX, maxX, minY, maxY, minZ, maxZ, size);
87
88                 double xx, yy, zz, rr = size * size;
89
90                 for (i = minX; i <= maxX; i++) {
91                         xx = _px - i;
92                         xx = xx * xx;
93                         for (j = minY; j <= maxY; j++) {
94                                 yy = _py - j;
95                                 yy = yy * yy;
96                                 for (k = minZ; k <= maxZ; k++) {
97 //                    if ((i>=_minX) && (i<=_maxX) && (j>=_minY) && (j<=_maxY) && (k>=_minZ) && (k<=_maxZ))
98 //                    {
99
100                                         float scalarComponent = _image->GetScalarComponentAsFloat(i,
101                                                         j, k, 0);
102                                         if ((this->GetRangeMin() <= scalarComponent)
103                                                         && (scalarComponent <= this->GetRangeMax())) {
104                                                 zz = _pz - k;
105                                                 zz = zz * zz;
106                                                 if (_brushform == 0) {
107                                                         this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
108                                                         _image->SetScalarComponentFromFloat(i, j, k, 0,
109                                                                         value);
110                                                 } else if (_brushform == 1) {
111                                                         if ((xx + yy + zz) <= rr) {
112                                                                 this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
113                                                                 _image->SetScalarComponentFromFloat(i, j, k, 0,
114                                                                                 value);
115                                                         }
116                                                 } // _brushform
117                                         } //   GetRangeMin && GetRangeMax
118
119 //                    } //if _minX _maxX _minY _maxY _minZ _maxZ
120
121                                 } //k
122                         } //j
123                 } //i
124                 _image->Modified();
125         } else {
126                 printf(
127                                 "ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
128         } // _image
129 }
130
131 //---------------------------------------------------------------------------
132 void BrushFilter::SetBrushSize(int brushsize) {
133         _brushsize = brushsize;
134 }
135
136 //---------------------------------------------------------------------------
137 void BrushFilter::SetBrushForm(int brushform) {
138         _brushform = brushform;
139 }
140
141 //---------------------------------------------------------------------------
142 void BrushFilter::SetBrushTool(int brushtool) {
143         _brushtool = brushtool;
144 }
145
146 //---------------------------------------------------------------------------
147 void BrushFilter::SetRangeMin(int min) {
148         _RangeMin = min;
149 }
150
151 //---------------------------------------------------------------------------
152 void BrushFilter::SetRangeMax(int max) {
153         _RangeMax = max;
154 }
155
156 //---------------------------------------------------------------------------
157 int BrushFilter::GetRangeMin() {
158         return (_RangeMin);
159 }
160
161 //---------------------------------------------------------------------------
162 int BrushFilter::GetRangeMax() {
163         return (_RangeMax);
164 }
165