public bool Load(StreamReader sr) { try { //load color int a = byte.Parse(sr.ReadLine()); int r = byte.Parse(sr.ReadLine()); //R int g = byte.Parse(sr.ReadLine()); //G int b = byte.Parse(sr.ReadLine()); //B m_color = Color.FromArgb(a, r, g, b); //load numer of points int npoint = int.Parse(sr.ReadLine()); //load points for (int c = 0; c < npoint; c++) { Point3d p = new Point3d(); p.Load(sr); m_points.Add(p); } return(true); } catch (Exception) { return(false); } }
public bool LoadSTL_Binary(string filename) { BinaryReader br = null; try { br = new BinaryReader(File.Open(filename, FileMode.Open)); m_fullname = filename; m_name = Path.GetFileNameWithoutExtension(filename); byte[] data = new byte[80]; data = br.ReadBytes(80); // read the header uint numtri = br.ReadUInt32(); for (uint c = 0; c < numtri; c++) { Polygon p = new Polygon(); m_lstpolys.Add(p); // add this polygon to the object p.m_normal.Load(br); // load the normal p.m_points = new Point3d[3]; // create storage for (int pc = 0; pc < 3; pc++) //iterate through the points { Point3d pnt = new Point3d(); pnt.Load(br); m_lstpoints.Add(pnt); p.m_points[pc] = pnt; } uint attr = br.ReadUInt16(); // not used attribute } Update(); // initial positions please... br.Close(); return(true); } catch (Exception) { if (br != null) { br.Close(); } return(false); } }
public bool LoadSTL_Binary(string filename) { BinaryReader br = null; try { br = new BinaryReader(File.Open(filename, FileMode.Open)); m_fullname = filename; m_name = Path.GetFileNameWithoutExtension(filename); byte[] data = new byte[80]; data = br.ReadBytes(80); // read the header uint numtri = br.ReadUInt32(); for (uint c = 0; c < numtri; c++) { Polygon p = new Polygon(); m_lstpolys.Add(p); // add this polygon to the object p.m_normal.Load(br); // load the normal p.m_points = new Point3d[3]; // create storage for (int pc = 0; pc < 3; pc++) //iterate through the points { Point3d pnt = new Point3d(); pnt.Load(br); m_lstpoints.Add(pnt); p.m_points[pc] = pnt; } uint attr = br.ReadUInt16(); // attribute COULD be used for color /* * The VisCAM and SolidView software packages use the two "attribute byte count" bytes at the end of every triangle to store a 15-bit RGB color: * * bit 0 to 4 are the intensity level for blue (0 to 31), * bits 5 to 9 are the intensity level for green (0 to 31), * bits 10 to 14 are the intensity level for red (0 to 31), * bit 15 is 1 if the color is valid, or 0 if the color is not valid (as with normal STL files). * */ //BBBBBGGGGGRRRRRV //VRRRRRGGGGGBBBBB byte R, G, B, used; B = (byte)((attr & 0x001f) << 3); G = (byte)((attr >> 5 & 0x001f) << 3); R = (byte)((attr >> 10 & 0x001f) << 3); used = (byte)(attr >> 15 & 0x0001); if (used != 0) { p.m_colorsource = Color.FromArgb(255, R, G, B); p.m_color = p.m_colorsource; } } Update(); // initial positions please... br.Close(); return(true); } catch (Exception) { if (br != null) { br.Close(); } return(false); } }