ayha1999
asked on
Running script
Hi,
How can I run attached c# code in page_load or form load event by proving the following STL file?
http://orion.math.iastate.edu/burkardt/data/stl/bottle.stl
Please help.
ayha
script.txt
How can I run attached c# code in page_load or form load event by proving the following STL file?
http://orion.math.iastate.edu/burkardt/data/stl/bottle.stl
Please help.
ayha
script.txt
The filename argument is the location of the .stl file in the server.
ASKER
I will check it and come back.
Meantime, could u please have look the following question?
https://www.experts-exchange.com/questions/28009868/PHP-to-C.html
Thanks
Meantime, could u please have look the following question?
https://www.experts-exchange.com/questions/28009868/PHP-to-C.html
Thanks
U already got it answered
ASKER
I tried the code but ended up with a syntax error.
ERROR: Possible mistaken empty statement at ';' in the end of the statement.
protected void Page_Load(object sender, EventArgs e)
{
var stlutils = new STLUtils();
if (stlutils.IsValidated(new string[] { Server.MapPath("~/website1 /Part1_ful l tray..stl"), STLUtils.LengthType.inch.T oString() }));
}
ayha
ERROR: Possible mistaken empty statement at ';' in the end of the statement.
protected void Page_Load(object sender, EventArgs e)
{
var stlutils = new STLUtils();
if (stlutils.IsValidated(new string[] { Server.MapPath("~/website1
}
ayha
U have 2 dots between the file name and the extension stl
ASKER
I removed but still same error.
Debug the code and post the line that causes the error
Also can u post the stlutil class here?
ASKER
instead of red underline for syntax error it is green underline and when debugging, not showing error.
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
using System.IO;
/// </summary>
public class Triangle
{
public double x; public double y; public double z;
}
public class STLUtils
{
public enum LengthType { inch, cm } ;
List<byte[]> _normals = new List<byte[]>();
List<byte[]> _points = new List<byte[]>();
List<Triangle> _triangles = new List<Triangle>();
List<byte> _bytecount = new List<byte>();
byte[] _fileBytes;
LengthType _lengthType;
string _filename;
public bool IsValidated(string[] args)
{
if (args.Length != 2) return false;
if (!Enum.TryParse<LengthType >(args[1], true, out _lengthType))
{
return false;
}
_filename = args[0];
return File.Exists(_filename);
}
public double CalculateVolume()
{
//read binary file
_fileBytes = File.ReadAllBytes(_filenam e);
//reverse array if little indian
if (BitConverter.IsLittleEndi an)
Array.Reverse(_fileBytes);
//read length
int length = ReadLength();
double totalVol = 0;
//skip 80(header) + 4(length)
var bytes = _fileBytes.Skip(84);
//loop through all triangles data
for (int i = 0; i < length; i++)
{
_normals.Add(bytes.Take(12 ).ToArray( ));
var p1 = bytes.Skip(12).Take(12).To Array();
var p2 = bytes.Skip(24).Take(12).To Array();
var p3 = bytes.Skip(36).Take(12).To Array();
var b = bytes.Skip(48).Take(2);
var l = _points.Count;
_points.Add(p1);
_points.Add(p2);
_points.Add(p3);
_triangles.Add(new Triangle { x = l, y = l + 1, z = l + 2 });
_bytecount.Add(b.First());
totalVol += signedVolumeOfTriangle(p1, p2, p3);
bytes = bytes.Skip(50);
}
//convert to required length type (cm/inch)
return (_lengthType == LengthType.cm) ?
totalVol / 1000 :
cm3_To_inch3Transform(tota lVol / 1000);
}
private double cm3_To_inch3Transform(doub le totalVol)
{
return totalVol * 0.0610237441;
}
private int ReadLength()
{
//skip 80 chars (header), read next 4 bytes to get length
int length = BitConverter.ToInt32(_file Bytes.Skip (80).Take( 4).ToArray (), 0);
return length;
}
public double signedVolumeOfTriangle(byt e[] p1, byte[] p2, byte[] p3)
{
double v321 = p3[0] * p2[1] * p1[2];
double v231 = p2[0] * p3[1] * p1[2];
double v312 = p3[0] * p1[1] * p2[2];
double v132 = p1[0] * p3[1] * p2[2];
double v213 = p2[0] * p1[1] * p3[2];
double v123 = p1[0] * p2[1] * p3[2];
return (1.0 / 6.0) * (-v321 + v231 + v312 - v132 - v213 + v123);
}
}
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.IO;
/// </summary>
public class Triangle
{
public double x; public double y; public double z;
}
public class STLUtils
{
public enum LengthType { inch, cm } ;
List<byte[]> _normals = new List<byte[]>();
List<byte[]> _points = new List<byte[]>();
List<Triangle> _triangles = new List<Triangle>();
List<byte> _bytecount = new List<byte>();
byte[] _fileBytes;
LengthType _lengthType;
string _filename;
public bool IsValidated(string[] args)
{
if (args.Length != 2) return false;
if (!Enum.TryParse<LengthType
{
return false;
}
_filename = args[0];
return File.Exists(_filename);
}
public double CalculateVolume()
{
//read binary file
_fileBytes = File.ReadAllBytes(_filenam
//reverse array if little indian
if (BitConverter.IsLittleEndi
Array.Reverse(_fileBytes);
//read length
int length = ReadLength();
double totalVol = 0;
//skip 80(header) + 4(length)
var bytes = _fileBytes.Skip(84);
//loop through all triangles data
for (int i = 0; i < length; i++)
{
_normals.Add(bytes.Take(12
var p1 = bytes.Skip(12).Take(12).To
var p2 = bytes.Skip(24).Take(12).To
var p3 = bytes.Skip(36).Take(12).To
var b = bytes.Skip(48).Take(2);
var l = _points.Count;
_points.Add(p1);
_points.Add(p2);
_points.Add(p3);
_triangles.Add(new Triangle { x = l, y = l + 1, z = l + 2 });
_bytecount.Add(b.First());
totalVol += signedVolumeOfTriangle(p1,
bytes = bytes.Skip(50);
}
//convert to required length type (cm/inch)
return (_lengthType == LengthType.cm) ?
totalVol / 1000 :
cm3_To_inch3Transform(tota
}
private double cm3_To_inch3Transform(doub
{
return totalVol * 0.0610237441;
}
private int ReadLength()
{
//skip 80 chars (header), read next 4 bytes to get length
int length = BitConverter.ToInt32(_file
return length;
}
public double signedVolumeOfTriangle(byt
{
double v321 = p3[0] * p2[1] * p1[2];
double v231 = p2[0] * p3[1] * p1[2];
double v312 = p3[0] * p1[1] * p2[2];
double v132 = p1[0] * p3[1] * p2[2];
double v213 = p2[0] * p1[1] * p3[2];
double v123 = p1[0] * p2[1] * p3[2];
return (1.0 / 6.0) * (-v321 + v231 + v312 - v132 - v213 + v123);
}
}
What is that mean? do u get an error or not?
ASKER
as I told you, a syntax error and when I run no result in the page. Actually I expect to execute CalculateVolume function and return result.
What is the error? Which line of code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Now error but no result returned,
Debug the code see if it calculates all data correctly
Ive no way of knowing what is wrong without a file
Ive no way of knowing what is wrong without a file
ASKER
could u pls try this file
http://orion.math.iastate.edu/burkardt/data/stl/bottle.stl
no error but no result.
http://orion.math.iastate.edu/burkardt/data/stl/bottle.stl
no error but no result.
i didn't realize it can be open in any text editor... (i wasn't familiar with the file type).
did u try it?
do you see the figures?
cause it would make it so much easier to process it as if it was a text file rather binary file like you had in php.
what do u think?
did u try it?
do you see the figures?
cause it would make it so much easier to process it as if it was a text file rather binary file like you had in php.
what do u think?
ASKER
Thanks
Take the stlutil class and add it to your aspnet project.
If the file is on the server then put it in the physical directory where you deploy your web app.
In your form load use the same code from class main but pass the args array to IsValidated like thid:
var stlutils=new STLUtils();
If(stlutils.IsValidated(ne