Interactive3DSurfacePlot.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. using System;
  2. using System.Drawing;
  3. using System.Threading;
  4. using System.Windows.Forms;
  5. namespace PaintDotNet.Data.SurfacePlot
  6. {
  7. public class Interactive3DSurfacePlot
  8. {
  9. private int DOTS = 0;
  10. private int LINES = 1;
  11. private int MESH = 2;
  12. private int FILLED = 3;
  13. private int ISOLINES = 4;
  14. private int plotType = 1;
  15. /**
  16. private String DOTS_PLOT = "Dots";
  17. private String LINES_PLOT = "Lines";
  18. private String MESH_PLOT = "Mesh";
  19. private String FILLED_PLOT = "Filled";
  20. private String ISOLINES_PLOT = "Isolines";
  21. **/
  22. private static int ORIGINAL = 0;
  23. //private static int GRAYSCALE = 1;
  24. //private static int SPECTRUM = 2;
  25. //private static int FIRE = 3;
  26. //private static int THERMAL = 4;
  27. //private static int GRADIENT = 5;
  28. //private static int BLUE = 6;
  29. //private static int ORANGE = 7;
  30. private int colorType = ORIGINAL;
  31. //private String ORIGINAL_COLORS = "Original Colors";
  32. //private String GRAYSCALE_LUT = "Grayscale";
  33. //private String SPECTRUM_LUT = "Spectrum LUT";
  34. //private String FIRE_LUT = "Fire LUT";
  35. //private String THERMAL_LUT = "Thermal LUT";
  36. //private String GRADIENT_COLORS = "Gradient";
  37. //private String ORANGE_LUT = "Orange";
  38. //private String BLUE_LUT = "Blue";
  39. // imgeJ3D API components
  40. private JRenderer3D jRenderer3D;
  41. // other global params
  42. static int SIZE = 600;
  43. private int windowWidth = (int)(SIZE * 1.2);
  44. private int windowHeight = SIZE;
  45. private int startWindowWidth = (int)(SIZE * 1.2);
  46. private int startWindowHeight = SIZE;
  47. private double scaleWindow = 1; // scaling caused by the resize
  48. private int xStart;
  49. private int yStart;
  50. private bool drag;
  51. private int xdiff;
  52. private int ydiff;
  53. private double light = 0.2;
  54. private bool invertZ = false;
  55. private int imageWidth;
  56. private int imageHeight;
  57. private double scaleInit = 1;
  58. private double zRatioInit = 1;
  59. private double scaledWidth;
  60. private double scaledHeight;
  61. private double minVal;
  62. private double maxVal;
  63. private string units;
  64. private double maxDistance;
  65. //private Calibration cal;
  66. private bool isEqualxyzRatio = true;
  67. private double zAspectRatioSlider = 1;
  68. private double zAspectRatio = 1;
  69. private double scaleSlider = 1;
  70. private double minZ;
  71. private double maxZ;
  72. protected bool draftDrawing = true;
  73. private int xloc;
  74. private int yloc;
  75. private int grid = 128;
  76. private double smooth = 3;
  77. private double perspective = 0;
  78. private bool drawText = true;
  79. private bool drawLegend = true;
  80. private bool drawAxes = true;
  81. private bool drawLines = true;
  82. private double rotationX = 65;
  83. private double rotationZ = 39;
  84. private int minSlider = 0;
  85. private int maxSlider = 100;
  86. private bool snapshot = false;
  87. protected Color bgColor = Color.Gray;
  88. protected Color lineColor = Color.White;
  89. //zyh加的参数
  90. private Bitmap image;
  91. private Form frame;
  92. private PictureBox mainPanel;
  93. public void run(Bitmap mat)
  94. {
  95. if (mat == null)
  96. {
  97. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
  98. }
  99. else
  100. {
  101. image = mat;
  102. imageWidth = image.Width;
  103. imageHeight = image.Height;
  104. runApplication("3D展示");
  105. }
  106. }
  107. private void runApplication(String name)
  108. {
  109. readPrefs();
  110. string strFrame = "Interactive 3D Surface Plot";
  111. string str = "";
  112. // read macro parameters
  113. try
  114. {
  115. if (str != null)
  116. {
  117. string[] params1 = new string[]{
  118. "light=", "perspective=", "grid=", "smooth=", "plotType=", "colorType=", "drawAxes=", "drawLines=",
  119. "drawText=","drawLegend=", "invertZ=", "isEqualxyzRatio=", "rotationX=", "rotationZ=", "scale=", "scaleZ=",
  120. "min=", "max=", "snapshot=", "backgroundColor=", "lineColor=" , "windowHeight=", "windowWidth=" };
  121. double[] paramVals = { light, perspective, grid, smooth, plotType, colorType, (drawAxes == true) ? 1 : 0, (drawLines == true) ? 1 : 0,
  122. (drawText == true) ? 1 : 0, (drawLegend == true) ? 1 : 0, (invertZ == true) ? 1 : 0, (isEqualxyzRatio == true) ? 1 : 0,
  123. rotationX, rotationZ, scaleSlider, zAspectRatioSlider,
  124. minSlider, maxSlider, (snapshot == true) ? 1 : 0, bgColor.ToArgb(), lineColor.ToArgb(), windowHeight, windowWidth };
  125. light = Math.Min(1, Math.Max(0, paramVals[0]));
  126. perspective = Math.Min(1, Math.Max(0, paramVals[1]));
  127. grid = (int)Math.Min(1024, Math.Max(10, paramVals[2]));
  128. smooth = paramVals[3];
  129. plotType = (int)paramVals[4];
  130. colorType = (int)paramVals[5];
  131. drawAxes = (paramVals[6] == 1) ? true : false;
  132. drawLines = (paramVals[7] == 1) ? true : false;
  133. drawText = (paramVals[8] == 1) ? true : false;
  134. drawLegend = (paramVals[9] == 1) ? true : false;
  135. invertZ = (paramVals[10] == 1) ? true : false;
  136. isEqualxyzRatio = (paramVals[11] == 1) ? true : false;
  137. rotationX = paramVals[12];
  138. rotationZ = paramVals[13];
  139. scaleSlider = Math.Min(3, Math.Max(0.25, paramVals[14]));
  140. zAspectRatioSlider = Math.Min(10, Math.Max(0.1, paramVals[15]));
  141. minSlider = (int)Math.Min(99, Math.Max(0, paramVals[16]));
  142. maxSlider = (int)Math.Min(100, Math.Max(1, paramVals[17]));
  143. snapshot = (paramVals[18] == 1) ? true : false;
  144. bgColor = Color.Gray;
  145. lineColor = Color.Red;
  146. windowHeight = (int)paramVals[21];
  147. windowWidth = (int)paramVals[22];
  148. }
  149. }
  150. catch (Exception e1)
  151. {
  152. Console.WriteLine(e1.ToString());
  153. }
  154. frame = new Form();
  155. frame.Width = windowWidth; // image.Width * 3;
  156. frame.Height = windowHeight; // image.Height * 3;
  157. frame.Name = strFrame;
  158. createGUI();
  159. frame.Location = new System.Drawing.Point(xloc, yloc);
  160. create3DRenderer();
  161. }
  162. /**
  163. * Initializes the JRenderer3D. Set Background, the surface plot, plot mode, lightning mode.
  164. * Adds a coordinate system. Sets scale. Renders and updates the image.
  165. */
  166. private void create3DRenderer()
  167. {
  168. double wc = (imageWidth) / 2;
  169. double hc = (imageHeight) / 2;
  170. double dc = 256 / 2;
  171. /**
  172. *zyh 这里比较重要,目前是写死的,需要换算缩放比例
  173. **/
  174. scaledWidth = imageWidth;// cal.getX(imageWidth);
  175. scaledHeight = imageHeight;// cal.getY(imageHeight);
  176. minVal = 0; //ip.getMin();
  177. maxVal = 255; //ip.getMax();
  178. units = "pixels"; // cal.getUnits();
  179. // create 3D renderer
  180. // center in the middle of the image
  181. jRenderer3D = new JRenderer3D(wc, hc, dc);
  182. jRenderer3D.setBufferSize(windowWidth, windowHeight);
  183. setScaleAndZRatio();
  184. int gridHeight, gridWidth; ;
  185. if (imageHeight > imageWidth)
  186. {
  187. gridHeight = grid;
  188. gridWidth = grid * imageWidth / imageHeight;
  189. }
  190. else
  191. {
  192. gridWidth = grid;
  193. gridHeight = grid * imageHeight / imageWidth;
  194. }
  195. jRenderer3D.setSurfacePlotGridSize(gridWidth, gridHeight);
  196. jRenderer3D.setAxes(drawAxes);
  197. jRenderer3D.setLines(drawLines);
  198. jRenderer3D.setText(drawText);
  199. jRenderer3D.setLegend(drawLegend);
  200. // surface plot
  201. jRenderer3D.setSurfacePlot(image);
  202. jRenderer3D.surfacePlotSetInverse(invertZ);
  203. jRenderer3D.setTransformRotationXYZ(rotationX, 0, rotationZ); // viewing angle (in degrees)
  204. jRenderer3D.setSurfaceSmoothingFactor(smooth);
  205. jRenderer3D.setSurfacePlotLight(light);
  206. jRenderer3D.setSurfacePlotMinMax(minSlider, maxSlider);
  207. jRenderer3D.setBackgroundColor(bgColor.ToArgb());
  208. setSurfaceColorType(colorType);
  209. setSurfacePlotType(plotType);
  210. try
  211. {
  212. Thread.Sleep(2500);
  213. }
  214. catch (Exception e)
  215. {
  216. Console.WriteLine(e.ToString());
  217. }
  218. renderAndUpdateDisplay();
  219. }
  220. /**
  221. * Sets the surface color type.
  222. *
  223. */
  224. private void setSurfaceColorType(int type)
  225. {
  226. colorType = type;
  227. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_ORIGINAL);
  228. /**
  229. if (type == ORIGINAL)
  230. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_ORIGINAL);
  231. else if (type == GRAYSCALE)
  232. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_GRAY);
  233. else if (type == SPECTRUM)
  234. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_SPECTRUM);
  235. else if (type == FIRE)
  236. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_FIRE);
  237. else if (type == THERMAL)
  238. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_THERMAL);
  239. else if (type == GRADIENT)
  240. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_GRADIENT);
  241. else if (type == ORANGE)
  242. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_ORANGE);
  243. else if (type == BLUE)
  244. jRenderer3D.setSurfacePlotLut(JRenderer3D.LUT_BLUE);
  245. **/
  246. }
  247. /**
  248. * Sets the surface plot mode.
  249. *
  250. */
  251. private void setSurfacePlotType(int type)
  252. {
  253. if (type == DOTS)
  254. jRenderer3D.setSurfacePlotMode(JRenderer3D.SURFACEPLOT_DOTS);
  255. else if (type == LINES)
  256. jRenderer3D.setSurfacePlotMode(JRenderer3D.SURFACEPLOT_LINES);
  257. else if (type == MESH)
  258. jRenderer3D.setSurfacePlotMode(JRenderer3D.SURFACEPLOT_MESH);
  259. else if (type == ISOLINES)
  260. jRenderer3D.setSurfacePlotMode(JRenderer3D.SURFACEPLOT_ISOLINES);
  261. else if (type == FILLED)
  262. jRenderer3D.setSurfacePlotMode(JRenderer3D.SURFACEPLOT_FILLED);
  263. }
  264. /**
  265. * Renders and updates the 3D image.
  266. * Image region is repainted.
  267. */
  268. bool show = false;
  269. private void renderAndUpdateDisplay()
  270. {
  271. jRenderer3D.doRendering();
  272. if (mainPanel != null)
  273. {
  274. mainPanel.Refresh();
  275. mainPanel.Image = jRenderer3D.getImage();
  276. if (!show)
  277. {
  278. show = true;
  279. frame.ShowDialog();
  280. }
  281. }
  282. }
  283. private void setScaleAndZRatio()
  284. {
  285. if (isEqualxyzRatio)
  286. {
  287. zRatioInit = (maxVal - minVal) / (255 * scaledWidth / imageWidth);
  288. // determine initial scale factor
  289. scaleInit = 0.55 * Math.Max(startWindowHeight, startWindowWidth) / (double)Math.Max(imageWidth, Math.Max(255 * zRatioInit, imageHeight));
  290. }
  291. else
  292. {
  293. scaleInit = 0.55 * Math.Max(startWindowHeight, startWindowWidth) / (double)Math.Max(imageHeight, imageWidth);
  294. zRatioInit = 0.55 * startWindowHeight / (256 * scaleInit);
  295. }
  296. zAspectRatio = zRatioInit * zAspectRatioSlider;
  297. scaleWindow = Math.Min(windowHeight, windowWidth) / (double)startWindowHeight;
  298. jRenderer3D.setTransformZAspectRatio(zAspectRatio);
  299. double scale = scaleInit * scaleSlider * scaleWindow;
  300. jRenderer3D.setTransformScale(scale);
  301. jRenderer3D.setTransformPerspective(perspective);
  302. maxDistance = Math.Max(scaledWidth, Math.Max(scaledHeight, 256 * Math.Max(zAspectRatio, 1)));
  303. jRenderer3D.setTransformMaxDistance(maxDistance);
  304. jRenderer3D.setLegendTextColor(lineColor);
  305. addCoordinateSystem();
  306. }
  307. private void addCoordinateSystem()
  308. {
  309. jRenderer3D.clearText();
  310. jRenderer3D.clearLines();
  311. jRenderer3D.clearCubes();
  312. int id = 256;
  313. minZ = minVal + minSlider / 100 * (maxVal - minVal);
  314. maxZ = maxVal - (100 - maxSlider) / 100 * (maxVal - minVal);
  315. jRenderer3D.setMinZValue(minZ);
  316. jRenderer3D.setMaxZValue(maxZ);
  317. // add text to the coordinate system
  318. double off = 16 / scaleInit;
  319. double fontSize = 12 / scaleInit;
  320. double offZ = off / zAspectRatio;
  321. int ticksDist = 40;
  322. Color textColor = lineColor;
  323. double x1 = 0;
  324. double y1 = 0;
  325. double z1 = 0;
  326. double x2 = imageWidth;
  327. double y2 = imageHeight;
  328. double z2 = id;
  329. int numTicks = (int)Math.Round(imageHeight * scaleInit / ticksDist);
  330. double pos = 0;
  331. double stepValue = calcStepSize(scaledHeight, numTicks);
  332. for (double value = 0; value <= scaledHeight; value += stepValue)
  333. {
  334. String s;
  335. if (Math.Floor(value) - value == 0)
  336. s = "" + (int)value;
  337. else
  338. s = "" + (int)Math.Round(value * 1000) / 1000;
  339. // unit String for the last position
  340. if (value + stepValue > scaledHeight || value == scaledHeight)
  341. {
  342. if (!units.Equals("pixels"))
  343. s = "y/" + units;
  344. else
  345. s = "y";
  346. }
  347. pos = (value * imageHeight / scaledHeight);
  348. y1 = y2 = pos;
  349. jRenderer3D.addText3D(new Text3D(s, x1 - off, y1, z1 - offZ, textColor, fontSize, 2));
  350. jRenderer3D.addText3D(new Text3D(s, x2 + off, y2, z1 - offZ, textColor, fontSize));
  351. jRenderer3D.addLine3D(new Line3D(x1, y1, z1, x1, y1, z2, lineColor, true));
  352. jRenderer3D.addLine3D(new Line3D(x2, y2, z1, x2, y2, z2, lineColor));
  353. jRenderer3D.addLine3D(new Line3D(x1, y1, z1, x2, y2, z1, lineColor, true));
  354. jRenderer3D.addLine3D(new Line3D(x1, y1, z2, x2, y2, z2, lineColor));
  355. }
  356. numTicks = (int)Math.Round(imageWidth * scaleInit / ticksDist);
  357. stepValue = calcStepSize(scaledWidth, numTicks);
  358. y1 = 0;
  359. y2 = imageHeight;
  360. for (double value = 0; value <= scaledWidth; value += stepValue)
  361. {
  362. String s;
  363. if (Math.Floor(value) - value == 0)
  364. s = "" + (int)value;
  365. else
  366. s = "" + (int)Math.Round(value * 1000) / 1000;
  367. if (value + stepValue > scaledWidth || value == scaledWidth)
  368. {
  369. if (!units.Equals("pixels"))
  370. s = "x/" + units;
  371. else
  372. s = "x";
  373. }
  374. pos = value * imageWidth / scaledWidth;
  375. x1 = x2 = pos;
  376. jRenderer3D.addText3D(new Text3D(s, x1, y1 - off, z1 - offZ, textColor, fontSize, 2));
  377. jRenderer3D.addText3D(new Text3D(s, x2, y2 + off, z1 - offZ, textColor, fontSize));
  378. jRenderer3D.addLine3D(new Line3D(x1, y1, z1, x1, y1, z2, lineColor, true));
  379. jRenderer3D.addLine3D(new Line3D(x2, y2, z1, x2, y2, z2, lineColor));
  380. jRenderer3D.addLine3D(new Line3D(x1, y1, z1, x2, y2, z1, lineColor, true));
  381. jRenderer3D.addLine3D(new Line3D(x1, y1, z2, x2, y2, z2, lineColor));
  382. }
  383. double d = maxZ - minZ;
  384. numTicks = (int)Math.Round(255 * zAspectRatio * scaleInit / (ticksDist / 1.3));
  385. if (numTicks < 2)
  386. numTicks = 2;
  387. stepValue = calcStepSize(d, numTicks);
  388. x1 = 0;
  389. y1 = 0;
  390. x2 = imageWidth;
  391. y2 = imageHeight;
  392. double minStart = Math.Floor(minZ / stepValue) * stepValue;
  393. double delta = minStart - minZ;
  394. for (double value = 0; value + delta <= d; value += stepValue)
  395. {
  396. String s;
  397. if (Math.Floor(minStart + value) - (minStart + value) == 0)
  398. s = "" + (int)(minStart + value);
  399. else
  400. s = "" + (int)Math.Round((minStart + value) * 1000) / 1000;
  401. pos = ((value + delta) * id / d);
  402. if (pos >= 0)
  403. {
  404. z1 = z2 = pos;
  405. if (invertZ)
  406. z1 = z2 = 255 - pos;
  407. jRenderer3D.addText3D(new Text3D(s, x1 - off, y1 - off, z1, textColor, fontSize, 4));
  408. jRenderer3D.addText3D(new Text3D(s, x2 + off, y2 + off, z2, textColor, fontSize));
  409. jRenderer3D.addText3D(new Text3D(s, x1 - off, y2 + off, z1, textColor, fontSize));
  410. jRenderer3D.addText3D(new Text3D(s, x2 + off, y1 - off, z2, textColor, fontSize));
  411. jRenderer3D.addLine3D(new Line3D(x1, y1, z1, x1, y2, z2, lineColor, true));
  412. jRenderer3D.addLine3D(new Line3D(x2, y1, z1, x2, y2, z2, lineColor));
  413. jRenderer3D.addLine3D(new Line3D(x1, y1, z1, x2, y1, z2, lineColor, true));
  414. jRenderer3D.addLine3D(new Line3D(x1, y2, z1, x2, y2, z2, lineColor));
  415. }
  416. }
  417. double myvalue = d + stepValue / 1.3;
  418. String mys = " z";
  419. double fontzoom = 1;
  420. pos = ((myvalue + delta) * id / d);
  421. if (pos >= 0)
  422. {
  423. z1 = z2 = pos;
  424. if (invertZ)
  425. z1 = z2 = 255 - pos;
  426. jRenderer3D.addText3D(new Text3D(mys, x1 - off, y1 - off, z1, textColor, fontSize * fontzoom, 4));
  427. jRenderer3D.addText3D(new Text3D(mys, x2 + off, y2 + off, z2, textColor, fontSize * fontzoom));
  428. jRenderer3D.addText3D(new Text3D(mys, x1 - off, y2 + off, z1, textColor, fontSize * fontzoom));
  429. jRenderer3D.addText3D(new Text3D(mys, x2 + off, y1 - off, z2, textColor, fontSize * fontzoom));
  430. }
  431. // add coordinate system
  432. jRenderer3D.add3DCube(0, 0, 0, imageWidth, imageHeight, id, lineColor);
  433. }
  434. double calcStepSize(double range, double targetSteps)
  435. {
  436. // Calculate an initial guess at step size
  437. double tempStep = range / targetSteps;
  438. // Get the magnitude of the step size
  439. double mag = Math.Floor(Math.Log(tempStep) / Math.Log(10));
  440. double magPow = Math.Pow((double)10.0, mag);
  441. // Calculate most significant digit of the new step size
  442. double magMsd = ((int)(tempStep / magPow + .5));
  443. // promote the MSD to either 1, 2, 4, or 5
  444. if (magMsd > 6) // 5
  445. magMsd = 10.0;
  446. else if (magMsd > 3)
  447. magMsd = 5.0;
  448. else if (magMsd > 2)
  449. magMsd = 4.0;
  450. else if (magMsd > 1)
  451. magMsd = 2.0;
  452. return magMsd * magPow;
  453. }
  454. private void createGUI()
  455. {
  456. mainPanel = createImagePanel();
  457. frame.Controls.Add(mainPanel);
  458. }
  459. private PictureBox createImagePanel()
  460. {
  461. mainPanel = new PictureBox();
  462. mainPanel.Dock = DockStyle.Fill;
  463. mainPanel.MouseDown += new MouseEventHandler(this.picMoveDownListener);
  464. mainPanel.MouseUp += new MouseEventHandler(this.picMoveUpListener);
  465. mainPanel.MouseMove += new MouseEventHandler(this.picMoveListener);
  466. mainPanel.DoubleClick += new EventHandler(this.picDoubleClickListener);
  467. return mainPanel;
  468. }
  469. private void picDoubleClickListener(object sender, EventArgs e)
  470. {
  471. jRenderer3D.setTransformRotationXYZ(0, 0, 0);
  472. renderAndUpdateDisplay();
  473. }
  474. private void picMoveDownListener(object sender, MouseEventArgs e)
  475. {
  476. xStart = e.X;
  477. yStart = e.Y;
  478. xdiff = 0;
  479. ydiff = 0;
  480. drag = true;
  481. }
  482. private void picMoveUpListener(object sender, MouseEventArgs e)
  483. {
  484. drag = false;
  485. }
  486. private void picMoveListener(object sender, MouseEventArgs e)
  487. {
  488. if (drag)
  489. {
  490. if (draftDrawing)
  491. jRenderer3D.setSurfacePlotMode(JRenderer3D.SURFACEPLOT_DOTSNOLIGHT);
  492. int xAct = e.X;
  493. int yAct = e.Y;
  494. xdiff = xAct - xStart;
  495. ydiff = yAct - yStart;
  496. xStart = xAct;
  497. yStart = yAct;
  498. jRenderer3D.changeTransformRotationXZ(-ydiff / 2, xdiff / 2);
  499. rotationX = jRenderer3D.getTransformRotationX();
  500. rotationZ = jRenderer3D.getTransformRotationZ();
  501. renderAndUpdateDisplay();
  502. }
  503. }
  504. private void readPrefs()
  505. {
  506. if (true)
  507. {
  508. // get screen dimensions
  509. //Toolkit toolkit = Toolkit.getDefaultToolkit();
  510. //Dimension screenSize = toolkit.getScreenSize();
  511. int screenWidth = Screen.PrimaryScreen.Bounds.Width;
  512. int screenHeight = Screen.PrimaryScreen.Bounds.Height;
  513. //Insets ins = frame.getInsets();
  514. //xloc = (screenWidth-windowWidth-ins.left-ins.right - 70)/2;
  515. //yloc = (screenHeight-windowHeight-ins.bottom-ins.top - 75)/2;
  516. xloc = (screenWidth - windowWidth - 70) / 2;
  517. yloc = (screenHeight - windowHeight - 75) / 2;
  518. light = 0.0;
  519. perspective = 0.0;
  520. grid = 512;
  521. smooth = 43.0;
  522. plotType = 1;// FILLED;
  523. colorType = 1;// GRADIENT;
  524. drawAxes = true;
  525. drawLines = true;
  526. drawText = true;
  527. drawLegend = true;
  528. invertZ = false;
  529. isEqualxyzRatio = false;
  530. rotationX = 65;
  531. rotationZ = 39;
  532. scaleSlider = 1;
  533. zAspectRatioSlider = 1;
  534. minSlider = 0;
  535. maxSlider = 100;
  536. }
  537. else
  538. {
  539. /**
  540. int screenWidth = Screen.PrimaryScreen.Bounds.Width;
  541. int screenHeight = Screen.PrimaryScreen.Bounds.Height;
  542. xloc = (screenWidth - windowWidth - 70) / 2;
  543. yloc = (screenHeight - windowHeight - 75) / 2;
  544. //xloc = 541; // (int)Prefs.get("ISP3D.xloc", 100);
  545. //yloc = 95; // (int)Prefs.get("ISP3D.yloc", 50);
  546. light = 0.3; //Prefs.get("ISP3D.light", 0.2);
  547. perspective = 0.0; // Prefs.get("ISP3D.perspective", 0);
  548. grid = 256; // (int)Prefs.get("ISP3D.grid", 256);
  549. smooth = 22.0; // Prefs.get("ISP3D.smooth", 0);
  550. plotType = 1;// (int)Prefs.get("ISP3D.plotType", LINES);
  551. colorType = 1;// (int)Prefs.get("ISP3D.colorType", ORIGINAL);
  552. drawAxes = true;//Prefs.get("ISP3D.drawAxes", true);
  553. drawLines = true;//Prefs.get("ISP3D.drawLines", true);
  554. drawText = true;//Prefs.get("ISP3D.drawText", true);
  555. drawLegend = true;//Prefs.get("ISP3D.drawLegend", true);
  556. invertZ = false;//Prefs.get("ISP3D.invertZ", false);
  557. isEqualxyzRatio = false;//Prefs.get("ISP3D.isEqualxyzRatio", false);
  558. rotationX = 359;// Prefs.get("ISP3D.rotationX", 65);
  559. rotationZ = -1.5;// Prefs.get("ISP3D.rotationZ", 39);
  560. windowHeight = 600;// (int)Prefs.get("ISP3D.windowHeight", windowHeight);
  561. windowWidth = 720;// (int)Prefs.get("ISP3D.windowWidth", windowWidth);
  562. scaleSlider = 1.01;// Prefs.get("ISP3D.scale", scaleSlider);
  563. zAspectRatioSlider = 2.8138;// Prefs.get("ISP3D.zScale", zAspectRatioSlider);
  564. minSlider = 0;// Math.min(Math.max((int)Prefs.get("ISP3D.min", minSlider), 0), 99);
  565. maxSlider = 100;// Math.min(Math.max((int)Prefs.get("ISP3D.max", maxSlider), 1), 100);
  566. bgColor = Color.Gray;//new Color((int)Prefs.get("ISP3D.bgColor", Color.GRAY.getRGB()));
  567. lineColor = Color.White;// new Color((int)Prefs.get("ISP3D.lineColor", Color.WHITE.getRGB()));
  568. **/
  569. }
  570. }
  571. }
  572. }