//-----------------------------------------------------------------------
    Vector2 StringConverter::parseVector2(const String& val, const Vector2& defaultValue)
    {
        // Split on space
        vector<String>::type vec = StringUtil::split(val);

        if (vec.size() != 2)
        {
            return defaultValue;
        }
        else
        {
            return Vector2(parseReal(vec[0], defaultValue[0]), parseReal(vec[1], defaultValue[1]));
        }
    }
//-----------------------------------------------------------------------
Quaternion StringConverter::parseQuaternion(const String& val)
{
    // Split on space
    std::vector<String> vec = StringUtil::split(val);

    if (vec.size() != 4)
    {
        return Quaternion::IDENTITY;
    }
    else
    {
        return Quaternion(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]), parseReal(vec[3]));
    }
}
    //-----------------------------------------------------------------------
    Quaternion StringConverter::parseQuaternion(const String& val, const Quaternion& defaultValue)
    {
        // Split on space
        vector<String>::type vec = StringUtil::split(val);

        if (vec.size() != 4)
        {
            return defaultValue;
        }
        else
        {
            return Quaternion(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]), parseReal(vec[3]));
        }
    }
//-----------------------------------------------------------------------
Vector4 StringConverter::parseVector4(const String& val)
{
    // Split on space
    std::vector<String> vec = StringUtil::split(val);

    if (vec.size() != 4)
    {
        return Vector4::ZERO;
    }
    else
    {
        return Vector4(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]),parseReal(vec[3]));
    }
}
示例#5
0
bool getAttrib(const TiXmlElement* XMLNode, const gkString& attrib, gkScalar &value)
{
	if (!XMLNode || !XMLNode->Attribute(attrib)) return false;

	value = parseReal(XMLNode->Attribute(attrib.c_str()));
	return true;
}
示例#6
0
文件: meshdolfin.c 项目: Kun-Qu/petsc
    void XMLMesh::readVertex(const xmlChar *name, const xmlChar **attrs) {
      // Read index
      uint v = parseUnsignedInt(name, attrs, "index");

      switch (this->embedDim) {
      case 3:
        this->coords[v*this->embedDim+2] = parseReal(name, attrs, "z");
      case 2:
        this->coords[v*this->embedDim+1] = parseReal(name, attrs, "y");
      case 1:
        this->coords[v*this->embedDim+0] = parseReal(name, attrs, "x");
        break;
      default:
        error("Dimension of mesh must be 1, 2 or 3.");
      }
    };
示例#7
0
bool getValue(const TiXmlElement* XMLNode, gkScalar &value)
{
	if (!XMLNode || !XMLNode->GetText()) 
		return false;
	
	value = parseReal(XMLNode->GetText());
	return true;
}
    //-----------------------------------------------------------------------
    Matrix3 StringConverter::parseMatrix3(const String& val, const Matrix3& defaultValue)
    {
        // Split on space
        vector<String>::type vec = StringUtil::split(val);

        if (vec.size() != 9)
        {
            return defaultValue;
        }
        else
        {
            return Matrix3(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]),
                parseReal(vec[3]),parseReal(vec[4]),parseReal(vec[5]),
                parseReal(vec[6]),parseReal(vec[7]),parseReal(vec[8]));
        }
    }
//-----------------------------------------------------------------------
Matrix3 StringConverter::parseMatrix3(const String& val)
{
    // Split on space
    std::vector<String> vec = StringUtil::split(val);

    if (vec.size() != 9)
    {
        return Matrix3::IDENTITY;
    }
    else
    {
        return Matrix3(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]),
                       parseReal(vec[3]),parseReal(vec[4]),parseReal(vec[5]),
                       parseReal(vec[6]),parseReal(vec[7]),parseReal(vec[8]));
    }
}
//-----------------------------------------------------------------------
ColourValue StringConverter::parseColourValue(const String& val)
{
    // Split on space
    std::vector<String> vec = StringUtil::split(val);

    if (vec.size() == 4)
    {
        return ColourValue(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]), parseReal(vec[3]));
    }
    else if (vec.size() == 3)
    {
        return ColourValue(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]), 1.0f);
    }
    else
    {
        return ColourValue::Black;
    }
}
示例#11
0
    //-----------------------------------------------------------------------
    ColourValue StringConverter::parseColourValue(const String& val, const ColourValue& defaultValue)
    {
        // Split on space
        vector<String>::type vec = StringUtil::split(val);

        if (vec.size() == 4)
        {
            return ColourValue(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]), parseReal(vec[3]));
        }
        else if (vec.size() == 3)
        {
            return ColourValue(parseReal(vec[0]),parseReal(vec[1]),parseReal(vec[2]), 1.0f);
        }
        else
        {
            return defaultValue;
        }
    }
    //-----------------------------------------------------------------------
    Matrix4 StringConverter::parseMatrix4(const String& val, const Matrix4& defaultValue)
    {
        // Split on space
        vector<String>::type vec = StringUtil::split(val);

        if (vec.size() != 16)
        {
            return defaultValue;
        }
        else
        {
            return Matrix4(parseReal(vec[0], defaultValue[0][0]),
                           parseReal(vec[1], defaultValue[0][1]),
                           parseReal(vec[2], defaultValue[0][2]),
                           parseReal(vec[3], defaultValue[0][3]),
                           
                           parseReal(vec[4], defaultValue[1][0]),
                           parseReal(vec[5], defaultValue[1][1]),
                           parseReal(vec[6], defaultValue[1][2]),
                           parseReal(vec[7], defaultValue[1][3]),
                           
                           parseReal(vec[8], defaultValue[2][0]),
                           parseReal(vec[9], defaultValue[2][1]),
                           parseReal(vec[10], defaultValue[2][2]),
                           parseReal(vec[11], defaultValue[2][3]),
                           
                           parseReal(vec[12], defaultValue[3][0]),
                           parseReal(vec[13], defaultValue[3][1]),
                           parseReal(vec[14], defaultValue[3][2]),
                           parseReal(vec[15], defaultValue[3][3]));
        }
    }
示例#13
0
	bool parsePoint (const char * _pValue, const char * _pEnd, point_t & _pt, const char ** _ppEnd) {
		const char * p = _pValue;

		// Omit spaces.
		while (p < _pEnd && * p == ' ')
			++ p;
		// Get opening bracket.
		if (p >= _pEnd || * p != '(') {
			* _ppEnd = _pEnd;
			return false;
		}
		++ p;
		while (p < _pEnd && * p == ' ')
			++ p;

		// Get latitude.
		if (! parseReal (p, _pEnd, & p, _pt.y)) { //NS
			//ReportWarning (m_cOffset, "Latitude value is expected. The point will be ignored.");
			* _ppEnd = _pEnd;
			return false;
		}
		// Omit spaces.
		while (p < _pEnd && * p == ' ')
			++ p;
		// Get delimiting comma.
		if (p >= _pEnd || * p != ',') {
			//ReportWarning (m_cOffset, "Comma between latitude and longitude is expected. The point will be ignored.");
			* _ppEnd = _pEnd;
			return false;
		}
		++ p;

		// Omit spaces.
		while (p < _pEnd && * p == ' ')
			++ p;

		// Get longitude.
		if (! parseReal (p, _pEnd, & p, _pt.x)) {
			//ReportWarning (m_cOffset, "Longitude value is expected. The point will be ignored.");
			* _ppEnd = _pEnd;
			return false;
		}

		// Omit spaces.
		while (p < _pEnd && * p == ' ')
			++ p;

		// Get closing bracket.
		if (p >= _pEnd || * p != ')') {
			//ReportWarning (m_cOffset, "Closing bracket for point is expected. The point will be ignored.");
			* _ppEnd = _pEnd;
			return false;
		}
		++ p;

		* _ppEnd = p;
		/*
		// Check coordinates.
		if (90 <= _pt.y || _pt.y <= -90) {
		ReportWarning (m_cOffset, "Invalid latitude value: %0.5f. The point will be ignored.", _pt.y);
		return false;
		}
		if (180 < _pt.x || _pt.x < -180) {
		ReportWarning (m_cOffset, "Invalid longitude value: %0.5f. The point will be ignored.", _pt.x);
		return false;
		}
		*/
		return true;
	}
示例#14
0
 float VSSValue::asReal() const
 {
     float f = 0;
     parseReal(f);
     return f;
 }
示例#15
0
 bool VSSValue::isReal() const
 {
     float f;
     return parseReal(f);
 }