]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/BrushFilter.cpp
3085a209b22683f968a0f910885bd5f6e32ab43f
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualPaint / BrushFilter.cpp
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "BrushFilter.h"
27
28 BrushFilter::BrushFilter() 
29 {
30         _brushsize = 1;
31         _brushform = 0; // 0 rectangle-cube  ,   1 circle-sphere
32         _brushtool = 0; // 0 pencil         ,   1 fill
33 }
34
35 //---------------------------------------------------------------------------
36 BrushFilter::~BrushFilter() // virtual
37 {
38 }
39
40 //---------------------------------------------------------------------------
41 void BrushFilter::FindMinMaxBrush(int &minX, int &maxX, int &minY, int &maxY,
42                 int &minZ, int &maxZ, int &size) 
43 {
44         size = _brushsize - 1;
45         minX = _px - size;
46         maxX = _px + size;
47         minY = _py - size;
48         maxY = _py + size;
49         minZ = _pz - size;
50         maxZ = _pz + size;
51
52         if (_2D3D == 0) //2D
53                         {
54                 if (_direction == 0) // YZ
55                                 {
56                         minX = _px;
57                         maxX = _px;
58                 }
59                 if (_direction == 1) // XZ
60                                 {
61                         minY = _py;
62                         maxY = _py;
63                 }
64                 if (_direction == 2) // XY
65                                 {
66                         minZ = _pz;
67                         maxZ = _pz;
68                 }
69         }
70
71         if (_2D3D == 1) // 3D
72                         {
73         }
74
75         if (minX < _minX) {
76                 minX = _minX;
77         }
78
79         if (minY < _minY) {
80                 minY = _minY;
81         }
82
83         if (minZ < _minZ) {
84                 minZ = _minZ;
85         }
86
87         if (maxX > _maxX) {
88                 maxX = _maxX;
89         }
90
91         if (maxY > _maxY) {
92                 maxY = _maxY;
93         }
94
95         if (maxZ > _maxZ) {
96                 maxZ = _maxZ;
97         }
98
99         //--
100         SetGeneralMinMax(minX, maxX, minY, maxY, minZ, maxZ);
101 }
102
103 //---------------------------------------------------------------------------
104 void BrushFilter::Run() // virtual
105 {
106         if (_image != NULL)
107         {
108                 float value = (float) _graylevel;
109                 int i, j, k;
110
111                 int size;
112                 int minX, maxX, minY, maxY, minZ, maxZ;
113                 FindMinMaxBrush(minX, maxX, minY, maxY, minZ, maxZ, size);
114
115                 double xx, yy, zz, rr = size * size;
116                 float scalarComponent;
117                 bool pixelModify;
118
119                 for (i = minX; i <= maxX; i++) 
120                 {
121                         xx = _px - i;
122                         xx = xx * xx;
123                         for (j = minY; j <= maxY; j++) 
124                         {
125                                 yy = _py - j;
126                                 yy = yy * yy;
127                                 for (k = minZ; k <= maxZ; k++) 
128                                 {
129                                         pixelModify=false;
130                                         scalarComponent = _image->GetScalarComponentAsFloat(i,j, k, 0);
131                                         if ((_RangeMin <= scalarComponent) && (scalarComponent <= _RangeMax )) 
132                                         {
133                                                 if (_brushform == 0) 
134                                                 {
135                                                         pixelModify=true;
136 //                                                      this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
137 //                                                      _image->SetScalarComponentFromFloat(i, j, k, 0,value);
138                                                 } // _brushform 0
139                                                 if (_brushform == 1) 
140                                                 {
141                                                         zz = _pz - k;
142                                                         zz = zz * zz;
143                                                         if ((xx + yy + zz) <= rr) {
144                                                                 pixelModify=true;
145 //                                                              this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
146 //                                                              _image->SetScalarComponentFromFloat(i, j, k, 0,value);
147                                                         }
148                                                 } // _brushform 1
149                                                 if (pixelModify==true)
150                                                 {
151                                                                 this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
152                                                                 if (_image2!=NULL)
153                                                                 {
154                                                                         _image2->SetScalarComponentFromFloat(i, j, k, 0,value);
155                                                                 }else {
156                                                                         _image->SetScalarComponentFromFloat(i, j, k, 0,value);
157                                                                 }
158                                                 } // if pixelModify
159                                         } //   GetRangeMin && GetRangeMax
160
161                                 } //for k
162                         } //for j
163                 } //for i
164                 _image->Modified();
165         } else {
166                 printf(
167                                 "ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
168         } // _image
169 }
170
171 //---------------------------------------------------------------------------
172 void BrushFilter::SetBrushSize(int brushsize) 
173 {
174         _brushsize = brushsize;
175 }
176
177 //---------------------------------------------------------------------------
178 void BrushFilter::SetBrushForm(int brushform) 
179 {
180         _brushform = brushform;
181 }
182
183 //---------------------------------------------------------------------------
184 void BrushFilter::SetBrushTool(int brushtool) 
185 {
186         _brushtool = brushtool;
187 }
188
189