public bool LoadV4(BinaryReader b) { int count = b.ReadInt32(); int origMapWidth = b.ReadInt32(); for (int i = 0; i < count; i++) { MaskItem item = new MaskItem(); item.Name = b.ReadString(); string type = b.ReadString(); if (type == typeof(ArrayBasedMask).ToString()) { item.mMask = MaskFactory.GetNewMask(); JaggedContainer <float> container = item.mMask as JaggedContainer <float>; container.LoadByStripe(b, (JaggedContainer <float> .LoadStripeDelegate)(delegate(BinaryReader r, float[] values) { for (int j = 0; j < values.Length; j++) { values[j] = r.ReadSingle(); } })); } else if (type == typeof(GraphBasedMask).ToString()) { long len = b.ReadInt64(); item.mMask = new GraphBasedMask(b, len); } MaskCheckList.Items.Add(item, false); } return(true); }
public bool LoadV2(BinaryReader b) { int count = b.ReadInt32(); for (int i = 0; i < count; i++) { MaskItem item = new MaskItem(); item.mMask = MaskFactory.GetNewMask(); item.Name = b.ReadString(); JaggedContainer <float> container = item.mMask as JaggedContainer <float>; container.LoadByStripe(b, (JaggedContainer <float> .LoadStripeDelegate)(delegate(BinaryReader r, float[] values) { for (int j = 0; j < values.Length; j++) { values[j] = r.ReadSingle(); } })); //CLM [07.27.07] //these older versions need to be scaled by 0.5 because of a //massive terrain scaling change. int oldSize = TerrainGlobals.getTerrain().getNumXVerts() * 2; resampleJaggedArrayFloat(ref container, oldSize, oldSize, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumXVerts(), 0); MaskCheckList.Items.Add(item, false); } return(true); }
public bool LoadV3(BinaryReader b) { int count = b.ReadInt32(); int origMapWidth = b.ReadInt32(); for (int i = 0; i < count; i++) { MaskItem item = new MaskItem(); item.mMask = MaskFactory.GetNewMask(); item.Name = b.ReadString(); JaggedContainer <float> container = item.mMask as JaggedContainer <float>; container.LoadByStripe(b, (JaggedContainer <float> .LoadStripeDelegate)(delegate(BinaryReader r, float[] values) { for (int j = 0; j < values.Length; j++) { values[j] = r.ReadSingle(); } })); MaskCheckList.Items.Add(item, false); } return(true); }
public bool LoadV1(int count, Stream s) { MaskCheckList.Items.Clear(); BinaryReader b = new BinaryReader(s); //int count = b.ReadInt32(); for (int i = 0; i < count; i++) { MaskItem item = new MaskItem(); item.mMask = MaskFactory.GetNewMask(); item.Name = b.ReadString(); int hashSize = b.ReadInt32(); for (int j = 0; j < hashSize; j++) { long key = b.ReadInt64(); float val = b.ReadSingle(); item.mMask.SetMaskWeight(key, val); } //MaskListView.Items.Add(item); //CLM [07.27.07] //these older versions need to be scaled by 0.5 because of a //massive terrain scaling change. int oldSize = TerrainGlobals.getTerrain().getNumXVerts() * 2; JaggedContainer <float> container = item.mMask as JaggedContainer <float>; resampleJaggedArrayFloat(ref container, oldSize, oldSize, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumXVerts(), 0); MaskCheckList.Items.Add(item, false); } return(true); }
private IMask AddMasks(List <IMask> inputs) { IMask mask = MaskFactory.GetNewMask(); foreach (IMask input in inputs) { if (input is GraphBasedMask) { ((GraphBasedMask)input).loadAndExecute(); } float destVal; long index; float value; input.ResetIterator(); while (input.MoveNext(out index, out value)) { float baseValue = 1.0f; if (Masking.checkBaseWritePermission(index, out baseValue) == false) { continue; } if (value == 0) { continue; } destVal = mask.GetMaskWeight(index); //if (destVal == 0) continue; destVal = value + destVal; if (destVal > 1) { destVal = 1; } destVal = Masking.combineValueWithBaseMask(baseValue, destVal); mask.SetMaskWeight(index, destVal); } } return(mask); }
private void MaskCheckList_ItemCheck(object sender, ItemCheckEventArgs e) { List <IMask> masks = new List <IMask>(); MaskItem mClickedItem = null; mClickedItem = ((MaskItem)MaskCheckList.Items[e.Index]); if (e.NewValue == CheckState.Checked) { masks.Add(mClickedItem.mMask); //betterPropertyGrid1.SelectedObject = mClickedItem; //DeleteLinkLabel.Enabled = true; //SaveLinkLabel.Enabled = true; CurrentMaskNameTextBox.Text = mClickedItem.Name; } else { //betterPropertyGrid1.SelectedObject = null; //DeleteLinkLabel.Enabled = false; //SaveLinkLabel.Enabled = false; } foreach (MaskItem m in MaskCheckList.CheckedItems) { if (mClickedItem != m) { masks.Add(m.mMask); } } if (masks.Count > 0) { Masking.setCurrSelectionMaskWeights(AddMasks(masks)); } else { Masking.setCurrSelectionMaskWeights(MaskFactory.GetNewMask()); } }
private void ImportMaskButton_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Filter = "Image (*.bmp)|*.bmp|Raw32 (*.r32)|*.r32"; if (d.ShowDialog() == DialogResult.OK) { string tName = Path.GetFileNameWithoutExtension(d.FileName); bool okToLoad = true; for (int i = 0; i < MaskCheckList.Items.Count; i++) { MaskItem mi = MaskCheckList.Items[i] as MaskItem; if (Path.GetFileNameWithoutExtension(mi.Name) == tName) { if (MessageBox.Show("There exists a similar mask name already loaded. Would you still like to import this mask?", "Warning!", MessageBoxButtons.YesNo) != DialogResult.Yes) { okToLoad = false; } break; } } if (!okToLoad) { return; } if (Path.GetExtension(d.FileName.ToLower()) == ".bmp") { Image loadedImage = Masking.GetScaledImageFromFile(d.FileName, TerrainGlobals.getTerrain().getNumXVerts(), TerrainGlobals.getTerrain().getNumZVerts()); MaskItem item = new MaskItem(); item.Name = Path.GetFileName(d.FileName); item.mMask = Masking.CreateMask(loadedImage); MaskCheckList.Items.Add(item, false); Masking.setCurrSelectionMaskWeights(item.mMask.Clone()); } else if (Path.GetExtension(d.FileName.ToLower()) == ".r32") { MaskItem item = new MaskItem(); item.Name = Path.GetFileName(d.FileName); item.mMask = MaskFactory.GetNewMask(); BinaryReader r = new BinaryReader(File.OpenRead(d.FileName)); long index = 0; try { while (true) { item.mMask.SetMaskWeight(index, r.ReadSingle()); index++; } } catch (System.IO.EndOfStreamException ex) { ex.ToString(); } if (scaleToFitCheckbox.Checked) { //rescale this mask to fit current terrain int numX = (int)Math.Sqrt(index); float[] img = new float[numX * numX]; long id; float value; item.mMask.ResetIterator(); while (item.mMask.MoveNext(out id, out value)) { if (value == 0) { continue; } img[id] = value; } int newWidth = TerrainGlobals.getTerrain().getNumXVerts(); float[] outImg = ImageManipulation.resizeF32Img(img, numX, numX, newWidth, newWidth, ImageManipulation.eFilterType.cFilter_Linear); item.mMask.Clear(); for (index = 0; index < newWidth * newWidth; index++) { item.mMask.SetMaskWeight(index, outImg[index]); } } MaskCheckList.Items.Add(item, false); Masking.setCurrSelectionMaskWeights(item.mMask.Clone()); r.Close(); } } //ImageSourcePicker picker = new ImageSourcePicker(); //picker.ImageSelected += new EventHandler(picker_ImageSelected); //PopupEditor editor = new PopupEditor(); //editor.ShowPopup(this, picker); }
public static IMask CreateMask(Image source1) { if (myCallback == null) { myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback); } IMask mask = MaskFactory.GetNewMask(); Bitmap source = (Bitmap)(source1.Clone()); Rectangle r = new Rectangle(0, 0, source.Width, source.Height); int formatSize = Image.GetPixelFormatSize(source.PixelFormat); unsafe { BitmapData sourceData = source.LockBits(r, ImageLockMode.ReadWrite, source.PixelFormat); if (sourceData.PixelFormat == PixelFormat.Format24bppRgb) { PixelData24 *sourceBase = (PixelData24 *)sourceData.Scan0; int width = source.Width; int height = source.Height; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { PixelData24 *pSourcePixel = sourceBase + y * width + x; byte blue = pSourcePixel->blue; //pOututPixel->alpha = (byte)(blue); //pOututPixel->red = (byte)(blue); //pOututPixel->blue = (byte)(blue); //pOututPixel->green = (byte)(blue); long index = y * width + x; float value = blue / (float)byte.MaxValue; //mask.Add(index, value); mask.SetMaskWeight(index, value); } } source.UnlockBits(sourceData); } else if (sourceData.PixelFormat == PixelFormat.Format32bppRgb) { PixelData32Rgb *sourceBase = (PixelData32Rgb *)sourceData.Scan0; int width = source.Width; int height = source.Height; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { PixelData32Rgb *pSourcePixel = sourceBase + y * width + x; byte blue = pSourcePixel->blue; //pOututPixel->alpha = (byte)(blue); //pOututPixel->red = (byte)(blue); //pOututPixel->blue = (byte)(blue); //pOututPixel->green = (byte)(blue); long index = y * width + x; float value = blue / (float)byte.MaxValue; //mask.Add(index, value); mask.SetMaskWeight(index, value); } } source.UnlockBits(sourceData); } else if (sourceData.PixelFormat == PixelFormat.Format32bppPArgb) { PixelData32PArgb *sourceBase = (PixelData32PArgb *)sourceData.Scan0; int width = source.Width; int height = source.Height; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { PixelData32PArgb *pSourcePixel = sourceBase + y * width + x; byte blue = pSourcePixel->blue; //pOututPixel->alpha = (byte)(blue); //pOututPixel->red = (byte)(blue); //pOututPixel->blue = (byte)(blue); //pOututPixel->green = (byte)(blue); long index = y * width + x; float value = blue / (float)byte.MaxValue; //mask.Add(index, value); mask.SetMaskWeight(index, value); } } source.UnlockBits(sourceData); } } return(mask); }
static public void setCurrentMaskToBase() { mBaseMaskingMask = mCurrSelectionMask; mCurrSelectionMask = MaskFactory.GetNewMask(); rebuildVisualsAfterSelection(); }
static public void InitMasking(int maxCapacity) { MaskFactory.mMaxCapacity = maxCapacity; mCurrSelectionMask = MaskFactory.GetNewMask(); }