1
1
/* ============================================================================
2
- * Copyright (c) 2009-2016 BlueQuartz Software, LLC
3
- *
4
- * Redistribution and use in source and binary forms, with or without modification,
5
- * are permitted provided that the following conditions are met:
6
- *
7
- * Redistributions of source code must retain the above copyright notice, this
8
- * list of conditions and the following disclaimer.
9
- *
10
- * Redistributions in binary form must reproduce the above copyright notice, this
11
- * list of conditions and the following disclaimer in the documentation and/or
12
- * other materials provided with the distribution.
13
- *
14
- * Neither the name of BlueQuartz Software, the US Air Force, nor the names of its
15
- * contributors may be used to endorse or promote products derived from this software
16
- * without specific prior written permission.
17
- *
18
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27
- * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
- *
29
- * The code contained herein was partially funded by the followig contracts:
30
- * United States Air Force Prime Contract FA8650-07-D-5800
31
- * United States Air Force Prime Contract FA8650-10-D-5210
32
- * United States Prime Contract Navy N00173-07-C-2068
33
- *
34
- * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
2
+ * Copyright (c) 2009-2016 BlueQuartz Software, LLC
3
+ *
4
+ * Redistribution and use in source and binary forms, with or without modification,
5
+ * are permitted provided that the following conditions are met:
6
+ *
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ * list of conditions and the following disclaimer.
9
+ *
10
+ * Redistributions in binary form must reproduce the above copyright notice, this
11
+ * list of conditions and the following disclaimer in the documentation and/or
12
+ * other materials provided with the distribution.
13
+ *
14
+ * Neither the name of BlueQuartz Software, the US Air Force, nor the names of its
15
+ * contributors may be used to endorse or promote products derived from this software
16
+ * without specific prior written permission.
17
+ *
18
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ *
29
+ * The code contained herein was partially funded by the followig contracts:
30
+ * United States Air Force Prime Contract FA8650-07-D-5800
31
+ * United States Air Force Prime Contract FA8650-10-D-5210
32
+ * United States Prime Contract Navy N00173-07-C-2068
33
+ *
34
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
35
35
#include " AlignSectionsMutualInformation.h"
36
36
37
37
#include < fstream>
@@ -222,7 +222,8 @@ void AlignSectionsMutualInformation::find_shifts(std::vector<int64_t>& xshifts,
222
222
DataContainer::Pointer m = getDataContainerArray ()->getDataContainer (getDataContainerName ());
223
223
224
224
int64_t totalPoints = m->getAttributeMatrix (getCellAttributeMatrixName ())->getNumberOfTuples ();
225
- m_MIFeaturesPtr = Int32ArrayType::CreateArray ((totalPoints * 1 ), " _INTERNAL_USE_ONLY_MIFeatureIds" );
225
+ m_MIFeaturesPtr = Int32ArrayType::CreateArray ((totalPoints * 1 ), " MIFeatureIds" );
226
+ m->getAttributeMatrix (getCellAttributeMatrixName ())->addAttributeArray (m_MIFeaturesPtr->getName (), m_MIFeaturesPtr);
226
227
m_MIFeaturesPtr->initializeWithZeros ();
227
228
int32_t * miFeatureIds = m_MIFeaturesPtr->getPointer (0 );
228
229
@@ -236,7 +237,9 @@ void AlignSectionsMutualInformation::find_shifts(std::vector<int64_t>& xshifts,
236
237
std::tie (udims[0 ], udims[1 ], udims[2 ]) = m->getGeometryAs <ImageGeom>()->getDimensions ();
237
238
238
239
int64_t dims[3 ] = {
239
- static_cast <int64_t >(udims[0 ]), static_cast <int64_t >(udims[1 ]), static_cast <int64_t >(udims[2 ]),
240
+ static_cast <int64_t >(udims[0 ]),
241
+ static_cast <int64_t >(udims[1 ]),
242
+ static_cast <int64_t >(udims[2 ]),
240
243
};
241
244
242
245
float disorientation = 0 .0f ;
@@ -269,6 +272,7 @@ void AlignSectionsMutualInformation::find_shifts(std::vector<int64_t>& xshifts,
269
272
{
270
273
float prog = ((float )iter / dims[2 ]) * 100 ;
271
274
QString ss = QObject::tr (" Aligning Sections || Determining Shifts || %1% Complete" ).arg (QString::number (prog, ' f' , 0 ));
275
+
272
276
notifyStatusMessage (getMessagePrefix (), getHumanLabel (), ss);
273
277
mindisorientation = std::numeric_limits<float >::max ();
274
278
slice = (dims[2 ] - 1 ) - iter;
@@ -435,13 +439,15 @@ void AlignSectionsMutualInformation::form_features_sections()
435
439
std::tie (udims[0 ], udims[1 ], udims[2 ]) = m->getGeometryAs <ImageGeom>()->getDimensions ();
436
440
437
441
int64_t dims[3 ] = {
438
- static_cast <int64_t >(udims[0 ]), static_cast <int64_t >(udims[1 ]), static_cast <int64_t >(udims[2 ]),
442
+ static_cast <int64_t >(udims[0 ]),
443
+ static_cast <int64_t >(udims[1 ]),
444
+ static_cast <int64_t >(udims[2 ]),
439
445
};
440
446
441
447
int64_t point = 0 ;
442
448
int64_t seed = 0 ;
443
449
bool noseeds = false ;
444
- int32_t featurecount = 1 ;
450
+ int32_t featureCount = 1 ;
445
451
int64_t neighbor = 0 ;
446
452
QuatF q1 = QuaternionMathF::New ();
447
453
QuatF q2 = QuaternionMathF::New ();
@@ -465,7 +471,7 @@ void AlignSectionsMutualInformation::form_features_sections()
465
471
466
472
int32_t * miFeatureIds = m_MIFeaturesPtr->getPointer (0 );
467
473
468
- std::vector<int64_t > voxelslist (initialVoxelsListSize, -1 );
474
+ std::vector<int64_t > voxelList (initialVoxelsListSize, -1 );
469
475
int64_t neighpoints[4 ] = {0 , 0 , 0 , 0 };
470
476
neighpoints[0 ] = -dims[0 ];
471
477
neighpoints[1 ] = -1 ;
@@ -479,37 +485,21 @@ void AlignSectionsMutualInformation::form_features_sections()
479
485
float prog = ((float )slice / dims[2 ]) * 100 ;
480
486
QString ss = QObject::tr (" Aligning Sections || Identifying Features on Sections || %1% Complete" ).arg (QString::number (prog, ' f' , 0 ));
481
487
notifyStatusMessage (getMessagePrefix (), getHumanLabel (), ss);
482
- featurecount = 1 ;
488
+ int64_t startPoint = slice * dims[0 ] * dims[1 ];
489
+ int64_t endPoint = (slice + 1 ) * dims[0 ] * dims[1 ];
490
+ int64_t currentStartPoint = startPoint;
491
+
492
+ featureCount = 1 ;
483
493
noseeds = false ;
484
494
while (!noseeds)
485
495
{
486
496
seed = -1 ;
487
- randx = static_cast <int64_t >(float (rg.genrand_res53 ()) * float (dims[0 ]));
488
- randy = static_cast <int64_t >(float (rg.genrand_res53 ()) * float (dims[1 ]));
489
- for (int64_t j = 0 ; j < dims[1 ]; ++j)
497
+ for (int64_t point = currentStartPoint; point < endPoint; point++)
490
498
{
491
- for ( int64_t i = 0 ; i < dims[ 0 ]; ++i )
499
+ if ((!m_UseGoodVoxels || (m_GoodVoxels != nullptr && m_GoodVoxels[point])) && miFeatureIds[point] == 0 && m_CellPhases[point] > 0 )
492
500
{
493
- x = randx + i;
494
- y = randy + j;
495
- z = slice;
496
- if (x > dims[0 ] - 1 )
497
- {
498
- x = x - dims[0 ];
499
- }
500
- if (y > dims[1 ] - 1 )
501
- {
502
- y = y - dims[1 ];
503
- }
504
- point = (z * dims[0 ] * dims[1 ]) + (y * dims[0 ]) + x;
505
- if ((!m_UseGoodVoxels || m_GoodVoxels[point]) && miFeatureIds[point] == 0 && m_CellPhases[point] > 0 )
506
- {
507
- seed = point;
508
- }
509
- if (seed > -1 )
510
- {
511
- break ;
512
- }
501
+ seed = point;
502
+ currentStartPoint = point;
513
503
}
514
504
if (seed > -1 )
515
505
{
@@ -523,37 +513,36 @@ void AlignSectionsMutualInformation::form_features_sections()
523
513
if (seed >= 0 )
524
514
{
525
515
size = 0 ;
526
- miFeatureIds[seed] = featurecount ;
527
- voxelslist [size] = seed;
516
+ miFeatureIds[seed] = featureCount ;
517
+ voxelList [size] = seed;
528
518
size++;
529
519
for (size_t j = 0 ; j < size; ++j)
530
520
{
531
- int64_t currentpoint = voxelslist [j];
521
+ int64_t currentpoint = voxelList [j];
532
522
col = currentpoint % dims[0 ];
533
523
row = (currentpoint / dims[0 ]) % dims[1 ];
534
524
QuaternionMathF::Copy (quats[currentpoint], q1);
535
525
phase1 = m_CrystalStructures[m_CellPhases[currentpoint]];
536
526
for (int32_t i = 0 ; i < 4 ; i++)
537
527
{
538
- good = true ;
539
528
neighbor = currentpoint + neighpoints[i];
540
529
if ((i == 0 ) && row == 0 )
541
530
{
542
- good = false ;
531
+ continue ;
543
532
}
544
533
if ((i == 3 ) && row == (dims[1 ] - 1 ))
545
534
{
546
- good = false ;
535
+ continue ;
547
536
}
548
537
if ((i == 1 ) && col == 0 )
549
538
{
550
- good = false ;
539
+ continue ;
551
540
}
552
541
if ((i == 2 ) && col == (dims[0 ] - 1 ))
553
542
{
554
- good = false ;
543
+ continue ;
555
544
}
556
- if (good && miFeatureIds[neighbor] <= 0 && m_CellPhases[neighbor] > 0 )
545
+ if (miFeatureIds[neighbor] <= 0 && m_CellPhases[neighbor] > 0 )
557
546
{
558
547
w = std::numeric_limits<float >::max ();
559
548
QuaternionMathF::Copy (quats[neighbor], q2);
@@ -564,28 +553,28 @@ void AlignSectionsMutualInformation::form_features_sections()
564
553
}
565
554
if (w < misorientationTolerance)
566
555
{
567
- miFeatureIds[neighbor] = featurecount ;
568
- voxelslist [size] = neighbor;
556
+ miFeatureIds[neighbor] = featureCount ;
557
+ voxelList [size] = neighbor;
569
558
size++;
570
- if (std::vector<int64_t >::size_type (size) >= voxelslist .size ())
559
+ if (std::vector<int64_t >::size_type (size) >= voxelList .size ())
571
560
{
572
- size = voxelslist .size ();
573
- voxelslist .resize (size + initialVoxelsListSize);
574
- for (std::vector<int64_t >::size_type v = size; v < voxelslist .size (); ++v)
561
+ size = voxelList .size ();
562
+ voxelList .resize (size + initialVoxelsListSize);
563
+ for (std::vector<int64_t >::size_type v = size; v < voxelList .size (); ++v)
575
564
{
576
- voxelslist [v] = -1 ;
565
+ voxelList [v] = -1 ;
577
566
}
578
567
}
579
568
}
580
569
}
581
570
}
582
571
}
583
- voxelslist .erase (std::remove (voxelslist .begin (), voxelslist .end (), -1 ), voxelslist .end ());
584
- featurecount ++;
585
- voxelslist .assign (initialVoxelsListSize, -1 );
572
+ voxelList .erase (std::remove (voxelList .begin (), voxelList .end (), -1 ), voxelList .end ());
573
+ featureCount ++;
574
+ voxelList .assign (initialVoxelsListSize, -1 );
586
575
}
587
576
}
588
- featurecounts[slice] = featurecount ;
577
+ featurecounts[slice] = featureCount ;
589
578
}
590
579
}
591
580
@@ -603,8 +592,6 @@ void AlignSectionsMutualInformation::execute()
603
592
}
604
593
605
594
AlignSections::execute ();
606
-
607
-
608
595
}
609
596
610
597
// -----------------------------------------------------------------------------
0 commit comments