@jacek
The type can already be determined in the constructor of VolumeWrapper. Normally it would be done when calling loadVolume, and the type would be determined based on the type of image files which are loaded (U8 or U16). But it is not so difficult to poll a file's type before creating the object. But nevertheless, from then on a lot of methods are used where the type should not be specified.
@wysota
Do you mean something like this:
/*Pure abstract class, only has type specified and lists all methods operating on the
volume data, but not requiring explicit exposure of type.*/
class VolumeGeneral
{
public:
enum type
{
typeUnknown,
typeU8,
typeU16
};
VolumeGeneral(void);
~VolumeGeneral(void);
type getType() const;
virtual void init() = 0;
virtual void doSomething() = 0;
protected:
type type_;
};
VolumeGeneral::VolumeGeneral(void)
{
type_ = typeUnknown;
}
VolumeGeneral::~VolumeGeneral(void)
{
}
VolumeGeneral::type VolumeGeneral::getType() const
{
return type_ ;
}
/*Pure abstract class, only has type specified and lists all methods operating on the
volume data, but not requiring explicit exposure of type.*/
class VolumeGeneral
{
public:
enum type
{
typeUnknown,
typeU8,
typeU16
};
VolumeGeneral(void);
~VolumeGeneral(void);
type getType() const;
virtual void init() = 0;
virtual void doSomething() = 0;
protected:
type type_;
};
VolumeGeneral::VolumeGeneral(void)
{
type_ = typeUnknown;
}
VolumeGeneral::~VolumeGeneral(void)
{
}
VolumeGeneral::type VolumeGeneral::getType() const
{
return type_ ;
}
To copy to clipboard, switch view to plain text mode
/*Class containing all actual code. Methods operating on data are overridden to actually
do something. Type-specific methods are added to allow an extra interface for these
operations.*/
template <class T>
class VolumeSpecified : public VolumeGeneral
{
public:
VolumeSpecified(void);
~VolumeSpecified(void);
void init();
void doSomething();
void setData(T& data);
T getData() const;
private:
T data_;
};
template <class T>
VolumeSpecified<T>::VolumeSpecified(void)
{
if (typeid(T) == typeid(unsigned char))
type_ = typeU8;
else if (typeid(T) == typeid(unsigned short))
type_ = typeU16;
//else keep typeUnknown (already set)
}
template <class T>
VolumeSpecified<T>::~VolumeSpecified(void)
{
}
template <class T>
void VolumeSpecified<T>::setData(T& data)
{
data_ = data;
}
template <class T>
T VolumeSpecified<T>::getData() const
{
return data;
}
/*Class containing all actual code. Methods operating on data are overridden to actually
do something. Type-specific methods are added to allow an extra interface for these
operations.*/
template <class T>
class VolumeSpecified : public VolumeGeneral
{
public:
VolumeSpecified(void);
~VolumeSpecified(void);
void init();
void doSomething();
void setData(T& data);
T getData() const;
private:
T data_;
};
template <class T>
VolumeSpecified<T>::VolumeSpecified(void)
{
if (typeid(T) == typeid(unsigned char))
type_ = typeU8;
else if (typeid(T) == typeid(unsigned short))
type_ = typeU16;
//else keep typeUnknown (already set)
}
template <class T>
VolumeSpecified<T>::~VolumeSpecified(void)
{
}
template <class T>
void VolumeSpecified<T>::setData(T& data)
{
data_ = data;
}
template <class T>
T VolumeSpecified<T>::getData() const
{
return data;
}
To copy to clipboard, switch view to plain text mode
/*Use of the classes in the main program*/
//Check for type of files and allocate based on type
VolumeGeneral* volume = new VolumeSpecified<unsigned short>();
//Perform type specific operations
if (volume->getType() == VolumeGeneral::typeU16)
{
VolumeSpecified<unsigned short>* volumeS = dynamic_cast<VolumeSpecified<unsigned short>*>(volume);
volumeS->setData(365);
}
//Perform general operations
volume->init();
volume->doSomething();
delete volume;
/*Use of the classes in the main program*/
//Check for type of files and allocate based on type
VolumeGeneral* volume = new VolumeSpecified<unsigned short>();
//Perform type specific operations
if (volume->getType() == VolumeGeneral::typeU16)
{
VolumeSpecified<unsigned short>* volumeS = dynamic_cast<VolumeSpecified<unsigned short>*>(volume);
volumeS->setData(365);
}
//Perform general operations
volume->init();
volume->doSomething();
delete volume;
To copy to clipboard, switch view to plain text mode
Bookmarks