00001
00002 #include "vtkActor.h"
00003 #include "vtkCylinderSource.h"
00004 #include "vtkPolyDataMapper.h"
00005 #include "vtkRenderer.h"
00006 #include "vtkRenderWindow.h"
00007 #include "vtkRenderWindowInteractor.h"
00008 #include "vtkProperty.h"
00009 #include "vtkCamera.h"
00010 #include "vtkPoints.h"
00011 #include "vtkCellArray.h"
00012 #include "vtkPolyData.h"
00013 #include "vtkPolyDataMapper.h"
00014 #include "vtkPolyDataWriter.h"
00015 #include "vtkPolyDataReader.h"
00016 #include "vtkImageReader.h"
00017 #include "vtkImageViewer.h"
00018 #include "vtkImageViewer2.h"
00019 #include "vtkImageToStructuredPoints.h"
00020
00021
00022 #include "vtkExtractVOI.h"
00023 #include "vtkImageClip.h"
00024 #include "vtkImageResample.h"
00025 #include "vtkImageThreshold.h"
00026 #include "vtkImageCast.h"
00027 #include "vtkImageSeedConnectivity.h"
00028 #include "vtkImageData.h"
00029 #include "vtkMarchingCubes.h"
00030 #include "vtkImageReslice.h"
00031 #include "vtkTransform.h"
00032 #include "vtkSphereSource.h"
00033 #include "vtkDoubleArray.h"
00034 #include "vtkPointData.h"
00035 #include "vtkCommand.h"
00036 #include "vtkCallbackCommand.h"
00037 #include "vtkImageResample.h"
00038 #include "vtkMath.h"
00039 #include "vtkStripper.h"
00040
00041
00042 #include "wxEmptyPanelWidget.h"
00043
00044 #include <wx/splitter.h>
00045
00046
00047
00048
00049 wxEmptyPanelWidget::wxEmptyPanelWidget(wxWindow *parent)
00050 : wxPanel( parent, -1)
00051 {
00052 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL );
00053 wxSplitterWindow *pnlSplitter = new wxSplitterWindow( this , -1);
00054 wxPanel *viewPanel = CreateViewPanel(pnlSplitter);
00055 wxPanel *controlPanel = CreateControlPanel(pnlSplitter);
00056
00057 sizer -> Add( pnlSplitter ,1,wxGROW ,0);
00058 pnlSplitter -> SetMinimumPaneSize( 150 );
00059 pnlSplitter -> SplitVertically( viewPanel, controlPanel, 600 );
00060 this -> SetSizer(sizer);
00061
00062
00063 _mCubes = NULL;
00064 _surfMapper = NULL;
00065 _surfActor = NULL;
00066
00067
00068 _prgov = NULL;
00069 _mapfinal = NULL;
00070 _stripfinal = NULL;
00071 _isoMapperMC6 = NULL;
00072 _isoActorMC6 = NULL;
00073 _isoMC6 = NULL;
00074 }
00075
00076 wxEmptyPanelWidget::~wxEmptyPanelWidget(){
00077
00078
00079 _mCubes -> Delete();
00080 _surfMapper -> Delete();
00081 _surfActor -> Delete();
00082
00083
00084 _prgov -> Delete();
00085 _mapfinal -> Delete();
00086 _stripfinal -> Delete();
00087 _isoMapperMC6 -> Delete();
00088 _isoActorMC6 -> Delete();
00089 _isoMC6 -> Delete();
00090 }
00091
00092 wxPanel* wxEmptyPanelWidget::CreateViewPanel(wxWindow *parent)
00093 {
00094 wxPanel *panel = new wxPanel(parent,-1);
00095 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00096
00097 _imageviewer3D = new wxVtk3DBaseView(panel);
00098 wxVTKRenderWindowInteractor *iren = _imageviewer3D->GetWxVTKRenderWindowInteractor();
00099 sizer->Add(iren , 1, wxEXPAND, 0);
00100
00101 panel->SetSizer(sizer);
00102 panel->SetAutoLayout(true);
00103 panel->SetSize(400,400);
00104 panel->Layout();
00105 return panel;
00106 }
00107
00108 wxPanel* wxEmptyPanelWidget::CreateControlPanel(wxWindow *parent)
00109 {
00110 wxPanel *panel = new wxPanel(parent,-1);
00111 _opacity1 = new wxSlider( panel, -1, 50, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00112 _isoValue = new wxSlider( panel, -1, 0 , 0, 3000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00113 _opacity2 = new wxSlider( panel, -1, 50, 0, 100 , wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS );
00114 _opacity1->SetSize(250,20);
00115 _isoValue->SetSize(250,20);
00116 _opacity2->SetSize(250,20);
00117 wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
00118 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00119 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00120 sizer->Add(new wxStaticText(panel,-1,_T("Isovalue - Original Volume")));
00121 sizer->Add(_isoValue);
00122 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00123 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00124 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00125 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00126 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Original Volume")));
00127 sizer->Add(_opacity1);
00128 sizer->Add(new wxStaticText(panel,-1,_T(" ")));
00129 sizer->Add(new wxStaticText(panel,-1,_T("Opacity - Result Volume")));
00130 sizer->Add(_opacity2);
00131
00132 panel->SetSizer(sizer);
00133 panel->SetAutoLayout(true);
00134 panel->SetSize(400,400);
00135 panel->Layout();
00136 Connect(_opacity1->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget::OnOpacity1 );
00137 Connect(_isoValue->GetId() , wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &wxEmptyPanelWidget::OnIsoValue );
00138 Connect(_opacity2->GetId() , wxEVT_COMMAND_SLIDER_UPDATED , (wxObjectEventFunction) &wxEmptyPanelWidget::OnOpacity2 );
00139 return panel;
00140 }
00141
00142 void wxEmptyPanelWidget::Refresh()
00143 {
00144 _imageviewer3D->Refresh();
00145 }
00146
00147
00148 void wxEmptyPanelWidget::ConfigureVTK(vtkImageData *imagedata, int x, int y, int z)
00149 {
00150 wxBusyCursor wait;
00151 _imageviewer3D->Configure();
00152
00153 double puntoactualprov[3];
00154 puntoactualprov[0]=x;
00155 puntoactualprov[1]=y;
00156 puntoactualprov[2]=z;
00157
00158 double espprin[3];
00159 int extprin[6];
00160
00161 imagedata->GetSpacing(espprin);
00162 imagedata->GetExtent(extprin);
00163
00164 puntoactualprov[0]=puntoactualprov[0]*espprin[0];
00165 puntoactualprov[1]=puntoactualprov[1]*espprin[1];
00166 puntoactualprov[2]=puntoactualprov[2]*espprin[2];
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 _prgov= axisExtractor02::New();
00179 _prgov->SetParam(1);
00180 _prgov->SetParam2(1);
00181 _prgov->SetParam3(0.5);
00182 _prgov->SetMaxant(20);
00183 _prgov->SetMinant(5);
00184 _prgov->SetInput(imagedata);
00185 _prgov->SetPoint(puntoactualprov);
00186 _prgov->Update();
00187
00188
00189 vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
00190 writer->SetInput(_prgov->GetOutput());
00191 writer->SetFileName("c:/temp/salida_JF.vtk");
00192 writer->SetFileTypeToASCII();
00193 writer->Write();
00194
00195
00196
00197 _mapfinal = vtkPolyDataMapper::New();
00198 _mapfinal->SetInput(_prgov->GetOutput());
00199
00200 _stripfinal = vtkActor::New();
00201 _stripfinal->SetMapper(_mapfinal);
00202 _stripfinal->GetProperty()->SetColor(1, 1, 1);
00203 _stripfinal->GetProperty()->SetLineWidth(2);
00204
00205 _stripfinal->GetProperty()->BackfaceCullingOff();
00206
00207
00208 vtkImageData *imageOut = _prgov->GetVolumen();
00209 imageOut->Update();
00210
00211 _isoMC6 = vtkMarchingCubes::New();
00212 _isoMC6->SetInput(imageOut);
00213 _isoMC6->SetValue(0, 1);
00214 _isoMC6->Update();
00215
00216 _isoMapperMC6 = vtkPolyDataMapper::New();
00217 _isoMapperMC6->SetInput(_isoMC6->GetOutput());
00218 _isoMapperMC6->ScalarVisibilityOff();
00219 _isoMapperMC6->ImmediateModeRenderingOn();
00220
00221 _isoActorMC6 = vtkActor::New();
00222 _isoActorMC6->SetMapper(_isoMapperMC6);
00223 _isoActorMC6->GetProperty()->SetColor( 0, 1, 0);
00224 _isoActorMC6->GetProperty()->SetOpacity(0.25);
00225
00226
00227 double range[2];
00228 imagedata->GetScalarRange( range );
00229
00230 _mCubes = vtkMarchingCubes::New( );
00231 _mCubes->SetInput( imagedata );
00232 _mCubes->SetValue( 0, range[1] / 4 );
00233
00234 vtkStripper *stripper = vtkStripper::New();
00235 stripper->SetInput( _mCubes->GetOutput( ) );
00236
00237 _surfMapper = vtkPolyDataMapper::New( );
00238 _surfMapper->SetInput( stripper->GetOutput() );
00239 _surfMapper->ScalarVisibilityOff( );
00240 stripper->Delete();
00241
00242 _surfActor = vtkActor::New( );
00243 _surfActor->SetMapper( _surfMapper );
00244 _surfActor->PickableOff( );
00245 _surfActor->GetProperty( )->SetColor( 0.9803, 0.9215, 0.8392 );
00246 _surfActor->GetProperty( )->SetOpacity( 0.3 );
00247
00248
00249
00250 _isoValue->SetRange( (int)(range[0]), (int)(range[1]) );
00251 _isoValue->SetValue( (int)(range[1]/4) );
00252 _opacity1->SetValue( (int)(_surfActor->GetProperty( )->GetOpacity( )*100) );
00253 _opacity2->SetValue( (int)(_isoActorMC6->GetProperty( )->GetOpacity( )*100));
00254
00255
00256 vtkRenderer *ren = _imageviewer3D->GetRenderer();
00257 ren->AddActor(_surfActor);
00258 ren->AddActor(_isoActorMC6);
00259 ren->AddActor(_stripfinal);
00260
00261 }
00262
00263
00264
00265
00266 void wxEmptyPanelWidget::OnOpacity1(wxScrollEvent& event){
00267 double value = ((double)_opacity1->GetValue())/100;
00268 _surfActor->GetProperty( )->SetOpacity( value );
00269 Refresh();
00270 }
00271
00272 void wxEmptyPanelWidget::OnOpacity2(wxScrollEvent& event){
00273 double value = ((double)_opacity2->GetValue())/100;
00274 _isoActorMC6->GetProperty( )->SetOpacity( value );
00275 Refresh();
00276 }
00277
00278 void wxEmptyPanelWidget::OnIsoValue(wxScrollEvent& event){
00279 wxBusyCursor wait;
00280 _mCubes->SetValue(0, _isoValue->GetValue());
00281 Refresh();
00282 }