RenderStack 11.06.1
Public Member Functions | Properties
RenderStack.Geometry.Corner Class Reference

A connection between Point and Polygon. More...

List of all members.

Public Member Functions

 Corner (Point point, Polygon polygon)
void SmoothNormalize (Dictionary< Corner, Vector3 > cornerAttribute, Dictionary< Polygon, Vector3 > polygonAttribute, Dictionary< Polygon, Vector3 > polygonNormals, float cosMaxSmoothingAngle)
 Computes smoothed attribute value for corner.
void SmoothAverage (Dictionary< Corner, Vector4 > newCornerAttribute, Dictionary< Corner, Vector4 > oldCornerAttribute, Dictionary< Corner, Vector3 > cornerNormals, Dictionary< Point, Vector3 > pointNormals)
void Dispose ()

Properties

Point Point [get, set]
Polygon Polygon [get, set]

Detailed Description

Note:
Corner stores only connectivity information. All corner attributes such as texture coordinates are stored externally in attribute maps such as Dictionary<Corner, Vector2>.
Mostly stable.

Definition at line 35 of file Corner.cs.


Constructor & Destructor Documentation

RenderStack.Geometry.Corner.Corner ( Point  point,
Polygon  polygon 
)

Definition at line 40 of file Corner.cs.

        {
            Point   = point;
            Polygon = polygon;
        }

Member Function Documentation

void RenderStack.Geometry.Corner.SmoothNormalize ( Dictionary< Corner, Vector3 cornerAttribute,
Dictionary< Polygon, Vector3 polygonAttribute,
Dictionary< Polygon, Vector3 polygonNormals,
float  cosMaxSmoothingAngle 
)
Parameters:
cornerAttributeAttribute map where to store smoothed attribute value
polygonAttributeAttribute map where to retrieve polygon attribute values from
polygonNormalsAttribute map where to retrieve polygon normals from
cosMaxSmoothingAngleCosine of maximum smoothing angle. Edges sharper than this are not smoothed

Definition at line 51 of file Corner.cs.

References RenderStack.Geometry.Point.Corners, RenderStack.Math.Vector3.Dot(), and RenderStack.Math.Vector3.Normalize().

Referenced by RenderStack.Geometry.Polygon.SmoothNormalize().

        {
            if(polygonNormals.ContainsKey(Polygon) == false)
            {
                return;
            }
            Vector3 polygonNormal = polygonNormals[this.Polygon];
            Vector3 polygonValue = polygonAttribute[this.Polygon];
            Vector3 cornerValue = polygonValue;

            int pointCorners = 0;
            int participants = 0;
            foreach(var pointCorner in Point.Corners)
            {
                ++pointCorners;
                var neighborPolygon = pointCorner.Polygon;
                if(
                    (Polygon != neighborPolygon) &&
                    (polygonNormals.ContainsKey(neighborPolygon) == true) &&
                    (polygonAttribute.ContainsKey(neighborPolygon) == true) &&
                    (neighborPolygon.Corners.Count > 2)
                )
                {
                    Vector3 neighborNormal = polygonNormals[neighborPolygon];
                    //float pLen = polygonNormal.Length;
                    //float nLen = neighborNormal.Length;
                    float cosAngle = Vector3.Dot(
                        polygonNormal, 
                        neighborNormal
                    );
                    if(cosAngle > 1.0f)
                    {
                        cosAngle = 1.0f;
                    }
                    if(cosAngle < -1.0f)
                    {
                        cosAngle = -1.0f;
                    }
                    //  Smaller cosine means larger angle means less sharp
                    //  Higher cosine means lesser angle means more sharp
                    //  Cosine == 1 == maximum sharpness
                    //  Cosine == -1 == minimum sharpness (flat)
                    if(cosAngle <= cosMaxSmoothingAngle)
                    {
                        cornerValue += polygonAttribute[neighborPolygon];
                        ++participants;
                    }
                }
            }

            cornerValue = Vector3.Normalize(cornerValue);
            cornerAttribute[this] = cornerValue;
        }
void RenderStack.Geometry.Corner.SmoothAverage ( Dictionary< Corner, Vector4 newCornerAttribute,
Dictionary< Corner, Vector4 oldCornerAttribute,
Dictionary< Corner, Vector3 cornerNormals,
Dictionary< Point, Vector3 pointNormals 
)

Definition at line 109 of file Corner.cs.

References RenderStack.Geometry.Point.Corners, and RenderStack.Math.Vector4.Zero.

Referenced by RenderStack.Geometry.Polygon.SmoothAverage().

        {
            bool hasCornerNormal = cornerNormals.ContainsKey(this);
            if(
                (hasCornerNormal == false) &&
                (pointNormals.ContainsKey(this.Point) == false)
            )
            {
                return;
            }
            Vector3 cornerNormal = hasCornerNormal ? cornerNormals[this] : pointNormals[this.Point];
            Vector4 cornerValue = Vector4.Zero;

            int pointCorners = 0;
            int participants = 0;
            foreach(Corner pointCorner in Point.Corners)
            {
                ++pointCorners;
                hasCornerNormal = cornerNormals.ContainsKey(pointCorner);
                if(
                    (hasCornerNormal == false) ||
                    (cornerNormals[pointCorner] == cornerNormal)
                )
                {
                    if(oldCornerAttribute.ContainsKey(pointCorner))
                    {
                        cornerValue += oldCornerAttribute[pointCorner];
                        ++participants;
                    }
                }
            }

            cornerValue = cornerValue / (float)(participants);
            newCornerAttribute[this] = cornerValue;
        }
void RenderStack.Geometry.Corner.Dispose ( )

Definition at line 150 of file Corner.cs.

        {
            Point = null;
            Polygon = null;
        }

Property Documentation

Point RenderStack.Geometry.Corner.Point [get, set]
Polygon RenderStack.Geometry.Corner.Polygon [get, set]

The documentation for this class was generated from the following file: