Computer Assited Medical Intervention Tool Kit  version 5.0
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-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 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 <algorithm> // for the remove
39 #include <string>
40 
41 //pmlschema forward declarations
42 namespace physicalModel {
44 }
53 public:
57 
59  StructuralComponent(PhysicalModel* p, physicalModel::StructuralComponent xmlSC);
60 
63  StructuralComponent(PhysicalModel*, std::string);
64 
66  ~StructuralComponent() override;
67 
69  unsigned int getNumberOfStructures() const;
70 
77  void addStructure(Structure* s, bool check = true);
78 
87 
92  bool isStructureIn(Structure* s);
93 
100  virtual void removeStructure(Structure* s);
101 
107  virtual void deleteAllStructures();
108 
112  Structure* getStructure(const unsigned int) const;
113 
117  Structure* getStructureByName(const std::string);
118 
122  Structure* getStructureByIndex(const unsigned int);
123 
126  void xmlPrint(std::ostream&) const override;
127 
129  bool isInstanceOf(const char*) const override;
130 
132  unsigned int getNumberOfCells() const override;
133 
135  Cell* getCell(unsigned int) const override;
136 
143 
146 
150  void setColor(const double r, const double b, const double g, const double a);
152  void setColor(const double r, const double b, const double g);
156  double* getColor() const;
158  void getColor(double* r, double* g, double* b, double* a) const;
159 
162 
164  void setMode(const RenderingMode::Mode);
168  bool isVisible(const RenderingMode::Mode mode) const override;
170  void setVisible(const RenderingMode::Mode mode, const bool b) override;
171 
173  enum ComposedBy {
177  };
178 
183  virtual ComposedBy composedBy();
184 
188  bool isCompatible(Structure*);
189 
194  void plannedNumberOfStructures(const unsigned int);
195 
197  void setPhysicalModel(PhysicalModel*) override;
198 
199 protected:
203  std::vector <Structure*> structures;
204 
208 
209 };
210 
211 // ------- INLINE -----------
212 inline void StructuralComponent::addStructure(Structure* s, bool check) {
213  // add the structure in the list, only if it is compatible
214  if (!check || isCompatible(s)) {
215  structures.push_back(s);
216  // tell the structure that it is a part of this sc
217  s->addStructuralComponent(this);
218  }
219 }
220 inline Structure* StructuralComponent::getStructure(const unsigned int i) const {
221  if (i < structures.size()) {
222  return structures[i];
223  }
224  else {
225  return nullptr;
226  }
227 }
229  auto it = structures.begin();
230  while (it != structures.end() && (*it)->getIndex() != i) {
231  it++;
232  }
233  if (it == structures.end()) {
234  return nullptr;
235  }
236  else {
237  return (*it);
238  }
239 }
241  auto it = structures.begin();
242  while (it != structures.end() && (*it)->getName() != n) {
243  it++;
244  }
245  if (it == structures.end()) {
246  return nullptr;
247  }
248  else {
249  return (*it);
250  }
251 }
252 inline unsigned int StructuralComponent::getNumberOfStructures() const {
253  return (unsigned int) structures.size();
254 }
256  if (s) {
257  // remove it from the list
258  auto it = std::find(structures.begin(), structures.end(), s);
259  if (it != structures.end()) {
260  structures.erase(it);
261  // tell s that it is no more used by this structural component
262  s->removeStructuralComponent(this);
263  }
264  }
265 }
266 inline bool StructuralComponent::isInstanceOf(const char* className) const {
267  return (std::string(className) == std::string("StructuralComponent"));
268 }
269 
270 inline void StructuralComponent::plannedNumberOfStructures(const unsigned int size) {
271  structures.reserve(size);
272 }
273 
276 }
277 
278 #endif //STRUCTURALCOMPONENT_H
Component.h
StructuralComponent::isCompatible
bool isCompatible(Structure *)
return true if the given structure is compatible with what composes this structural component.
Definition: StructuralComponent.cpp:310
StructuralComponent::ComposedBy
ComposedBy
What this structural component is made of.
Definition: StructuralComponent.h:173
Cell.h
StructuralComponent::getNumberOfStructures
unsigned int getNumberOfStructures() const
get the number of structures
Definition: StructuralComponent.h:252
Structure::isInstanceOf
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
StructuralComponent::isInstanceOf
bool isInstanceOf(const char *) const override
return true only if the parameter is equal to "StructuralComponent"
Definition: StructuralComponent.h:266
StructuralComponent::~StructuralComponent
~StructuralComponent() override
delete all the structures (call the deleteAllStructures method)
Definition: StructuralComponent.cpp:73
Component::removeFromParents
void removeFromParents()
this tell the parent components that this component is removed from memory.
Definition: modeling/libraries/pml/Component.cpp:48
StructuralComponentProperties.h
StructuralComponent::isStructureIn
bool isStructureIn(Structure *s)
Check if a given structure is present in the list.
Definition: StructuralComponent.cpp:239
Component::properties
Properties * properties
Definition: modeling/libraries/pml/Component.h:118
a
#define a
StructuralComponent::getStructureByName
Structure * getStructureByName(const std::string)
get a structure by its name
Definition: StructuralComponent.h:240
StructuralComponent::deleteAllStructures
virtual void deleteAllStructures()
this method free all the sub-components (i.e.
Definition: StructuralComponent.cpp:89
RenderingMode.h
StructuralComponent::setColor
void setColor(const StructuralComponentProperties::Color c)
Set the new color (using a StructuralComponentProperties::Color enum)
Definition: StructuralComponent.cpp:105
Component::deleteProperties
void deleteProperties()
delete the "properties" pointer and set it to NULL
Definition: modeling/libraries/pml/Component.cpp:42
StructuralComponent::setVisible
void setVisible(const RenderingMode::Mode mode, const bool b) override
set the visibility of a specific rendering mode
Definition: StructuralComponent.cpp:149
StructuralComponent
A structural component is composed either by cell or by atoms.
Definition: StructuralComponent.h:52
StructuralComponent::getStructuralComponentPropertiesColor
StructuralComponentProperties::Color getStructuralComponentPropertiesColor() const
Return the color as a code (see StructuralComponentProperties::Color enum)
Definition: StructuralComponent.cpp:128
StructuralComponent::removeStructure
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:255
Structure
Pure virtual class that represent an element of the structure. This implies that every structure coul...
Definition: Structure.h:43
StructuralComponent::addStructure
void addStructure(Structure *s, bool check=true)
Add a Structure in the list (and tells the structure to add this structural component in its list).
Definition: StructuralComponent.h:212
StructuralComponentProperties
A class that manages the structural component properties.
Definition: StructuralComponentProperties.h:44
Atom.h
StructuralComponent::StructuralComponent
StructuralComponent(PhysicalModel *)
Default Constructor.
Definition: StructuralComponent.cpp:37
Structure::addStructuralComponent
virtual void addStructuralComponent(StructuralComponent *)
add a particular StructuralComponent in the list
Definition: Structure.h:128
StructuralComponent::NOTHING
@ NOTHING
there are no structure yet, so everything is possible
Definition: StructuralComponent.h:174
PhysicalModel
This is the main class of this project. Following a nice concept, a physical model is able to represe...
Definition: PhysicalModel.h:86
StructuralComponent::getAtoms
StructuralComponent * getAtoms()
Return a StructuralComponent with all the atoms of this structural component.
Definition: StructuralComponent.cpp:261
StructuralComponent::getStructureByIndex
Structure * getStructureByIndex(const unsigned int)
get a structure by its unique index
Definition: StructuralComponent.h:228
Properties::getPhysicalModel
PhysicalModel * getPhysicalModel() const
get the physical model
Definition: Properties.h:262
StructuralComponent::setPhysicalModel
void setPhysicalModel(PhysicalModel *) override
set the physical model (recursively to all cells or to all atoms)
Definition: StructuralComponent.cpp:321
Cell
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:46
PhysicalModelIO.h
StructuralComponent.h
StructuralComponent::setMode
void setMode(const RenderingMode::Mode)
set the rendering mode
Definition: StructuralComponent.cpp:134
StructuralComponent::structures
std::vector< Structure * > structures
List of the structure representing this component, all the structure in this list are either all Atom...
Definition: StructuralComponent.h:203
StructuralComponent::getColor
double * getColor() const
Get the color.
Definition: StructuralComponent.cpp:116
StructuralComponent::composedBy
virtual ComposedBy composedBy()
return the type of structure composing the structural component: a structural component is either a l...
Definition: StructuralComponent.cpp:296
StructuralComponent::CELLS
@ CELLS
the structural component is made of cells
Definition: StructuralComponent.h:175
StructuralComponentProperties::DEFAULT
@ DEFAULT
no color given, decided by the GUI
Definition: StructuralComponentProperties.h:50
Structure::setPhysicalModel
virtual void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: Structure.cpp:53
StructuralComponent::atomList
StructuralComponent * atomList
List of all the atoms of this structural component, build the first time.
Definition: StructuralComponent.h:207
StructuralComponent::getStructure
Structure * getStructure(const unsigned int) const
get a structure by its index (fisrt structure is at index 0)
Definition: StructuralComponent.h:220
RenderingMode::Mode
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:63
StructuralComponent::xmlPrint
void xmlPrint(std::ostream &) const override
print to an output stream in "pseudo" XML format (do nothing if there are no sub structures).
Definition: StructuralComponent.cpp:154
StructuralComponent::isVisible
bool isVisible(const RenderingMode::Mode mode) const override
tell if a specific rendering mode is visible or not
Definition: StructuralComponent.cpp:144
Component
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
physicalModel
Definition: Atom.h:36
StructuralComponent::getCell
Cell * getCell(unsigned int) const override
get cell by order number (not cell index)
Definition: StructuralComponent.cpp:197
StructuralComponentProperties::Color
Color
Default color settings.
Definition: StructuralComponentProperties.h:49
Structure.h
StructuralComponent::getProperties
StructuralComponentProperties * getProperties()
get the structural component properties of this SC
Definition: StructuralComponent.h:274
StructuralComponent::getNumberOfCells
unsigned int getNumberOfCells() const override
get the total nr of cell of the component
Definition: StructuralComponent.cpp:183
StructuralComponent::getMode
RenderingMode::Mode getMode() const
get the rendering mode
Definition: StructuralComponent.cpp:139
Structure::removeStructuralComponent
void removeStructuralComponent(StructuralComponent *)
remove a particular StructuralComponent from the list
Definition: Structure.h:132
StructuralComponent::ATOMS
@ ATOMS
the structural component is made of atoms
Definition: StructuralComponent.h:176
Component::setPhysicalModel
virtual void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: modeling/libraries/pml/Component.h:180
StructuralComponent::addStructureIfNotIn
bool addStructureIfNotIn(Structure *s)
Add a Structure in the list, only if it is not already in (and in this case tells the structure to ad...
Definition: StructuralComponent.cpp:248
StructuralComponent::plannedNumberOfStructures
void plannedNumberOfStructures(const unsigned int)
optimize the I/O of the std:vector structures.
Definition: StructuralComponent.h:270