csv - Using jzy3d to plot 3D surface in Java -
i have tab-delimited csv file has header, , first column labels each row. example.
label sample1 sample2 sample3 sample4 sample5 u.s.a. 10.1 3.2 5.6 6.9 7.3 canada 9.8 4.5 5.7 6.8 7.9
i use supercsv parse csv file , create polygons each point, example: (1, 1, 10.1) [meaning first row, first column]. points added list of polygons. use polygons create surface, surface not continuous. have attached screenshot of plotting
part of code follows:
public void init() { /* build list of polygons out of csv file */ list<polygon> polygons = null; try { polygons = parsecsv("my_csvfile.csv"); } catch (ioexception e) { e.printstacktrace(); } system.out.println("size of polygons is: " + polygons.size()); // creates 3d object shape surface = new shape(polygons); surface.setcolormapper(new colormapper(new colormaprainbow(), surface.getbounds().getzmin(), surface.getbounds().getzmax(), new org.jzy3d.colors.color(1,1,1,1f))); surface.setwireframedisplayed(true); surface.setwireframecolor(org.jzy3d.colors.color.black); chart = awtchartcomponentfactory.chart(quality.advanced, getcanvastype()); // chart = new chart(); chart.getscene().getgraph().add(surface); } public list<polygon> parsecsv(string csvfile) throws ioexception { if (csvfile.isempty()) system.exit(-1); file inputfile = new file(csvfile); string[] header = null; /* header row */ if (inputfile.exists()) { filereader fr = new filereader(inputfile); linenumberreader linereader = new linenumberreader(fr); string headerline = null; while (linereader.getlinenumber() == 0) { headerline = linereader.readline(); } linereader.close(); if (headerline != null) { header = headerline.split("\\t"); } } icsvlistreader listreader = null; list<polygon> polygons = new arraylist<polygon>(); try { listreader = new csvlistreader(new filereader(csvfile), csvpreference.tab_preference); listreader.getheader(true); list<string> contentlist; int rowindex = 1; // excluding header row while((contentlist = listreader.read()) != null) { if (contentlist.size() != header.length) { system.out.println("contentlist size is: " + contentlist.size() + ", header length is: " + header.length); continue; } polygon polygon = new polygon(); (int = 1; < contentlist.size(); i++) { if (doublefactory.tryparsedouble(contentlist.get(i)) != -1) /* unsuccessful double parse returns -1 */ { polygon.add(new point(new coord3d(rowindex, i, double.parsedouble(contentlist.get(i))))); } } rowindex++; polygons.add(polygon); } } { if(listreader != null) { listreader.close(); } } return polygons; } /* inner class parsing string double */ private static class doublefactory { public static double tryparsedouble(final string number) { double result; try { result = double.parsedouble(number); } catch (numberformatexception e) { result = -1; /* default failed parsing*/ } return result; } }
i need creating continuous smooth 3d surface out of csv contents (the numbers)
my code creating polygon list follows
list<polygon> polygons = new arraylist<polygon>(); (int = 0; < m_data.rows-k; i++) { (int j = 0; j < m_data.columns-k; j++) { polygon polygon = new polygon(); polygon.add(new point(new coord3d(i, j, m_data.get(i, j )))); polygon.add(new point(new coord3d(i+1,j, m_data.get(i+1,j )))); polygon.add(new point(new coord3d(i+1,j+1,m_data.get(i+1,j+1)))); polygon.add(new point(new coord3d(i, j+1,m_data.get(i, j+1)))); polygons.add(polygon); } }
where m_data
class variable , matrix. far know, way should create polygon. polygon consisting of single point seems rather unlikely correct.
related question: build 3d surface plot using xyz coordinates jzy3d
Comments
Post a Comment