CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
43 namespace cx
44 {
45 typedef boost::shared_ptr<class Rep> RepPtr;
46 
47 typedef std::map<QString, RepPtr> RepMap;
48 typedef std::map<QString, VolumetricBaseRepPtr> VolumetricRepMap;
49 typedef boost::shared_ptr<class ThresholdPreview> ThresholdPreviewPtr;
50 typedef boost::shared_ptr<class RepContainer> RepContainerPtr;
51 
61 class cxResourceVisualization_EXPORT RepContainer
62 {
63 public:
64  RepContainer(std::vector<RepPtr> reps) : mReps(reps) {}
65 
66  template<class REP>
67  boost::shared_ptr<REP> findFirst(ToolPtr tool)
68  {
69  for (unsigned i = 0; i < mReps.size(); ++i)
70  {
71  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
72  if (rep && rep->hasTool(tool))
73  {
74  return rep;
75  }
76  }
77  return boost::shared_ptr<REP>();
78  }
79 // template<class REP>
80 // static boost::shared_ptr<REP> findFirstRep(std::vector<RepPtr> reps, ToolPtr tool)
81 // {
82 // for (unsigned i = 0; i < reps.size(); ++i)
83 // {
84 // boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
85 // if (rep && rep->hasTool(tool))
86 // {
87 // return rep;
88 // }
89 // }
90 // return boost::shared_ptr<REP>();
91 // }
92 
93  template<class REP>
94  boost::shared_ptr<REP> findFirst(DataPtr data)
95  {
96  for (unsigned i = 0; i < mReps.size(); ++i)
97  {
98  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(mReps[i]);
99  if (rep && rep->hasData(data))
100  return rep;
101  }
102  return boost::shared_ptr<REP>();
103  }
104 // template<class REP>
105 // static boost::shared_ptr<REP> findFirstRep(std::vector<RepPtr> reps, DataPtr data)
106 // {
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 && rep->hasData(data))
111 // return rep;
112 // }
113 // return boost::shared_ptr<REP>();
114 // }
115 
116  template<class REP>
117  boost::shared_ptr<REP> findFirst()
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)
123  return rep;
124  }
125  return boost::shared_ptr<REP>();
126  }
127 // template<class REP>
128 // static boost::shared_ptr<REP> findFirstRep(std::vector<RepPtr> reps)
129 // {
130 // for (unsigned i = 0; i < reps.size(); ++i)
131 // {
132 // boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
133 // if (rep)
134 // return rep;
135 // }
136 // return boost::shared_ptr<REP>();
137 // }
138 
139  template<class REP>
140  static std::vector<boost::shared_ptr<REP> > findReps(std::vector<RepPtr> reps)
141  {
142  std::vector<boost::shared_ptr<REP> > retval;
143  for (unsigned i = 0; i < reps.size(); ++i)
144  {
145  boost::shared_ptr<REP> rep = boost::dynamic_pointer_cast<REP>(reps[i]);
146  if (rep)
147  retval.push_back(rep);
148  }
149  return retval;
150  }
151 
152 private:
153  std::vector<RepPtr> mReps;
154 };
155 
156 
157 } //namespace cx
158 
159 #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< class RepContainer > RepContainerPtr
boost::shared_ptr< class ThresholdPreview > ThresholdPreviewPtr
Definition: cxRepManager.h:53
boost::shared_ptr< REP > findFirst(ToolPtr tool)
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
boost::shared_ptr< class Tool > ToolPtr
RepContainer(std::vector< RepPtr > reps)