Computer Assited Medical Intervention Tool Kit  version 4.1
MultiComponent.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2018 Univ. Grenoble Alpes, 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 MULTICOMPONENT_H
27 #define MULTICOMPONENT_H
28 
29 #include <vector>
30 #include <algorithm>
31 
32 #include "Component.h"
44 class MultiComponent : public Component {
45 public:
49  MultiComponent(PhysicalModel*, std::string);
51  ~MultiComponent() override;
52 
54  unsigned int getNumberOfSubComponents() const;
55 
57  Component* getSubComponent(const unsigned int) const;
58 
61 
70 
77 
79  bool isInstanceOf(const char*) const override;
80 
83  void xmlPrint(std::ostream&) const override;
84 
86  unsigned int getNumberOfCells() const override;
87 
89  Cell* getCell(unsigned int) const override;
90 
92  Component* getComponentByName(const std::string);
93 
95  bool isVisible(const RenderingMode::Mode mode) const override;
96 
98  void setVisible(const RenderingMode::Mode mode, const bool b) override;
99 
101  void setPhysicalModel(PhysicalModel*) override;
102 
103 protected:
107  std::vector <Component*> components;
108 };
109 
110 // -------------------- inline methods -------------------
111 inline unsigned int MultiComponent::getNumberOfSubComponents() const {
112  return (unsigned int) components.size();
113 }
114 inline Component* MultiComponent::getSubComponent(const unsigned int i) const {
115  if (i < components.size()) {
116  return components[i];
117  }
118  else {
119  return nullptr;
120  }
121 }
123  // add c in the list
124  components.push_back(c);
125  // add this in the list of c's composing component
126  c->addParentMultiComponent(this);
127  // set the isExclusive flag accordingly
129 }
131  auto it = std::find(components.begin(), components.end(), c);
132  if (it != components.end()) {
133  components.erase(it);
135  }
136 }
137 inline Component* MultiComponent::getComponentByName(const std::string n) {
138  auto it = components.begin();
139  Component* foundC = nullptr;
140  while (it != components.end() && !foundC) {
141  foundC = ((*it)->getName() == n) ? (*it) : NULL;
142  // look inside the component if it is a MultiComponent
143  if (!foundC && (*it)->isInstanceOf("MultiComponent")) {
144  foundC = ((MultiComponent*)(*it))->getComponentByName(n);
145  }
146  it++;
147  }
148  return foundC;
149 }
150 inline bool MultiComponent::isInstanceOf(const char* className) const {
151  return (std::string(className) == std::string("MultiComponent"));
152 }
153 
154 #endif //MULTICOMPONENT_H
~MultiComponent() override
delete all the subcomponents (call the deleteAllSubComponents method)
Definition: MultiComponent.cpp:38
bool isExclusive() const
tell if this component is exclusive or not
Definition: modeling/libraries/pml/Component.h:144
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:46
Cell * getCell(unsigned int) const override
get cell by order number (not cell index)
Definition: MultiComponent.cpp:89
MultiComponent(PhysicalModel *)
Default Constructor.
Definition: MultiComponent.cpp:29
void setPhysicalModel(PhysicalModel *) override
set the physical model (recursively)
Definition: MultiComponent.cpp:131
void xmlPrint(std::ostream &) const override
print to an output stream in "pseaudo" XML format (do nothing if there are no sub components)...
Definition: MultiComponent.cpp:56
void setVisible(const RenderingMode::Mode mode, const bool b) override
set the state of a visibility mode in all the sub component.
Definition: MultiComponent.cpp:123
bool isInstanceOf(const char *) const override
return true only if the parameter is equal to "MultiComponent"
Definition: MultiComponent.h:150
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
std::vector< Component * > components
List of sub component.
Definition: MultiComponent.h:107
void setExclusive(const bool)
set the exclusive flag
Definition: modeling/libraries/pml/Component.h:141
Component * getComponentByName(const std::string)
conveniant method to get the sub component of the name given in parameter
Definition: MultiComponent.h:137
void removeParentMultiComponent(MultiComponent *)
remove a particular parent MultiComponent
Definition: modeling/libraries/pml/Component.h:173
unsigned int getNumberOfSubComponents() const
return the number of subcomponents
Definition: MultiComponent.h:111
unsigned int getNumberOfCells() const override
get the total nr of cell of the component
Definition: MultiComponent.cpp:77
bool isVisible(const RenderingMode::Mode mode) const override
return the state of a visibility mode in all the sub component (if at least one sub component is visi...
Definition: MultiComponent.cpp:114
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
void removeSubComponent(Component *c)
Remove a component from the list.
Definition: MultiComponent.h:130
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:40
This is the main class of this project.
Definition: PhysicalModel.h:86
void addSubComponent(Component *)
add a component in the list of subcomponents (and set the isExclusive flag accordingly to the state o...
Definition: MultiComponent.h:122
void deleteAllSubComponents()
this method free all the sub-components (i.e.
Definition: MultiComponent.cpp:48
void addParentMultiComponent(MultiComponent *)
add a particular parent MultiComponent in the list
Definition: modeling/libraries/pml/Component.h:170
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44
Component * getSubComponent(const unsigned int) const
get a subcomponent by its order number (index in the list of subcomponents)
Definition: MultiComponent.h:114