Skip to content

Commit

Permalink
- Fixed executable use of shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
GeertLitjens committed Apr 30, 2016
1 parent 61d549a commit 77e987a
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 61 deletions.
3 changes: 1 addition & 2 deletions executables/WSIArithmetic/WSIArithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
return 1;
}
MultiResolutionImageReader reader;
MultiResolutionImage* input = reader.open(inputPth);
std::shared_ptr<MultiResolutionImage> input = std::shared_ptr<MultiResolutionImage>(reader.open(inputPth));
CmdLineProgressMonitor monitor;
if (input) {
ArithmeticWholeSlideFilter fltr;
Expand All @@ -72,7 +72,6 @@ int main(int argc, char *argv[]) {
if (!fltr.process()) {
std::cerr << "ERROR: Processing failed" << std::endl;
}
delete input;
}
else {
std::cerr << "ERROR: Invalid input image" << std::endl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
return 1;
}
MultiResolutionImageReader reader;
MultiResolutionImage* input = reader.open(inputPth);
std::shared_ptr<MultiResolutionImage> input = std::shared_ptr<MultiResolutionImage>(reader.open(inputPth));
CmdLineProgressMonitor monitor;
if (input) {
ConnectedComponentsWholeSlideFilter fltr;
Expand All @@ -69,7 +69,6 @@ int main(int argc, char *argv[]) {
if (!fltr.process()) {
std::cerr << "ERROR: Processing failed" << std::endl;
}
delete input;
}
else {
std::cerr << "ERROR: Invalid input image" << std::endl;
Expand Down
3 changes: 1 addition & 2 deletions executables/WSIDistanceTransform/WSIDistanceTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
return 1;
}
MultiResolutionImageReader reader;
MultiResolutionImage* input = reader.open(inputPth);
std::shared_ptr<MultiResolutionImage> input = std::shared_ptr<MultiResolutionImage>(reader.open(inputPth));
CmdLineProgressMonitor monitor;
if (input) {
DistanceTransformWholeSlideFilter fltr;
Expand All @@ -70,7 +70,6 @@ int main(int argc, char *argv[]) {
if (!fltr.process()) {
std::cerr << "ERROR: Processing failed" << std::endl;
}
delete input;
}
else {
std::cerr << "ERROR: Invalid input image" << std::endl;
Expand Down
3 changes: 1 addition & 2 deletions executables/WSILabelStatistics/WSILabelStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
return 1;
}
MultiResolutionImageReader reader;
MultiResolutionImage* input = reader.open(inputPth);
std::shared_ptr<MultiResolutionImage> input = std::shared_ptr<MultiResolutionImage>(reader.open(inputPth));
CmdLineProgressMonitor monitor;
if (input) {
LabelStatisticsWholeSlideFilter fltr;
Expand All @@ -70,7 +70,6 @@ int main(int argc, char *argv[]) {
if (!fltr.process()) {
std::cerr << "ERROR: Processing failed" << std::endl;
}
delete input;
}
else {
std::cerr << "ERROR: Invalid input image" << std::endl;
Expand Down
5 changes: 2 additions & 3 deletions executables/WSIThreshold/WSIThreshold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ int main(int argc, char *argv[]) {
std::cerr << "Use -h or --help for usage information" << std::endl;
return 1;
}
MultiResolutionImageReader reader;
MultiResolutionImage* input = reader.open(inputPth);
MultiResolutionImageReader reader;
std::shared_ptr<MultiResolutionImage> input = std::shared_ptr<MultiResolutionImage>(reader.open(inputPth));
CmdLineProgressMonitor monitor;
if (input) {
ThresholdWholeSlideFilter fltr;
Expand All @@ -77,7 +77,6 @@ int main(int argc, char *argv[]) {
if (!fltr.process()) {
std::cerr << "ERROR: Processing failed" << std::endl;
}
delete input;
}
else {
std::cerr << "ERROR: Invalid input image" << std::endl;
Expand Down
13 changes: 6 additions & 7 deletions imgproc/wholeslide/ArithmeticWholeSlideFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <iostream>

ArithmeticWholeSlideFilter::ArithmeticWholeSlideFilter() :
_input(NULL),
_monitor(NULL),
_processedLevel(0),
_outPath(""),
Expand All @@ -20,10 +19,9 @@ _expression("")
}

ArithmeticWholeSlideFilter::~ArithmeticWholeSlideFilter() {
_input = NULL;
}

void ArithmeticWholeSlideFilter::setInput(MultiResolutionImage* const input) {
void ArithmeticWholeSlideFilter::setInput(const std::shared_ptr<MultiResolutionImage>& input) {
_input = input;
}

Expand Down Expand Up @@ -56,16 +54,17 @@ std::string ArithmeticWholeSlideFilter::getExpression() const {
}

bool ArithmeticWholeSlideFilter::process() {
std::vector<unsigned long long> dims = this->_input->getLevelDimensions(this->_processedLevel);
double downsample = this->_input->getLevelDownsample(this->_processedLevel);
std::shared_ptr<MultiResolutionImage> img = _input.lock();
std::vector<unsigned long long> dims = img->getLevelDimensions(this->_processedLevel);
double downsample = img->getLevelDownsample(this->_processedLevel);

MultiResolutionImageWriter writer;
writer.setColorType(pathology::ColorType::Monochrome);
writer.setCompression(pathology::Compression::LZW);
writer.setDataType(pathology::DataType::UInt32);
writer.setInterpolation(pathology::Interpolation::NearestNeighbor);
writer.setTileSize(512);
std::vector<double> spacing = _input->getSpacing();
std::vector<double> spacing = img->getSpacing();
if (!spacing.empty()) {
spacing[0] *= downsample;
spacing[1] *= downsample;
Expand All @@ -89,7 +88,7 @@ bool ArithmeticWholeSlideFilter::process() {
unsigned int* out_tile = new unsigned int[512 * 512];
for (unsigned long long t_y = 0; t_y < dims[1]; t_y += 512) {
for (unsigned long long t_x = 0; t_x < dims[0]; t_x += 512) {
this->_input->getRawRegion<unsigned int>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
img->getRawRegion<unsigned int>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
for (unsigned int y = 0; y < 512; ++y) {
for (unsigned int x = 0; x < 512; ++x) {
float curVal = tile[y * 512 + x];
Expand Down
5 changes: 3 additions & 2 deletions imgproc/wholeslide/ArithmeticWholeSlideFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <string>
#include <vector>
#include <map>
#include <memory>

class MultiResolutionImage;
class ProgressMonitor;

class EXPORT_WHOLESLIDEFILTERS ArithmeticWholeSlideFilter {

private:
MultiResolutionImage* _input;
std::weak_ptr<MultiResolutionImage> _input;
ProgressMonitor* _monitor;
unsigned int _processedLevel;
std::string _outPath;
Expand All @@ -22,7 +23,7 @@ class EXPORT_WHOLESLIDEFILTERS ArithmeticWholeSlideFilter {
ArithmeticWholeSlideFilter();
virtual ~ArithmeticWholeSlideFilter();

void setInput(MultiResolutionImage* const input);
void setInput(const std::shared_ptr<MultiResolutionImage>& input);
void setProcessedLevel(const unsigned int processedLevel);
unsigned int getProcessedLevel();
void setProgressMonitor(ProgressMonitor* progressMonitor);
Expand Down
13 changes: 6 additions & 7 deletions imgproc/wholeslide/ConnectedComponentsWholeSlideFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ void ConnectedComponentsWholeSlideFilter::DisjointSet::addElements(int numToAdd)
}

ConnectedComponentsWholeSlideFilter::ConnectedComponentsWholeSlideFilter() :
_input(NULL),
_monitor(NULL),
_processedLevel(0),
_outPath(""),
Expand All @@ -121,10 +120,9 @@ _threshold(0.5)
}

ConnectedComponentsWholeSlideFilter::~ConnectedComponentsWholeSlideFilter() {
_input = NULL;
}

void ConnectedComponentsWholeSlideFilter::setInput(MultiResolutionImage* const input) {
void ConnectedComponentsWholeSlideFilter::setInput(const std::shared_ptr<MultiResolutionImage>& input) {
_input = input;
}

Expand Down Expand Up @@ -157,16 +155,17 @@ float ConnectedComponentsWholeSlideFilter::getThreshold() {
}

bool ConnectedComponentsWholeSlideFilter::process() const {
std::vector<unsigned long long> dims = this->_input->getLevelDimensions(this->_processedLevel);
double downsample = this->_input->getLevelDownsample(this->_processedLevel);
std::shared_ptr<MultiResolutionImage> img = _input.lock();
std::vector<unsigned long long> dims = img->getLevelDimensions(this->_processedLevel);
double downsample = img->getLevelDownsample(this->_processedLevel);

MultiResolutionImageWriter writer;
writer.setColorType(pathology::ColorType::Monochrome);
writer.setCompression(pathology::Compression::LZW);
writer.setDataType(pathology::DataType::UInt32);
writer.setInterpolation(pathology::Interpolation::NearestNeighbor);
writer.setTileSize(512);
std::vector<double> spacing = _input->getSpacing();
std::vector<double> spacing = img->getSpacing();
if (!spacing.empty()) {
spacing[0] *= downsample;
spacing[1] *= downsample;
Expand Down Expand Up @@ -197,7 +196,7 @@ bool ConnectedComponentsWholeSlideFilter::process() const {
for (unsigned long long t_y = 0; t_y < dims[1]; t_y += 512) {
std::fill(buffer_t_x, buffer_t_x + 512, 0);
for (unsigned long long t_x = 0; t_x < dims[0]; t_x += 512) {
this->_input->getRawRegion<float>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
img->getRawRegion<float>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
std::fill(label_tile, label_tile + 512 * 512, 0);
for (int y = 0; y < 512; ++y) {
for (int x = 0; x < 512; ++x) {
Expand Down
5 changes: 3 additions & 2 deletions imgproc/wholeslide/ConnectedComponentsWholeSlideFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include "config/pathology_config.h"
#include <string>
#include <vector>
#include <memory>

class MultiResolutionImage;
class ProgressMonitor;

class EXPORT_WHOLESLIDEFILTERS ConnectedComponentsWholeSlideFilter {

private:
MultiResolutionImage* _input;
std::weak_ptr<MultiResolutionImage> _input;
ProgressMonitor* _monitor;
unsigned int _processedLevel;
std::string _outPath;
Expand Down Expand Up @@ -62,7 +63,7 @@ class EXPORT_WHOLESLIDEFILTERS ConnectedComponentsWholeSlideFilter {
ConnectedComponentsWholeSlideFilter();
virtual ~ConnectedComponentsWholeSlideFilter();

void setInput(MultiResolutionImage* const input);
void setInput(const std::shared_ptr<MultiResolutionImage>& input);
void setProcessedLevel(const unsigned int processedLevel);
unsigned int getProcessedLevel();
void setProgressMonitor(ProgressMonitor* progressMonitor);
Expand Down
13 changes: 6 additions & 7 deletions imgproc/wholeslide/DistanceTransformWholeSlideFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <set>

DistanceTransformWholeSlideFilter::DistanceTransformWholeSlideFilter() :
_input(NULL),
_monitor(NULL),
_processedLevel(0),
_outPath("")
Expand All @@ -16,10 +15,9 @@ _outPath("")
}

DistanceTransformWholeSlideFilter::~DistanceTransformWholeSlideFilter() {
_input = NULL;
}

void DistanceTransformWholeSlideFilter::setInput(MultiResolutionImage* const input) {
void DistanceTransformWholeSlideFilter::setInput(const std::shared_ptr<MultiResolutionImage>& input) {
_input = input;
}

Expand All @@ -44,16 +42,17 @@ ProgressMonitor* DistanceTransformWholeSlideFilter::getProgressMonitor() {
}

bool DistanceTransformWholeSlideFilter::process() const {
std::vector<unsigned long long> dims = this->_input->getLevelDimensions(this->_processedLevel);
double downsample = this->_input->getLevelDownsample(this->_processedLevel);
std::shared_ptr<MultiResolutionImage> img = _input.lock();
std::vector<unsigned long long> dims = img->getLevelDimensions(this->_processedLevel);
double downsample = img->getLevelDownsample(this->_processedLevel);

MultiResolutionImageWriter writer;
writer.setColorType(pathology::ColorType::Monochrome);
writer.setCompression(pathology::Compression::LZW);
writer.setDataType(pathology::DataType::UInt32);
writer.setInterpolation(pathology::Interpolation::NearestNeighbor);
writer.setTileSize(512);
std::vector<double> spacing = _input->getSpacing();
std::vector<double> spacing = img->getSpacing();
if (!spacing.empty()) {
spacing[0] *= downsample;
spacing[1] *= downsample;
Expand Down Expand Up @@ -83,7 +82,7 @@ bool DistanceTransformWholeSlideFilter::process() const {
for (unsigned long long t_y = 0; t_y < dims[1]; t_y += 512) {
std::fill(buffer_t_x, buffer_t_x + 512, maxDist);
for (unsigned long long t_x = 0; t_x < dims[0]; t_x += 512) {
this->_input->getRawRegion<unsigned char>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
img->getRawRegion<unsigned char>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
std::fill(out_tile, out_tile + 512 * 512, (dims[0] + dims[1] / 2) + 1);
int startX = 0;
int startY = 0;
Expand Down
5 changes: 3 additions & 2 deletions imgproc/wholeslide/DistanceTransformWholeSlideFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include "config/pathology_config.h"
#include <string>
#include <vector>
#include <memory>

class MultiResolutionImage;
class ProgressMonitor;

class EXPORT_WHOLESLIDEFILTERS DistanceTransformWholeSlideFilter {

private:
MultiResolutionImage* _input;
std::weak_ptr<MultiResolutionImage> _input;
ProgressMonitor* _monitor;
unsigned int _processedLevel;
std::string _outPath;
Expand All @@ -20,7 +21,7 @@ class EXPORT_WHOLESLIDEFILTERS DistanceTransformWholeSlideFilter {
DistanceTransformWholeSlideFilter();
virtual ~DistanceTransformWholeSlideFilter();

void setInput(MultiResolutionImage* const input);
void setInput(const std::shared_ptr<MultiResolutionImage>& input);
void setProcessedLevel(const unsigned int processedLevel);
unsigned int getProcessedLevel();
void setProgressMonitor(ProgressMonitor* progressMonitor);
Expand Down
11 changes: 5 additions & 6 deletions imgproc/wholeslide/LabelStatisticsWholeSlideFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <iostream>

LabelStatisticsWholeSlideFilter::LabelStatisticsWholeSlideFilter() :
_input(NULL),
_monitor(NULL),
_processedLevel(0),
_outPath("")
Expand All @@ -18,10 +17,9 @@ _outPath("")
}

LabelStatisticsWholeSlideFilter::~LabelStatisticsWholeSlideFilter() {
_input = NULL;
}

void LabelStatisticsWholeSlideFilter::setInput(MultiResolutionImage* const input) {
void LabelStatisticsWholeSlideFilter::setInput(const std::shared_ptr<MultiResolutionImage>& input) {
_input = input;
}

Expand Down Expand Up @@ -51,8 +49,9 @@ std::vector<std::vector<float> > LabelStatisticsWholeSlideFilter::getLabelStatis

bool LabelStatisticsWholeSlideFilter::process() {
_labelStats.clear();
std::vector<unsigned long long> dims = this->_input->getLevelDimensions(this->_processedLevel);
double downsample = this->_input->getLevelDownsample(this->_processedLevel);
std::shared_ptr<MultiResolutionImage> img = _input.lock();
std::vector<unsigned long long> dims = img->getLevelDimensions(this->_processedLevel);
double downsample = img->getLevelDownsample(this->_processedLevel);

std::ofstream csvfile;
if (!_outPath.empty()) {
Expand All @@ -66,7 +65,7 @@ bool LabelStatisticsWholeSlideFilter::process() {
unsigned int* tile = new unsigned int[512 * 512];
for (unsigned long long t_y = 0; t_y < dims[1]; t_y += 512) {
for (unsigned long long t_x = 0; t_x < dims[0]; t_x += 512) {
this->_input->getRawRegion<unsigned int>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
img->getRawRegion<unsigned int>(static_cast<unsigned long long>(t_x*downsample), static_cast<unsigned long long>(t_y*downsample), 512, 512, this->_processedLevel, tile);
for (unsigned int y = 0; y < 512; ++y) {
for (unsigned int x = 0; x < 512; ++x) {
unsigned int curVal = tile[y * 512 + x];
Expand Down
5 changes: 3 additions & 2 deletions imgproc/wholeslide/LabelStatisticsWholeSlideFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#include <string>
#include <vector>
#include <map>
#include <memory>

class MultiResolutionImage;
class ProgressMonitor;

class EXPORT_WHOLESLIDEFILTERS LabelStatisticsWholeSlideFilter {

private:
MultiResolutionImage* _input;
std::weak_ptr<MultiResolutionImage> _input;
ProgressMonitor* _monitor;
unsigned int _processedLevel;
std::string _outPath;
Expand All @@ -22,7 +23,7 @@ class EXPORT_WHOLESLIDEFILTERS LabelStatisticsWholeSlideFilter {
LabelStatisticsWholeSlideFilter();
virtual ~LabelStatisticsWholeSlideFilter();

void setInput(MultiResolutionImage* const input);
void setInput(const std::shared_ptr<MultiResolutionImage>& input);
void setProcessedLevel(const unsigned int processedLevel);
unsigned int getProcessedLevel();
void setProgressMonitor(ProgressMonitor* progressMonitor);
Expand Down
Loading

0 comments on commit 77e987a

Please sign in to comment.