00001
00002
00003
00004
00005
00006 #include <QGraphicsView>
00007 #include <QGraphicsScene>
00008 #include <QImage>
00009 #include <QResizeEvent>
00010 #include <QGradientStops>
00011
00012 #include "CTransferWdt.h"
00013 #include "CProperties.h"
00014 #include "CGLHistogram.h"
00015 #include "QColorSelect.h"
00016 #include "CVolumeStatistics.h"
00017 #include "CConsole.h"
00018
00019 #include "Definitions.h"
00020 #include "modules/Memory/mmgr.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 CTransferWdt::CTransferWdt(QWidget *parent,int transferSize)
00032 : QFrame(parent)
00033 {
00034 ui.setupUi(this);
00035
00036
00037 pHistogram = new CGLHistogram(this);
00038 QHBoxLayout *hL = new QHBoxLayout();
00039 hL->setMargin(0);
00040 hL->addWidget(pHistogram);
00041 ui.glFrame->setLayout(hL);
00042
00043
00044 pQualitySlider = ui.quantSlider;
00045
00046
00047 pColorSelect = new QColorSelect(SELECT_COLOR,this);
00048 connect(pColorSelect,SIGNAL(GradientChanged()),this,SLOT(on_colorSelect_Changed()));
00049 QHBoxLayout *cL = new QHBoxLayout();
00050 cL->setMargin(0);
00051 cL->addWidget(pColorSelect);
00052 ui.colFrame->setLayout(cL);
00053
00054
00055 pAlphaSelect = new QColorSelect(SELECT_ALPHA,this);
00056 connect(pAlphaSelect,SIGNAL(GradientChanged()),this,SLOT(on_alphaSelect_Changed()));
00057 QHBoxLayout *aL = new QHBoxLayout();
00058 aL->setMargin(0);
00059 aL->addWidget(pAlphaSelect);
00060 ui.alFlame->setLayout(aL);
00061
00062 connect(pHistogram,SIGNAL(TransformChange(float,float)),pColorSelect,SLOT(Transform(float,float)));
00063 connect(pHistogram,SIGNAL(TransformChange(float,float)),pAlphaSelect,SLOT(Transform(float,float)));
00064
00065 colorTransferImg = new QImage(transferSize,5,QImage::Format_ARGB32);
00066 alphaTransferImg = new QImage(transferSize,5,QImage::Format_RGB32);
00067 transfer = new uchar[transferSize*4];
00068 dirty = true;
00069 }
00070
00071
00072 CTransferWdt::~CTransferWdt()
00073 {
00074 delete pHistogram;
00075 delete pColorSelect;
00076 delete pAlphaSelect;
00077 delete colorTransferImg;
00078 delete alphaTransferImg;
00079 SAFE_DELETE_ARRAY(transfer);
00080 }
00081
00082
00083 void CTransferWdt::SetHistogramData(float * data,int dataSize)
00084 {
00085 pHistogram->DisplayData(data,dataSize);
00086 }
00087
00088
00089 int CTransferWdt::GetHistogramQuality()
00090 {
00091 return histQuality;
00092 }
00093
00094
00095 void CTransferWdt::SetHistogramQuality(int val)
00096 {
00097 histQuality = val;
00098 pQualitySlider->setValue(val);
00099 }
00100
00101
00102 int CTransferWdt::GetHistogramSize()
00103 {
00104 return histSize;
00105 }
00106
00107
00108 void CTransferWdt::SetHistogramSize( int size )
00109 {
00110 histSize = size;
00111 }
00112
00113
00114 QSize CTransferWdt::GetTransferSize()
00115 {
00116 return QSize(colorTransferImg->width(),1);
00117 }
00118
00119
00120 void CTransferWdt::SetTransferSize( int size)
00121 {
00122 delete colorTransferImg;
00123 delete alphaTransferImg;
00124
00125 colorTransferImg = new QImage(size,5,QImage::Format_ARGB32);
00126 alphaTransferImg = new QImage(size,5,QImage::Format_RGB32);
00127
00128 uchar * oldtransfer = transfer;
00129 transfer = new uchar[size*4];
00130 SAFE_DELETE_ARRAY(oldtransfer);
00131 }
00132
00133
00134 void CTransferWdt::SetColorStops(QGradientStops & stopList, eColorSelectType type)
00135 {
00136 QColorSelect * ptr;
00137
00138 if(type == SELECT_COLOR){
00139 ptr = pColorSelect;
00140 }else{
00141 ptr = pAlphaSelect;
00142 }
00143
00144 for(int i = 0 ; i < stopList.size() ; i++){
00145 ptr->SetColorStop(stopList.at(i).first,QColor(stopList.at(i).second));
00146 }
00147 }
00148
00149
00150 QGradientStops CTransferWdt::GetColorStops( eColorSelectType type )
00151 {
00152 if(type == SELECT_COLOR){
00153 return pColorSelect->GetColorStops();
00154 }else{
00155 return pAlphaSelect->GetColorStops();
00156 }
00157 }
00158
00159
00160 void CTransferWdt::ClearColorStops(eColorSelectType type)
00161 {
00162 if(type == SELECT_COLOR){
00163 pColorSelect->ClearColorStops();
00164 }else{
00165 pAlphaSelect->ClearColorStops();
00166 }
00167 }
00168
00169
00170
00171
00172
00173
00174 void CTransferWdt::resizeEvent( QResizeEvent * event)
00175 {
00176
00177 }
00178
00179
00180
00181
00182
00183
00184 void CTransferWdt::on_quantSlider_valueChanged(int val)
00185 {
00186 histQuality = val;
00187 emit Dirty(DIRTY_HISTOGRAM);
00188 }
00189
00190
00191 void CTransferWdt::on_colorSelect_Changed()
00192 {
00193 pColorSelect->GetGradient(*colorTransferImg);
00194 memcpy(transfer,colorTransferImg->rgbSwapped().scanLine(4),colorTransferImg->width()*4);
00195 on_alphaSelect_Changed();
00196 }
00197
00198
00199 void CTransferWdt::on_alphaSelect_Changed()
00200 {
00201 pAlphaSelect->GetGradient(*alphaTransferImg);
00202 uchar * alphaScanline = alphaTransferImg->scanLine(4);
00203
00204 for(int i = 3 ; i< colorTransferImg->width()*4 ; i+= 4){
00205 transfer[i] = alphaScanline[i-2];
00206 }
00207 dirty = true;
00208
00209 emit Dirty(DIRTY_TRANSFER);
00210 }
00211
00212 void CTransferWdt::on_logCheck_pressed()
00213 {
00214
00215 }
00216
00217 void CTransferWdt::on_overCheck_pressed()
00218 {
00219
00220 }
00221
00222 void CTransferWdt::on_logCheck_stateChanged(int)
00223 {
00224 emit Dirty(DIRTY_LOG);
00225 }
00226
00227 void CTransferWdt::on_overCheck_stateChanged(int)
00228 {
00229 emit Dirty(DIRTY_OVERLAY);
00230 }