RenderStack 11.06.1
Public Member Functions | Public Attributes | Static Protected Member Functions
RenderStack.Geometry.GeometryOperation Class Reference

Base class for Geometry manipulation operations. More...

Inheritance diagram for RenderStack.Geometry.GeometryOperation:
RenderStack.Geometry.CatmullClarkGeometryOperation RenderStack.Geometry.CloneGeometryOperation RenderStack.Geometry.Sqrt3GeometryOperation RenderStack.Geometry.SubdivideGeometryOperation RenderStack.Geometry.TriangulateGeometryOperation RenderStack.Geometry.TruncateGeometryOperation

List of all members.

Public Member Functions

Point MakeNewPointFromPoint (float weight, Point oldPoint)
Point MakeNewPointFromPoint (Point oldPoint)
 Creates a new Point to Destination from old Point. The new Point is linked to the old point in Source. Old point is set as source for the new Point with weight 1.0.
Point MakeNewPointFromPolygonCentroid (Polygon oldPolygon)
 Creates a new point to Destination from centroid of old Polygon. The new Point is linked to the old Polygon in Source. Each corner of the old Polygon is added as source for the new Point with weight 1.0.
void AddPolygonCentroid (Point newPoint, float weight, Polygon oldPolygon)
void AddPointRing (Point newPoint, float weight, Point oldPoint)
Polygon MakeNewPolygonFromPolygon (Polygon oldPolygon)
Corner MakeNewCornerFromPolygonCentroid (Polygon newPolygon, Polygon oldPolygon)
Corner MakeNewCornerFromCorner (Polygon newPolygon, Corner oldCorner)
void AddPolygonCorners (Polygon newPolygon, Polygon oldPolygon)
void AddPointSource (Point newPoint, float weight, Point oldPoint)
void AddPointSource (Point newPoint, float weight, Corner oldCorner)
void AddCornerSource (Corner newCorner, float weight, Corner oldCorner)
void DistributeCornerSources (Corner newCorner, float weight, Point newPoint)
void AddPolygonSource (Polygon newPolygon, float weight, Polygon oldPolygon)
void AddEdgeSource (Edge newEdge, float weight, Edge oldEdge)
void BuildDestinationEdgesWithSourcing ()
void InterpolateAllAttributeMaps ()

Public Attributes

Geometry Source
Geometry Destination = new Geometry()
Dictionary< Point, PointpointOldToNew = new Dictionary<Point,Point>()
Dictionary< Polygon, PolygonpolygonOldToNew = new Dictionary<Polygon,Polygon>()
Dictionary< Corner, CornercornerOldToNew = new Dictionary<Corner,Corner>()
Dictionary< Edge, EdgeedgeOldToNew = new Dictionary<Edge,Edge>()
Dictionary< Polygon, PointoldPolygonCentroidToNewPoints = new Dictionary<Polygon,Point>()
Dictionary< Point, List
< KeyValuePair< float, Point > > > 
newPointSources = new Dictionary<Point,List<KeyValuePair<float,Point>>>()
Dictionary< Point, List
< KeyValuePair< float, Corner > > > 
newPointCornerSources = new Dictionary<Point,List<KeyValuePair<float,Corner>>>()
Dictionary< Corner, List
< KeyValuePair< float, Corner > > > 
newCornerSources = new Dictionary<Corner,List<KeyValuePair<float,Corner>>>()
Dictionary< Polygon, List
< KeyValuePair< float, Polygon > > > 
newPolygonSources = new Dictionary<Polygon,List<KeyValuePair<float,Polygon>>>()
Dictionary< Edge, List
< KeyValuePair< float, Edge > > > 
newEdgeSources = new Dictionary<Edge,List<KeyValuePair<float,Edge>>>()

Static Protected Member Functions

static void InterpolateAttributeMaps< KeyType > (AttributeMapCollection< KeyType > original, AttributeMapCollection< KeyType > clone, Dictionary< KeyType, List< KeyValuePair< float, KeyType >>> keyNewToOlds)

Detailed Description

GeometryOperation applies some operation to a source Geometry, building a new geometry. Key support functionality is implemented in this base class. Mmapping information from source to destination is maintained here.

New Geometry parts (Points, Corners and Polygons) can be a weighted sum of source parts.

Bug:
Attribute discontinuities on corner attributes are not properly handled (for example texture seams on sphere).
Note:
Mostly stable, somewhat experimental.

Definition at line 46 of file GeometryOperation.cs.


Member Function Documentation

Point RenderStack.Geometry.GeometryOperation.MakeNewPointFromPoint ( float  weight,
Point  oldPoint 
)

Creates a new Point to Destination from old Point. The new Point is linked to the old point in Source. Old point is set as source for the new Point with specified weight.

Parameters:
weightWeight for old point as source
Parameters:
oldPointOld point used as source for the new point
Returns:
The new Point.

Definition at line 69 of file GeometryOperation.cs.

        {
            Debug.Assert(oldPoint != null);

            Point newPoint = Destination.MakePoint();
            AddPointSource(newPoint, weight, oldPoint);
            pointOldToNew[oldPoint] = newPoint;
            return newPoint;
        }
Point RenderStack.Geometry.GeometryOperation.MakeNewPointFromPoint ( Point  oldPoint)
Parameters:
oldPointOld point used as source for the new point
Returns:
The new Point.

Definition at line 85 of file GeometryOperation.cs.

        {
            Debug.Assert(oldPoint != null);

            Point newPoint = Destination.MakePoint();
            AddPointSource(newPoint, 1.0f, oldPoint);
            pointOldToNew[oldPoint] = newPoint;
            return newPoint;
        }
Point RenderStack.Geometry.GeometryOperation.MakeNewPointFromPolygonCentroid ( Polygon  oldPolygon)
Parameters:
oldPolygon
Returns:

Definition at line 101 of file GeometryOperation.cs.

        {
            Debug.Assert(oldPolygon != null);

            Point newPoint = Destination.MakePoint();
            oldPolygonCentroidToNewPoints[oldPolygon] = newPoint;
            AddPolygonCentroid(newPoint, 1.0f, oldPolygon);
            return newPoint;
        }
void RenderStack.Geometry.GeometryOperation.AddPolygonCentroid ( Point  newPoint,
float  weight,
Polygon  oldPolygon 
)

Definition at line 110 of file GeometryOperation.cs.

References RenderStack.Geometry.Corner.Point.

        {
            foreach(Corner oldCorner in oldPolygon.Corners)
            {
                AddPointSource(newPoint, weight, oldCorner);
                AddPointSource(newPoint, weight, oldCorner.Point);
            }
        }
void RenderStack.Geometry.GeometryOperation.AddPointRing ( Point  newPoint,
float  weight,
Point  oldPoint 
)

Definition at line 118 of file GeometryOperation.cs.

References RenderStack.Geometry.Polygon.NextCorner(), RenderStack.Geometry.Corner.Point, and RenderStack.Geometry.Corner.Polygon.

        {
            Debug.Assert(newPoint != null);
            Debug.Assert(oldPoint != null);

            foreach(Corner ringCorner in oldPoint.Corners)
            {
                Polygon ringPolygon     = ringCorner.Polygon;
                Corner  nextRingCorner  = ringPolygon.NextCorner(ringCorner);
                Point   nextRingPoint   = nextRingCorner.Point;
                AddPointSource(newPoint, weight, nextRingPoint);
            }
        }
Polygon RenderStack.Geometry.GeometryOperation.MakeNewPolygonFromPolygon ( Polygon  oldPolygon)

Definition at line 131 of file GeometryOperation.cs.

        {
            Debug.Assert(oldPolygon != null);

            Polygon newPolygon = Destination.MakePolygon();

            AddPolygonSource(newPolygon, 1.0f, oldPolygon);
            polygonOldToNew[oldPolygon] = newPolygon;

            return newPolygon;
        }
Corner RenderStack.Geometry.GeometryOperation.MakeNewCornerFromPolygonCentroid ( Polygon  newPolygon,
Polygon  oldPolygon 
)

Definition at line 142 of file GeometryOperation.cs.

References RenderStack.Geometry.Polygon.MakeCorner().

        {
            Debug.Assert(newPolygon != null);
            Debug.Assert(oldPolygon != null);

            Point   newPoint    = oldPolygonCentroidToNewPoints[oldPolygon];
            Corner  newCorner   = newPolygon.MakeCorner(newPoint);
            DistributeCornerSources(newCorner, 1.0f, newPoint);
            return newCorner;
        }
Corner RenderStack.Geometry.GeometryOperation.MakeNewCornerFromCorner ( Polygon  newPolygon,
Corner  oldCorner 
)

Definition at line 152 of file GeometryOperation.cs.

References RenderStack.Geometry.Polygon.MakeCorner(), and RenderStack.Geometry.Corner.Point.

        {
            Debug.Assert(newPolygon != null);
            Debug.Assert(oldCorner  != null);

            Point   oldPoint    = oldCorner.Point;
            Point   newPoint    = pointOldToNew[oldPoint];
            Corner  newCorner   = newPolygon.MakeCorner(newPoint);
            AddCornerSource(newCorner, 1.0f, oldCorner);
            return newCorner;
        }
void RenderStack.Geometry.GeometryOperation.AddPolygonCorners ( Polygon  newPolygon,
Polygon  oldPolygon 
)

Definition at line 163 of file GeometryOperation.cs.

References RenderStack.Geometry.Corner.Point.

        {
            Debug.Assert(newPolygon != null);
            Debug.Assert(oldPolygon != null);

            foreach(Corner oldCorner in oldPolygon.Corners)
            {
                Point   oldPoint    = oldCorner.Point;
                Point   newPoint    = pointOldToNew[oldPoint];
                Corner  newCorner   = newPolygon.MakeCorner(newPoint);
                AddCornerSource(newCorner, 1.0f, oldCorner);
            }
        }
void RenderStack.Geometry.GeometryOperation.AddPointSource ( Point  newPoint,
float  weight,
Point  oldPoint 
)

Definition at line 176 of file GeometryOperation.cs.

        {
            Debug.Assert(oldPoint != null);
            Debug.Assert(oldPoint != null);

            if(newPointSources.ContainsKey(newPoint) == false)
            {
                newPointSources[newPoint] = new List<KeyValuePair<float,Point>>();
            }
            newPointSources[newPoint].Add(new KeyValuePair<float,Point>(weight, oldPoint));
        }
void RenderStack.Geometry.GeometryOperation.AddPointSource ( Point  newPoint,
float  weight,
Corner  oldCorner 
)

Definition at line 187 of file GeometryOperation.cs.

        {
            Debug.Assert(newPoint != null);
            Debug.Assert(oldCorner != null);

            if(newPointCornerSources.ContainsKey(newPoint) == false)
            {
                newPointCornerSources[newPoint] = new List<KeyValuePair<float,Corner>>();
            }
            newPointCornerSources[newPoint].Add(new KeyValuePair<float,Corner>(weight, oldCorner));
        }
void RenderStack.Geometry.GeometryOperation.AddCornerSource ( Corner  newCorner,
float  weight,
Corner  oldCorner 
)

Definition at line 198 of file GeometryOperation.cs.

        {
            Debug.Assert(newCorner != null);
            Debug.Assert(oldCorner != null);

            if(newCornerSources.ContainsKey(newCorner) == false)
            {
                newCornerSources[newCorner] = new List<KeyValuePair<float,Corner>>();
            }
            newCornerSources[newCorner].Add(new KeyValuePair<float,Corner>(weight, oldCorner));
        }
void RenderStack.Geometry.GeometryOperation.DistributeCornerSources ( Corner  newCorner,
float  weight,
Point  newPoint 
)

Definition at line 209 of file GeometryOperation.cs.

        {
            Debug.Assert(newCorner != null);
            Debug.Assert(newPoint  != null);

            foreach(var kvp in newPointCornerSources[newPoint])
            {
                AddCornerSource(newCorner, weight * kvp.Key, kvp.Value);
            }
        }
void RenderStack.Geometry.GeometryOperation.AddPolygonSource ( Polygon  newPolygon,
float  weight,
Polygon  oldPolygon 
)

Definition at line 219 of file GeometryOperation.cs.

        {
            Debug.Assert(newPolygon != null);
            Debug.Assert(oldPolygon != null);

            if(newPolygonSources.ContainsKey(newPolygon) == false)
            {
                newPolygonSources[newPolygon] = new List<KeyValuePair<float,Polygon>>();
            }
            newPolygonSources[newPolygon].Add(new KeyValuePair<float,Polygon>(weight, oldPolygon));
        }
void RenderStack.Geometry.GeometryOperation.AddEdgeSource ( Edge  newEdge,
float  weight,
Edge  oldEdge 
)

Definition at line 230 of file GeometryOperation.cs.

References RenderStack.Geometry.Edge.A, and RenderStack.Geometry.Edge.B.

        {
            Debug.Assert(newEdge.A != null);
            Debug.Assert(newEdge.B != null);
            Debug.Assert(oldEdge.A != null);
            Debug.Assert(oldEdge.B != null);

            if(newEdgeSources.ContainsKey(newEdge) == false)
            {
                newEdgeSources[newEdge] = new List<KeyValuePair<float,Edge>>();
            }
            newEdgeSources[newEdge].Add(new KeyValuePair<float,Edge>(weight, oldEdge));
        }
static void RenderStack.Geometry.GeometryOperation.InterpolateAttributeMaps< KeyType > ( AttributeMapCollection< KeyType >  original,
AttributeMapCollection< KeyType >  clone,
Dictionary< KeyType, List< KeyValuePair< float, KeyType >>>  keyNewToOlds 
) [static, protected]

Definition at line 244 of file GeometryOperation.cs.

        {
            /*  For all original attribute maps  */ 
            foreach(KeyValuePair<string, object> kvp in original.AttributeMaps)
            {
                string  mapName         = kvp.Key;
                object  oldMap          = kvp.Value;    // real type is Dictionary<KeyType, ValueType>
                object  newMap;
                Type    mapValueType    = oldMap.GetType().GetGenericArguments()[1];

                if(mapName == "corner_indices")
                {
                    continue;
                }
                //Type    mapKeyType      = oldMap.GetType().GetGenericArguments()[0];
                //Debug.WriteLine("Attribute map name       : " + mapName);
                //Debug.WriteLine("Attribute map key type   : " + mapKeyType.ToString());
                //Debug.WriteLine("Attribute map value type : " + mapValueType.ToString());
                if(clone.AttributeMaps.ContainsKey(mapName) == true)
                {
                    Debug.WriteLine("!");
                }
                newMap = System.Activator.CreateInstance(oldMap.GetType());
                clone.AttributeMaps[mapName] = newMap;

                IDictionary oldMapDictionary = (IDictionary)oldMap;
                IDictionary newMapDictionary = (IDictionary)newMap;

                //Debug.WriteLine("Attribute map count      : " + oldMapDictionary.Count);

                /*  For each new object in keyNewToOlds.Keys  */ 
                foreach(var kvp2 in keyNewToOlds)
                {
                    KeyType newKey = kvp2.Key;
                    List<KeyValuePair<float,KeyType>> oldKeys = kvp2.Value;

                    //  Compute sum of weights, for normalizing
                    float sumWeights = 0.0f;
                    foreach(var kvp3 in oldKeys)
                    {
                        KeyType oldKey = kvp3.Value;
                        if(oldMapDictionary.Contains(oldKey))
                        {
                            sumWeights += kvp3.Key;
                        }
                    }
                    if(sumWeights == 0.0f)
                    {
                        continue;
                    }

                    object newValue = System.Activator.CreateInstance(mapValueType);
                    if(newValue is ILinear)
                    {
                        ILinear newLinearValue  = (ILinear)newValue;
                        foreach(var kvp3 in oldKeys)
                        {
                            float   weight  = kvp3.Key;
                            KeyType oldKey  = kvp3.Value;
                            object  oldValue;
                            if(oldMapDictionary.Contains(oldKey))
                            {
                                oldValue        = oldMapDictionary[oldKey];
                                //  TODO MUSTIFIX oldValue = null 
                                ILinear oldLinearValue  = (ILinear)oldValue;
                                newLinearValue.PlusWeightTimesOther(weight / sumWeights, oldLinearValue);
                            }
                            else
                            {
                                oldValue = null;
                            }
                        }
                        newMapDictionary[newKey] = newLinearValue;
                    }
                    else if(newValue is float)
                    {
                        float newFloatValue  = (float)newValue;
                        foreach(var kvp3 in oldKeys)
                        {
                            float   weight          = kvp3.Key;
                            KeyType oldKey          = kvp3.Value;
                            object  oldValue        = oldMapDictionary[oldKey];
                            float   oldFloatValue   = (float)oldValue;
                            newFloatValue += (weight / sumWeights) * oldFloatValue;
                        }
                        newMapDictionary[newKey] = newFloatValue;
                    }
                    else
                    {
                        Debug.WriteLine("!");
                    }
                }
            }
        }
void RenderStack.Geometry.GeometryOperation.BuildDestinationEdgesWithSourcing ( )

Definition at line 343 of file GeometryOperation.cs.

References RenderStack.Geometry.Edge.A, and RenderStack.Geometry.Edge.B.

        {
            Destination.BuildEdges();
            foreach(Edge oldEdge in Source.Edges.Keys)
            {
                Edge newEdge = new Edge(pointOldToNew[oldEdge.A], pointOldToNew[oldEdge.B]);
                AddEdgeSource(newEdge, 1.0f, oldEdge);
                edgeOldToNew[oldEdge] = new Edge(
                    pointOldToNew[oldEdge.A],
                    pointOldToNew[oldEdge.B]
                );
            }

        }
void RenderStack.Geometry.GeometryOperation.InterpolateAllAttributeMaps ( )

Definition at line 357 of file GeometryOperation.cs.

        {
            InterpolateAttributeMaps<Point>   (Source.PointAttributes,   Destination.PointAttributes,    newPointSources);
            InterpolateAttributeMaps<Polygon> (Source.PolygonAttributes, Destination.PolygonAttributes,  newPolygonSources);
            InterpolateAttributeMaps<Corner>  (Source.CornerAttributes,  Destination.CornerAttributes,   newCornerSources);
            InterpolateAttributeMaps<Edge>    (Source.EdgeAttributes,    Destination.EdgeAttributes,     newEdgeSources);
        }

Member Data Documentation

Definition at line 48 of file GeometryOperation.cs.

Definition at line 50 of file GeometryOperation.cs.

Definition at line 51 of file GeometryOperation.cs.

Definition at line 52 of file GeometryOperation.cs.

Definition at line 53 of file GeometryOperation.cs.

Definition at line 54 of file GeometryOperation.cs.

Dictionary<Point, List<KeyValuePair<float, Point> > > RenderStack.Geometry.GeometryOperation.newPointSources = new Dictionary<Point,List<KeyValuePair<float,Point>>>()

Definition at line 56 of file GeometryOperation.cs.

Dictionary<Point, List<KeyValuePair<float, Corner> > > RenderStack.Geometry.GeometryOperation.newPointCornerSources = new Dictionary<Point,List<KeyValuePair<float,Corner>>>()

Definition at line 57 of file GeometryOperation.cs.

Dictionary<Corner, List<KeyValuePair<float, Corner> > > RenderStack.Geometry.GeometryOperation.newCornerSources = new Dictionary<Corner,List<KeyValuePair<float,Corner>>>()

Definition at line 58 of file GeometryOperation.cs.

Dictionary<Polygon, List<KeyValuePair<float, Polygon> > > RenderStack.Geometry.GeometryOperation.newPolygonSources = new Dictionary<Polygon,List<KeyValuePair<float,Polygon>>>()

Definition at line 59 of file GeometryOperation.cs.

Dictionary<Edge, List<KeyValuePair<float, Edge> > > RenderStack.Geometry.GeometryOperation.newEdgeSources = new Dictionary<Edge,List<KeyValuePair<float,Edge>>>()

Definition at line 60 of file GeometryOperation.cs.


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