]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/BrushFilter.cpp
#3332 creaContours Bug New - Manual Paint UnDo ReDo with vtk update (working)
[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 &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         } // _2D3D
70
71         if (_2D3D == 1) {  }  // 3D 
72
73         if (minX < _minX) { minX = _minX; }
74         if (minY < _minY) { minY = _minY; }
75
76         if (minZ < _minZ) { minZ = _minZ; }
77         if (maxX > _maxX) { maxX = _maxX; }
78         if (maxY > _maxY) { maxY = _maxY; }
79         if (maxZ > _maxZ) { maxZ = _maxZ; }
80
81         //--
82         SetGeneralMinMax(minX, maxX, minY, maxY, minZ, maxZ);
83 }
84
85 //---------------------------------------------------------------------------
86 void BrushFilter::Run() // virtual
87 {
88         if (_image != NULL)
89         {
90                 float value = (float) _graylevel;
91                 int i, j, k;
92
93                 int size;
94                 int minX, maxX, minY, maxY, minZ, maxZ;
95                 FindMinMaxBrush(minX, maxX, minY, maxY, minZ, maxZ, size);
96
97                 double xx, yy, zz, rr = size * size;
98                 float scalarComponent;
99                 bool pixelModify;
100
101                 for (i = minX; i <= maxX; i++) 
102                 {
103                         xx = _px - i;
104                         xx = xx * xx;
105                         for (j = minY; j <= maxY; j++) 
106                         {
107                                 yy = _py - j;
108                                 yy = yy * yy;
109                                 for (k = minZ; k <= maxZ; k++) 
110                                 {
111                                         pixelModify=false;
112                                         scalarComponent = _image->GetScalarComponentAsFloat(i,j, k, 0);
113                                         if ((_RangeMin <= scalarComponent) && (scalarComponent <= _RangeMax )) 
114                                         {
115                                                 if (_brushform == 0) 
116                                                 {
117                                                         pixelModify=true;
118 //                                                      this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
119 //                                                      _image->SetScalarComponentFromFloat(i, j, k, 0,value);
120                                                 } // _brushform 0
121                                                 if (_brushform == 1) 
122                                                 {
123                                                         zz = _pz - k;
124                                                         zz = zz * zz;
125                                                         if ((xx + yy + zz) <= rr) {
126                                                                 pixelModify=true;
127 //                                                              this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
128 //                                                              _image->SetScalarComponentFromFloat(i, j, k, 0,value);
129                                                         }
130                                                 } // _brushform 1
131                                                 if (pixelModify==true)
132                                                 {
133                                                                 this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
134                                                                 if (_image2!=NULL)
135                                                                 {
136                                                                         _image2->SetScalarComponentFromFloat(i, j, k, 0,value);
137                                                                 }else {
138                                                                         _image->SetScalarComponentFromFloat(i, j, k, 0,value);
139                                                                 }
140                                                 } // if pixelModify
141                                         } //   GetRangeMin && GetRangeMax
142
143                                 } //for k
144                         } //for j
145                 } //for i
146                 _image->Modified();
147         } else {
148                 printf(
149                                 "ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
150         } // _image
151 }
152
153 //---------------------------------------------------------------------------
154 void BrushFilter::SetBrushSize(int brushsize) 
155 {
156         _brushsize = brushsize;
157 }
158
159 //---------------------------------------------------------------------------
160 void BrushFilter::SetBrushForm(int brushform) 
161 {
162         _brushform = brushform;
163 }
164
165 //---------------------------------------------------------------------------
166 void BrushFilter::SetBrushTool(int brushtool) 
167 {
168         _brushtool = brushtool;
169 }
170
171