public void SetColors(uint bubbleValueId, FieldDerivativeType dt, FEWorld world, IColorMap colorMap) { FieldValue fv = world.GetFieldValue(bubbleValueId); System.Diagnostics.Debug.Assert(fv.IsBubble == true); uint quantityId = fv.QuantityId; var mesh = world.Mesh; MeshType meshType; int[] vertexs; mesh.GetConnectivity(MeshId, out meshType, out vertexs); if (Type == ElementType.Tri) { Colors = new float[ElemCount * 3]; for (int iTri = 0; iTri < ElemCount; iTri++) { // Bubble uint feId = world.GetTriangleFEIdFromMesh(quantityId, MeshId, (uint)iTri); System.Diagnostics.Debug.Assert(feId != 0); double value = fv.GetShowValue((int)(feId - 1), 0, dt); var color = colorMap.GetColor(value); for (int iColor = 0; iColor < 3; iColor++) { Colors[iTri * 3 + iColor] = (float)color[iColor]; } } } else if (Type == ElementType.Quad) { // TRIと同じでよいが要素IDを取得するメソッドが現状ない throw new NotImplementedException(); } }
/// <summary> /// /// </summary> public void UpdateRectangle(IColorMap aColorMap) { iFillRectangle = new System.Drawing.RectangleF( (iLowerLeft.X * iScale.X), (iLowerLeft.Y * iScale.Y), (iWidth * iScale.X), iHeight * iScale.Y); if (aColorMap.GetColors().GetLength(0) < iId) { iId = 0; } iBrush = new System.Drawing.Drawing2D.LinearGradientBrush( iFillRectangle, aColorMap.GetColor(iId), Color.Black, System.Drawing.Drawing2D.LinearGradientMode.Vertical); iGrayBrush = new System.Drawing.Drawing2D.LinearGradientBrush( iFillRectangle, Color.Gray, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.Vertical); iBorderRectangle = new System.Drawing.Rectangle( (int)Math.Ceiling(iLowerLeft.X * iScale.X), (int)Math.Ceiling(iLowerLeft.Y * iScale.Y), (int)Math.Ceiling(iWidth * iScale.X), (int)Math.Ceiling(iHeight * iScale.Y)); }
static void CreateColorMapTest() { IColorMap cmap = GetColorMap(out string name); using (var img = new MagicCanvas(Options.Width, Options.Height)) { for (int x = 0; x < Options.Width; x++) { ColorD c = cmap.GetColor(x, Options.Width); img.DrawLine(c, x, 0, x, Options.Height - 1); } img.SavePng("ColorMapTest-" + name + ".png"); } }
static void PaintImageData(IDensityMatrix matrix, IColorMap cm, ICanvas img, ColorComponent comp = ColorComponent.None) { double lm = matrix.Maximum; // find minimum method double ln = double.MaxValue; for (int y = 1; y < Options.Height - 1; y++) { for (int x = 1; x < Options.Width - 1; x++) { double li = matrix[x, y]; if (li > 0.0 && li < ln) { ln = li; } } } Debug.WriteLine("ln = " + ln); //chop at most frequent value //double hmax = 0.0; //int cmax = 0; //var histogram = new Dictionary<double,int>(); //for (int y = 1; y < Options.Height - 1; y++) { // for (int x = 1; x < Options.Width - 1; x++) { // double li = matrix[x, y]; // if (li < double.Epsilon || double.IsInfinity(li) || double.IsNaN(li)) { continue; } // if (!histogram.TryGetValue(li,out int val)) { // val = 1; // } else { // val++; // } // if (val > cmax) { // cmax = val; // hmax = li; // } // histogram[li] = val; // } //} // Debug.WriteLine("hmax = "+hmax+" cmax = "+cmax); //find minimum method using average of blocks //double ln = double.MaxValue; //int aspect = 32; //int aw = (Options.Width - 1) / aspect; //int ah = (Options.Height - 1) / aspect; //for (int ay = 1; ay < ah; ay++) { // for (int ax = 1; ax < aw; ax++) { // int ys = ay * aspect; int ye = ys + aspect - 1; // int xs = ax * aspect; int xe = xs + aspect - 1; // double avg = 0.0; // for(int y = ys; y < ye; y++) { // for(int x = xs; x < xe; x++) { // if (x >= 0 && x < Options.Width && y >=0 && y < Options.Height) { // double li = matrix[x, y]; // avg += li; // } // } // } // avg /= (aspect * aspect); // if (avg > 0.0 && avg < ln) { ln = avg; } // } //} //Debug.WriteLine("ln = "+ln); //find average method //double total = 0.0; //long count = 0; //for (int y = 1; y < Options.Height - 1; y++) { // for (int x = 1; x < Options.Width - 1; x++) { // double li = matrix[x, y]; // if (li >= 0.0 && !double.IsInfinity(li) && !double.IsNaN(li)) { // total += li; // count++; // } // } //} //double ln = total / count; //Debug.WriteLine("ln = "+ln); for (int y = 0; y < Options.Height; y++) { for (int x = 0; x < Options.Width; x++) { double li = matrix[x, y]; ColorD c = cm.GetColor(li - ln, lm - ln); if (comp != ColorComponent.None) { img.SetPixelComponent(x, y, comp, c.GetComponent(comp)); } else { img.SetPixel(x, y, c); } } } }
/// <summary> /// /// </summary> /// <param name="aGraphics"></param> /// <param name="aColorMap"></param> private void DrawChild(Graphics aGraphics, IColorMap aColorMap, List <int> aSelectedIds, IndexVisibilityHandler aVisibility) { float height = iHeight * iScale.Y; if (height <= 1) { return; } UpdateRectangle(aColorMap); // Last level: Draw Label and Fill Rectangle if (iChildRectangles.Count == 0) { int amount = aColorMap.GetColors().GetLength(0); if (amount < iId) { iId = 0; } // *** If selected *** if (aSelectedIds != null && aSelectedIds.Contains(iId) && (aVisibility != null && aVisibility.GetVisibility(iId))) { System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush( iFillRectangle, aColorMap.GetColor(iId), Color.White, System.Drawing.Drawing2D.LinearGradientMode.Vertical); aGraphics.FillRectangle(brush, iFillRectangle); DrawLabel(aGraphics, iSelectedGroupLabelPen); Pen selectedPen = new Pen(Color.Cyan, 3); Pen selectedPen2 = new Pen(Color.Blue, 3); aGraphics.DrawRectangle(selectedPen, iBorderRectangle.X + 3, iBorderRectangle.Y + 3, iBorderRectangle.Width - 7, iBorderRectangle.Height - 7); aGraphics.DrawRectangle(selectedPen2, iBorderRectangle.X + 6, iBorderRectangle.Y + 6, iBorderRectangle.Width - 12, iBorderRectangle.Height - 12); } else { if (aVisibility != null && aVisibility.GetVisibility(iId)) { aGraphics.FillRectangle(iBrush, iFillRectangle); } else { aGraphics.FillRectangle(iGrayBrush, iFillRectangle); } DrawLabel(aGraphics); } } else { // Call children recursively foreach (TreeRectangle rectangle in iChildRectangles) { rectangle.DrawChild(aGraphics, aColorMap, aSelectedIds, aVisibility); } // Draw the The Group Rectangle (as a border) aGraphics.DrawRectangle(iPen, iBorderRectangle); // Draw the Group Label DrawGroupLabel(iFillRectangle, aGraphics, iBorderPen); } }