Skip to content

Commit

Permalink
exposed blending option to volume import. closes #35. Resets BBox on …
Browse files Browse the repository at this point in the history
…new mesh.
  • Loading branch information
Brig Bagley committed Jul 6, 2016
1 parent c36062e commit 88b8bde
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/cli/mesher/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const double kDefaultLipschitz = 0.2;
const double kDefaultMultiplier = 1.0;
const int kDefaultPadding = 0;
const int kDefaultMaxIterations = 1000;
const double kDefaultSigma = 1.;

namespace po = boost::program_options;

Expand Down Expand Up @@ -111,6 +112,7 @@ int main(int argc, char* argv[])
bool strip_exterior = false;
enum cleaver::MeshType mesh_mode = cleaver::Structured;
cleaver::MeshFormat output_format = kDefaultOutputFormat;
double sigma = kDefaultSigma;

double sizing_field_time = 0;
double background_time = 0;
Expand Down Expand Up @@ -145,6 +147,7 @@ int main(int argc, char* argv[])
("output_format,f", po::value<std::string>(), "output mesh format (tetgen [default], scirun, matlab, vtkUSG, vtkPoly, ply [Surface mesh only])")
("strict,t", "warnings become errors")
("segmentation,S", "The input file is a segmentation file.")
("blend_sigma,B", po::value<double>(), "blending sigma for input(s) to remove alias artifacts.")
;

boost::program_options::variables_map variables_map;
Expand Down Expand Up @@ -242,6 +245,9 @@ int main(int argc, char* argv[])
if (variables_map.count("alpha_long")) {
alpha_long = variables_map["alpha_long"].as<double>();
}
if (variables_map.count("blend_sigma")) {
sigma = variables_map["blend_sigma"].as<double>();
}

if (variables_map.count("background_mesh")) {
have_background_mesh = true;
Expand Down Expand Up @@ -343,7 +349,7 @@ int main(int argc, char* argv[])
std::cerr << "WARNING: More than 1 input provided for segmentation." <<
" Only the first input will be used." << std::endl;
}
NRRDTools::segmentationToIndicatorFunctions(material_fields[0]);
NRRDTools::segmentationToIndicatorFunctions(material_fields[0], sigma);
} else if (material_fields.size() == 1) {
add_inverse = true;
} else {
Expand Down
23 changes: 21 additions & 2 deletions src/gui/Application/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include <QProgressDialog>
#include <QApplication>
#include <QCheckBox>
#include <QDoubleSpinBox>
#include <NRRDTools.h>
#include <QStatusBar>
#include <QLayoutItem>
#include <QLabel>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent) {}
Expand Down Expand Up @@ -319,15 +322,21 @@ class MyFileDialog : public QFileDialog
MyFileDialog(QWidget *, const QString& a,
const QString& b, const QString& c);
bool isSegmentation();
double sigma();
QSize sizeHint() const;
private:
QCheckBox *segmentation_check_;
QCheckBox * segmentation_check_;
QDoubleSpinBox * sigmaValue_;
};

bool MyFileDialog::isSegmentation() {
return !this->segmentation_check_->isChecked();
}

double MyFileDialog::sigma() {
return this->sigmaValue_->value();
}

MyFileDialog::MyFileDialog( QWidget *parent, const QString& a,
const QString& b, const QString& c) :
QFileDialog( parent, a, b, c),
Expand All @@ -342,7 +351,15 @@ MyFileDialog::MyFileDialog( QWidget *parent, const QString& a,
// add some widgets
segmentation_check_ = new QCheckBox("These are individual indicator functions", this);
segmentation_check_->setChecked(false);
sigmaValue_ = new QDoubleSpinBox(this);
sigmaValue_->setValue(1.);
sigmaValue_->setMinimum(0.);
sigmaValue_->setMaximum(64.);
sigmaValue_->setSingleStep(1.);
hbl->addWidget(segmentation_check_);
hbl->addItem(new QSpacerItem(30, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
hbl->addWidget(new QLabel("Blending Function Sigma", this));
hbl->addWidget(sigmaValue_);

int numRows = mainLayout->rowCount();

Expand Down Expand Up @@ -393,6 +410,7 @@ bool MainWindow::checkSaved() {
}
return true;
}

void MainWindow::importVolume() {
if (!this->checkSaved()) {
return;
Expand All @@ -403,6 +421,7 @@ void MainWindow::importVolume() {
if (dialog.exec())
fileNames = dialog.selectedFiles();
bool segmentation = dialog.isSegmentation();
double sigma = dialog.sigma();
if(!fileNames.isEmpty()) {
std::string file1 = (*fileNames.begin()).toStdString();
auto pos = file1.find_last_of('/');
Expand Down Expand Up @@ -431,7 +450,7 @@ void MainWindow::importVolume() {
std::cerr << "WARNING: More than one inputs provided for segmentation." <<
" Only the first input will be used." << std::endl;
}
fields = NRRDTools::segmentationToIndicatorFunctions(inputs[0]);
fields = NRRDTools::segmentationToIndicatorFunctions(inputs[0], sigma);
status.setValue(90);
QApplication::processEvents();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/gui/Application/ViewWidgets/MeshWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ void MeshWindow::closeEvent(QCloseEvent *event)
void MeshWindow::setMesh(cleaver::TetMesh *mesh)
{
this->mesh_ = mesh;
m_dataBounds = cleaver::BoundingBox::merge(m_dataBounds, mesh->bounds);
m_dataBounds = cleaver::BoundingBox::merge(cleaver::BoundingBox(), mesh->bounds);

if (mesh->imported) {

Expand Down
14 changes: 10 additions & 4 deletions src/lib/nrrd2cleaver/NRRDTools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typedef itk::DiscreteGaussianImageFilter<
typedef itk::ApproximateSignedDistanceMapImageFilter
<ImageType, ImageType> DMapType;
std::vector<cleaver::AbstractScalarField*>
NRRDTools::segmentationToIndicatorFunctions(std::string filename) {
NRRDTools::segmentationToIndicatorFunctions(std::string filename, double sigma) {
// read file using ITK
if (filename.find(".nrrd") != std::string::npos) {
itk::NrrdImageIOFactory::RegisterOneFactory();
Expand Down Expand Up @@ -98,7 +98,7 @@ NRRDTools::segmentationToIndicatorFunctions(std::string filename) {
//do some blurring
GaussianBlurType::Pointer blur = GaussianBlurType::New();
blur->SetInput(multiplyImageFilter->GetOutput());
blur->SetVariance(1.);
blur->SetVariance(sigma * sigma);
blur->Update();
//find the average value between
ImageCalculatorFilterType::Pointer calc =
Expand Down Expand Up @@ -155,7 +155,8 @@ NRRDTools::segmentationToIndicatorFunctions(std::string filename) {
}

std::vector<cleaver::AbstractScalarField*>
NRRDTools::loadNRRDFiles(std::vector<std::string> files) {
NRRDTools::loadNRRDFiles(std::vector<std::string> files,
double sigma) {
std::vector<cleaver::AbstractScalarField*> fields;
size_t num = 0;
for (auto file : files) {
Expand All @@ -168,7 +169,12 @@ NRRDTools::loadNRRDFiles(std::vector<std::string> files) {
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(file);
reader->Update();
ImageType::Pointer img = reader->GetOutput();
//do some blurring
GaussianBlurType::Pointer blur = GaussianBlurType::New();
blur->SetInput(reader->GetOutput());
blur->SetVariance(sigma * sigma);
blur->Update();
ImageType::Pointer img = blur->GetOutput();
//convert the image to a cleaver "abstract field"
auto region = img->GetLargestPossibleRegion();
auto numPixel = region.GetNumberOfPixels();
Expand Down
6 changes: 3 additions & 3 deletions src/lib/nrrd2cleaver/NRRDTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

class NRRDTools {
public:
static std::vector<cleaver::AbstractScalarField*>
segmentationToIndicatorFunctions(std::string file);
static std::vector<cleaver::AbstractScalarField*>
loadNRRDFiles(std::vector<std::string> files);
segmentationToIndicatorFunctions(std::string file, double sigma = 1.);
static std::vector<cleaver::AbstractScalarField*>
loadNRRDFiles(std::vector<std::string> files, double sigma = 1.);
static void saveNRRDFile(cleaver::AbstractScalarField* field,
std::string name);
};
Expand Down

0 comments on commit 88b8bde

Please sign in to comment.