Computer Assisted Medical Intervention Tool Kit  version 5.2
modeling/libraries/pml/Component.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, 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 COMPONENT_H
27 #define COMPONENT_H
28 
29 #include "RenderingMode.h"
30 #include "Properties.h"
31 #include <string>
32 #include <vector>
33 #include <algorithm> // for remove
34 class Cell;
35 class MultiComponent;
48 class Component {
49 public:
53  Component(PhysicalModel*, std::string n = "");
54 
56  virtual ~Component();
57 
59  bool isExclusive() const;
60 
62  void setExclusive(const bool);
63 
65  virtual bool isInstanceOf(const char*) const = 0;
66 
68  const std::string getName() const;
69 
71  void setName(const std::string);
72 
75  virtual void xmlPrint(std::ostream&) const = 0;
76 
78  virtual unsigned int getNumberOfCells() const = 0;
79 
81  virtual Cell* getCell(unsigned int) const = 0;
82 
84  virtual bool isVisible(const RenderingMode::Mode mode) const = 0;
85 
87  virtual void setVisible(const RenderingMode::Mode mode, const bool b) = 0;
88 
93  std::vector <MultiComponent*> getAllParentMultiComponents();
94 
96  unsigned int getNumberOfParentMultiComponents() const;
97 
100 
103 
109  virtual void setPhysicalModel(PhysicalModel*);
110 
113 
116 
117 protected:
119 
125  void removeFromParents();
126 
128  void deleteProperties();
129 
130 private:
131  bool exclusive;
132 
136  std::vector <MultiComponent*> parentMultiComponentList;
137 
138 };
139 
140 // -------------- inline -------------
141 inline void Component::setExclusive(const bool b) {
142  exclusive = b;
143 }
144 inline bool Component::isExclusive() const {
145  return exclusive;
146 }
147 inline const std::string Component::getName() const {
148  return properties->getName();
149 }
150 inline void Component::setName(const std::string n) {
151  properties->setName(n);
152 }
153 
154 // -------------- parent Multi Component admin -------------
155 
156 inline std::vector <MultiComponent*> Component::getAllParentMultiComponents() {
157  return parentMultiComponentList;
158 }
159 inline unsigned int Component::getNumberOfParentMultiComponents() const {
160  return (unsigned int) parentMultiComponentList.size();
161 }
163  if (i < parentMultiComponentList.size()) {
164  return parentMultiComponentList[i];
165  }
166  else {
167  return nullptr;
168  }
169 }
171  parentMultiComponentList.push_back(c);
172 }
174  auto it = std::find(parentMultiComponentList.begin(), parentMultiComponentList.end(), c);
175  if (it != parentMultiComponentList.end()) {
176  parentMultiComponentList.erase(it);
177  }
178 }
179 
182 }
183 
185  return properties->getPhysicalModel();
186 }
187 
189  return properties;
190 }
191 
192 
193 #endif //COMPONENT_H
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:46
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
bool isExclusive() const
tell if this component is exclusive or not
Definition: modeling/libraries/pml/Component.h:144
Properties * getProperties()
get the component structural properties (guarantied to be non NULL)
Definition: modeling/libraries/pml/Component.h:188
virtual Cell * getCell(unsigned int) const =0
conveniant method to get cell by order number (not cell index)
void setExclusive(const bool)
set the exclusive flag
Definition: modeling/libraries/pml/Component.h:141
Component(PhysicalModel *, std::string n="")
Default constructor, a component needs to know the PM it is in.
Definition: modeling/libraries/pml/Component.cpp:30
virtual unsigned int getNumberOfCells() const =0
get the total nr of cell of the component
Properties * properties
Definition: modeling/libraries/pml/Component.h:118
virtual void setVisible(const RenderingMode::Mode mode, const bool b)=0
set the state of a visibility mode
virtual void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: modeling/libraries/pml/Component.h:180
unsigned int getNumberOfParentMultiComponents() const
get the number of MultiComponent that are using this Component (= nr of parent component)
Definition: modeling/libraries/pml/Component.h:159
void removeParentMultiComponent(MultiComponent *)
remove a particular parent MultiComponent
Definition: modeling/libraries/pml/Component.h:173
std::vector< MultiComponent * > getAllParentMultiComponents()
get the list of all the Multi Component that are using this Component
Definition: modeling/libraries/pml/Component.h:156
void addParentMultiComponent(MultiComponent *)
add a particular parent MultiComponent in the list
Definition: modeling/libraries/pml/Component.h:170
MultiComponent * getParentMultiComponent(unsigned int)
get a particular MultiComponent that is using this Component (a particular parent component)
Definition: modeling/libraries/pml/Component.h:162
PhysicalModel * getPhysicalModel() const
get the physical model
Definition: modeling/libraries/pml/Component.h:184
virtual void xmlPrint(std::ostream &) const =0
print to an output stream in "pseudo" XML format.
const std::string getName() const
get the name of the component
Definition: modeling/libraries/pml/Component.h:147
virtual bool isInstanceOf(const char *) const =0
pure virtual method, implemented in the child-class
void removeFromParents()
this tell the parent components that this component is removed from memory.
Definition: modeling/libraries/pml/Component.cpp:48
virtual ~Component()
Virtual destructor needed here as this is an abstract class (pure virtual)
Definition: modeling/libraries/pml/Component.cpp:36
void setName(const std::string)
set the name of the component
Definition: modeling/libraries/pml/Component.h:150
virtual bool isVisible(const RenderingMode::Mode mode) const =0
return the state of a visibility mode
void deleteProperties()
delete the "properties" pointer and set it to NULL
Definition: modeling/libraries/pml/Component.cpp:42
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44
This is the main class of this project.
Definition: PhysicalModel.h:86
Describes the properties common to all structures and components.
Definition: Properties.h:59
std::string getName() const
get the name (be careful, this method DOES NOT return a copy, so you got the direct ptr to the name!...
Definition: Properties.h:250
PhysicalModel * getPhysicalModel() const
get the physical model
Definition: Properties.h:262
void setName(std::string)
set the name (use the string = operator)
Definition: Properties.h:254
void setPhysicalModel(PhysicalModel *)
set the physical model
Definition: Properties.h:258
Mode
This is a duplicate of RenderingMode Mode....
Definition: RenderingMode.h:40