⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtvisualizer.cpp

📁 此文件包含了在linux下实现tpr-tree索引的源代码
💻 CPP
字号:
//------------------------------------------------------------------------//      RTvisualizer.cpp//      ----------------//      Implements the functionality to visualize an entry, a node or//      a group of nodes in (space-dimension, time) dimensions.//      Produces xfig files.//      Uses the libxfig library by Kazuo Amano.////      TPR-tree - Index for continuously moving objects//      July 2001 release, Aalborg University//#include "rtvisualizer.h"#include "xfig.h"double RTvisualizer::colors[] = {1.0, 6.0/7, 5.0/7, 4.0/7, 3.0/7, 2.0/7, 1.0/7};//------------------------------------------------RTvisualizer::~RTvisualizer (){   if (figFile) fclose(figFile);   ResetToBeMeasured();}//------------------------------------------------bool RTvisualizer::OpenFig (const char* figName, RTperiod h){   if (figFile) fclose(figFile);   if ((figFile = fopen(figName, "w")) == NULL) return false;   xfig_startfile (figFile);   ResetToBeMeasured();   horizon = h;   return true;}//------------------------------------------------bool RTvisualizer::VisualizeNode (const char* figName, const RTnode& node, RTperiod h){   if (!OpenFig (figName, h)) return false;   RTentry* entry = (RTentry*) node.Union();         entry->SetLevel(node.Level() + 1);   Measure   (*entry);   Visualize (*entry);   Visualize (node);   delete entry;      return true;}//------------------------------------------------void RTvisualizer::Measure (const RTnode& node){   for (int i = 0; i < node.NumEntries(); i++)      Measure (*(RTentry*)node[i].Ptr());}//------------------------------------------------void RTvisualizer::Measure (const RTentry& entry){   toBeMeasured.push_back ((RTkey*) entry.bbox().Copy());}//------------------------------------------------void RTvisualizer::Visualize (const RTnode&  node, int color){   if (!toBeMeasured.empty()) DoMeasurement();   SetLevelStyle (node.Level());      if (color != -1)    xfig_color (colors[color % maxColors]);   else if (colorMode) xfig_color (colors[node.Path().Page() % maxColors]);   for (int i = 0; i < node.NumEntries(); i++)      VisualizeEntry (*(RTentry*)node[i].Ptr());   }//------------------------------------------------void RTvisualizer::Visualize (const RTentry& entry, int color){   if (!toBeMeasured.empty()) DoMeasurement();     SetLevelStyle  (entry.Level());   if (color != -1)    xfig_color (colors[color % maxColors]);   else if (colorMode) xfig_color (colors[entry.Ptr() % maxColors]);   VisualizeEntry (entry);   }//------------------------------------------------void RTvisualizer::SetLevelStyle (int level){   xfig_color     (colors[level % maxColors]);   xfig_linewidth (lWidth * (level + 1));   xfig_depth     (lWidth * (level + 1));}//------------------------------------------------void RTvisualizer::VisualizeEntry (const RTentry& entry){   int    d;   double points[10];     if (entry.t2() == TPR_TS_INF)   {      xfig_linestyle (lStyleInf);      points[0]   = 0.0;      points[1*2] = 1.0;      points[2*2] = points[2*2+1] = -1.0;      for (d = 0; d < Settings.GetDims(); d++)      {         xfig_new_picture(d / 2, d % 2);         points[1]     = (entry.CoordT(d, 0) - minY[d]) / scaleY;         points[1*2+1] = (entry.CoordT(d, 0, scaleT) - minY[d]) / scaleY;         xfig_2d_polyline (points);         points[1]     = (entry.CoordT(d, 1) - minY[d]) / scaleY;         points[1*2+1] = (entry.CoordT(d, 1, scaleT) - minY[d]) / scaleY;         xfig_2d_polyline (points);      }   }   else   {      xfig_linestyle (lStyleExp);      points[0]   = points[3*2]   = 0.0;      points[1*2] = points[2*2]   = (entry.t2() - CT) / scaleT;      points[4*2] = points[4*2+1] = -1.0;      for (d = 0; d < Settings.GetDims(); d++)      {         xfig_new_picture(d / 2, d % 2);         points[1]     = (entry.CoordT(d, 0) - minY[d]) / scaleY;         points[1*2+1] = (entry.Coordtp(d, 0, entry.t2()) - minY[d]) / scaleY;         points[2*2+1] = (entry.Coordtp(d, 1, entry.t2()) - minY[d]) / scaleY;         points[3*2+1] = (entry.CoordT(d, 1) - minY[d]) / scaleY;         xfig_2d_polyline (points);      }   }}//------------------------------------------------//  DoMeasurement////  scaleT, scaleY, and minY are computed from toBeMeasured (and//  horizon), toBeMeasured is cleaned.//void RTvisualizer::DoMeasurement (){   int         i, d;   double      maxY[TPR_MAX_DIMS];   RTtimeStamp maxT, endT;   // finding the maximum t2   //      maxT = CT;   for (i = 0; i < toBeMeasured.size(); i++)      if (toBeMeasured[i]->t2 != TPR_TS_INF && toBeMeasured[i]->t2 > maxT)         maxT = toBeMeasured[i]->t2;   scaleT = maxT - CT;   if (scaleT <= 0.0) scaleT = horizon;   // finding maxY and minY in all dimensions and computing a global scaleY   //   scaleY = DBL_MIN;   for (d = 0; d < Settings.GetDims(); d++)   {      minY[d] =  DBL_MAX;      maxY[d] = -DBL_MAX;      for (i = 0; i < toBeMeasured.size(); i++)      {         endT = toBeMeasured[i]->t2;         if (endT == TPR_TS_INF) endT = CT + (RTperiod) scaleT;         if (toBeMeasured[i]->CoordT(d, 0) < minY[d])            minY[d] = toBeMeasured[i]->CoordT(d, 0);         if (toBeMeasured[i]->Coordtp(d, 0, endT) < minY[d])            minY[d] = toBeMeasured[i]->Coordtp(d, 0, endT);         if (toBeMeasured[i]->CoordT(d, 1) > maxY[d])            maxY[d] = toBeMeasured[i]->CoordT(d, 1);         if (toBeMeasured[i]->Coordtp(d, 1, endT) > maxY[d])            maxY[d] = toBeMeasured[i]->Coordtp(d, 1, endT);      }      if (maxY[d] - minY[d] > scaleY) scaleY = maxY[d] - minY[d];   }      // y-centering images in all dimensions    //   for (d = 0; d < Settings.GetDims(); d++)      minY[d] -= (scaleY - (maxY[d] - minY[d])) / 2;   ResetToBeMeasured();}//------------------------------------------------void RTvisualizer::ResetToBeMeasured (){   for (int i = 0; i < toBeMeasured.size(); i++) delete toBeMeasured[i];   toBeMeasured.clear();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -