]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/BrushFilter.cpp
#2864 creaMaracasVisu Feature New Normal - Manual Paint , modify external image
[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         _brushsize = 1;
30         _brushform = 0; // 0 rectangle-cube  ,   1 circle-sphere
31         _brushtool = 0; // 0 pencil         ,   1 fill
32 }
33
34 //---------------------------------------------------------------------------
35 BrushFilter::~BrushFilter() // virtual
36 {
37 }
38
39 //---------------------------------------------------------------------------
40 void BrushFilter::FindMinMaxBrush(int &minX, int &maxX, int &minY, int &maxY,
41                 int &minZ, int &maxZ, int &size) {
42         size = _brushsize - 1;
43         minX = _px - size;
44         maxX = _px + size;
45         minY = _py - size;
46         maxY = _py + size;
47         minZ = _pz - size;
48         maxZ = _pz + size;
49
50         if (_2D3D == 0) //2D
51                         {
52                 if (_direction == 0) // YZ
53                                 {
54                         minX = _px;
55                         maxX = _px;
56                 }
57                 if (_direction == 1) // XZ
58                                 {
59                         minY = _py;
60                         maxY = _py;
61                 }
62                 if (_direction == 2) // XY
63                                 {
64                         minZ = _pz;
65                         maxZ = _pz;
66                 }
67         }
68
69         if (_2D3D == 1) // 3D
70                         {
71         }
72
73         if (minX < _minX) {
74                 minX = _minX;
75         }
76
77         if (minY < _minY) {
78                 minY = _minY;
79         }
80
81         if (minZ < _minZ) {
82                 minZ = _minZ;
83         }
84
85         if (maxX > _maxX) {
86                 maxX = _maxX;
87         }
88
89         if (maxY > _maxY) {
90                 maxY = _maxY;
91         }
92
93         if (maxZ > _maxZ) {
94                 maxZ = _maxZ;
95         }
96
97         //--
98         SetGeneralMinMax(minX, maxX, minY, maxY, minZ, maxZ);
99 }
100
101 //---------------------------------------------------------------------------
102 void BrushFilter::Run() // virtual
103 {
104         if (_image != NULL)
105         {
106                 float value = (float) _graylevel;
107                 int i, j, k;
108
109                 int size;
110                 int minX, maxX, minY, maxY, minZ, maxZ;
111                 FindMinMaxBrush(minX, maxX, minY, maxY, minZ, maxZ, size);
112
113                 double xx, yy, zz, rr = size * size;
114                 float scalarComponent;
115                 bool pixelModify;
116
117                 for (i = minX; i <= maxX; i++) 
118                 {
119                         xx = _px - i;
120                         xx = xx * xx;
121                         for (j = minY; j <= maxY; j++) 
122                         {
123                                 yy = _py - j;
124                                 yy = yy * yy;
125                                 for (k = minZ; k <= maxZ; k++) 
126                                 {
127                                         pixelModify=false;
128                                         scalarComponent = _image->GetScalarComponentAsFloat(i,j, k, 0);
129                                         if ((_RangeMin <= scalarComponent)
130                                                         && (scalarComponent <= _RangeMax )) 
131                                         {
132                                                 if (_brushform == 0) 
133                                                 {
134                                                         pixelModify=true;
135 //                                                      this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
136 //                                                      _image->SetScalarComponentFromFloat(i, j, k, 0,value);
137                                                 } // _brushform 0
138                                                 if (_brushform == 1) 
139                                                 {
140                                                         zz = _pz - k;
141                                                         zz = zz * zz;
142                                                         if ((xx + yy + zz) <= rr) {
143                                                                 pixelModify=true;
144 //                                                              this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
145 //                                                              _image->SetScalarComponentFromFloat(i, j, k, 0,value);
146                                                         }
147                                                 } // _brushform 1
148                                                 if (pixelModify==true)
149                                                 {
150                                                                 this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
151                                                                 if (_image2!=NULL)
152                                                                 {
153                                                                         _image2->SetScalarComponentFromFloat(i, j, k, 0,value);
154                                                                 }else {
155                                                                         _image->SetScalarComponentFromFloat(i, j, k, 0,value);
156                                                                 }
157                                                 } // if pixelModify
158                                         } //   GetRangeMin && GetRangeMax
159
160                                 } //for k
161                         } //for j
162                 } //for i
163                 _image->Modified();
164         } else {
165                 printf(
166                                 "ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
167         } // _image
168 }
169
170 //---------------------------------------------------------------------------
171 void BrushFilter::SetBrushSize(int brushsize) 
172 {
173         _brushsize = brushsize;
174 }
175
176 //---------------------------------------------------------------------------
177 void BrushFilter::SetBrushForm(int brushform) 
178 {
179         _brushform = brushform;
180 }
181
182 //---------------------------------------------------------------------------
183 void BrushFilter::SetBrushTool(int brushtool) 
184 {
185         _brushtool = brushtool;
186 }
187
188