1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: marExperiment.cpp,v $
31 Date: $Date: 2012/11/15 14:15:31 $
32 Version: $Revision: 1.3 $
34 Copyright: (c) 2002, 2003
37 This software is distributed WITHOUT ANY WARRANTY; without even
38 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39 PURPOSE. See the above copyright notice for more information.
41 =========================================================================*/
44 #include "marExperiment.h"
45 #include "FonctionsGrales.h"
46 #include "ExtractionAxe.h"
48 // ----------------------------------------------------------------------------
49 marExperiment::marExperiment( marParameters* p ) : marObject( p ),
50 _dynData( NULL ), _description( _T("NO DESCRIPTION") )
52 _voi[ 0 ] = _voi[ 1 ] = _voi[ 2 ] = 0;
53 _voi[ 3 ] = _voi[ 4 ] = _voi[ 5 ] = 0;
54 _startPoint[ 0 ] = _startPoint[ 1 ] = _startPoint[ 2 ] = 0;
55 _axes.push_back( NULL );
59 marExperiment::~marExperiment( ) {
63 // ----------------------------------------------------------------------------
64 void marExperiment::initExperiment( kVolume* volume )
68 _dynData = new marDynData( getParameters( ) );
70 _dynData->loadData( volume, _voi );
74 _dynData->loadData( volume, _voi );
76 _dynData->loadDataDXMM( volume, _voi );
82 // ----------------------------------------------------------------------------
83 void marExperiment::setStartPoint( int sx, int sy, int sz )
86 // _startPoint[ 0 ] = ( int )( ( double )sx * getParameters( )->getVoxelSize( ) );
87 // _startPoint[ 1 ] = ( int )( ( double )sy * getParameters( )->getVoxelSize( ) );
88 // _startPoint[ 2 ] = ( int )( ( double )sz * getParameters( )->getVoxelSize( ) );
90 _startPoint[ 0 ] = sx;
91 _startPoint[ 1 ] = sy;
92 _startPoint[ 2 ] = sz;
96 // ----------------------------------------------------------------------------
97 void marExperiment::extractVascularTree( int sens , double *vit, int cleanLevel)
103 #ifdef __LFV__GET__VASCULAR__TREE__
104 PPPOINTAXE pts = NULL;
105 PARBREVASCULAIRE res = NULL;
107 PPPOINTAXE res = NULL;
108 double pt[ marAxis::INDX_count ];
115 ( PPPVOLUME_USHORT )( _dynData->getVolume( )->castIdo( ) ),
117 _dynData->getVolume( )->getXdim( ) - 1,
118 _dynData->getVolume( )->getYdim( ) - 1,
119 _dynData->getVolume( )->getZdim( ) - 1,
120 ( double )( getParameters( )->getIntParam( marParameters::e_roi_dimension ) ),
121 ( double )( getParameters( )->getIntParam( marParameters::e_step ) ),
122 getParameters( )->getDoubleParam( marParameters::e_gravity_distance ),
123 getParameters( )->getDoubleParam( marParameters::e_distance_to_maximum_intensity ),
124 getParameters( )->getDoubleParam( marParameters::e_flexion_coeficient ),
125 getParameters( )->getDoubleParam( marParameters::e_tension_coeficient ),
126 getParameters( )->getIntParam( marParameters::e_mass_power ),
127 #ifdef __LFV__GET__VASCULAR__TREE__
135 #ifdef __LFV__GET__VASCULAR__TREE__
136 for( n = 0; n < res->nomAxes; n++ ) {
137 tmp = new marAxis( getParameters( ) );
138 tmp->set_points_disc( res->lstAxes[ n ] );
139 for( i = 0; i < res->lstAxes[ n ]->nomPoints; i++ )
140 tmp->AddAxisPoint( *( res->lstAxes[ n ]->lstPoints[ i ] ) );
142 tmp->calculateSignal( _dynData->getVolume( ) );
143 _axes.push_back( tmp );
148 double voxSize = this->getParameters( )->getVoxelSize( );
149 tmpAxis = new marAxis( this->getParameters( ) );
150 std::string desc = "Axis N.";
151 desc += _axes.size( );
152 tmpAxis->setDescription( desc );
153 tmpAxis->set_points_disc( res );
154 for( i = 0; i < n; i++ ) {
155 memcpy( pt, res[ i ], sizeof( POINTAXE ) );
159 tmpAxis->addAxisPoint( pt );
161 tmpAxis->doSpline( );
162 tmpAxis->calculateSignal( _dynData->getVolume( ) );
166 tmpAxis2 = new marAxis( this->getParameters( ) );
167 tmpAxis2->setDescription( desc );
168 tmpAxis2->set_points_disc( res );
169 for( i = 0; i < n; i++ ) {
170 if (tmpAxis->getSignal(i)>=cleanLevel ){
172 memcpy( pt, res[ i ], sizeof( POINTAXE ) );
176 tmpAxis2->addAxisPoint( pt );
184 tmpAxis2->doSpline( );
185 tmpAxis2->calculateSignal( _dynData->getVolume( ) );
186 _axes.push_back( tmpAxis2 );
187 _axes[ 0 ] = tmpAxis2;
192 #endif // __LFV__GET__VASCULAR__TREE__
197 //marContour* marExperiment::generateContour( int slice, int x, int y, std::vector< double* >* points)
198 vtkPolyData* marExperiment::generateContour( int slice, int x, int y, std::vector< double* >* points)
200 /* vtkImageData* imagedata;
202 imagedata = getSliceImage( slice );
203 vtkKitwareContourFilter* cntVTK = vtkKitwareContourFilter::New( );
204 cntVTK->SetInput( imagedata );
205 cntVTK->SetNumberOfContours( 1 );
206 //cntVTK->SetValue( 0, vmin );
207 cntVTK->SetValue( 0, 20 );
208 //cntVTK->SetValue( 1, vmax );
213 // return(_axes[ 0 ]->setContour( slice, x, y, points));
217 //return( _axes[ 0 ]->getContour( slice ) );
221 // ----------------------------------------------------------------------------
222 void marExperiment::applyChangeResolution( )
226 for( i = 1; i < _axes.size( ); i++ )
227 _axes[ i ]->changeAxisResolution( );
230 // ----------------------------------------------------------------------------
231 void marExperiment::prepareQuantification( )
235 // _axes[0]->sliceVolumeAxis( _dynData->getVolume( ), true);
238 _axes[ 0 ]->createEmptyVectors();
242 // ----------------------------------------------------------------------------
243 void marExperiment::backQuant( )
245 //Cette m�thode n'existe plus: dommage
246 // if ( _axes[0]->getQuantOn() )
248 _axes[0]->setFinishQuant( _axes[0]->getFinishQuant() - 1);
249 if ( _axes[0]->getFinishQuant() < 0 )
250 _axes[0]->setFinishQuant(0);
255 // ----------------------------------------------------------------------------
256 void marExperiment::reset( )
260 _description = _T("");
261 if( _dynData != NULL ) delete _dynData;
266 for( i = 1; i < _axes.size( ); i++ ){
267 if (_axes[ i ]!=NULL) delete _axes[ i ];
271 _axes.push_back( NULL );
272 // PS -> // PS Et les images ???? _quantificationImages
275 // ----------------------------------------------------------------------------
276 void marExperiment::calculateAxesSignal( )
279 for( i = 1; i < _axes.size( ); i++ )
280 _axes[ i ]->calculateSignal( _dynData->getVolume( ) );
283 // ----------------------------------------------------------------------------
284 void marExperiment::prepareContourImages( )
287 _axes[ 0 ]->sliceVolumeAxis( _dynData->getVolume( ) );
290 // ----------------------------------------------------------------------------
291 void marExperiment::copyFrom( const marObject& from )
295 // ----------------------------------------------------------------------------
296 bool marExperiment::save( std::ofstream& os )
301 st = _description.length( );
302 os.write( ( const char* )&st, sizeof( size_t ) );
303 os.write( ( const char* )_description.c_str( ), sizeof( char ) * st );
304 os.write( ( const char* )_startPoint, 3 * sizeof( int ) );
305 os.write( ( const char* )_voi, 6 * sizeof( int ) );
306 _dynData->save( os );
307 i = _axes.size( ) - 1;
308 os.write( ( const char* )&i, sizeof( int ) );
309 for( i = 1; i < _axes.size( ); i++ )
310 _axes[ i ]->save( os );
314 // ----------------------------------------------------------------------------
315 bool marExperiment::load( std::ifstream& is )
325 is.read( ( char* )&st, sizeof( size_t ) );
326 is.read( ( char* )ttmp, sizeof( char ) * st );
330 // _description = ttmp;
331 _description = wxString(ttmp, wxConvUTF8);
333 is.read( ( char* )_startPoint, 3 * sizeof( int ) );
334 is.read( ( char* )_voi, 6 * sizeof( int ) );
336 _dynData = new marDynData( getParameters( ) );
337 _dynData->load( is );
339 is.read( ( char* )&n, sizeof( int ) );
340 for( i = 1; i <= n; i++ ) {
341 ax = new marAxis( getParameters( ) );
343 _axes.push_back( ax );
349 // ----------------------------------------------------------------------------
350 void marExperiment::DeleteAxis( unsigned int index )
352 /* Very naughty bug, when doing a - 1, where a is uint32_t result is still
353 uint32_t, imaging when a=0 :) need to cast to int*/
355 int axesize=_axes.size( )-1;
357 delete _axes[ index ];
358 for( int i = index; i < axesize; i++ )
359 _axes[ i ] = _axes[ i + 1 ];
363 _axes[ 0 ]=_axes[ index ];
369 _axes[index]->Delete();
371 _axes[ 0 ]->Delete( );
372 _axes.erase(_axes.begin() + index);
375 // PS -> // PS : traitement identique � la methode std::vector::erase(iterator)
378 _axes[ 0 ]->Delete( );
379 delete _axes[ index ];
382 // ----------------------------------------------------------------------------
383 void marExperiment::RegenerateSignal(){
384 marAxis *maraxis = getAxis();
386 maraxis->calculateSignal( _dynData->getVolume( ) );
387 maraxis->eraseContourVectorsContent();
390 // ----------------------------------------------------------------------------
391 void marExperiment::ClearContours(){
392 marAxis *maraxis = getAxis();
393 if (maraxis!=NULL) maraxis->eraseContourVectorsContent();
395 // ----------------------------------------------------------------------------
396 void marExperiment::RegenerateAxis(){
397 if (getAxis()!=NULL){
398 int actualquant=getAxis()->getActualQuant();
400 extractVascularTree();
402 getAxis()->setActualQuant(actualquant);
403 getAxis()->createEmptyVectors();
406 // ----------------------------------------------------------------------------
407 void marExperiment::RecalculateAxis(){
408 marAxis *maraxis = getAxis();
411 int nCnts = ( int ) maraxis->getNumberOfSplinePoints( );
412 getAxis()->setActualQuant(nCnts/2);
413 getAxis()->createEmptyVectors();
417 // eof - experiment.cxx