コード例 #1
0
static void PlotAdd(void)
{
  Ihandle *ih = iuplua_checkihandle(1);
  IupPlotAdd(ih, (float)luaL_check_number(2), (float)luaL_check_number(3));
}
コード例 #2
0
ファイル: iuplua_plot.c プロジェクト: mwoz/Hildim.Source
int IupPlotSetFormula(Ihandle* ih, int sample_count, const char* formula, const char* init)
{
  lua_State *L;
  int i, ds_index, ret_count = 1;
  double min, max, step, p, x, y;
  char formula_func[1024];
  IFnL init_cb;

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return -1;

  /* must be an IupMatrix */
  if (ih->iclass->nativetype != IUP_TYPECANVAS ||
      !IupClassMatch(ih, "plot"))
    return -1;

  L = luaL_newstate();
  luaL_openlibs(L);

  {
    const char* register_global =
      "function openpackage(ns)\n"
      "  for n, v in pairs(ns) do _G[n] = v end\n"
      "end\n"
      "openpackage(math)\n";
    luaL_dostring(L, register_global);
  }

  if (init)
    luaL_dostring(L, init);

  init_cb = (IFnL)IupGetCallback(ih, "FORMULAINIT_CB");
  if (init_cb)
    init_cb(ih, L);

  lua_pushlightuserdata(L, ih);
  lua_setglobal(L, "plot");

  if (IupGetInt(ih, "FORMULA_PARAMETRIC"))
    ret_count = 2;

  sprintf(formula_func, "function plot_formula(sample_index, %s)\n"
          "  return %s\n"
          "end\n", ret_count == 2 ? "t" : "x", formula);

  if (luaL_dostring(L, formula_func) != 0)
  {
    ShowFormulaError(ih, L);
    lua_close(L);
    return -1;
  }

  min = IupGetDouble(ih, "FORMULA_MIN");
  max = IupGetDouble(ih, "FORMULA_MAX");
  step = (max - min) / (double)(sample_count - 1);

  IupPlotBegin(ih, 0);

  for (i = 0, p = min; i < sample_count; i++, p += step)
  {
    lua_getglobal(L, "plot_formula");
    lua_pushinteger(L, i);
    lua_pushnumber(L, p);

    if (lua_pcall(L, 2, ret_count, 0) != 0)
    {
      ShowFormulaError(ih, L);
      lua_close(L);
      return -1;
    }

    if (!lua_isnumber(L, -1))
    {
      const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA");
      IupMessageError(IupGetDialog(ih), str_message);
      lua_close(L);
      return -1;
    }

    if (ret_count == 2)
    {
      if (!lua_isnumber(L, -2))
      {
        const char* str_message = IupGetLanguageString("IUP_ERRORINVALIDFORMULA");
        IupMessageError(IupGetDialog(ih), str_message);
        lua_close(L);
        return -1;
      }

      x = lua_tonumber(L, -2);
      y = lua_tonumber(L, -1);

      lua_pop(L, 2);  /* remove the result from the stack */
    }
    else
    {
      x = p;
      y = lua_tonumber(L, -1);

      lua_pop(L, 1);  /* remove the result from the stack */
    }

    IupPlotAdd(ih, x, y);
  }

  ds_index = IupPlotEnd(ih);

  lua_close(L);
  return ds_index;
}
コード例 #3
0
ファイル: pplot.cpp プロジェクト: svn2github/iup-iup
void InitPlots(void)
{
  int theI;
  float x, y;

  // PLOT 0 - MakeExamplePlot1
  IupSetAttribute(plot[0], "TITLE", "AutoScale");
  IupSetAttribute(plot[0], "MARGINTOP", "40");
  IupSetAttribute(plot[0], "MARGINLEFT", "40");
  IupSetAttribute(plot[0], "MARGINBOTTOM", "50");
  IupSetAttribute(plot[0], "TITLEFONTSIZE", "16");
  IupSetAttribute(plot[0], "AXS_XLABEL", "gnu (Foo)");
  IupSetAttribute(plot[0], "AXS_YLABEL", "Space (m^3)");
  IupSetAttribute(plot[0], "AXS_YFONTSIZE", "7");
  IupSetAttribute(plot[0], "AXS_YTICKFONTSIZE", "7");
  IupSetAttribute(plot[0], "LEGENDSHOW", "YES");
  IupSetAttribute(plot[0], "AXS_XFONTSIZE", "10");
  IupSetAttribute(plot[0], "AXS_YFONTSIZE", "10");
  IupSetAttribute(plot[0], "AXS_XLABELCENTERED", "NO");
  IupSetAttribute(plot[0], "AXS_YLABELCENTERED", "NO");
  
//  IupSetAttribute(plot[0], "USE_IMAGERGB", "YES");
//  IupSetAttribute(plot[0], "USE_GDI+", "YES");

  float theFac = (float)1.0/(100*100*100);
  IupPlotBegin(plot[0], 0);
  for (theI=-100; theI<=100; theI++) 
  {
    x = (float)(theI+50);
    y = theFac*theI*theI*theI;
    IupPlotAdd(plot[0], x, y);
  }
  IupPlotEnd(plot[0]);
  IupSetAttribute(plot[0], "DS_LINEWIDTH", "3");
  IupSetAttribute(plot[0], "DS_LEGEND", "Line");

  theFac = (float)2.0/100;
  IupPlotBegin(plot[0], 0);
  for (theI=-100; theI<=100; theI++) 
  {
    x = (float)theI;
    y = -theFac*theI;
    IupPlotAdd(plot[0], x, y);
  }
  IupPlotEnd(plot[0]);
  IupSetAttribute(plot[0], "DS_LEGEND", "Curve 1");

  IupPlotBegin(plot[0], 0);
  for (theI=-100; theI<=100; theI++) 
  {
    x = (float)(0.01*theI*theI-30);
    y = (float)0.01*theI;
    IupPlotAdd(plot[0], x, y);
  }
  IupPlotEnd(plot[0]);
  IupSetAttribute(plot[0], "DS_LEGEND", "Curve 2");

  // PLOT 1 - MakeExamplePlot2
  IupSetAttribute(plot[1], "TITLE", "No Autoscale+No CrossOrigin");
  IupSetAttribute(plot[1], "TITLEFONTSIZE", "16");
  IupSetAttribute(plot[1], "MARGINTOP", "40");
  IupSetAttribute(plot[1], "MARGINLEFT", "55");
  IupSetAttribute(plot[1], "MARGINBOTTOM", "50");
  IupSetAttribute(plot[1], "BGCOLOR", "0 192 192");
  IupSetAttribute(plot[1], "AXS_XLABEL", "Tg (X)");
  IupSetAttribute(plot[1], "AXS_YLABEL", "Tg (Y)");
  IupSetAttribute(plot[1], "AXS_XAUTOMIN", "NO");
  IupSetAttribute(plot[1], "AXS_XAUTOMAX", "NO");
  IupSetAttribute(plot[1], "AXS_YAUTOMIN", "NO");
  IupSetAttribute(plot[1], "AXS_YAUTOMAX", "NO");
  IupSetAttribute(plot[1], "AXS_XMIN", "10");
  IupSetAttribute(plot[1], "AXS_XMAX", "60");
  IupSetAttribute(plot[1], "AXS_YMIN", "-0.5");
  IupSetAttribute(plot[1], "AXS_YMAX", "0.5");
  IupSetAttribute(plot[1], "AXS_XCROSSORIGIN", "NO");
  IupSetAttribute(plot[1], "AXS_YCROSSORIGIN", "NO");
  IupSetAttribute(plot[1], "AXS_XFONTSTYLE", "BOLD");
  IupSetAttribute(plot[1], "AXS_YFONTSTYLE", "BOLD");
  IupSetAttribute(plot[1], "AXS_XREVERSE", "YES");
  IupSetAttribute(plot[1], "GRIDCOLOR", "128 255 128");
  IupSetAttribute(plot[1], "GRIDLINESTYLE", "DOTTED");
  IupSetAttribute(plot[1], "GRID", "YES");
  IupSetAttribute(plot[1], "LEGENDSHOW", "YES");

  theFac = (float)1.0/(100*100*100);
  IupPlotBegin(plot[1], 0);
  for (theI=0; theI<=100; theI++) 
  {
    x = (float)(theI);
    y = theFac*theI*theI*theI;
    IupPlotAdd(plot[1], x, y);
  }
  IupPlotEnd(plot[1]);

  theFac = (float)2.0/100;
  IupPlotBegin(plot[1], 0);
  for (theI=0; theI<=100; theI++) 
  {
    x = (float)(theI);
    y = -theFac*theI;
    IupPlotAdd(plot[1], x, y);
  }
  IupPlotEnd(plot[1]);

  // PLOT 2 - MakeExamplePlot4
  IupSetAttribute(plot[2], "TITLE", "Log Scale");
  IupSetAttribute(plot[2], "TITLEFONTSIZE", "16");
  IupSetAttribute(plot[2], "MARGINTOP", "40");
  IupSetAttribute(plot[2], "MARGINLEFT", "70");
  IupSetAttribute(plot[2], "MARGINBOTTOM", "50");
  IupSetAttribute(plot[2], "GRID", "YES");
  IupSetAttribute(plot[2], "AXS_XSCALE", "LOG10");
  IupSetAttribute(plot[2], "AXS_YSCALE", "LOG2");
  IupSetAttribute(plot[2], "AXS_XLABEL", "Tg (X)");
  IupSetAttribute(plot[2], "AXS_YLABEL", "Tg (Y)");
  IupSetAttribute(plot[2], "AXS_XFONTSTYLE", "BOLD");
  IupSetAttribute(plot[2], "AXS_YFONTSTYLE", "BOLD");

  theFac = (float)100.0/(100*100*100);
  IupPlotBegin(plot[2], 0);
  for (theI=0; theI<=100; theI++) 
  {
    x = (float)(0.0001+theI*0.001);
    y = (float)(0.01+theFac*theI*theI*theI);
    IupPlotAdd(plot[2], x, y);
  }
  IupPlotEnd(plot[2]);
  IupSetAttribute(plot[2], "DS_COLOR", "100 100 200");

  //PLOT 3 - MakeExamplePlot5
  IupSetAttribute(plot[3], "TITLE", "Bar Mode");
  IupSetAttribute(plot[3], "TITLEFONTSIZE", "16");
  IupSetAttribute(plot[3], "MARGINTOP", "40");
  IupSetAttribute(plot[3], "MARGINLEFT", "30");
  IupSetAttribute(plot[3], "MARGINBOTTOM", "30");
  const char * kLables[12] = {"jan","feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"};
  const float kData[12] = {1,2,3,4,5,6,7,8,9,0,1,2};

  IupPlotBegin(plot[3], 1);
  for (theI=0;  theI<12; theI++) 
    IupPlotAddStr(plot[3], kLables[theI], kData[theI]);
  IupPlotEnd(plot[3]);
  IupSetAttribute(plot[3], "DS_COLOR", "100 100 200");
  IupSetAttribute(plot[3], "DS_MODE", "BAR");

  //PLOT 4 - MakeExamplePlot6
  IupSetAttribute(plot[4], "TITLE", "Marks Mode");
  IupSetAttribute(plot[4], "TITLEFONTSIZE", "16");
  IupSetAttribute(plot[4], "MARGINTOP", "40");
  IupSetAttribute(plot[4], "MARGINLEFT", "45");
  IupSetAttribute(plot[4], "MARGINBOTTOM", "40");
  IupSetAttribute(plot[4], "AXS_XAUTOMIN", "NO");
  IupSetAttribute(plot[4], "AXS_XAUTOMAX", "NO");
  IupSetAttribute(plot[4], "AXS_YAUTOMIN", "NO");
  IupSetAttribute(plot[4], "AXS_YAUTOMAX", "NO");
  IupSetAttribute(plot[4], "AXS_XMIN", "0");
  IupSetAttribute(plot[4], "AXS_XMAX", "0.011");
  IupSetAttribute(plot[4], "AXS_YMIN", "0");
  IupSetAttribute(plot[4], "AXS_YMAX", "0.22");
  IupSetAttribute(plot[4], "AXS_XCROSSORIGIN", "NO");
  IupSetAttribute(plot[4], "AXS_YCROSSORIGIN", "NO");
  IupSetAttribute(plot[4], "AXS_XTICKFORMAT", "%1.3f");
  IupSetAttribute(plot[4], "LEGENDSHOW", "YES");
  IupSetAttribute(plot[4], "LEGENDPOS", "BOTTOMRIGHT");

  theFac = (float)100.0/(100*100*100);
  IupPlotBegin(plot[4], 0);
  for (theI=0; theI<=10; theI++) 
  {
    x = (float)(0.0001+theI*0.001);
    y = (float)(0.01+theFac*theI*theI);
    IupPlotAdd(plot[4], x, y);
  }
  IupPlotEnd(plot[4]);
  IupSetAttribute(plot[4], "DS_MODE", "MARKLINE");
  IupSetAttribute(plot[4], "DS_SHOWVALUES", "YES");

  IupPlotBegin(plot[4], 0);
  for (theI=0; theI<=10; theI++) 
  {
    x = (float)(0.0001+theI*0.001);
    y = (float)(0.2-theFac*theI*theI);
    IupPlotAdd(plot[4], x, y);
  }
  IupPlotEnd(plot[4]);
  IupSetAttribute(plot[4], "DS_MODE", "MARK");
  IupSetAttribute(plot[4], "DS_MARKSTYLE", "HOLLOW_CIRCLE");
  
  //PLOT 5 - MakeExamplePlot8
  IupSetAttribute(plot[5], "TITLE", "Data Selection and Editing");
  IupSetAttribute(plot[5], "TITLEFONTSIZE", "16");
  IupSetAttribute(plot[5], "MARGINTOP", "40");

  theFac = (float)100.0/(100*100*100);
  IupPlotBegin(plot[5], 0);
  for (theI=-10; theI<=10; theI++) 
  {
    x = (float)(0.001*theI);
    y = (float)(0.01+theFac*theI*theI*theI);
    IupPlotAdd(plot[5], x, y);
  }
  IupPlotEnd(plot[5]);
  IupSetAttribute(plot[5], "DS_COLOR", "100 100 200");
  IupSetAttribute(plot[5], "DS_EDIT", "YES");
  IupSetCallback(plot[5], "DELETE_CB", (Icallback)delete_cb);
  IupSetCallback(plot[5], "SELECT_CB", (Icallback)select_cb);
  IupSetCallback(plot[5], "POSTDRAW_CB", (Icallback)postdraw_cb);
  IupSetCallback(plot[5], "PREDRAW_CB", (Icallback)predraw_cb);
  IupSetCallback(plot[5], "EDIT_CB", (Icallback)edit_cb);
}
コード例 #4
0
ファイル: iuplua_plot.c プロジェクト: mwoz/Hildim.Source
static int PlotAdd(lua_State *L)
{
  Ihandle *ih = iuplua_checkihandle(L,1);
  IupPlotAdd(ih, luaL_checknumber(L,2), luaL_checknumber(L,3));
  return 0;
}
コード例 #5
0
ファイル: TransferFunction.cpp プロジェクト: rustanitu/TFG
/// <summary>
/// Generates a transfer function file at a given path.
/// If a file with the same path already exists, it'll
/// be replaced.
/// </summary>
/// <returns>Returns true if the transfer function can
/// be generated, false otherwise.</returns>
bool TransferFunction::Generate()
{
  if (!m_value || !m_distance || !m_path)
    throw std::exception_ptr();

  std::ofstream file;
  file.open(m_path);

  if (!file.is_open())
    return false;

  file << "linear" << std::endl;
  file << "0" << std::endl;

  if (m_color_size < 2)
    throw std::domain_error("At least two color must be set!");

  file << m_color_size << std::endl;

  // Assign color to transfer function
  for (int i = 0; i < MAX_V; ++i)
  {
    if (m_has_color[i])
    {
      float r = m_color[(i * 3)] / 255.0f;
      float g = m_color[(i * 3) + 1] / 255.0f;
      float b = m_color[(i * 3) + 2] / 255.0f;

      file << r << " ";
      file << g << " ";
      file << b << " ";
      file << i << std::endl;
    }
  }

  file << m_values_size << std::endl;

  IupSetAttribute(m_tf_plot, "CLEAR", "YES");
  IupPlotBegin(m_tf_plot, 0);
  IupSetAttribute(m_bx_plot, "CLEAR", "YES");
  IupPlotBegin(m_bx_plot, 0);
  
  float amax = 0.4f;
  float base = m_thickness;

  // Assign opacity to transfer function
  int b = 0;
  float last_a = 0.0f;
  for (int i = 0; i < m_values_size; ++i)
  {
    unsigned int value = (unsigned int)m_value[i];
    float x = m_distance[value];

    IupPlotAdd(m_bx_plot, value, fmax(fmin(x, 20), -20));
    
    float a = CenteredTriangleFunction(amax, base, x);

    if (a != last_a && last_a == 0.0f)
      b++;

    last_a = a;
    if (m_boundary != 0 && b != m_boundary)
      a = 0.0f;
    
    file << a << "\t" << value << std::endl;
    IupPlotAdd(m_tf_plot, value, a);
  }

  IupPlotEnd(m_tf_plot);
  IupSetAttribute(m_tf_plot, "DS_NAME", "Transfer Function");
  IupSetAttribute(m_tf_plot, "DS_COLOR", "128 128 128");
  IupSetAttribute(m_tf_plot, "REDRAW", "YES");

  IupPlotEnd(m_bx_plot);
  IupSetAttribute(m_bx_plot, "DS_NAME", "p(v)");

  IupPlotBegin(m_bx_plot, 0);
  IupPlotAdd(m_bx_plot, 0, 0);
  IupPlotAdd(m_bx_plot, 255, 0);
  IupPlotEnd(m_bx_plot);
  IupSetAttribute(m_bx_plot, "DS_NAME", "0");
  IupSetAttribute(m_bx_plot, "DS_COLOR", "0 0 0");

  //IupPlotBegin(m_bx_plot, 0);
  //IupPlotAdd(m_bx_plot, 0, m_thickness);
  //IupPlotAdd(m_bx_plot, 255, m_thickness);
  //IupPlotEnd(m_bx_plot);
  //IupSetAttribute(m_bx_plot, "DS_NAME", "b(x)");
  //IupSetAttribute(m_bx_plot, "DS_COLOR", "128 128 0");

  //IupPlotBegin(m_bx_plot, 0);
  //IupPlotAdd(m_bx_plot, 0, -m_thickness);
  //IupPlotAdd(m_bx_plot, 255, -m_thickness);
  //IupPlotEnd(m_bx_plot);
  //IupSetAttribute(m_bx_plot, "DS_NAME", "b(x)");
  //IupSetAttribute(m_bx_plot, "DS_COLOR", "128 128 0");

  IupSetAttribute(m_bx_plot, "REDRAW", "YES");

  file.close();
  return true;
}