NorMIT-nav  18.04
An IGT application
cxRepContainer.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #ifndef CXREPCONTAINER_H
13 #define CXREPCONTAINER_H
14 
15 #include "cxResourceVisualizationExport.h"
16 
17 #include <QObject>
18 #include <map>
19 #include <vector>
20 #include "cxForwardDeclarations.h"
21 #include "cxTool.h"
22 
23 namespace cx
24 {
25 typedef boost::shared_ptr<class Rep> RepPtr;
26 
27 typedef std::map<QString, RepPtr> RepMap;
28 typedef std::map<QString, VolumetricBaseRepPtr> VolumetricRepMap;
29 
39 class cxResourceVisualization_EXPORT RepContainer
40 {
41 public:
42  RepContainer(std::vector<RepPtr> reps) : mReps(reps) {}
43 
44  template<class REP>
45  boost::shared_ptr<REP> findFirst(ToolPtr tool)
46  {
47  for (unsigned i = 0; i < mReps.size(); ++i)
48  {
49  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
50  if (rep && rep->hasTool(tool))
51  {
52  return rep;
53  }
54  }
55  return boost::shared_ptr<REP>();
56  }
57 
58  template<class REP>
59  boost::shared_ptr<REP> findFirst(DataPtr data)
60  {
61  for (unsigned i = 0; i < mReps.size(); ++i)
62  {
63  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
64  if (rep && rep->hasData(data))
65  return rep;
66  }
67  return boost::shared_ptr<REP>();
68  }
69 
70  template<class REP>
71  boost::shared_ptr<REP> findFirst()
72  {
73  for (unsigned i = 0; i < mReps.size(); ++i)
74  {
75  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
76  if (rep)
77  return rep;
78  }
79  return boost::shared_ptr<REP>();
80  }
81 
82  template<class REP>
83  static std::vector<boost::shared_ptr<REP> > findReps(std::vector<RepPtr> reps)
84  {
85  std::vector<boost::shared_ptr<REP> > retval;
86  for (unsigned i = 0; i < reps.size(); ++i)
87  {
88  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
89  if (rep)
90  retval.push_back(rep);
91  }
92  return retval;
93  }
94 
95  template<class REP>
96  boost::shared_ptr<REP> findManualToolRep()
97  {
98  for (unsigned i = 0; i < mReps.size(); ++i)
99  {
100  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
101  if (rep && rep->getTool()->hasType(Tool::TOOL_MANUAL))
102  {
103  return rep;
104  }
105  }
106  return boost::shared_ptr<REP>();
107  }
108 
109 private:
110  std::vector<RepPtr> mReps;
111 };
112 
113 
114 } //namespace cx
115 
116 #endif // CXREPCONTAINER_H
std::map< QString, RepPtr > RepMap
Definition: cxRepManager.h:30
boost::shared_ptr< REP > findFirst()
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< REP > findManualToolRep()
boost::shared_ptr< REP > findFirst(ToolPtr tool)
Representation of a mouse/keyboard-controlled virtual tool.
Definition: cxTool.h:85
std::map< QString, VolumetricBaseRepPtr > VolumetricRepMap
Definition: cxRepManager.h:31
boost::shared_ptr< REP > findFirst(DataPtr data)
static std::vector< boost::shared_ptr< REP > > findReps(std::vector< RepPtr > reps)
boost::shared_ptr< class Rep > RepPtr
Definition: cxRepManager.h:24
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr
RepContainer(std::vector< RepPtr > reps)