Computer Assited Medical Intervention Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PMManagerDC.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2013 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 PMManagerDC_H
27 #define PMManagerDC_H
28 
29 #include <pml/StructuralComponent.h>
30 #include <pml/MultiComponent.h>
31 #include <pml/PhysicalModel.h>
32 
33 // Qt
34 class QMenu;
35 class QPixmap;
36 #include <QProgressDialog>
37 class QWidget;
38 
39 // PML
40 class PhysicalModel;
41 class Cell;
42 class Atom;
43 
44 
45 // vtk
46 class vtkPoints;
47 class vtkCell;
48 #include <vtkCell.h>
49 #include <vtkPoints.h>
50 #include <vtkSmartPointer.h>
51 
52 // physicalmodel component
53 #include "PMComponentAPI.h"
54 class AtomDC;
55 class ComponentDC;
56 class MultiComponentDC;
58 class PMManagerDCPopup;
59 class CellDC;
60 class AtomDC;
61 class AtomDCWidget;
62 
63 class LoadsManager;
64 
65 // camitk
66 #include <MeshComponent.h>
67 #include <InterfaceGeometry.h>
68 #include <Geometry.h>
69 using namespace camitk;
70 
71 
72 namespace std {
76 typedef std::pair< ::Component *, ComponentDC *> ComponentDCPair;
84 typedef std::map < ::Component *, ComponentDC *> ComponentDCMap;
86 typedef std::map < ::Component *, ComponentDC *>::iterator ComponentDCMapIterator;
87 
91 typedef std::pair<Atom *, AtomDC *> AtomDCPair;
97 typedef std::map <Atom *, AtomDC *> AtomDCMap;
99 typedef std::map <Atom *, AtomDC *>::iterator AtomDCMapIterator;
100 }
101 
112  Q_OBJECT
113 public:
115  PMManagerDC(const QString &) throw(AbortException);
116 
118  PMManagerDC(PhysicalModel *, const QString &);
119 
121  virtual ~PMManagerDC();
122 
124  bool getModified() const;
125 
127  virtual void setName(const QString &);
128 
130  virtual QMenu * getPopupMenu(QWidget* parent);
131 
133  void progressOneStep();
134 
136  virtual QPixmap getIcon();
137 
149  void createPointData();
150 
152  void destroyPointData();
153 
154  /*
155  // /@name Input/Output
156  // /@see save (for vtk export)
157 
158  // /@{
159  // / Transform an geometry to a physical model
160  static PhysicalModel * geometryToPhysicalModel(Geometry *);
161 
162  / ** Read the file given in parameter as a VTK file and create a physical model from it .
163  * As no assumpution could be made on a basic VTK file, the resulting physical model
164  * object will have only the list of atoms and one exclusive component containing all the vtk cells.
165  * As this method use the VtkMeshUtil static methods, it can import from any vtk file that
166  * are supported by the VtkMeshUtil class.
167  * Beware to remember to delete this physical model in your own method.
168  * @return the new physical model or NULL if an error occurs.
169  * /
170  static PhysicalModel * vtkToPhysicalModel(const QString&);
171 
172  / ** Create a StructuralComponent from a list of vtkPoints
173  * (i.e. the resulting structural component is simply a list of atoms).
174  * @param n name to give to the structural component
175  * /
176  static StructuralComponent *vtkToPhysicalModel(PhysicalModel *, vtkSmartPointer<vtkPoints>, const QString& n);
177 
178  / ** Create a Cell Structure from a vtkCell and the atom StructuralComponent describing the
179  * list where to find the atoms to use. This StructuralComponent has to be complete.
180  * This method is mostly used in conjonction with vtkToPhysicalModel(vtkPoints*, std:string) method
181  * (the latter giving the proper StructuralComponent to use here).
182  * /
183  static StructuralComponent *vtkToPhysicalModel(PhysicalModel *, vtkSmartPointer<vtkCell>, StructuralComponent *atomSC);
184 
185  / ** Export the structure to a vtk file.
186  * Write all the list of atoms as the vtkPoints and the exclusive cells as the vtkCells.
187  * @return tells if the method worked properly (or not!).
188  * /
189  static bool physicalModelToVtk(PhysicalModel *, const QString& fileName);
190 
191  / ** same as physicalModelToVtk but considering all the nodes.
192  * Directly write all the atoms and cell, even if some atoms are not used
193  * This is the method to call to export the PM for Ansys, and be able to use
194  * the informative components.
195  * /
196  static bool physicalModelToVtkAllNodes(PhysicalModel *myPM, const QString&);
197  // /@}
198  */
199 
203 
205  PhysicalModel *getPhysicalModel();
206 
208  virtual double getBoundingRadius();
209 
211  virtual void getBounds(double bounds[6]);
212 
214  void computeBoundingRadius();
215 
217  InterfaceGeometry::RenderingModes toDCRenderingMode(::RenderingMode::Mode);
218 
220  ::RenderingMode::Mode toPMRenderingMode(InterfaceGeometry::RenderingModes);
221 
223  ComponentDC * getDC(::Component *);
224 
226  MultiComponentDC * getDC(MultiComponent *);
227 
229  StructuralComponentDC * getDC(StructuralComponent *);
230 
232  CellDC * getDC(Cell *);
233 
235  AtomDC * getDC(Atom *);
236 
238  void addMultiComponentDCPair(std::ComponentDCPair);
239 
241  void addStructuralComponentDCPair(std::ComponentDCPair);
242 
244  void addCellDCPair(std::ComponentDCPair);
245 
247  void addAtomDCPair(std::AtomDCPair);
249 
252 
256  QWidget *getAtomDCWidget(AtomDC *adc = NULL, QWidget *parent = NULL);
257 
259  LoadsManager * getLoadsManager();
260 
262 
263 private:
264 
266  void buildPhysicalModelDCs();
267 
271  virtual void initRepresentation();
272 
274  unsigned int nrOfDoneSteps;
275 
277  unsigned int nrOfSteps;
278 
281 
283  static QPixmap * myPixmap;
284 
286  std::ComponentDCMap myMCDCMap;
287 
289  std::ComponentDCMap mySCDCMap;
290 
292  std::ComponentDCMap myCDCMap;
293 
295  std::AtomDCMap myADCMap;
296 
299 
301  PhysicalModel * myPM;
302 
305 
308 };
309 
310 
311 // -------------------- getPhysicalModel --------------------
312 inline PhysicalModel *PMManagerDC::getPhysicalModel() {
313  return myPM;
314 }
315 
316 // -------------------- getBoundingRadius --------------------
318  return initialBoundingRadius;
319 }
320 
321 // -------------------- getLoadsManager --------------------
323  return myLoadsManager;
324 }
325 
326 // -------------------- C / DC Map --------------------
328  if (mc->isInstanceOf("StructuralComponent"))
329  return (ComponentDC *) getDC(dynamic_cast<StructuralComponent *>(mc));
330  else if (mc->isInstanceOf("MultiComponent"))
331  return (ComponentDC *) getDC(dynamic_cast<MultiComponent *>(mc));
332  else
333  return NULL;
334 }
335 
336 // -------------------- MC / DC Map --------------------
337 inline void PMManagerDC::addMultiComponentDCPair(std::ComponentDCPair p) {
338  myMCDCMap.insert(p);
339 }
340 
341 // -------------------- SC / DC Map --------------------
342 inline void PMManagerDC::addStructuralComponentDCPair(std::ComponentDCPair p) {
343  mySCDCMap.insert(p);
344 }
345 
346 // -------------------- Atom / DC Map --------------------
347 inline void PMManagerDC::addAtomDCPair(std::AtomDCPair p) {
348  myADCMap.insert(p);
349 }
350 
351 inline AtomDC * PMManagerDC::getDC(Atom *a) {
352  if (!a)
353  return NULL;
354  std::AtomDCMapIterator result = myADCMap.find(a);
355  return (result == myADCMap.end()) ? NULL : (result->second);
356 }
357 
358 
359 #endif