]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/BrushFilter.cpp
#2844 creaMaracasVisu Feature New Normal - ManualPaint_model box, Refresh TransferF...
[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
115 printf("EED BrushFilter::Run() %d  %d\n", _RangeMin, _RangeMax);
116
117                 for (i = minX; i <= maxX; i++) {
118                         xx = _px - i;
119                         xx = xx * xx;
120                         for (j = minY; j <= maxY; j++) {
121                                 yy = _py - j;
122                                 yy = yy * yy;
123                                 for (k = minZ; k <= maxZ; k++) {
124 //                    if ((i>=_minX) && (i<=_maxX) && (j>=_minY) && (j<=_maxY) && (k>=_minZ) && (k<=_maxZ))
125 //                    {
126
127                                         float scalarComponent = _image->GetScalarComponentAsFloat(i,j, k, 0);
128                                         if ((_RangeMin <= scalarComponent)
129                                                         && (scalarComponent <= _RangeMax )) {
130                                                 if (_brushform == 0) 
131                                                 {
132                                                         this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
133                                                         _image->SetScalarComponentFromFloat(i, j, k, 0,value);
134                                                 } // _brushform 0
135                                                 if (_brushform == 1) 
136                                                 {
137                                                         zz = _pz - k;
138                                                         zz = zz * zz;
139                                                         if ((xx + yy + zz) <= rr) {
140                                                                 this->_IMManager->AddModifiedPixel(i, j, k); //DFCH
141                                                                 _image->SetScalarComponentFromFloat(i, j, k, 0,value);
142                                                         }
143                                                 } // _brushform 1
144                                         } //   GetRangeMin && GetRangeMax
145
146 //                    } //if _minX _maxX _minY _maxY _minZ _maxZ
147
148                                 } //k
149                         } //j
150                 } //i
151                 _image->Modified();
152         } else {
153                 printf(
154                                 "ERROR : bbcreaMaracasvisu::vtkInteractorManualPaint::PaintImage :  Image not set. \n");
155         } // _image
156 }
157
158 //---------------------------------------------------------------------------
159 void BrushFilter::SetBrushSize(int brushsize) {
160         _brushsize = brushsize;
161 }
162
163 //---------------------------------------------------------------------------
164 void BrushFilter::SetBrushForm(int brushform) {
165         _brushform = brushform;
166 }
167
168 //---------------------------------------------------------------------------
169 void BrushFilter::SetBrushTool(int brushtool) {
170         _brushtool = brushtool;
171 }
172
173 //---------------------------------------------------------------------------
174 void BrushFilter::SetRangeMin(int min) {
175         _RangeMin = min;
176 }
177
178 //---------------------------------------------------------------------------
179 void BrushFilter::SetRangeMax(int max) {
180         _RangeMax = max;
181 }
182
183 //---------------------------------------------------------------------------
184 int BrushFilter::GetRangeMin() {
185         return _RangeMin;
186 }
187
188 //---------------------------------------------------------------------------
189 int BrushFilter::GetRangeMax() {
190         return _RangeMax;
191 }
192