Skip to content

Commit

Permalink
ENH: Added option to set scaling factor for image intensity for 3ddos…
Browse files Browse the repository at this point in the history
…e file reader

SlicerRt#73
  • Loading branch information
anna-ilina committed Oct 26, 2017
1 parent 4f9d00c commit 51f9d97
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,50 +58,41 @@ vtkSlicerDosxyzNrc3dDoseFileReaderLogic::~vtkSlicerDosxyzNrc3dDoseFileReaderLogi
{
}



//----------------------------------------------------------------------------
bool vtkSlicerDosxyzNrc3dDoseFileReaderLogic::AreEqualWithTolerance(double a, double b)
{
return fabs(a - b) < MAX_TOLERANCE_SPACING;
}



//----------------------------------------------------------------------------
void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//


//----------------------------------------------------------------------------
void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* filename)
void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* filename, float intensityScalingFactor/*=1.0*/)
{

ifstream readFileStream(filename); //todo test that this doesn't crash when filename is null

if (!readFileStream){
vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The specified file could not be opened.");
return;
if (!readFileStream)
{
vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The specified file could not be opened.");
return;
}

int size[3] = { 0, 0, 0 };
double spacing[3] = { 0, 0, 0 };
double origin[3] = { 0, 0, 0 };
std::string title = "";

// read in block 1 (number of voxels in x, y, z directions)
readFileStream >> size[0] >> size[1] >> size[2];
int numTotalVoxels = size[0] * size[1] * size[2];


if (size[0] <= 0 || size[1] <= 0 || size[2] <= 0)
{
vtkErrorMacro("LoadDosxyzNrc3dDoseFile: Number of voxels in X, Y, or Z direction must be greater than zero." << "numVoxelsX " << size[0] << ", numVoxelsY " << size[1] << ", numVoxelsZ " << size[2]);
return;
}


std::vector<double> voxelBoundariesX(size[0] + 1);
std::vector<double> voxelBoundariesY(size[1] + 1);
Expand Down Expand Up @@ -135,7 +126,6 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file
counter += 1;
}


// read in block 3 (voxel boundaries, cm, in y direction)
counter = 0;
while (!readFileStream.eof() && counter < size[1] + 1)
Expand Down Expand Up @@ -183,6 +173,8 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file
floatDosxyzNrc3dDoseVolumeData->SetExtent(0, size[0] - 1, 0, size[1] - 1, 0, size[2] - 1);
floatDosxyzNrc3dDoseVolumeData->AllocateScalars(VTK_FLOAT, 1);

//todo: When loading .3ddose file from python, it is intensityScalarFactor set to 0

float* floatPtr = (float*)floatDosxyzNrc3dDoseVolumeData->GetScalarPointer();
float currentValue = 0.0;
for (long z = 0; z < size[2]; z++)
Expand All @@ -196,13 +188,13 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file
vtkErrorMacro("LoadDosxyzNrc3dDoseFile: The end of file was reached earlier than specified.");
}
readFileStream >> currentValue;
currentValue = currentValue * intensityScalingFactor;
(*floatPtr) = currentValue;
++floatPtr;
}
}
}


// create volume node for dose values
vtkSmartPointer<vtkMRMLScalarVolumeNode> dosxyzNrc3dDoseVolumeNode = vtkSmartPointer<vtkMRMLScalarVolumeNode>::New();
dosxyzNrc3dDoseVolumeNode->SetScene(this->GetMRMLScene());
Expand Down Expand Up @@ -230,12 +222,9 @@ void vtkSlicerDosxyzNrc3dDoseFileReaderLogic::LoadDosxyzNrc3dDoseFile(char* file
dosxyzNrc3dDoseVolumeDisplayNode->SetAndObserveColorNodeID("vtkMRMLColorTableNodeGrey");
dosxyzNrc3dDoseVolumeNode->SetAndObserveDisplayNodeID(dosxyzNrc3dDoseVolumeDisplayNode->GetID());


//todo: read in block 6 (error values array; relative errors)
//todo: read error values in another volume node
//todo: do I also need voxelCenters?

readFileStream.close();
}


Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class VTK_SLICER_DOSXYZNRC3DDOSEFILEREADER_LOGIC_EXPORT vtkSlicerDosxyzNrc3dDose

/// Load DosxyzNrc3dDose volume from file
/// \param filename Path and filename of the DosxyzNrc3dDose file
void LoadDosxyzNrc3dDoseFile(char* filename);
void LoadDosxyzNrc3dDoseFile(char* filename, float intensityScalingFactor=1.0);

/// Determine if two numbers are equal within a small tolerance (0.001)
static bool AreEqualWithTolerance(double a, double b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@
</rect>
</property>
<property name="windowTitle">
<string>Volume Options</string>
<string>DosxyzNrc3dDoseFileReader Options</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="UseImageIntensityScaleAndOffsetCheckBox">
<widget class="QLabel" name="ScalingFactorLabel">
<property name="toolTip">
<string>Scaling factor applied on the dose values</string>
</property>
<property name="text">
<string>Scaling factor:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ScalingFactorLineEdit">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Use Image Intensity Scale and Image Intensity Offset</string>
<string>1.0</string>
</property>
</widget>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

/// Qt includes
#include <QFileInfo>
#include <QDebug>

// CTK includes
#include <ctkFlowLayout.h>
Expand Down Expand Up @@ -48,11 +49,13 @@ qSlicerDosxyzNrc3dDoseFileReaderOptionsWidget::qSlicerDosxyzNrc3dDoseFileReaderO

ctkFlowLayout::replaceLayout(this);

connect(d->UseImageIntensityScaleAndOffsetCheckBox, SIGNAL(toggled(bool)),
this, SLOT(updateProperties()));
connect(d->ScalingFactorLineEdit, SIGNAL(textChanged(QString)), this, SLOT(updateProperties()));

// Image instensity scaling factor is 1.0 by default
float defaultScalingFactorValue = 1.0;
QString defaultScalingFactorString = QString::number(defaultScalingFactorValue);
d->ScalingFactorLineEdit->setText(defaultScalingFactorString);

// Image intensity scale and offset turned off by default
d->UseImageIntensityScaleAndOffsetCheckBox->setChecked(false);
}

//-----------------------------------------------------------------------------
Expand All @@ -65,5 +68,13 @@ void qSlicerDosxyzNrc3dDoseFileReaderOptionsWidget::updateProperties()
{
Q_D(qSlicerDosxyzNrc3dDoseFileReaderOptionsWidget);

d->Properties["imageIntensityScaleAndOffset"] = d->UseImageIntensityScaleAndOffsetCheckBox->isChecked();
bool ok = false;
float scalingFactor = d->ScalingFactorLineEdit->text().toFloat(&ok);
if (ok == false)
{
qCritical() << Q_FUNC_INFO << ": Unable to parse scaling factor parameter " << d->ScalingFactorLineEdit->text() << ". Using default value 1.0";
scalingFactor = 1.0;
}

d->Properties["scalingFactor"] = scalingFactor;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ bool qSlicerDosxyzNrc3dDoseFileReaderPlugin::load(const IOProperties& properties
QString fileName = properties["fileName"].toString();
Q_ASSERT(d->Logic);

bool useImageIntensityScaleAndOffsetFromFile = properties["imageIntensityScaleAndOffset"].toBool();
d->Logic->LoadDosxyzNrc3dDoseFile(fileName.toLatin1().data());
float intensityScalingFactor = properties["scalingFactor"].toFloat();
d->Logic->LoadDosxyzNrc3dDoseFile(fileName.toLatin1().data(), intensityScalingFactor);

this->setLoadedNodes(QStringList());

Expand Down

0 comments on commit 51f9d97

Please sign in to comment.