Fraxinus  17.12
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 #ifndef CXREPCONTAINER_H
34 #define CXREPCONTAINER_H
35 
36 #include "cxResourceVisualizationExport.h"
37 
38 #include <QObject>
39 #include <map>
40 #include <vector>
41 #include "cxForwardDeclarations.h"
42 #include "cxTool.h"
43 
44 namespace cx
45 {
46 typedef boost::shared_ptr<class Rep> RepPtr;
47 
48 typedef std::map<QString, RepPtr> RepMap;
49 typedef std::map<QString, VolumetricBaseRepPtr> VolumetricRepMap;
50 
60 class cxResourceVisualization_EXPORT RepContainer
61 {
62 public:
63  RepContainer(std::vector<RepPtr> reps) : mReps(reps) {}
64 
65  template<class REP>
66  boost::shared_ptr<REP> findFirst(ToolPtr tool)
67  {
68  for (unsigned i = 0; i < mReps.size(); ++i)
69  {
70  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
71  if (rep && rep->hasTool(tool))
72  {
73  return rep;
74  }
75  }
76  return boost::shared_ptr<REP>();
77  }
78 
79  template<class REP>
80  boost::shared_ptr<REP> findFirst(DataPtr data)
81  {
82  for (unsigned i = 0; i < mReps.size(); ++i)
83  {
84  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
85  if (rep && rep->hasData(data))
86  return rep;
87  }
88  return boost::shared_ptr<REP>();
89  }
90 
91  template<class REP>
92  boost::shared_ptr<REP> findFirst()
93  {
94  for (unsigned i = 0; i < mReps.size(); ++i)
95  {
96  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
97  if (rep)
98  return rep;
99  }
100  return boost::shared_ptr<REP>();
101  }
102 
103  template<class REP>
104  static std::vector<boost::shared_ptr<REP> > findReps(std::vector<RepPtr> reps)
105  {
106  std::vector<boost::shared_ptr<REP> > retval;
107  for (unsigned i = 0; i < reps.size(); ++i)
108  {
109  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
110  if (rep)
111  retval.push_back(rep);
112  }
113  return retval;
114  }
115 
116  template<class REP>
117  boost::shared_ptr<REP> findManualToolRep()
118  {
119  for (unsigned i = 0; i < mReps.size(); ++i)
120  {
121  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
122  if (rep && rep->getTool()->hasType(Tool::TOOL_MANUAL))
123  {
124  return rep;
125  }
126  }
127  return boost::shared_ptr<REP>();
128  }
129 
130 private:
131  std::vector<RepPtr> mReps;
132 };
133 
134 
135 } //namespace cx
136 
137 #endif // CXREPCONTAINER_H
std::map< QString, RepPtr > RepMap
Definition: cxRepManager.h:51
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:106
std::map< QString, VolumetricBaseRepPtr > VolumetricRepMap
Definition: cxRepManager.h:52
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:45
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr
RepContainer(std::vector< RepPtr > reps)