threshold_config_widget.cpp

Go to the documentation of this file.
00001 //--------------------------------------------------
00012 //---------------------------------------------------
00013 
00014 #include "threshold_config_widget.h"
00015 #include "threshold_configuration.h"
00016 #include "../../exceptions/invalid_cast_exception.h"
00017 #include "../../datasets/pixel_metadata.h"
00018 
00019 #include <QGridLayout>
00020 #include <QLabel>
00021 #include <QMessageBox>
00022 #include <QSpinBox>
00023 #include <QErrorMessage>
00024 #include <iostream>
00025 
00026 namespace imedgine
00027 {
00028 
00029   //--------------------------------------------------
00030 
00031   ThresholdConfigWidget::ThresholdConfigWidget()
00032     : ConfigWidget()
00033   {
00034    
00035     
00036     
00037   }
00038 
00039   //--------------------------------------------------
00040 
00041   ThresholdConfigWidget::~ThresholdConfigWidget()
00042   {
00043   }
00044   
00045   //--------------------------------------------------
00046 
00047   void ThresholdConfigWidget::applyConfiguration()
00048       throw(InvalidCastException)
00049   {
00050     ThresholdConfiguration* configuration = dynamic_cast<ThresholdConfiguration*>(configuration_.get());
00051     
00052     if(configuration == 0)
00053     {
00054       throw(InvalidCastException("ThresholdConfigWidget", 
00055                                  "ThresholdConfiguration", 
00056                                  "Configuration"));
00057     }
00058     configuration->setLowerBound(lower_spin_box_->value());
00059     configuration->setUpperBound(upper_spin_box_->value());
00060     configuration->setDefaultPixelValue(default_spin_box_->value());
00061   }
00062 
00063   //--------------------------------------------------
00064 
00065   void ThresholdConfigWidget::setupUi()
00066   {
00067     layout_ = new QGridLayout(this);
00068     QLabel* minimum_label = new QLabel(tr("Minimum"));
00069     QLabel* maximum_label = new QLabel(tr("Maximum"));
00070     QLabel* default_value_label = new QLabel(tr("Default"));
00071     
00072     lower_spin_box_ = new QSpinBox();
00073     upper_spin_box_ = new QSpinBox();
00074     default_spin_box_ = new QSpinBox();
00075     
00076     layout_->addWidget(minimum_label, 0,0);
00077     layout_->addWidget(maximum_label, 1,0);
00078     layout_->addWidget(default_value_label, 2,0);
00079     
00080     layout_->addWidget(lower_spin_box_, 0, 1);
00081     layout_->addWidget(upper_spin_box_, 1, 1);
00082     layout_->addWidget(default_spin_box_, 2, 1);
00083   }
00084   
00085   //--------------------------------------------------
00086 
00087   bool ThresholdConfigWidget::showConfiguration()
00088   {
00089     setupUi();
00090     metadata_pointer_type meta_data = getMetadataForInputDataset("threshold_input");
00091     
00092     if(meta_data == 0)
00093     {
00094       QErrorMessage message;
00095       message.showMessage ( tr("Error") );
00096       std::cout << "0 received" << std::endl;
00097       return false;
00098     }
00099     
00100     PixelMetadata* pixel_metadata = dynamic_cast<PixelMetadata*>(meta_data.get());
00101     if(pixel_metadata == 0)
00102     {
00103       QErrorMessage message;
00104       message.showMessage ( tr("Error2") );
00105       std::cout << "dyamic cast received0 " << std::endl;
00106       return false;
00107     }
00108     switch(pixel_metadata->getNumBytesPerPixel())
00109     {
00110       case 1:
00111       {
00112         lower_spin_box_->setMinimum(std::numeric_limits<one_byte_pixel_type>::min());
00113         upper_spin_box_->setMinimum(std::numeric_limits<one_byte_pixel_type>::min());
00114         default_spin_box_->setMinimum(std::numeric_limits<one_byte_pixel_type>::min());
00115         
00116         lower_spin_box_->setMaximum(std::numeric_limits<one_byte_pixel_type>::max());
00117         upper_spin_box_->setMaximum(std::numeric_limits<one_byte_pixel_type>::max());
00118         default_spin_box_->setMaximum(std::numeric_limits<one_byte_pixel_type>::max());
00119         
00120         lower_spin_box_->setValue(std::numeric_limits<one_byte_pixel_type>::min());
00121         upper_spin_box_->setValue(std::numeric_limits<one_byte_pixel_type>::max());
00122         default_spin_box_->setValue(0);
00123         return true;
00124       }
00125       case 2:
00126       {
00127         lower_spin_box_->setMinimum(std::numeric_limits<two_byte_pixel_type>::min());
00128         upper_spin_box_->setMinimum(std::numeric_limits<two_byte_pixel_type>::min());
00129         default_spin_box_->setMinimum(std::numeric_limits<two_byte_pixel_type>::min());
00130         
00131         lower_spin_box_->setMaximum(std::numeric_limits<two_byte_pixel_type>::max());
00132         upper_spin_box_->setMaximum(std::numeric_limits<two_byte_pixel_type>::max());
00133         default_spin_box_->setMaximum(std::numeric_limits<two_byte_pixel_type>::max());
00134 
00135         lower_spin_box_->setValue(std::numeric_limits<two_byte_pixel_type>::min());
00136         upper_spin_box_->setValue(std::numeric_limits<two_byte_pixel_type>::max());
00137         default_spin_box_->setValue(0);
00138         
00139         return true;
00140       }
00141       case 4:
00142       {
00143         lower_spin_box_->setMinimum(
00144             static_cast<int>(std::numeric_limits<four_byte_pixel_type>::min()));
00145         upper_spin_box_->setMinimum(
00146             static_cast<int>(std::numeric_limits<four_byte_pixel_type>::min()));
00147         default_spin_box_->setMinimum(
00148             static_cast<int>(std::numeric_limits<four_byte_pixel_type>::min()));
00149 
00150         lower_spin_box_->setMaximum(
00151             static_cast<int>(std::numeric_limits<four_byte_pixel_type>::max()));
00152         upper_spin_box_->setMaximum(
00153             static_cast<int>(std::numeric_limits<four_byte_pixel_type>::max()));
00154         default_spin_box_->setMaximum(
00155             static_cast<int>(std::numeric_limits<four_byte_pixel_type>::max()));
00156         
00157         lower_spin_box_->setValue(static_cast<int>(std::numeric_limits<four_byte_pixel_type>::min()));
00158         upper_spin_box_->setValue(static_cast<int>(std::numeric_limits<four_byte_pixel_type>::max()));
00159         default_spin_box_->setValue(0);
00160         return true;
00161       }
00162       default:
00163       {
00164         QErrorMessage message;
00165         message.showMessage ( tr("Error default") );
00166       
00167         return false;
00168       }
00169       
00170     }
00171     
00172   }
00173 }
00174 

Generated on Sun Aug 13 18:19:37 2006 for iMEDgine by  doxygen 1.4.6