/*===========================================================================*/ bool KVSMLTransferFunction::read( const std::string& filename ) { BaseClass::setFilename( filename ); BaseClass::setSuccess( true ); // XML document kvs::XMLDocument document; if ( !document.read( filename ) ) { kvsMessageError( "%s", document.ErrorDesc().c_str() ); BaseClass::setSuccess( false ); return false; } // <KVSML> if ( !m_kvsml_tag.read( &document ) ) { kvsMessageError( "Cannot read <%s>.", m_kvsml_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } // <TransferFunction> kvs::kvsml::TransferFunctionTag tfunc_tag; if ( !tfunc_tag.read( m_kvsml_tag.node() ) ) { kvsMessageError( "Cannot read <%s>.", tfunc_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } if ( !tfunc_tag.hasResolution() ) { kvsMessageError( "'resolution' is not specified in <%s>.", tfunc_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } m_resolution = tfunc_tag.resolution(); if ( tfunc_tag.hasMinValue() ) m_min_value = tfunc_tag.minValue(); if ( tfunc_tag.hasMaxValue() ) m_max_value = tfunc_tag.maxValue(); // <ColorMap> and <OpacityMap> kvs::kvsml::ColorMapTag color_map_tag; kvs::kvsml::OpacityMapTag opacity_map_tag; if ( color_map_tag.isExisted( tfunc_tag.node() ) ) { // Both <ColorMap> and <OpacityMap> are existed. if ( opacity_map_tag.isExisted( tfunc_tag.node() ) ) { if ( !color_map_tag.read( tfunc_tag.node() ) ) { kvsMessageError( "Cannot read <%s>.", color_map_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } // <ColorMapValue> for <ColorMap> kvs::kvsml::ColorMapValueTag color_value_tag; if ( color_value_tag.isExisted( color_map_tag.node() ) ) { kvs::XMLNode::SuperClass* node = kvs::XMLNode::FindChildNode( color_map_tag.node(), color_value_tag.name() ); while( node ) { color_value_tag.read( kvs::XMLNode::ToElement( node ) ); const float scalar = color_value_tag.scalar(); const kvs::RGBColor color = color_value_tag.color(); m_color_point_list.push_back( ColorPoint( scalar, color ) ); node = color_map_tag.node()->IterateChildren( color_value_tag.name(), node ); } } // <DataArray> for <ColorMap> else { const size_t colors_nelements = m_resolution * 3; kvs::kvsml::DataArrayTag colors; if ( !colors.read( color_map_tag.node(), colors_nelements, &m_colors ) ) { kvsMessageError( "Cannot read <%s> for <%s>.", colors.name().c_str(), color_map_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } } if ( !opacity_map_tag.read( tfunc_tag.node() ) ) { kvsMessageError( "Cannot read <%s>.", opacity_map_tag.name().c_str() ); return false; } // <OpacityMapValue> for <OpacityMap> kvs::kvsml::OpacityMapValueTag opacity_value_tag; if ( opacity_value_tag.isExisted( opacity_map_tag.node() ) ) { kvs::XMLNode::SuperClass* node = kvs::XMLNode::FindChildNode( opacity_map_tag.node(), opacity_value_tag.name() ); while( node ) { opacity_value_tag.read( kvs::XMLNode::ToElement( node ) ); const float scalar = opacity_value_tag.scalar(); const kvs::Real32 opacity = opacity_value_tag.opacity(); m_opacity_point_list.push_back( OpacityPoint( scalar, opacity ) ); node = opacity_map_tag.node()->IterateChildren( opacity_value_tag.name(), node ); } } else { // <DataArray> for <OpacityMap> const size_t opacities_nelements = m_resolution; kvs::kvsml::DataArrayTag opacities; if ( !opacities.read( opacity_map_tag.node(), opacities_nelements, &m_opacities ) ) { kvsMessageError( "Cannot read <%s> for <%s>.", opacities.name().c_str(), opacity_map_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } } } // <ColorMap> is existed, but <OpacityMap> is not existed. else { kvsMessageError( "Cannot find <%s>.", opacity_map_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } } else { // <OpacityMap> is existed, but <ColorMap> is not existed. if ( opacity_map_tag.isExisted( tfunc_tag.node() ) ) { kvsMessageError( "Cannot find <%s>.", color_map_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } else { if ( !tfunc_tag.hasFile() ) { /* <TransferFunction resolution="xxx"> * a r b g * a r b g * ....... * </TransferFunction> */ TiXmlText* values = kvs::XMLNode::ToText( tfunc_tag.node() ); if ( !values ) { kvsMessageError( "No values in <%s>", tfunc_tag.name().c_str() ); BaseClass::setSuccess( false ); return false; } const std::string delim(" \n"); kvs::Tokenizer t( values->Value(), delim ); m_opacities.allocate( m_resolution ); m_colors.allocate( m_resolution * 3 ); const size_t nloops = m_resolution; for ( size_t i = 0, i3 = 0; i < nloops; i++, i3 += 3 ) { m_opacities[ i ] = static_cast<kvs::Real32>( atof( t.token().c_str() ) ); m_colors[ i3 ] = static_cast<kvs::UInt8>( atoi( t.token().c_str() ) ); m_colors[ i3 + 1 ] = static_cast<kvs::UInt8>( atoi( t.token().c_str() ) ); m_colors[ i3 + 2 ] = static_cast<kvs::UInt8>( atoi( t.token().c_str() ) ); } } else { /* <TransferFunction resolution="xxx" file="filename.dat"/> * * "filename.dat" should be described as follows: * a r b g * a r b g * ....... */ std::ifstream ifs( tfunc_tag.file().c_str() ); if ( !ifs.is_open() ) { kvsMessageError( "Cannot open %s.", tfunc_tag.file().c_str() ); BaseClass::setSuccess( false ); return false; } m_opacities.allocate( m_resolution ); m_colors.allocate( m_resolution * 3 ); kvs::Real32 a = 0; kvs::UInt8 r = 0; kvs::UInt8 g = 0; kvs::UInt8 b = 0; for ( size_t i = 0, i3 = 0; i < m_resolution; i++, i3 += 3 ) { ifs >> a >> r >> g >> b; m_opacities[ i ] = a; m_colors[ i3 + 0 ] = r; m_colors[ i3 + 1 ] = g; m_colors[ i3 + 2 ] = b; } ifs.close(); } } } return true; }
****************************************************************************/ //includes #include "GenWindow.h" #include <stdlib.h> #include <time.h> //Static member definitions /*! * @brief the window id to draw to */ int GenWindow::_windowID = 0; /*! * @brief the newest point to be generated using ISF */ ColorPoint GenWindow::idle = ColorPoint(); /*! * @brief tells whether to generate points or not */ bool GenWindow::generate = false; /*! * @brief the color of the object points */ double GenWindow::color[3] = { 0.0, 0.0, 0.0 }; /*! * @brief the list of transforms to perform */ vector<TransformMatrix> GenWindow::Transforms = vector<TransformMatrix>();
/*===========================================================================*/ void KVSMLTransferFunction::addColorPoint( const float value, const kvs::RGBColor color ) { m_color_point_list.push_back( ColorPoint( value, color ) ); }