Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ParamGUISample1.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003, 2004 (see file CONTACTS for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS 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 for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /**
27  @example ParamGUISample1.cpp
28  @relates ParamGUI
29  @brief Example for using the parameter gui classes
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 #include <wx/wx.h>
35 
36 #include <Base/Common/BIASpragma.hh>
37 
38 #include <Gui/ParamGUI.hh>
39 #include <Gui/StringConv.hh>
40 #include <Utils/Param.hh>
41 #include <iostream>
42 #include <vector>
43 #include <string>
44 
45 using namespace BIAS;
46 using namespace std;
47 
48 /** \cond HIDDEN_SYMBOLS
49  * \class MyAlgorithm */
50 class MyAlgorithm : public ParamCallbackInterface
51 {
52 public:
53  MyAlgorithm(){coollevel = NULL;};
54  ~MyAlgorithm(){};
55 
56  void ParamAdd(Param &p) {
57  coollevel = p.AddParamInt("coollevel","Really cool threshold",0,0,100,0,1);
58  cooldbl = p.AddParamDouble("cooldbl","Really cool double ",0,0,100,0,1);
59  // set callback class instance to run on parameter change
60  p.RegisterCallbackObject("coollevel",this);
61  p.RegisterCallbackObject("cooldbl", this);
62  };
63 
64 
65  void ParameterChanged(const std::string &name, const void *data){
66  cout <<"Here is MyAlgorithm! My parameter \""<<name<<"\" changed"<<endl;
67  if (data == coollevel)
68  cout <<"Hey, it was \"coollevel\", new cool level is: "<<*coollevel
69  <<endl;
70  };
71 
72 protected:
73  int *coollevel;
74  double *cooldbl;
75 
76 };
77 
78 
79 class MyApp : public wxApp
80 {
81 public:
82  virtual bool OnInit();
83 };
84 
85 DECLARE_APP(MyApp)
86 
87 
88 class MyFrame : public wxFrame
89 {
90 public:
91  MyFrame();
92  ~MyFrame();
93  ParamGUI param_;
94 };
95 
96 // uncool global, for testing
97 MyAlgorithm *algo;
98 
99 // implementation
100 
101 IMPLEMENT_APP(MyApp)
102 
103 bool MyApp::OnInit()
104 {
105  MyFrame *frame = new MyFrame();
106  frame->Show(TRUE);
107  SetTopWindow(frame);
108  return true;
109 }
110 
111 MyFrame::MyFrame()
112 : wxFrame(NULL, -1, _T("ParamGUISample1"), wxDefaultPosition,
113  wxSize(400,600) )
114 {
115  param_.AddParamInt("SampleInt1","Hilfetext zu SampleInt1",0,-100,100,0,1);
116  param_.AddParamBool("SampleBool1","Hilfetext zu SampleBool1",false,0,1);
117  param_.AddParamDouble("SampleDouble1","Hilfetext zu SampleDouble1");
118  param_.AddParamString("SampleString1","Hilfetext zu SampleString1");
119 
120  vector<string> enums;
121  enums.push_back("Enum 1");
122  enums.push_back("Enum 2");
123  enums.push_back("Enum 3");
124  enums.push_back("Enum 4");
125 
126  param_.AddParamEnum("SampleEnum","Hilfetext zu SampleEnum",enums);
127 
128  algo = new MyAlgorithm();
129  algo->ParamAdd(param_);
130 
131  param_.ParseCommandLine(wxTheApp->argc,WxToAsciiArray(wxTheApp->argv,wxTheApp->argc));
132  param_.ShowData();
133  /* You can get the panel via: (commented out to avoid set-but-not-used warning)
134  wxPanel *MyPanel;
135  MyPanel = param_.GetPanel(this,1);
136  */
137 }
138 
139 MyFrame::~MyFrame()
140 {
141  param_.ShowData();
142 }
143 
144 /** \endcond */
The main Parameter Gui interface, derived from BIAS::Param and extends this class.
Definition: ParamGUI.hh:88
int RegisterCallbackObject(const std::string &name, ParamCallbackInterface *obj)
Definition: Param.cpp:1813
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:351
This class provides an interface to be called if parameter changes occured.
Definition: Param.hh:74
This class Param provides generic support for parameters.
Definition: Param.hh:231
Class for converting an array of wxStrings to an array of non-const ASCII strings.
Definition: StringConv.hh:60
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276