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 #ifndef MAR__INTERFACE__TCL__HXX
27 #define MAR__INTERFACE__TCL__HXX
29 #include "../kernel/marInterface.h"
30 #include <kgfo/volstat.hxx>
34 #include <wx/string.h>
35 #include <vtkCellArray.h>
36 #include <vtkCellLocator.h>
37 #include <vtkImageData.h>
39 #include <vtkPoints.h>
40 #include <vtkPolyData.h>
41 #include <vtkTclUtil.h>
43 // ----------------------------------------------------------------------------
44 static marInterface MyMaracasData;
45 static kVolume* _ucharVol = NULL;
47 // ----------------------------------------------------------------------------
48 void freeAllMaracasInterfaces_dll( )
50 MyMaracasData.reset( );
51 if( _ucharVol ) delete _ucharVol;
55 // ----------------------------------------------------------------------------
56 wxStringList params_dll( )
58 return( MyMaracasData._parameters->getRelationalArray( ) );
62 // ----------------------------------------------------------------------------
63 void setParams_dll( wxStringList& raParams )
65 MyMaracasData._parameters->setRelationalArray( raParams );
69 // ----------------------------------------------------------------------------
70 bool saveParams_dll( std::string& fName )
72 return( MyMaracasData.saveParameters( std::string( fName ) ) );
76 // ----------------------------------------------------------------------------
77 bool loadParams_dll( std::string& fName )
79 return( MyMaracasData.loadParameters( std::string( fName ) ) );
83 // ----------------------------------------------------------------------------
84 void SetROIStep_dll( double vWidth )
86 MyMaracasData._parameters->setROIStep( vWidth );
90 // ----------------------------------------------------------------------------
91 double GetActualVoxelSize_dll( ) {
93 return( MyMaracasData._parameters->getVoxelSize( ) );
97 // ----------------------------------------------------------------------------
98 wxStringList studies_dll( )
100 return( MyMaracasData._dicom->getStudies( ) );
103 // ----------------------------------------------------------------------------
104 wxStringList studyData_dll( std::string& study )
106 MyMaracasData._dicom->setActualStudy( study );
107 return( MyMaracasData._dicom->getRelationalArrayStudyData( ) );
111 // ----------------------------------------------------------------------------
112 wxStringList series_dll( std::string& study )
114 MyMaracasData._dicom->setActualStudy( study );
115 return( MyMaracasData._dicom->getSeries( ) );
119 // ----------------------------------------------------------------------------
120 wxStringList serieData_dll( std::string& study, std::string& serie )
122 MyMaracasData._dicom->setActualStudy( study );
123 MyMaracasData._dicom->setActualSerie( serie );
124 return( MyMaracasData._dicom->getRelationalArraySerieData( ) );
128 // ----------------------------------------------------------------------------
129 void SubtractSeries_dll( std::string& sl, std::string& sr, std::string& ss, std::string& description )
131 marDicom::SubtractSeries(
132 MyMaracasData._parameters,
133 MyMaracasData._dicom->getActualStudy( ),
140 // ----------------------------------------------------------------------------
141 bool LoadImages_dll( )
143 MyMaracasData._dicom->loadActualSerie( );
148 // ----------------------------------------------------------------------------
149 void CastVolume_dummy( )
151 if( _ucharVol ) delete _ucharVol;
152 _ucharVol = new kVolume( *( MyMaracasData._dicom->getVolume( ) ) );
154 _ucharVol->convertScale( kVolume::UCHAR, 0, 255 );
158 // ----------------------------------------------------------------------------
159 void LoadTkImage_dummy( uchar** image, int w, int h,
160 std::string& tkName, Tcl_Interp* interp )
163 Tk_PhotoImageBlock bl;
165 hnd = Tk_FindPhoto( interp, ( char* )tkName.c_str( ) );
172 // One pixel is represented with one unsigned short value
173 bl.pixelSize = sizeof( uchar );
175 // We're working on intensity images i.e. no RGB
181 // To go to next in vertical value
182 bl.pitch = bl.pixelSize * bl.width;
185 bl.pixelPtr = ( uchar* )image[ 0 ];
188 Tk_PhotoPutBlock( hnd, &bl, 0, 0, bl.width, bl.height );
194 // ----------------------------------------------------------------------------
195 void LoadTkImages_dll( wxStringList& tkNames, Tcl_Interp* interp )
200 w = MyMaracasData._dicom->getVolume( )->getXdim( );
201 h = MyMaracasData._dicom->getVolume( )->getYdim( );
202 d = MyMaracasData._dicom->getVolume( )->getZdim( );
205 uchar*** vol = ( uchar*** )( _ucharVol->getData3D( ) );
206 for( k = 0; k < d; k++ ) {
209 LoadTkImage_dummy( vol[ k ],
216 // ----------------------------------------------------------------------------
217 int GetNumberOfImages_dll( )
219 return( MyMaracasData._dicom->getVolume( )->getZdim( ) );
223 // ----------------------------------------------------------------------------
224 wxStringList GetImagesNumbers_dll( )
226 return( MyMaracasData._dicom->getImageNumbers( ) );
230 // ----------------------------------------------------------------------------
231 double GetImageIntensity_dll( int x, int y, int z )
233 return( MyMaracasData._dicom->getVolume( )->getPixel( x, y, z ) );
237 // ----------------------------------------------------------------------------
238 ushort* GetProfilFromTotalVolume_dll( int xO, int yO, int zO,
239 int xF, int yF, int zF )
242 kVolumeStat* stats = new kVolumeStat( MyMaracasData._dicom->
245 stats->profile( xO, yO, zO, xF, yF, zF );
247 ushort* r = new ushort[ stats->getSize( ) + 6 ];
249 r[ 0 ] = stats->getSize( ) + 6;
250 r[ 1 ] = ( ushort )stats->getMin( );
251 r[ 2 ] = ( ushort )stats->getMax( );
252 r[ 3 ] = ( ushort )stats->getAvg( );
253 r[ 4 ] = ( ushort )stats->getSD( );
254 r[ 5 ] = ( ushort )stats->getSize( );
255 for( i = 0; i < stats->getSize( ); i++ )
256 r[ i + 6 ] = ( ushort )( stats->getValues( ) )[ i ];
261 // ----------------------------------------------------------------------------
262 void GetAreaValuesFromTotalVolume_dll( int xO, int yO, int zO,
263 int xF, int yF, int zF,
264 int* min, int* max, int* avg,
267 kVolumeStat* stats = new kVolumeStat( MyMaracasData._dicom->getVolume( ) );
269 stats->stats( xO, yO, zO, xF, yF, zF );
271 *min = ( int )stats->getMin( );
272 *max = ( int )stats->getMax( );
273 *avg = ( int )stats->getAvg( );
274 *sd = ( int )stats->getSD( );
275 *size = stats->getSize( );
279 // ----------------------------------------------------------------------------
280 bool SaveExperiment_dll ( std::string& fName )
282 return( MyMaracasData.saveExperiment( fName ) );
286 // ----------------------------------------------------------------------------
287 bool LoadExperiment_dll ( std::string& fName )
289 return( MyMaracasData.loadExperiment( fName ) );
293 // ----------------------------------------------------------------------------
294 void InitExperiment_dll ( int* voi )
296 MyMaracasData._experiment->setVOI( voi );
297 MyMaracasData._experiment->initExperiment( MyMaracasData._dicom->
299 //if( _ucharVol ) delete _ucharVol;
301 MyMaracasData._dicom->freeVolume( );
304 // ----------------------------------------------------------------------------
305 void SetStartPoint_dll( int x, int y, int z )
307 MyMaracasData._experiment->setStartPoint( x, y, z );
310 // ----------------------------------------------------------------------------
311 void ExtractAxes_dll( )
313 MyMaracasData._experiment->extractVascularTree( );
316 // ----------------------------------------------------------------------------
317 int GetNumberOfAxes_dll( )
319 return( MyMaracasData._experiment->getNumberOfAxes( ) );
322 // ----------------------------------------------------------------------------
323 vtkPolyData* GetAllAxes_dll( )
326 double p[ marAxis::INDX_count ];
329 vtkPoints* allPoints = vtkPoints::New( );
330 vtkCellArray* allTopology = vtkCellArray::New( );
333 for( n = 0; n < MyMaracasData._experiment->getNumberOfAxes( ); n++ ) {
335 tmp = MyMaracasData._experiment->getAxis( );
336 allTopology->InsertNextCell( tmp->getNumberOfControlPoints( ) );
337 for( i = 0; i < tmp->getNumberOfControlPoints( ); i++ ) {
339 tmp->getControlPoint( i, p, p + 3 );
340 allPoints->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] );
341 allTopology->InsertCellPoint( j );
348 vtkPolyData* allData = vtkPolyData::New( );
349 allData->SetPoints( allPoints );
350 allData->SetLines( allTopology );
353 allTopology->Delete();
359 // ----------------------------------------------------------------------------
360 vtkPolyData* GetActualAxis_dll( )
363 double p[ marAxis::INDX_count ];
366 vtkPoints* points = vtkPoints::New( );
367 vtkCellArray* topology = vtkCellArray::New( );
370 h = MyMaracasData._experiment->getDynData( )->getVolume( )->getYdim( );
371 tmp = MyMaracasData._experiment->getAxis( );
372 topology->InsertNextCell( tmp->getNumberOfControlPoints( ) );
373 for( i = 0; i < tmp->getNumberOfControlPoints( ); i++ ) {
375 tmp->getControlPoint( i, p, p + 3 );
376 topology->InsertCellPoint( j++ );
377 points->InsertNextPoint( p[ 0 ], h - 1 - p[ 1 ], p[ 2 ] );
381 vtkPolyData* data = vtkPolyData::New( );
382 data->SetPoints( points );
383 data->SetLines( topology );
391 // ----------------------------------------------------------------------------
392 int GetActualAxisNumberOfPoints_dll( )
394 return( MyMaracasData._experiment->getAxis( )->getNumberOfControlPoints( ) );
398 // ----------------------------------------------------------------------------
399 double* GetActualAxisPoint_dll( int i )
401 double* ret = new double[ marAxis::INDX_count + 1 ];
403 ret[ 0 ] = marAxis::INDX_count;
404 MyMaracasData._experiment->getAxis( )->getControlPoint( i, ret + 1, ret + 4 );
408 // ----------------------------------------------------------------------------
409 vtkImageData* GetActualAxisSlice_dll( int i )
411 // return( MyMaracasData._experiment->GetSliceImage( i ) );
416 // ----------------------------------------------------------------------------
417 void PrepareQuantification_dll( int i )
420 MyMaracasData._experiment->SetAxis( i );
421 MyMaracasData._experiment->PrepareQuantification( );
425 // ----------------------------------------------------------------------------
426 double GetAxisLength_dll( )
428 return( MyMaracasData._experiment->getAxis( )->length( ) );
432 // ----------------------------------------------------------------------------
433 void GetImageRange_dll( int* min, int* max )
437 MyMaracasData._experiment->getDynData( )->getVolume( )->getMinMax( m, M );
443 // ----------------------------------------------------------------------------
444 vtkImageData* GetVTKVolume_dll( )
446 return( MyMaracasData._experiment->getDynData( )->getVolume( )->castVtk( ) );
450 // ----------------------------------------------------------------------------
451 int IntersectWithLine_dll(
452 vtkCellLocator* iCellLocator,
453 double x1, double y1, double z1,
454 double x2, double y2, double z2,
455 double tol, double *xI, double *yI, double *zI
458 float a0[ 3 ], a1[ 3 ], x[ 3 ], t, pcoords[ 3 ];
463 iCellLocator->Update( );
465 a0[ 0 ] = x1; a0[ 1 ] = y1; a0[ 2 ] = z1;
466 a1[ 0 ] = x2; a1[ 1 ] = y2; a1[ 2 ] = z2;
468 returnVal = iCellLocator->IntersectWithLine( a0, a1, tol, t, x, pcoords, subId );
469 ( *xI ) = x[ 0 ]; ( *yI ) = x[ 1 ]; ( *zI ) = x[ 2 ];
474 // ----------------------------------------------------------------------------
475 void TclPerpendiculars_dll(
476 double xN, double yN, double zN, double angle,
477 double *xP1, double *yP1, double *zP1,
478 double *xP2, double *yP2, double *zP2
481 double x[ 3 ], y[ 3 ], z[ 3 ];
484 x[ 0 ] = xN; x[ 1 ] = yN; x[ 2 ] = zN;
485 math = vtkMath::New( );
486 math->Perpendiculars( x, y, z,angle );
487 ( *xP1 ) = y[ 0 ]; ( *yP1 ) = y[ 1 ]; ( *zP1 ) = y[ 2 ];
488 ( *xP2 ) = z[ 0 ]; ( *yP2 ) = z[ 1 ]; ( *zP2 ) = z[ 2 ];
492 #endif // MAR__INTERFACE__TCL__HXX
494 // EOF - interfaceTCL.hxx