1 /*=========================================================================
4 Module: $RCSfile: marAxis.cpp,v $
6 Date: $Date: 2008/10/31 16:32:54 $
7 Version: $Revision: 1.1 $
9 Copyright: (c) 2002, 2003
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notice for more information.
16 =========================================================================*/
17 #include <vtkPlaneSource.h>
18 #include <vtkKochanekSpline.h>
19 #include <vtkPolyDataConnectivityFilter.h>
20 #include <vtkContourFilter.h>
21 #include <vtkProbeFilter.h>
24 #include <vtkImageChangeInformation.h>
25 #include <vtkImageShiftScale.h>
26 #include <vtkDoubleArray.h>
30 #include "marVector.h"
32 #include "ExtractionAxe.h"
33 #include "FonctionsGrales.h"
35 #include <vtkCellArray.h>
37 #include <vtkCleanPolyData.h>
38 #include <vtkIdList.h>
40 #include <vtkMatrix4x4.h>
41 #include <vtkPointData.h>
42 #include <vtkPolyData.h>
44 #include <vtkSetGet.h>
45 #include <vtkStripper.h>
46 #include <vtkStructuredPoints.h>
47 #include <vtkTransform.h>
49 // ----------------------------------------------------------------------------
50 marAxis::marAxis( marParameters* p ) :
52 kCurve( 3, INDX_count - 3 ),
53 _healthySlice( -1 ), _startQuant( -1 ),
54 _finishQuant( -1 ), _actualQuant( -1 )
60 _referenceAverDiam=-1;
65 _healthySliceStart=-1;
71 // ----------------------------------------------------------------------------
72 void marAxis::addAxisPoint( double* p )
74 double pt[ INDX_count ];
76 memcpy( pt, p, sizeof( POINTAXE ) );
77 pt[ INDX_SIGNALVALUE ] = 0;
78 addControlPoint( pt, pt + 3 );
81 // ----------------------------------------------------------------------------
83 double* marAxis::getNormal( unsigned int slice ) {
85 double* ret = new double[ 3 ];
88 ret[0] = _points[ slice + 1 ][0] - _points[ slice ][0];
89 ret[1] = _points[ slice + 1 ][1] - _points[ slice ][1];
90 ret[2] = _points[ slice + 1 ][2] - _points[ slice ][2];
92 else if ( slice == _points.size( ) - 1 ) {
93 ret[0] = _points[ slice - 1 ][0] - _points[ slice ][0];
94 ret[1] = _points[ slice - 1 ][1] - _points[ slice ][1];
95 ret[2] = _points[ slice - 1 ][2] - _points[ slice ][2];
97 else if ( slice > 0 && slice < _points.size( ) - 1 ) {
98 ret[0] = _points[ slice - 1 ][0] - _points[ slice + 1 ][0];
99 ret[1] = _points[ slice - 1 ][1] - _points[ slice + 1 ][1];
100 ret[2] = _points[ slice - 1 ][2] - _points[ slice + 1 ][2];
106 // ----------------------------------------------------------------------------
107 void marAxis::changeAxisResolution( )
110 int nOut = ( int )ceil(
112 getDoubleParam( marParameters::e_axis_discret_step )
113 * ( double )( GetNumberOfPoints( ) )
116 i = GetNumberOfPoints( );
117 double d = getParameters( )->
118 getDoubleParam( marParameters::e_axis_discret_step );
120 SetResolution( nOut );
121 for( i = 0; i < _contours.size( ); i++ )
122 delete _contours[ i ];
124 for( i = 0; i < nOut; i++ )
125 _contours.push_back( new marContour( getParameters( ) ) );
129 // ----------------------------------------------------------------------------
130 void marAxis::calculateSignal( kVolume* vol )
133 * PSIGNAL_USHORT <-> unsigned short *
135 /* PSIGNAL_FLOAT PutSignalValueFloat(PSIGNAL_FLOAT signal, int pos, float value)
144 unsigned int i, mask_size = getParameters( )-> getIntParam( marParameters::e_mask_size );
146 while( _signal.size( ) > 0 ) _signal.pop_back( );
149 PSIGNAL_USHORT signal = ( PSIGNAL_USHORT ) IdSigAlloc( _points.size( ), SIG_USHORT );
150 for( i = 0; i < _points.size( ); i++ ) {
156 _points_disc, getNumberOfControlPoints( ));
158 maxlocal = vol->GetMaxIntSphere2( p, rayon );
159 PutSignalValue( signal, i, maxlocal );
162 PSIGNAL_FLOAT mask_signal = ( PSIGNAL_FLOAT )IdSigAlloc( mask_size, SIG_FLOAT );
164 for( i = 0; i < mask_size; i++ )
165 PutSignalValueFloat( mask_signal, i, 1 );
167 PSIGNAL_USHORT signalfilt = ( PSIGNAL_USHORT )IdSigAlloc( _points.size( ), SIG_USHORT );
168 signalfilt = MonSigConvolve( signal, mask_signal, signalfilt, 1.0 / ( double )mask_size, 0 );
169 for( i = 0; i < _points.size( ); i++ ){
170 _signal.push_back( GetSignalValue( signalfilt, i ) );
173 IdSigFree( mask_signal );
174 IdSigFree( signalfilt );
177 // ----------------------------------------------------------------------------
178 void marAxis::start( )
181 int swap, n = GetNumberOfPoints( );
183 swap = GSL_MIN( _startQuant, _finishQuant );
184 _finishQuant = GSL_MAX( _startQuant, _finishQuant );
187 _startQuant = ( _startQuant >= 0 )? _startQuant: 0;
188 _finishQuant = ( _finishQuant >= n )? _finishQuant: n - 1;
189 _actualQuant = _startQuant;
193 // ----------------------------------------------------------------------------
194 void marAxis::cut( int slice, bool up )
199 // ----------------------------------------------------------------------------
200 void marAxis::doSpline( )
203 unsigned int nop, nip;
205 float p1[ 3 ], p2[ 3 ];
206 double p[marAxis::INDX_count];
208 vtkKochanekSpline* spX = vtkKochanekSpline::New( );
209 vtkKochanekSpline* spY = vtkKochanekSpline::New( );
210 vtkKochanekSpline* spZ = vtkKochanekSpline::New( );
212 for( i = 0, length = 0.0; i < _controlPoints.size( ); i++ ) {
213 getControlPoint(i, p, p+3);
214 p2[ 0 ] = (float) p[marAxis::INDX_X];
215 p2[ 1 ] = (float) p[marAxis::INDX_Y];
216 p2[ 2 ] = (float) p[marAxis::INDX_Z];
217 spX->AddPoint( (float) i, p2[ 0 ] );
218 spY->AddPoint( (float) i, p2[ 1 ] );
219 spZ->AddPoint( (float) i, p2[ 2 ] );
221 length += (float) (sqrt( (p2[0]-p1[0])*(p2[0]-p1[0]) +
222 (p2[1]-p1[1])*(p2[1]-p1[1]) +
223 (p2[2]-p1[2])*(p2[2]-p1[2]) ) );
224 p1[ 0 ] = p2[ 0 ]; p1[ 1 ] = p2[ 1 ]; p1[ 2 ] = p2[ 2 ];
227 nop = ( unsigned int ) ( getParameters( )->getDoubleParam(
228 marParameters::e_axis_discret_step ) * length );
229 nip = _controlPoints.size( );
232 while( _points.size( ) > 0 ) {
233 delete _points[ _points.size( ) - 1 ];
237 while( _contours.size( ) > 0 ) {
238 delete _contours[ _contours.size( ) - 1 ];
239 _contours.pop_back( );
242 for( i = 0; i < nop; i++ ) {
243 t = (float) (( ( double ) nip - 1.0 ) / ( ( double ) nop - 1.0 ) * i);
244 double* np = new double[ 3 ];
248 np[ 0 ] = (double) (spX->Evaluate( t ));
249 np[ 1 ] = (double) (spY->Evaluate( t ));
250 np[ 2 ] = (double) (spZ->Evaluate( t ));
251 _points.push_back( np );
252 _contours.push_back( new marContour( i, getParameters( ) ) );
264 // ----------------------------------------------------------------------------
265 void marAxis::sliceVolumeAxis( kVolume* vol, bool forceCnt )
268 int nCnts = ( int ) getNumberOfSplinePoints( );
269 int sizeIma = getParameters( )->getSizeIma( );
270 double dimIma = getParameters( )->getDimIma( );
271 double voxSize = getParameters( )->getVoxelSize( );
274 for( unsigned int i = 0; i < _contours.size( ); i++ )
275 delete _contours[ i ];
278 for( unsigned int i = 0; i < _slices.size( ); i++ ) {
280 _3Dslices[ i ]->Delete( );
281 _quantificationImages[ i ]->Delete( );
286 _quantificationImages.clear( );
289 // "Cutter" initialization
290 vtkStructuredPoints* stPoints = vtkStructuredPoints::New( );
293 for( int k = 0; k < nCnts; k++ ) {
294 //s = ( double )k / ( double )( nCnts - 1 );
297 vtkPlaneSource* pSource = vtkPlaneSource::New( );
298 pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
299 pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
300 pSource->SetPoint2( p[ 0 ], p[ 1 ], p[ 2 ] + dimIma - 1.0 );
301 pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
303 pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
304 pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
307 _3Dslices.push_back( vtkProbeFilter::New( ) );
308 _3Dslices[ k ]->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
309 _3Dslices[ k ]->SetSource( vol->castVtk( ) );
310 _3Dslices[ k ]->Update( );
313 stPoints->GetPointData( )->
314 SetScalars( _3Dslices[ k ]->GetOutput( )->
315 GetPointData( )->GetScalars( ) );
316 stPoints->SetDimensions( sizeIma, sizeIma, 1 );
317 stPoints->SetScalarType( vol->castVtk( )->GetDataObjectType( ) );
321 marContour* tmp_marContour = new marContour( k, getParameters( ) ) ;
322 tmp_marContour->calculateVariables();
323 _contours.push_back( tmp_marContour );
325 _slices.push_back( new kVolume( kVolume::UCHAR, 1, 1, 1 ) );
327 *( _slices[ k ] ) = ( vtkImageData* )stPoints; //copy
328 _quantificationImages.push_back( (_slices[ k ])->castVtk( ) );
337 // ----------------------------------------------------------------------------
338 int marAxis::getNumberOfContours( )
340 return( _contours.size( ) );
343 // ----------------------------------------------------------------------------
344 int marAxis::getNumberOfSplinePoints( )
346 return( _points.size( ) );
350 // EED Esto toca limpiarlo o reimplementarlo en varias partes o algo
351 // ----------------------------------------------------------------------------
352 vtkPolyData* marAxis::setContour( int i, int x, int y, std::vector< double* >* points, marContour* c )
356 c->setS( c->getS( ) );
357 _contours[ i ]->copyFrom( *c );
361 // PS -> // int numberOfPoints, numberOfCells; // PS
362 // PS -> // int id; // PS
363 // PS -> // gslobj_vector p( 3 ); // PS
364 // PS -> // double new_p[3]; // PS
365 // PS -> // float pf[ 3 ]; // PS
366 vtkImageData* imagedata;
368 // Contour parameters
369 // PS -> int typ = getParameters( )->getIntParam( marParameters::e_algorithm_type );
370 double thr = getParameters( )->getDoubleParam( marParameters::e_threshold_isocontour );
372 // PS -> double thr = ( typ == marParameters::ISOCONTOURS )?
373 // PS -> getParameters( )->
374 // PS -> getDoubleParam( marParameters::e_threshold_isocontour ):
375 // PS -> ( typ == marParameters::SNAKE ) ?
376 // PS -> getParameters( )->
377 // PS -> getDoubleParam( marParameters::e_threshold_snake_isocontour ):
381 int sizeIma = getParameters( )->getSizeIma( );
382 double localint = getSignal( i );
383 double sigma = getParameters( )->getDoubleParam( marParameters::e_sigma );
384 double threshold = localint * thr / 100.0;
385 int dimIma = ( int ) ( ( double ) sizeIma /getParameters( )->getDoubleParam( marParameters::e_scale ) );
386 int vmin = ( int )threshold;
387 int vmax = ( int )threshold;
389 x = ( x != -1 )? x: sizeIma / 2;
390 y = ( y != -1 )? y: sizeIma / 2;
393 imagedata = (vtkImageData*) ((getSlice( i , NULL ))->castVtk( ));
394 float *range = imagedata->GetScalarRange();
396 //vtkKitwareContourFilter* cntVTK = vtkKitwareContourFilter::New( );
397 vtkContourFilter* cntVTK = vtkContourFilter::New( );
398 cntVTK->SetInput( imagedata );
399 cntVTK->SetNumberOfContours( 1 );
400 //cntVTK->SetValue( 0, vmin );
401 cntVTK->SetValue( 0, (range[1]*thr/100) );
402 //cntVTK->SetValue( 1, vmax );
405 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
406 cpd->SetInput( cntVTK->GetOutput( ) );
407 cpd->ConvertLinesToPointsOff( );
410 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
411 //conn->SetMaxRecursionDepth( 3000 );
413 // PS -> //conn->SetInput( cntVTK->GetOutput( ) ); PS
414 conn->SetInput( cpd->GetOutput( ) );
416 conn->SetClosestPoint( x, y, 0 );
417 conn->SetExtractionModeToClosestPointRegion( );
420 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
421 cpd2->SetInput( conn->GetOutput( ) );
424 vtkPolyData* polyDataResult = cpd2->GetOutput() ;
426 double ta = _contours[ i ]->getS( );
428 _contours[ i ]->reset( );
430 // PS -> gslobj_vector o( 3 ), n( 3 ), y( 3 ), vr( 3 );
434 int numberOfPoints,numberOfPoints2;
438 // PS -> double new_p[3];
441 numberOfCells = polyDataResult->GetNumberOfCells( );
442 cell = polyDataResult->GetCell( 0 );
443 pids = cell->GetPointIds( );
444 numberOfPoints = pids->GetNumberOfIds( );
446 numberOfPoints2=polyDataResult->GetNumberOfPoints();
448 marVector o(3),n(3),y(3),vr(3);
450 y( 0 ) = y( 2 ) = 0.0;
452 getPoint( ( double* )o, ta );
453 getTangent( ( double* )n, ta );
454 vr = y.cross( n ).normalize( );
455 sint = y.cross( n ).norm2( );
458 for( int j = 0; j < numberOfPoints; j++ )
460 id = pids->GetId( j );
461 polyDataResult->GetPoint( id, pf );
467 p = ( p * cost ) + ( vr * ( vr.dot( p ) * ( 1.0 - cost ) ) ) -
468 ( p.cross( vr ) * sint ) + o;
470 // PS -> double p_cross_vr[3];
471 // PS -> vtkMath::Cross( p, vr, p_cross_vr);
472 // PS -> for(int k=0; k<3; k++)
474 // PS -> new_p[i] = (new_p[k] * cost) + ( vr(k) * ( vtkMath::Dot(vr, p) * ( 1.0 - cost ) ) ) -
475 // PS -> ( p_cross_vr[k] * sint ) + o(i);
478 //TODO: check if p and new_p are the same...
479 _contours[ i ]->addContourPoint( p );
482 // PS -> int nbPoints=polyDataResult->GetNumberOfPoints();
484 // PS -> float* vtkContourPoint;
485 // PS -> vtkContourPoint= new float[3];
486 // PS -> double* marContourPoint;
487 // PS -> marContourPoint= new double[3];
489 // PS -> for (int j=0;j< nbPoints;j++)
491 // PS -> vtkContourPoint=polyDataResult->GetPoint(j);
492 // PS -> marContourPoint[0]=(double)vtkContourPoint[0];
493 // PS -> marContourPoint[1]=(double)vtkContourPoint[1];
494 // PS -> marContourPoint[2]=(double)vtkContourPoint[2];
495 // PS -> _contours[ i ]->addContourPoint( marContourPoint );
497 marContour * tutu=_contours[ i ];
498 _contours[ i ]->getArea();
499 _contours[ i ]->getPerimeter();
500 return( polyDataResult );
501 //return( cpd->GetOutput( ) );
502 //return( cntVTK->GetOutput( ) );
505 //EED1 vtkStripper* isoStrips = vtkStripper::New( );
506 //EED1 isoStrips->SetInput( cpd2->GetOutput( ) );
507 //EED1 isoStrips->Update( );
509 //EED1 vtkPolyData* data = isoStrips->GetOutput( );
510 //EED1 data->Update( );
511 //EED1 vtkCell* cell;
512 //EED1 vtkIdList* pids;
514 //EED1 numberOfCells = data->GetNumberOfCells( );
515 //EED1 cell = data->GetCell( 0 );
516 //EED1 pids = cell->GetPointIds( );
517 //EED1 numberOfPoints = pids->GetNumberOfIds( );
520 //EED2 _contours[ i ]->reset( );
521 //EED2 if( typ == marParameters::ISOCONTOURS ) {
522 //EED2 gslobj_vector o( 3 ), n( 3 ), y( 3 ), vr( 3 );
523 //EED2 double cost, sint;
524 //EED2 y( 0 ) = y( 2 ) = 0.0;
526 //EED2 getPoint( ( double* )o, ta );
527 //EED2 getTangent( ( double* )n, ta );
528 //EED2 vr = y.cross( n ).normalize( );
529 //EED2 sint = y.cross( n ).norm2( );
530 //EED2 cost = y.dot( n );
532 //EED2 for( int j = 0; j < numberOfPoints; j++ ) {
533 //EED2 id = pids->GetId( j );
534 //EED2 data->GetPoint( id, pf );
535 //EED2 p( 0 ) = pf[ 0 ];
537 //EED2 p( 2 ) = pf[ 1 ];
539 //EED2 // 3D transformation
540 //EED2 p = ( p * cost ) + ( vr * ( vr.dot( p ) * ( 1.0 - cost ) ) ) -
541 //EED2 ( p.cross( vr ) * sint ) + o;
543 //EED2 double p_cross_vr[3];
544 //EED2 vtkMath::Cross( p, vr, p_cross_vr);
545 //EED2 for(int ii=0; ii<3; ii++) {
546 //EED2 new_p[i] = (new_p[ii] * cost) + ( vr(ii) * ( vtkMath::Dot(vr, p) * ( 1.0 - cost ) ) ) -
547 //EED2 ( p_cross_vr[ii] * sint ) + o(i);
550 //EED2 //TODO: check if p and new_p are the same...
551 //EED2 _contours[ i ]->addContourPoint( p );
553 //EED2 } else if( typ == marParameters::SNAKE || typ == marParameters::DERICHE ) {
554 //EED2 // ONLY Isocontours at the moment.
557 //EED2 cntVTK->Delete( );
558 //EED2 cpd->Delete( );
559 //EED2 conn->Delete( );
560 //EED2 cpd2->Delete( );
561 //EED2 isoStrips->Delete( );
571 // ----------------------------------------------------------------------------
572 void marAxis::createContour(int i, kVolume* vol)
576 int numberOfPoints,numberOfCells;
580 vtkPolyData* vtkPolyData_2DContour;
583 int sizeIma = getParameters( )->getSizeIma( );
584 double dimIma = getParameters( )->getDimIma( );
589 _contours[i] = new marContour( i, getParameters( ) ) ;
590 vtkPolyData_2DContour = get2Dcontour(i,vol);
592 numberOfCells = vtkPolyData_2DContour->GetNumberOfCells( );
593 cell = vtkPolyData_2DContour->GetCell( 0 );
594 pids = cell->GetPointIds( );
595 numberOfPoints = pids->GetNumberOfIds( );
597 for( j = 0; j < numberOfPoints; j++ )
599 id = pids->GetId( j );
600 vtkPolyData_2DContour->GetPoint( id, p);
603 x=x * dimIma / ( float ) sizeIma;
604 y=y * dimIma / ( float ) sizeIma;
605 _contours[ i ]->addContourPoint( x , y );
608 _contours[i]->do_spline();
609 _contours[i]->calculateVariables();
613 // ----------------------------------------------------------------------------
614 void marAxis::EraseContour(int i){
615 if (_3Dcontour[i]!=NULL){
616 _3Dcontour[i]->Delete();
620 if (_2DDiameterMax[i]!=NULL){
621 _2DDiameterMax[i]->Delete();
622 _2DDiameterMax[i]=NULL;
625 if (_2DDiameterMin[i]!=NULL){
626 _2DDiameterMin[i]->Delete();
627 _2DDiameterMin[i]=NULL;
630 if (_2Dcontours[i]!=NULL){
631 _2Dcontours[i]->Delete();
635 if (_contours[i]!=NULL){
641 // ----------------------------------------------------------------------------
642 void marAxis::replaceContour2D(int i,int size,double *vx,double *vy){
647 vtkPoints *_pts = vtkPoints::New();
648 _pts->SetNumberOfPoints(size);
651 for (j=0 ; j<size ; j++){
652 _pts->SetPoint(j, vx[j] , vy[j] , 0 );
654 // _pts->SetPoint(0, vx[0] , vy[0] , 0 );
656 vtkCellArray *lines = vtkCellArray::New();
657 lines->InsertNextCell( size );
658 for ( j=0 ; j<size+1 ; j++ ){
659 lines->InsertCellPoint(j % size );
662 vtkPolyData *_pd = vtkPolyData::New();
663 _pd->SetPoints( _pts );
664 _pd->SetLines( lines );
665 lines->Delete(); //do not delete lines ??
669 createContour(i,NULL);
671 // ----------------------------------------------------------------------------
672 void marAxis::createSlice(int i , kVolume* vol){
674 int sizeIma = getParameters( )->getSizeIma( );
676 vtkStructuredPoints* stPoints = vtkStructuredPoints::New( );
681 stPoints->GetPointData( )->SetScalars( get3DSlice(k,vol)->GetOutput()->GetPointData()->GetScalars() );
682 stPoints->SetDimensions( sizeIma, sizeIma, 1 );
685 stPoints->SetScalarType( vol->castVtk( )->GetDataObjectType( ) );
686 stPoints->SetScalarTypeToShort ();
689 vtkImageChangeInformation* change = vtkImageChangeInformation::New();
690 change->SetInput( stPoints );
691 change->Update(); //important
694 if (_slices[k]!=NULL) { delete _slices[k]; }
695 _slices[k] = new kVolume( change->GetOutput() ) ;
700 // ----------------------------------------------------------------------------
701 void marAxis::create3DSlice(int i , kVolume* vol )
705 int sizeIma = getParameters( )->getSizeIma( );
706 double dimIma = getParameters( )->getDimIma( );
711 // double voxSize = getParameters( )->getVoxelSize( );
714 // for( unsigned int i = 0; i < _contours.size( ); i++ )
715 // delete _contours[ i ];
716 // _contours.clear( );
718 // for( unsigned int i = 0; i < _slices.size( ); i++ ) {
719 // delete _slices[ i ];
720 // _3Dslices[ i ]->Delete( );
721 // _quantificationImages[ i ]->Delete( );
725 // _3Dslices.clear( );
726 // _quantificationImages.clear( );
728 // "Cutter" initialization
729 // vtkStructuredPoints* stPoints = vtkStructuredPoints::New( );
733 // for( int k = 0; k < nCnts; k++ ) {
734 //s = ( double )k / ( double )( nCnts - 1 );
738 vtkPlaneSource* pSource = vtkPlaneSource::New( );
739 pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
740 pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
741 pSource->SetPoint2( p[ 0 ], p[ 1 ], p[ 2 ] + dimIma - 1.0 );
742 pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
744 pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
745 pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
748 if (_3Dslices[ k ]!=NULL){ _3Dslices[ k ]->Delete(); }
749 _3Dslices[ k ] = vtkProbeFilter::New( ) ;
750 _3Dslices[ k ]->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
751 _3Dslices[ k ]->SetSource( vol->castVtk( ) );
752 _3Dslices[ k ]->Update( );
755 // stPoints->GetPointData( )->
756 // SetScalars( _3Dslices[ k ]->GetOutput( )->
757 // GetPointData( )->GetScalars( ) );
758 // stPoints->SetDimensions( sizeIma, sizeIma, 1 );
759 // stPoints->SetScalarType( vol->castVtk( )->GetDataObjectType( ) );
760 // stPoints->Update( );
764 // marContour* tmp_marContour = new marContour( k, getParameters( ) ) ;
765 // tmp_marContour->calculateVariables();
766 // _contours.push_back( tmp_marContour );
768 // _slices.push_back( new kVolume( kVolume::UCHAR, 1, 1, 1 ) );
769 // *( _slices[ k ] ) = ( vtkImageData* )stPoints; //copy
770 // _quantificationImages.push_back( (_slices[ k ])->castVtk( ) );
773 // stPoints->Delete( );
775 // _3Dslices[i]=NULL;
781 // ----------------------------------------------------------------------------
782 void marAxis::create3Dcontour(int i, kVolume* vol)
784 vtkPoints *_vtkPoints;
790 double c[3],p1[3],p2[3];
793 _vtkPoints = vtkPoints::New();
796 mat = vtkMatrix4x4::New();
797 trans = vtkTransform::New();
800 nn[0]=n[0]; nn[1]=n[1]; nn[2]=n[2];
801 nC=sqrt( nn[0]*nn[0] + nn[1]*nn[1] + nn[2]*nn[2] );
802 nn[0]=nn[0]/nC; nn[1]=nn[1]/nC; nn[2]=nn[2]/nC;
804 vtkPlaneSource* pSource = vtkPlaneSource::New( );
805 pSource->SetOrigin( 0, 0 , 0 );
806 pSource->SetPoint1( 1, 0 , 0 );
807 pSource->SetPoint2( 0, 0 , 1.0 );
808 pSource->SetCenter( 0,0,0 );
809 pSource->SetNormal( nn[ 0 ], nn[ 1 ], nn[ 2 ] );
811 // pSource->Update( );
812 pSource->GetOrigin(c);
813 pSource->GetPoint1(p1);
814 pSource->GetPoint2(p2);
816 p1[0]=p1[0]-c[0]; p1[1]=p1[1]-c[1]; p1[2]=p1[2]-c[2];
817 p2[0]=p2[0]-c[0]; p2[1]=p2[1]-c[1]; p2[2]=p2[2]-c[2];
818 nA=sqrt( p1[0]*p1[0] + p1[1]*p1[1] + p1[2]*p1[2] );
819 nB=sqrt( p2[0]*p2[0] + p2[1]*p2[1] + p2[2]*p2[2] );
820 p1[0]=p1[0]/nA; p1[1]=p1[1]/nA; p1[2]=p1[2]/nA;
821 p2[0]=p2[0]/nB; p2[1]=p2[1]/nB; p2[2]=p2[2]/nB;
823 mat->SetElement (0,0, nn[0]);
824 mat->SetElement (1,0, nn[1]);
825 mat->SetElement (2,0, nn[2]);
826 mat->SetElement (3,0, 0);
827 mat->SetElement (0,1, p2[0]);
828 mat->SetElement (1,1, p2[1]);
829 mat->SetElement (2,1, p2[2]);
830 mat->SetElement (3,1, 0);
831 mat->SetElement (0,2, p1[0]);
832 mat->SetElement (1,2, p1[1]);
833 mat->SetElement (2,2, p1[2]);
834 mat->SetElement (3,2, 0);
835 mat->SetElement (0,3, 0);
836 mat->SetElement (1,3, 0);
837 mat->SetElement (2,3, 0);
838 mat->SetElement (3,3, 1);
840 // double deter=mat->Determinant(mat);
842 trans->SetMatrix(mat);
845 trans->RotateWXYZ ( ang,0,1,0);
849 // trans->Scale ( scale , scale, scale);
853 vtkMatrix4x4 *m=vtkMatrix4x4::New();
854 trans->GetMatrix ( m );
857 int j,numberOfPoints;
858 marContour* contour2D = getContour(i,vol);
859 numberOfPoints = contour2D->getNumberOfPoints( );
864 for( j = 0; j <= numberOfPoints; j++ ) {
865 contour2D->getPoint( fpA,j % numberOfPoints);
867 pA[0] = fpA[0] + 0.2; // correction EED
868 pA[1] = fpA[1] + 0.2; // correction EED
872 // Why this does not works...(release version)????
873 // trans->TransformPoint(pA,ppp);
875 // trans->TransformVector(pA,ppp);
877 ppp[0] = m->GetElement(0,0)*pA[0] + m->GetElement(0,1)*pA[1] + m->GetElement(0,2)*pA[2] + m->GetElement(0,3);
878 ppp[1] = m->GetElement(1,0)*pA[0] + m->GetElement(1,1)*pA[1] + m->GetElement(1,2)*pA[2] + m->GetElement(1,3);
879 ppp[2] = m->GetElement(2,0)*pA[0] + m->GetElement(2,1)*pA[1] + m->GetElement(2,2)*pA[2] + m->GetElement(2,3);
881 // ppp[0]=ppp[0]+o[0]-c[0]; ppp[1]=ppp[1]+o[1]-c[1]; ppp[2]=ppp[2]+o[2]-c[2];
882 ppp[0]=ppp[0]+o[0]; ppp[1]=ppp[1]+o[1]; ppp[2]=ppp[2]+o[2];
883 // ppp[0]=ppp[0]+o[0]-c[0]*0.781; ppp[1]=ppp[1]+o[1]-c[1]*0.781;; ppp[2]=ppp[2]+o[2]-c[2]*0.781;;
884 _vtkPoints->InsertNextPoint( (float)ppp[0],(float)ppp[1],(float)ppp[2] );
890 if (_3Dcontour[i]!=NULL){ _3Dcontour[i]->Delete(); }
891 _3Dcontour[i]=_vtkPoints;
894 // ----------------------------------------------------------------------------
895 void marAxis::createSliceImage(int i , kVolume* vol )
897 _quantificationImages[i] = getSlice(i,vol)->castVtk( ) ;
900 // ----------------------------------------------------------------------------
901 void marAxis::create2Dcontour(int i , kVolume* vol )
903 vtkImageData* imagedata;
905 double thr = getParameters( )->getDoubleParam( marParameters::e_threshold_isocontour );
906 int sizeIma = getParameters( )->getSizeIma( );
907 double localint = getSignal( i );
908 double sigma = getParameters( )->getDoubleParam( marParameters::e_sigma );
909 double threshold = localint * thr / 100.0;
911 int dimIma = ( int ) ( ( double ) sizeIma /getParameters( )->getDoubleParam( marParameters::e_scale ) );
912 int vmin = ( int )threshold;
913 int vmax = ( int )threshold;
918 x = ( x != -1 )? x: sizeIma / 2;
919 y = ( y != -1 )? y: sizeIma / 2;
922 imagedata = (vtkImageData*) ((getSlice( i , vol ))->castVtk( ));
923 double *range = imagedata->GetScalarRange();
925 //vtkKitwareContourFilter* cntVTK = vtkKitwareContourFilter::New( );
926 vtkContourFilter* cntVTK = vtkContourFilter::New( );
927 cntVTK->SetInput( imagedata );
928 cntVTK->SetNumberOfContours( 1 );
929 //cntVTK->SetValue( 0, vmin );
930 cntVTK->SetValue( 0, (range[1]*thr/100) );
931 //cntVTK->SetValue( 1, vmax );
934 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
935 cpd->SetInput( cntVTK->GetOutput( ) );
936 cpd->ConvertLinesToPointsOff( );
939 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
940 //conn->SetMaxRecursionDepth( 3000 );
942 // PS -> //conn->SetInput( cntVTK->GetOutput( ) ); PS
943 conn->SetInput( cpd->GetOutput( ) );
945 conn->SetClosestPoint( x, y, 0 );
946 conn->SetExtractionModeToClosestPointRegion( );
949 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
950 cpd2->SetInput( conn->GetOutput( ) );
953 vtkStripper* vtkstripper = vtkStripper::New( );
954 vtkstripper->SetInput( cpd2->GetOutput() );
955 vtkstripper->Update();
957 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
958 polyDataResult->Update( );
968 int ii,size=polyDataResult->GetNumberOfPoints();
969 printf("EED marAxis::create2Dcontour size %d\n",size);
970 for (ii=0;ii<size;ii++)
972 p=polyDataResult->GetPoint(ii);
973 printf("EED marAxis::create2Dcontour %d >> %f %f %f\n",ii,p[0], p[1], p[2]);
977 for (ii=0;ii<size;ii++)
979 p=polyDataResult->GetPoint(ii);
980 printf("EED marAxis::create2Dcontour xxxxx %d >> %f %f %f\n",ii,p[0], p[1], p[2]);
984 if ( _2Dcontours[i]!=NULL ) { _2Dcontours[i]->Delete(); }
985 _2Dcontours[i]=polyDataResult;
987 // ----------------------------------------------------------------------------
988 void marAxis::create2DDiameterMin( int i , kVolume* vol ){
990 marContour *marcontour=getContour(i,vol);
991 marcontour->getMinimumLine(p1,p2);
992 vtkPoints *_vtkPoints = vtkPoints::New();
993 int sizeIma = getParameters( )->getSizeIma( );
995 double dimIma = getParameters( )->getDimIma( );
1000 double factor=( float ) sizeIma / dimIma;
1001 p1[0]=p1[0]*factor+sizeIma/2;
1002 p1[1]=p1[1]*factor+sizeIma/2;
1003 p2[0]=p2[0]*factor+sizeIma/2;
1004 p2[1]=p2[1]*factor+sizeIma/2;
1005 _vtkPoints->InsertNextPoint( p1[0] , p1[1] , 1 );
1006 _vtkPoints->InsertNextPoint( p2[0] , p2[1] , 1 );
1007 if ( _2DDiameterMin[i]!=NULL ) { _2DDiameterMin[i]->Delete(); }
1008 _2DDiameterMin[i] = _vtkPoints;
1010 // ----------------------------------------------------------------------------
1011 void marAxis::create2DDiameterMax( int i , kVolume* vol ){
1013 marContour *marcontour=getContour(i,vol);
1014 marcontour->getMaximumLine(p1,p2);
1015 vtkPoints *_vtkPoints = vtkPoints::New();
1016 int sizeIma = getParameters( )->getSizeIma( );
1018 double dimIma = getParameters( )->getDimIma( );
1022 double factor=( float ) sizeIma / dimIma;
1023 p1[0]=p1[0]*factor+sizeIma/2;
1024 p1[1]=p1[1]*factor+sizeIma/2;
1025 p2[0]=p2[0]*factor+sizeIma/2;
1026 p2[1]=p2[1]*factor+sizeIma/2;
1027 _vtkPoints->InsertNextPoint( p1[0] , p1[1] , 1 );
1028 _vtkPoints->InsertNextPoint( p2[0] , p2[1] , 1 );
1029 if ( _2DDiameterMax[i]!=NULL ) { _2DDiameterMax[i]->Delete(); }
1030 _2DDiameterMax[i] = _vtkPoints;
1032 // ----------------------------------------------------------------------------
1033 void marAxis::createEmptyVectors()
1035 int nCnts = ( int ) getNumberOfSplinePoints( );
1038 // int xxxx=getNumberOfContours();
1039 for (i=0;i<nCnts;i++){
1040 _contours.push_back( NULL );
1041 _slices.push_back( NULL );
1042 _3Dslices.push_back( NULL );
1043 _3Dcontour.push_back( NULL );
1044 _quantificationImages.push_back( NULL );
1045 _2Dcontours.push_back( NULL );
1046 _2DDiameterMin.push_back( NULL );
1047 _2DDiameterMax.push_back( NULL );
1050 // ----------------------------------------------------------------------------
1051 void marAxis::clearAllVectors()
1055 for (i=0;i<_contours.size();i++){
1056 if (_contours[i]!=NULL) { // DATA-MODEL-2D
1057 delete _contours[i];
1063 for (i=0;i<_slices.size();i++){ // DATA-MODEL-Voxel XxYx1
1064 if (_slices[i]!=NULL) {
1072 for (i=0;i<_3Dslices.size();i++){ // VISUALISATION_VTK 3D
1073 if (_3Dslices[i]!=NULL) {
1074 _3Dslices[i]->Delete();
1080 for (i=0;i<_3Dcontour.size();i++){ // VISUALISATION_VTK 3D
1081 if (_3Dcontour[i]!=NULL) {
1082 _3Dcontour[i]->Delete();
1088 for (i=0;i<_quantificationImages.size();i++){ // VISUALISATION_VTK 2D
1089 if (_quantificationImages[i]!=NULL) {
1090 // _quantificationImages[i]->Delete();
1091 // _quantificationImages[i]=NULL;
1094 _quantificationImages.clear();
1096 for (i=0;i<_2Dcontours.size();i++){ // VISUALISATION_VTK 2D
1097 if (_2Dcontours[i]!=NULL) {
1098 // EED ??? This object was allready erased bye the VTK pipeline
1099 // _2Dcontours[i]->Delete();
1100 _2Dcontours[i]=NULL;
1103 _2Dcontours.clear();
1105 for (i=0;i<_2DDiameterMin.size();i++){ // VISUALISATION_VTK 2D
1106 if (_2DDiameterMin[i]!=NULL) {
1107 _2DDiameterMin[i]->Delete() ;
1108 _2DDiameterMin[i]=NULL;
1111 _2DDiameterMin.clear();
1113 for (i=0;i<_2DDiameterMax.size();i++){ // VISUALISATION_VTK 2D
1114 if (_2DDiameterMax[i]!=NULL) {
1115 _2DDiameterMax[i]->Delete();
1116 _2DDiameterMax[i]=NULL;
1119 _2DDiameterMax.clear();
1122 // ----------------------------------------------------------------------------
1123 void marAxis::eraseContourVectorsContent()
1126 for (i=0;i<_contours.size();i++){
1127 if (_contours[i]!=NULL) { // DATA-MODEL-2D
1128 delete _contours[i];
1132 for (i=0;i<_2Dcontours.size();i++){ // VISUALISATION_VTK 2D
1133 if (_2Dcontours[i]!=NULL) {
1134 _2Dcontours[i]->Delete();
1135 _2Dcontours[i]=NULL;
1138 for (i=0;i<_2DDiameterMin.size();i++){ // VISUALISATION_VTK 2D
1139 if (_2DDiameterMin[i]!=NULL) {
1140 _2DDiameterMin[i]->Delete();
1141 _2DDiameterMin[i]=NULL;
1144 for (i=0;i<_2DDiameterMax.size();i++){ // VISUALISATION_VTK 2D
1145 if (_2DDiameterMax[i]!=NULL) {
1146 _2DDiameterMax[i]->Delete();
1147 _2DDiameterMax[i]=NULL;
1150 for (i=0;i<_3Dcontour.size();i++){ // VISUALISATION_VTK 3D
1151 if (_3Dcontour[i]!=NULL) {
1152 _3Dcontour[i]->Delete();
1158 // ----------------------------------------------------------------------------
1159 marContour* marAxis::getContour(int i, kVolume* vol) // DATA-MODEL 2D
1161 if (_contours[i]==NULL){ createContour(i, vol); }
1162 return _contours[i];
1164 // ----------------------------------------------------------------------------
1165 kVolume* marAxis::getSlice(int i, kVolume* vol) // DATA-MODEL-Voxel XxYx1
1167 if (_slices[i]==NULL){ createSlice( i , vol ); }
1170 // ----------------------------------------------------------------------------
1172 bool marAxis::if3DcontourExist(int i)
1175 if (_3Dcontour[i]==NULL)
1182 // ----------------------------------------------------------------------------
1183 void marAxis::Save3Dcontour(FILE *ff,int id)
1187 if (_3Dcontour[id]!=NULL)
1189 //Ramiro fprintf(ff,"contour_id: %d \n", id);
1190 size = _3Dcontour[id]->GetNumberOfPoints();
1191 //Ramiro fprintf(ff,"numberOfPoints: %d \n", size);
1192 for ( i=0 ; i<size ;i++ ){
1193 _3Dcontour[id]->GetPoint( i , point );
1194 fprintf(ff,"%f %f %f %d\n", point[0], point[1],point[2],id);
1198 // ----------------------------------------------------------------------------
1199 void marAxis::SaveExisting3DContours(FILE *ff)
1203 // counting existing 3Dcontours
1205 int i,size=_3Dcontour.size();
1206 for (i=0; i<size; i++)
1208 if (_3Dcontour[i]!=NULL)
1213 //Ramiro fprintf(ff, "NumberOf3DContours: %d \n", acum);
1214 // saving existing 3Dcontours
1215 for (i=0; i<size; i++)
1217 Save3Dcontour(ff,i);
1222 // ----------------------------------------------------------------------------
1223 vtkProbeFilter* marAxis::get3DSlice(int i, kVolume* vol){ // VISUALISATION-VTK 3D
1224 if (_3Dslices[i]==NULL){ create3DSlice(i,vol); }
1225 return _3Dslices[i];
1227 // ----------------------------------------------------------------------------
1228 vtkPoints* marAxis::get3Dcontour(int i, kVolume* vol){ // VISUALISATION-VTK 3D
1229 if (_3Dcontour[i]==NULL){ create3Dcontour(i, vol); }
1230 return _3Dcontour[i];
1232 // ----------------------------------------------------------------------------
1233 vtkImageData* marAxis::getSliceImage(int i, kVolume* vol){ // VISUALISATION-VTK 2D
1234 if (_quantificationImages[i]==NULL){ createSliceImage(i,vol); }
1235 return _quantificationImages[i];
1237 // ----------------------------------------------------------------------------
1238 vtkPolyData* marAxis::get2Dcontour(int i , kVolume* vol){ // VISUALISATION-VTK 2D
1239 if (_2Dcontours[i]==NULL){ create2Dcontour(i,vol); }
1240 return _2Dcontours[i];
1242 // ----------------------------------------------------------------------------
1243 vtkPoints* marAxis::get2DDiameterMin(int i , kVolume* vol){ // VISUALISATION-VTK 2D
1244 if (_2DDiameterMin[i]==NULL){ create2DDiameterMin(i,vol); }
1245 return _2DDiameterMin[i];
1247 // ----------------------------------------------------------------------------
1248 vtkPoints* marAxis::get2DDiameterMax(int i , kVolume* vol){ // VISUALISATION-VTK 2D
1249 if (_2DDiameterMax[i]==NULL){ create2DDiameterMax(i,vol); }
1250 return _2DDiameterMax[i];
1252 // ----------------------------------------------------------------------------
1253 double marAxis::getAxisLenght(int pIni,int pEnd){
1261 marVector* pO = new marVector(2);
1262 marVector* pF = new marVector(2);
1265 for( j = pIni, L = 0.0; j < pEnd-1; j++ ) {
1275 // ----------------------------------------------------------------------------
1276 void marAxis::calculateTotalAxisLenght(){
1277 _totalAxisLenght = getAxisLenght( 0 , _points.size( ) );
1279 // ----------------------------------------------------------------------------
1280 double marAxis::getTotalLength(){
1281 if (_totalAxisLenght==-1){
1282 calculateTotalAxisLenght();
1284 return _totalAxisLenght;
1287 // ----------------------------------------------------------------------------
1288 void marAxis::calculateSubAxisLength(){
1289 _subAxisLenght = getAxisLenght( _startQuant , _finishQuant );
1291 // ----------------------------------------------------------------------------
1292 double marAxis::getSubAxisLength(){
1293 if (_subAxisLenght==-1){
1294 calculateSubAxisLength();
1296 return _subAxisLenght;
1298 // ----------------------------------------------------------------------------
1299 double marAxis::getAverageArea(int pIni, int pEnd, kVolume* vol){
1300 marContour *marcontourHealthy;
1301 int ihealthySlice,itemp;
1302 double acumArea = 0;
1303 for (ihealthySlice = pIni ; ihealthySlice <= pEnd ; ihealthySlice++ ){
1304 itemp=ihealthySlice;
1305 if (itemp<0) { itemp=0; }
1306 if (itemp>=_points.size( )) { itemp=_points.size( )-1; }
1307 marcontourHealthy = getContour( itemp , vol );
1308 acumArea = acumArea + marcontourHealthy->getArea();
1310 return acumArea / (pEnd - pIni + 1);
1312 // ----------------------------------------------------------------------------
1313 void marAxis::calculateReferenceArea(kVolume* vol){
1314 _referenceArea = getAverageArea(_healthySliceStart,_healthySliceEnd, vol);
1316 // ----------------------------------------------------------------------------
1317 double marAxis::getReferenceArea(kVolume* vol){
1318 if (_referenceArea==-1){
1319 calculateReferenceArea(vol);
1321 return _referenceArea;
1323 // ----------------------------------------------------------------------------
1324 void marAxis::calculateReferenceAverDiam(kVolume* vol){
1325 marContour *marcontourHealthy;
1328 for (ihealthySlice=_healthySliceStart; ihealthySlice<=_healthySliceEnd; ihealthySlice++){
1329 marcontourHealthy = getContour( ihealthySlice , vol );
1330 acumDiam = acumDiam + marcontourHealthy->getAverageDiameter();
1332 _referenceAverDiam = acumDiam / (_healthySliceEnd-_healthySliceStart+1);
1334 // ----------------------------------------------------------------------------
1335 double marAxis::getReferenceAverDiam(kVolume* vol){
1336 if (_referenceAverDiam==-1){
1337 calculateReferenceAverDiam(vol);
1339 return _referenceAverDiam;
1342 // ----------------------------------------------------------------------------
1343 void marAxis::reset( )
1355 _subAxisLenght = -1;
1356 _referenceArea = -1;
1357 _referenceAverDiam = -1;
1363 for( i = 0; i < _contours.size( ); i++ )
1364 delete _contours[ i ];
1366 for( i = 0; i < _slices.size( ); i++ )
1367 delete _slices[ i ];
1372 // ----------------------------------------------------------------------------
1373 void marAxis::copyFrom( const marObject& from )
1377 // ----------------------------------------------------------------------------
1378 bool marAxis::save( std::ofstream& os )
1380 double p[ INDX_count ];
1383 i = _description.length( );
1384 os.write( ( const char* )&i, sizeof( int ) );
1385 os.write( ( char* )_description.c_str( ), i * sizeof( char ) );
1387 i = getNumberOfControlPoints( );
1388 os.write( ( const char* )&i, sizeof( int ) );
1389 for( i = 0; i < getNumberOfControlPoints( ); i++ ) {
1391 memcpy( p, _controlPoints[ i ], 3 * sizeof( double ) );
1392 memcpy( p + 3, _controlState[ i ],
1393 ( INDX_count - 3 ) * sizeof( double ) );
1394 os.write( ( const char* )p, INDX_count * sizeof( double ) );
1397 i = getNumberOfContours( );
1398 os.write( ( const char* )&i, sizeof( int ) );
1399 for( i = 0; i < getNumberOfContours( ); i++ )
1400 _contours[ i ]->save( os );
1405 // ----------------------------------------------------------------------------
1406 bool marAxis::load( std::ifstream& is )
1408 double p[ INDX_count ];
1413 is.read( ( char* )&n, sizeof( int ) );
1414 _description.resize( n );
1415 is.read( ( char* )_description.c_str( ), n * sizeof( char ) );
1417 is.read( ( char* )&n, sizeof( int ) );
1418 for( i = 0; i < n; i++ ) {
1420 is.read( ( char* )p, INDX_count * sizeof( double ) );
1421 addControlPoint( p, p + 3 );
1424 is.read( ( char* )&n, sizeof( int ) );
1425 for( i = 0; i < n; i++ ) {
1427 _contours.push_back( new marContour( 0, getParameters( ) ) );
1428 _contours[ i ]->load( is );
1433 // ----------------------------------------------------------------------------
1434 vtkPolyData* marAxis::Draw( )
1439 vtkPoints* allPoints = vtkPoints::New( );
1440 vtkCellArray* allTopology = vtkCellArray::New( );
1442 allTopology->InsertNextCell( _points.size( ) );
1443 for( i = 0, j=0; i < _points.size( ); i++, j++ ) {
1445 allPoints->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
1446 allTopology->InsertCellPoint( j );
1449 _allData = vtkPolyData::New( );
1450 _allData->SetPoints( allPoints );
1451 _allData->SetLines( allTopology );
1452 allPoints->Delete();
1453 allTopology->Delete();
1455 return ( _allData );
1457 // ----------------------------------------------------------------------------
1458 vtkPolyData *marAxis::GetAxisData( )
1463 double p[marAxis::INDX_count];
1466 vtkPoints *allPoints = vtkPoints::New( );
1467 vtkCellArray *allTopology = vtkCellArray::New( );
1468 vtkDoubleArray *allRadios = vtkDoubleArray::New( );
1469 allRadios->SetName("radio");
1471 for( i = 0; i < _controlPoints.size( ); i++ ) {
1472 getControlPoint(i, p, p+3);
1473 point[ 0 ] = p[marAxis::INDX_X];
1474 point[ 1 ] = p[marAxis::INDX_Y];
1475 point[ 2 ] = p[marAxis::INDX_Z];
1476 radio = p[marAxis::INDX_RAYON]*2.0;
1477 allPoints -> InsertPoint( i, point[ 0 ] , point[ 1 ] , point[ 2 ] ); //para saber exactamante el indice que se le asigno
1479 allRadios -> InsertValue(i,radio);
1482 allTopology->InsertNextCell(2);
1483 allTopology->InsertCellPoint(i);
1484 allTopology->InsertCellPoint(i-1);
1489 _allData = vtkPolyData::New( );
1490 _allData -> SetPoints( allPoints );
1491 _allData -> SetLines( allTopology );
1492 _allData -> GetPointData()->SetScalars(allRadios);
1495 return ( _allData );
1497 // ----------------------------------------------------------------------------
1498 void marAxis::Delete( ){
1502 for (i=0;i<_points.size();i++){
1503 if (_points[i]!=NULL) {
1519 // ----------------------------------------------------------------------------
1520 void marAxis::setHealthySlice( int hsS, int hs, int hsE ){
1521 _healthySliceStart = hsS;
1523 _healthySliceEnd = hsE;
1525 _referenceAverDiam=-1;
1527 // ----------------------------------------------------------------------------
1528 void marAxis::setStartQuant( int sq ){
1530 _subAxisLenght = -1;
1532 // ----------------------------------------------------------------------------
1533 void marAxis::setFinishQuant( int fq ){
1535 _subAxisLenght = -1;
1538 // ----------------------------------------------------------------------------
1539 void marAxis::AddPointToList(double x, double y, double z, int signal)
1542 p=(double *)malloc(sizeof(double)*3);
1546 _points.push_back( p );
1547 _signal.push_back( signal );