void PcInfo::dumpQuery(Stage const& stage, IndexedPointBuffer& data) const { boost::char_separator<char> sep(SEPARATORS); tokenizer tokens(m_QueryPoint, sep); std::vector<double> values; for (tokenizer::iterator t = tokens.begin(); t != tokens.end(); ++t) { values.push_back(boost::lexical_cast<double>(*t)); } if (values.size() < 2) throw app_runtime_error("--points must be two or three values"); boost::scoped_ptr<StageSequentialIterator> iter(stage.createSequentialIterator(data)); const boost::uint32_t numRead = iter->read(data); bool is3D(true); if (values.size() < 3) is3D = false; data.build(is3D); Schema const& schema = data.getSchema(); Dimension const& dimX = schema.getDimension("X"); Dimension const& dimY = schema.getDimension("Y"); Dimension const& dimZ = schema.getDimension("Z"); double x = values[0]; double y = values[1]; double z(0.0); if (is3D) z = values[2]; boost::uint32_t count(m_numPointsToWrite); if (!m_numPointsToWrite) count = 1; double d(0.0); std::vector<std::size_t> ids = data.neighbors(x, y, z, d, count); PointBuffer response(data.getSchema(), count); typedef std::vector<std::size_t>::const_iterator Iterator; std::vector<std::size_t>::size_type pos(0); for (Iterator i = ids.begin(); i != ids.end(); ++i) { response.copyPointFast(pos, *i, data); response.setNumPoints(response.getNumPoints() + 1); pos++; } boost::property_tree::ptree tree = response.toPTree(); std::ostream& ostr = m_outputStream ? *m_outputStream : std::cout; boost::property_tree::ptree output; output.add_child("point", tree); if (m_useXML) write_xml(ostr, output); else write_json(ostr, tree); return; }
void Delta::outputDetail(PointBuffer& source_data, IndexedPointBuffer& candidate_data, std::map<Point, Point> *points) const { Schema const& candidate_schema = candidate_data.getSchema(); Dimension const& cDimX = candidate_schema.getDimension("X"); Dimension const& cDimY = candidate_schema.getDimension("Y"); Dimension const& cDimZ = candidate_schema.getDimension("Z"); Schema const& source_schema = source_data.getSchema(); Dimension const& sDimX = source_schema.getDimension("X"); Dimension const& sDimY = source_schema.getDimension("Y"); Dimension const& sDimZ = source_schema.getDimension("Z"); bool bWroteHeader(false); std::ostream& ostr = m_outputStream ? *m_outputStream : std::cout; candidate_data.build(m_3d); boost::uint32_t count(std::min(source_data.getNumPoints(), candidate_data.getNumPoints())); for (boost::uint32_t i = 0; i < count; ++i) { double sx = source_data.applyScaling(sDimX, i); double sy = source_data.applyScaling(sDimY, i); double sz = source_data.applyScaling(sDimZ, i); std::vector<std::size_t> ids = candidate_data.neighbors(sx, sy, sz, 1); if (!ids.size()) { std::ostringstream oss; oss << "unable to find point for id '" << i <<"'"; throw app_runtime_error(oss.str() ); } std::size_t id = ids[0]; double cx = candidate_data.applyScaling(cDimX, id); double cy = candidate_data.applyScaling(cDimY, id); double cz = candidate_data.applyScaling(cDimZ, id); Point s(sx, sy, sz, id); Point c(cx, cy, cz, id); double xd = sx - cx; double yd = sy - cy; double zd = sz - cz; if (!bWroteHeader) { writeHeader(ostr, m_3d); bWroteHeader = true; } ostr << i << ","; boost::uint32_t precision = Utils::getStreamPrecision(cDimX.getNumericScale()); ostr.setf(std::ios_base::fixed, std::ios_base::floatfield); ostr.precision(precision); ostr << xd << ","; precision = Utils::getStreamPrecision(cDimY.getNumericScale()); ostr.precision(precision); ostr << yd; if (m_3d) { ostr << ","; precision = Utils::getStreamPrecision(cDimZ.getNumericScale()); ostr.precision(precision); ostr << zd; } ostr << std::endl; } if (m_outputStream) { FileUtils::closeFile(m_outputStream); } }