]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuTransferFunctionView.cxx
MIP function
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuTransferFunctionView.cxx
1 #include "bbmaracasvisuTransferFunctionView.h"
2 #include "bbcreaMaracasVisuPackage.h"
3 namespace bbcreaMaracasVisu
4 {
5
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,TransferFunctionView)
7 BBTK_BLACK_BOX_IMPLEMENTATION(TransferFunctionView,bbtk::WxBlackBox);
8
9 //-----------------------------------------------------
10 void TransferFunctionView::Process()
11 {
12
13         
14
15         
16
17         if(bbGetInputIn()!=NULL){
18
19                 if(_currentimg != bbGetInputIn()){
20                         _currentimg =  bbGetInputIn();
21                         //mwxwidget->initializeHistogram(_currentimg);                  
22                         mwxwidget->setImageData(_currentimg);   
23                         //mwxwidget->Refresh(); 
24                 }               
25
26                 onColorChange();
27                 
28                 /*bbSetOutputGreyLevel(greylevel);
29                 bbSetOutputValue(value);
30                 bbSetOutputGreyLevelColors(greylevelcolors);
31                 bbSetOutputRed(red);
32                 bbSetOutputGreen(green);
33                 bbSetOutputBlue(blue);*/
34
35
36
37
38         }
39         
40     
41 }
42
43 void TransferFunctionView::onColorChange(){
44
45         std::vector<double> greylevel;
46         std::vector<double> value;
47
48         std::vector<double> greylevelcolors;
49         std::vector<double> red;
50         std::vector<double> green;
51         std::vector<double> blue;
52
53         mwxwidget->GetValuesPointsFunction(greylevel, value);
54         mwxwidget->GetValuesColorPointsFunction(greylevelcolors,red, green,blue);
55
56
57         _tfun->RemoveAllPoints();
58         for(int i = 0; i < greylevel.size();i++){
59                 _tfun->AddPoint(greylevel[i], value[i]);
60                 std::cout<<"TransferFunctionView::Process()transfer function "<<greylevel[i]<<" "<< value[i]<<std::endl;
61         }
62         _ctfun->RemoveAllPoints();
63         for(int i = 0; i < greylevelcolors.size();i++){
64                 _ctfun->AddRGBPoint(greylevelcolors[i], red[i],green[i], blue[i]);
65         std::cout<<"TransferFunctionView::Process()transfer color function "<<greylevelcolors[i]<<" "<<red[i]<<" "<<green[i]<<" "<<blue[i]<<std::endl;
66         }               
67
68         bbSignalOutputModification();
69         
70         _tfun->Update();
71         bbSetOutputOpacityFunction(_tfun);
72         bbSetOutputColorFunction(_ctfun);
73 }
74
75 void TransferFunctionView::onSliderChange(){
76         
77
78
79
80         bbSignalOutputModification();
81
82         bbSetOutputWindowLevel(mwxwidget->GetWindowLevel());
83         bbSetOutputColorLevel(mwxwidget->GetColorLevel());
84
85 }
86
87 //-----------------------------------------------------
88 void TransferFunctionView::CreateWidget(wxWindow* parent)
89 {
90         bbtkDebugMessageInc("Core",9,"TransferFunctionView::CreateWxWindow()"<<std::endl);
91         
92         mwxwidget = new HistogramDialogComboBox(parent);                                
93
94
95         HandlerTransferFunctionView* handler = new HandlerTransferFunctionView(this);
96
97         parent->Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction) (&HandlerTransferFunctionView::onColorChange),NULL,handler);
98         parent->Connect(mwxwidget->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) (&HandlerTransferFunctionView::onSliderChange),NULL,handler);
99
100     bbtkDebugDecTab("Core",9);
101         bbSetOutputWidget( mwxwidget );                         
102 }
103
104 //-----------------------------------------------------
105
106 void TransferFunctionView::bbUserSetDefaultValues()
107 {
108         mwxwidget = NULL;
109         _currentimg = NULL;
110
111         _tfun = NULL;
112         _ctfun = NULL;   
113
114         bbSetOutputOpacityFunction(0);
115         bbSetOutputColorFunction(0);
116
117 }
118
119         
120         //-----------------------------------------------------------------     
121         void TransferFunctionView::bbUserInitializeProcessing()
122         {
123                 _tfun = vtkPiecewiseFunction::New();
124                 _ctfun = vtkColorTransferFunction::New();  
125                 _ctfun->SetClamping(-1);
126                 bbSetInputIn(NULL);
127         }
128         
129         //-----------------------------------------------------------------     
130         void TransferFunctionView::bbUserFinalizeProcessing()
131         {
132         }
133
134                 
135         //-----------------------------------------------------------------     
136         
137
138         HandlerTransferFunctionView::HandlerTransferFunctionView(TransferFunctionView* box){
139                 _box = box;             
140         }
141         HandlerTransferFunctionView::~HandlerTransferFunctionView(){
142
143         }       
144         void HandlerTransferFunctionView::onColorChange(wxCommandEvent& event){
145                 _box->onColorChange();
146         }
147         void HandlerTransferFunctionView::onSliderChange(wxCommandEvent& event){
148                 _box->onSliderChange();
149         }
150
151 }
152
153
154 // EO namespace bbcreaMaracasVisu
155
156