Computer Assited Medical Intervention Tool Kit  version 4.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-2016 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);
52 
54  unsigned int getNumberOfSubComponents() const;
55 
57  Component * getSubComponent(const unsigned int) const;
58 
60  void addSubComponent(Component *);
61 
70 
77 
79  virtual bool isInstanceOf(const char *) const;
80 
83  void xmlPrint(std::ostream &) const;
84 
86  unsigned int getNumberOfCells() const;
87 
89  Cell * getCell(unsigned int) const;
90 
92  Component * getComponentByName(const std::string);
93 
95  virtual bool isVisible(const RenderingMode::Mode mode) const;
96 
98  virtual void setVisible(const RenderingMode::Mode mode, const bool b);
99 
101  virtual void setPhysicalModel(PhysicalModel *);
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  else
118  return NULL;
119 }
121  // add c in the list
122  components.push_back(c);
123  // add this in the list of c's composing component
124  c->addParentMultiComponent(this);
125  // set the isExclusive flag accordingly
127 }
129  std::vector <Component *>::iterator it = std::find(components.begin(), components.end(), c);
130  if (it != components.end()) {
131  components.erase(it);
133  }
134 }
135 inline Component * MultiComponent::getComponentByName(const std::string n) {
136  std::vector <Component *>::iterator it=components.begin();
137  Component *foundC=NULL;
138  while (it!=components.end() && !foundC) {
139  foundC = ((*it)->getName()==n)?(*it):NULL;
140  // look inside the component if it is a MultiComponent
141  if (!foundC && (*it)->isInstanceOf("MultiComponent")) {
142  foundC = ((MultiComponent *) (*it))->getComponentByName(n);
143  }
144  it++;
145  }
146  return foundC;
147 }
148 inline bool MultiComponent::isInstanceOf(const char *className) const {
149  return (std::string(className)==std::string("MultiComponent"));
150 }
151 
152 #endif //MULTICOMPONENT_H
bool isExclusive() const
tell if this component is exclusive or not
Definition: modeling/libraries/pml/Component.h:144
std::vector< Component * > components
List of sub component.
Definition: MultiComponent.h:107
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
get cell by order number (not cell index)
Definition: MultiComponent.cpp:86
MultiComponent(PhysicalModel *)
Default Constructor.
Definition: MultiComponent.cpp:29
virtual bool isVisible(const RenderingMode::Mode mode) const
return the state of a visibility mode in all the sub component (if at least one sub component is visi...
Definition: MultiComponent.cpp:109
void xmlPrint(std::ostream &) const
print to an output stream in "pseaudo" XML format (do nothing if there are no sub components)...
Definition: MultiComponent.cpp:55
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
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:135
virtual void setVisible(const RenderingMode::Mode mode, const bool b)
set the state of a visibility mode in all the sub component.
Definition: MultiComponent.cpp:117
void removeParentMultiComponent(MultiComponent *)
remove a particular parent MultiComponent
Definition: modeling/libraries/pml/Component.h:171
unsigned int getNumberOfSubComponents() const
return the number of subcomponents
Definition: MultiComponent.h:111
virtual void setPhysicalModel(PhysicalModel *)
set the physical model (recursively)
Definition: MultiComponent.cpp:124
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:128
unsigned int getNumberOfCells() const
get the total nr of cell of the component
Definition: MultiComponent.cpp:74
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:120
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:168
~MultiComponent()
delete all the subcomponents (call the deleteAllSubComponents method)
Definition: MultiComponent.cpp:38
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44
virtual bool isInstanceOf(const char *) const
return true only if the parameter is equal to "MultiComponent"
Definition: MultiComponent.h:148
Component * getSubComponent(const unsigned int) const
get a subcomponent by its order number (index in the list of subcomponents)
Definition: MultiComponent.h:114