Skip to content

Commit 6f7419d

Browse files
authored
Merge pull request #1 from pyushkevich/JLasserv-master
J lasserv master
2 parents c092ba0 + f59c004 commit 6f7419d

File tree

13 files changed

+85
-121
lines changed

13 files changed

+85
-121
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#--------------------------------------------------------------------------------
23
# PROJECT: SNAP
34
#--------------------------------------------------------------------------------

Common/Minzip/crypt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
6464
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
6565
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
6666
{
67-
register int keyshift = (int)((*(pkeys+1)) >> 24);
67+
int keyshift = (int)((*(pkeys+1)) >> 24);
6868
(*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift);
6969
}
7070
return c;

Common/Minzip/miniunz.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <errno.h>
1616
#include <fcntl.h>
1717

18+
#ifdef __APPLE__
19+
#include <sys/stat.h>
20+
#endif
21+
1822
#ifdef unix
1923
# include <unistd.h>
2024
# include <utime.h>
@@ -336,7 +340,7 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
336340
{
337341
char c=*(filename_withoutpath-1);
338342
*(filename_withoutpath-1)='\0';
339-
makedir(write_filename);
343+
makedir((char *)(write_filename));
340344
*(filename_withoutpath-1)=c;
341345
fout=fopen(write_filename,"wb");
342346
}

Common/Minzip/miniunz.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
#ifndef _miniumz_H
1+
#ifndef _miniunz_H
22
#define _miniunz_H
33

44

55
#ifdef __cplusplus
66
extern "C" {
77
#endif
88

9+
#ifdef __APPLE__
10+
#define unix
11+
#endif
12+
913
#ifdef unix
1014
# include <unistd.h>
1115
# include <utime.h>

Common/SNAPOpenGL.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#ifndef __SNAPOpenGL_h_
3636
#define __SNAPOpenGL_h_
3737

38+
// Prevent errors due to OpenGL having moved on...
39+
#define GL_SILENCE_DEPRECATION
3840

3941
#include "IRISVectorTypes.h"
4042

GUI/Model/InterpolateLabelModel.cxx

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ScalarImageWrapper.h"
66
#include "itkMorphologicalContourInterpolator.h"
77
#include "SegmentationUpdateIterator.h"
8+
#include "itkBinaryThresholdImageFilter.h"
89

910
void InterpolateLabelModel::SetParentModel(GlobalUIModel *parent)
1011
{
@@ -23,6 +24,18 @@ void InterpolateLabelModel::UpdateOnShow()
2324
this->SetDrawOverFilter(m_Parent->GetGlobalState()->GetDrawOverFilter());
2425
}
2526

27+
template <class TLabel>
28+
class BinarizeFunctor
29+
{
30+
public:
31+
void SetLabel(const TLabel &l) { m_Label = l; }
32+
33+
TLabel operator()(const TLabel &in) { return (in == m_Label) ? m_Label : 0; }
34+
bool operator != (const BinarizeFunctor<TLabel> &other ) { return m_Label != other.m_Label; }
35+
private:
36+
TLabel m_Label;
37+
};
38+
2639
void InterpolateLabelModel::Interpolate()
2740
{
2841
// Get the segmentation wrapper
@@ -35,11 +48,28 @@ void InterpolateLabelModel::Interpolate()
3548
// Are we interpolating all labels?
3649
bool interp_all = this->GetInterpolateAll();
3750

38-
mci->SetInput(liw->GetImage());
39-
40-
// Should we be interpolating a specific label?
41-
if (!interp_all)
51+
// Should we be interpolating a specific label or all labels?
52+
if(interp_all)
53+
{
54+
mci->SetInput(liw->GetImage());
55+
}
56+
else
57+
{
58+
// We need to extract a single component from the segmentation image to interpolate
59+
typedef GenericImageData::LabelImageType LabelImageType;
60+
typedef BinarizeFunctor<LabelType> FunctorType;
61+
typedef itk::UnaryFunctorImageFilter<LabelImageType, LabelImageType, FunctorType> BinarizeFilterType;
62+
typename BinarizeFilterType::Pointer flt = BinarizeFilterType::New();
63+
64+
FunctorType fn;
65+
fn.SetLabel(this->GetInterpolateLabel());
66+
flt->SetInput(liw->GetImage());
67+
flt->SetFunctor(fn);
68+
flt->Update();
69+
70+
mci->SetInput(flt->GetOutput());
4271
mci->SetLabel(this->GetInterpolateLabel());
72+
}
4373

4474
// Should we interpolate only one axis?
4575
if (this->GetMorphologyInterpolateOneAxis())
@@ -56,7 +86,7 @@ void InterpolateLabelModel::Interpolate()
5686

5787
// Update the filter
5888
mci->Update();
59-
89+
6090
// Apply the labels back to the segmentation
6191
SegmentationUpdateIterator it_trg(liw->GetImage(), liw->GetImage()->GetBufferedRegion(),
6292
this->GetDrawingLabel(), this->GetDrawOverFilter());
@@ -74,17 +104,19 @@ void InterpolateLabelModel::Interpolate()
74104
}
75105
else
76106
{
107+
LabelType l_interp = this->GetInterpolateLabel();
77108
LabelType l_replace = this->GetDrawingLabel();
78109
for(; !it_trg.IsAtEnd(); ++it_trg, ++it_src)
79-
it_trg.PaintLabelWithExtraProtection(it_src.Get(), l_replace);
110+
if(it_src.Get() == l_interp)
111+
it_trg.PaintLabelWithExtraProtection(l_interp, l_replace);
80112
}
81113

82114
// Finish the segmentation editing and create an undo point
83115
it_trg.Finalize();
84116
liw->StoreUndoPoint("Interpolate label", it_trg.RelinquishDelta());
85117

86-
// TODO: this should not be needed because this should propagate from wrapper
87-
// this->m_Parent->GetDriver()->InvokeEvent(SegmentationChangeEvent());
118+
// Fire event to inform GUI that segmentation has changed
119+
this->m_Parent->GetDriver()->InvokeEvent(SegmentationChangeEvent());
88120
}
89121

90122

GUI/Model/InterpolateLabelModel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ class InterpolateLabelModel : public AbstractPropertyContainerModel
9393

9494
typedef ConcretePropertyModel<InterpolationType, TrivialDomain> ConcreteInterpolationType;
9595
SmartPtr<ConcreteInterpolationType> m_InterpolationMethodModel;
96-
96+
97+
// Templated code to interpolate an image
98+
template <class TImage> void DoInterpolate(TImage *image);
9799

98100
// The parent model
99101
GlobalUIModel *m_Parent;

GUI/Qt/Windows/InterpolateLabelsDialog.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void InterpolateLabelsDialog::SetModel(InterpolateLabelModel *model)
2828

2929
makeCoupling(ui->inActiveLabel, m_Model->GetDrawingLabelModel());
3030
makeCoupling(ui->inLabelToInterpolate, m_Model->GetInterpolateLabelModel());
31+
makeCoupling(ui->inDrawOverFilter, m_Model->GetDrawOverFilterModel());
3132

3233
makeRadioGroupCoupling(ui->btnInterpolateAll, ui->btnInterpolateOne, m_Model->GetInterpolateAllModel());
3334

GUI/Qt/Windows/InterpolateLabelsDialog.ui

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ color: gray;</string>
8989
<item row="3" column="0">
9090
<widget class="QLabel" name="label_4">
9191
<property name="text">
92-
<string>Interpolate with:</string>
92+
<string>Paint with label:</string>
9393
</property>
9494
</widget>
9595
</item>
@@ -100,6 +100,20 @@ color: gray;</string>
100100
</property>
101101
</widget>
102102
</item>
103+
<item row="4" column="1">
104+
<widget class="QComboBox" name="inDrawOverFilter">
105+
<property name="toolTip">
106+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Select which label of set of labels will be painted over during interpolation. You can paint over all labels, clear voxels, or a specific label.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
107+
</property>
108+
</widget>
109+
</item>
110+
<item row="4" column="0">
111+
<widget class="QLabel" name="label_5">
112+
<property name="text">
113+
<string>Paint over label(s):</string>
114+
</property>
115+
</widget>
116+
</item>
103117
</layout>
104118
</widget>
105119
</item>

GUI/Qt/Windows/MainImageWindow.cxx

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,115 +1068,12 @@ SliceViewPanel * MainImageWindow::GetSlicePanel(unsigned int i)
10681068

10691069
void MainImageWindow::remove_dir(const std::string path)
10701070
{
1071-
#ifdef WIN32
1072-
WIN32_FIND_DATA ffd;
1073-
TCHAR szDir[MAX_PATH];
1074-
HANDLE hFind = INVALID_HANDLE_VALUE;
1075-
1076-
// Prepare string for use with FindFile functions. First, copy the
1077-
// string to a buffer, then append '\*' to the directory name.
1078-
StringCchCopy(szDir, MAX_PATH, path.c_str());
1079-
StringCchCat(szDir, MAX_PATH, TEXT("\\*"));
1080-
1081-
// Find the first file in the directory.
1082-
hFind = FindFirstFile(szDir, &ffd);
1083-
1084-
1085-
while (FindNextFile(hFind, &ffd) != 0)
1086-
{
1087-
// If the directory contains a directory, we empty it
1088-
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1089-
{
1090-
if (strcmp(ffd.cFileName, ".") != 0 & strcmp(ffd.cFileName, "..") != 0) {
1091-
std::string new_path = path + "\\" + ffd.cFileName;
1092-
if (_rmdir(new_path.c_str()) == -1) { // Error while removing the directory
1093-
if (errno == ENOTEMPTY) {
1094-
//Open the subdirectory to delete files
1095-
remove_dir(new_path);
1096-
}
1097-
}
1098-
}
1099-
}
1100-
else //Remove files
1101-
{
1102-
std::string new_path = path + "\\" + ffd.cFileName;
1103-
remove(new_path.c_str());
1104-
}
1105-
}
1106-
//Remove the folder once it's empty
1107-
if (FindNextFile(hFind, &ffd) == 0) {
1108-
_rmdir(path.c_str());
1109-
}
1110-
FindClose(hFind);
1111-
1112-
#else
1113-
DIR* dir;
1114-
DIR* subdir;
1115-
struct dirent* ent;
1116-
if ((dir = opendir(path.c_str())) != NULL) {
1117-
while ((ent = readdir(dir)) != NULL) {
1118-
std::string file = std::string(path) + "/" + std::string(ent->d_name);
1119-
// If the folder contains a folder:
1120-
if ((subdir = opendir(file.c_str())) != NULL) {
1121-
closedir(subdir);
1122-
remove_dir(file.c_str());
1123-
1124-
}
1125-
else {
1126-
remove(file.c_str());
1127-
}
1128-
}
1129-
closedir(dir);
1130-
}
1131-
#endif
1071+
m_Model->GetDriver()->remove_dir(path);
11321072
}
11331073

11341074
void MainImageWindow::cleanUp_tempdir(void)
11351075
{
1136-
#ifdef WIN32
1137-
char tempDir[_MAX_PATH + 1] = "";
1138-
// First call return a directory only
1139-
DWORD length = GetTempPath(_MAX_PATH+1, tempDir);
1140-
WIN32_FIND_DATA ffd;
1141-
TCHAR szDir[MAX_PATH];
1142-
HANDLE hFind = INVALID_HANDLE_VALUE;
1143-
1144-
// Prepare string for use with FindFile functions. First, copy the
1145-
// string to a buffer, then append '\*' to the directory name.
1146-
StringCchCopy(szDir, MAX_PATH, tempDir);
1147-
StringCchCat(szDir, MAX_PATH, TEXT("\\*"));
1148-
1149-
// Find the first file in the directory.
1150-
hFind = FindFirstFile(szDir, &ffd);
1151-
1152-
1153-
while (FindNextFile(hFind, &ffd) != 0)
1154-
{
1155-
std::size_t find_zip = std::string(ffd.cFileName).find("ZIP");
1156-
if (find_zip != std::string::npos) {
1157-
std::string path = tempDir + std::string(ffd.cFileName);
1158-
remove_dir(path);
1159-
}
1160-
}
1161-
1162-
1163-
#else
1164-
//Find the folders extracted into temp directory
1165-
DIR* dir;
1166-
struct dirent* ent;
1167-
std::string path;
1168-
if ((dir = opendir("/tmp")) != NULL) {
1169-
while ((ent = readdir (dir)) != NULL) {
1170-
//Find the extracted folders
1171-
std::size_t find_zip = std::string(ent->d_name).find("ZIPDIR");
1172-
if (find_zip != std::string::npos) {
1173-
path = "/tmp/" + std::string(ent->d_name);
1174-
remove_dir(path);
1175-
}
1176-
}
1177-
closedir(dir);
1178-
}
1179-
#endif
1076+
m_Model->GetDriver()->cleanUp_tempdir();
11801077
}
11811078

11821079
void MainImageWindow::closeEvent(QCloseEvent *event)

0 commit comments

Comments
 (0)