marExperiment.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   wxMaracas
00004   Module:    $RCSfile: marExperiment.cpp,v $
00005   Language:  C++
00006   Date:      $Date: 2009/05/14 13:55:07 $
00007   Version:   $Revision: 1.1 $
00008 
00009   Copyright: (c) 2002, 2003
00010   License:
00011   
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notice for more information.
00015 
00016 =========================================================================*/
00017 
00018 //#include "matrix.h"
00019 #include "marExperiment.h"
00020 #include "FonctionsGrales.h"
00021 #include "ExtractionAxe.h"
00022 
00023 // ----------------------------------------------------------------------------
00024 marExperiment::marExperiment( marParameters* p ) : marObject( p ),
00025                               _dynData( NULL ), _description( _T("NO DESCRIPTION") )
00026 {
00027   _voi[ 0 ] = _voi[ 1 ] = _voi[ 2 ] = 0;
00028   _voi[ 3 ] = _voi[ 4 ] = _voi[ 5 ] = 0;
00029   _startPoint[ 0 ] = _startPoint[ 1 ] = _startPoint[ 2 ] = 0;
00030   _axes.push_back( NULL );
00031 
00032 }
00033 
00034 marExperiment::~marExperiment( ) { 
00035         reset( ); 
00036 }
00037 
00038 // ----------------------------------------------------------------------------
00039 void marExperiment::initExperiment( kVolume* volume )
00040 {
00041   {
00042     reset( );
00043     _dynData = new marDynData( getParameters( ) );
00044 
00045      _dynData->loadData( volume, _voi );
00046 
00047 /* EED Borrame
00048 #ifndef DXMM
00049      _dynData->loadData( volume, _voi );
00050 #else
00051     _dynData->loadDataDXMM( volume, _voi );
00052 #endif
00053 */
00054   }
00055 }
00056 
00057 // ----------------------------------------------------------------------------
00058 void marExperiment::setStartPoint( int sx, int sy, int sz )
00059 {
00060 // EED 22 sep 2006
00061 //  _startPoint[ 0 ] = ( int )( ( double )sx * getParameters( )->getVoxelSize( ) );
00062 //  _startPoint[ 1 ] = ( int )( ( double )sy * getParameters( )->getVoxelSize( ) );
00063 //  _startPoint[ 2 ] = ( int )( ( double )sz * getParameters( )->getVoxelSize( ) );
00064 
00065   _startPoint[ 0 ] = sx;
00066   _startPoint[ 1 ] = sy;
00067   _startPoint[ 2 ] = sz;
00068 
00069 }
00070 
00071 // ----------------------------------------------------------------------------
00072 void marExperiment::extractVascularTree( int sens , double *vit, int cleanLevel)
00073 {
00074 
00075   marAxis* tmpAxis;
00076   marAxis* tmpAxis2;
00077 
00078 #ifdef __LFV__GET__VASCULAR__TREE__
00079     PPPOINTAXE pts = NULL;
00080     PARBREVASCULAIRE res = NULL;
00081 #else
00082     PPPOINTAXE res = NULL;
00083     double pt[ marAxis::INDX_count ];
00084 #endif
00085     int n, i;
00086     res = ExtraireArbre(
00087       _startPoint[ 0 ],
00088       _startPoint[ 1 ],
00089       _startPoint[ 2 ],
00090       ( PPPVOLUME_USHORT )( _dynData->getVolume( )->castIdo( ) ),
00091       1, 1, 1,
00092       _dynData->getVolume( )->getXdim( ) - 1,
00093       _dynData->getVolume( )->getYdim( ) - 1,
00094       _dynData->getVolume( )->getZdim( ) - 1,
00095       ( double )( getParameters( )->getIntParam( marParameters::e_roi_dimension ) ),
00096       ( double )( getParameters( )->getIntParam( marParameters::e_step ) ),
00097       getParameters( )->getDoubleParam( marParameters::e_gravity_distance ),
00098       getParameters( )->getDoubleParam( marParameters::e_distance_to_maximum_intensity ),
00099       getParameters( )->getDoubleParam( marParameters::e_flexion_coeficient ),
00100       getParameters( )->getDoubleParam( marParameters::e_tension_coeficient ),
00101       getParameters( )->getIntParam( marParameters::e_mass_power ),
00102 #ifdef __LFV__GET__VASCULAR__TREE__
00103       pts,
00104 #else
00105       res,
00106 #endif
00107       &n , sens , vit);
00108 
00109     // Data treatment
00110 #ifdef __LFV__GET__VASCULAR__TREE__
00111     for( n = 0; n < res->nomAxes; n++ ) {
00112       tmp = new marAxis( getParameters( ) );
00113       tmp->set_points_disc( res->lstAxes[ n ] );
00114       for( i = 0; i < res->lstAxes[ n ]->nomPoints; i++ )
00115         tmp->AddAxisPoint( *( res->lstAxes[ n ]->lstPoints[ i ] ) );
00116       tmp->doSpline( );
00117       tmp->calculateSignal( _dynData->getVolume( ) );
00118       _axes.push_back( tmp );
00119     } // rof
00120 #else
00121         if (n>2){
00122                 //
00123                 double voxSize = this->getParameters( )->getVoxelSize( );
00124                 tmpAxis = new marAxis( this->getParameters( ) );
00125                 std::string desc = "Axis N.";
00126                 desc += _axes.size( );
00127                 tmpAxis->setDescription( desc );
00128                 tmpAxis->set_points_disc( res );
00129                 for( i = 0; i < n; i++ ) {
00130                         memcpy( pt, res[ i ], sizeof( POINTAXE ) );
00131                         pt[ 0 ] *= voxSize;
00132                         pt[ 1 ] *= voxSize;
00133                         pt[ 2 ] *= voxSize;
00134                         tmpAxis->addAxisPoint( pt );
00135                 }        // rof
00136                 tmpAxis->doSpline( );
00137                 tmpAxis->calculateSignal( _dynData->getVolume( ) );
00138 
00139                 //
00140                 int jCount=0;
00141                 tmpAxis2 = new marAxis( this->getParameters( ) );
00142                 tmpAxis2->setDescription( desc );
00143                 tmpAxis2->set_points_disc( res );       
00144                 for( i = 0; i < n; i++ ) {
00145                         if (tmpAxis->getSignal(i)>=cleanLevel ){
00146                                 jCount++;
00147                                 memcpy( pt, res[ i ], sizeof( POINTAXE ) );
00148                                 pt[ 0 ] *= voxSize;
00149                                 pt[ 1 ] *= voxSize;
00150                                 pt[ 2 ] *= voxSize;
00151                                 tmpAxis2->addAxisPoint( pt );
00152                         } else {
00153                                 i=n;
00154                         }
00155                 } // for 
00156                 delete tmpAxis;
00157 
00158                 if (jCount>2){
00159                         tmpAxis2->doSpline( );
00160                         tmpAxis2->calculateSignal( _dynData->getVolume( ) );
00161                         _axes.push_back( tmpAxis2 );
00162                         _axes[ 0 ] = tmpAxis2;
00163                 } else {
00164                         delete tmpAxis2;
00165                 }
00166     }
00167 #endif // __LFV__GET__VASCULAR__TREE__
00168 
00169 }
00170 
00171 
00172 //marContour* marExperiment::generateContour( int slice, int x, int y, std::vector< double* >* points) 
00173 vtkPolyData* marExperiment::generateContour( int slice, int x, int y, std::vector< double* >* points)
00174 {
00175 /*  vtkImageData* imagedata;
00176 
00177   imagedata = getSliceImage( slice );
00178   vtkKitwareContourFilter* cntVTK = vtkKitwareContourFilter::New( );
00179   cntVTK->SetInput( imagedata );
00180   cntVTK->SetNumberOfContours( 1 );
00181   //cntVTK->SetValue( 0, vmin );
00182   cntVTK->SetValue( 0, 20 );
00183   //cntVTK->SetValue( 1, vmax );
00184   cntVTK->Update( );
00185 
00186     return cntVTK;*/
00187 
00188 //  return(_axes[ 0 ]->setContour( slice, x, y, points));
00189 
00190         return NULL;
00191         
00192   //return( _axes[ 0 ]->getContour( slice ) );
00193 }
00194 
00195 
00196 // ----------------------------------------------------------------------------
00197 void marExperiment::applyChangeResolution( )
00198 {
00199   int i;
00200 
00201   for( i = 1; i < _axes.size( ); i++ )
00202     _axes[ i ]->changeAxisResolution( );
00203 }
00204 
00205 // ----------------------------------------------------------------------------
00206 void marExperiment::prepareQuantification( )
00207 {
00208 
00209 // EED borrame
00210 //  _axes[0]->sliceVolumeAxis( _dynData->getVolume( ), true);
00211 
00212   if( _axes[ 0 ] )
00213     _axes[ 0 ]->createEmptyVectors();
00214 
00215 }
00216 
00217 // ----------------------------------------------------------------------------
00218 void marExperiment::backQuant( )
00219 {
00220 //Cette méthode n'existe plus: dommage 
00221 //    if ( _axes[0]->getQuantOn() )
00222   {
00223     _axes[0]->setFinishQuant( _axes[0]->getFinishQuant() - 1);
00224     if ( _axes[0]->getFinishQuant() < 0 )
00225       _axes[0]->setFinishQuant(0);
00226   }
00227 }
00228 
00229 
00230 // ----------------------------------------------------------------------------
00231 void marExperiment::reset( )
00232 {
00233   int i;
00234 
00235   _description = _T("");
00236   if( _dynData != NULL ) delete _dynData;
00237     
00238  
00239   _dynData = NULL;
00240 
00241   for( i = 1; i < _axes.size( ); i++ ){
00242     if (_axes[ i ]!=NULL) delete _axes[ i ];
00243   }
00244 
00245   _axes.clear( );
00246   _axes.push_back( NULL );
00247 // PS ->   // PS Et les images ???? _quantificationImages
00248 }
00249 
00250 // ----------------------------------------------------------------------------
00251 void marExperiment::calculateAxesSignal( )
00252 {
00253   int i;
00254   for( i = 1; i < _axes.size( ); i++ )
00255     _axes[ i ]->calculateSignal( _dynData->getVolume( ) );
00256 }
00257 
00258 // ----------------------------------------------------------------------------
00259 void marExperiment::prepareContourImages( )
00260 {
00261   if( _axes[ 0 ] )
00262     _axes[ 0 ]->sliceVolumeAxis( _dynData->getVolume( ) );
00263 }
00264 
00265 // ----------------------------------------------------------------------------
00266 void marExperiment::copyFrom( const marObject& from )
00267 { // TODO
00268 }
00269 
00270 // ----------------------------------------------------------------------------
00271 bool marExperiment::save( std::ofstream& os )
00272 {
00273   int i;
00274   size_t st;
00275 
00276   st = _description.length( );
00277   os.write( ( const char* )&st, sizeof( size_t ) );
00278   os.write( ( const char* )_description.c_str( ), sizeof( char ) * st );
00279   os.write( ( const char* )_startPoint, 3 * sizeof( int ) );
00280   os.write( ( const char* )_voi, 6 * sizeof( int ) );
00281   _dynData->save( os );
00282   i = _axes.size( ) - 1;
00283   os.write( ( const char* )&i, sizeof( int ) );
00284   for( i = 1; i < _axes.size( ); i++ )
00285     _axes[ i ]->save( os );
00286   return( true );
00287 }
00288 
00289 // ----------------------------------------------------------------------------
00290 bool marExperiment::load(  std::ifstream& is )
00291 {
00292 
00293   int i, n;
00294   char ttmp[ 5000 ];
00295   size_t st;
00296   marAxis* ax;
00297 
00298   reset( );
00299 
00300   is.read( ( char* )&st, sizeof( size_t ) );
00301   is.read( ( char* )ttmp, sizeof( char ) * st );
00302   ttmp[ st ] = '\0';
00303 
00304 // EED 05 join 2007
00305 // _description  = ttmp;
00306   _description   = wxString(ttmp, wxConvUTF8);
00307 
00308   is.read( ( char* )_startPoint, 3 * sizeof( int ) );
00309   is.read( ( char* )_voi, 6 * sizeof( int ) );
00310 
00311   _dynData = new marDynData( getParameters( ) );
00312   _dynData->load( is );
00313 
00314   is.read( ( char* )&n, sizeof( int ) );
00315   for( i = 1; i <= n; i++ ) {
00316     ax = new marAxis( getParameters( ) );
00317     ax->load( is );
00318     _axes.push_back( ax );
00319     _axes[ 0 ] = ax;
00320   } // rof
00321   return( true );
00322 }
00323 
00324 // ----------------------------------------------------------------------------
00325 void marExperiment::DeleteAxis( unsigned int index )
00326 {
00327         /* Very naughty bug, when doing a - 1, where a is uint result is still
00328         uint, imaging when a=0 :) need to cast to int*/
00329   
00330   int axesize=_axes.size( )-1;
00331   index=index+1;
00332   delete _axes[ index ];
00333   for( int i = index; i < axesize; i++ ) 
00334      _axes[ i ] = _axes[ i + 1 ];
00335   _axes.pop_back( );
00336 
00337   if (index<axesize) {
00338         _axes[ 0 ]=_axes[ index ];
00339   } else {
00340         _axes[ 0 ]=NULL;
00341   }
00342 
00343 /*  
00344   _axes[index]->Delete();
00345   if(_axes[ 0 ]) 
00346           _axes[ 0 ]->Delete( );
00347   _axes.erase(_axes.begin() + index);
00348 */
00349 
00350 // PS ->   // PS : traitement identique à la methode std::vector::erase(iterator)
00351 /*
00352   if(_axes[ 0 ]) 
00353           _axes[ 0 ]->Delete( );
00354   delete _axes[ index ];
00355 */
00356 }
00357 // ----------------------------------------------------------------------------
00358 void marExperiment::RegenerateSignal(){
00359         marAxis *maraxis = getAxis(); 
00360         if (maraxis!=NULL) {
00361                 maraxis->calculateSignal( _dynData->getVolume( ) );
00362                 maraxis->eraseContourVectorsContent();                   
00363         }
00364 }
00365 // ----------------------------------------------------------------------------
00366 void marExperiment::ClearContours(){
00367         marAxis *maraxis = getAxis(); 
00368         if (maraxis!=NULL) maraxis->eraseContourVectorsContent();                        
00369 }
00370 // ----------------------------------------------------------------------------
00371 void marExperiment::RegenerateAxis(){
00372         if (getAxis()!=NULL){
00373                 int actualquant=getAxis()->getActualQuant();
00374                 DeleteAxis(0);                  
00375                 extractVascularTree();
00376                 setAxis(0);     
00377                 getAxis()->setActualQuant(actualquant);
00378                 getAxis()->createEmptyVectors();                         
00379         }
00380 }
00381 // ----------------------------------------------------------------------------
00382 void marExperiment::RecalculateAxis(){
00383         marAxis *maraxis = getAxis(); 
00384         if (maraxis!=NULL){
00385                 maraxis->doSpline();     
00386                 int nCnts = ( int ) maraxis->getNumberOfSplinePoints( );
00387                 getAxis()->setActualQuant(nCnts/2);
00388                 getAxis()->createEmptyVectors();                         
00389         }
00390 }
00391 
00392 // eof - experiment.cxx

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1