public List<string> CreateSketch(Section section, Section symmetricSection, CampaignReport campaignReport)
        {
            try
            {
                if (section == null)
                {
                    throw new ArgumentNullException("section");
                }

                if (symmetricSection == null)
                {
                    throw new ArgumentNullException("symmetricSection");
                }

                if (campaignReport == null)
                {
                    throw new ArgumentNullException("campaignReport");
                }

                if (!section.SectionType.Name.Equals("Shell") && !section.SectionType.Name.Equals("Longitudinal") &&
                    !section.SectionType.Name.Equals("LongitudinalBulkheads") && !symmetricSection.SectionType.Name.Equals("Shell") &&
                    !symmetricSection.SectionType.Name.Equals("Longitudinal") && !symmetricSection.SectionType.Name.Equals("LongitudinalBulkheads")
                    )
                {
                    return null;
                }

                SortedList<string, IList> sectionElementsInCampaign = section.GetPermanentElementsInCampaignReport(campaignReport);
                SortedList<string, IList> symmetricElementsInCampaign = symmetricSection.GetPermanentElementsInCampaignReport(campaignReport);

                List<SteelThicknessGaugingPoint> sectionSteelThicknessGaugingPoints = (sectionElementsInCampaign.ContainsKey("SteelThicknessGaugingPoint")) ? sectionElementsInCampaign["SteelThicknessGaugingPoint"].Cast<SteelThicknessGaugingPoint>().ToList() : null;
                List<SteelThicknessGaugingPoint> symmetricSteelThicknessGaugingPoints = (symmetricElementsInCampaign.ContainsKey("SteelThicknessGaugingPoint")) ? symmetricElementsInCampaign["SteelThicknessGaugingPoint"].Cast<SteelThicknessGaugingPoint>().ToList() : null;

                List<SteelThicknessGaugingPoint> steelThicknessGaugingPoints = new List<SteelThicknessGaugingPoint>();
                if (sectionSteelThicknessGaugingPoints != null && sectionSteelThicknessGaugingPoints.Count > 0)
                {
                    steelThicknessGaugingPoints.AddRange(sectionSteelThicknessGaugingPoints);
                }
                if (symmetricSteelThicknessGaugingPoints != null && symmetricSteelThicknessGaugingPoints.Count > 0)
                {
                    steelThicknessGaugingPoints.AddRange(symmetricSteelThicknessGaugingPoints);
                }

                SortedList<int, List<SteelThicknessGaugingPoint>> pointsPerSketch;
                return this.CreateSketch(section, symmetricSection, campaignReport, steelThicknessGaugingPoints, out pointsPerSketch);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Sketch for section/campaign report cannot be created!", ex);
            }
        }
        public List<string> CreateSketch(Section section, CampaignReport campaignReport, List<SteelThicknessGaugingPoint> steelThicknessGaugingPoints, out SortedList<int, List<SteelThicknessGaugingPoint>> pointsPerSketch)
        {
            try
            {
                if (section == null)
                {
                    throw new ArgumentNullException("section");
                }

                if (campaignReport == null)
                {
                    throw new ArgumentNullException("campaignReport");
                }

                int index = 0;
                pointsPerSketch = new SortedList<int, List<SteelThicknessGaugingPoint>>();

                SortedList<string, IList> elementsInCampaign = section.GetPermanentElementsInCampaignReport(campaignReport);
                if (!elementsInCampaign.ContainsKey("SteelThicknessGaugingPoint") || elementsInCampaign["SteelThicknessGaugingPoint"].Count == 0)
                {
                    return null;
                }

                Document document = campaignReport.Vessel.Document as Document;
                Vessel vessel = document.Vessel;

                List<string> bitmaps = new List<string>();

                string sectionDrawerCurrentViewModeName = section.SectionDrawer.CurrentViewModeName;
                section.SectionDrawer.CurrentViewModeName = "SketchFormat";

                if (!this.sectionThumbnails.ContainsKey(vessel.GUID))
                {
                    this.sectionThumbnails.Add(vessel.GUID, new Dictionary<int, Bitmap>());
                }
                if (!this.sectionThumbnails[vessel.GUID].ContainsKey(section.ID))
                {
                    this.sectionThumbnails[vessel.GUID].Add(section.ID, null);
                }
                if (this.sectionThumbnails[vessel.GUID][section.ID] == null)
                {
                    CaptionsModel.Instance.SetCaptionPropertySelection("Plate", "IACSSketchDescription", false);

                    section.SectionDrawer.CurrentViewModeName = "Wireframe";

                    section.SectionDrawer.ConfigureView(this.glPanel, section.GetDefaultView(), true);
                    section.SectionDrawer.UpdateLastCamera(this.glPanel);

                    section.SectionDrawer.DrawAxis = false;
                    bool isWireframeVisible = ViewModesData.Instance.IsVisible(section.SectionDrawer.CurrentViewModeName, "Wireframe");
                    if (!isWireframeVisible)
                    {
                        ViewModesData.Instance.SetVisibility(section.SectionDrawer.CurrentViewModeName, "Wireframe", true, true);
                    }

                    Bitmap bitmap = section.SectionDrawer.DrawModelImmediateMode(this.glPanel);

                    if (!isWireframeVisible)
                    {
                        ViewModesData.Instance.SetVisibility(section.SectionDrawer.CurrentViewModeName, "Wireframe", false, true);
                    }
                    section.SectionDrawer.DrawAxis = true;

                    this.sectionThumbnails[vessel.GUID][section.ID] = bitmap;

                    section.SectionDrawer.CurrentViewModeName = "SketchFormat";

                    CaptionsModel.Instance.SetCaptionPropertySelection("Plate", "IACSSketchDescription", true);
                }

                Bitmap originalThumbnail = this.sectionThumbnails[vessel.GUID][section.ID];

                if (section.SectionType.Name.Equals("WebFrames") ||
                    section.SectionType.Name.Equals("TransverseBulkheads") ||
                    section.SectionType.Name.Equals("TransverseCentralBulkheads") ||
                    section.SectionType.Name.Equals("SwashBulkheads")
                   )
                {
                    #region Non Longitudinal

                    pointsPerSketch.Add(index, steelThicknessGaugingPoints);
                    index++;

                    BoundingBox boundingBox = section.GetBoundingBoxOfElementType("Plate");

                    Vector3D planeNormal = section.Normal * section.Up;
                    Point3D planePoint = boundingBox.Center;
                    Plane plane = new Plane(planeNormal, planePoint);

                    List<SteelThicknessGaugingPoint> backGaugingPoints = null;
                    List<SteelThicknessGaugingPoint> frontGaugingPoints = null;

                    this.averageGaugingsCreator.SeparateGaugingPoints(steelThicknessGaugingPoints, plane, out backGaugingPoints, out frontGaugingPoints);

                    SortedList<int, List<SteelThicknessGaugingPoint>> backOrganizedGaugingPoints = this.OrganizeIACSGaugingPointsByID(backGaugingPoints);
                    SortedList<int, List<SteelThicknessGaugingPoint>> frontOrganizedGaugingPoints = this.OrganizeIACSGaugingPointsByID(frontGaugingPoints);

                    #region Clone gauging points that only exists in source side, and copy to target side

                    List<SteelThicknessGaugingPoint> pointsToBeDeleted = new List<SteelThicknessGaugingPoint>();

                    List<SteelThicknessGaugingPoint> sourceGaugingPoints = (backGaugingPoints.Count < frontGaugingPoints.Count) ? backGaugingPoints : frontGaugingPoints;
                    List<SteelThicknessGaugingPoint> targetGaugingPoints = (backGaugingPoints.Count < frontGaugingPoints.Count) ? frontGaugingPoints : backGaugingPoints;

                    List<int> sourceGaugingPointsIACSID = (backGaugingPoints.Count < frontGaugingPoints.Count) ? new List<int>(backOrganizedGaugingPoints.Keys) : new List<int>(frontOrganizedGaugingPoints.Keys);
                    List<int> targetGaugingPointsIACSID = (backGaugingPoints.Count < frontGaugingPoints.Count) ? new List<int>(frontOrganizedGaugingPoints.Keys) : new List<int>(backOrganizedGaugingPoints.Keys);

                    foreach (SteelThicknessGaugingPoint sourceGaugingPoint in sourceGaugingPoints)
                    {
                        if (targetGaugingPointsIACSID.Contains((int)sourceGaugingPoint.IACSReportLocationData.ID))
                        {
                            continue;
                        }

                        Point3D pointPosition = new Point3D(sourceGaugingPoint.PointGeometry.Position);
                        pointPosition = (Point3D)pointPosition.Mirror(plane);
                        Vector3D pointNormal = new Vector3D(sourceGaugingPoint.PointGeometry.Normal);

                        int geometryID, geometryPartID;
                        List<string> elementTypeNames = new List<string>();
                        elementTypeNames.Add(sourceGaugingPoint.TargetElement.GetBaseType().Name);
                        Point3D closestPoint;
                        SectionElement sectionElement = section.PointOverDomainEntity(pointPosition, elementTypeNames, 0.01, out closestPoint, out geometryID, out geometryPartID) as SectionElement;
                        if (sectionElement == null)
                        {
                            continue;
                        }

                        AverageSteelThicknessGaugingPoint averageSteelThicknessGaugingPoint = new AverageSteelThicknessGaugingPoint();

                        averageSteelThicknessGaugingPoint.PointGeometry.Position = pointPosition;
                        averageSteelThicknessGaugingPoint.PointGeometry.Normal = pointNormal;

                        averageSteelThicknessGaugingPoint.Section = section;
                        averageSteelThicknessGaugingPoint.Campaign = campaignReport.Campaign;
                        averageSteelThicknessGaugingPoint.CampaignReport = campaignReport;
                        averageSteelThicknessGaugingPoint.TargetElement = sectionElement as IWorkableElement;
                        averageSteelThicknessGaugingPoint.TargetElementGeometryID = geometryID;
                        averageSteelThicknessGaugingPoint.TargetElementGeometrySegmentID = geometryPartID;
                        averageSteelThicknessGaugingPoint.TargetElementPart = sourceGaugingPoint.TargetElementPart;
                        averageSteelThicknessGaugingPoint.Active = true;
                        averageSteelThicknessGaugingPoint.GaugingValue = sourceGaugingPoint.GaugingValue;

                        averageSteelThicknessGaugingPoint.IACSReportLocationData.ID = sourceGaugingPoint.IACSReportLocationData.ID;
                        averageSteelThicknessGaugingPoint.IACSReportLocationData.SetColumnNull();
                        averageSteelThicknessGaugingPoint.IACSReportLocationData.Strake = sourceGaugingPoint.IACSReportLocationData.Strake;
                        averageSteelThicknessGaugingPoint.IACSReportLocationData.IsPortSide = !(bool)sourceGaugingPoint.IACSReportLocationData.IsPortSide;

                        averageSteelThicknessGaugingPoint.Name = averageSteelThicknessGaugingPoint.IACSReportLocationData.ID.ToString();

                        //#if (DEBUG)
                        //                        newFrontGaugingPoint.Name += ((bool)newFrontGaugingPoint.IACSReportLocationData.IsPortSide) ? " P " : " S ";
                        //#endif

                        section.AddPermanentDomainEntityToGroup(averageSteelThicknessGaugingPoint, true, false);
                        //section.Vessel.Document.DocumentStateController.BroadcastEntityCreation(this, averageSteelThicknessGaugingPoint);

                        targetGaugingPoints.Add(averageSteelThicknessGaugingPoint);
                        pointsToBeDeleted.Add(averageSteelThicknessGaugingPoint);
                    }

                    #endregion

                    List<SectionElement> sectionElements = this.GetSectionElementsVisibleInSketch(section, targetGaugingPoints);

                    // Generate thumbnail
                    Bitmap thumbnail = originalThumbnail.Clone() as Bitmap;

                    Rectangle rectangle = this.GetRectangleOfRenderizedArea(sectionElements);
                    for (int i = 0; i < thumbnail.Width; i++)
                    {
                        for (int j = 0; j < thumbnail.Height; j++)
                        {
                            if (this.IsPixelOfRectangle(i, j, rectangle, 3))
                            {
                                thumbnail.SetPixel(i, j, Color.Red);
                            }
                        }
                    }

                    //int newWidht = (int)(thumbnail.Width / 5);
                    //int newHeight = (int)(thumbnail.Height / 5);
                    //Image image = thumbnail.GetThumbnailImage(newWidht, newHeight, null, IntPtr.Zero);
                    //thumbnail = new Bitmap(image);

                    string thumbName = thumbnail.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                    this.bitmapCount++;

                    thumbName = document.HDF5DataAccessController.SaveBitmap(thumbnail, thumbName);
                    bitmaps.Add(thumbName);

                    //section.SectionDrawer.CurrentViewModeName = "SketchFormat";

                    C4DView view = section.SectionDrawer.ComputeViewForSectionElements(this.glPanel, sectionElements, false, 1.2f, true);
                    if (view == null)
                    {
                        view = section.GetDefaultView();
                    }

                    section.SectionDrawer.ConfigureView(this.glPanel, view, false);
                    section.SectionDrawer.UpdateLastCamera(this.glPanel);

                    // Get IDs of gauging points to set in SectionDrawer
                    List<int> pointIDs = new List<int>();
                    foreach (SteelThicknessGaugingPoint steelThicknessGaugingPoint in targetGaugingPoints)
                    {
                        pointIDs.Add(steelThicknessGaugingPoint.ID);
                    }

                    section.SectionDrawer.SetPriorityVisibleElements("SteelThicknessGaugingPoint", pointIDs);

                    Bitmap bitmap = section.SectionDrawer.DrawModelImmediateModeCuttingOfCompartment(this.glPanel);

                    section.SectionDrawer.ClearPriorityVisibleElements("SteelThicknessGaugingPoint");

                    string bitmapName = bitmap.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                    this.bitmapCount++;

                    bitmapName = document.HDF5DataAccessController.SaveBitmap(bitmap, bitmapName);
                    bitmaps.Add(bitmapName);

                    bitmap.Dispose();

                    foreach (SteelThicknessGaugingPoint pointToBeDeleted in pointsToBeDeleted)
                    {
                        document.DeleteSectionElement(pointToBeDeleted, false);
                    }

                    #endregion
                }
                else if (section.SectionType.Name.Equals("MainDeck") ||
                  section.SectionType.Name.Equals("OtherDecks") ||
                  section.SectionType.Name.Equals("InnerBottom") ||
                  section.SectionType.Name.Equals("Bottom")
                 )
                {
                    #region Decks and Inner Bottom

                    #region Old Code

                    //// Get plates in campaigns of construction or in campaigns of conversion
                    //SortedList<int, Plate> originalPlates = new SortedList<int, Plate>();

                    //List<Campaign> originalCampaigns = vessel.GetOriginalCampaigns();
                    //foreach (Campaign campaign in originalCampaigns)
                    //{
                    //    SortedList<string, IList> platesInCampaign = section.GetElementsInCampaign(campaign, true, "Plate");
                    //    if (platesInCampaign.ContainsKey("Plate"))
                    //    {
                    //        List<Plate> platesInCampaignList = platesInCampaign["Plate"].Cast<Plate>().ToList();
                    //        foreach (Plate plate in platesInCampaignList)
                    //        {
                    //            originalPlates.Add(plate.ID, plate);
                    //        }
                    //    }
                    //}

                    //// Get plates in center column
                    //Plane centerPlaneYZ = new Plane(new Vector3D(1, 0, 0), section.BoundingBox.Center);
                    //SortedList<int, Plate> intersectedPlatesYZ = this.IntersectPlates(originalPlates, centerPlaneYZ);

                    //// Get bounding box of plates in center column
                    //BoundingBox boundingBox = new BoundingBox();
                    //foreach (Plate plate in intersectedPlatesYZ.Values)
                    //{
                    //    boundingBox.Union(plate.Design.Geometry.BoundingBox);
                    //}

                    //Plane centerPlaneXZ = new Plane(new Vector3D(0, 1, 0), boundingBox.Center);

                    //Vector3D xAxis = new Vector3D(1, 0, 0);
                    //SortedList<double, Compartment> sortedCompartments = this.IntersectCompartments(section, centerPlaneXZ);
                    //foreach (Compartment compartment in sortedCompartments.Values)
                    //{
                    //    Plane minPlane = new Plane(xAxis, compartment.BoundingBox.MinPoint);
                    //    Plane maxPlane = new Plane(xAxis, compartment.BoundingBox.MaxPoint);
                    //    List<SteelThicknessGaugingPoint> pointsBetweenPlanes = this.GetPointsBetweenPlanes(steelThicknessGaugingPoints, minPlane, maxPlane);

                    #endregion

                    SortedList<float, SteelThicknessGaugingPoint> sortedSteelThicknessGaugingPoints = new SortedList<float, SteelThicknessGaugingPoint>();

                    foreach (SteelThicknessGaugingPoint steelThicknessGaugingPoint in steelThicknessGaugingPoints)
                    {
                        float x = steelThicknessGaugingPoint.PointGeometry.Position.X;
                        while (sortedSteelThicknessGaugingPoints.ContainsKey(x))
                        {
                            x += (float)Point3D.Epsilon;
                        }

                        sortedSteelThicknessGaugingPoints.Add(x, steelThicknessGaugingPoint);
                    }

                    float minKey = sortedSteelThicknessGaugingPoints.Keys[0];
                    float maxKey = sortedSteelThicknessGaugingPoints.Keys[sortedSteelThicknessGaugingPoints.Count - 1];

                    Point3D minPoint = sortedSteelThicknessGaugingPoints[minKey].PointGeometry.Position;
                    Point3D maxPoint = sortedSteelThicknessGaugingPoints[maxKey].PointGeometry.Position;

                    minPoint.Translate(-2 * Point3D.Epsilon, 0, 0);
                    maxPoint.Translate(2 * Point3D.Epsilon, 0, 0);

                    double defaultSketchSize = 40;
                    double sizeX = maxPoint.X - minPoint.X;

                    int numberOfSketches = (int)Math.Floor(sizeX / defaultSketchSize);

                    if (sizeX < defaultSketchSize)
                    {
                        defaultSketchSize = sizeX;
                        numberOfSketches = 1;
                    }
                    else
                    {
                        double mod = sizeX - (numberOfSketches * defaultSketchSize);
                        if (mod > (defaultSketchSize / 2))
                        {
                            numberOfSketches++;
                            defaultSketchSize -= (mod / numberOfSketches);
                        }
                        else
                        {
                            defaultSketchSize += (mod / numberOfSketches);
                        }
                    }

                    Vector3D planeNormal = new Vector3D(1, 0, 0);
                    for (int i = 0; i < numberOfSketches; i++)
                    {
                        Point3D minPlanePoint = new Point3D(minPoint.X + (i * defaultSketchSize), minPoint.Y, minPoint.Z);
                        Point3D maxPlanePoint = new Point3D(minPoint.X + ((i + 1) * defaultSketchSize), minPoint.Y, minPoint.Z);
                        Plane minPlane = new Plane(planeNormal, minPlanePoint);
                        Plane maxPlane = new Plane(planeNormal, maxPlanePoint);
                        List<SteelThicknessGaugingPoint> pointsBetweenPlanes = this.GetPointsBetweenPlanes(steelThicknessGaugingPoints, minPlane, maxPlane);

                        if (pointsBetweenPlanes == null || pointsBetweenPlanes.Count == 0)
                        {
                            continue;
                        }

                        pointsPerSketch.Add(index, pointsBetweenPlanes);
                        index++;

                        foreach (SteelThicknessGaugingPoint pointBetweenPlane in pointsBetweenPlanes)
                        {
                            if (steelThicknessGaugingPoints.Contains(pointBetweenPlane))
                            {
                                steelThicknessGaugingPoints.Remove(pointBetweenPlane);
                            }
                        }

                        //List<SectionElement> sectionElements = this.GetSectionElementsVisibleInSketch(section, compartment);
                        List<SectionElement> sectionElements = this.GetSectionElementsVisibleInSketch(section, minPlane, maxPlane);

                        // Generate thumbnail
                        section.SectionDrawer.ConfigureView(this.glPanel, section.GetDefaultView(), true);
                        section.SectionDrawer.UpdateLastCamera(this.glPanel);

                        Bitmap thumbnail = originalThumbnail.Clone() as Bitmap;

                        Rectangle rectangle = this.GetRectangleOfRenderizedArea(sectionElements);
                        for (int j = 0; j < thumbnail.Width; j++)
                        {
                            for (int k = 0; k < thumbnail.Height; k++)
                            {
                                if (this.IsPixelOfRectangle(j, k, rectangle, 3))
                                {
                                    thumbnail.SetPixel(j, k, Color.Red);
                                }
                            }
                        }

                        //int newWidht = (int)(thumbnail.Width / 5);
                        //int newHeight = (int)(thumbnail.Height / 5);
                        //Image image = thumbnail.GetThumbnailImage(newWidht, newHeight, null, IntPtr.Zero);
                        //thumbnail = new Bitmap(image);

                        string thumbName = thumbnail.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                        this.bitmapCount++;

                        thumbName = document.HDF5DataAccessController.SaveBitmap(thumbnail, thumbName);
                        bitmaps.Add(thumbName);

                        C4DView view = section.SectionDrawer.ComputeViewForSectionElements(this.glPanel, sectionElements, false, 1.2f, true);
                        if (view == null)
                        {
                            view = section.GetDefaultView();
                        }

                        section.SectionDrawer.ConfigureView(this.glPanel, view, false);
                        section.SectionDrawer.UpdateLastCamera(this.glPanel);

                        List<int> pointIDs = new List<int>();
                        foreach (SteelThicknessGaugingPoint steelThicknessGaugingPoint in pointsBetweenPlanes)
                        {
                            pointIDs.Add(steelThicknessGaugingPoint.ID);
                        }

                        section.SectionDrawer.SetPriorityVisibleElements("SteelThicknessGaugingPoint", pointIDs);

                        Bitmap bitmap = section.SectionDrawer.DrawModelImmediateModeCuttingOfCompartment(this.glPanel);

                        section.SectionDrawer.ClearPriorityVisibleElements("SteelThicknessGaugingPoint");

                        string bitmapName = bitmap.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                        this.bitmapCount++;

                        bitmapName = document.HDF5DataAccessController.SaveBitmap(bitmap, bitmapName);
                        bitmaps.Add(bitmapName);

                        bitmap.Dispose();
                    }

                    #endregion
                }
                else if (section.SectionType.Name.Equals("Shell") ||
                         section.SectionType.Name.Equals("Longitudinal") ||
                         section.SectionType.Name.Equals("LongitudinalBulkheads") ||
                         section.SectionType.Name.Equals("LongitudinalCentralBulkheads")
                 )
                {
                    #region Symmetric Longitudinal

                    #region Old Code

                    //int numberOfSketches = 9;

                    //BoundingBox sectionBoundingBox = section.GetBoundingBoxOfElementType("Plate");

                    //Point3D minPoint = sectionBoundingBox.MinPoint;
                    //Point3D maxPoint = sectionBoundingBox.MaxPoint;

                    //double sizeX = maxPoint.X - minPoint.X;
                    //double deltaX = Math.Ceiling(sizeX / numberOfSketches);

                    //Vector3D planeNormal = new Vector3D(1, 0, 0);
                    //for (int i = 0; i < numberOfSketches; i++)
                    //{
                    //    Point3D minPlanePoint = new Point3D(minPoint.X + (i * deltaX), minPoint.Y, minPoint.Z);
                    //    Point3D maxPlanePoint = new Point3D(minPoint.X + ((i + 1) * deltaX), minPoint.Y, minPoint.Z);
                    //    Plane minPlane = new Plane(planeNormal, minPlanePoint);
                    //    Plane maxPlane = new Plane(planeNormal, maxPlanePoint);

                    #endregion

                    SortedList<float, SteelThicknessGaugingPoint> sortedSteelThicknessGaugingPoints = new SortedList<float, SteelThicknessGaugingPoint>();

                    foreach (SteelThicknessGaugingPoint steelThicknessGaugingPoint in steelThicknessGaugingPoints)
                    {
                        float x = steelThicknessGaugingPoint.PointGeometry.Position.X;
                        while (sortedSteelThicknessGaugingPoints.ContainsKey(x))
                        {
                            x += (float)Point3D.Epsilon;
                        }

                        sortedSteelThicknessGaugingPoints.Add(x, steelThicknessGaugingPoint);
                    }

                    float minKey = sortedSteelThicknessGaugingPoints.Keys[0];
                    float maxKey = sortedSteelThicknessGaugingPoints.Keys[sortedSteelThicknessGaugingPoints.Count - 1];

                    Point3D minPoint = sortedSteelThicknessGaugingPoints[minKey].PointGeometry.Position;
                    Point3D maxPoint = sortedSteelThicknessGaugingPoints[maxKey].PointGeometry.Position;

                    minPoint.Translate(-2 * Point3D.Epsilon, 0, 0);
                    maxPoint.Translate(2 * Point3D.Epsilon, 0, 0);

                    double defaultSketchSize = 40;
                    double sizeX = maxPoint.X - minPoint.X;

                    int numberOfSketches = (int)Math.Floor(sizeX / defaultSketchSize);

                    if (sizeX < defaultSketchSize)
                    {
                        defaultSketchSize = sizeX;
                        numberOfSketches = 1;
                    }
                    else
                    {
                        double mod = sizeX - (numberOfSketches * defaultSketchSize);
                        if (mod > (defaultSketchSize / 2))
                        {
                            numberOfSketches++;
                            defaultSketchSize -= (mod / numberOfSketches);
                        }
                        else
                        {
                            defaultSketchSize += (mod / numberOfSketches);
                        }
                    }

                    Vector3D planeNormal = new Vector3D(1, 0, 0);
                    for (int i = 0; i < numberOfSketches; i++)
                    {
                        Point3D minPlanePoint = new Point3D(minPoint.X + (i * defaultSketchSize), minPoint.Y, minPoint.Z);
                        Point3D maxPlanePoint = new Point3D(minPoint.X + ((i + 1) * defaultSketchSize), minPoint.Y, minPoint.Z);
                        Plane minPlane = new Plane(planeNormal, minPlanePoint);
                        Plane maxPlane = new Plane(planeNormal, maxPlanePoint);

                        List<SteelThicknessGaugingPoint> gaugingPointsBySketch = this.GetPointsBetweenPlanes(steelThicknessGaugingPoints, minPlane, maxPlane);
                        if (gaugingPointsBySketch == null || gaugingPointsBySketch.Count == 0)
                        {
                            continue;
                        }

                        pointsPerSketch.Add(index, gaugingPointsBySketch);
                        index++;

                        Vector3D sketchNormal = new Vector3D();
                        foreach (SteelThicknessGaugingPoint gaugingPointBySketch in gaugingPointsBySketch)
                        {
                            sketchNormal += gaugingPointBySketch.PointGeometry.Normal;

                            if (steelThicknessGaugingPoints.Contains(gaugingPointBySketch))
                            {
                                steelThicknessGaugingPoints.Remove(gaugingPointBySketch);
                            }
                        }
                        sketchNormal /= gaugingPointsBySketch.Count;
                        sketchNormal.Normalize();

                        List<SectionElement> sectionElements = this.GetSectionElementsVisibleInSketch(section, minPlane, maxPlane, gaugingPointsBySketch, sketchNormal);

                        // Generate thumbnail
                        section.SectionDrawer.ConfigureView(this.glPanel, section.GetDefaultView(), true);
                        section.SectionDrawer.UpdateLastCamera(this.glPanel);

                        Bitmap thumbnail = originalThumbnail.Clone() as Bitmap;

                        Rectangle rectangle = this.GetRectangleOfRenderizedArea(sectionElements);
                        for (int j = 0; j < thumbnail.Width; j++)
                        {
                            for (int k = 0; k < thumbnail.Height; k++)
                            {
                                if (this.IsPixelOfRectangle(j, k, rectangle, 3))
                                {
                                    thumbnail.SetPixel(j, k, Color.Red);
                                }
                            }
                        }

                        string thumbName = thumbnail.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                        this.bitmapCount++;

                        thumbName = document.HDF5DataAccessController.SaveBitmap(thumbnail, thumbName);
                        bitmaps.Add(thumbName);

                        C4DView view = section.SectionDrawer.ComputeViewForSectionElements(this.glPanel, sectionElements, false, 1.2f, true);
                        if (view == null)
                        {
                            view = section.GetDefaultView();
                        }

                        section.SectionDrawer.ConfigureView(this.glPanel, view, false);
                        section.SectionDrawer.UpdateLastCamera(this.glPanel);

                        List<int> pointIDs = new List<int>();
                        foreach (SteelThicknessGaugingPoint steelThicknessGaugingPoint in gaugingPointsBySketch)
                        {
                            pointIDs.Add(steelThicknessGaugingPoint.ID);
                        }

                        section.SectionDrawer.SetPriorityVisibleElements("SteelThicknessGaugingPoint", pointIDs);

                        Bitmap bitmap = section.SectionDrawer.DrawModelImmediateModeCuttingOfCompartment(this.glPanel);

                        section.SectionDrawer.ClearPriorityVisibleElements("SteelThicknessGaugingPoint");

                        string bitmapName = bitmap.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                        this.bitmapCount++;

                        bitmapName = document.HDF5DataAccessController.SaveBitmap(bitmap, bitmapName);
                        bitmaps.Add(bitmapName);

                        bitmap.Dispose();
                    }

                    #endregion
                }
                else if (section.SectionType.Name.Equals("AnyOtherSection"))
                {
                    #region Any Other Section

                    pointsPerSketch.Add(index, steelThicknessGaugingPoints);
                    index++;

                    List<SectionElement> sectionElements = this.GetSectionElementsVisibleInSketch(section, steelThicknessGaugingPoints);

                    Bitmap thumbnail = originalThumbnail.Clone() as Bitmap;

                    Rectangle rectangle = this.GetRectangleOfRenderizedArea(sectionElements);
                    for (int i = 0; i < thumbnail.Width; i++)
                    {
                        for (int j = 0; j < thumbnail.Height; j++)
                        {
                            if (this.IsPixelOfRectangle(i, j, rectangle, 3))
                            {
                                thumbnail.SetPixel(i, j, Color.Red);
                            }
                        }
                    }

                    //int newWidht = (int)(thumbnail.Width / 5);
                    //int newHeight = (int)(thumbnail.Height / 5);
                    //Image image = thumbnail.GetThumbnailImage(newWidht, newHeight, null, IntPtr.Zero);
                    //thumbnail = new Bitmap(image);

                    string thumbName = thumbnail.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                    this.bitmapCount++;

                    thumbName = document.HDF5DataAccessController.SaveBitmap(thumbnail, thumbName);
                    bitmaps.Add(thumbName);

                    //section.SectionDrawer.CurrentViewModeName = "SketchFormat";

                    C4DView view = section.SectionDrawer.ComputeViewForSectionElements(this.glPanel, sectionElements, false);
                    if (view == null)
                    {
                        view = section.GetDefaultView();
                    }

                    section.SectionDrawer.ConfigureView(this.glPanel, view, false);
                    section.SectionDrawer.UpdateLastCamera(this.glPanel);

                    // Get IDs of gauging points to set in SectionDrawer
                    List<int> pointIDs = new List<int>();
                    foreach (SteelThicknessGaugingPoint steelThicknessGaugingPoint in steelThicknessGaugingPoints)
                    {
                        pointIDs.Add(steelThicknessGaugingPoint.ID);
                    }

                    section.SectionDrawer.SetPriorityVisibleElements("SteelThicknessGaugingPoint", pointIDs);

                    Bitmap bitmap = section.SectionDrawer.DrawModelImmediateModeCuttingOfCompartment(this.glPanel);

                    section.SectionDrawer.ClearPriorityVisibleElements("SteelThicknessGaugingPoint");

                    string bitmapName = bitmap.RawFormat.Guid.ToString() + "-" + this.bitmapCount.ToString() + ".jpg";
                    this.bitmapCount++;

                    bitmapName = document.HDF5DataAccessController.SaveBitmap(bitmap, bitmapName);
                    bitmaps.Add(bitmapName);

                    bitmap.Dispose();

                    #endregion
                }

                section.SectionDrawer.CurrentViewModeName = sectionDrawerCurrentViewModeName;

                return bitmaps;
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Sketch for section/campaign report cannot be created!", ex);
            }
        }
        public List<string> CreateSketch(Section section, CampaignReport campaignReport)
        {
            try
            {
                if (section == null)
                {
                    throw new ArgumentNullException("section");
                }

                if (campaignReport == null)
                {
                    throw new ArgumentNullException("campaignReport");
                }

                SortedList<string, IList> elementsInCampaign = section.GetPermanentElementsInCampaignReport(campaignReport);
                if (!elementsInCampaign.ContainsKey("SteelThicknessGaugingPoint") || elementsInCampaign["SteelThicknessGaugingPoint"].Count == 0)
                {
                    return null;
                }

                SortedList<int, List<SteelThicknessGaugingPoint>> pointsPerSketch;
                List<SteelThicknessGaugingPoint> steelThicknessGaugingPoints = elementsInCampaign["SteelThicknessGaugingPoint"].Cast<SteelThicknessGaugingPoint>().ToList();

                return this.CreateSketch(section, campaignReport, steelThicknessGaugingPoints, out pointsPerSketch);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Sketch for section/campaign report cannot be created!", ex);
            }
        }