Computer Assited Medical Intervention Tool Kit  version 5.0
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-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 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
Component.h
MultiComponent::getComponentByName
Component * getComponentByName(const std::string)
conveniant method to get the sub component of the name given in parameter
Definition: MultiComponent.h:137
MultiComponent::xmlPrint
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:58
MultiComponent::isVisible
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:116
MultiComponent::getSubComponent
Component * getSubComponent(const unsigned int) const
get a subcomponent by its order number (index in the list of subcomponents)
Definition: MultiComponent.h:114
Component::removeFromParents
void removeFromParents()
this tell the parent components that this component is removed from memory.
Definition: modeling/libraries/pml/Component.cpp:48
Properties::getField
std::string getField(unsigned int) const
get the name of field of given index
Definition: Properties.cpp:68
Component::properties
Properties * properties
Definition: modeling/libraries/pml/Component.h:118
MultiComponent::setPhysicalModel
void setPhysicalModel(PhysicalModel *) override
set the physical model (recursively)
Definition: MultiComponent.cpp:133
Component::isInstanceOf
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
MultiComponent::getNumberOfSubComponents
unsigned int getNumberOfSubComponents() const
return the number of subcomponents
Definition: MultiComponent.h:111
Component::setExclusive
void setExclusive(const bool)
set the exclusive flag
Definition: modeling/libraries/pml/Component.h:141
Component::deleteProperties
void deleteProperties()
delete the "properties" pointer and set it to NULL
Definition: modeling/libraries/pml/Component.cpp:42
Properties::numberOfFields
unsigned int numberOfFields() const
get the number of extra fields found in the PML
Definition: Properties.cpp:63
MultiComponent::removeSubComponent
void removeSubComponent(Component *c)
Remove a component from the list.
Definition: MultiComponent.h:130
Component::addParentMultiComponent
void addParentMultiComponent(MultiComponent *)
add a particular parent MultiComponent in the list
Definition: modeling/libraries/pml/Component.h:170
MultiComponent::isInstanceOf
bool isInstanceOf(const char *) const override
return true only if the parameter is equal to "MultiComponent"
Definition: MultiComponent.h:150
MultiComponent::deleteAllSubComponents
void deleteAllSubComponents()
this method free all the sub-components (i.e.
Definition: MultiComponent.cpp:48
PhysicalModel
This is the main class of this project. Following a nice concept, a physical model is able to represe...
Definition: PhysicalModel.h:86
Cell
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:46
Component::getName
const std::string getName() const
get the name of the component
Definition: modeling/libraries/pml/Component.h:147
MultiComponent::setVisible
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:125
Properties::getString
std::string getString(std::string attName) const
field accessor: get the field attName as a string value, if field does not exist, empty string is ret...
Definition: Properties.h:178
MultiComponent::addSubComponent
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
MultiComponent::MultiComponent
MultiComponent(PhysicalModel *)
Default Constructor.
Definition: MultiComponent.cpp:29
MultiComponent::getNumberOfCells
unsigned int getNumberOfCells() const override
get the total nr of cell of the component
Definition: MultiComponent.cpp:79
RenderingMode::Mode
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:63
Component
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
MultiComponent::~MultiComponent
~MultiComponent() override
delete all the subcomponents (call the deleteAllSubComponents method)
Definition: MultiComponent.cpp:38
Component::removeParentMultiComponent
void removeParentMultiComponent(MultiComponent *)
remove a particular parent MultiComponent
Definition: modeling/libraries/pml/Component.h:173
MultiComponent.h
MultiComponent
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44
Component::isExclusive
bool isExclusive() const
tell if this component is exclusive or not
Definition: modeling/libraries/pml/Component.h:144
Component::setPhysicalModel
virtual void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: modeling/libraries/pml/Component.h:180
MultiComponent::components
std::vector< Component * > components
List of sub component.
Definition: MultiComponent.h:130
MultiComponent::getCell
Cell * getCell(unsigned int) const override
get cell by order number (not cell index)
Definition: MultiComponent.cpp:91