Skip to content

Commit 7496946

Browse files
authored
Merge pull request #2378 from SCIInstitute/merge_v6.6.1
Merge v6.6.1 into master
2 parents 7fd76e6 + fdf7ee4 commit 7496946

22 files changed

Lines changed: 152 additions & 41 deletions

Libs/Analyze/MeshGenerator.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <QMeshWarper.h>
88
#include <SurfaceReconstructor.h>
99
#include <Utils/StringUtils.h>
10+
#include <itkConstantPadImageFilter.h>
1011
#include <itkImageFileReader.h>
1112
#include <itkOrientImageFilter.h>
1213
#include <itkPoint.h>
@@ -16,7 +17,6 @@
1617
#include <vtkPolyDataNormals.h>
1718

1819
#include <QFileInfo>
19-
#include <limits>
2020

2121
namespace shapeworks {
2222

@@ -99,12 +99,16 @@ MeshHandle MeshGenerator::build_mesh_from_image(ImageType::Pointer image, float
9999

100100
try {
101101
// only interested in 1's and 0's
102-
Image itk_image = Image(image);
103-
if (!itk_image.isDistanceTransform()) {
104-
itk_image.binarize(0, 1);
105-
image = itk_image.getITKImage();
102+
Image sw_image = Image(image);
103+
if (!sw_image.isDistanceTransform()) {
104+
sw_image.binarize();
105+
image = sw_image.getITKImage();
106106
}
107107

108+
// pad the image in case the segmentation is on the edge
109+
sw_image.pad(1);
110+
image = sw_image.getITKImage();
111+
108112
// connect to VTK
109113
vtkSmartPointer<vtkImageImport> vtk_image = vtkSmartPointer<vtkImageImport>::New();
110114
itk::VTKImageExport<ImageType>::Pointer itk_exporter = itk::VTKImageExport<ImageType>::New();
@@ -165,6 +169,8 @@ MeshHandle MeshGenerator::build_mesh_from_file(std::string filename, float iso_v
165169
}
166170
} else if (is_image) {
167171
try {
172+
ImageUtils::register_itk_factories();
173+
168174
// read file using ITK
169175
using ReaderType = itk::ImageFileReader<ImageType>;
170176
ReaderType::Pointer reader = ReaderType::New();

Libs/Analyze/MeshWorker.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ void MeshWorker::run()
1919
{
2020
// build the mesh using our MeshGenerator
2121
auto item = this->queue_->get_next_work_item();
22+
if (!item) {
23+
return;
24+
}
2225

2326
MeshHandle mesh = this->mesh_generator_->build_mesh(*item);
2427

Libs/Analyze/Shape.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,8 @@ void Shape::recompute_original_surface() {
125125
original_meshes_.set_mesh(0, mesh_handle);
126126
}
127127

128-
129128
//---------------------------------------------------------------------------
130-
void Shape::ensure_segmentation()
131-
{
129+
void Shape::ensure_segmentation() {
132130
if (get_segmentation()) {
133131
return;
134132
}
@@ -159,8 +157,7 @@ void Shape::ensure_segmentation()
159157
//---------------------------------------------------------------------------
160158
MeshGroup Shape::get_groomed_meshes(bool wait) {
161159
if (!subject_) {
162-
std::cerr << "Error: asked for groomed meshes when none are present!\n";
163-
assert(0);
160+
return {};
164161
}
165162

166163
if (!groomed_meshes_.valid() || groomed_meshes_.meshes().size() != subject_->get_number_of_domains()) {

Libs/Common/Logging.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace shapeworks {
1313
static std::string create_header(const int line, const char* filename, const char* function = "") {
1414
const char* name = (strrchr(filename, '/') ? strrchr(filename, '/') + 1 : filename);
1515
const char* name2 = (strrchr(name, '\\') ? strrchr(name, '\\') + 1 : name);
16-
const char* function_name = (strrchr(function, ':') ? strrchr(function, ':') + 1 : function);
1716
if (!function) {
1817
std::string header = "[" + std::string(name2) + "|" + std::to_string(line) + "]";
1918
return header;
2019
} else {
20+
const char* function_name = (strrchr(function, ':') ? strrchr(function, ':') + 1 : function);
2121
std::string header = "[" + std::string(name2) + "|" + std::string(function_name) + "|" + std::to_string(line) + "]";
2222
return header;
2323
}
@@ -69,6 +69,14 @@ void Logging::log_message(const std::string& message, const int line, const char
6969
}
7070
}
7171

72+
//-----------------------------------------------------------------------------
73+
void Logging::log_only(const std::string& message, const int line, const char* file) const {
74+
spd::info(message);
75+
if (log_open_) {
76+
spd::get("file")->info(message);
77+
}
78+
}
79+
7280
//-----------------------------------------------------------------------------
7381
void Logging::log_stack(const std::string& message) const {
7482
spd::error(message);

Libs/Common/Logging.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class Logging {
102102
//! Log a message, use SW_LOG macro
103103
void log_message(const std::string& message, const int line, const char* file) const;
104104

105+
//! Log a message, use SW_LOG_ONLY macro
106+
void log_only(const std::string& message, const int line, const char* file) const;
107+
105108
//! Log a stack trace message, use SW_LOG_STACK macro
106109
void log_stack(const std::string& message) const;
107110

@@ -171,6 +174,10 @@ class Logging {
171174
#define SW_LOG(message, ...) \
172175
shapeworks::Logging::Instance().log_message(safe_format(message, ##__VA_ARGS__), __LINE__, __FILE__);
173176

177+
//! Log only macro
178+
#define SW_LOG_ONLY(message, ...) \
179+
shapeworks::Logging::Instance().log_only(safe_format(message, ##__VA_ARGS__), __LINE__, __FILE__);
180+
174181
//! Log warning macro
175182
#define SW_WARN(message, ...) \
176183
shapeworks::Logging::Instance().log_warning(safe_format(message, ##__VA_ARGS__), __LINE__, __FILE__)

Libs/Groom/GroomParameters.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ class GroomParameters {
137137
bool get_skip_grooming();
138138
void set_skip_grooming(bool skip);
139139

140-
141140
bool get_shared_boundary();
142141
void set_shared_boundary(bool shared_boundary);
143142

@@ -152,6 +151,8 @@ class GroomParameters {
152151

153152
void restore_defaults();
154153

154+
Parameters get_parameters() const { return params_; }
155+
155156
// constants
156157
const static std::string GROOM_SMOOTH_VTK_LAPLACIAN_C;
157158
const static std::string GROOM_SMOOTH_VTK_WINDOWED_SINC_C;

Libs/Image/Image.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,8 @@
4444
#include "ShapeworksUtils.h"
4545
#include "itkTPGACLevelSetImageFilter.h" // actually a shapeworks class, not itk
4646

47-
// ITK image factories
48-
#include <itkMetaImageIOFactory.h>
49-
#include <itkNiftiImageIOFactory.h>
50-
#include <itkNrrdImageIOFactory.h>
51-
5247
namespace shapeworks {
5348

54-
namespace {
55-
void register_factories() {
56-
static bool registered = false;
57-
if (!registered) {
58-
// register all the factories
59-
itk::NrrdImageIOFactory::RegisterOneFactory();
60-
itk::NiftiImageIOFactory::RegisterOneFactory();
61-
itk::MetaImageIOFactory::RegisterOneFactory();
62-
registered = true;
63-
}
64-
}
65-
} // namespace
66-
6749
Image::Image(const Dims dims) : itk_image_(ImageType::New()) {
6850
ImageType::RegionType region;
6951
region.SetSize(dims);
@@ -119,7 +101,7 @@ Image& Image::operator=(Image&& img) {
119101
}
120102

121103
Image::ImageType::Pointer Image::read(const std::string& pathname) {
122-
register_factories();
104+
ImageUtils::register_itk_factories();
123105

124106
if (pathname.empty()) {
125107
throw std::invalid_argument("Empty pathname");

Libs/Image/ImageUtils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
#include <itkPointSet.h>
44

5+
// ITK image factories
6+
#include <itkMetaImageIOFactory.h>
7+
#include <itkNiftiImageIOFactory.h>
8+
#include <itkNrrdImageIOFactory.h>
9+
510
namespace shapeworks {
611

712
PhysicalRegion ImageUtils::boundingBox(const std::vector<std::string>& filenames, Image::PixelType isoValue) {
@@ -39,6 +44,18 @@ PhysicalRegion ImageUtils::boundingBox(const std::vector<std::reference_wrapper<
3944
return bbox;
4045
}
4146

47+
void ImageUtils::register_itk_factories()
48+
{
49+
static bool registered = false;
50+
if (!registered) {
51+
// register all the factories
52+
itk::NrrdImageIOFactory::RegisterOneFactory();
53+
itk::NiftiImageIOFactory::RegisterOneFactory();
54+
itk::MetaImageIOFactory::RegisterOneFactory();
55+
registered = true;
56+
}
57+
}
58+
4259
ImageUtils::TPSTransform::Pointer ImageUtils::createWarpTransform(const std::string& source_landmarks_file,
4360
const std::string& target_landmarks_file,
4461
const int stride) {

Libs/Image/ImageUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class ImageUtils {
2222
using TPSTransform = itk::ThinPlateSplineKernelTransform<double, 3>;
2323
static TPSTransform::Pointer createWarpTransform(const std::string& source_landmarks_file,
2424
const std::string& target_landmarks_file, const int stride = 1);
25+
26+
static void register_itk_factories();
27+
2528
};
2629

2730
} // namespace shapeworks

Libs/Mesh/MeshWarper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ vtkSmartPointer<vtkPolyData> MeshWarper::build_mesh(const Eigen::MatrixXd& parti
5656
//---------------------------------------------------------------------------
5757
void MeshWarper::set_reference_mesh(vtkSmartPointer<vtkPolyData> reference_mesh,
5858
const Eigen::MatrixXd& reference_particles, const Eigen::MatrixXd& landmarks) {
59+
// lock so that we don't swap out the reference mesh while we are using it
60+
std::scoped_lock lock(mutex);
61+
5962
if (this->incoming_reference_mesh_ == reference_mesh) {
6063
if (this->reference_particles_.size() == reference_particles.size()) {
6164
if (this->reference_particles_ == reference_particles && landmarks_points_ == landmarks) {

0 commit comments

Comments
 (0)