00001
00002 #include "vtkClipping3DDataViewer.h"
00003 #include "vtkDataSetReader.h"
00004 #include "vtkProperty.h"
00005
00006 vtkClipping3DDataViewer::vtkClipping3DDataViewer()
00007 {
00008 int i;
00009 for (i=0; i<VTKMPRDATA_MAXTISSUE; i++){
00010 _visibleTissue[i] = false;
00011 _representationType[i] = true;
00012 }
00013 _visibleVolume=false;
00014 }
00015
00016 vtkClipping3DDataViewer::~vtkClipping3DDataViewer()
00017 {
00018 int i;
00019 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
00020 _mCubes[i]->Delete();
00021 _tissueStripper[i]->Delete();
00022 _tissueMapper[i]->Delete();
00023 _tissuePlanes[i]->Delete();
00024 _tissueClipper[i]->Delete();
00025 }
00026 _outlineData->Delete();
00027 _mapOutline->Delete();
00028 _outline->Delete();
00029
00030 _tfun->Delete();
00031 _ctfun->Delete();
00032 _compositeFunction->Delete();
00033 _volumeMapper->Delete();
00034 _volumeProperty->Delete();
00035 _newvol->Delete();
00036 _volumePlanes->Delete();
00037
00038 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
00039 _tissue[i]-> Delete();
00040 _observerS[i]-> Delete();
00041 }
00042 _observerV-> Delete();
00043 }
00044
00045 vtkActor* vtkClipping3DDataViewer::GetOutlineActor()
00046 {
00047 return _outline;
00048 }
00049
00050 vtkClipPolyData* vtkClipping3DDataViewer::GetTissueClipper(int id)
00051 {
00052 return this->_tissueClipper[id];
00053 }
00054
00055 vtkPolyDataMapper* vtkClipping3DDataViewer::GetTissueMapper(int id)
00056 {
00057 return _tissueMapper[id];
00058 }
00059
00060 vtkPlanes* vtkClipping3DDataViewer::GetTissuePlanes(int id)
00061 {
00062 return _tissuePlanes[id];
00063 }
00064
00065 vtkStripper* vtkClipping3DDataViewer::GetTissueStripper(int id)
00066 {
00067 return _tissueStripper[id];
00068 }
00069
00070 void vtkClipping3DDataViewer::Refresh()
00071 {
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 }
00088
00089 void vtkClipping3DDataViewer::RefreshSurface()
00090 {
00091 int i;
00092 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
00093 {
00094 SetIsovalue(i, (int) (GetIsovalue(i)+1) );
00095
00096 }
00097 }
00098
00099 void vtkClipping3DDataViewer::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
00100 {
00101 _vtkmprbasedata=vtkmprbasedata;
00102 }
00103
00104 vtkMPRBaseData* vtkClipping3DDataViewer::GetVtkMPRBaseData()
00105 {
00106 return _vtkmprbasedata;
00107 }
00108
00109
00110
00111 void vtkClipping3DDataViewer::SetVisibleTissue(int idTissue, bool visible)
00112 {
00113 _visibleTissue[idTissue]=visible;
00114 }
00115
00116 bool vtkClipping3DDataViewer::GetVisibleTissue(int idTissue){
00117 return _visibleTissue[idTissue];
00118 }
00119
00120 void vtkClipping3DDataViewer::SetRepresentationType(int idTissue, bool representationType)
00121 {
00122 _representationType[idTissue]=representationType;
00123 }
00124
00125 bool vtkClipping3DDataViewer::GetRepresentationType(int idTissue)
00126 {
00127 return _representationType[idTissue];
00128 }
00129
00130
00131 vtkActor* vtkClipping3DDataViewer::GetTissueActor(int id){
00132 return _tissue[id];
00133 }
00134
00135
00136 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverS(int idObserverS)
00137 {
00138 return _observerS[idObserverS];
00139 }
00140
00141 boxSurfaceObserver *vtkClipping3DDataViewer::GetObserverV()
00142 {
00143 return _observerV;
00144 }
00145
00146
00147 bool vtkClipping3DDataViewer::GetVisibleVolume()
00148 {
00149 return _visibleVolume;
00150 }
00151
00152 void vtkClipping3DDataViewer::SetVisibleVolume(bool visiblevolume)
00153 {
00154 _visibleVolume = visiblevolume;
00155 }
00156
00157
00158
00159 void vtkClipping3DDataViewer::Configure_Tissue()
00160 {
00161
00162 double range[2];
00163 int i;
00164 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
00165
00166 vtkImageData *imagedata=_vtkmprbasedata->GetImageData();
00167 imagedata->GetScalarRange( range );
00168 _mCubes[i] = vtkMarchingCubes::New( );
00169 _mCubes[i]->SetInput( imagedata );
00170
00171 _mCubes[i]->SetValue( 0, range[1]*(4+i) / 8 );
00172
00173
00174 _tissueStripper[i] = vtkStripper::New();
00175 _tissueStripper[i]->SetInput( _mCubes[i]->GetOutput( ) );
00176
00177
00178
00179 _tissuePlanes[i] = vtkPlanes::New();
00180
00181 int x1,x2,y1,y2,z1,z2;
00182 imagedata->GetExtent(x1,x2,y1,y2,z1,z2);
00183 _tissuePlanes[i]->SetBounds (x1,x2,y1,y2,z1,z2);
00184
00185 _tissueClipper[i] = vtkClipPolyData::New();
00186 _tissueClipper[i]->SetInput( _tissueStripper[i]->GetOutput() );
00187 _tissueClipper[i]->SetClipFunction( _tissuePlanes[i] );
00188 _tissueClipper[i]->InsideOutOn( );
00189
00190 _tissueMapper[i] = vtkPolyDataMapper::New( );
00191 _tissueMapper[i]->SetInput( _tissueClipper[i]->GetOutput() );
00192 _tissueMapper[i]->ScalarVisibilityOff( );
00193
00194
00195 }
00196
00197
00198
00199
00200 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++){
00201
00202 _tissue[i] = vtkActor::New();
00203 _tissue[i]->SetMapper( GetTissueMapper(i) );
00204 float cr=1,cg=0.5,cb=0.5;
00205 _tissue[i]->GetProperty()->SetDiffuseColor(cr/255, cg/255 , cb/255 );
00206 _tissue[i]->GetProperty()->SetSpecular(.3);
00207 _tissue[i]->GetProperty()->SetSpecularPower(20);
00208 _tissue[i]->GetProperty()->SetOpacity(0.5);
00209 if (i==0) _tissue[i]->GetProperty()->SetColor(0.85, 0.85 , 0.85 );
00210 if (i==1) _tissue[i]->GetProperty()->SetColor(0, 0 , 1 );
00211 if (i==2) _tissue[i]->GetProperty()->SetColor(0.85, 0.20 , 0.20 );
00212 if (i==3) _tissue[i]->GetProperty()->SetColor(0, 1 , 0 );
00213 }
00214
00215 for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
00216 {
00217 _observerS[i] = boxSurfaceObserver::New();
00218 _observerS[i]->SetPlanes( GetTissuePlanes(i) );
00219 _observerS[i]->SetActor( _tissue[i] );
00220 }
00221
00222 }
00223
00224
00225
00226 void vtkClipping3DDataViewer::Configure_Volume()
00227 {
00228
00229
00230 _tfun = vtkPiecewiseFunction::New();
00231 _ctfun = vtkColorTransferFunction::New();
00232
00233 double range[2];
00234 this->_vtkmprbasedata->GetImageData()->GetScalarRange(range);
00235 double max = range[1];
00236
00237
00238
00239
00240
00241 greyValuesTransferenceFVector.push_back(max * 0/2);
00242 greyValuesTransferenceFVector.push_back(max * 1/2);
00243 greyValuesTransferenceFVector.push_back(max * 2/2);
00244
00245 intensityValuesTransferenceFVector.push_back(0.0);
00246 intensityValuesTransferenceFVector.push_back(1.0);
00247 intensityValuesTransferenceFVector.push_back(1.0);
00248
00249 _tfun->AddPoint(max * 0/2 , 0.0);
00250 _tfun->AddPoint(max * 1/2 , 1.0);
00251 _tfun->AddPoint(max * 2/2 , 1.0);
00252
00253
00254
00255
00256
00257 redColorsOfColorTransferenceFVector.push_back(0.0);
00258 redColorsOfColorTransferenceFVector.push_back(1.0);
00259 redColorsOfColorTransferenceFVector.push_back(0.0);
00260 redColorsOfColorTransferenceFVector.push_back(0.0);
00261 redColorsOfColorTransferenceFVector.push_back(0.0);
00262
00263
00264 greenColorsOfColorTransferenceFVector.push_back(0.0);
00265 greenColorsOfColorTransferenceFVector.push_back(0.0);
00266 greenColorsOfColorTransferenceFVector.push_back(0.0);
00267 greenColorsOfColorTransferenceFVector.push_back(1.0);
00268 greenColorsOfColorTransferenceFVector.push_back(0.2);
00269
00270
00271 blueColorsOfColorTransferenceFVector.push_back(0.0);
00272 blueColorsOfColorTransferenceFVector.push_back(0.0);
00273 blueColorsOfColorTransferenceFVector.push_back(1.0);
00274 blueColorsOfColorTransferenceFVector.push_back(0.0);
00275 blueColorsOfColorTransferenceFVector.push_back(0.0);
00276
00277 greyValueColorsOfColorTransferenceFVector.push_back(max*0/4);
00278 greyValueColorsOfColorTransferenceFVector.push_back(max*1/4);
00279 greyValueColorsOfColorTransferenceFVector.push_back(max*2/4);
00280 greyValueColorsOfColorTransferenceFVector.push_back(max*3/4);
00281 greyValueColorsOfColorTransferenceFVector.push_back(max*4/4);
00282
00283 _ctfun->AddRGBPoint( max*0/4 , 0.0, 0.0, 0.0);
00284 _ctfun->AddRGBPoint( max*1/4 , 1.0, 0.0, 0.0);
00285 _ctfun->AddRGBPoint( max*2/4 , 0.0, 0.0, 1.0);
00286 _ctfun->AddRGBPoint( max*3/4 , 0.0, 1.0, 0.0);
00287 _ctfun->AddRGBPoint( max*4/4 , 0.0, 0.2, 0.0);
00288
00289 _volumePlanes = vtkPlanes::New();
00290
00291
00292
00293
00294
00295 _compositeFunction = vtkVolumeRayCastCompositeFunction::New();
00296
00297 _volumeMapper = vtkVolumeRayCastMapper::New();
00298 _volumeMapper->SetInput( this->GetVtkMPRBaseData()->GetImageData() );
00299 _volumeMapper->SetVolumeRayCastFunction(_compositeFunction);
00300 _volumeMapper->SetClippingPlanes( _volumePlanes );
00301 _volumeMapper->AutoAdjustSampleDistancesOn();
00302
00303 _volumeProperty = vtkVolumeProperty::New();
00304 _volumeProperty->SetColor(_ctfun);
00305 _volumeProperty->SetScalarOpacity( _tfun );
00306
00307 _volumeProperty->SetInterpolationTypeToLinear();
00308 _volumeProperty->ShadeOn();
00309 _volumeProperty->DisableGradientOpacityOn();
00310
00311
00312
00313
00314
00315
00316
00317
00318 _newvol = vtkVolume::New();
00319 _newvol->SetMapper(_volumeMapper );
00320 _newvol->SetProperty(_volumeProperty );
00321
00322 _observerV = boxSurfaceObserver::New();
00323 _observerV->SetPlanes( _volumePlanes );
00324 _observerV->SetActor( _newvol );
00325 _observerV->SetvtkVolumeRayCastMapper( _volumeMapper );
00326 }
00327
00328
00329
00330 void vtkClipping3DDataViewer::Configure()
00331 {
00332 Configure_Tissue();
00333 Configure_Volume();
00334
00335
00336
00337 _outlineData = vtkOutlineFilter::New();
00338 _outlineData->SetInput((vtkDataSet *) _vtkmprbasedata->GetImageData() );
00339 _mapOutline = vtkPolyDataMapper::New();
00340 _mapOutline->SetInput(_outlineData->GetOutput());
00341 _outline = vtkActor::New();
00342 _outline->SetMapper(_mapOutline);
00343 _outline->GetProperty()->SetColor(0,0,0);
00344 }
00345
00346
00347
00348 void vtkClipping3DDataViewer::SetIsovalue(int idTissue, int isoValue)
00349 {
00350 _mCubes[idTissue]->SetValue(0, isoValue);
00351 }
00352
00353 double vtkClipping3DDataViewer::GetIsovalue(int idTissue)
00354 {
00355 return _mCubes[idTissue]->GetValue(0);
00356 }
00357
00358 vtkVolume* vtkClipping3DDataViewer::GetVolumeActor()
00359 {
00360 return _newvol;
00361 }
00362
00363 vtkVolumeRayCastMapper* vtkClipping3DDataViewer::GetVolumeMapper(){
00364 return _volumeMapper;
00365 }
00366
00367 vtkPlanes* vtkClipping3DDataViewer::GetVolumePlanes()
00368 {
00369 return _volumePlanes;
00370 }
00371
00372
00373 vtkMarchingCubes *vtkClipping3DDataViewer::GetMCubes(int idTissue)
00374 {
00375 return _mCubes[idTissue];
00376 }
00377
00378
00379
00380
00381
00382 std::vector<double>* vtkClipping3DDataViewer::GetGreyValuesTransferenceFVector()
00383 {
00384 return &greyValuesTransferenceFVector;
00385 }
00386
00387 std::vector<double>* vtkClipping3DDataViewer::GetIntensityValuesTransferenceFVector()
00388 {
00389 return &intensityValuesTransferenceFVector;
00390 }
00391
00392 std::vector<double>* vtkClipping3DDataViewer::GetRedColorsOfColorTransferenceFVector()
00393 {
00394 return &redColorsOfColorTransferenceFVector;
00395 }
00396
00397 std::vector<double>* vtkClipping3DDataViewer::GetGreenColorsOfColorTransferenceFVector()
00398 {
00399 return &greenColorsOfColorTransferenceFVector;
00400 }
00401
00402 std::vector<double>* vtkClipping3DDataViewer::GetBlueColorsOfColorTransferenceFVector()
00403 {
00404 return &blueColorsOfColorTransferenceFVector;
00405 }
00406
00407 std::vector<double>* vtkClipping3DDataViewer::GetGreyValueColorsOfColorTransferenceFVector()
00408 {
00409 return &greyValueColorsOfColorTransferenceFVector;
00410 }
00411
00412
00413
00414
00415
00416 vtkPiecewiseFunction* vtkClipping3DDataViewer::GetTransferencefunction()
00417 {
00418 return this->_tfun;
00419 }
00420
00421 vtkColorTransferFunction* vtkClipping3DDataViewer::GetColorTransferenceFunction()
00422 {
00423 return this->_ctfun;
00424 }
00425
00426
00427
00428 void vtkClipping3DDataViewer::ReadVolumeFunctions()
00429 {
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 }
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 void vtkClipping3DDataViewer::ReadMeshVTK(char *namefile)
00618 {
00619 vtkDataSetReader *reader = vtkDataSetReader::New();
00620 reader->SetFileName(namefile);
00621 reader->Update();
00622 _tissueStripper[3]->SetInput( reader->GetPolyDataOutput() );
00623 }
00624
00625 void vtkClipping3DDataViewer::setColorTransferFunction(vtkColorTransferFunction* colortable){
00626
00627 _volumeProperty->SetColor(colortable);
00628
00629 }