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