]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualPaint/ManualPaintModel.cpp
8736b835eba01931628c52d2a247cefabcc6d888
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualPaint / ManualPaintModel.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 "ManualPaintModel.h"
27
28 ManualPaintModel::ManualPaintModel() 
29 {
30         _active                 = true;
31         _tool                   = 0; // 0 pencil         ,   1 fill
32         _brushfilter    = new BrushFilter();
33         _fillfilter     = new FillFilter();
34         _imageUndoRedo  = new ImageUndoRedo();
35 }
36
37 //---------------------------------------------------------------------------
38 ManualPaintModel::~ManualPaintModel() 
39 {
40         delete _brushfilter;
41         delete _fillfilter;
42 }
43
44
45 //---------------------------------------------------------------------------
46 void ManualPaintModel::SetActive( bool active )
47 {
48   _active = active;
49 }
50
51 //---------------------------------------------------------------------------
52 void ManualPaintModel::PaintImage(int px, int py, int pz) 
53 {
54   if (_active==true)
55   {
56         if (_tool == 0) 
57         {
58                 _brushfilter->SetPoint(px, py, pz);
59                 _brushfilter->Run();
60         } // _tool 2
61         if (_tool == 1) 
62         {
63                 _fillfilter->SetPoint(px, py, pz);
64                 _fillfilter->Run();
65         } // _tool 1
66   } // _active
67 }
68
69 //---------------------------------------------------------------------------
70 void ManualPaintModel::SetTool(int tool) 
71 {
72         _tool = tool;
73 }
74
75 //---------------------------------------------------------------------------
76 void ManualPaintModel::Set2D3D(int dim2D3D) 
77 {
78         _brushfilter->Set2D3D(dim2D3D);
79         _fillfilter->Set2D3D(dim2D3D);
80 }
81
82 //---------------------------------------------------------------------------
83 void ManualPaintModel::SetImages(vtkImageData *image,vtkImageData *image2) 
84 {
85         if (image!=NULL)
86         {
87                 _brushfilter -> SetImages(image,image2);
88                 _fillfilter  -> SetImages(image,image2);
89                 _imageUndoRedo->SetImage(image);
90         } else {
91                 printf("EED Warning image=NULL in ManualPaintModel::SetImage(image)\n ");
92         }
93 }
94
95 //---------------------------------------------------------------------------
96 void ManualPaintModel::SetGrayLevel(double graylevel) 
97 {
98         _brushfilter->SetGrayLevel(graylevel);
99         _fillfilter->SetGrayLevel(graylevel);
100 }
101
102 //---------------------------------------------------------------------------
103 void ManualPaintModel::SetRangeMin(int min) 
104 {
105         _brushfilter->SetRangeMin(min);
106         _fillfilter->SetRangeMin(min);
107 }
108
109 //---------------------------------------------------------------------------
110 void ManualPaintModel::SetRangeMax(int max) 
111 {
112         _brushfilter->SetRangeMax(max);
113         _fillfilter->SetRangeMax(max);
114 }
115
116 //---------------------------------------------------------------------------
117 void ManualPaintModel::SetDirection(int direction) 
118 {
119         _brushfilter->SetDirection(direction);
120         _fillfilter->SetDirection(direction);
121 }
122
123 //---------------------------------------------------------------------------
124 void ManualPaintModel::SetBrushSize(int brushsize) 
125 {
126         _brushfilter->SetBrushSize(brushsize);
127 }
128
129 //---------------------------------------------------------------------------
130 void ManualPaintModel::SetBrushForm(int brushform) 
131 {
132         _brushfilter->SetBrushForm(brushform);
133 }
134
135 //---------------------------------------------------------------------------
136 void ManualPaintModel::SetToleranceFill(double tolerancefill) 
137 {
138         _fillfilter->SetToleranceFill(tolerancefill);
139 }
140
141 //---------------------------------------------------------------------------
142 void ManualPaintModel::SetDistanceFill(int distancefill) 
143 {
144         _fillfilter->SetDistanceFill(distancefill);
145 }
146
147 //---------------------------------------------------------------------------
148 void ManualPaintModel::GetScalarRange(double * range) 
149 {
150         _fillfilter->GetScalarRange(range);
151 }
152
153 //---------------------------------------------------------------------------
154 void ManualPaintModel::SetUndoImage() 
155 {
156         ImageMManager* imMManager = NULL;
157         if (_tool == 0) 
158         {
159                 imMManager = this->_brushfilter->GetImageMManager();
160         } // if 0
161         if (_tool == 1) 
162         {
163                 imMManager = this->_fillfilter->GetImageMManager();
164         } // if 1
165         this->_imageUndoRedo->SetURImages(imMManager);
166         this->_brushfilter->CleanImageMManager();
167         this->_fillfilter->CleanImageMManager();
168 }
169 //---------------------------------------------------------------------------
170
171 void ManualPaintModel::Undo() 
172 {
173         this->_imageUndoRedo->Undo();
174 }
175
176 void ManualPaintModel::Redo() 
177 {
178         this->_imageUndoRedo->Redo();
179 }