Skip to content

Commit 81e4283

Browse files
committed
AlignSectionsMutualInformatio: fix bad segmentation Algorithm
Signed-off-by: Michael Jackson <mike.jackson@bluequartz.net>
1 parent 7c68b13 commit 81e4283

File tree

2 files changed

+84
-86
lines changed

2 files changed

+84
-86
lines changed

Documentation/ReferenceManual/5_ReleaseNotes/ReleaseNotes_6_5_0.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@ The developers of DREAM.3D maintain a pair of Google Groups for discussions on t
1111
[DREAM.3D Developers List](https://groups.google.com/forum/?hl=en#!forum/dream3d-developers)
1212

1313

14+
## Version 6.5.XX ##
15+
16+
### 6.5.XX Fixed DREAM3D Issues ###
17+
18+
+ Adjusted segmentation algorithm in AlignSectionsMutualInformation to remove the random seed value generation. We just start in the 0,0 position and start looking for a viable voxel.
19+
+ Fixed issue validating mu values in `GeneratePrimaryStatsData` filter
20+
+ Fixed crash if user changes phase name in `GeneratePrimaryStatsData` filter
21+
22+
### SIMPL Changes ###
23+
24+
1425

1526
## Version 6.5.168 ##
1627

17-
### 6.5.169 Fixed DREAM3D Issues ###
28+
### 6.5.168 Fixed DREAM3D Issues ###
1829

1930
+ Fixed issue where the OrientationUtility stopped working due to move to Qt 5.15
2031
+ Fixed crashing issue in OrientationUtility if invalid Quaternion was generated

Source/Plugins/Reconstruction/ReconstructionFilters/AlignSectionsMutualInformation.cpp

Lines changed: 72 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
/* ============================================================================
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+
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
3535
#include "AlignSectionsMutualInformation.h"
3636

3737
#include <fstream>
@@ -222,7 +222,8 @@ void AlignSectionsMutualInformation::find_shifts(std::vector<int64_t>& xshifts,
222222
DataContainer::Pointer m = getDataContainerArray()->getDataContainer(getDataContainerName());
223223

224224
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);
226227
m_MIFeaturesPtr->initializeWithZeros();
227228
int32_t* miFeatureIds = m_MIFeaturesPtr->getPointer(0);
228229

@@ -236,7 +237,9 @@ void AlignSectionsMutualInformation::find_shifts(std::vector<int64_t>& xshifts,
236237
std::tie(udims[0], udims[1], udims[2]) = m->getGeometryAs<ImageGeom>()->getDimensions();
237238

238239
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]),
240243
};
241244

242245
float disorientation = 0.0f;
@@ -269,6 +272,7 @@ void AlignSectionsMutualInformation::find_shifts(std::vector<int64_t>& xshifts,
269272
{
270273
float prog = ((float)iter / dims[2]) * 100;
271274
QString ss = QObject::tr("Aligning Sections || Determining Shifts || %1% Complete").arg(QString::number(prog, 'f', 0));
275+
272276
notifyStatusMessage(getMessagePrefix(), getHumanLabel(), ss);
273277
mindisorientation = std::numeric_limits<float>::max();
274278
slice = (dims[2] - 1) - iter;
@@ -435,13 +439,15 @@ void AlignSectionsMutualInformation::form_features_sections()
435439
std::tie(udims[0], udims[1], udims[2]) = m->getGeometryAs<ImageGeom>()->getDimensions();
436440

437441
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]),
439445
};
440446

441447
int64_t point = 0;
442448
int64_t seed = 0;
443449
bool noseeds = false;
444-
int32_t featurecount = 1;
450+
int32_t featureCount = 1;
445451
int64_t neighbor = 0;
446452
QuatF q1 = QuaternionMathF::New();
447453
QuatF q2 = QuaternionMathF::New();
@@ -465,7 +471,7 @@ void AlignSectionsMutualInformation::form_features_sections()
465471

466472
int32_t* miFeatureIds = m_MIFeaturesPtr->getPointer(0);
467473

468-
std::vector<int64_t> voxelslist(initialVoxelsListSize, -1);
474+
std::vector<int64_t> voxelList(initialVoxelsListSize, -1);
469475
int64_t neighpoints[4] = {0, 0, 0, 0};
470476
neighpoints[0] = -dims[0];
471477
neighpoints[1] = -1;
@@ -479,37 +485,21 @@ void AlignSectionsMutualInformation::form_features_sections()
479485
float prog = ((float)slice / dims[2]) * 100;
480486
QString ss = QObject::tr("Aligning Sections || Identifying Features on Sections || %1% Complete").arg(QString::number(prog, 'f', 0));
481487
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;
483493
noseeds = false;
484494
while(!noseeds)
485495
{
486496
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++)
490498
{
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)
492500
{
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;
513503
}
514504
if(seed > -1)
515505
{
@@ -523,37 +513,36 @@ void AlignSectionsMutualInformation::form_features_sections()
523513
if(seed >= 0)
524514
{
525515
size = 0;
526-
miFeatureIds[seed] = featurecount;
527-
voxelslist[size] = seed;
516+
miFeatureIds[seed] = featureCount;
517+
voxelList[size] = seed;
528518
size++;
529519
for(size_t j = 0; j < size; ++j)
530520
{
531-
int64_t currentpoint = voxelslist[j];
521+
int64_t currentpoint = voxelList[j];
532522
col = currentpoint % dims[0];
533523
row = (currentpoint / dims[0]) % dims[1];
534524
QuaternionMathF::Copy(quats[currentpoint], q1);
535525
phase1 = m_CrystalStructures[m_CellPhases[currentpoint]];
536526
for(int32_t i = 0; i < 4; i++)
537527
{
538-
good = true;
539528
neighbor = currentpoint + neighpoints[i];
540529
if((i == 0) && row == 0)
541530
{
542-
good = false;
531+
continue;
543532
}
544533
if((i == 3) && row == (dims[1] - 1))
545534
{
546-
good = false;
535+
continue;
547536
}
548537
if((i == 1) && col == 0)
549538
{
550-
good = false;
539+
continue;
551540
}
552541
if((i == 2) && col == (dims[0] - 1))
553542
{
554-
good = false;
543+
continue;
555544
}
556-
if(good && miFeatureIds[neighbor] <= 0 && m_CellPhases[neighbor] > 0)
545+
if(miFeatureIds[neighbor] <= 0 && m_CellPhases[neighbor] > 0)
557546
{
558547
w = std::numeric_limits<float>::max();
559548
QuaternionMathF::Copy(quats[neighbor], q2);
@@ -564,28 +553,28 @@ void AlignSectionsMutualInformation::form_features_sections()
564553
}
565554
if(w < misorientationTolerance)
566555
{
567-
miFeatureIds[neighbor] = featurecount;
568-
voxelslist[size] = neighbor;
556+
miFeatureIds[neighbor] = featureCount;
557+
voxelList[size] = neighbor;
569558
size++;
570-
if(std::vector<int64_t>::size_type(size) >= voxelslist.size())
559+
if(std::vector<int64_t>::size_type(size) >= voxelList.size())
571560
{
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)
575564
{
576-
voxelslist[v] = -1;
565+
voxelList[v] = -1;
577566
}
578567
}
579568
}
580569
}
581570
}
582571
}
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);
586575
}
587576
}
588-
featurecounts[slice] = featurecount;
577+
featurecounts[slice] = featureCount;
589578
}
590579
}
591580

@@ -603,8 +592,6 @@ void AlignSectionsMutualInformation::execute()
603592
}
604593

605594
AlignSections::execute();
606-
607-
608595
}
609596

610597
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)