-
Notifications
You must be signed in to change notification settings - Fork 1
/
DICMesh.cxx
1561 lines (1340 loc) · 63.7 KB
/
DICMesh.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DICMesh.cxx
//
// Copyright 2011 Seth Gilchrist <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
#ifndef DICMESH_H
#define DICMESH_H
#include <cstring>
#include <ctime>
#include "DIC.cxx"
#include "itkMesh.h"
#include "itkTetrahedronCell.h"
#include <vtkDoubleArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPoints.h>
#include <vtkCellArray.h>
#include <vtkUnstructuredGridWriter.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
#include <vtkSmartPointer.h>
#include <vtkPKdTree.h>
#include <vtkIdList.h>
#include <vtkCellDerivatives.h>
#include <vtkCellDataToPointData.h>
#include <vtkMath.h>
#include <vtkImageGaussianSmooth.h>
#include <vtkImageData.h>
#include <itkImageFileWriter.h>
#include <itkShrinkImageFilter.h>
#include "vtkUnstructuredGridReader.h"
template<typename TFixedImage, typename TMovingImage>
class DICMesh : public DIC<TFixedImage, TMovingImage>
{
public:
/** Inherited typedefs from DIC.*/
typedef typename DIC<TFixedImage,TMovingImage>::FixedImageType FixedImageType;
typedef typename DIC<TFixedImage,TMovingImage>::MovingImageType MovingImageType;
typedef typename DIC<TFixedImage,TMovingImage>::FixedImagePointer FixedImagePointer;
typedef typename DIC<TFixedImage,TMovingImage>::MovingImagePointer MovingImagePointer;
typedef typename DIC<TFixedImage,TMovingImage>::FixedImageType::IndexType FixedImageIndexType;
typedef typename DIC<TFixedImage,TMovingImage>::MovingImageType::IndexType MovingImageIndexType;
typedef typename DIC<TFixedImage,TMovingImage>::FixedImageRegionType FixedImageRegionType;
typedef typename DIC<TFixedImage,TMovingImage>::MovingImageRegionType MovingImageRegionType;
typedef typename DIC<TFixedImage,TMovingImage>::FixedImageRegionListType FixedImageRegionListType;
typedef typename DIC<TFixedImage,TMovingImage>::MovingImageRegionListType MovingImageRegionListType;
typedef typename DIC<TFixedImage,TMovingImage>::ImageRegistrationMethodType ImageRegistrationType;
typedef typename ImageRegistrationType::ParametersType RegistrationParametersType;
typedef typename DIC<TFixedImage,TMovingImage>::TransformInitializerType TransformInitializerType;
typedef typename DIC<TFixedImage,TMovingImage>::TransformType TransformType;
typedef vtkSmartPointer<vtkUnstructuredGrid> DataImagePointer;
typedef vtkSmartPointer<vtkPoints> DataImagePointsPointer;
typedef vtkSmartPointer<vtkDoubleArray> DataImagePixelPointer;
/* Methods. **/
/** Constructor **/
DICMesh()
{
m_DataImage = 0; // must be provided by user or read in using the ReadMeshFromGmshFile method
m_KDTree = vtkSmartPointer<vtkPKdTree>::New();
m_errorRadius = 4; // initialize the error search radius to 3 image units
m_displacementErrorTolerance = 2; // difference of a pixel from its neighbours to be considered erronious, in standard deviations from the mean
m_strainErrorTolerance = 1;
m_pointsList = vtkSmartPointer<vtkIdList>::New(); // the points list for analysis
m_maxMeticValue = -0.00; // TODO: make this setable using a method
m_GlobalRegDownsampleValue = 3; // This value is the default downsample when preforming the global registration.
}
/** Destructor **/
~DICMesh() {}
/** This function will compile a list of valid moving image regions.*/
void CalculateInitialMovingImageRegionList()
{
vtkIdType numberOfNodes = m_DataImage->GetNumberOfPoints();
this->m_MovingImageRegionList.clear();
// visit every point in the image
for ( int i = 0; i < numberOfNodes; ++i){
double *currentLocation = new double[3];
currentLocation = this->GetMovingImageRegionLocationFromIndex( i ); // get the current node location
MovingImageRegionType *currentRegion = new MovingImageRegionType;
this->GetMovingImageRegionFromLocation( currentRegion, currentLocation ); // get the region
this->PushRegionOntoMovingImageRegionList( currentRegion ); // add the region to the moving image region list.
}
}
/** Given an intex, this will calcualted the center of a valid moving image region.*/
double *GetMovingImageRegionLocationFromIndex( vtkIdType i)
{
double *currentPoint = new double[3];
double *currentValue = new double[3];
double *currentLocation = new double[3];
m_DataImage->GetPoint( i, currentPoint ); // get the current point location
this->m_DataImage->GetPointData()->GetArray("Displacement")->GetTuple( i, currentValue );
*currentLocation = *currentPoint + *currentValue; // set the current point to the original local to the disp
*(currentLocation +1) = *(currentPoint +1)+ *(currentValue +1);
*(currentLocation +2) = *(currentPoint +2)+ *(currentValue +2);
return currentLocation;
}
/** A function to calculate the initial fixed image region list. */
void CalculateInitialFixedImageRegionList()
{
this->m_FixedImageRegionList.clear();
this->m_pointsList->Reset();
for (int i = 0; i < this->m_DataImage->GetNumberOfPoints(); ++i){
double *currentLocation = new double[3];
m_DataImage->GetPoint( i, currentLocation ); // the fixed image region is always centered on the current mesh point
FixedImageRegionType *currentRegion = new FixedImageRegionType;
this->GetFixedImageRegionFromLocation( currentRegion, currentLocation );
this->PushRegionOntoFixedImageRegionList( currentRegion );
this->m_pointsList->InsertNextId( i );
}
}
/** A function to read a gmsh file. */
void ReadMeshFromGmshFile( std::string gmshFileName )
{
std::stringstream msg("");
std::ifstream gmshFileInput(gmshFileName.c_str());
//open file for reading
if (!gmshFileInput){
msg.str(" ");
msg << "Cannot open Gmsh file for reading."<<std::endl <<
"Please check the filename and try again.";
this->WriteToLogfile( msg.str() );
std::exit(1);
}
char str[255];
gmshFileInput.getline(str,255);
// read in the nodes /
while ( strcmp(str,"$Nodes") ){
gmshFileInput.getline(str,255); // skip all lines until we get to "$Nodes"
}
unsigned int numberOfNodes;
gmshFileInput >> numberOfNodes; // the next line will be the number of nodes
// create the data image
DataImagePointsPointer points = DataImagePointsPointer::New();
DataImagePointer meshImage = DataImagePointer::New();
DataImagePixelPointer displacementData = DataImagePixelPointer::New();
DataImagePixelPointer optimizerData = DataImagePixelPointer::New();
meshImage->SetPoints( points );
displacementData->SetNumberOfComponents(3);
displacementData->SetName("Displacement");
meshImage->GetPointData()->AddArray( displacementData );
optimizerData->SetNumberOfComponents(1);
optimizerData->SetName("Optimizer Value");
meshImage->GetPointData()->AddArray( optimizerData );
meshImage->GetPoints()->SetNumberOfPoints( (vtkIdType)numberOfNodes );
for (unsigned int i = 0; i < numberOfNodes; ++i){ // run through the number of nodes and put them in the pointset
unsigned int pointNumber;
float x, y, z;
gmshFileInput >> pointNumber >> x >> y >> z;
meshImage->GetPoints()->SetPoint(i,x,y,z);
}
// read in the elements. /
while ( strcmp(str,"$Elements") ){
gmshFileInput.getline(str,255); // skip all lines until we get to "$Elements"
}
unsigned int numberOfElements;
gmshFileInput >> numberOfElements; // the next line will be the number of elements
for ( unsigned int i = 0; i < numberOfElements; ++i ){
unsigned int elNo, elTyp;
gmshFileInput >> elNo >> elTyp;
//~ if (elTyp == 1){ // 2 node line
//~ unsigned int elNTags;
//~ gmshFileInput >> elNTags;
//~ for (unsigned int j = 0; j < elNTags+1; ++j){
//~ gmshFileInput.ignore(255,' ');
//~ }
//~ int nodes[2];
//~ gmshFileInput >> nodes[0] >> nodes[1];
//~ vtkIdType ptIds[] = { nodes[0]-1, nodes[1]-1 };
//~ meshImage->InsertNextCell(3, 2, ptIds);
//~ }
//~ if (elTyp == 2){ // 3 node triangle
//~ unsigned int elNTags;
//~ gmshFileInput >> elNTags;
//~ for (unsigned int j = 0; j < elNTags+1; ++j){
//~ gmshFileInput.ignore(255,' ');
//~ }
//~ int nodes[3];
//~ gmshFileInput >> nodes[0] >> nodes[1] >> nodes[2];
//~ vtkIdType ptIds[] = { nodes[0]-1, nodes[1]-1, nodes[2]-1 };
//~ meshImage->InsertNextCell(5, 3, ptIds);
//~ }
if (elTyp == 4){ // linear tet element
unsigned int elNTags;
gmshFileInput >> elNTags;
for (unsigned int j = 0;j < elNTags+1; ++j){ // ignore tags
gmshFileInput.ignore(255,' ');
}
int nodes[4];
gmshFileInput >> nodes[0] >> nodes[1] >> nodes[2] >> nodes[3];
vtkIdType ptIds[] = { nodes[0]-1, nodes[1]-1, nodes[2]-1, nodes[3]-1 };
meshImage->InsertNextCell(10, 4, ptIds);
}
//~ if (elTyp == 8){ // quadratic line element
//~ std::stringstream msg("");
//~ msg << "Warning: Qadratic line element in gmsh file."<<std::endl << "Qadratic lines are not supported" <<std::endl <<
//~ "Continuing with the file input."<<std::endl; // not supported because they give bad jaboians in the strain calcs
//~ this->WriteToLogfile( msg.str() );
//~ gmshFileInput.ignore(255,'\n');
//~ continue;
//~ }
//~ if (elTyp == 9){ //quadratic triangle element
//~ unsigned int elNTags;
//~ gmshFileInput >> elNTags;
//~ for (unsigned int j = 0; j< elNTags+1; ++j){ //ignore tags
//~ gmshFileInput.ignore(255,' ');
//~ }
//~ int nodes[6];
//~ gmshFileInput >> nodes[0] >> nodes[1] >> nodes[2] >> nodes[3] >> nodes[4] >> nodes[5];
//~ vtkIdType ptIds[] = { nodes[0]-1, nodes[1]-1, nodes[2]-1, nodes[3]-1, nodes[4]-1, nodes[5]-1};
//~ meshImage->InsertNextCell(22,6,ptIds);
//~ }
if (elTyp == 11){ // quatratic tet element
unsigned int elNTags;
gmshFileInput >> elNTags;
for (unsigned int j = 0;j < elNTags+1; ++j){ // ignore tags
gmshFileInput.ignore(255,' ');
}
int nodes[10];//, node1, node2, node3, node4, node5, node6, node7, node8, node9;
gmshFileInput >> nodes[0] >> nodes[1] >> nodes[2] >> nodes[3] >> nodes[4] >> nodes[5] >> nodes[6] >> nodes[7] >> nodes[9] >> nodes[8]; // nodes[8] and modes[9] intensionally switched due to vtk/gmsh node numbering differences
vtkIdType ptIds[] = { nodes[0]-1, nodes[1]-1, nodes[2]-1, nodes[3]-1, nodes[4]-1, nodes[5]-1, nodes[6]-1, nodes[7]-1, nodes[8]-1, nodes[9]-1 };
meshImage->InsertNextCell(24, 10, ptIds);
}
//~ if (elTyp == 15){ // 3D vertex
//~ unsigned int elNTags;
//~ gmshFileInput >> elNTags;
//~ for (unsigned int j = 0; j< elNTags+1; ++j){ //ignore tags
//~ gmshFileInput.ignore(255,' ');
//~ }
//~ int nodes[1];
//~ gmshFileInput >> nodes[0];
//~ vtkIdType ptIds[] = { nodes[0]-1 };
//~ meshImage->InsertNextCell(1,1,ptIds);
//~ }
//~ if (elTyp != 1 && elTyp != 2 && elTyp != 4 && elTyp != 8 && elTyp != 9 && elTyp != 11 && elTyp != 15){ // only support the above element types
//~ std::stringstream msg("");
//~ msg << "Unsupported element types detected!"<<std::endl << "Unsupported type = "<<elTyp<<std::endl <<
//~ "Continuing with the file input."<<std::endl;
//~ this->WriteToLogfile( msg.str() );
//~ gmshFileInput.ignore(255,'\n');
//~ continue;
//~ }
if (elTyp != 4 && elTyp != 11){ // only support the above element types
std::stringstream msg("");
msg << "Unsupported element types detected!"<<std::endl << "Unsupported type = "<<elTyp<<std::endl <<
"Continuing with the file input.";
this->WriteToLogfile( msg.str() );
gmshFileInput.ignore(255,'\n');
continue;
}
}
for ( unsigned int i = 0; i < numberOfNodes; ++i ){
meshImage->GetPointData()->GetArray("Displacement")->InsertNextTuple3( 0, 0, 0 );
meshImage->GetPointData()->GetArray("Optimizer Value")->InsertNextTuple1( 0 );
}
this->SetDataImage( meshImage );
}
/** A fucntion to read a vtk mesh file **/
void ReadVTKMesh(std::string meshFileName )
{
vtkSmartPointer<vtkUnstructuredGridReader> vtkReader= vtkSmartPointer<vtkUnstructuredGridReader>::New();
vtkReader->SetFileName( meshFileName.c_str() );
vtkReader->Update();
this->SetDataImage( vtkReader->GetOutput() );
}
/** A function to fill a mesh with an single value. */
void SetMeshToSingleValue( double initialData[] )
{
for ( unsigned int i = 0; i < this->m_DataImage->GetNumberOfPoints(); ++i ){
this->m_DataImage->GetPointData()->GetArray("Displacement")->SetTuple( i , initialData );
}
}
/** Get a pixel value from the mesh using an index */
void GetMeshPixelValueFromIndex( vtkIdType index, double *pixel )
{
this->m_DataImage->GetPointData()->GetArray("Displacement")->GetTuple( index, pixel );
}
/** Get the value of the optimizer at a certain point. */
void GetMeshPixelOptimizerFromIndex( vtkIdType index, double *opt )
{
this->m_DataImage->GetPointData()->GetArray("Optimizer Value")->GetTuple( index, opt );
}
/** Set a pixel value in the mesh using an index */
void SetMeshPixelValueFromIndex(vtkIdType index, double *pixel )
{
this->m_DataImage->GetPointData()->GetArray("Displacement")->SetTuple( index, pixel );
}
/** Set the value of the optimizer at a certain point. */
void SetMeshPixelOptimizerFromIndex( vtkIdType index, double *opt )
{
this->m_DataImage->GetPointData()->GetArray("Optimizer Value")->SetTuple( index, opt );
}
/** Get a point by index from the mesh. */
void GetMeshPointLocationFromIndex( vtkIdType index, double *point )
{
this->m_DataImage->GetPoint(index,point);
}
/** Set the data Image. */
void SetDataImage( vtkUnstructuredGrid *initialDataImage )
{
if (this->m_DataImage.GetPointer() != initialDataImage){
this->m_DataImage = initialDataImage;
}
this->KDTreeSetAndBuild();
}
/** Get the pointer to the data image. */
DataImagePointer GetDataImage()
{
return this->m_DataImage;
}
/** a function to execute the analysis. */
void ExecuteDIC()
{
std::stringstream msg(""); // test if everything is set
if( !this->m_Registration ){
msg.str("");
msg << "Registration not set. Please define and set the\nregistration using the SetRegistrationMethod() method.";
this->WriteToLogfile( msg.str() );
std::abort();
}
if( !this->m_FixedImage ){
msg.str("");
msg << "Fixed image not set. Please define and set the\n fixed image using the SetFixedImage() method.";
this->WriteToLogfile( msg.str() );
std::abort();
}
if( !this->m_MovingImage ){
msg.str("");
msg << "Moving image not set. Please define and set the\n moving image using the SetMovingImage() method.";
this->WriteToLogfile( msg.str() );
std::abort();
}
if( !this->m_DataImage ){
msg.str("");
msg << "The data image not set. Please define and set the\n initial data image using either the ReadMeshFromGmshFile or\n SetDataImage() methods.";
this->WriteToLogfile( msg.str() );
std::abort();
}
if( this->m_FixedImageRegionList.empty() ){ // if the region list is empty, create full region lists
this->CalculateInitialFixedImageRegionList();
}
if( this->m_MovingImageRegionList.empty() ){
this->CalculateInitialMovingImageRegionList();
}
struct tm * timeValue; // record the time
std::time_t rawTime;
std::time( &rawTime );
timeValue = std::localtime( &rawTime );
msg.str("");
msg << "Starting DIC at: "<<std::asctime( timeValue );
this->WriteToLogfile( msg.str() );
// visit every point in the points list
unsigned int nMeshPoints = this->m_pointsList->GetNumberOfIds();
for( unsigned int i = 0; i<nMeshPoints; ++i){
vtkIdType pointId = this->m_pointsList->GetId( i );
msg.str("");
msg << "Starting image registraion for point: "<<i+1<<" of "<<nMeshPoints<<" (mesh index "<<pointId<<")";
this->WriteToLogfile( msg.str() );
std::time_t rawTime; // record the time for each DVC
struct tm * timeValue;
std::time( &rawTime );
timeValue = std::localtime( &rawTime );
msg.str("");
msg << "Time: "<<std::asctime( timeValue );
this->WriteToLogfile( msg.str() );
FixedImageRegionType *fixedRegion = new FixedImageRegionType ; // get the fixed image from the fixed image list
FixedImagePointer fixedImage;
fixedRegion = this->GetFixedImageRegionFromIndex( i );
fixedImage = this->GetFixedROIAsImage( fixedRegion );
this->SetFixedROIImage( fixedImage );
MovingImageRegionType *movingRegion = new MovingImageRegionType; // get the moving image from the moving image list
MovingImagePointer movingImage;
movingRegion = this->GetMovingImageRegionFromIndex( i );
movingImage = this->GetMovingROIAsImage( movingRegion );
this->SetMovingROIImage( movingImage );
this->SetTransformToIdentity(); // Set the transform to do nothing
// initialize the transform to perform rotations about the fixed region center
this->m_TransformInitializer->SetFixedImage( this->m_Registration->GetFixedImage() );
this->m_TransformInitializer->SetMovingImage( this->m_Registration->GetMovingImage() );
this->m_TransformInitializer->SetTransform( this->m_Transform );
this->m_TransformInitializer->GeometryOn();
this->m_TransformInitializer->InitializeTransform();
this->m_Registration->SetInitialTransformParameters( this->m_Transform->GetParameters() );
double *displacementData = new double[3]; // set the initial displacement
this->GetMeshPixelValueFromIndex( pointId, displacementData );
this->SetInitialDisplacement( displacementData );
msg.str("");
msg <<"Current transform: "<<this->m_Registration->GetInitialTransformParameters();
this->WriteToLogfile( msg.str() );
// if the optimizer is the lbfgsb then set the bounds based on teh current displacement
if( !strcmp(this->m_Registration->GetOptimizer()->GetNameOfClass(),"LBFGSBOptimizer") ){
unsigned int nParameters = this->m_Registration->GetTransform()->GetNumberOfParameters();
itk::Array< long > boundSelect( nParameters );
itk::Array< double > upperBound( nParameters );
itk::Array< double > lowerBound( nParameters );
boundSelect.Fill( 0 );
boundSelect[nParameters-3] = 2;
boundSelect[nParameters-2] = 2;
boundSelect[nParameters-1] = 2;
typename FixedImageType::SpacingType imageSpacing = this->m_Registration->GetFixedImage()->GetSpacing();
upperBound[nParameters-3] = *displacementData + .5*imageSpacing[0];
upperBound[nParameters-2] = *(displacementData+1) + .5*imageSpacing[1];
upperBound[nParameters-1] = *(displacementData+2) + .5*imageSpacing[2];
lowerBound.Fill( 0 );
lowerBound[nParameters-3] = *displacementData - .5*imageSpacing[0];
lowerBound[nParameters-2] = *(displacementData+1) - .5*imageSpacing[1];
lowerBound[nParameters-1] = *(displacementData+2) - .5*imageSpacing[2];
reinterpret_cast<itk::LBFGSBOptimizer *>(this->m_Registration->GetOptimizer())->SetBoundSelection( boundSelect );
reinterpret_cast<itk::LBFGSBOptimizer *>(this->m_Registration->GetOptimizer())->SetUpperBound( upperBound );
reinterpret_cast<itk::LBFGSBOptimizer *>(this->m_Registration->GetOptimizer())->SetLowerBound( lowerBound );
}
// update the registration
this->UpdateRegionRegistration();
// output the results
double *lastDisp = new double[3];
this->GetLastDisplacement( lastDisp );
this->SetMeshPixelValueFromIndex( pointId, lastDisp );
double *lastOpt = new double;
this->GetLastOptimizer( lastOpt );
this->SetMeshPixelOptimizerFromIndex( pointId, lastOpt );
msg.str("");
msg << "Final displacement value: ("<<*lastDisp<<", "<<*(lastDisp+1)<<", "<<*(lastDisp+2)<<")"<<std::endl <<
"Optimizer stop condition: " << this->m_Registration->GetOptimizer()->GetStopConditionDescription() << std::endl <<
"Final optimizer value: "<<*lastOpt<<std::endl;
this->WriteToLogfile( msg.str() );
std::string debugFile = this->m_OutputDirectory + "/debug.vtk";
this->WriteMeshToVTKFile( debugFile );
}
}
/** A function to write the mesh data to a VTK ASCII file. */
void WriteMeshToVTKFile(std::string outFile)
{
vtkSmartPointer<vtkUnstructuredGridWriter> writer = vtkSmartPointer<vtkUnstructuredGridWriter>::New();
writer->SetFileName( outFile.c_str() );
writer->SetFileTypeToASCII();
writer->SetInput( this->m_DataImage );
writer->Update();
}
/** A function to build the KDTree locator from the data image. This method
* is called when the data image is set. */
void KDTreeSetAndBuild()
{
this->m_KDTree->SetDataSet( this->m_DataImage );
this->m_KDTree->BuildLocatorFromPoints( this->m_DataImage->GetPoints() );
}
/** A function to find the values that are outside a given bounds
* compared to their connected neighbours. */
void CreateNewRegionListFromBadPixels()
{
this->m_FixedImageRegionList.clear(); // clear the regions for calculation
this->m_MovingImageRegionList.clear();
this->m_pointsList->Reset(); // clear the point list
DataImagePointer tempImage = DataImagePointer::New(); // make a copy of the image to work with
tempImage->DeepCopy(this->m_DataImage);
// visit every point in the image
unsigned int numberOfPoints = tempImage->GetNumberOfPoints();
for( unsigned int i = 0; i < numberOfPoints; ++i ){
// find connected points
vtkSmartPointer<vtkIdList> pointList = vtkSmartPointer<vtkIdList>::New();
this->GetNeighbouringPoints( i, pointList );
// calc the average and standard deviabtions of the displacements stored in the neighbourhood points
double averageValue[3] = {0,0,0};
double averageMag = 0;
double stDevValue[3] = {0,0,0};
double stDevMag = 0;
this->GetDisplacementStats(i, pointList, averageValue, averageMag, stDevValue, stDevMag, tempImage );
// get the displacement value stored in the current point
double *currentValue = new double[3];
currentValue = tempImage->GetPointData()->GetArray("Displacement")->GetTuple( i );
// check if there the pixel is valid - if any component is out of value it is considered invalid
if( !DisplacementValid(currentValue, averageValue, averageMag, stDevValue, stDevMag ) ){
double *averagedDisplacement = new double[3];
averagedDisplacement = CalculateDisplacementWeightedMovingAverage( 2, 0, i, tempImage );
this->m_DataImage->GetPointData()->GetArray("Displacement")->SetTuple( i, averagedDisplacement ); // apply a smoothed value to the mesh to be used in the next evaluation
double *movingImageCenterLocation = new double[3];
movingImageCenterLocation = this->GetMovingImageRegionLocationFromIndex( i ); // new moving image centre
MovingImageRegionType *currentMovingRegion = new MovingImageRegionType;
this->GetMovingImageRegionFromLocation( currentMovingRegion, movingImageCenterLocation );
this->PushRegionOntoMovingImageRegionList( currentMovingRegion ); // new moving image
FixedImageRegionType *currentFixedRegion = new FixedImageRegionType; // calculated the new fixed region
this->GetFixedImageRegionFromLocation( currentFixedRegion, this->m_DataImage->GetPoint( i ) );
this->PushRegionOntoFixedImageRegionList( currentFixedRegion );
this->m_pointsList->InsertNextId( i ); // add the current point to the next round of evaluation
}
}
}
/** A function to calcluate the component and mangnitued averages of point
* values from a list of point IDs.
* rPoint = reference point
* points = list of points for stats calculation
* vectorAverage = average value of each component (eg, vectorAverage[0] = average(x_displacement)
* magAverage = average magnitude of vectorAverage
* vectorStDev = standard deviation of each component
* magStDev = magnitude of the standard deviations
* image = pointer to an unstructured grid image */
void GetDisplacementStats(vtkIdType rPoint, vtkSmartPointer<vtkIdList> points, double vectorAverage[3], double &magAverage, double vectorStDev[3], double &magStDev, DataImagePointer image)
{
// visit each point in the list and calculate the average
unsigned int nPoints = points->GetNumberOfIds();
int denominator = 0;
for( unsigned int i = 0; i < nPoints; ++i){
vtkIdType pointId = points->GetId( i );
if ( pointId == rPoint) continue; // don't include the current point in the average.
denominator++; // increment the denominator only once passed the current point check
double *cPoint = new double[3];
image->GetPointData()->GetArray("Displacement")->GetTuple( pointId, cPoint ); // get the current point value
vectorAverage[0] = vectorAverage[0] + cPoint[0];
vectorAverage[1] = vectorAverage[1] + cPoint[1];
vectorAverage[2] = vectorAverage[2] + cPoint[2];
magAverage = magAverage + std::sqrt( std::pow(cPoint[0],2) + std::pow(cPoint[1],2) + std::pow(cPoint[2],2) );
}
vectorAverage[0] = vectorAverage[0]/denominator;
vectorAverage[1] = vectorAverage[1]/denominator;
vectorAverage[2] = vectorAverage[2]/denominator;
magAverage = magAverage/denominator;
double vectDiff[3] = {0, 0, 0};
double magDiff = 0;
denominator = 0;
for( unsigned int i = 0; i <nPoints; ++i){
vtkIdType pointId = points->GetId( i );
if ( pointId == rPoint) continue; // don't include the current point in the average.
denominator++; // increment the denominator only once passed the current point check
double *cPoint = new double[3];
image->GetPointData()->GetArray("Displacement")->GetTuple( pointId, cPoint ); // get the current point value
double cMag = std::sqrt( std::pow(cPoint[0],2) + std::pow(cPoint[1],2) + std::pow(cPoint[2],2) );
// the sum of all the squared distances from the mean
vectDiff[0] = vectDiff[0] + std::pow( (cPoint[0]-vectorAverage[0]), 2);
vectDiff[1] = vectDiff[1] + std::pow( (cPoint[1]-vectorAverage[1]), 2);
vectDiff[2] = vectDiff[2] + std::pow( (cPoint[2]-vectorAverage[2]), 2);
magDiff = magDiff + std::pow( (cMag - magAverage), 2);
}
vectorStDev[0] = std::sqrt(vectDiff[0]/denominator);
vectorStDev[1] = std::sqrt(vectDiff[1]/denominator);
vectorStDev[2] = std::sqrt(vectDiff[2]/denominator);
magStDev = std::sqrt(magDiff/denominator);
}
/** A function to find and replace bad displacement values. Displacements
* statistics are calculated and the displacement at a given point is
* tested for validity. If the displacement is found to be outside the
* valid region, it is replaced by a weighted average of its neighbours.
* The weighting parameters are given by sigma and mean and a list of
* replaced pixels is returned in replacedList.
* see DICMesh::DisplacementWeightedMovingAverageFilter */
void ReplaceBadDisplacementPixels( double sigma, double mean, vtkIdList *replacedList)
{
// if sigma = 0, there's nothing to do
if ( sigma == 0) {return;}
// create a duplicate of the data image
DataImagePointer tempImage = DataImagePointer::New();
tempImage->DeepCopy(this->m_DataImage);
// empty the list of replaced points
replacedList->Reset();
// visit every point in the image
unsigned int numberOfPoints = tempImage->GetNumberOfPoints();
for( unsigned int i = 0; i < numberOfPoints; ++i ){
// get connected points
vtkSmartPointer<vtkIdList> pointList = vtkSmartPointer<vtkIdList>::New();
this->GetNeighbouringPoints( i, pointList );
// calc the average and stDev of the points in the list
double vectorAverage[3] = { 0 };
double magAverage = 0;
double vectorStDev[3] = { 0 };
double magStDev = 0;
this->GetDisplacementStats( i, pointList, vectorAverage, magAverage, vectorStDev, magStDev, tempImage );
// get the value of the current point
double *currentValue = new double[3];
tempImage->GetPointData()->GetArray("Displacement")->GetTuple( i, currentValue );
// check if there the pixel is valid - if any component is out of value it is considered invalid
if( !this->DisplacementValid( currentValue, vectorAverage, magAverage, vectorStDev, magStDev ) ){
double *newDisplacement = new double[3];
newDisplacement = CalculateDisplacementWeightedMovingAverage( sigma, mean, i, tempImage );
this->m_DataImage->GetPointData()->GetArray("Displacement")->SetTuple( i, newDisplacement ); // apply pixel value to the mesh
replacedList->InsertNextId( i );
}
}
}
/** A function to test if a displacement vector is to be considered
* erronious or not. The displacementErrorTollerance is used to tell the
* number of standard deviations from the mean that are permitted for
* each componenent.*/
bool DisplacementValid(double value[3], double vectorAverage[3], double &magAverage, double vectorStDev[3], double &magStDev)
{
if (
std::fabs(value[0] - vectorAverage[0]) > this->m_displacementErrorTolerance * vectorStDev[0] ||
std::fabs(value[1] - vectorAverage[1]) > this->m_displacementErrorTolerance * vectorStDev[1] ||
std::fabs(value[2] - vectorAverage[2]) > this->m_displacementErrorTolerance * vectorStDev[2] )
{
return false;
}
else
{
return true;
}
}
/** A function to find and replace bad strain values. Strain
* statistics are calculated and the strain at a given point is
* tested for validity. If the strain is found to be outside the
* valid region, it is replaced by a weighted average of its neighbours.
* The weighting parameters are given by sigma and mean and a list of
* replaced pixels is returned in replacedList.
* see DICMesh::StrainWeightedMovingAverageFilter */
void ReplaceBadStrainPixels( double sigma, double mean, vtkIdList *replacedList)
{
// if sigma = 0, there's nothing to do
if ( sigma == 0) {return;}
// create a duplicate of the data image
DataImagePointer tempImage = DataImagePointer::New();
tempImage->DeepCopy(this->m_DataImage);
// empty the list of replaced points
replacedList->Reset();
// visit every point in the image
unsigned int numberOfPoints = tempImage->GetNumberOfPoints();
for( unsigned int i = 0; i < numberOfPoints; ++i ){
// get connected points
vtkSmartPointer<vtkIdList> pointList = vtkSmartPointer<vtkIdList>::New();
this->GetNeighbouringPoints( i, pointList );
// calc the average and stDev of the points in the list
double averageValue[9] = { 0 };
double stDevValue[9] = { 0 };
this->GetStrainStats(i, pointList, averageValue, stDevValue );
// get the value of the current point
double *currentValue = new double[9];
currentValue = tempImage->GetPointData()->GetArray("Strain")->GetTuple( i );
// check if there the pixel is valid - if any component is out of value it is considered invalid
if( !this->StrainValid(currentValue, averageValue, stDevValue) ){
double *newStrain = new double[9];
newStrain = CalculateStrainWeightedMovingAverage( sigma, mean, i, tempImage );
this->m_DataImage->GetPointData()->GetArray("Strain")->SetTuple( i, newStrain ); // apply pixel value to the mesh
replacedList->InsertNextId( i );
}
}
}
void GetStrainStats( vtkIdType c_point, vtkSmartPointer<vtkIdList> points, double vectorAverage[9], double vectorStDev[9] )
{
unsigned int nPoints = points->GetNumberOfIds();
int denominator = 0;
for( unsigned int i = 0; i < nPoints; ++i){
vtkIdType pointId = points->GetId( i );
if ( pointId == c_point) continue; // don't include the current point in the average.
denominator++;
double *cPoint = new double[9];
this->m_DataImage->GetPointData()->GetArray("Strain")->GetTuple( pointId, cPoint );
vectorAverage[0] = vectorAverage[0] + cPoint[0];
vectorAverage[1] = vectorAverage[1] + cPoint[1];
vectorAverage[2] = vectorAverage[2] + cPoint[2];
vectorAverage[3] = vectorAverage[3] + cPoint[3];
vectorAverage[4] = vectorAverage[4] + cPoint[4];
vectorAverage[5] = vectorAverage[5] + cPoint[5];
vectorAverage[6] = vectorAverage[6] + cPoint[6];
vectorAverage[7] = vectorAverage[7] + cPoint[7];
vectorAverage[8] = vectorAverage[8] + cPoint[8];
}
vectorAverage[0] = vectorAverage[0]/denominator;
vectorAverage[1] = vectorAverage[1]/denominator;
vectorAverage[2] = vectorAverage[2]/denominator;
vectorAverage[3] = vectorAverage[3]/denominator;
vectorAverage[4] = vectorAverage[4]/denominator;
vectorAverage[5] = vectorAverage[5]/denominator;
vectorAverage[6] = vectorAverage[6]/denominator;
vectorAverage[7] = vectorAverage[7]/denominator;
vectorAverage[8] = vectorAverage[8]/denominator;
double vectDiff[9] = { 0 };
denominator = 0;
for( unsigned int i = 0; i <nPoints; ++i){
vtkIdType pointId = points->GetId( i );
if ( pointId == c_point) continue; // don't include the current point in the average.
denominator++;
double *cPoint = new double[9];
this->m_DataImage->GetPointData()->GetArray("Strain")->GetTuple( pointId, cPoint );
vectDiff[0] = vectDiff[0] + std::pow( (cPoint[0] - vectorAverage[0]), 2);
vectDiff[1] = vectDiff[1] + std::pow( (cPoint[1] - vectorAverage[1]), 2);
vectDiff[2] = vectDiff[2] + std::pow( (cPoint[2] - vectorAverage[2]), 2);
vectDiff[3] = vectDiff[3] + std::pow( (cPoint[3] - vectorAverage[3]), 2);
vectDiff[4] = vectDiff[4] + std::pow( (cPoint[4] - vectorAverage[4]), 2);
vectDiff[5] = vectDiff[5] + std::pow( (cPoint[5] - vectorAverage[5]), 2);
vectDiff[6] = vectDiff[6] + std::pow( (cPoint[6] - vectorAverage[6]), 2);
vectDiff[7] = vectDiff[7] + std::pow( (cPoint[7] - vectorAverage[7]), 2);
vectDiff[8] = vectDiff[8] + std::pow( (cPoint[8] - vectorAverage[8]), 2);
}
vectorStDev[0] = std::sqrt( vectDiff[0]/denominator );
vectorStDev[1] = std::sqrt( vectDiff[1]/denominator );
vectorStDev[2] = std::sqrt( vectDiff[2]/denominator );
vectorStDev[3] = std::sqrt( vectDiff[3]/denominator );
vectorStDev[4] = std::sqrt( vectDiff[4]/denominator );
vectorStDev[5] = std::sqrt( vectDiff[5]/denominator );
vectorStDev[6] = std::sqrt( vectDiff[6]/denominator );
vectorStDev[7] = std::sqrt( vectDiff[7]/denominator );
vectorStDev[8] = std::sqrt( vectDiff[8]/denominator );
}
bool StrainValid(double currentValue[9], double averageValue[9], double stDevValue[9])
{
if (std::fabs(currentValue[0] - averageValue[0]) > this->m_strainErrorTolerance * stDevValue[0] ||
std::fabs(currentValue[1] - averageValue[1]) > this->m_strainErrorTolerance * stDevValue[1] ||
std::fabs(currentValue[2] - averageValue[2]) > this->m_strainErrorTolerance * stDevValue[2] ||
std::fabs(currentValue[3] - averageValue[3]) > this->m_strainErrorTolerance * stDevValue[3] ||
std::fabs(currentValue[4] - averageValue[4]) > this->m_strainErrorTolerance * stDevValue[4] ||
std::fabs(currentValue[5] - averageValue[5]) > this->m_strainErrorTolerance * stDevValue[5] ||
std::fabs(currentValue[6] - averageValue[6]) > this->m_strainErrorTolerance * stDevValue[6] ||
std::fabs(currentValue[7] - averageValue[7]) > this->m_strainErrorTolerance * stDevValue[7] ||
std::fabs(currentValue[8] - averageValue[8]) > this->m_strainErrorTolerance * stDevValue[8] )
{
return false;
}
else
{
return true;
}
}
/** A function to calculate the strains. */
void GetStrains()
{
// calculate derivatives
vtkCellDerivatives *derivativeCalculator = vtkCellDerivatives::New();
derivativeCalculator->SetInput( this->m_DataImage );
derivativeCalculator->SetTensorModeToComputeStrain();
derivativeCalculator->SetVectorModeToComputeGradient();
derivativeCalculator->SetInputArrayToProcess(1,0,0,0,"Displacement"); // the CellDerivatives calculator sets the array idx to 0 for scalars and 1 for vector inputs. We want it to operate on vectors, so idx is set to 1. Further, giving it the name of the array allows it to verify that it is operating on the correct array.
derivativeCalculator->Update();
this->SetDataImage( derivativeCalculator->GetUnstructuredGridOutput() );
// move the data from cells to nodes
vtkCellDataToPointData *dataTransformer = vtkCellDataToPointData::New();
dataTransformer->SetInput( this->m_DataImage );
dataTransformer->PassCellDataOn();
dataTransformer->SetInputArrayToProcess(0,0,0,1,"Strain");// Strain is on array zero of the cells in m_DataImage. The 4th is an enum to tell the algorithm the data is stored in cells, the last in the name of the array.
dataTransformer->Update();
this->SetDataImage( dataTransformer->GetUnstructuredGridOutput() );
}
/** A function to calculate the principal strains. */
void GetPrincipalStrains()
{
vtkSmartPointer<vtkMath> mathAlgorithm = vtkSmartPointer<vtkMath>::New();
// First find the principal strains for the point data
vtkIdType nPoints = this->m_DataImage->GetPointData()->GetArray("Strain")->GetNumberOfTuples();
DataImagePixelPointer V0;
DataImagePixelPointer V1;
DataImagePixelPointer V2;
DataImagePixelPointer val0;
DataImagePixelPointer val1;
DataImagePixelPointer val2;
// create the eigenvector containers if they don't exist
if ( this->m_DataImage->GetPointData()->GetArray("Principal Strain Vector 1") ){
V0 = vtkDoubleArray::SafeDownCast( this->m_DataImage->GetPointData()->GetArray( "Principal Strain Vector 1" ) );
}
else{
V0 = DataImagePixelPointer::New();
V0->SetNumberOfComponents(3);
V0->SetName("Principal Strain Vector 1");
V0->Allocate(nPoints);
V0->SetNumberOfTuples(nPoints);
this->m_DataImage->GetPointData()->AddArray( V0 );
}
if ( this->m_DataImage->GetPointData()->GetArray("Principal Strain Vector 2") ){
V1 = vtkDoubleArray::SafeDownCast( this->m_DataImage->GetPointData()->GetArray( "Principal Strain Vector 2" ) );
}
else{
V1 = DataImagePixelPointer::New();
V1->SetNumberOfComponents(3);
V1->SetName("Principal Strain Vector 2");
V1->Allocate(nPoints);
V1->SetNumberOfTuples(nPoints);
this->m_DataImage->GetPointData()->AddArray( V1 );
}
if ( this->m_DataImage->GetPointData()->GetArray("Principal Strain Vector 3") ){
V2 = vtkDoubleArray::SafeDownCast( this->m_DataImage->GetPointData()->GetArray( "Principal Strain Vector 3" ) );
}
else{
V2 = DataImagePixelPointer::New();
V2->SetNumberOfComponents(3);
V2->SetName("Principal Strain Vector 3");
V2->Allocate(nPoints);
V2->SetNumberOfTuples(nPoints);
this->m_DataImage->GetPointData()->AddArray( V2 );
}
// create the eigenvalue containers if they don't exist
if ( this->m_DataImage->GetPointData()->GetArray("Principal Strain Value 1") ){
val0 = vtkDoubleArray::SafeDownCast( this->m_DataImage->GetPointData()->GetArray( "Principal Strain Value 1" ) );
}
else{
val0 = DataImagePixelPointer::New();
val0->SetNumberOfComponents(1);
val0->SetName("Principal Strain Value 1");
val0->Allocate(nPoints);
val0->SetNumberOfTuples(nPoints);
this->m_DataImage->GetPointData()->AddArray( val0 );
}
if ( this->m_DataImage->GetPointData()->GetArray("Principal Strain Value 2") ){
val1 = vtkDoubleArray::SafeDownCast( this->m_DataImage->GetPointData()->GetArray("Principal Strain Value 2") );
}
else{
val1 = DataImagePixelPointer::New();
val1->SetNumberOfComponents(1);
val1->SetName("Principal Strain Value 2");
val1->Allocate(nPoints);
val1->SetNumberOfTuples(nPoints);
this->m_DataImage->GetPointData()->AddArray( val1 );
}
if ( this->m_DataImage->GetPointData()->GetArray("Principal Strain Value 3") ){
val2 = vtkDoubleArray::SafeDownCast( this->m_DataImage->GetPointData()->GetArray("Principal Strain Value 3") );
}
else{
val2 = DataImagePixelPointer::New();
val2->SetNumberOfComponents(1);
val2->SetName("Principal Strain Value 3");
val2->Allocate(nPoints);
val2->SetNumberOfTuples(nPoints);
this->m_DataImage->GetPointData()->AddArray( val2 );
}
for ( unsigned int i = 0; i < nPoints; ++i ){
// Get the point tensor
double *cTensorRaw = this->m_DataImage->GetPointData()->GetArray("Strain")->GetTuple( i );
// reform tensor into an appropreate array
double *cTensor[3];
double cT0[3];
double cT1[3];
double cT2[3];
cTensor[0] = cT0; cTensor[1] = cT1; cTensor[2] = cT2;
cT0[0] = *cTensorRaw;
cT0[1] = *(cTensorRaw+1);
cT0[2] = *(cTensorRaw+2);
cT1[0] = *(cTensorRaw+3);
cT1[1] = *(cTensorRaw+4);
cT1[2] = *(cTensorRaw+5);
cT2[0] = *(cTensorRaw+6);
cT2[1] = *(cTensorRaw+7);
cT2[2] = *(cTensorRaw+8);
// Get the eigen-values and -vectors
double eigenValues[3]; // The Eigenvalues
double *eigenVectors[3]; // vector of pointers to eigenvectors
double v0[3]; // eigen vector 1
double v1[3]; // eigen vector 2
double v2[3]; // eigen vector 3
eigenVectors[0] = v0; eigenVectors[1] = v1; eigenVectors[2] = v2;
// perform the calculation of the principal strains
mathAlgorithm->Jacobi(cTensor,eigenValues,eigenVectors);
// save the values and vectors into the data image
V0->SetTuple( i, eigenVectors[0] );
val0->SetTuple( i, &eigenValues[0] );
V1->SetTuple( i, eigenVectors[1] );
val1->SetTuple( i, &eigenValues[1] );
V2->SetTuple( i, eigenVectors[2] );
val2->SetTuple( i, &eigenValues[2] );
}
// next find the principal strains for the cell data
nPoints = this->m_DataImage->GetCellData()->GetArray("Strain")->GetNumberOfTuples();
// create the eigenvector containers if they don't exist
if ( this->m_DataImage->GetCellData()->GetArray("Principal Strain Vector 1") ){
V0 = vtkDoubleArray::SafeDownCast( this->m_DataImage->GetCellData()->GetArray("Principal Strain Vector 1") );
}
else{
V0 = DataImagePixelPointer::New();
V0->SetNumberOfComponents(3);