Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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-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 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:
52 
53  unsigned int getNumberOfSubComponents() const;
54  Component * getSubComponent(const unsigned int) const;
55  void addSubComponent(Component *);
64 
71 
73  virtual bool isInstanceOf(const char *) const;
74 
77  void xmlPrint(std::ostream &) const;
78 
80  unsigned int getNumberOfCells() const;
81 
83  Cell * getCell(unsigned int) const;
84 
87 
89  virtual bool isVisible(const RenderingMode::Mode mode) const;
90 
92  virtual void setVisible(const RenderingMode::Mode mode, const bool b);
93 
95  virtual void setPhysicalModel(PhysicalModel *);
96 
97 protected:
101  std::vector <Component *> components;
102 };
103 
104 // -------------------- inline methods -------------------
105 inline unsigned int MultiComponent::getNumberOfSubComponents() const {
106  return components.size();
107 }
108 inline Component * MultiComponent::getSubComponent(const unsigned int i) const {
109  if (i<components.size())
110  return components[i];
111  else
112  return NULL;
113 }
115  // add c in the list
116  components.push_back(c);
117  // add this in the list of c's composing component
118  c->addParentMultiComponent(this);
119 }
121  std::vector <Component *>::iterator it = std::find(components.begin(), components.end(), c);
122  if (it != components.end()) {
123  components.erase(it);
125  }
126 }
128  std::vector <Component *>::iterator it=components.begin();
129  Component *foundC=NULL;
130  while (it!=components.end() && !foundC) {
131  foundC = ((*it)->getName()==n)?(*it):NULL;
132  // look inside the component if it is a MultiComponent
133  if (!foundC && (*it)->isInstanceOf("MultiComponent")) {
134  foundC = ((MultiComponent *) (*it))->getComponentByName(n);
135  }
136  it++;
137  }
138  return foundC;
139 }
140 inline bool MultiComponent::isInstanceOf(const char *className) const {
141  return (std::string(className)==std::string("MultiComponent"));
142 }
143 
144 #endif //MULTICOMPONENT_H
std::vector< Component * > components
List of sub component.
Definition: MultiComponent.h:101
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:41
virtual bool isInstanceOf(const char *) const
return true only if the parameter is equal to "MultiComponent"
Definition: MultiComponent.h:140
MultiComponent(PhysicalModel *)
Default Constructor.
virtual void setPhysicalModel(PhysicalModel *)
set the physical model (recursively)
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
unsigned int getNumberOfCells() const
get the total nr of cell of the component
unsigned int getNumberOfSubComponents() const
Definition: MultiComponent.h:105
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...
virtual void setVisible(const RenderingMode::Mode mode, const bool b)
set the state of a visibility mode in all the sub component.
Component * getComponentByName(const std::string)
conveniant method to get the sub component of the name given in parameter
Definition: MultiComponent.h:127
void removeParentMultiComponent(MultiComponent *)
remove a particular parent MultiComponent
Definition: modeling/libraries/pml/Component.h:171
Component * getSubComponent(const unsigned int) const
Definition: MultiComponent.h:108
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:120
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:40
This is the main class of this project.
Definition: PhysicalModel.h:74
void addSubComponent(Component *)
Definition: MultiComponent.h:114
void xmlPrint(std::ostream &) const
print to an output stream in "pseaudo" XML format (do nothing if there are no sub components)...
void deleteAllSubComponents()
this method free all the sub-components (i.e.
void addParentMultiComponent(MultiComponent *)
add a particular parent MultiComponent in the list
Definition: modeling/libraries/pml/Component.h:168
string(REGEX REPLACE"^.*-(.*)-.*""\\1"ARCH"${CAMITK_CONTINUOUS_INTEGRATION}") string(REGEX REPLACE"^.*-.*-(.*)""\\1"BUILDTYPE"$
Definition: continuous.cmake:34
Cell * getCell(unsigned int) const
get cell by order number (not cell index)
~MultiComponent()
delete all the subcomponents (call the deleteAllSubComponents method)
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44