Main_Dialog.cpp
Go to the documentation of this file.
00001 
00021 #include "descriptor_surface_based_trainer/Main_Dialog.h"
00022 #include "descriptor_surface_based_trainer/Desc_Models_Dialog.h"
00023 #include <boost/filesystem.hpp>
00024 
00025 #include <ros/ros.h>
00026 #include <ros/package.h>
00027 #include <ros/console.h>
00028 
00029 #include <boost/regex.hpp>
00030 
00031 #include <HalconCpp.h>
00032 #include "descriptor_surface_based_trainer/Utils.h"
00033 
00034 Main_Dialog::Main_Dialog(wxWindow *parent) : MainDialogBase(parent)
00035 {
00036     std::vector<boost::filesystem::path> files;
00037     boost::filesystem::path input_path(ros::package::getPath("asr_descriptor_surface_based_recognition") + INPUT_FOLDER + "/");
00038 
00039     get_all_files_with_ext(input_path, ".obj", files);
00040     for (unsigned int i = 0; i < files.size(); i++) {
00041         choice_object_model->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
00042     }   
00043     choice_object_model->SetSelection(0);
00044     if (choice_object_model->GetCount() > 0) {
00045 
00046         std::string object_model_name =  std::string(choice_object_model->GetStringSelection().mb_str());
00047         std::string object_model_path = input_path.string() + object_model_name;
00048         HalconCpp::HObjectModel3D model;
00049         model.ReadObjectModel3d(object_model_path.c_str(), "mm", HalconCpp::HTuple(), HalconCpp::HTuple());
00050         wxString diameter_string;
00051         diameter_string << model.MaxDiameterObjectModel3d();
00052         std::replace(diameter_string.begin(), diameter_string.end(), ',', '.');
00053         edit_diameter->SetValue(diameter_string);
00054     }
00055 
00056     files.clear();
00057     get_all_files_with_ext(input_path, ".dae", files);
00058     for (unsigned int i = 0; i < files.size(); i++) {
00059         choice_mesh->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
00060     }
00061     choice_mesh->SetSelection(0);
00062 
00063     Centre();
00064 
00065 }
00066 
00067 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)
00068     : MainDialogBase(parent)
00069 {
00070     edit_name->SetValue(wxString(name.c_str(), wxConvUTF8));
00071     edit_orientation_x->SetValue(wxString(orientation_x.c_str(), wxConvUTF8));
00072     edit_orientation_y->SetValue(wxString(orientation_y.c_str(), wxConvUTF8));
00073     edit_orientation_z->SetValue(wxString(orientation_z.c_str(), wxConvUTF8));
00074     edit_diameter->SetValue(wxString(diameter.c_str(), wxConvUTF8));
00075     edit_score_3D->SetValue(wxString(score_3D.c_str(), wxConvUTF8));
00076 
00077     std::vector<boost::filesystem::path> files;
00078     boost::filesystem::path input_path(ros::package::getPath("asr_descriptor_surface_based_recognition") + INPUT_FOLDER + "/");
00079 
00080     get_all_files_with_ext(input_path, ".obj", files);
00081     int selection = 0;
00082     for (unsigned int i = 0; i < files.size(); i++) {
00083         choice_object_model->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
00084         if (files[i].string() == object_model) {
00085             selection = i;
00086         }
00087     }
00088     choice_object_model->SetSelection(selection);
00089 
00090 
00091     files.clear();
00092     selection = 0;
00093     get_all_files_with_ext(input_path, ".dae", files);
00094     for (unsigned int i = 0; i < files.size(); i++) {
00095         choice_mesh->AppendString(wxString(files[i].string().c_str(), wxConvUTF8));
00096         if (files[i].string() == mesh) {
00097             selection = i;
00098         }
00099     }
00100     choice_mesh->SetSelection(selection);
00101 
00102     if (rotation_type == ROTATIONTYPE_NO_ROTATION) { choice_rotation_type->SetSelection(0); }
00103     else if (rotation_type == ROTATIONTYPE_CYLINDER) { choice_rotation_type->SetSelection(1); }
00104     else if (rotation_type == ROTATIONTYPE_SPHERE) { choice_rotation_type->SetSelection(2); }
00105 
00106     Centre();
00107 }
00108 
00109 void Main_Dialog::onDialogClose(wxCloseEvent &event) {
00110     wxMessageDialog *dial = new wxMessageDialog(this,
00111           wxT("Are you sure to quit?"), wxT("Quit"),
00112           wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
00113       if (dial->ShowModal() == wxID_YES) {
00114           Destroy();
00115       }
00116 }
00117 
00118 void Main_Dialog::onObjectModelSelected(wxCommandEvent &event) {
00119     boost::filesystem::path input_path(ros::package::getPath("asr_descriptor_surface_based_recognition") + INPUT_FOLDER + "/");
00120     std::string object_model_name =  std::string(choice_object_model->GetStringSelection().mb_str());
00121     std::string object_model_path = input_path.string() + object_model_name;
00122     HalconCpp::HObjectModel3D model;
00123     model.ReadObjectModel3d(object_model_path.c_str(), "mm", HalconCpp::HTuple(), HalconCpp::HTuple());
00124     wxString diameter_string;
00125     diameter_string << model.MaxDiameterObjectModel3d();;
00126     edit_diameter->SetValue(diameter_string);
00127 }
00128 
00129 void Main_Dialog::onCancelPressed( wxCommandEvent& event )
00130 {  
00131     wxMessageDialog *dial = new wxMessageDialog(this,
00132           wxT("Are you sure to quit?"), wxT("Quit"),
00133           wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
00134       if (dial->ShowModal() == wxID_YES) {
00135           Destroy();
00136       }
00137 }
00138 
00139 
00140 
00141 void Main_Dialog::onNextPressed( wxCommandEvent& event )
00142 {
00143 
00144     std::string name = trim(std::string(edit_name->GetValue().mb_str()));
00145     std::string orientation_x = trim(std::string(edit_orientation_x->GetValue().mb_str()));
00146     std::string orientation_y = trim(std::string(edit_orientation_y->GetValue().mb_str()));
00147     std::string orientation_z = trim(std::string(edit_orientation_z->GetValue().mb_str()));
00148     std::string diameter = trim(std::string(edit_diameter->GetValue().mb_str()));
00149     std::string score_3D = trim(std::string(edit_score_3D->GetValue().mb_str()));
00150 
00151     if (check_string_redex(name, boost::regex("[a-zA-Z]+"))) {
00152         if (check_string_redex(orientation_x, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$"))) {
00153             if (check_string_redex(orientation_y, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$"))) {
00154                 if (check_string_redex(orientation_z, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$"))) {
00155                     if (check_string_redex(diameter, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
00156                         if (check_string_redex(score_3D, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
00157                             //edit values are valid, check choice-values:
00158                             if (choice_object_model->GetCount() > 0) {
00159                                 if (choice_mesh->GetCount() > 0) {
00160                                     //all input values are valid
00161                                     std::string object_model = std::string(choice_object_model->GetStringSelection().mb_str());
00162                                     std::string mesh = std::string(choice_mesh->GetStringSelection().mb_str());
00163                                     std::string rotation_type = std::string(choice_rotation_type->GetStringSelection().mb_str());
00164                                     DescModelsDialog *descModelsDialog = new DescModelsDialog( (wxWindow*)NULL, name, object_model, mesh, rotation_type, orientation_x, orientation_y, orientation_z, diameter, score_3D);
00165 
00166                                     descModelsDialog ->Show();
00167                                     Destroy();
00168 
00169 
00170                                 } else {
00171                                     wxMessageDialog *dial = new wxMessageDialog(this,
00172                                        wxT("There was no valid mesh found in the input folder. Please provide a mesh-file (*.dae)"), wxT("Warning"), wxOK | wxICON_WARNING);
00173                                     dial->ShowModal();
00174                                 }
00175                             } else {
00176                                 wxMessageDialog *dial = new wxMessageDialog(this,
00177                                    wxT("There was no valid object-model found in the input folder. Please provide an object model (*.obj)"), wxT("Warning"), wxOK | wxICON_WARNING);
00178                                 dial->ShowModal();
00179                             }
00180                         } else {
00181                             wxMessageDialog *dial = new wxMessageDialog(this,
00182                                wxT("The provided score is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
00183                             dial->ShowModal();
00184                         }
00185                     } else {
00186                         wxMessageDialog *dial = new wxMessageDialog(this,
00187                            wxT("The provided diameter is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
00188                         dial->ShowModal();
00189                     }
00190                 } else {
00191                     wxMessageDialog *dial = new wxMessageDialog(this,
00192                        wxT("The provided z-value of the orientation is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
00193                     dial->ShowModal();
00194                 }
00195             } else {
00196                 wxMessageDialog *dial = new wxMessageDialog(this,
00197                    wxT("The provided y-value of the orientation is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
00198                 dial->ShowModal();
00199             }
00200         } else {
00201             wxMessageDialog *dial = new wxMessageDialog(this,
00202                wxT("The provided x-value of the orientation is not a valid double!"), wxT("Warning"), wxOK | wxICON_WARNING);
00203             dial->ShowModal();
00204         }
00205     } else {
00206         wxMessageDialog *dial = new wxMessageDialog(this,
00207            wxT("The provided name is not correct, please enter a name containing only letters!"), wxT("Warning"), wxOK | wxICON_WARNING);
00208         dial->ShowModal();
00209     }
00210 
00211 }
00212 
00213 
00214 void Main_Dialog::onKillFocusName(wxFocusEvent &event)
00215 {
00216     std::string name = trim(std::string(edit_name->GetValue().mb_str()));
00217     if (!(check_string_redex(name, boost::regex("^[a-zA-Z]+$")))) {
00218         edit_name->SetValue(wxT(""));
00219     }
00220 }
00221 
00222 void Main_Dialog::onKillFocusOrientationX(wxFocusEvent &event)
00223 {
00224     std::string orientation_x = trim(std::string(edit_orientation_x->GetValue().mb_str()));
00225     if (!(check_string_redex(orientation_x, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$")))) {
00226         edit_orientation_x->SetValue(wxT("1.0"));
00227     }
00228 }
00229 
00230 void Main_Dialog::onKillFocusOrientationY(wxFocusEvent &event)
00231 {
00232     std::string orientation_y = trim(std::string(edit_orientation_y->GetValue().mb_str()));
00233     if (!(check_string_redex(orientation_y, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$")))) {
00234         edit_orientation_y->SetValue(wxT("0.0"));
00235     }
00236 }
00237 
00238 void Main_Dialog::onKillFocusOrientationZ(wxFocusEvent &event)
00239 {
00240     std::string orientation_z = trim(std::string(edit_orientation_z->GetValue().mb_str()));
00241     if (!(check_string_redex(orientation_z, boost::regex("^[-+]?[0-9]+(\\.[0-9]+)?$")))) {
00242         edit_orientation_z->SetValue(wxT("0.0"));
00243     }
00244 }
00245 
00246 void Main_Dialog::onKillFocusDiameter(wxFocusEvent &event)
00247 {
00248     std::string diameter = trim(std::string(edit_diameter->GetValue().mb_str()));
00249     if (check_string_redex(diameter, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
00250         double dia = boost::lexical_cast<double>(trim(std::string(edit_diameter->GetValue().mb_str())));
00251         if (dia <= 0) {
00252             edit_diameter->SetValue(wxT("0.2"));
00253         }
00254     } else {
00255         edit_diameter->SetValue(wxT("0.2"));
00256     }
00257 }
00258 
00259 void Main_Dialog::onKillFocusScore3D(wxFocusEvent &event)
00260 {
00261     std::string score_3D = trim(std::string(edit_score_3D->GetValue().mb_str()));
00262     if (check_string_redex(score_3D, boost::regex("^[0-9]+(\\.[0-9]+)?$"))) {
00263         double score = boost::lexical_cast<double>(trim(std::string(edit_score_3D->GetValue().mb_str())));
00264         if ((score <= 0) || (score >= 1)) {
00265             edit_score_3D->SetValue(wxT("0.15"));
00266         }
00267     } else {
00268         edit_score_3D->SetValue(wxT("0.15"));
00269     }
00270 }
00271 
00272 void Main_Dialog::onTextEnterName(wxCommandEvent &event)
00273 {
00274     wxFocusEvent evt;
00275     onKillFocusName(evt);
00276 }
00277 
00278 void Main_Dialog::onTextEnterOrientationX(wxCommandEvent &event)
00279 {
00280     wxFocusEvent evt;
00281     onKillFocusOrientationX(evt);
00282 }
00283 
00284 void Main_Dialog::onTextEnterOrientationY(wxCommandEvent &event)
00285 {
00286     wxFocusEvent evt;
00287     onKillFocusOrientationY(evt);
00288 }
00289 
00290 void Main_Dialog::onTextEnterOrientationZ(wxCommandEvent &event)
00291 {
00292     wxFocusEvent evt;
00293     onKillFocusOrientationZ(evt);
00294 }
00295 
00296 void Main_Dialog::onTextEnterDiameter(wxCommandEvent &event)
00297 {
00298     wxFocusEvent evt;
00299     onKillFocusDiameter(evt);
00300 }
00301 
00302 void Main_Dialog::onTextEnterScore3D(wxCommandEvent &event)
00303 {
00304     wxFocusEvent evt;
00305     onKillFocusScore3D(evt);
00306 }
00307 
00308 
00309 


asr_descriptor_surface_based_recognition
Author(s): Allgeyer Tobias, Hutmacher Robin, Meißner Pascal
autogenerated on Thu Jun 6 2019 17:57:29