Main_Dialog.cpp
Go to the documentation of this file.
1 
23 #include <boost/filesystem.hpp>
24 
25 #include <ros/ros.h>
26 #include <ros/package.h>
27 #include <ros/console.h>
28 
29 #include <boost/regex.hpp>
30 
31 #include <HalconCpp.h>
33 
34 Main_Dialog::Main_Dialog(wxWindow *parent) : MainDialogBase(parent)
35 {
36  std::vector<boost::filesystem::path> files;
37  boost::filesystem::path input_path(ros::package::getPath("asr_descriptor_surface_based_recognition") + INPUT_FOLDER + "/");
38 
39  get_all_files_with_ext(input_path, ".obj", files);
40  for (unsigned int i = 0; i < files.size(); i++) {
41  choice_object_model->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
42  }
43  choice_object_model->SetSelection(0);
44  if (choice_object_model->GetCount() > 0) {
45 
46  std::string object_model_name = std::string(choice_object_model->GetStringSelection().mb_str());
47  std::string object_model_path = input_path.string() + object_model_name;
48  HalconCpp::HObjectModel3D model;
49  model.ReadObjectModel3d(object_model_path.c_str(), "mm", HalconCpp::HTuple(), HalconCpp::HTuple());
50  wxString diameter_string;
51  diameter_string << model.MaxDiameterObjectModel3d();
52  std::replace(diameter_string.begin(), diameter_string.end(), ',', '.');
53  edit_diameter->SetValue(diameter_string);
54  }
55 
56  files.clear();
57  get_all_files_with_ext(input_path, ".dae", files);
58  for (unsigned int i = 0; i < files.size(); i++) {
59  choice_mesh->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
60  }
61  choice_mesh->SetSelection(0);
62 
63  Centre();
64 
65 }
66 
67 Main_Dialog::Main_Dialog(wxWindow *parent, std::string name, std::string object_model, std::string mesh, std::string rotation_type, std::string orientation_x, std::string orientation_y, std::string orientation_z, std::string diameter, std::string score_3D)
68  : MainDialogBase(parent)
69 {
70  edit_name->SetValue(wxString(name.c_str(), wxConvUTF8));
71  edit_orientation_x->SetValue(wxString(orientation_x.c_str(), wxConvUTF8));
72  edit_orientation_y->SetValue(wxString(orientation_y.c_str(), wxConvUTF8));
73  edit_orientation_z->SetValue(wxString(orientation_z.c_str(), wxConvUTF8));
74  edit_diameter->SetValue(wxString(diameter.c_str(), wxConvUTF8));
75  edit_score_3D->SetValue(wxString(score_3D.c_str(), wxConvUTF8));
76 
77  std::vector<boost::filesystem::path> files;
78  boost::filesystem::path input_path(ros::package::getPath("asr_descriptor_surface_based_recognition") + INPUT_FOLDER + "/");
79 
80  get_all_files_with_ext(input_path, ".obj", files);
81  int selection = 0;
82  for (unsigned int i = 0; i < files.size(); i++) {
83  choice_object_model->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
84  if (files[i].string() == object_model) {
85  selection = i;
86  }
87  }
88  choice_object_model->SetSelection(selection);
89 
90 
91  files.clear();
92  selection = 0;
93  get_all_files_with_ext(input_path, ".dae", files);
94  for (unsigned int i = 0; i < files.size(); i++) {
95  choice_mesh->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
96  if (files[i].string() == mesh) {
97  selection = i;
98  }
99  }
100  choice_mesh->SetSelection(selection);
101 
102  if (rotation_type == ROTATIONTYPE_NO_ROTATION) { choice_rotation_type->SetSelection(0); }
103  else if (rotation_type == ROTATIONTYPE_CYLINDER) { choice_rotation_type->SetSelection(1); }
104  else if (rotation_type == ROTATIONTYPE_SPHERE) { choice_rotation_type->SetSelection(2); }
105 
106  Centre();
107 }
108 
109 void Main_Dialog::onDialogClose(wxCloseEvent &event) {
110  wxMessageDialog *dial = new wxMessageDialog(this,
111  wxT("Are you sure to quit?"), wxT("Quit"),
112  wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
113  if (dial->ShowModal() == wxID_YES) {
114  Destroy();
115  }
116 }
117 
118 void Main_Dialog::onObjectModelSelected(wxCommandEvent &event) {
119  boost::filesystem::path input_path(ros::package::getPath("asr_descriptor_surface_based_recognition") + INPUT_FOLDER + "/");
120  std::string object_model_name = std::string(choice_object_model->GetStringSelection().mb_str());
121  std::string object_model_path = input_path.string() + object_model_name;
122  HalconCpp::HObjectModel3D model;
123  model.ReadObjectModel3d(object_model_path.c_str(), "mm", HalconCpp::HTuple(), HalconCpp::HTuple());
124  wxString diameter_string;
125  diameter_string << model.MaxDiameterObjectModel3d();;
126  edit_diameter->SetValue(diameter_string);
127 }
128 
129 void Main_Dialog::onCancelPressed( wxCommandEvent& event )
130 {
131  wxMessageDialog *dial = new wxMessageDialog(this,
132  wxT("Are you sure to quit?"), wxT("Quit"),
133  wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
134  if (dial->ShowModal() == wxID_YES) {
135  Destroy();
136  }
137 }
138 
139 
140 
141 void Main_Dialog::onNextPressed( wxCommandEvent& event )
142 {
143 
144  std::string name = trim(std::string(edit_name->GetValue().mb_str()));
145  std::string orientation_x = trim(std::string(edit_orientation_x->GetValue().mb_str()));
146  std::string orientation_y = trim(std::string(edit_orientation_y->GetValue().mb_str()));
147  std::string orientation_z = trim(std::string(edit_orientation_z->GetValue().mb_str()));
148  std::string diameter = trim(std::string(edit_diameter->GetValue().mb_str()));
149  std::string score_3D = trim(std::string(edit_score_3D->GetValue().mb_str()));
150 
151  if (check_string_redex(name, boost::regex("[a-zA-Z]+"))) {
152  if (check_string_redex(orientation_x, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$"))) {
153  if (check_string_redex(orientation_y, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$"))) {
154  if (check_string_redex(orientation_z, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$"))) {
155  if (check_string_redex(diameter, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
156  if (check_string_redex(score_3D, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
157  //edit values are valid, check choice-values:
158  if (choice_object_model->GetCount() > 0) {
159  if (choice_mesh->GetCount() > 0) {
160  //all input values are valid
161  std::string object_model = std::string(choice_object_model->GetStringSelection().mb_str());
162  std::string mesh = std::string(choice_mesh->GetStringSelection().mb_str());
163  std::string rotation_type = std::string(choice_rotation_type->GetStringSelection().mb_str());
164  DescModelsDialog *descModelsDialog = new DescModelsDialog( (wxWindow*)NULL, name, object_model, mesh, rotation_type, orientation_x, orientation_y, orientation_z, diameter, score_3D);
165 
166  descModelsDialog ->Show();
167  Destroy();
168 
169 
170  } else {
171  wxMessageDialog *dial = new wxMessageDialog(this,
172  wxT("There was no valid mesh found in the input folder. Please provide a mesh-file (*.dae)"), wxT("Warning"), wxOK | wxICON_WARNING);
173  dial->ShowModal();
174  }
175  } else {
176  wxMessageDialog *dial = new wxMessageDialog(this,
177  wxT("There was no valid object-model found in the input folder. Please provide an object model (*.obj)"), wxT("Warning"), wxOK | wxICON_WARNING);
178  dial->ShowModal();
179  }
180  } else {
181  wxMessageDialog *dial = new wxMessageDialog(this,
182  wxT("The provided score is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
183  dial->ShowModal();
184  }
185  } else {
186  wxMessageDialog *dial = new wxMessageDialog(this,
187  wxT("The provided diameter is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
188  dial->ShowModal();
189  }
190  } else {
191  wxMessageDialog *dial = new wxMessageDialog(this,
192  wxT("The provided z-value of the orientation is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
193  dial->ShowModal();
194  }
195  } else {
196  wxMessageDialog *dial = new wxMessageDialog(this,
197  wxT("The provided y-value of the orientation is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
198  dial->ShowModal();
199  }
200  } else {
201  wxMessageDialog *dial = new wxMessageDialog(this,
202  wxT("The provided x-value of the orientation is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
203  dial->ShowModal();
204  }
205  } else {
206  wxMessageDialog *dial = new wxMessageDialog(this,
207  wxT("The provided name is not correct, please enter a name containing only letters!"), wxT("Warning"), wxOK | wxICON_WARNING);
208  dial->ShowModal();
209  }
210 
211 }
212 
213 
214 void Main_Dialog::onKillFocusName(wxFocusEvent &event)
215 {
216  std::string name = trim(std::string(edit_name->GetValue().mb_str()));
217  if (!(check_string_redex(name, boost::regex("^[a-zA-Z]+$")))) {
218  edit_name->SetValue(wxT(""));
219  }
220 }
221 
222 void Main_Dialog::onKillFocusOrientationX(wxFocusEvent &event)
223 {
224  std::string orientation_x = trim(std::string(edit_orientation_x->GetValue().mb_str()));
225  if (!(check_string_redex(orientation_x, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$")))) {
226  edit_orientation_x->SetValue(wxT("1.0"));
227  }
228 }
229 
230 void Main_Dialog::onKillFocusOrientationY(wxFocusEvent &event)
231 {
232  std::string orientation_y = trim(std::string(edit_orientation_y->GetValue().mb_str()));
233  if (!(check_string_redex(orientation_y, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$")))) {
234  edit_orientation_y->SetValue(wxT("0.0"));
235  }
236 }
237 
238 void Main_Dialog::onKillFocusOrientationZ(wxFocusEvent &event)
239 {
240  std::string orientation_z = trim(std::string(edit_orientation_z->GetValue().mb_str()));
241  if (!(check_string_redex(orientation_z, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$")))) {
242  edit_orientation_z->SetValue(wxT("0.0"));
243  }
244 }
245 
246 void Main_Dialog::onKillFocusDiameter(wxFocusEvent &event)
247 {
248  std::string diameter = trim(std::string(edit_diameter->GetValue().mb_str()));
249  if (check_string_redex(diameter, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
250  double dia = boost::lexical_cast<double>(trim(std::string(edit_diameter->GetValue().mb_str())));
251  if (dia <= 0) {
252  edit_diameter->SetValue(wxT("0.2"));
253  }
254  } else {
255  edit_diameter->SetValue(wxT("0.2"));
256  }
257 }
258 
259 void Main_Dialog::onKillFocusScore3D(wxFocusEvent &event)
260 {
261  std::string score_3D = trim(std::string(edit_score_3D->GetValue().mb_str()));
262  if (check_string_redex(score_3D, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
263  double score = boost::lexical_cast<double>(trim(std::string(edit_score_3D->GetValue().mb_str())));
264  if ((score <= 0) || (score >= 1)) {
265  edit_score_3D->SetValue(wxT("0.15"));
266  }
267  } else {
268  edit_score_3D->SetValue(wxT("0.15"));
269  }
270 }
271 
272 void Main_Dialog::onTextEnterName(wxCommandEvent &event)
273 {
274  wxFocusEvent evt;
275  onKillFocusName(evt);
276 }
277 
278 void Main_Dialog::onTextEnterOrientationX(wxCommandEvent &event)
279 {
280  wxFocusEvent evt;
282 }
283 
284 void Main_Dialog::onTextEnterOrientationY(wxCommandEvent &event)
285 {
286  wxFocusEvent evt;
288 }
289 
290 void Main_Dialog::onTextEnterOrientationZ(wxCommandEvent &event)
291 {
292  wxFocusEvent evt;
294 }
295 
296 void Main_Dialog::onTextEnterDiameter(wxCommandEvent &event)
297 {
298  wxFocusEvent evt;
299  onKillFocusDiameter(evt);
300 }
301 
302 void Main_Dialog::onTextEnterScore3D(wxCommandEvent &event)
303 {
304  wxFocusEvent evt;
305  onKillFocusScore3D(evt);
306 }
307 
308 
309 
#define NULL
void onDialogClose(wxCloseEvent &event)
void onCancelPressed(wxCommandEvent &event)
Main_Dialog(wxWindow *parent)
The constructor of this class.
Definition: Main_Dialog.cpp:34
void onKillFocusOrientationY(wxFocusEvent &event)
wxTextCtrl * edit_orientation_x
void onTextEnterOrientationY(wxCommandEvent &event)
std::string trim(std::string input)
Removes spaces from the beginning and end of the given string.
Definition: Utils.cpp:34
void onTextEnterOrientationX(wxCommandEvent &event)
const std::string ROTATIONTYPE_CYLINDER
Definition: Utils.h:40
wxTextCtrl * edit_orientation_y
wxTextCtrl * edit_diameter
void onKillFocusOrientationZ(wxFocusEvent &event)
void onKillFocusDiameter(wxFocusEvent &event)
const std::string ROTATIONTYPE_SPHERE
Definition: Utils.h:43
wxChoice * choice_rotation_type
void onNextPressed(wxCommandEvent &event)
const std::string ROTATIONTYPE_NO_ROTATION
Definition: Utils.h:37
bool check_string_redex(std::string to_check, boost::regex regex)
Checks a string with the given regex.
Definition: Utils.cpp:27
ROSLIB_DECL std::string getPath(const std::string &package_name)
wxTextCtrl * edit_name
wxTextCtrl * edit_orientation_z
void get_all_files_with_ext(const boost::filesystem::path &root, const std::string &ext, std::vector< boost::filesystem::path > &ret)
Gets all files in a directory with a specific extension.
Definition: Utils.cpp:103
void onKillFocusOrientationX(wxFocusEvent &event)
void onObjectModelSelected(wxCommandEvent &event)
const std::string INPUT_FOLDER
Definition: Utils.h:46
void onTextEnterName(wxCommandEvent &event)
void onKillFocusScore3D(wxFocusEvent &event)
void onTextEnterDiameter(wxCommandEvent &event)
wxChoice * choice_object_model
void onKillFocusName(wxFocusEvent &event)
void onTextEnterScore3D(wxCommandEvent &event)
wxTextCtrl * edit_score_3D
wxChoice * choice_mesh
void onTextEnterOrientationZ(wxCommandEvent &event)


asr_descriptor_surface_based_recognition
Author(s): Allgeyer Tobias, Hutmacher Robin, Meißner Pascal
autogenerated on Mon Dec 16 2019 03:31:15