00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <vtkPlaneSource.h>
00018 #include <vtkKochanekSpline.h>
00019 #include <vtkPolyDataConnectivityFilter.h>
00020 #include <vtkContourFilter.h>
00021 #include <vtkProbeFilter.h>
00022
00023
00024 #include <vtkImageChangeInformation.h>
00025 #include <vtkImageShiftScale.h>
00026 #include <vtkDoubleArray.h>
00027
00028
00029 #include "marAxis.h"
00030 #include "marVector.h"
00031
00032 #include "ExtractionAxe.h"
00033 #include "FonctionsGrales.h"
00034
00035 #include <vtkCellArray.h>
00036 #include <vtkCell.h>
00037 #include <vtkCleanPolyData.h>
00038 #include <vtkIdList.h>
00039 #include <vtkMath.h>
00040 #include <vtkMatrix4x4.h>
00041 #include <vtkPointData.h>
00042 #include <vtkPolyData.h>
00043 #include <vtkPlane.h>
00044 #include <vtkSetGet.h>
00045 #include <vtkStripper.h>
00046 #include <vtkStructuredPoints.h>
00047 #include <vtkTransform.h>
00048
00049
00050 marAxis::marAxis( marParameters* p ) :
00051 marObject( p ),
00052 kCurve( 3, INDX_count - 3 ),
00053 _healthySlice( -1 ), _startQuant( -1 ),
00054 _finishQuant( -1 ), _actualQuant( -1 )
00055
00056 {
00057 _totalAxisLenght=-1;
00058 _subAxisLenght=-1;
00059 _referenceArea=-1;
00060 _referenceAverDiam=-1;
00061
00062
00063 _allData = NULL;
00064
00065 _healthySliceStart=-1;
00066 _healthySliceEnd=-1;
00067 reset( );
00068 calibration = false;
00069 }
00070
00071
00072 void marAxis::addAxisPoint( double* p )
00073 {
00074 double pt[ INDX_count ];
00075
00076 memcpy( pt, p, sizeof( POINTAXE ) );
00077 pt[ INDX_SIGNALVALUE ] = 0;
00078 addControlPoint( pt, pt + 3 );
00079 }
00080
00081
00082
00083 double* marAxis::getNormal( unsigned int slice ) {
00084
00085 double* ret = new double[ 3 ];
00086
00087 if ( slice == 0 ) {
00088 ret[0] = _points[ slice + 1 ][0] - _points[ slice ][0];
00089 ret[1] = _points[ slice + 1 ][1] - _points[ slice ][1];
00090 ret[2] = _points[ slice + 1 ][2] - _points[ slice ][2];
00091 }
00092 else if ( slice == _points.size( ) - 1 ) {
00093 ret[0] = _points[ slice - 1 ][0] - _points[ slice ][0];
00094 ret[1] = _points[ slice - 1 ][1] - _points[ slice ][1];
00095 ret[2] = _points[ slice - 1 ][2] - _points[ slice ][2];
00096 }
00097 else if ( slice > 0 && slice < _points.size( ) - 1 ) {
00098 ret[0] = _points[ slice - 1 ][0] - _points[ slice + 1 ][0];
00099 ret[1] = _points[ slice - 1 ][1] - _points[ slice + 1 ][1];
00100 ret[2] = _points[ slice - 1 ][2] - _points[ slice + 1 ][2];
00101 }
00102
00103 return( ret );
00104 }
00105
00106
00107 void marAxis::changeAxisResolution( )
00108 {
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 }
00128
00129
00130 void marAxis::calculateSignal( kVolume* vol )
00131 {
00135
00136
00137
00138
00139
00140 ushort maxlocal;
00141 double *p;
00142
00143 double rayon;
00144 unsigned int i, mask_size = getParameters( )-> getIntParam( marParameters::e_mask_size );
00145
00146 while( _signal.size( ) > 0 ) _signal.pop_back( );
00147
00148
00149 PSIGNAL_USHORT signal = ( PSIGNAL_USHORT ) IdSigAlloc( _points.size( ), SIG_USHORT );
00150 for( i = 0; i < _points.size( ); i++ ) {
00151 p = _points[i];
00152 rayon = RayonLocal(
00153 ( int ) ( p[ 0 ] ),
00154 ( int ) ( p[ 1 ] ),
00155 ( int ) ( p[ 2 ] ),
00156 _points_disc, getNumberOfControlPoints( ));
00157
00158 maxlocal = vol->GetMaxIntSphere2( p, rayon );
00159 PutSignalValue( signal, i, maxlocal );
00160 }
00161
00162 PSIGNAL_FLOAT mask_signal = ( PSIGNAL_FLOAT )IdSigAlloc( mask_size, SIG_FLOAT );
00163
00164 for( i = 0; i < mask_size; i++ )
00165 PutSignalValueFloat( mask_signal, i, 1 );
00166
00167 PSIGNAL_USHORT signalfilt = ( PSIGNAL_USHORT )IdSigAlloc( _points.size( ), SIG_USHORT );
00168 signalfilt = MonSigConvolve( signal, mask_signal, signalfilt, 1.0 / ( double )mask_size, 0 );
00169 for( i = 0; i < _points.size( ); i++ ){
00170 _signal.push_back( GetSignalValue( signalfilt, i ) );
00171 }
00172 IdSigFree( signal );
00173 IdSigFree( mask_signal );
00174 IdSigFree( signalfilt );
00175 }
00176
00177
00178 void marAxis::start( )
00179 {
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 }
00192
00193
00194 void marAxis::cut( int slice, bool up )
00195 {
00196 }
00197
00198
00199
00200 void marAxis::doSpline( )
00201 {
00202 unsigned int i;
00203 unsigned int nop, nip;
00204 float length=0, t;
00205 float p1[ 3 ], p2[ 3 ];
00206 double p[marAxis::INDX_count];
00207
00208 vtkKochanekSpline* spX = vtkKochanekSpline::New( );
00209 vtkKochanekSpline* spY = vtkKochanekSpline::New( );
00210 vtkKochanekSpline* spZ = vtkKochanekSpline::New( );
00211
00212 for( i = 0, length = 0.0; i < _controlPoints.size( ); i++ ) {
00213 getControlPoint(i, p, p+3);
00214 p2[ 0 ] = (float) p[marAxis::INDX_X];
00215 p2[ 1 ] = (float) p[marAxis::INDX_Y];
00216 p2[ 2 ] = (float) p[marAxis::INDX_Z];
00217 spX->AddPoint( (float) i, p2[ 0 ] );
00218 spY->AddPoint( (float) i, p2[ 1 ] );
00219 spZ->AddPoint( (float) i, p2[ 2 ] );
00220 if( i > 0 )
00221 length += (float) (sqrt( (p2[0]-p1[0])*(p2[0]-p1[0]) +
00222 (p2[1]-p1[1])*(p2[1]-p1[1]) +
00223 (p2[2]-p1[2])*(p2[2]-p1[2]) ) );
00224 p1[ 0 ] = p2[ 0 ]; p1[ 1 ] = p2[ 1 ]; p1[ 2 ] = p2[ 2 ];
00225 }
00226
00227 nop = ( unsigned int ) ( getParameters( )->getDoubleParam(
00228 marParameters::e_axis_discret_step ) * length );
00229 nip = _controlPoints.size( );
00230 _healthySlice = -1;
00231
00232 while( _points.size( ) > 0 ) {
00233 delete _points[ _points.size( ) - 1 ];
00234 _points.pop_back( );
00235 }
00236
00237 while( _contours.size( ) > 0 ) {
00238 delete _contours[ _contours.size( ) - 1 ];
00239 _contours.pop_back( );
00240 }
00241
00242 for( i = 0; i < nop; i++ ) {
00243 t = (float) (( ( double ) nip - 1.0 ) / ( ( double ) nop - 1.0 ) * i);
00244 double* np = new double[ 3 ];
00245 np[ 0 ] = 0;
00246 np[ 1 ] = 0;
00247 np[ 2 ] = 0;
00248 np[ 0 ] = (double) (spX->Evaluate( t ));
00249 np[ 1 ] = (double) (spY->Evaluate( t ));
00250 np[ 2 ] = (double) (spZ->Evaluate( t ));
00251 _points.push_back( np );
00252 _contours.push_back( new marContour( i, getParameters( ) ) );
00253
00254 }
00255
00256 spX->Delete( );
00257 spY->Delete( );
00258 spZ->Delete( );
00259
00260 }
00261
00262
00263
00264
00265 void marAxis::sliceVolumeAxis( kVolume* vol, bool forceCnt )
00266 {
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 }
00334
00335
00336
00337
00338 int marAxis::getNumberOfContours( )
00339 {
00340 return( _contours.size( ) );
00341 }
00342
00343
00344 int marAxis::getNumberOfSplinePoints( )
00345 {
00346 return( _points.size( ) );
00347 }
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
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 void marAxis::createContour(int i, kVolume* vol)
00573 {
00574
00575 int j,id;
00576 int numberOfPoints,numberOfCells;
00577 vtkCell* cell;
00578 vtkIdList* pids;
00579 double p[ 3 ];
00580 vtkPolyData* vtkPolyData_2DContour;
00581 double x,y;
00582
00583 int sizeIma = getParameters( )->getSizeIma( );
00584 double dimIma = getParameters( )->getDimIma( );
00585
00586
00587 dimIma=sizeIma/3;
00588
00589 _contours[i] = new marContour( i, getParameters( ) ) ;
00590 vtkPolyData_2DContour = get2Dcontour(i,vol);
00591
00592 numberOfCells = vtkPolyData_2DContour->GetNumberOfCells( );
00593 cell = vtkPolyData_2DContour->GetCell( 0 );
00594 pids = cell->GetPointIds( );
00595 numberOfPoints = pids->GetNumberOfIds( );
00596
00597 for( j = 0; j < numberOfPoints; j++ )
00598 {
00599 id = pids->GetId( j );
00600 vtkPolyData_2DContour->GetPoint( id, p);
00601 x=p[0]-64.0;
00602 y=p[1]-64.0;
00603 x=x * dimIma / ( float ) sizeIma;
00604 y=y * dimIma / ( float ) sizeIma;
00605 _contours[ i ]->addContourPoint( x , y );
00606 }
00607
00608 _contours[i]->do_spline();
00609 _contours[i]->calculateVariables();
00610
00611 }
00612
00613
00614 void marAxis::EraseContour(int i){
00615 if (_3Dcontour[i]!=NULL){
00616 _3Dcontour[i]->Delete();
00617 _3Dcontour[i]=NULL;
00618 }
00619
00620 if (_2DDiameterMax[i]!=NULL){
00621 _2DDiameterMax[i]->Delete();
00622 _2DDiameterMax[i]=NULL;
00623 }
00624
00625 if (_2DDiameterMin[i]!=NULL){
00626 _2DDiameterMin[i]->Delete();
00627 _2DDiameterMin[i]=NULL;
00628 }
00629
00630 if (_2Dcontours[i]!=NULL){
00631 _2Dcontours[i]->Delete();
00632 _2Dcontours[i]=NULL;
00633 }
00634
00635 if (_contours[i]!=NULL){
00636 delete _contours[i];
00637 _contours[i]=NULL;
00638 }
00639 }
00640
00641
00642 void marAxis::replaceContour2D(int i,int size,double *vx,double *vy){
00643
00644 EraseContour(i);
00645
00646
00647 vtkPoints *_pts = vtkPoints::New();
00648 _pts->SetNumberOfPoints(size);
00649 int j;
00650
00651 for (j=0 ; j<size ; j++){
00652 _pts->SetPoint(j, vx[j] , vy[j] , 0 );
00653 }
00654
00655
00656 vtkCellArray *lines = vtkCellArray::New();
00657 lines->InsertNextCell( size );
00658 for ( j=0 ; j<size+1 ; j++ ){
00659 lines->InsertCellPoint(j % size );
00660 }
00661
00662 vtkPolyData *_pd = vtkPolyData::New();
00663 _pd->SetPoints( _pts );
00664 _pd->SetLines( lines );
00665 lines->Delete();
00666 _pts->Delete();
00667
00668 _2Dcontours[i]=_pd;
00669 createContour(i,NULL);
00670 }
00671
00672 void marAxis::createSlice(int i , kVolume* vol){
00673 int k=i;
00674 int sizeIma = getParameters( )->getSizeIma( );
00675
00676 vtkStructuredPoints* stPoints = vtkStructuredPoints::New( );
00677 double *p, *n;
00678 p = _points[k];
00679 n = getNormal( k );
00680
00681 stPoints->GetPointData( )->SetScalars( get3DSlice(k,vol)->GetOutput()->GetPointData()->GetScalars() );
00682 stPoints->SetDimensions( sizeIma, sizeIma, 1 );
00683
00684
00685 stPoints->SetScalarType( vol->castVtk( )->GetDataObjectType( ) );
00686 stPoints->SetScalarTypeToShort ();
00687 stPoints->Update();
00688
00689 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
00690 change->SetInput( stPoints );
00691 change->Update();
00692
00693
00694 if (_slices[k]!=NULL) { delete _slices[k]; }
00695 _slices[k] = new kVolume( change->GetOutput() ) ;
00696
00697 stPoints->Delete( );
00698 change->Delete();
00699 }
00700
00701 void marAxis::create3DSlice(int i , kVolume* vol )
00702 {
00703
00704 int k=i;
00705 int sizeIma = getParameters( )->getSizeIma( );
00706 double dimIma = getParameters( )->getDimIma( );
00707
00708 dimIma=sizeIma/3;
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732 double *p, *n;
00733
00734
00735 p = _points[k];
00736 n = getNormal( k );
00737
00738 vtkPlaneSource* pSource = vtkPlaneSource::New( );
00739 pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
00740 pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
00741 pSource->SetPoint2( p[ 0 ], p[ 1 ], p[ 2 ] + dimIma - 1.0 );
00742 pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
00743 pSource->Update( );
00744 pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
00745 pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
00746 pSource->Update( );
00747
00748 if (_3Dslices[ k ]!=NULL){ _3Dslices[ k ]->Delete(); }
00749 _3Dslices[ k ] = vtkProbeFilter::New( ) ;
00750 _3Dslices[ k ]->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
00751 _3Dslices[ k ]->SetSource( vol->castVtk( ) );
00752 _3Dslices[ k ]->Update( );
00753 pSource->Delete( );
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773
00774
00775
00776 }
00777
00778
00779
00780
00781
00782 void marAxis::create3Dcontour(int i, kVolume* vol)
00783 {
00784 vtkPoints *_vtkPoints;
00785 double *o;
00786 double *n;
00787 vtkMatrix4x4* mat;
00788 vtkTransform* trans;
00789 double nn[3];
00790 double c[3],p1[3],p2[3];
00791 double nA,nB,nC;
00792
00793 _vtkPoints = vtkPoints::New();
00794 o = _points[i];
00795 n = getNormal( i );
00796 mat = vtkMatrix4x4::New();
00797 trans = vtkTransform::New();
00798
00799
00800 nn[0]=n[0]; nn[1]=n[1]; nn[2]=n[2];
00801 nC=sqrt( nn[0]*nn[0] + nn[1]*nn[1] + nn[2]*nn[2] );
00802 nn[0]=nn[0]/nC; nn[1]=nn[1]/nC; nn[2]=nn[2]/nC;
00803
00804 vtkPlaneSource* pSource = vtkPlaneSource::New( );
00805 pSource->SetOrigin( 0, 0 , 0 );
00806 pSource->SetPoint1( 1, 0 , 0 );
00807 pSource->SetPoint2( 0, 0 , 1.0 );
00808 pSource->SetCenter( 0,0,0 );
00809 pSource->SetNormal( nn[ 0 ], nn[ 1 ], nn[ 2 ] );
00810 pSource->Update( );
00811
00812 pSource->GetOrigin(c);
00813 pSource->GetPoint1(p1);
00814 pSource->GetPoint2(p2);
00815 pSource->Delete();
00816 p1[0]=p1[0]-c[0]; p1[1]=p1[1]-c[1]; p1[2]=p1[2]-c[2];
00817 p2[0]=p2[0]-c[0]; p2[1]=p2[1]-c[1]; p2[2]=p2[2]-c[2];
00818 nA=sqrt( p1[0]*p1[0] + p1[1]*p1[1] + p1[2]*p1[2] );
00819 nB=sqrt( p2[0]*p2[0] + p2[1]*p2[1] + p2[2]*p2[2] );
00820 p1[0]=p1[0]/nA; p1[1]=p1[1]/nA; p1[2]=p1[2]/nA;
00821 p2[0]=p2[0]/nB; p2[1]=p2[1]/nB; p2[2]=p2[2]/nB;
00822
00823 mat->SetElement (0,0, nn[0]);
00824 mat->SetElement (1,0, nn[1]);
00825 mat->SetElement (2,0, nn[2]);
00826 mat->SetElement (3,0, 0);
00827 mat->SetElement (0,1, p2[0]);
00828 mat->SetElement (1,1, p2[1]);
00829 mat->SetElement (2,1, p2[2]);
00830 mat->SetElement (3,1, 0);
00831 mat->SetElement (0,2, p1[0]);
00832 mat->SetElement (1,2, p1[1]);
00833 mat->SetElement (2,2, p1[2]);
00834 mat->SetElement (3,2, 0);
00835 mat->SetElement (0,3, 0);
00836 mat->SetElement (1,3, 0);
00837 mat->SetElement (2,3, 0);
00838 mat->SetElement (3,3, 1);
00839
00840
00841 trans->Identity();
00842 trans->SetMatrix(mat);
00843 float ang;
00844 ang=-90;
00845 trans->RotateWXYZ ( ang,0,1,0);
00846
00847
00848
00849
00850
00851 trans->Update();
00852
00853 vtkMatrix4x4 *m=vtkMatrix4x4::New();
00854 trans->GetMatrix ( m );
00855
00856
00857 int j,numberOfPoints;
00858 marContour* contour2D = getContour(i,vol);
00859 numberOfPoints = contour2D->getNumberOfPoints( );
00860 double fpA[3];
00861 double pA[3],ppp[3];
00862
00863
00864 for( j = 0; j <= numberOfPoints; j++ ) {
00865 contour2D->getPoint( fpA,j % numberOfPoints);
00866
00867 pA[0] = fpA[0] + 0.2;
00868 pA[1] = fpA[1] + 0.2;
00869
00870 pA[2] = 0;
00871
00872
00873
00874
00875
00876
00877 ppp[0] = m->GetElement(0,0)*pA[0] + m->GetElement(0,1)*pA[1] + m->GetElement(0,2)*pA[2] + m->GetElement(0,3);
00878 ppp[1] = m->GetElement(1,0)*pA[0] + m->GetElement(1,1)*pA[1] + m->GetElement(1,2)*pA[2] + m->GetElement(1,3);
00879 ppp[2] = m->GetElement(2,0)*pA[0] + m->GetElement(2,1)*pA[1] + m->GetElement(2,2)*pA[2] + m->GetElement(2,3);
00880
00881
00882 ppp[0]=ppp[0]+o[0]; ppp[1]=ppp[1]+o[1]; ppp[2]=ppp[2]+o[2];
00883
00884 _vtkPoints->InsertNextPoint( (float)ppp[0],(float)ppp[1],(float)ppp[2] );
00885 }
00886
00887 m->Delete();
00888 mat->Delete();
00889 trans->Delete();
00890 if (_3Dcontour[i]!=NULL){ _3Dcontour[i]->Delete(); }
00891 _3Dcontour[i]=_vtkPoints;
00892
00893 }
00894
00895 void marAxis::createSliceImage(int i , kVolume* vol )
00896 {
00897 _quantificationImages[i] = getSlice(i,vol)->castVtk( ) ;
00898
00899 }
00900
00901 void marAxis::create2Dcontour(int i , kVolume* vol )
00902 {
00903 vtkImageData* imagedata;
00904
00905 double thr = getParameters( )->getDoubleParam( marParameters::e_threshold_isocontour );
00906 int sizeIma = getParameters( )->getSizeIma( );
00907 double localint = getSignal( i );
00908 double sigma = getParameters( )->getDoubleParam( marParameters::e_sigma );
00909 double threshold = localint * thr / 100.0;
00910
00911 int dimIma = ( int ) ( ( double ) sizeIma /getParameters( )->getDoubleParam( marParameters::e_scale ) );
00912 int vmin = ( int )threshold;
00913 int vmax = ( int )threshold;
00914
00915 int x = -1;
00916 int y = -1;
00917
00918 x = ( x != -1 )? x: sizeIma / 2;
00919 y = ( y != -1 )? y: sizeIma / 2;
00920
00921
00922 imagedata = (vtkImageData*) ((getSlice( i , vol ))->castVtk( ));
00923 double *range = imagedata->GetScalarRange();
00924
00925
00926 vtkContourFilter* cntVTK = vtkContourFilter::New( );
00927 cntVTK->SetInput( imagedata );
00928 cntVTK->SetNumberOfContours( 1 );
00929
00930 cntVTK->SetValue( 0, (range[1]*thr/100) );
00931
00932 cntVTK->Update( );
00933
00934 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
00935 cpd->SetInput( cntVTK->GetOutput( ) );
00936 cpd->ConvertLinesToPointsOff( );
00937 cpd->Update( );
00938
00939 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
00940
00941
00942
00943 conn->SetInput( cpd->GetOutput( ) );
00944
00945 conn->SetClosestPoint( x, y, 0 );
00946 conn->SetExtractionModeToClosestPointRegion( );
00947 conn->Update( );
00948
00949 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
00950 cpd2->SetInput( conn->GetOutput( ) );
00951 cpd2->Update();
00952
00953 vtkStripper* vtkstripper = vtkStripper::New( );
00954 vtkstripper->SetInput( cpd2->GetOutput() );
00955 vtkstripper->Update();
00956
00957 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
00958 polyDataResult->Update( );
00959
00960 cntVTK -> Delete();
00961 cpd2 -> Delete();
00962 cpd -> Delete();
00963 conn -> Delete();
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984 if ( _2Dcontours[i]!=NULL ) { _2Dcontours[i]->Delete(); }
00985 _2Dcontours[i]=polyDataResult;
00986 }
00987
00988 void marAxis::create2DDiameterMin( int i , kVolume* vol ){
00989 double p1[2],p2[2];
00990 marContour *marcontour=getContour(i,vol);
00991 marcontour->getMinimumLine(p1,p2);
00992 vtkPoints *_vtkPoints = vtkPoints::New();
00993 int sizeIma = getParameters( )->getSizeIma( );
00994
00995 double dimIma = getParameters( )->getDimIma( );
00996
00997
00998 dimIma=sizeIma/3;
00999
01000 double factor=( float ) sizeIma / dimIma;
01001 p1[0]=p1[0]*factor+sizeIma/2;
01002 p1[1]=p1[1]*factor+sizeIma/2;
01003 p2[0]=p2[0]*factor+sizeIma/2;
01004 p2[1]=p2[1]*factor+sizeIma/2;
01005 _vtkPoints->InsertNextPoint( p1[0] , p1[1] , 1 );
01006 _vtkPoints->InsertNextPoint( p2[0] , p2[1] , 1 );
01007 if ( _2DDiameterMin[i]!=NULL ) { _2DDiameterMin[i]->Delete(); }
01008 _2DDiameterMin[i] = _vtkPoints;
01009 }
01010
01011 void marAxis::create2DDiameterMax( int i , kVolume* vol ){
01012 double p1[2],p2[2];
01013 marContour *marcontour=getContour(i,vol);
01014 marcontour->getMaximumLine(p1,p2);
01015 vtkPoints *_vtkPoints = vtkPoints::New();
01016 int sizeIma = getParameters( )->getSizeIma( );
01017
01018 double dimIma = getParameters( )->getDimIma( );
01019
01020 dimIma=sizeIma/3;
01021
01022 double factor=( float ) sizeIma / dimIma;
01023 p1[0]=p1[0]*factor+sizeIma/2;
01024 p1[1]=p1[1]*factor+sizeIma/2;
01025 p2[0]=p2[0]*factor+sizeIma/2;
01026 p2[1]=p2[1]*factor+sizeIma/2;
01027 _vtkPoints->InsertNextPoint( p1[0] , p1[1] , 1 );
01028 _vtkPoints->InsertNextPoint( p2[0] , p2[1] , 1 );
01029 if ( _2DDiameterMax[i]!=NULL ) { _2DDiameterMax[i]->Delete(); }
01030 _2DDiameterMax[i] = _vtkPoints;
01031 }
01032
01033 void marAxis::createEmptyVectors()
01034 {
01035 int nCnts = ( int ) getNumberOfSplinePoints( );
01036 clearAllVectors();
01037 int i;
01038
01039 for (i=0;i<nCnts;i++){
01040 _contours.push_back( NULL );
01041 _slices.push_back( NULL );
01042 _3Dslices.push_back( NULL );
01043 _3Dcontour.push_back( NULL );
01044 _quantificationImages.push_back( NULL );
01045 _2Dcontours.push_back( NULL );
01046 _2DDiameterMin.push_back( NULL );
01047 _2DDiameterMax.push_back( NULL );
01048 }
01049 }
01050
01051 void marAxis::clearAllVectors()
01052 {
01053 unsigned int i;
01054
01055 for (i=0;i<_contours.size();i++){
01056 if (_contours[i]!=NULL) {
01057 delete _contours[i];
01058 _contours[i]=NULL;
01059 }
01060 }
01061 _contours.clear();
01062
01063 for (i=0;i<_slices.size();i++){
01064 if (_slices[i]!=NULL) {
01065 delete _slices[i];
01066 _slices[i]=NULL;
01067 }
01068 }
01069 _slices.clear();
01070
01071
01072 for (i=0;i<_3Dslices.size();i++){
01073 if (_3Dslices[i]!=NULL) {
01074 _3Dslices[i]->Delete();
01075 _3Dslices[i]=NULL;
01076 }
01077 }
01078 _3Dslices.clear();
01079
01080 for (i=0;i<_3Dcontour.size();i++){
01081 if (_3Dcontour[i]!=NULL) {
01082 _3Dcontour[i]->Delete();
01083 _3Dcontour[i]=NULL;
01084 }
01085 }
01086 _3Dcontour.clear();
01087
01088 for (i=0;i<_quantificationImages.size();i++){
01089 if (_quantificationImages[i]!=NULL) {
01090
01091
01092 }
01093 }
01094 _quantificationImages.clear();
01095
01096 for (i=0;i<_2Dcontours.size();i++){
01097 if (_2Dcontours[i]!=NULL) {
01098
01099
01100 _2Dcontours[i]=NULL;
01101 }
01102 }
01103 _2Dcontours.clear();
01104
01105 for (i=0;i<_2DDiameterMin.size();i++){
01106 if (_2DDiameterMin[i]!=NULL) {
01107 _2DDiameterMin[i]->Delete() ;
01108 _2DDiameterMin[i]=NULL;
01109 }
01110 }
01111 _2DDiameterMin.clear();
01112
01113 for (i=0;i<_2DDiameterMax.size();i++){
01114 if (_2DDiameterMax[i]!=NULL) {
01115 _2DDiameterMax[i]->Delete();
01116 _2DDiameterMax[i]=NULL;
01117 }
01118 }
01119 _2DDiameterMax.clear();
01120
01121 }
01122
01123 void marAxis::eraseContourVectorsContent()
01124 {
01125 unsigned int i;
01126 for (i=0;i<_contours.size();i++){
01127 if (_contours[i]!=NULL) {
01128 delete _contours[i];
01129 _contours[i]=NULL;
01130 }
01131 }
01132 for (i=0;i<_2Dcontours.size();i++){
01133 if (_2Dcontours[i]!=NULL) {
01134 _2Dcontours[i]->Delete();
01135 _2Dcontours[i]=NULL;
01136 }
01137 }
01138 for (i=0;i<_2DDiameterMin.size();i++){
01139 if (_2DDiameterMin[i]!=NULL) {
01140 _2DDiameterMin[i]->Delete();
01141 _2DDiameterMin[i]=NULL;
01142 }
01143 }
01144 for (i=0;i<_2DDiameterMax.size();i++){
01145 if (_2DDiameterMax[i]!=NULL) {
01146 _2DDiameterMax[i]->Delete();
01147 _2DDiameterMax[i]=NULL;
01148 }
01149 }
01150 for (i=0;i<_3Dcontour.size();i++){
01151 if (_3Dcontour[i]!=NULL) {
01152 _3Dcontour[i]->Delete();
01153 _3Dcontour[i]=NULL;
01154 }
01155 }
01156 }
01157
01158
01159 marContour* marAxis::getContour(int i, kVolume* vol)
01160 {
01161 if (_contours[i]==NULL){ createContour(i, vol); }
01162 return _contours[i];
01163 }
01164
01165 kVolume* marAxis::getSlice(int i, kVolume* vol)
01166 {
01167 if (_slices[i]==NULL){ createSlice( i , vol ); }
01168 return _slices[i];
01169 }
01170
01171
01172 bool marAxis::if3DcontourExist(int i)
01173 {
01174 bool result=true;
01175 if (_3Dcontour[i]==NULL)
01176 {
01177 result=false;
01178 }
01179 return result;
01180 }
01181
01182
01183 void marAxis::Save3Dcontour(FILE *ff,int id)
01184 {
01185 int i,size;
01186 double point[3];
01187 if (_3Dcontour[id]!=NULL)
01188 {
01189
01190 size = _3Dcontour[id]->GetNumberOfPoints();
01191
01192 for ( i=0 ; i<size ;i++ ){
01193 _3Dcontour[id]->GetPoint( i , point );
01194 fprintf(ff,"%f %f %f %d\n", point[0], point[1],point[2],id);
01195 }
01196 }
01197 }
01198
01199 void marAxis::SaveExisting3DContours(FILE *ff)
01200 {
01201 if (ff!=NULL)
01202 {
01203
01204 int acum=0;
01205 int i,size=_3Dcontour.size();
01206 for (i=0; i<size; i++)
01207 {
01208 if (_3Dcontour[i]!=NULL)
01209 {
01210 acum++;
01211 }
01212 }
01213
01214
01215 for (i=0; i<size; i++)
01216 {
01217 Save3Dcontour(ff,i);
01218 }
01219 }
01220 }
01221
01222
01223 vtkProbeFilter* marAxis::get3DSlice(int i, kVolume* vol){
01224 if (_3Dslices[i]==NULL){ create3DSlice(i,vol); }
01225 return _3Dslices[i];
01226 }
01227
01228 vtkPoints* marAxis::get3Dcontour(int i, kVolume* vol){
01229 if (_3Dcontour[i]==NULL){ create3Dcontour(i, vol); }
01230 return _3Dcontour[i];
01231 }
01232
01233 vtkImageData* marAxis::getSliceImage(int i, kVolume* vol){
01234 if (_quantificationImages[i]==NULL){ createSliceImage(i,vol); }
01235 return _quantificationImages[i];
01236 }
01237
01238 vtkPolyData* marAxis::get2Dcontour(int i , kVolume* vol){
01239 if (_2Dcontours[i]==NULL){ create2Dcontour(i,vol); }
01240 return _2Dcontours[i];
01241 }
01242
01243 vtkPoints* marAxis::get2DDiameterMin(int i , kVolume* vol){
01244 if (_2DDiameterMin[i]==NULL){ create2DDiameterMin(i,vol); }
01245 return _2DDiameterMin[i];
01246 }
01247
01248 vtkPoints* marAxis::get2DDiameterMax(int i , kVolume* vol){
01249 if (_2DDiameterMax[i]==NULL){ create2DDiameterMax(i,vol); }
01250 return _2DDiameterMax[i];
01251 }
01252
01253 double marAxis::getAxisLenght(int pIni,int pEnd){
01254
01255 if (pIni>pEnd){
01256 int tmp=pIni;
01257 pIni=pEnd;
01258 pEnd=tmp;
01259 }
01260
01261 marVector* pO = new marVector(2);
01262 marVector* pF = new marVector(2);
01263 double L;
01264 unsigned int j;
01265 for( j = pIni, L = 0.0; j < pEnd-1; j++ ) {
01266 (*pO)=_points[j];
01267 (*pF)=_points[j+1];
01268 (*pF)=(*pF)-(*pO);
01269 L+=pF->norm2();
01270 }
01271 delete pO;
01272 delete pF;
01273 return L;
01274 }
01275
01276 void marAxis::calculateTotalAxisLenght(){
01277 _totalAxisLenght = getAxisLenght( 0 , _points.size( ) );
01278 }
01279
01280 double marAxis::getTotalLength(){
01281 if (_totalAxisLenght==-1){
01282 calculateTotalAxisLenght();
01283 }
01284 return _totalAxisLenght;
01285 }
01286
01287
01288 void marAxis::calculateSubAxisLength(){
01289 _subAxisLenght = getAxisLenght( _startQuant , _finishQuant );
01290 }
01291
01292 double marAxis::getSubAxisLength(){
01293 if (_subAxisLenght==-1){
01294 calculateSubAxisLength();
01295 }
01296 return _subAxisLenght;
01297 }
01298
01299 double marAxis::getAverageArea(int pIni, int pEnd, kVolume* vol){
01300 marContour *marcontourHealthy;
01301 int ihealthySlice,itemp;
01302 double acumArea = 0;
01303 for (ihealthySlice = pIni ; ihealthySlice <= pEnd ; ihealthySlice++ ){
01304 itemp=ihealthySlice;
01305 if (itemp<0) { itemp=0; }
01306 if (itemp>=_points.size( )) { itemp=_points.size( )-1; }
01307 marcontourHealthy = getContour( itemp , vol );
01308 acumArea = acumArea + marcontourHealthy->getArea();
01309 }
01310 return acumArea / (pEnd - pIni + 1);
01311 }
01312
01313 void marAxis::calculateReferenceArea(kVolume* vol){
01314 _referenceArea = getAverageArea(_healthySliceStart,_healthySliceEnd, vol);
01315 }
01316
01317 double marAxis::getReferenceArea(kVolume* vol){
01318 if (_referenceArea==-1){
01319 calculateReferenceArea(vol);
01320 }
01321 return _referenceArea;
01322 }
01323
01324 void marAxis::calculateReferenceAverDiam(kVolume* vol){
01325 marContour *marcontourHealthy;
01326 int ihealthySlice;
01327 double acumDiam=0;
01328 for (ihealthySlice=_healthySliceStart; ihealthySlice<=_healthySliceEnd; ihealthySlice++){
01329 marcontourHealthy = getContour( ihealthySlice , vol );
01330 acumDiam = acumDiam + marcontourHealthy->getAverageDiameter();
01331 }
01332 _referenceAverDiam = acumDiam / (_healthySliceEnd-_healthySliceStart+1);
01333 }
01334
01335 double marAxis::getReferenceAverDiam(kVolume* vol){
01336 if (_referenceAverDiam==-1){
01337 calculateReferenceAverDiam(vol);
01338 }
01339 return _referenceAverDiam;
01340 }
01341
01342
01343 void marAxis::reset( )
01344 {
01345
01346
01347 kCurve::reset( );
01348
01349 _description = "";
01350 _healthySlice = -1;
01351 _startQuant = -1;
01352 _finishQuant = -1;
01353 _actualQuant = -1;
01354
01355 _subAxisLenght = -1;
01356 _referenceArea = -1;
01357 _referenceAverDiam = -1;
01358
01359 Delete( );
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370 }
01371
01372
01373 void marAxis::copyFrom( const marObject& from )
01374 {
01375 }
01376
01377
01378 bool marAxis::save( std::ofstream& os )
01379 {
01380 double p[ INDX_count ];
01381 unsigned int i;
01382
01383 i = _description.length( );
01384 os.write( ( const char* )&i, sizeof( int ) );
01385 os.write( ( char* )_description.c_str( ), i * sizeof( char ) );
01386
01387 i = getNumberOfControlPoints( );
01388 os.write( ( const char* )&i, sizeof( int ) );
01389 for( i = 0; i < getNumberOfControlPoints( ); i++ ) {
01390
01391 memcpy( p, _controlPoints[ i ], 3 * sizeof( double ) );
01392 memcpy( p + 3, _controlState[ i ],
01393 ( INDX_count - 3 ) * sizeof( double ) );
01394 os.write( ( const char* )p, INDX_count * sizeof( double ) );
01395
01396 }
01397 i = getNumberOfContours( );
01398 os.write( ( const char* )&i, sizeof( int ) );
01399 for( i = 0; i < getNumberOfContours( ); i++ )
01400 _contours[ i ]->save( os );
01401
01402 return( true );
01403 }
01404
01405
01406 bool marAxis::load( std::ifstream& is )
01407 {
01408 double p[ INDX_count ];
01409 int i, n;
01410
01411 reset( );
01412
01413 is.read( ( char* )&n, sizeof( int ) );
01414 _description.resize( n );
01415 is.read( ( char* )_description.c_str( ), n * sizeof( char ) );
01416
01417 is.read( ( char* )&n, sizeof( int ) );
01418 for( i = 0; i < n; i++ ) {
01419
01420 is.read( ( char* )p, INDX_count * sizeof( double ) );
01421 addControlPoint( p, p + 3 );
01422
01423 }
01424 is.read( ( char* )&n, sizeof( int ) );
01425 for( i = 0; i < n; i++ ) {
01426
01427 _contours.push_back( new marContour( 0, getParameters( ) ) );
01428 _contours[ i ]->load( is );
01429
01430 }
01431 return( true );
01432 }
01433
01434 vtkPolyData* marAxis::Draw( )
01435 {
01436 unsigned int i, j;
01437 double *p;
01438
01439 vtkPoints* allPoints = vtkPoints::New( );
01440 vtkCellArray* allTopology = vtkCellArray::New( );
01441
01442 allTopology->InsertNextCell( _points.size( ) );
01443 for( i = 0, j=0; i < _points.size( ); i++, j++ ) {
01444 p = _points[i];
01445 allPoints->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
01446 allTopology->InsertCellPoint( j );
01447 }
01448
01449 _allData = vtkPolyData::New( );
01450 _allData->SetPoints( allPoints );
01451 _allData->SetLines( allTopology );
01452 allPoints->Delete();
01453 allTopology->Delete();
01454
01455 return ( _allData );
01456 }
01457
01458 vtkPolyData *marAxis::GetAxisData( )
01459 {
01460 unsigned int i;
01461 double point[ 3 ];
01462 double radio;
01463 double p[marAxis::INDX_count];
01464
01465
01466 vtkPoints *allPoints = vtkPoints::New( );
01467 vtkCellArray *allTopology = vtkCellArray::New( );
01468 vtkDoubleArray *allRadios = vtkDoubleArray::New( );
01469 allRadios->SetName("radio");
01470
01471 for( i = 0; i < _controlPoints.size( ); i++ ) {
01472 getControlPoint(i, p, p+3);
01473 point[ 0 ] = p[marAxis::INDX_X];
01474 point[ 1 ] = p[marAxis::INDX_Y];
01475 point[ 2 ] = p[marAxis::INDX_Z];
01476 radio = p[marAxis::INDX_RAYON]*2.0;
01477 allPoints -> InsertPoint( i, point[ 0 ] , point[ 1 ] , point[ 2 ] );
01478
01479 allRadios -> InsertValue(i,radio);
01480
01481 if(i>0){
01482 allTopology->InsertNextCell(2);
01483 allTopology->InsertCellPoint(i);
01484 allTopology->InsertCellPoint(i-1);
01485 }
01486
01487 }
01488
01489 _allData = vtkPolyData::New( );
01490 _allData -> SetPoints( allPoints );
01491 _allData -> SetLines( allTopology );
01492 _allData -> GetPointData()->SetScalars(allRadios);
01493
01494
01495 return ( _allData );
01496 }
01497
01498 void marAxis::Delete( ){
01499 clearAllVectors();
01500
01501 int i;
01502 for (i=0;i<_points.size();i++){
01503 if (_points[i]!=NULL) {
01504 delete _points[i];
01505 _points[i]=NULL;
01506 }
01507 }
01508 _points.clear();
01509 _signal.clear();
01510
01511
01512 if(_allData) {
01513 _allData->Delete();
01514 _allData = NULL;
01515 }
01516
01517
01518 }
01519
01520 void marAxis::setHealthySlice( int hsS, int hs, int hsE ){
01521 _healthySliceStart = hsS;
01522 _healthySlice = hs;
01523 _healthySliceEnd = hsE;
01524 _referenceArea=-1;
01525 _referenceAverDiam=-1;
01526 };
01527
01528 void marAxis::setStartQuant( int sq ){
01529 _startQuant = sq;
01530 _subAxisLenght = -1;
01531 };
01532
01533 void marAxis::setFinishQuant( int fq ){
01534 _finishQuant = fq;
01535 _subAxisLenght = -1;
01536 };
01537
01538
01539 void marAxis::AddPointToList(double x, double y, double z, int signal)
01540 {
01541 double *p;
01542 p=(double *)malloc(sizeof(double)*3);
01543 p[0]=x;
01544 p[1]=y;
01545 p[2]=z;
01546 _points.push_back( p );
01547 _signal.push_back( signal );
01548 }
01549
01550
01551
01552