Computer Assited Medical Intervention Tool Kit  version 4.0
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-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 PHYSICALMODEL_H
27 #define PHYSICALMODEL_H
28 
29 //pmlschema forward declaration
30 namespace physicalModel {
31 class PhysicalModel;
32 class Atoms;
33 class ExclusiveComponent;
34 class InformativeComponent;
35 class MultiComponent;
36 }
37 
38 #include "PhysicalModelIO.h"
39 #include <string>
40 #include <memory>
41 #include <algorithm>
42 #include "PMLAbortException.h"
43 #include "StructuralComponent.h" // so we can put the optimized getAtom method inline
44 #include "Atom.h" // so we can put the optimized getAtom method inline
45 #include "Cell.h" // so we can put the optimized getCell method inline
46 
47 
48 class MultiComponent;
49 class Component;
50 class Cell;
51 class Structure;
52 
53 
54 // Hide warning for Exception + declspec(nothrow)
55 #if defined(_WIN32) && !defined(__MINGW32__) // MSVC only
56 #pragma warning( disable : 4290 )
57 #endif // MSVC only
58 
60 typedef void (*PtrToSetProgressFunction)(const float donePercentage);
61 
62 namespace std {
66 typedef std::pair<unsigned int, Structure *> GlobalIndexStructurePair;
71 typedef std::map <unsigned int, Structure *> GlobalIndexStructureMap;
73 typedef std::map <unsigned int, Structure *> ::iterator GlobalIndexStructureMapIterator;
74 }
75 
76 
87 
88 public:
95  PhysicalModel();
101  PhysicalModel(const char * fileName, PtrToSetProgressFunction pspf = NULL) throw(PMLAbortException);
103  virtual ~PhysicalModel();
105  static const char * VERSION;
107 
112  const std::string getName() const;
114  void setName(const std::string);
119  Properties * getProperties();
121  bool isModified();
125  void setModified();
127 
141  void xmlPrint(std::ostream &o, bool opt=false);
142 
150  void exportPatran(std::string filename);
151 
159  void exportAnsysMesh(std::string filename);
161 
165  unsigned int getNumberOfExclusiveComponents() const;
167 
169  unsigned int getNumberOfInformativeComponents() const;
170 
172  unsigned int getNumberOfAtoms() const;
173 
175  unsigned int getNumberOfCells() const;
176 
178  Component * getExclusiveComponent(const unsigned int) const;
179 
181  void setExclusiveComponents(MultiComponent *);
182 
184  MultiComponent * getExclusiveComponents() const;
185 
187  MultiComponent * getInformativeComponents() const;
188 
190  StructuralComponent * getAtoms() const;
191 
193  Component * getInformativeComponent(const unsigned int) const;
194 
196  void setInformativeComponents(MultiComponent *);
197 
203  void setAtoms(StructuralComponent *, bool deleteOld=true);
204 
210  bool addAtom(Atom *);
211 
224  Atom * getAtom(const unsigned int id);
225 
230  bool addGlobalIndexAtomPair(std::GlobalIndexStructurePair);
231 
236  bool addGlobalIndexCellPair(std::GlobalIndexStructurePair);
237 
242  Cell * getCell(const unsigned int id);
243 
245  Structure * getStructureByName(const std::string n);
246 
251  Component * getComponentByName(const std::string n);
252 
257  virtual void setProgress(const float donePercentage);
258 
261  virtual void setAtomPosition(Atom *atom, const double pos[3]);
262 
267  double * getPositionPointer() const;
268 
270  double * getPositionPointer(const unsigned int index) const;
271 
273  double * getPositionPointer(const Atom* a) const;
275 
276 
277 private:
281  void xmlRead(const char * n) throw(PMLAbortException);
282 
284  bool parseTree(std::auto_ptr<physicalModel::PhysicalModel> root, std::string defaultName);
286  bool parseAtoms(physicalModel::Atoms atomsRoot);
288  bool parseComponents(physicalModel::MultiComponent mcFather, Component* father, bool isExclusive );
289 
292 
295 
302 
309 
314 
316  void clear();
317 
320 
322  std::vector <Cell *> optimizedCellList;
323 
326 
329  void optimizeIndexes();
330 
332  void optimizeIndexes(MultiComponent*, unsigned int *);
333 
336 
338  void init();
339 
342 
344  double *positionPtr;
345 };
346 
347 
348 // ------------------ simple inline functions ------------------
350  return properties;
351 }
352 
353 inline const std::string PhysicalModel::getName() const {
354  return properties->getName();
355 }
356 
357 inline void PhysicalModel::setName(const std::string n) {
358  properties->setName(n);
359 }
360 
362  return isModifiedFlag;
363 }
364 
366  isModifiedFlag = true;
367 }
368 
370  return exclusiveComponents;
371 }
373  return informativeComponents;
374 }
376  return atoms;
377 }
378 
379 // ------------------ getAtom ------------------
380 inline Atom * PhysicalModel::getAtom(const unsigned int id) {
381 
382  // optimization: first check if the order is the structure is not the same
383  // as the atom index (which is the case very often)
384  Atom *quickAccessed = dynamic_cast<Atom *>(atoms->getStructure(id));
385 
386  if (quickAccessed && quickAccessed->getIndex()==id) {
387  return quickAccessed;
388  } else {
389  // if not then check if it could be found in the map
390  std::GlobalIndexStructureMapIterator mapIt; // a representation map iterator
391  mapIt = atomMap.find(id);
392 
393  // search in the map, and return the correct result
394  return ( (mapIt == atomMap.end()) ? NULL : (Atom *) mapIt->second );
395  }
396 }
397 
398 // ------------------ getCell ------------------
399 inline Cell * PhysicalModel::getCell(const unsigned int cellIndex) {
400  if (cellIndexOptimized) {
401  return optimizedCellList[cellIndex];
402  } else {
403  std::GlobalIndexStructureMapIterator mapIt; // a representation map iterator
404 
405  // check if it was find in the list
406  mapIt = cellMap.find(cellIndex);
407 
408  // search in the map, and return the correct result
409  return ( (mapIt == cellMap.end()) ? NULL : (Cell *) mapIt->second );
410  }
411 }
412 
413 // ------------------ getStructureByName ------------------
414 inline Structure * PhysicalModel::getStructureByName(const std::string n) {
415  // look for structures into the global maps
416 
417  // look for a cell with this name
418  std::GlobalIndexStructureMapIterator mapIt = cellMap.begin();
419 
420  while (mapIt != cellMap.end() && mapIt->second->getName()!=n) {
421  mapIt++;
422  }
423 
424  // if found returns it
425  if (mapIt!=cellMap.end())
426  return mapIt->second;
427 
428  // look now in the atoms
429  mapIt = atomMap.begin();
430 
431  while (mapIt != atomMap.end() && mapIt->second->getName()!=n) {
432  mapIt++;
433  }
434 
435  // if found returns it
436  if (mapIt!=atomMap.end())
437  return mapIt->second;
438 
439  return NULL;
440 }
441 
442 #endif
std::map< unsigned int, Structure * > GlobalIndexStructureMap
definition of the association set (=map in STL) globalIndexStructureMap.
Definition: PhysicalModel.h:71
const std::string getName() const
Return the name of the physical model.
Definition: PhysicalModel.h:353
Properties * properties
all physical model properties
Definition: PhysicalModel.h:291
A cell has an unique index in the physical model object, is composed by atoms, and different basic pr...
Definition: Cell.h:46
bool cellIndexOptimized
tell if optimizedCellList can be used
Definition: PhysicalModel.h:325
std::pair< unsigned int, Structure * > GlobalIndexStructurePair
definition of a couple (=STL pair) (int , Structure *) this associates a global cell/atom index to th...
Definition: PhysicalModel.h:66
bool isModified()
check if something have changed
Definition: PhysicalModel.h:361
MultiComponent * getInformativeComponents() const
get all the informative components
Definition: PhysicalModel.h:372
StructuralComponent * getAtoms() const
get all the atoms
Definition: PhysicalModel.h:375
Pure virtual class that represent an element of the structure.
Definition: Structure.h:43
STL namespace.
Cell * getCell(const unsigned int id)
get the cell that has the global index given in parameters.
Definition: PhysicalModel.h:399
Describes the properties common to all structures and components.
Definition: Properties.h:59
bool isModifiedFlag
is the current property state modified
Definition: PhysicalModel.h:294
Atom * getAtom(const unsigned int id)
Get the atom that has the global index given in parameters.
Definition: PhysicalModel.h:380
Exception class to handle abortion in the xmlReading Particularly useful to handle constructor&#39;s abor...
Definition: PMLAbortException.h:39
unsigned int getIndex() const
get the structure unique index (stored in its property)
Definition: Structure.cpp:30
Definition: Atom.h:36
PtrToSetProgressFunction setProgressFunction
the progress function
Definition: PhysicalModel.h:341
void setName(const std::string)
set the name of the physical model
Definition: PhysicalModel.h:357
std::GlobalIndexStructureMap atomMap
the association couple list, which contains the direct map between the atom&#39;s global index and the at...
Definition: PhysicalModel.h:335
std::map< unsigned int, Structure * >::iterator GlobalIndexStructureMapIterator
the iterator corresponding to GlobalIndexStructureMap
Definition: PhysicalModel.h:73
MultiComponent * exclusiveComponents
Exclusive components are the non-overlaping components : they defined all the components of the physi...
Definition: PhysicalModel.h:301
A component is something that composed something and could also be a part of something.
Definition: modeling/libraries/pml/Component.h:48
MultiComponent * getExclusiveComponents() const
get all the exclusive components
Definition: PhysicalModel.h:369
An atom has an unique index in the physical model object, a 3D position, and different basic properti...
Definition: Atom.h:49
This is the main class of this project.
Definition: PhysicalModel.h:86
double * positionPtr
the big memory space where all the atom&#39;s position are stored (it is one big block, optimizing the memory cache management). Size = 3*nrOfAtoms*sizeof(double)
Definition: PhysicalModel.h:344
static const char * VERSION
Current PML library version.
Definition: PhysicalModel.h:105
Structure * getStructureByName(const std::string n)
get a cell using its name
Definition: PhysicalModel.h:414
void(* PtrToSetProgressFunction)(const float donePercentage)
Definition of a function/method that could be called by the setProgress method.
Definition: PhysicalModel.h:60
std::vector< Cell * > optimizedCellList
optimized consecutive cell vector (in here optimizedCellList[i]->getIndex() == i ) ...
Definition: PhysicalModel.h:322
void setModified()
tell the physical model something has changed (for example: a property was modified/added).
Definition: PhysicalModel.h:365
A structural component is composed either by cell or by atoms.
Definition: StructuralComponent.h:52
MultiComponent * informativeComponents
Informative components could be overlaping with other components : they are extra components that giv...
Definition: PhysicalModel.h:308
Properties * getProperties()
get all properties (beware of what you do with them!): please consider calling setModified().
Definition: PhysicalModel.h:349
std::GlobalIndexStructureMap cellMap
the association couple list, which contains the direct map between the cell&#39;s global index and the ce...
Definition: PhysicalModel.h:319
StructuralComponent * atoms
List of all the atoms : this is the basic stuff for a physicall model.
Definition: PhysicalModel.h:313
A multi-component stores other components, hence providing a way to have an tree representation of co...
Definition: MultiComponent.h:44