Help Calculating Normals - Sample Code?

Oct 3, 2012 at 9:10 PM

first thanks for this amaizing tool , i am using mesh builder to create an object made of quads i am passing to the function four points in counter clock  order, this is a laser scanner and i am reading contour to recreated an object, now i have data and an object but it looks bumpy or facet not smooth i need to calculate normals to make it look better,  any help wil be appreciated.

thanks

Gilbert figueroa

orlando, fl

Coordinator
Oct 3, 2012 at 9:41 PM

You don't have to calculate normals, just share vertices for adjacent panels where you want a smooth surface. You will not share vertices when you use the AddQuad method, try to use AddRectangularMesh (if your surface is a 'rectangular mesh') or set the positions and triangle indices yourself!

Oct 13, 2012 at 6:49 AM

Hi Objo

thanks for your last replay i still stock trying to get  a smooth surface im trying to use the addrectangularmesh but no results i was wondering where i can find sample code of the type of data i need to pass to the method it saids it is IList<Point3D>? sample code or sample will be appreciated.

 

thanks

gilbert

Coordinator
Oct 14, 2012 at 2:54 PM

Use "Find usages" function (Shift-F12?) in Visual Studio to find two examples of AddRectangularMesh. The points should be specified 'row by row' and you have to specify the number of 'columns'. Note that the front side of the geometry is defined by the order of the points (reversing the order should reverse the normals).

Oct 14, 2012 at 9:54 PM
Hi Objo and thanks for the replay
Let me add a little more information about what I'm trying to accomplish with the HelixToolkit.

I'm building an application that needs to detect the contour or shape of a hand or foot. This application uses a laser to draw a line on a surface, a hand in this case. We move the laser to a position, then take a snapshot with a camara, analyze the image to detect the X,Y coordinates of the detected red laser line. Then we command the laser to advance a certain distance to a new 'row' (Y coordinate).

What we end up with is a List of rows, technically a List<List<Point3D>>. Our image might be 380 cols by 480 rows. But this list does not contains all the 380x480 points, it just contains the X,Y,Z coordinates of the 'red' laser pixels it detected. As we are advancing the laser 5 or 10 rows at a time we most rows are missing in this collection. Also there can be undetected pixels in each of the rows. So what we have is not a complete collection of X,Y coordinates. And each row might be a different size, etc.

In order to display a more realistic image of the scanned object I'm trying to take this collection of points and plot a smooth surface that interpolates all the missing points from the pixel points we collected from the images.

Below is an excerpt of the different approaches I have taken so far.

First I create the meshBuilder:
MeshBuilder meshBuilder = new MeshBuilder(true, false);

Then we create our points collection and fill it with the data vaules:
List<List<Point3D>> pointsList = new List<List<Point3D>>();
[some code here to fill in the collection]

A- This approach plots a series of small cubes that resemble our scaned hand:
foreach (List<Point3D> pointsRow in pointsList)
foreach (Point3D point in pointsRow)
meshBuilder.AddBox(point, 1, 1, 1);

So that indicates that our points collection is not that far off.

So I'm trying to create a mesh with this points collection by doing this:

Approach #1: (where matrix.maxCols is the width of our image)
meshBuilder.CreateNormals = true;
foreach (List<Point3D> pointsRow in pointsList) {
meshBuilder.AddRectangularMesh(pointsRow, matrix.maxCols);
}

Approach #2: (this will feed a maxCols x maxRows points array with the undertemined values = (0,0,0)
Point3D[,] pointsArray = new Point3D[matrix.maxCols, matrix.maxRows];
foreach (List<Point3D> pointsRow in pointsList)
foreach (Point3D point in pointsRow)
pointsArray[(int)point.X, (int)point.Y] = point;
meshBuilder.AddRectangularMesh(pointsArray);

None of these 2 approaches seems to be working for me and I can't figure out what I'm doing wrong here.
I think it complains about not having the correct number of Normals.
I have also tried to find some examples that uses AddRectangularMesh but no luck so far.
 
Any examples or help in this regard will be greatly appreciated as I'm in an URGENT need to move past this stumble block in order to complete this application.

Thanks in advance!