Computer Assisted Medical Intervention Tool Kit  version 5.2
StructuralComponentProperties.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef STRUCTURALCOMPONENTPROPERTIES_H
27 #define STRUCTURALCOMPONENTPROPERTIES_H
28 
29 //pmlschema forward declarations
30 namespace physicalModel {
32 }
33 
34 #include "Properties.h"
35 #include "RenderingMode.h"
36 
45 
46 public:
49  enum Color {
51  RED,
53  BLUE,
54  GRAY,
55  OTHER
56  };
57 
60  alloc();
61  setColor(c);
63  };
64 
65  StructuralComponentProperties(PhysicalModel* p, physicalModel::StructuralComponent xmlSC);
66  StructuralComponentProperties(PhysicalModel* p, const Color c, const std::string n) : Properties(p, n) {
67  alloc();
68  setColor(c);
70  };
71 
74  alloc();
75  setRGB(rgb);
76  setAlpha(1.0);
78  };
79 
80  StructuralComponentProperties(PhysicalModel* p, const double* rgb, const std::string n) : Properties(p, n) {
81  alloc();
82  setRGB(rgb);
83  setAlpha(1.0);
85  };
86 
88  StructuralComponentProperties(PhysicalModel* p, const double r, const double g, const double b) : Properties(p) {
89  alloc();
90  setRGB(r, g, b);
91  setAlpha(1.0);
93  };
94 
95  StructuralComponentProperties(PhysicalModel* p, const double r, const double g, const double b, const std::string n) : Properties(p, n) {
96  alloc();
97  setRGB(r, g, b);
98  setAlpha(1.0);
100  };
101 
104  alloc();
105  setColor(DEFAULT);
107  }
108 
109  ;
110  StructuralComponentProperties(PhysicalModel* p, const std::string n) : Properties(p, n) {
111  alloc();
112  setColor(DEFAULT);
114  };
115 
117  delete [] colorRGBA;
118  };
119 
120  double getRed() const;
121  double getGreen() const;
122  double getBlue() const;
123  double getAlpha() const;
124  double* getRGB() const;
125  double* getRGBA() const;
126  Color getColor() const;
127 
128  void setRed(const double r);
129  void setGreen(const double g);
130  void setBlue(const double b);
131  void setAlpha(const double a);
132  void setRGB(const double* rgb);
133  void setRGB(const double r, const double g, const double b);
134  void setRGBA(const double r, const double g, const double b, const double a);
135  void setRGBA(const double* rgba);
136  void setColor(Color c);
137 
138  void setMode(const RenderingMode::Mode);
140  bool isVisible(const RenderingMode::Mode mode) const;
141  void setVisible(const RenderingMode::Mode, const bool);
142 
144  std::string getModeString() const;
145 
150  virtual void xmlPrint(std::ostream&);
151 
152 private:
153  double* colorRGBA;
154  void alloc();
155  Color color;
156  RenderingMode mode;
157 };
158 
159 // inlines
161  return colorRGBA[0];
162 }
163 
165  return colorRGBA[1];
166 }
167 
169  return colorRGBA[2];
170 }
171 
173  return colorRGBA[3];
174 }
175 
177  return colorRGBA;
178 }
179 
181  return colorRGBA;
182 }
183 
185  return color;
186 }
187 
188 // TODO : a test for the color, if a composant is changed it might still be something we know
189 // so color = OTHER is a bit presumptuous
190 inline void StructuralComponentProperties::setRed(const double r) {
191  colorRGBA[0] = r;
192  color = OTHER;
193 }
194 
195 inline void StructuralComponentProperties::setGreen(const double g) {
196  colorRGBA[1] = g;
197  color = OTHER;
198 }
199 
200 inline void StructuralComponentProperties::setBlue(const double b) {
201  colorRGBA[2] = b;
202  color = OTHER;
203 }
204 
205 inline void StructuralComponentProperties::setAlpha(const double a) {
206  colorRGBA[3] = a;
207  color = OTHER;
208 }
209 
210 inline void StructuralComponentProperties::setRGB(const double r, const double g, const double b) {
211  setRed(r);
212  setGreen(g);
213  setBlue(b);
214  color = OTHER;
215 }
216 
217 inline void StructuralComponentProperties::setRGB(const double* rgb) {
218  setRGB(rgb[0], rgb[1], rgb[2]);
219  color = OTHER;
220 }
221 
222 inline void StructuralComponentProperties::setRGBA(const double r, const double g, const double b, const double a) {
223  setRed(r);
224  setGreen(g);
225  setBlue(b);
226  setAlpha(a);
227  color = OTHER;
228 }
229 
230 inline void StructuralComponentProperties::setRGBA(const double* rgba) {
231  setRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
232  color = OTHER;
233 }
234 
236  switch (c) {
237 
238  case RED:
239  setRGBA(1.0, 0.0, 0.0, 1.0);
240  break;
241 
242  case GREEN:
243  setRGBA(0.0, 1.0, 0.0, 1.0);
244  break;
245 
246  case BLUE:
247  setRGBA(0.0, 0.0, 1.0, 1.0);
248  break;
249 
250  default: // DEFAULT:or GRAY:or OTHER
251  setRGBA(0.8, 0.8, 0.8, 1.0);
252  break;
253  }
254 
255  color = c;
256 }
257 
258 inline void StructuralComponentProperties::alloc() {
259  colorRGBA = new double[4];
260 }
261 
263  mode.setMode(m);
264 }
265 
267  return mode.getMode();
268 }
269 
271  return mode.getModeString();
272 }
273 
275  return mode.isVisible(m);
276 }
277 
279  mode.setVisible(m, b);
280 }
281 
282 
283 #endif //STRUCTURALCOMPONENTPROPERTIES_H
#define a
This is the main class of this project.
Definition: PhysicalModel.h:86
Describes the properties common to all structures and components.
Definition: Properties.h:59
Handle rendering options (surface and wireframe) of an Object3D.
Definition: RenderingMode.h:37
void setMode(const Mode mode)
set a vizualisation mode
Definition: RenderingMode.h:137
void setVisible(const Mode mode, const bool value)
Set a rendering mode visible or not.
Definition: RenderingMode.h:69
bool isVisible(const Mode mode) const
Return if a rendering mode is currently visible or not.
Definition: RenderingMode.h:101
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:40
@ WIREFRAME_AND_SURFACE
Definition: RenderingMode.h:45
std::string getModeString() const
get the string equivalent to the enum rendering mode
Definition: RenderingMode.h:213
RenderingMode::Mode getMode() const
get current mode
Definition: RenderingMode.h:173
A class that manages the structural component properties.
Definition: StructuralComponentProperties.h:44
double getGreen() const
Definition: StructuralComponentProperties.h:164
void setRGB(const double *rgb)
Definition: StructuralComponentProperties.h:217
void setMode(const RenderingMode::Mode)
Definition: StructuralComponentProperties.h:262
StructuralComponentProperties(PhysicalModel *p, const Color c)
use a Color constant to set the color
Definition: StructuralComponentProperties.h:59
void setVisible(const RenderingMode::Mode, const bool)
Definition: StructuralComponentProperties.h:278
StructuralComponentProperties(PhysicalModel *p, const double *rgb, const std::string n)
Definition: StructuralComponentProperties.h:80
StructuralComponentProperties(PhysicalModel *p, const double r, const double g, const double b)
use 3 floats to set the color
Definition: StructuralComponentProperties.h:88
StructuralComponentProperties(PhysicalModel *p, const double r, const double g, const double b, const std::string n)
Definition: StructuralComponentProperties.h:95
Color
Default color settings.
Definition: StructuralComponentProperties.h:49
@ OTHER
color is defined using RGBA
Definition: StructuralComponentProperties.h:55
@ GREEN
full complete flashy green
Definition: StructuralComponentProperties.h:52
@ DEFAULT
no color given, decided by the GUI
Definition: StructuralComponentProperties.h:50
@ GRAY
classic gray
Definition: StructuralComponentProperties.h:54
@ BLUE
full complete flashy blue
Definition: StructuralComponentProperties.h:53
@ RED
full complete flashy red
Definition: StructuralComponentProperties.h:51
double getAlpha() const
Definition: StructuralComponentProperties.h:172
~StructuralComponentProperties()
Definition: StructuralComponentProperties.h:116
StructuralComponentProperties(PhysicalModel *p)
defaultcolor is gray
Definition: StructuralComponentProperties.h:103
double getRed() const
Definition: StructuralComponentProperties.h:160
double * getRGB() const
Definition: StructuralComponentProperties.h:176
void setAlpha(const double a)
Definition: StructuralComponentProperties.h:205
void setRed(const double r)
Definition: StructuralComponentProperties.h:190
StructuralComponentProperties(PhysicalModel *p, const std::string n)
Definition: StructuralComponentProperties.h:110
StructuralComponentProperties(PhysicalModel *p, const Color c, const std::string n)
Definition: StructuralComponentProperties.h:66
virtual void xmlPrint(std::ostream &)
print to an output stream in "pseaudo" XML format.
Definition: StructuralComponentProperties.cpp:81
Color getColor() const
Definition: StructuralComponentProperties.h:184
RenderingMode::Mode getMode() const
Definition: StructuralComponentProperties.h:266
bool isVisible(const RenderingMode::Mode mode) const
Definition: StructuralComponentProperties.h:274
std::string getModeString() const
get the string equivalent to the enum rendering mode
Definition: StructuralComponentProperties.h:270
StructuralComponentProperties(PhysicalModel *p, const double *rgb)
use a double[3] array to set the color
Definition: StructuralComponentProperties.h:73
void setBlue(const double b)
Definition: StructuralComponentProperties.h:200
void setGreen(const double g)
Definition: StructuralComponentProperties.h:195
double getBlue() const
Definition: StructuralComponentProperties.h:168
double * getRGBA() const
Definition: StructuralComponentProperties.h:180
void setRGBA(const double r, const double g, const double b, const double a)
Definition: StructuralComponentProperties.h:222
void setColor(Color c)
Definition: StructuralComponentProperties.h:235
A structural component is composed either by cell or by atoms.
Definition: StructuralComponent.h:52
Definition: Atom.h:36