Computer Assited Medical Intervention Tool Kit  version 3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PhysicalModel.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 PHYSICALMODEL_H
27 #define PHYSICALMODEL_H
28 
29 #include "PhysicalModelIO.h"
30 #include <string>
31 #include <vector>
32 #include <algorithm>
33 #include "PMLAbortException.h"
34 #include "StructuralComponent.h" // so we can put the optimized getAtom method inline
35 #include "Atom.h" // so we can put the optimized getAtom method inline
36 #include "Cell.h" // so we can put the optimized getCell method inline
37 
38 class MultiComponent;
39 class Component;
40 class Cell;
41 class Structure;
42 
43 // Hide warning for Exception + declspec(nothrow)
44 #if defined(_WIN32) && !defined(__MINGW32__) // MSVC only
45 #pragma warning( disable : 4290 )
46 #endif // MSVC only
47 
49 typedef void (*PtrToSetProgressFunction)(const float donePercentage);
50 
51 namespace std {
55 typedef std::pair<unsigned int, Structure *> GlobalIndexStructurePair;
60 typedef std::map <unsigned int, Structure *> GlobalIndexStructureMap;
62 typedef std::map <unsigned int, Structure *> ::iterator GlobalIndexStructureMapIterator;
63 }
64 
75 
76 public:
83  PhysicalModel();
89  PhysicalModel(const char * fileName, PtrToSetProgressFunction pspf = NULL) throw(PMLAbortException);
91  virtual ~PhysicalModel();
93  static const char * VERSION;
95 
100  const std::string getName() const;
102  void setName(const std::string);
109  bool isModified();
113  void setModified();
115 
129  void xmlPrint(std::ostream &o, bool opt=false);
130 
138  void exportPatran(std::string filename);
139 
147  void exportAnsysMesh(std::string filename);
149 
153  unsigned int getNumberOfExclusiveComponents() const;
155 
157  unsigned int getNumberOfInformativeComponents() const;
158 
160  unsigned int getNumberOfAtoms() const;
161 
163  unsigned int getNumberOfCells() const;
164 
166  Component * getExclusiveComponent(const unsigned int) const;
167 
170 
173 
176 
178  StructuralComponent * getAtoms() const;
179 
181  Component * getInformativeComponent(const unsigned int) const;
182 
185 
191  void setAtoms(StructuralComponent *, bool deleteOld=true);
192 
198  bool addAtom(Atom *);
199 
204  Atom * getAtom(const unsigned int id);
205 
210  bool addGlobalIndexAtomPair(std::GlobalIndexStructurePair);
211 
216  bool addGlobalIndexCellPair(std::GlobalIndexStructurePair);
217 
222  Cell * getCell(const unsigned int id);
223 
225  Structure * getStructureByName(const std::string n);
226 
231  Component * getComponentByName(const std::string n);
232 
237  virtual void setProgress(const float donePercentage);
238 
241  virtual void setAtomPosition(Atom *atom, const double pos[3]);
242 
247  double * getPositionPointer() const;
248 
250  double * getPositionPointer(const unsigned int index) const;
251 
253  double * getPositionPointer(const Atom* a) const;
255 
256 
257 private:
261  void xmlRead(const char * n);
262 
264  bool parseTree(xmlNodePtr root);
266  bool parseAtoms(xmlNodePtr atomsRoot);
268  bool parseComponents(xmlNodePtr exclusiveRoot, Component * father, bool isExclusive);
269 
272 
275 
282 
289 
294 
296  void clear();
297 
299  std::GlobalIndexStructureMap cellMap;
300 
302  std::vector <Cell *> optimizedCellList;
303 
306 
309  void optimizeIndexes();
310 
312  void optimizeIndexes(MultiComponent*, unsigned int *);
313 
315  std::GlobalIndexStructureMap atomMap;
316 
318  void init();
319 
322 
324  double *positionPtr;
325 };
326 
327 
328 // ------------------ simple inline functions ------------------
330  return properties;
331 }
332 
333 inline const std::string PhysicalModel::getName() const {
334  return properties->getName();
335 }
336 
337 inline void PhysicalModel::setName(const std::string n) {
338  properties->setName(n);
339 }
340 
342  return isModifiedFlag;
343 }
344 
346  isModifiedFlag = true;
347 }
348 
350  return exclusiveComponents;
351 }
353  return informativeComponents;
354 }
356  return atoms;
357 }
358 
359 // ------------------ getAtom ------------------
360 inline Atom * PhysicalModel::getAtom(const unsigned int id) {
361 
362  // optimization: first check if the order is the structure is not the same
363  // as the atom index (which is the case very often)
364  Atom *quickAccessed = dynamic_cast<Atom *>(atoms->getStructure(id));
365 
366  if (quickAccessed && quickAccessed->getIndex()==id) {
367  return quickAccessed;
368  }
369  else {
370  // if not then check if it could be found in the map
371  std::GlobalIndexStructureMapIterator mapIt; // a representation map iterator
372  mapIt = atomMap.find(id);
373 
374  // search in the map, and return the correct result
375  return ( (mapIt == atomMap.end()) ? NULL : (Atom *) mapIt->second );
376  }
377 }
378 
379 // ------------------ getCell ------------------
380 inline Cell * PhysicalModel::getCell(const unsigned int cellIndex) {
381  if (cellIndexOptimized) {
382  return optimizedCellList[cellIndex];
383  }
384  else {
385  std::GlobalIndexStructureMapIterator mapIt; // a representation map iterator
386 
387  // check if it was find in the list
388  mapIt = cellMap.find(cellIndex);
389 
390  // search in the map, and return the correct result
391  return ( (mapIt == cellMap.end()) ? NULL : (Cell *) mapIt->second );
392  }
393 }
394 
395 // ------------------ getStructureByName ------------------
396 inline Structure * PhysicalModel::getStructureByName(const std::string n) {
397  // look for structures into the global maps
398 
399  // look for a cell with this name
400  std::GlobalIndexStructureMapIterator mapIt = cellMap.begin();
401 
402  while (mapIt != cellMap.end() && mapIt->second->getName()!=n) {
403  mapIt++;
404  }
405 
406  // if found returns it
407  if (mapIt!=cellMap.end())
408  return mapIt->second;
409 
410  // look now in the atoms
411  mapIt = atomMap.begin();
412 
413  while (mapIt != atomMap.end() && mapIt->second->getName()!=n) {
414  mapIt++;
415  }
416 
417  // if found returns it
418  if (mapIt!=atomMap.end())
419  return mapIt->second;
420 
421  return NULL;
422 }
423 
424 #endif
virtual ~PhysicalModel()
destructor
void setAtoms(StructuralComponent *, bool deleteOld=true)
set the atom structural component.
void init()
initialization method
void clear()
Clear everything. That allows to restart an allready instanciated object from scratch.
PhysicalModel()
Default constructor : this one just initialize everything.
Properties * properties
all physical model properties
Definition: PhysicalModel.h:271
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:41
bool cellIndexOptimized
tell if optimizedCellList can be used
Definition: PhysicalModel.h:305
bool isModified()
check if something have changed
Definition: PhysicalModel.h:341
Pure virtual class that represent an element of the structure.
Definition: Structure.h:43
void setName(std::string)
set the name (use the string = operator)
Definition: Properties.h:234
STL namespace.
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:230
unsigned int getNumberOfExclusiveComponents() const
get the total number of exclusive components
Cell * getCell(const unsigned int id)
get the cell that has the global index given in parameters.
Definition: PhysicalModel.h:380
unsigned int getIndex() const
get the structure unique index (stored in its property)
Describes the properties common to all structures and components.
Definition: Properties.h:57
Component * getInformativeComponent(const unsigned int) const
get an informative component by its index in the list
bool addGlobalIndexCellPair(std::GlobalIndexStructurePair)
add or update a pair to the cell map.
bool isModifiedFlag
is the current property state modified
Definition: PhysicalModel.h:274
Atom * getAtom(const unsigned int id)
Get the atom that has the global index given in parameters.
Definition: PhysicalModel.h:360
Exception class to handle abortion in the xmlReading Particularly useful to handle constructor's abor...
Definition: PMLAbortException.h:39
double * getPositionPointer() const
get the pointer to the memory space allocated for the atom's position.
PtrToSetProgressFunction setProgressFunction
the progress function
Definition: PhysicalModel.h:321
unsigned int getNumberOfCells() const
get the total nr of cell in the physical model (exclusive as well as informative) ...
void setName(const std::string)
set the name of the physical model
Definition: PhysicalModel.h:337
virtual void setProgress(const float donePercentage)
this method is called during a long process everytime a little bit of the process is finished...
Structure * getStructure(const unsigned int) const
get a structure by its index (fisrt structure is at index 0)
Definition: StructuralComponent.h:216
std::GlobalIndexStructureMap atomMap
the association couple list, which contains the direct map between the atom's global index and the at...
Definition: PhysicalModel.h:315
bool addAtom(Atom *)
Add a new atom to the atoms' structural component.
void xmlRead(const char *n)
use the XML Parser/Reader to read an XML file conform to physicalmodel.dtd
MultiComponent * exclusiveComponents
Exclusive components are the non-overlaping components : they defined all the components of the physi...
Definition: PhysicalModel.h:281
bool addGlobalIndexAtomPair(std::GlobalIndexStructurePair)
add or update a pair to the atom map.
MultiComponent * getExclusiveComponents() const
get all the exclusive components
Definition: PhysicalModel.h:349
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
const std::string getName() const
Return the name of the physical model.
Definition: PhysicalModel.h:333
Component * getComponentByName(const std::string n)
get a structural or multi component by its name.
unsigned int getNumberOfInformativeComponents() const
get the total number of informative components
virtual void setAtomPosition(Atom *atom, const double pos[3])
Set the new position of an atom.
void setInformativeComponents(MultiComponent *)
set the exclusive multi component. Becareful: the physical model takes control of this MultiComponent...
StructuralComponent * getAtoms() const
get all the atoms
Definition: PhysicalModel.h:355
bool parseComponents(xmlNodePtr exclusiveRoot, Component *father, bool isExclusive)
read the exclusive components list in the xml tree and build them.
An atom has an unique index in the physical model object, a 3D position, and different basic properti...
Definition: Atom.h:44
void(* PtrToSetProgressFunction)(const float donePercentage)
Definition of a function/method that could be called by the setProgress method.
Definition: PhysicalModel.h:49
void setExclusiveComponents(MultiComponent *)
set the exclusive multi component. Becareful: the physical model takes control of this MultiComponent...
This is the main class of this project.
Definition: PhysicalModel.h:74
void optimizeIndexes()
optimize atom and cell indexes so that each order number is equal to the index
unsigned int getNumberOfAtoms() const
get the number of atoms
void xmlPrint(std::ostream &o, bool opt=false)
print the physical model to an output stream in a XML format (see physicalmodel.xsd for detail about ...
double * positionPtr
the big memory space where all the atom's position are stored (it is one big block, optimizing the memory cache management). Size = 3*nrOfAtoms*sizeof(double)
Definition: PhysicalModel.h:324
bool parseAtoms(xmlNodePtr atomsRoot)
read the atom list in the xml tree and build them.
static const char * VERSION
Current PML library version.
Definition: PhysicalModel.h:93
Structure * getStructureByName(const std::string n)
get a cell using its name
Definition: PhysicalModel.h:396
std::vector< Cell * > optimizedCellList
optimized consecutive cell vector (in here optimizedCellList[i]->getIndex() == i ) ...
Definition: PhysicalModel.h:302
void setModified()
tell the physical model something has changed (for example: a property was modified/added).
Definition: PhysicalModel.h:345
A structural component is composed either by cell or by atoms.
Definition: StructuralComponent.h:48
MultiComponent * informativeComponents
Informative components could be overlaping with other components : they are extra components that giv...
Definition: PhysicalModel.h:288
Properties * getProperties()
get all properties (beware of what you do with them!): please consider calling setModified().
Definition: PhysicalModel.h:329
std::GlobalIndexStructureMap cellMap
the association couple list, which contains the direct map between the cell's global index and the ce...
Definition: PhysicalModel.h:299
StructuralComponent * atoms
List of all the atoms : this is the basic stuff for a physicall model.
Definition: PhysicalModel.h:293
bool parseTree(xmlNodePtr root)
read the xml tree and call other parse methods to biuld the physicalModel.
void exportAnsysMesh(std::string filename)
Save the mesh (atoms/cells) of this PhysicalModel in the Ansys format.
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44
MultiComponent * getInformativeComponents() const
get all the informative components
Definition: PhysicalModel.h:352
Component * getExclusiveComponent(const unsigned int) const
get an exclusive component by its index in the list
void exportPatran(std::string filename)
Save the geometry (atoms/cells) of this PhysicalModel in the Patran format.