]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/BrushFilter.cpp
#3418 creaMaracasVisu Feature New Normal - ManualPaint_model with openmp
[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 = 5;
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 px, int py, int pz,int &minX, int &maxX, int &minY, int &maxY,
42                 int &minZ, int &maxZ, int &size) 
43 {
44         size = _brushsize - 1;
45 //EED 2020-04-28  BORRAME Change to local variables to use with openmp
46 /*
47         minX = _px - size;
48         maxX = _px + size;
49         minY = _py - size;
50         maxY = _py + size;
51         minZ = _pz - size;
52         maxZ = _pz + size;
53         if (_2D3D == 0) //2D
54         {
55                 if (_direction == 0) // YZ
56                 {
57                         minX = _px;
58                         maxX = _px;
59                 }
60                 if (_direction == 1) // XZ
61                 {
62                         minY = _py;
63                         maxY = _py;
64                 }
65                 if (_direction == 2) // XY
66                 {
67                         minZ = _pz;
68                         maxZ = _pz;
69                 }
70         } // _2D3D
71 */
72         minX = px - size;
73         maxX = px + size;
74         minY = py - size;
75         maxY = py + size;
76         minZ = pz - size;
77         maxZ = pz + size;
78         if (_2D3D == 0) //2D
79         {
80                 if (_direction == 0) // YZ
81                 {
82                         minX = px;
83                         maxX = px;
84                 }
85                 if (_direction == 1) // XZ
86                 {
87                         minY = py;
88                         maxY = py;
89                 }
90                 if (_direction == 2) // XY
91                 {
92                         minZ = pz;
93                         maxZ = pz;
94                 }
95         } // _2D3D
96
97         if (_2D3D == 1) {  }  // 3D 
98
99         if (minX < _minX) { minX = _minX; }
100         if (minY < _minY) { minY = _minY; }
101         if (minZ < _minZ) { minZ = _minZ; }
102
103         if (maxX >= _dimX) { maxX = _dimX-1; }
104         if (maxY >= _dimY) { maxY = _dimY-1; }
105         if (maxZ >= _dimZ) { maxZ = _dimZ-1; }
106
107 //EED 2020-04-28  BORRAME Change to local variables to use with openmp
108 //      SetGeneralMinMax(minX, maxX, minY, maxY, minZ, maxZ);
109 }
110
111 //---------------------------------------------------------------------------
112 void BrushFilter::Run(int px, int py, int pz) // virtual
113 {
114         if (_image != NULL)
115         {
116 //EED 2020-04-28  BORRAME Change to local variables to use with openmp
117 //              this->_IMManager->BaseInitialPoint(_px, _py ,_pz);
118                 this->_IMManager->BaseInitialPoint(px, py ,pz);
119
120                 float value = (float) _graylevel;
121                 int i, j, k;
122
123                 int size;
124                 int minX, maxX, minY, maxY, minZ, maxZ;
125                 FindMinMaxBrush(px,py,pz,minX, maxX, minY, maxY, minZ, maxZ, size);
126
127                 double xx, yy, zz, rr = size * size;
128                 float scalarComponent;
129                 bool pixelModify;
130
131                 for (i = minX; i <= maxX; i++) 
132                 {
133 //EED 2020-04-28  BORRAME Change to local variables to use with openmp
134 //                      xx = _px - i;  
135                         xx = px - i;  
136                         xx = xx * xx;
137                         for (j = minY; j <= maxY; j++) 
138                         {
139 //EED 2020-04-28  BORRAME Change to local variables to use with openmp
140 //                              yy = _py - j;
141                                 yy = py - j;
142                                 yy = yy * yy;
143                                 for (k = minZ; k <= maxZ; k++) 
144                                 {
145                                         pixelModify=false;
146                                         scalarComponent = _image->GetScalarComponentAsFloat(i,j, k, 0);
147                                         if ((_RangeMin <= scalarComponent) && (scalarComponent <= _RangeMax )) 
148                                         {
149                                                 if (_brushform == 0) 
150                                                 {
151                                                         pixelModify=true;
152 //                                                      this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
153 //                                                      _image->SetScalarComponentFromFloat(i, j, k, 0,value);
154                                                 } // _brushform 0
155                                                 if (_brushform == 1) 
156                                                 {
157 //EED 2020-04-28  BORRAME Change to local variables to use with openmp
158 //                                                      zz = _pz - k;
159                                                         zz = pz - k;
160                                                         zz = zz * zz;
161                                                         if ((xx + yy + zz) <= rr) {
162                                                                 pixelModify=true;
163 //                                                              this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
164 //                                                              _image->SetScalarComponentFromFloat(i, j, k, 0,value);
165                                                         }
166                                                 } // _brushform 1
167                                                 if (pixelModify==true)
168                                                 {
169                                                                 this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
170                                                                 if (_image2!=NULL)
171                                                                 {
172                                                                         _image2->SetScalarComponentFromFloat(i, j, k, 0,value);
173                                                                 }else {
174                                                                         _image->SetScalarComponentFromFloat(i, j, k, 0,value);
175                                                                 }
176                                                 } // if pixelModify
177                                         } //   GetRangeMin && GetRangeMax
178
179                                 } //for k
180                         } //for j
181                 } //for i
182                 _image->Modified();
183         } else {
184                 printf(
185                                 "ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
186         } // _image
187 }
188
189 //---------------------------------------------------------------------------
190 void BrushFilter::SetBrushSize(int brushsize) 
191 {
192         _brushsize = brushsize;
193 }
194
195 //---------------------------------------------------------------------------
196 void BrushFilter::SetBrushForm(int brushform) 
197 {
198         _brushform = brushform;
199 }
200
201 //---------------------------------------------------------------------------
202 void BrushFilter::SetBrushTool(int brushtool) 
203 {
204         _brushtool = brushtool;
205 }
206
207