Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
StructuralComponent.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
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 STRUCTURALCOMPONENT_H
27 #define STRUCTURALCOMPONENT_H
28 
29 #include "PhysicalModelIO.h"
30 
31 // pml includes
32 #include "Component.h"
33 #include "Structure.h"
34 class Object3D;
36 
37 // other includes
38 #include <vector>
39 #include <algorithm> // for the remove
40 #include <string>
49 public:
53 
55  StructuralComponent(PhysicalModel *, xmlNodePtr);
56 
59  StructuralComponent(PhysicalModel *, std::string);
60 
62  virtual ~StructuralComponent();
63 
65  unsigned int getNumberOfStructures() const;
66 
73  void addStructure(Structure *s, bool check = true);
74 
83 
88  bool isStructureIn(Structure *s);
89 
96  virtual void removeStructure(Structure *s);
97 
103  virtual void deleteAllStructures();
104 
108  Structure * getStructure(const unsigned int) const;
109 
113  Structure * getStructureByName(const std::string);
114 
118  Structure * getStructureByIndex(const unsigned int);
119 
122  void xmlPrint(std::ostream &) const;
123 
125  virtual bool isInstanceOf(const char *) const;
126 
128  unsigned int getNumberOfCells() const;
129 
131  Cell * getCell(unsigned int) const;
132 
139 
142 
146  void setColor(const double r, const double b, const double g, const double a);
148  void setColor(const double r, const double b, const double g);
152  double * getColor() const;
154  void getColor(double *r, double *g, double *b, double *a) const;
155 
158 
160  void setMode(const RenderingMode::Mode);
164  virtual bool isVisible(const RenderingMode::Mode mode) const;
166  virtual void setVisible(const RenderingMode::Mode mode, const bool b);
167 
169  enum ComposedBy {
173  };
174 
180 
184  bool isCompatible(Structure *);
185 
190  void plannedNumberOfStructures(const unsigned int);
191 
193  virtual void setPhysicalModel(PhysicalModel *);
194 
195 protected:
199  std::vector <Structure *> structures;
200 
204 
205 };
206 
207 // ------- INLINE -----------
208 inline void StructuralComponent::addStructure(Structure *s, bool check) {
209  // add the structure in the list, only if it is compatible
210  if (!check || isCompatible(s)) {
211  structures.push_back(s);
212  // tell the structure that it is a part of this sc
213  s->addStructuralComponent(this);
214  }
215 }
216 inline Structure * StructuralComponent::getStructure(const unsigned int i) const {
217  if (i<structures.size())
218  return structures[i];
219  else
220  return NULL;
221 }
222 inline Structure * StructuralComponent::getStructureByIndex(const unsigned int i) {
223  std::vector <Structure *>::iterator it=structures.begin();
224  while (it!=structures.end() && (*it)->getIndex()!=i)
225  it++;
226  if (it==structures.end())
227  return NULL;
228  else
229  return (*it);
230 }
231 inline Structure * StructuralComponent::getStructureByName(const std::string n) {
232  std::vector <Structure *>::iterator it=structures.begin();
233  while (it!=structures.end() && (*it)->getName()!=n)
234  it++;
235  if (it==structures.end())
236  return NULL;
237  else
238  return (*it);
239 }
240 inline unsigned int StructuralComponent::getNumberOfStructures() const {
241  return structures.size();
242 }
244  if (s) {
245  // remove it from the list
246  std::vector <Structure *>::iterator it = std::find(structures.begin(), structures.end(), s);
247  if (it != structures.end()) {
248  structures.erase(it);
249  // tell s that it is no more used by this structural component
250  s->removeStructuralComponent(this);
251  }
252  }
253 }
254 inline bool StructuralComponent::isInstanceOf(const char *className) const {
255  return (std::string(className)==std::string("StructuralComponent"));
256 }
257 
258 inline void StructuralComponent::plannedNumberOfStructures(const unsigned int size) {
259  structures.reserve(size);
260 }
261 
264 }
265 
266 #endif //STRUCTURALCOMPONENT_H
double * getColor() const
Get the color.
void plannedNumberOfStructures(const unsigned int)
optimize the I/O of the std:vector structures.
Definition: StructuralComponent.h:258
void setColor(const StructuralComponentProperties::Color c)
Set the new color (using a StructuralComponentProperties::Color enum)
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:41
virtual void setPhysicalModel(PhysicalModel *)
set the physical model (recursively to all cells or to all atoms)
there are no structure yet, so everything is possible
Definition: StructuralComponent.h:170
Pure virtual class that represent an element of the structure.
Definition: Structure.h:43
StructuralComponent * getAtoms()
Return a StructuralComponent with all the atoms of this structural component.
the structural component is made of cells
Definition: StructuralComponent.h:171
bool isStructureIn(Structure *s)
Check if a given structure is present in the list.
StructuralComponentProperties * getProperties()
get the structural component properties of this SC
Definition: StructuralComponent.h:262
virtual void removeStructure(Structure *s)
Remove a structure from the list (and tells the structure to remove this structural component from it...
Definition: StructuralComponent.h:243
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:40
Color
Default color settings.
Definition: BasicSCProperties.h:47
void setMode(const RenderingMode::Mode)
set the rendering mode
StructuralComponent(PhysicalModel *)
Default Constructor.
void removeStructuralComponent(StructuralComponent *)
remove a particular StructuralComponent from the list
Definition: Structure.h:125
ComposedBy
What this structural component is made of.
Definition: StructuralComponent.h:169
Structure * getStructure(const unsigned int) const
get a structure by its index (fisrt structure is at index 0)
Definition: StructuralComponent.h:216
bool addStructureIfNotIn(Structure *s)
Add a Structure in the list, only if it is not already in (and tells the structure to remove this str...
StructuralComponent * atomList
List of all the atoms of this structural component, build the first time.
Definition: StructuralComponent.h:203
virtual void deleteAllStructures()
this method free all the sub-components (i.e.
StructuralComponentProperties::Color getStructuralComponentPropertiesColor() const
Return the color as a code (see StructuralComponentProperties::Color enum)
virtual bool isVisible(const RenderingMode::Mode mode) const
tell if a specific rendering mode is visible or not
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
void addStructure(Structure *s, bool check=true)
Add a Structure in the list (and tells the structure to remove this structural component from its lis...
Definition: StructuralComponent.h:208
unsigned int getNumberOfCells() const
get the total nr of cell of the component
Structure * getStructureByIndex(const unsigned int)
get a structure by its unique index
Definition: StructuralComponent.h:222
Cell * getCell(unsigned int) const
get cell by order number (not cell index)
ComposedBy composedBy()
return the type of structure composing the structural component: a structural component is either a l...
This is an automatically generated class for custom StructuralComponent properties.
Definition: StructuralComponentProperties.h:45
virtual ~StructuralComponent()
delete all the structures (call the deleteAllStructures method)
This is the main class of this project.
Definition: PhysicalModel.h:74
bool isCompatible(Structure *)
return true if the given structure is compatible with what composes this structural component...
std::vector< Structure * > structures
List of the structure representing this component, all the structure in this list are either all Atom...
Definition: StructuralComponent.h:199
RenderingMode::Mode getMode() const
get the rendering mode
unsigned int getNumberOfStructures() const
get the number of structures
Definition: StructuralComponent.h:240
A structural component is composed either by cell or by atoms.
Definition: StructuralComponent.h:48
Properties * properties
Definition: modeling/libraries/pml/Component.h:118
void xmlPrint(std::ostream &) const
print to an output stream in "pseudo" XML format (do nothing if there are no sub structures).
virtual void setVisible(const RenderingMode::Mode mode, const bool b)
set the visibility of a specific rendering mode
void addStructuralComponent(StructuralComponent *)
add a particular StructuralComponent in the list
Definition: Structure.h:121
the structural component is made of atoms
Definition: StructuralComponent.h:172
virtual bool isInstanceOf(const char *) const
return true only if the parameter is equal to "StructuralComponent"
Definition: StructuralComponent.h:254
Structure * getStructureByName(const std::string)
get a structure by its name
Definition: StructuralComponent.h:231