Commit 1dc33e43 authored by Julien Malik's avatar Julien Malik
Browse files

ENH: read display settings from descriptor

parent e8c86d11
......@@ -205,33 +205,39 @@ DatasetDescriptor
// TODO: Generalize code section.
if( imageSettings!=NULL )
{
VectorImageModel::Settings* settings =
static_cast< VectorImageModel::Settings* >( imageSettings );
// Access settings group element.
QDomElement settingsElt(
imageInfoElt.firstChildElement( TAG_NAMES[ ELEMENT_SETTINGS_GROUP ] )
);
// TODO: Manage XML structure errors.
assert( !settingsElt.isNull() );
{
VectorImageModel::Settings* settings =
static_cast< VectorImageModel::Settings* >( imageSettings );
// RGB
QDomElement rgbElt(
settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_RGB_CHANNELS ] )
);
// TODO: Manage XML structure errors.
assert( !rgbElt.isNull() );
// TODO: Get RGB channels from XML element.
// Access settings group element.
QDomElement settingsElt(
imageInfoElt.firstChildElement( TAG_NAMES[ ELEMENT_SETTINGS_GROUP ] )
);
// TODO: Manage XML structure errors.
assert( !settingsElt.isNull() );
// Dynamics
QDomElement dynamicsElt(
settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_DYNAMICS_PARAMETERS ] )
);
// TODO: Manage XML structure errors.
assert( !dynamicsElt.isNull() );
// TODO: Get dynamics parameters from XML element.
}
// RGB
QDomElement rgbElt(
settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_RGB_CHANNELS ] )
);
// TODO: Manage XML structure errors.
assert( !rgbElt.isNull() );
VectorImageModel::Settings::ChannelVector rgb;
ExtractVectorFromNode( rgb, rgbElt );
assert( rgb.size() == 3 );
settings->SetRgbChannels( rgb );
// Dynamics
QDomElement dynamicsElt(
settingsElt.firstChildElement( TAG_NAMES[ ELEMENT_DYNAMICS_PARAMETERS ] )
);
// TODO: Manage XML structure errors.
assert( !dynamicsElt.isNull() );
ParametersType dynamics;
ExtractArrayFromNode( dynamics, dynamicsElt );
assert( dynamics.GetSize() == 6 );
settings->SetDynamicsParams( dynamics );
}
}
/*******************************************************************************/
......
......@@ -45,6 +45,7 @@
//
// Monteverdi includes (sorted by alphabetic order)
#include "mvdTypes.h"
#include "mvdAbstractModel.h"
......@@ -179,9 +180,27 @@ private:
template< typename TInputIterator >
inline
QDomElement CreateContainerNode( const TInputIterator& first,
const TInputIterator& last,
const TInputIterator& last,
const QString& tagName );
/**
* \brief Deserialize a std::vector from a QDomElement
*/
template< typename T >
inline
static
void ExtractVectorFromNode( std::vector<T>& vector,
QDomElement& tagName );
/**
* \brief Deserialize a itk::Array from a QDomElement
*/
template< typename T >
inline
static
void ExtractArrayFromNode( itk::Array<T>& array,
QDomElement& tagName );
/**
*/
void Read( const QString& filename );
......@@ -308,6 +327,58 @@ DatasetDescriptor
return vectorElement;
}
template< typename T >
inline
void
DatasetDescriptor
::ExtractVectorFromNode( std::vector<T>& vector,
QDomElement& element )
{
QDomNode node = element.firstChild();
// TODO: Manage XML structure errors.
assert( !node.isNull() );
assert( node.isText() );
QDomText textNode = node.toText();
assert( !textNode.isNull() );
QString data = textNode.data();
QStringList stringList = data.split(" ");
vector.resize(stringList.size());
for (size_t i = 0; i < stringList.size(); ++i)
{
QVariant v = stringList[i];
vector[i] = v.value<T>();
}
}
template< typename T >
inline
void
DatasetDescriptor
::ExtractArrayFromNode( itk::Array<T>& array,
QDomElement& element )
{
QDomNode node = element.firstChild();
// TODO: Manage XML structure errors.
assert( !node.isNull() );
assert( node.isText() );
QDomText textNode = node.toText();
assert( !textNode.isNull() );
QString data = textNode.data();
QStringList stringList = data.split(" ");
array.SetSize(stringList.size());
for (size_t i = 0; i < stringList.size(); ++i)
{
QVariant v = stringList[i];
array[i] = v.value<T>();
}
}
} // end namespace 'mvd'
#endif // __mvdDatasetDescriptor_h
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