1 /*=========================================================================
4 Module: $RCSfile: marExperiment.cpp,v $
6 Date: $Date: 2010/04/20 16:11:41 $
7 Version: $Revision: 1.2 $
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 =========================================================================*/
19 #include "marExperiment.h"
20 #include "FonctionsGrales.h"
21 #include "ExtractionAxe.h"
23 // ----------------------------------------------------------------------------
24 marExperiment::marExperiment( marParameters* p ) : marObject( p ),
25 _dynData( NULL ), _description( _T("NO DESCRIPTION") )
27 _voi[ 0 ] = _voi[ 1 ] = _voi[ 2 ] = 0;
28 _voi[ 3 ] = _voi[ 4 ] = _voi[ 5 ] = 0;
29 _startPoint[ 0 ] = _startPoint[ 1 ] = _startPoint[ 2 ] = 0;
30 _axes.push_back( NULL );
34 marExperiment::~marExperiment( ) {
38 // ----------------------------------------------------------------------------
39 void marExperiment::initExperiment( kVolume* volume )
43 _dynData = new marDynData( getParameters( ) );
45 _dynData->loadData( volume, _voi );
49 _dynData->loadData( volume, _voi );
51 _dynData->loadDataDXMM( volume, _voi );
57 // ----------------------------------------------------------------------------
58 void marExperiment::setStartPoint( int sx, int sy, int sz )
61 // _startPoint[ 0 ] = ( int )( ( double )sx * getParameters( )->getVoxelSize( ) );
62 // _startPoint[ 1 ] = ( int )( ( double )sy * getParameters( )->getVoxelSize( ) );
63 // _startPoint[ 2 ] = ( int )( ( double )sz * getParameters( )->getVoxelSize( ) );
65 _startPoint[ 0 ] = sx;
66 _startPoint[ 1 ] = sy;
67 _startPoint[ 2 ] = sz;
71 // ----------------------------------------------------------------------------
72 void marExperiment::extractVascularTree( int sens , double *vit, int cleanLevel)
78 #ifdef __LFV__GET__VASCULAR__TREE__
79 PPPOINTAXE pts = NULL;
80 PARBREVASCULAIRE res = NULL;
82 PPPOINTAXE res = NULL;
83 double pt[ marAxis::INDX_count ];
90 ( PPPVOLUME_USHORT )( _dynData->getVolume( )->castIdo( ) ),
92 _dynData->getVolume( )->getXdim( ) - 1,
93 _dynData->getVolume( )->getYdim( ) - 1,
94 _dynData->getVolume( )->getZdim( ) - 1,
95 ( double )( getParameters( )->getIntParam( marParameters::e_roi_dimension ) ),
96 ( double )( getParameters( )->getIntParam( marParameters::e_step ) ),
97 getParameters( )->getDoubleParam( marParameters::e_gravity_distance ),
98 getParameters( )->getDoubleParam( marParameters::e_distance_to_maximum_intensity ),
99 getParameters( )->getDoubleParam( marParameters::e_flexion_coeficient ),
100 getParameters( )->getDoubleParam( marParameters::e_tension_coeficient ),
101 getParameters( )->getIntParam( marParameters::e_mass_power ),
102 #ifdef __LFV__GET__VASCULAR__TREE__
110 #ifdef __LFV__GET__VASCULAR__TREE__
111 for( n = 0; n < res->nomAxes; n++ ) {
112 tmp = new marAxis( getParameters( ) );
113 tmp->set_points_disc( res->lstAxes[ n ] );
114 for( i = 0; i < res->lstAxes[ n ]->nomPoints; i++ )
115 tmp->AddAxisPoint( *( res->lstAxes[ n ]->lstPoints[ i ] ) );
117 tmp->calculateSignal( _dynData->getVolume( ) );
118 _axes.push_back( tmp );
123 double voxSize = this->getParameters( )->getVoxelSize( );
124 tmpAxis = new marAxis( this->getParameters( ) );
125 std::string desc = "Axis N.";
126 desc += _axes.size( );
127 tmpAxis->setDescription( desc );
128 tmpAxis->set_points_disc( res );
129 for( i = 0; i < n; i++ ) {
130 memcpy( pt, res[ i ], sizeof( POINTAXE ) );
134 tmpAxis->addAxisPoint( pt );
136 tmpAxis->doSpline( );
137 tmpAxis->calculateSignal( _dynData->getVolume( ) );
141 tmpAxis2 = new marAxis( this->getParameters( ) );
142 tmpAxis2->setDescription( desc );
143 tmpAxis2->set_points_disc( res );
144 for( i = 0; i < n; i++ ) {
145 if (tmpAxis->getSignal(i)>=cleanLevel ){
147 memcpy( pt, res[ i ], sizeof( POINTAXE ) );
151 tmpAxis2->addAxisPoint( pt );
159 tmpAxis2->doSpline( );
160 tmpAxis2->calculateSignal( _dynData->getVolume( ) );
161 _axes.push_back( tmpAxis2 );
162 _axes[ 0 ] = tmpAxis2;
167 #endif // __LFV__GET__VASCULAR__TREE__
172 //marContour* marExperiment::generateContour( int slice, int x, int y, std::vector< double* >* points)
173 vtkPolyData* marExperiment::generateContour( int slice, int x, int y, std::vector< double* >* points)
175 /* vtkImageData* imagedata;
177 imagedata = getSliceImage( slice );
178 vtkKitwareContourFilter* cntVTK = vtkKitwareContourFilter::New( );
179 cntVTK->SetInput( imagedata );
180 cntVTK->SetNumberOfContours( 1 );
181 //cntVTK->SetValue( 0, vmin );
182 cntVTK->SetValue( 0, 20 );
183 //cntVTK->SetValue( 1, vmax );
188 // return(_axes[ 0 ]->setContour( slice, x, y, points));
192 //return( _axes[ 0 ]->getContour( slice ) );
196 // ----------------------------------------------------------------------------
197 void marExperiment::applyChangeResolution( )
201 for( i = 1; i < _axes.size( ); i++ )
202 _axes[ i ]->changeAxisResolution( );
205 // ----------------------------------------------------------------------------
206 void marExperiment::prepareQuantification( )
210 // _axes[0]->sliceVolumeAxis( _dynData->getVolume( ), true);
213 _axes[ 0 ]->createEmptyVectors();
217 // ----------------------------------------------------------------------------
218 void marExperiment::backQuant( )
220 //Cette méthode n'existe plus: dommage
221 // if ( _axes[0]->getQuantOn() )
223 _axes[0]->setFinishQuant( _axes[0]->getFinishQuant() - 1);
224 if ( _axes[0]->getFinishQuant() < 0 )
225 _axes[0]->setFinishQuant(0);
230 // ----------------------------------------------------------------------------
231 void marExperiment::reset( )
235 _description = _T("");
236 if( _dynData != NULL ) delete _dynData;
241 for( i = 1; i < _axes.size( ); i++ ){
242 if (_axes[ i ]!=NULL) delete _axes[ i ];
246 _axes.push_back( NULL );
247 // PS -> // PS Et les images ???? _quantificationImages
250 // ----------------------------------------------------------------------------
251 void marExperiment::calculateAxesSignal( )
254 for( i = 1; i < _axes.size( ); i++ )
255 _axes[ i ]->calculateSignal( _dynData->getVolume( ) );
258 // ----------------------------------------------------------------------------
259 void marExperiment::prepareContourImages( )
262 _axes[ 0 ]->sliceVolumeAxis( _dynData->getVolume( ) );
265 // ----------------------------------------------------------------------------
266 void marExperiment::copyFrom( const marObject& from )
270 // ----------------------------------------------------------------------------
271 bool marExperiment::save( std::ofstream& os )
276 st = _description.length( );
277 os.write( ( const char* )&st, sizeof( size_t ) );
278 os.write( ( const char* )_description.c_str( ), sizeof( char ) * st );
279 os.write( ( const char* )_startPoint, 3 * sizeof( int ) );
280 os.write( ( const char* )_voi, 6 * sizeof( int ) );
281 _dynData->save( os );
282 i = _axes.size( ) - 1;
283 os.write( ( const char* )&i, sizeof( int ) );
284 for( i = 1; i < _axes.size( ); i++ )
285 _axes[ i ]->save( os );
289 // ----------------------------------------------------------------------------
290 bool marExperiment::load( std::ifstream& is )
300 is.read( ( char* )&st, sizeof( size_t ) );
301 is.read( ( char* )ttmp, sizeof( char ) * st );
305 // _description = ttmp;
306 _description = wxString(ttmp, wxConvUTF8);
308 is.read( ( char* )_startPoint, 3 * sizeof( int ) );
309 is.read( ( char* )_voi, 6 * sizeof( int ) );
311 _dynData = new marDynData( getParameters( ) );
312 _dynData->load( is );
314 is.read( ( char* )&n, sizeof( int ) );
315 for( i = 1; i <= n; i++ ) {
316 ax = new marAxis( getParameters( ) );
318 _axes.push_back( ax );
324 // ----------------------------------------------------------------------------
325 void marExperiment::DeleteAxis( unsigned int index )
327 /* Very naughty bug, when doing a - 1, where a is uint32_t result is still
328 uint32_t, imaging when a=0 :) need to cast to int*/
330 int axesize=_axes.size( )-1;
332 delete _axes[ index ];
333 for( int i = index; i < axesize; i++ )
334 _axes[ i ] = _axes[ i + 1 ];
338 _axes[ 0 ]=_axes[ index ];
344 _axes[index]->Delete();
346 _axes[ 0 ]->Delete( );
347 _axes.erase(_axes.begin() + index);
350 // PS -> // PS : traitement identique à la methode std::vector::erase(iterator)
353 _axes[ 0 ]->Delete( );
354 delete _axes[ index ];
357 // ----------------------------------------------------------------------------
358 void marExperiment::RegenerateSignal(){
359 marAxis *maraxis = getAxis();
361 maraxis->calculateSignal( _dynData->getVolume( ) );
362 maraxis->eraseContourVectorsContent();
365 // ----------------------------------------------------------------------------
366 void marExperiment::ClearContours(){
367 marAxis *maraxis = getAxis();
368 if (maraxis!=NULL) maraxis->eraseContourVectorsContent();
370 // ----------------------------------------------------------------------------
371 void marExperiment::RegenerateAxis(){
372 if (getAxis()!=NULL){
373 int actualquant=getAxis()->getActualQuant();
375 extractVascularTree();
377 getAxis()->setActualQuant(actualquant);
378 getAxis()->createEmptyVectors();
381 // ----------------------------------------------------------------------------
382 void marExperiment::RecalculateAxis(){
383 marAxis *maraxis = getAxis();
386 int nCnts = ( int ) maraxis->getNumberOfSplinePoints( );
387 getAxis()->setActualQuant(nCnts/2);
388 getAxis()->createEmptyVectors();
392 // eof - experiment.cxx