From: <sv...@ww...> - 2005-10-15 19:43:47
|
Author: mkrose Date: 2005-10-15 12:43:37 -0700 (Sat, 15 Oct 2005) New Revision: 1624 Modified: trunk/CSP/SimData/CHANGES.current trunk/CSP/SimData/Include/SimData/Link.h trunk/CSP/SimData/SimData/Parse.py trunk/CSP/SimData/Source/LUT.cpp Log: * Add support for serializing uninitialized TableN instances, which allows TableN members to be marked as optional in an XML interface. * Add better support for TableN instances in the XML parser. The parser now checks that the number of values matches the count expected from the breakpoints. Breakpoints and table values can now be scaled by the parser (e.g., scale="0.5" in the BreakN and Values attributes), which for example allows radian angles to be conveniently specified in degrees in the XML file. Note that the "spacing" attribute for breakpoints is also scaled by this factor. * Fix a syntax error in Link.h. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1624 Modified: trunk/CSP/SimData/CHANGES.current =================================================================== --- trunk/CSP/SimData/CHANGES.current 2005-08-30 05:30:42 UTC (rev 1623) +++ trunk/CSP/SimData/CHANGES.current 2005-10-15 19:43:37 UTC (rev 1624) @@ -1,6 +1,20 @@ Version 0.4.0 (in progress) =========================== +2005-10-15: onsight + * Add support for serializing uninitialized TableN instances, which allows + TableN members to be marked as optional in an XML interface. + + * Add better support for TableN instances in the XML parser. The parser + now checks that the number of values matches the count expected from + the breakpoints. Breakpoints and table values can now be scaled by + the parser (e.g., scale="0.5" in the BreakN and Values attributes), + which for example allows radian angles to be conveniently specified in + degrees in the XML file. Note that the "spacing" attribute for + breakpoints is also scaled by this factor. + + * Fix a syntax error in Link.h. + 2005-08-28: onsight * Small tweaks to the SimData API (Random.h), typemaps, and build scripts to workaround problems with swig 1.3.23 and Modified: trunk/CSP/SimData/Include/SimData/Link.h =================================================================== --- trunk/CSP/SimData/Include/SimData/Link.h 2005-08-30 05:30:42 UTC (rev 1623) +++ trunk/CSP/SimData/Include/SimData/Link.h 2005-10-15 19:43:37 UTC (rev 1624) @@ -297,7 +297,7 @@ */ T *operator =(T *t) { _path = 0; - _assign_fast(t); + _reassign(t); return t; } #endif // SWIG Modified: trunk/CSP/SimData/SimData/Parse.py =================================================================== --- trunk/CSP/SimData/SimData/Parse.py 2005-08-30 05:30:42 UTC (rev 1623) +++ trunk/CSP/SimData/SimData/Parse.py 2005-10-15 19:43:37 UTC (rev 1624) @@ -441,7 +441,7 @@ p = SimData.LinkBase() p.setPath(self._element.encode('ascii')) return p - + def end(self): if self._attrs.has_key("source"): source = self._attrs["source"] @@ -545,16 +545,28 @@ tags = self._keys breaks = [] spacing = [] + total = 1 for i in range(self._dim): breakpoints, attrs = tags["Breaks%d" % i] if not attrs.has_key("spacing"): msg = "LUTHander <Breaks%d> tag missing required attribute 'spacing'" % i raise XMLSyntax, msg + dx = float(attrs["spacing"]) + if attrs.has_key("scale"): + scale = float(attrs["scale"]) + breakpoints = [x * scale for x in breakpoints] + dx *= scale breaks.append(breakpoints) - dx = float(attrs["spacing"]) n = 1 + int((max(breaks[i]) - min(breaks[i])) / dx) spacing.append(n) + total *= len(breakpoints) values, attrs = tags["Values"] + if attrs.has_key("scale"): + scale = float(attrs["scale"]) + values = [x * scale for x in values] + if len(values) != total: + msg = "LUTHander value count does not match breakpoint count (%d vs %d)" % (len(values), total) + raise XMLSyntax, msg table.load(values, breaks) try: method = getattr(table, self._method.upper()) Modified: trunk/CSP/SimData/Source/LUT.cpp =================================================================== --- trunk/CSP/SimData/Source/LUT.cpp 2005-08-30 05:30:42 UTC (rev 1623) +++ trunk/CSP/SimData/Source/LUT.cpp 2005-10-15 19:43:37 UTC (rev 1624) @@ -438,6 +438,7 @@ int dim, n; reader >> dim; if (dim != N) { + if (dim == -N) return; // not interpolated std::ostringstream msg; msg << "LUT<" << N << ">::serialize table of dimension " << dim; throw InterpolationUnpackMismatch(msg.str()); @@ -455,9 +456,13 @@ template <int N, class X> void LUT<N,X>::serialize(Writer &writer) const { + int dim = N; + if (!this->isInterpolated()) { + writer << -dim; + return; + } this->checkInterpolated(); int n = tableSize(); - int dim = N; writer << dim; writer << this->m_X0; writer << this->m_X1; @@ -688,6 +693,7 @@ X x0, x1; int n; if (dim != 1) { + if (dim == -1) return; std::ostringstream msg; msg << "LUT<1>::serialize table of dimension " << dim; throw InterpolationUnpackMismatch(msg.str()); @@ -706,6 +712,10 @@ template <typename X> void LUT<1,X>::serialize(Writer &writer) const { int dim = 1; + if (!this->isInterpolated()) { + writer << -dim; + return; + } writer << dim; this->checkInterpolated(); int n = tableSize(); |