Commit 79f928d6 authored by Sebastien Barre's avatar Sebastien Barre
Browse files

ENH: the whole preset name was probably overkill. Remove it for now (it was...

ENH: the whole preset name was probably overkill. Remove it for now (it was added couple weeks ago, no backward compat pb)
parent bbe6944a
......@@ -19,7 +19,7 @@
#include <vtksys/stl/vector>
//----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkMedicalImageProperties, "1.2");
vtkCxxRevisionMacro(vtkMedicalImageProperties, "1.3");
vtkStandardNewMacro(vtkMedicalImageProperties);
//----------------------------------------------------------------------------
......@@ -30,7 +30,6 @@ public:
class WindowLevelPreset
{
public:
vtksys_stl::string Name;
double Window;
double Level;
};
......@@ -104,48 +103,27 @@ void vtkMedicalImageProperties::DeepCopy(vtkMedicalImageProperties *p)
{
double w, l;
p->GetNthWindowLevelPreset(i, &w, &l);
this->AddWindowLevelPreset(w, l, p->GetNthWindowLevelPresetName(i));
this->AddWindowLevelPreset(w, l);
}
}
//----------------------------------------------------------------------------
void vtkMedicalImageProperties::AddWindowLevelPreset(
double w, double l, const char *name)
double w, double l)
{
if (!this->Internals)
if (!this->Internals || this->HasWindowLevelPreset(w, l))
{
return;
}
// If we have that preset already, replace its name
vtkMedicalImagePropertiesInternals::WindowLevelPresetPoolIterator it =
this->Internals->WindowLevelPresetPool.begin();
vtkMedicalImagePropertiesInternals::WindowLevelPresetPoolIterator end =
this->Internals->WindowLevelPresetPool.end();
for (; it != end; ++it)
{
if ((*it).Window == w && (*it).Level == l)
{
(*it).Name = name ? name : "";
return;
}
}
// Otherwise add it
vtkMedicalImagePropertiesInternals::WindowLevelPreset preset;
preset.Window = w;
preset.Level = l;
if (name)
{
preset.Name = name;
}
this->Internals->WindowLevelPresetPool.push_back(preset);
}
//----------------------------------------------------------------------------
void vtkMedicalImageProperties::RemoveWindowLevelPreset(double w, double l)
int vtkMedicalImageProperties::HasWindowLevelPreset(double w, double l)
{
if (this->Internals)
{
......@@ -157,17 +135,17 @@ void vtkMedicalImageProperties::RemoveWindowLevelPreset(double w, double l)
{
if ((*it).Window == w && (*it).Level == l)
{
this->Internals->WindowLevelPresetPool.erase(it);
break;
return 1;
}
}
}
return 0;
}
//----------------------------------------------------------------------------
void vtkMedicalImageProperties::RemoveWindowLevelPreset(const char *name)
void vtkMedicalImageProperties::RemoveWindowLevelPreset(double w, double l)
{
if (this->Internals && name && *name)
if (this->Internals)
{
vtkMedicalImagePropertiesInternals::WindowLevelPresetPoolIterator it =
this->Internals->WindowLevelPresetPool.begin();
......@@ -175,7 +153,7 @@ void vtkMedicalImageProperties::RemoveWindowLevelPreset(const char *name)
this->Internals->WindowLevelPresetPool.end();
for (; it != end; ++it)
{
if (!strcmp((*it).Name.c_str(), name))
if ((*it).Window == w && (*it).Level == l)
{
this->Internals->WindowLevelPresetPool.erase(it);
break;
......@@ -199,41 +177,6 @@ int vtkMedicalImageProperties::GetNumberOfWindowLevelPresets()
return this->Internals ? this->Internals->WindowLevelPresetPool.size() : 0;
}
//----------------------------------------------------------------------------
int vtkMedicalImageProperties::GetWindowLevelPreset(
const char *name, double *w, double *l)
{
if (this->Internals && name && *name && w && l)
{
vtkMedicalImagePropertiesInternals::WindowLevelPresetPoolIterator it =
this->Internals->WindowLevelPresetPool.begin();
vtkMedicalImagePropertiesInternals::WindowLevelPresetPoolIterator end =
this->Internals->WindowLevelPresetPool.end();
for (; it != end; ++it)
{
if (!strcmp((*it).Name.c_str(), name))
{
*w = (*it).Window;
*l = (*it).Level;
return 1;
}
}
}
return 0;
}
//----------------------------------------------------------------------------
double* vtkMedicalImageProperties::GetWindowLevelPreset(const char *name)
{
static double wl[2];
if (this->GetWindowLevelPreset(name, wl, wl + 1))
{
return wl;
}
return NULL;
}
//----------------------------------------------------------------------------
int vtkMedicalImageProperties::GetNthWindowLevelPreset(
int idx, double *w, double *l)
......@@ -260,39 +203,6 @@ double* vtkMedicalImageProperties::GetNthWindowLevelPreset(int idx)
return NULL;
}
//----------------------------------------------------------------------------
const char* vtkMedicalImageProperties::GetWindowLevelPresetName(
double w, double l)
{
if (this->Internals)
{
vtkMedicalImagePropertiesInternals::WindowLevelPresetPoolIterator it =
this->Internals->WindowLevelPresetPool.begin();
vtkMedicalImagePropertiesInternals::WindowLevelPresetPoolIterator end =
this->Internals->WindowLevelPresetPool.end();
for (; it != end; ++it)
{
if ((*it).Window == w && (*it).Level == l)
{
return (*it).Name.c_str();
}
}
}
return NULL;
}
//----------------------------------------------------------------------------
const char* vtkMedicalImageProperties::GetNthWindowLevelPresetName(int idx)
{
if (this->Internals &&
idx >= 0 && idx < this->GetNumberOfWindowLevelPresets())
{
return this->Internals->WindowLevelPresetPool[idx].Name.c_str();
}
return NULL;
}
//----------------------------------------------------------------------------
void vtkMedicalImageProperties::PrintSelf(ostream& os, vtkIndent indent)
{
......
......@@ -81,19 +81,13 @@ public:
// Description:
// Add/Remove/Query the window/level presets that may have been associated
// to a medical image.
// The preset name can be empty, and does not have to be unique
// (the window/level pair has to).
virtual void AddWindowLevelPreset(double w, double l, const char *name);
virtual void AddWindowLevelPreset(double w, double l);
virtual void RemoveWindowLevelPreset(double w, double l);
virtual void RemoveWindowLevelPreset(const char *name);
virtual void RemoveAllWindowLevelPresets();
virtual int GetNumberOfWindowLevelPresets();
virtual int GetWindowLevelPreset(const char *name, double *w, double *l);
virtual double* GetWindowLevelPreset(const char *name);
virtual int HasWindowLevelPreset(double w, double l);
virtual int GetNthWindowLevelPreset(int idx, double *w, double *l);
virtual double* GetNthWindowLevelPreset(int idx);
virtual const char* GetWindowLevelPresetName(double w, double l);
virtual const char* GetNthWindowLevelPresetName(int idx);
protected:
vtkMedicalImageProperties();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment