iRoCS Toolbox  1.1.0
MC_SVM_Finder.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * Copyright (C) 2004-2015 Olaf Ronneberger, Florian Pigorsch, Jörg Mechnich,
4  * Thorsten Falk
5  *
6  * Image Analysis Lab, University of Freiburg, Germany
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  **************************************************************************/
23 
24 /**************************************************************************
25 ** Title:
26 ** $RCSfile$
27 ** $Revision: 2825 $$Name$
28 ** $Date: 2009-09-15 17:04:15 +0200 (Tue, 15 Sep 2009) $
29 ** Copyright: GPL $Author: ronneber $
30 ** Description:
31 **
32 **
33 **
34 **-------------------------------------------------------------------------
35 **
36 ** $Log$
37 ** Revision 1.2 2005/11/07 22:18:37 mechnich
38 ** changes for g++ 4
39 **
40 ** Revision 1.1 2004/08/26 08:36:59 ronneber
41 ** initital import
42 **
43 **
44 **
45 **************************************************************************/
46 
47 
48 #ifndef MC_SVM_FINDER_HH
49 #define MC_SVM_FINDER_HH
50 
51 #ifdef HAVE_CONFIG_H
52 #include <config.hh>
53 #endif
54 
55 
56 
57 
58 namespace svt
59 {
60 
61  /*======================================================================*/
68 /*======================================================================*/
69 
70 
71  template< typename PRODUCER,
72  typename MC_ITER,
73  typename TC_ITER,
74  typename KF_ITER>
76  {
77  static PRODUCER search( const std::string& mcName,
78  const std::string& tcName,
79  const std::string& kfName)
80  {
81 
82  /*-----------------------------------------------------------------
83  * extract the multiclass, twoclass and kernelfunction
84  * types from the iterators. Because Multiclass and
85  * Twoclass types are templated, 'int' is taken as dummy
86  * template argument
87  *-----------------------------------------------------------------*/
88  typedef typename MC_ITER::template Traits<int>::val_t MCTYPE;
89  typedef typename TC_ITER::template Traits<int>::val_t TCTYPE;
90  typedef typename KF_ITER::val_t KFTYPE;
91 
92  /*-----------------------------------------------------------------
93  * Check if current MultiClass type has the correct name,
94  * otherwise instantiate MC_SVM_Finder with the next MultiClass type
95  *-----------------------------------------------------------------*/
96 
97  if( mcName != "" && mcName != MCTYPE::name())
98  {
99  return MC_SVM_Finder<
100  PRODUCER,
101  typename MC_ITER::next_t,
102  TC_ITER,
103  KF_ITER
104  >::search( mcName, tcName, kfName);
105  }
106  /*-----------------------------------------------------------------
107  * Check if current TwoClass type has the correct name,
108  * otherwise instantiate MC_SVM_Finder with the next TwoClass type
109  *-----------------------------------------------------------------*/
110  else if( tcName != "" && tcName != TCTYPE::name())
111  {
112  return MC_SVM_Finder<
113  PRODUCER,
114  MC_ITER,
115  typename TC_ITER::next_t,
116  KF_ITER
117  >::search( mcName, tcName, kfName);
118  }
119  /*-----------------------------------------------------------------
120  * Check if current Kernel type has the correct name,
121  * otherwise instantiate MC_SVM_Finder with the next Kernel type
122  *-----------------------------------------------------------------*/
123  else if( kfName != "" && kfName != KFTYPE::name())
124  {
125  return MC_SVM_Finder<
126  PRODUCER,
127  MC_ITER,
128  TC_ITER,
129  typename KF_ITER::next_t
130  >::search( mcName, tcName, kfName);
131  }
132  /*-----------------------------------------------------------------
133  * Ok, current MultiClass type, TwoClass type and Kernel
134  * type have the correct name. Instatiate an
135  * BasicCVAdapterTempl with the given types
136  *-----------------------------------------------------------------*/
137  else
138  {
139  typedef typename MC_ITER::template Traits<
140  typename TC_ITER::template Traits<
141  typename KF_ITER::val_t >::val_t >::val_t SVMTYPE;
142 
143  PRODUCER p;
144  // ugly workaround, because p.produce<SVMTYPE>() does not work...
145  SVMTYPE* s=0;
146  p.produce( s);
147 
148  return p;
149  }
150  }
151  };
152 
153 
154  /*-------------------------------------------------------------------------
155  * partial specializations for MC_SVM_Finder, when it has reached the
156  * end of given List, without having found the requested name
157  *-------------------------------------------------------------------------*/
158  template< typename PRODUCER,
159  typename TC_ITER,
160  typename KF_ITER>
161  struct MC_SVM_Finder<PRODUCER, TList_end, TC_ITER, KF_ITER>
162  {
163  static PRODUCER search( const std::string& mcName,
164  const std::string&,
165  const std::string&)
166  {
168  err << "Multi-Class type `" << mcName << "' does not exist!";
169  throw err;
170  }
171  };
172 
173 
174  template< typename PRODUCER,
175  typename MC_ITER,
176  typename KF_ITER>
177  struct MC_SVM_Finder<PRODUCER, MC_ITER, TList_end, KF_ITER>
178  {
179  static PRODUCER search( const std::string&,
180  const std::string& tcName,
181  const std::string&)
182  {
184  err << "Two-Class type `" << tcName << "' does not exist!";
185  throw err;
186  }
187  };
188 
189  template< typename PRODUCER,
190  typename MC_ITER,
191  typename TC_ITER>
192  struct MC_SVM_Finder<PRODUCER, MC_ITER, TC_ITER, TList_end >
193  {
194  static PRODUCER search( const std::string&,
195  const std::string&,
196  const std::string& kfName)
197  {
199  err << "Kernel type `" << kfName << "' does not exist!";
200  throw err;
201  }
202  };
203 }
204 
205 #endif
static PRODUCER search(const std::string &, const std::string &, const std::string &kfName)
The MC_SVM_Finder class finds the appropriate combination of Multiclass, Twoclass and Kernel specifie...
static PRODUCER search(const std::string &, const std::string &tcName, const std::string &)
static PRODUCER search(const std::string &mcName, const std::string &, const std::string &)
static PRODUCER search(const std::string &mcName, const std::string &tcName, const std::string &kfName)