Computer Assited Medical Intervention Tool Kit  version 5.0
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-2021 Univ. Grenoble Alpes, CNRS, Grenoble INP, 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,
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();
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 
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
RenderingMode::WIREFRAME
@ WIREFRAME
Definition: RenderingMode.h:93
RenderingMode::SURFACE
@ SURFACE
Definition: RenderingMode.h:90
RenderingMode::WIREFRAME_AND_SURFACE
@ WIREFRAME_AND_SURFACE
Definition: RenderingMode.h:91
StructuralComponentProperties::getModeString
std::string getModeString() const
get the string equivalent to the enum rendering mode
Definition: StructuralComponentProperties.h:270
RenderingMode::getMode
RenderingMode::Mode getMode() const
get current mode
Definition: RenderingMode.h:196
Properties::xmlToFields
void xmlToFields(xsd::cxx::tree::attribute_set< char > attrs)
convert the xml node parameters to data fields
Definition: Properties.cpp:41
StructuralComponentProperties.h
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p, const double *rgb, const std::string n)
Definition: StructuralComponentProperties.h:80
StructuralComponentProperties::setVisible
void setVisible(const RenderingMode::Mode, const bool)
Definition: StructuralComponentProperties.h:278
StructuralComponentProperties::xmlPrint
virtual void xmlPrint(std::ostream &)
print to an output stream in "pseaudo" XML format.
Definition: StructuralComponentProperties.cpp:81
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p, const double r, const double g, const double b, const std::string n)
Definition: StructuralComponentProperties.h:95
a
#define a
StructuralComponentProperties::setColor
void setColor(Color c)
Definition: StructuralComponentProperties.h:235
Properties.h
RenderingMode.h
StructuralComponentProperties::getRed
double getRed() const
Definition: StructuralComponentProperties.h:160
StructuralComponentProperties::setGreen
void setGreen(const double g)
Definition: StructuralComponentProperties.h:195
RenderingMode::setVisible
void setVisible(const Mode mode, const bool value)
Set a rendering mode visible or not.
Definition: RenderingMode.h:92
RenderingMode
Handle rendering options (surface and wireframe) of an Object3D.
Definition: RenderingMode.h:37
StructuralComponent
A structural component is composed either by cell or by atoms.
Definition: StructuralComponent.h:52
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p, const double r, const double g, const double b)
use 3 floats to set the color
Definition: StructuralComponentProperties.h:88
StructuralComponentProperties::setAlpha
void setAlpha(const double a)
Definition: StructuralComponentProperties.h:205
StructuralComponentProperties::OTHER
@ OTHER
color is defined using RGBA
Definition: StructuralComponentProperties.h:55
StructuralComponentProperties
A class that manages the structural component properties.
Definition: StructuralComponentProperties.h:44
RenderingMode::WIREFRAME_AND_POINTS
@ WIREFRAME_AND_POINTS
Definition: RenderingMode.h:92
Properties::getName
std::string getName() const
get the name (be careful, this method DOES NOT return a copy, so you got the direct ptr to the name!...
Definition: Properties.h:250
RenderingMode::NONE
@ NONE
Definition: RenderingMode.h:87
StructuralComponentProperties::~StructuralComponentProperties
~StructuralComponentProperties()
Definition: StructuralComponentProperties.h:116
StructuralComponentProperties::setRGB
void setRGB(const double *rgb)
Definition: StructuralComponentProperties.h:217
StructuralComponentProperties::getAlpha
double getAlpha() const
Definition: StructuralComponentProperties.h:172
PhysicalModel
This is the main class of this project. Following a nice concept, a physical model is able to represe...
Definition: PhysicalModel.h:86
StructuralComponentProperties::RED
@ RED
full complete flashy red
Definition: StructuralComponentProperties.h:51
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p)
defaultcolor is gray
Definition: StructuralComponentProperties.h:103
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p, const Color c, const std::string n)
Definition: StructuralComponentProperties.h:66
StructuralComponentProperties::setBlue
void setBlue(const double b)
Definition: StructuralComponentProperties.h:200
StructuralComponentProperties::getGreen
double getGreen() const
Definition: StructuralComponentProperties.h:164
StructuralComponentProperties::getRGBA
double * getRGBA() const
Definition: StructuralComponentProperties.h:180
StructuralComponentProperties::GREEN
@ GREEN
full complete flashy green
Definition: StructuralComponentProperties.h:52
StructuralComponentProperties::color
Color color
Definition: StructuralComponentProperties.h:155
RenderingMode::isVisible
bool isVisible(const Mode mode) const
Return if a rendering mode is currently visible or not.
Definition: RenderingMode.h:124
StructuralComponentProperties::setMode
void setMode(const RenderingMode::Mode)
Definition: StructuralComponentProperties.h:262
StructuralComponentProperties::getBlue
double getBlue() const
Definition: StructuralComponentProperties.h:168
StructuralComponentProperties::getMode
RenderingMode::Mode getMode() const
Definition: StructuralComponentProperties.h:266
RenderingMode::setMode
void setMode(const Mode mode)
set a vizualisation mode
Definition: RenderingMode.h:160
StructuralComponentProperties::setRed
void setRed(const double r)
Definition: StructuralComponentProperties.h:190
StructuralComponentProperties::DEFAULT
@ DEFAULT
no color given, decided by the GUI
Definition: StructuralComponentProperties.h:50
StructuralComponentProperties::BLUE
@ BLUE
full complete flashy blue
Definition: StructuralComponentProperties.h:53
StructuralComponentProperties::getRGB
double * getRGB() const
Definition: StructuralComponentProperties.h:176
Properties::setName
void setName(std::string)
set the name (use the string = operator)
Definition: Properties.h:254
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p, const double *rgb)
use a double[3] array to set the color
Definition: StructuralComponentProperties.h:73
StructuralComponentProperties::alloc
void alloc()
Definition: StructuralComponentProperties.h:258
StructuralComponentProperties::colorRGBA
double * colorRGBA
Definition: StructuralComponentProperties.h:153
RenderingMode::Mode
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:63
StructuralComponentProperties::mode
RenderingMode mode
Definition: StructuralComponentProperties.h:156
RenderingMode::WIREFRAME_AND_SURFACE_AND_POINTS
@ WIREFRAME_AND_SURFACE_AND_POINTS
Definition: RenderingMode.h:94
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p, const std::string n)
Definition: StructuralComponentProperties.h:110
StructuralComponentProperties::isVisible
bool isVisible(const RenderingMode::Mode mode) const
Definition: StructuralComponentProperties.h:274
StructuralComponentProperties::getColor
Color getColor() const
Definition: StructuralComponentProperties.h:184
RenderingMode::POINTS
@ POINTS
Definition: RenderingMode.h:88
physicalModel
Definition: Atom.h:36
StructuralComponentProperties::Color
Color
Default color settings.
Definition: StructuralComponentProperties.h:49
RenderingMode::POINTS_AND_SURFACE
@ POINTS_AND_SURFACE
Definition: RenderingMode.h:89
Properties
Describes the properties common to all structures and components.
Definition: Properties.h:59
RenderingMode::getModeString
std::string getModeString() const
get the string equivalent to the enum rendering mode
Definition: RenderingMode.h:236
StructuralComponentProperties::StructuralComponentProperties
StructuralComponentProperties(PhysicalModel *p, const Color c)
use a Color constant to set the color
Definition: StructuralComponentProperties.h:59
StructuralComponentProperties::GRAY
@ GRAY
classic gray
Definition: StructuralComponentProperties.h:54
Properties::fields
std::map< std::string, std::string > fields
map containing all the different fields (name, value stored as string )
Definition: Properties.h:129
StructuralComponentProperties::setRGBA
void setRGBA(const double r, const double g, const double b, const double a)
Definition: StructuralComponentProperties.h:222