using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using static CAPSTONE_4.Camera;
using static CAPSTONE_4.Obstacle;
using static CAPSTONE_4.Room;
using static CAPSTONE_4.Wall;
using static CAPSTONE_4.BitmapPixelMaker;
namespace CAPSTONE_4
{
public static class WriteableBitmapExtentions //mini class found in order to save WriteableBitmap as an image file (.png)
{
// Save the WriteableBitmap into a PNG file.
public static void Save(this WriteableBitmap wbitmap,
string filename)
{
// Save the bitmap into a file.
using (FileStream stream =
new FileStream(filename, FileMode.Create))
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(wbitmap));
encoder.Save(stream);
}
}
}
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
Room room = new Room(); //Room class to contain cams, and walls.
public BitmapPixelMaker bitmapPixelMaker = new BitmapPixelMaker(1200, 1200); //object used to get and set pixels on the screen
Image img = new Image(); // Canvas --> Image --> WriteableBitmap (which is drawn on by BitmapPixelMaker)
public Point centerofroom = new Point(); //Point used for coloring inside of room white at the creation of it.
bool donecams = false;
public List lastpoints = new List();
public int area = 0; //area of room in pixels
public int minheight = 1000000000; //dims of room, to be calculated and used later
public int minwidth = 1000000000;
public int maxheight = 0;
public int maxwidth = 0;
public int camnummove=-1; //used for camera functions. Needed to pass between handlers.
public int camnumremove = -1;//used for camera functions. Needed to pass between handlers.
bool donearea = false; //only calculate the area of the room once.
public bool mousemove = false; //used to calculate the movement of a camera. sent between handlers.
public MainWindow()
{
InitializeComponent();
AddWallBtn.IsEnabled = true;
ObsBtn.IsEnabled = false;
CamerasBtn.IsEnabled = false;
bitmapPixelMaker.SetColor(105, 105, 105);
WriteableBitmap tempwbitmap = bitmapPixelMaker.MakeBitmap(96, 96);
img.Stretch = Stretch.None;
img.Margin = new Thickness(0);
if (!MAP.Children.Contains(img))
{
MAP.Children.Add(img); //draws pixels just colored to canvas
}
// Set the Image source
img.Source = tempwbitmap;
}
private void ClickNewDoc(object sender, RoutedEventArgs e)//Creates new room, allowing user to save old one.
{
// Configure the message box to be displayed
string messageBoxText = "Do you want to save changes?";
string caption = "Preparing to Make New";
MessageBoxButton button = MessageBoxButton.YesNoCancel;
MessageBoxImage icon = MessageBoxImage.Warning;
//MessageBox.Show(messageBoxText, caption, button, icon);
// Display message box
MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
// Process message box results
switch (result)
{
case MessageBoxResult.Yes:
// User pressed Yes button
Save();
//MAKE NEW DOC
New();
break;
case MessageBoxResult.No:
// User pressed No button
//MAKE NEW DOC
New();
break;
case MessageBoxResult.Cancel:
// User pressed Cancel button
//RETURN
break;
}
}
private void ClickSaveDoc(object sender, RoutedEventArgs e) //Allows user to save doc
{
Save();
}
private void ClickLoadDoc(object sender, RoutedEventArgs e) //Allows user option to load existing room from txt, with or without saving first
{
// Configure the message box to be displayed
string messageBoxText = "Do you want to save changes?";
string caption = "Preparing to Load";
MessageBoxButton button = MessageBoxButton.YesNoCancel;
MessageBoxImage icon = MessageBoxImage.Warning;
//MessageBox.Show(messageBoxText, caption, button, icon);
// Display message box
MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
// Process message box results
switch (result)
{
case MessageBoxResult.Yes:
// User pressed Yes button
Save();
Open();
AddWallBtn.IsEnabled = false;
//ObsBtn.IsEnabled = true;
CamerasBtn.IsEnabled = true;
break;
case MessageBoxResult.No:
// User pressed No button
New();
Open();
AddWallBtn.IsEnabled = false;
//ObsBtn.IsEnabled = true;
CamerasBtn.IsEnabled = true;
break;
case MessageBoxResult.Cancel:
// User pressed Cancel button
//RETURN
break;
}
}
private void ClickPrintDoc(object sender, RoutedEventArgs e) //Allows user to save current room and cameras as .png
{
Print();
}
private void ClickClearDoc(object sender, RoutedEventArgs e) //Allows user to clear current room, without saving.
{
// Configure the message box to be displayed
string messageBoxText = "Are you sure you want to clear this room?";
string caption = "Preparing to Clear Screen";
MessageBoxButton button = MessageBoxButton.YesNo;
MessageBoxImage icon = MessageBoxImage.Warning;
// MessageBox.Show(messageBoxText, caption, button, icon);
// Display message box
MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
// Process message box results
switch (result)
{
case MessageBoxResult.Yes:
// User pressed Yes button
//SET ROOM TO EMPTY'
New();
break;
case MessageBoxResult.No:
// User pressed No button
//Leave alone
break;
}
}
private void ClickExitDoc(object sender, RoutedEventArgs e) //Allows user to exit, with or without saving
{
// Configure the message box to be displayed
string messageBoxText = "Do you want to save changes?";
string caption = "Preparing to Exit";
MessageBoxButton button = MessageBoxButton.YesNoCancel;
MessageBoxImage icon = MessageBoxImage.Warning;
//MessageBox.Show(messageBoxText, caption, button, icon);
// Display message box
MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
// Process message box results
switch (result)
{
case MessageBoxResult.Yes:
// User pressed Yes button
Save();
System.Windows.Application.Current.Shutdown();
break;
case MessageBoxResult.No:
// User pressed No button
//LEAVE
System.Windows.Application.Current.Shutdown();
break;
case MessageBoxResult.Cancel:
// User pressed Cancel button
//RETURN
break;
}
}
private void ClickAddWall(object sender, RoutedEventArgs e) //turns on handlers for adding exterior walls.
{
Console.WriteLine("in clickaddwall");
MAP.MouseLeftButtonDown += Wall_MouseLeftButtonDown;
MAP.MouseMove += Wall_MouseMove;
MAP.MouseRightButtonDown += Wall_MouseRightButtonDown;
AddWallBtn.IsEnabled = false;
}
private void ClickAddCamera(object sender, RoutedEventArgs e) //turns on handlers for adding cameras to room
{
MAP.MouseLeftButtonDown += Cam_MouseLeftButtonDown;
MAP.MouseMove += Cam_MouseMove;
MAP.MouseRightButtonDown += Cam_MouseRightButtonDown;
AddCamBtn.IsEnabled = false;
MoveCamBtn.IsEnabled = false;
RemoveCamBtn.IsEnabled = false;
if (room.RoomCameras.Count < 6)
{
room.RoomCameras.Add(new Camera(room.RoomCameras.Count, new Point(1, 1)));
}
}
private void ClickMoveCamera(object sender, RoutedEventArgs e) //turns on handlers for moving cameras within room
{
MAP.MouseLeftButtonDown += CamMove_MouseLeftButtonDown;
//MAP.MouseMove += CamMove_MouseMove;
MAP.MouseRightButtonDown += CamMove_MouseRightButtonDown;
AddCamBtn.IsEnabled = false;
MoveCamBtn.IsEnabled = false;
RemoveCamBtn.IsEnabled = false;
}
private void ClickRemoveCamera(object sender, RoutedEventArgs e) //turns on handlers for removing from room
{
MAP.MouseLeftButtonDown += CamRemove_MouseLeftButtonDown;
MAP.MouseRightButtonDown += CamRemove_MouseRightButtonDown;
AddCamBtn.IsEnabled = false;
MoveCamBtn.IsEnabled = false;
RemoveCamBtn.IsEnabled = false;
}
private void ClickAddRoundObs(object sender, RoutedEventArgs e)
{
} //NONE OF THESE FUNCTIONS DO ANYTHING
private void ClickAddSquareObs(object sender, RoutedEventArgs e)
{
} //NONE OF THESE FUNCTIONS DO ANYTHING
private void ClickAddWallObs(object sender, RoutedEventArgs e)
{
} //NONE OF THESE FUNCTIONS DO ANYTHING
private void ClickMoveObs(object sender, RoutedEventArgs e)
{
} //NONE OF THESE FUNCTIONS DO ANYTHING
private void ClickRemoveObs(object sender, RoutedEventArgs e)
{
} //NONE OF THESE FUNCTIONS DO ANYTHING
public void Open() //uses file streams to load in data from txt file to build room
{
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension
// Show open file dialog box
Nullable result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
string filename = dlg.FileName;
using (Stream readStream = dlg.OpenFile())
{
try
{
StreamReader reader = new StreamReader(readStream);
while(!reader.EndOfStream)
{
string x = reader.ReadLine();
string[] data = x.Split(':');
if(data[0]=="Wall")
{
Point tempStart = new Point(Convert.ToDouble(data[1]), Convert.ToDouble(data[2]));
Point tempEnd = new Point(Convert.ToDouble(data[3]), Convert.ToDouble(data[4]));
room.RoomWalls.Add(new Wall(tempStart,tempEnd));
}
else if(data[0]=="Camera")
{
int tempNum = Convert.ToInt32(data[1]);
Point tempCenter = new Point(Convert.ToDouble(data[2]), Convert.ToDouble(data[3]));
room.RoomCameras.Add(new Camera(tempNum,tempCenter));
}
else
{
int tempType = Convert.ToInt32(data[1]);
Point tempCenter = new Point(Convert.ToDouble(data[2]), Convert.ToDouble(data[3]));
room.RoomObstacles.Add(new Obstacle(tempType, tempCenter));
}
}
}
catch
{
// Handle any errors...
if (!readStream.CanRead)
readStream.Close();
}
finally
{
// then clean up
readStream.Flush();
readStream.Close();
}
}
}
//PROCESS ROOM *******************
BuildWalls();
string messageBoxText = "Click the inside of the room";
string caption = "Room built";
MessageBoxButton button = MessageBoxButton.OK;
MessageBoxImage icon = MessageBoxImage.Warning;
//MessageBox.Show(messageBoxText, caption, button, icon);
// Display message box
MessageBoxResult answer = MessageBox.Show(messageBoxText, caption, button, icon);
MAP.MouseLeftButtonDown += InsideRoom_MouseLeftButtonDown;
}
public void Save() //uses file streams to save data to txt file from current room
{
// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".txt"; // Default file extension
dlg.Filter = "Text Files (.txt)|*.txt"; // Filter files by extension
// Show save file dialog box
Nullable result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
//PROCESS AND WRITE ROOM
using (Stream writeStream = dlg.OpenFile())
{
try
{
StreamWriter writer = new StreamWriter(writeStream);
while (room.RoomWalls.Count > 1)
{
string output = "";
output += "Wall:";
output += room.RoomWalls[0].StartPt.X + ":";
output += room.RoomWalls[0].StartPt.Y + ":";
output += room.RoomWalls[0].EndPt.X + ":";
output += room.RoomWalls[0].EndPt.Y;
writer.WriteLine(output);
room.RoomWalls.RemoveAt(0);
}
writer.Flush();
while (room.RoomCameras.Count > 0)
{
string output = "";
output += "Camera:";
output += room.RoomCameras[0].camNum + ":";
output += room.RoomCameras[0].camCenter.X + ":";
output += room.RoomCameras[0].camCenter.Y;
writer.WriteLine(output);
room.RoomCameras.RemoveAt(0);
}
writer.Flush();
while (room.RoomObstacles.Count > 0)
{
string output = "";
output += "Obstacle:";
output += room.RoomObstacles[0].ObsType + ":";
output += room.RoomObstacles[0].ObsCenter.X + ":";
output += room.RoomObstacles[0].ObsCenter.Y;
writer.WriteLine(output);
room.RoomObstacles.RemoveAt(0);
}
writer.Flush();
}
catch
{
// Handle any errors...
if (!writeStream.CanWrite)
writeStream.Close();
}
finally
{
// then clean up
writeStream.Flush();
writeStream.Close();
}
}
}
}
public void New() //clears screen & resets options
{
room = new Room();
while (MAP.Children.Count != 0)
{
MAP.Children.RemoveAt(0);
}
BuildRoom();
AddWallBtn.IsEnabled = true;
ObsBtn.IsEnabled = false;
CamerasBtn.IsEnabled = false;
}
public void Print() //uses file streams to export room to a png
{
// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".png"; // Default file extension
dlg.Filter = "PNG Files (.png)|*.png"; // Filter files by extension
// Show save file dialog box
Nullable result = dlg.ShowDialog();
// Process save file dialog box results
if (result == true)
{
// Save document
string filename = dlg.FileName;
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create((BitmapSource)img.Source));
using (FileStream stream = new FileStream(filename, FileMode.Create))
encoder.Save(stream);
//PROCESS AND WRITE ROOM
}
}
public void BuildRoom() //bulk of room building, does, uh, everything.
{
Menu menu = ToolMenu;
//RadioButton rbon, rboff;
//area = 0;
BuildWalls(); //does what it says
if (room.RoomWalls.Count != 0) //only calls function with non-empty room
{
Color oldcolor = new Color(); //these colors used for floodFill
Color newcolor = new Color();
oldcolor = Color.FromArgb(255, 105, 105, 105);
newcolor = Color.FromArgb(255, 255, 255, 255);
//byte red1, blue1, green1, alpha1;
//bitmapPixelMaker.GetPixel((int)(room.RoomWalls[0].StartPt.X + 2), (int)(room.RoomWalls[0].StartPt.Y + 2), out red1, out green1, out blue1, out alpha1);
//Color tempcolor1 = Color.FromArgb(alpha1, red1, green1, blue1);
floodFill((int)centerofroom.Y, (int)centerofroom.X, oldcolor, newcolor); //colors newly built room white
for (int i = 0; i < room.RoomObstacles.Count; i++) //DOES NOT DO ANYTHING NO OBSTACLES
{
Point center = room.RoomObstacles[i].ObsCenter;
int type = room.RoomObstacles[i].ObsType;
switch (type)
{
case 0: //square
break;
case 1: //vertical wall
break;
case 2: //horizontal wall
break;
}
}
for (int i = 0; i < room.RoomCameras.Count; i++) //Colors cameras which are off first.
{
if (!room.RoomCameras[i].camOn)
{
UpdateCams(room.RoomCameras[i].camNum);
BitmapImage bimp = new BitmapImage(); //bimp is the little blue "dot" for the position of the camera
bimp.BeginInit();
bimp.UriSource = new Uri("C:/Users/mnichols/OneDrive - Nexus Solutions/FULL CAPSTONE/Capstone Docs/Cam360.png", UriKind.RelativeOrAbsolute);
bimp.DecodePixelWidth = 5;
bimp.DecodePixelHeight = 5;
bimp.EndInit();
if (room.RoomCameras[i].camImage != null)
{
MAP.Children.Remove(room.RoomCameras[i].camImage);
}
room.RoomCameras[i].SetImage(bimp);
room.RoomCameras[i].camImage.Margin = new Thickness((int)(room.RoomCameras[i].camCenter.X - 2), (room.RoomCameras[i].camCenter.Y - 2), 0, 0);
MAP.Children.Add(room.RoomCameras[i].camImage);
}
}
for (int i = 0; i < room.RoomCameras.Count; i++) //colors on cameras second. This is because the "off" cameras color with white, so they cover any overlaps
{
if (room.RoomCameras[i].camOn)
{
UpdateCams(room.RoomCameras[i].camNum);
BitmapImage bimp = new BitmapImage();
bimp.BeginInit();
bimp.UriSource = new Uri("C:/Users/mnichols/OneDrive - Nexus Solutions/FULL CAPSTONE/Capstone Docs/Cam360.png", UriKind.RelativeOrAbsolute);
bimp.DecodePixelWidth = 5;
bimp.DecodePixelHeight = 5;
bimp.EndInit();
if (room.RoomCameras[i].camImage != null)
{
MAP.Children.Remove(room.RoomCameras[i].camImage);
}
room.RoomCameras[i].SetImage(bimp);
room.RoomCameras[i].camImage.Margin = new Thickness((int)(room.RoomCameras[i].camCenter.X - 2), (room.RoomCameras[i].camCenter.Y - 2), 0, 0);
MAP.Children.Add(room.RoomCameras[i].camImage);
}
}
//CalculateRoom();
WriteableBitmap tempwbitmap = bitmapPixelMaker.MakeBitmap(96, 96); //adds bitmappixelmaker to writeable bitmap, and adds it to image
img.Stretch = Stretch.None;
img.Margin = new Thickness(0);
if (!MAP.Children.Contains(img))
{
MAP.Children.Add(img); //draws pixels just colored to canvas
}
// Set the Image source
img.Source = tempwbitmap;
}
}
public void BuildWalls() //If there aren't any walls, colors the screen in gray.
//otherwise, draws walls using the room.RoomWalls array. Also calculates min & max height & width, and # of cameras sufficient for room.
{
if (room.RoomWalls.Count == 0)
{
bitmapPixelMaker.SetColor(105, 105, 105);
}
else
{
for (int i = 0; i < room.RoomWalls.Count; i++)
{
Point start = room.RoomWalls[i].StartPt;
Point end = room.RoomWalls[i].EndPt;
int increment = 0;
double current = 0;
if (start.X == end.X) //vertical line
{
current = start.Y;
if (start.Y > end.Y) //start point right of end
{
increment = -1;
while (current >= end.Y)
{
bitmapPixelMaker.SetPixel((int)current, (int)start.X, 0, 0, 0, 255);//switches X and Y to be correct based on screen coords
current += increment;
}
}
else
{
increment = 1;
while (current <= end.Y)
{
bitmapPixelMaker.SetPixel((int)current, (int)start.X, 0, 0, 0, 255);//switches X and Y to be correct based on screen coords
current += increment;
}
}
}
else
{
current = start.X;
if (start.X > end.X) //start point below
{
increment = -1;
while (current >= end.X)
{
bitmapPixelMaker.SetPixel((int)start.Y, (int)current, 0, 0, 0, 255);//switches X and Y to be correct based on screen coords
current += increment;
}
}
else
{
increment = 1;
while (current <= end.X)
{
bitmapPixelMaker.SetPixel((int)start.Y, (int)current, 0, 0, 0, 255);//switches X and Y to be correct based on screen coords
current += increment;
}
}
}
}
for (int i = 0; i < room.RoomWalls.Count; i++) //these next two loops color the area inside the room to clear as a start
{
if (room.RoomWalls[i].StartPt.X > maxwidth)
{
maxwidth = (int)room.RoomWalls[i].StartPt.X;
}
if (room.RoomWalls[i].StartPt.Y > maxheight)
{
maxheight = (int)room.RoomWalls[i].StartPt.Y;
}
if (room.RoomWalls[i].StartPt.X < minwidth)
{
minwidth = (int)room.RoomWalls[i].StartPt.X;
}
if (room.RoomWalls[i].StartPt.Y < minheight)
{
minheight = (int)room.RoomWalls[i].StartPt.Y;
}
}
WriteableBitmap tempwbitmap = bitmapPixelMaker.MakeBitmap(96, 96);
img.Stretch = Stretch.None;
img.Margin = new Thickness(0);
if (!MAP.Children.Contains(img))
{
MAP.Children.Add(img); //draws pixels just colored to canvas
}
// Set the Image source
img.Source = tempwbitmap;
int numcameras = (int)Math.Floor((double)(room.RoomWalls.Count / 4));
string fortbcam = "";
fortbcam += "Number of\n Cameras\n Sufficient\n for Full\n Coverage:\n";
if (numcameras <= 6)
{
fortbcam += numcameras;
}
else
{
fortbcam += "Impossible";
}
tbcam.Text = fortbcam;
}
}
void supercover_line(Point p0, Point p1, List points) //does the bulk of the work gathering points between lines.
{
double dx = p1.X - p0.X;
double dy = p1.Y - p0.Y;
double nx = Math.Abs(dx);
double ny = Math.Abs(dy);
int sign_x = dx > 0 ? 1 : -1;
int sign_y = dy > 0 ? 1 : -1;
var p = new Point(p0.X, p0.Y);
points.Add(new Point(p.X, p.Y));
for (double ix = 0, iy = 0; ix < nx || iy < ny;)
{
if ((0.5 + ix) / nx == (0.5 + iy) / ny)
{
// next step is diagonal
p.X += sign_x;
p.Y += sign_y;
ix++;
iy++;
}
else if ((0.5 + ix) / nx < (0.5 + iy) / ny)
{
// next step is horizontal
p.X += sign_x;
ix++;
}
else
{
// next step is vertical
p.Y += sign_y;
iy++;
}
points.Add(new Point(p.X, p.Y)); /// erroring here 1127/3/4/2020
}
return;
}
private void Wall_MouseMove(object sender, MouseEventArgs e) //Shows movement of the wall the user is currently building.
{
//Console.WriteLine("in mousemove");
Point mousepoint = e.MouseDevice.GetPosition(MAP);
mousepoint.X = (int)mousepoint.X; //All points created by mouse events are converted to ints. Nice easy numbers.
mousepoint.Y = (int)mousepoint.Y;
List points = new List();
//Console.WriteLine(e.MouseDevice.GetPosition(MAP).X + " " + e.MouseDevice.GetPosition(MAP).Y);
//Console.WriteLine(mousepoint.ToString() + " here i am");
if (room.RoomWalls.Count != 0)
{
Point lastPointPlaced = room.RoomWalls[room.RoomWalls.Count - 1].StartPt;
if (room.RoomWalls.Count > 1) //this statement determines if the wall should be going up and down, or left and right, based on the previous one.
{
if (lastPointPlaced.X == room.RoomWalls[room.RoomWalls.Count - 2].StartPt.X)
{
Console.WriteLine(lastPointPlaced.X + " x ");
Console.WriteLine(room.RoomWalls[room.RoomWalls.Count - 2].StartPt.X + " x ");
mousepoint.Y = lastPointPlaced.Y;
supercover_line(lastPointPlaced, mousepoint, points);
}
else
{
Console.WriteLine(lastPointPlaced.Y + " y ");
Console.WriteLine(room.RoomWalls[room.RoomWalls.Count - 2].StartPt.Y + " y ");
mousepoint.X = lastPointPlaced.X;
supercover_line(lastPointPlaced, mousepoint, points);
}
}
else //otherwise this is the first wall placed
{
if (Math.Abs(lastPointPlaced.X - mousepoint.X) >= Math.Abs(lastPointPlaced.Y - mousepoint.Y))
{
mousepoint.Y = lastPointPlaced.Y;
supercover_line(lastPointPlaced, mousepoint, points);
}
else
{
mousepoint.X = lastPointPlaced.X;
supercover_line(lastPointPlaced, mousepoint, points);
}
}
//SUPERCOVER LINE OBTAINS AN ARRAY OF POINTS WHICH CAN BE ITERATED THROUGH AND USED TO DRAW LINES, PIXEL BY PIXEL.
byte red, green, blue, alpha;
for (int i = 1; i < points.Count(); i++) //this loop allows the user to shorten their selection and have it update visually.
{
for (int j =0; j points = new List();
//Console.WriteLine(e.MouseDevice.GetPosition(MAP).X + " " + e.MouseDevice.GetPosition(MAP).Y);
//Console.WriteLine(mousepoint.ToString() + " here i am");
if (room.RoomWalls.Count != 0)
{
Point lastPointPlaced = room.RoomWalls[room.RoomWalls.Count - 1].StartPt;
if (room.RoomWalls.Count > 1)
{
if(lastPointPlaced.X == room.RoomWalls[room.RoomWalls.Count - 2].StartPt.X)
{
//Console.WriteLine(lastPointPlaced.X + " x " );
//Console.WriteLine(room.RoomWalls[room.RoomWalls.Count - 2].StartPt.X + " x ");
mousepoint.Y = lastPointPlaced.Y;
supercover_line(lastPointPlaced, mousepoint, points);
}
else
{
//Console.WriteLine(lastPointPlaced.Y+ " y ");
//Console.WriteLine(room.RoomWalls[room.RoomWalls.Count - 2].StartPt.Y + " y ");
mousepoint.X = lastPointPlaced.X;
supercover_line(lastPointPlaced, mousepoint, points);
}
}
else
{
if (Math.Abs(lastPointPlaced.X - mousepoint.X) >= Math.Abs(lastPointPlaced.Y - mousepoint.Y))
{
mousepoint.Y = lastPointPlaced.Y;
supercover_line(lastPointPlaced, mousepoint, points);
}
else
{
mousepoint.X = lastPointPlaced.X;
supercover_line(lastPointPlaced, mousepoint, points);
}
}
byte red, green, blue, alpha;
List erasepts = new List();
bool done = false;
for (int i = 1; i < points.Count(); i++) //algy in order to draw new line and test if lines overlap which means stop drawing
{
bitmapPixelMaker.GetPixel((int)points[i].Y, (int)points[i].X, out red, out green, out blue, out alpha); //obtains current pixel color
Color tempcolor = Color.FromArgb(alpha, red, green, blue);
if (!tempcolor.Equals(Color.FromRgb(0, 0, 0))) //compare to black, if false, color black
{
if (!done)
{
bitmapPixelMaker.SetPixel((int)points[i].Y, (int)points[i].X, 0, 0, 0, 255);
}
else
{
bitmapPixelMaker.SetPixel((int)points[i].Y, (int)points[i].X, 105, 105, 105, 255);
}
}
else //if (tempcolor.Equals(Color.FromRgb(0, 0, 0))) //If we cross a black wall, we finish drawing the room, and end drawing
{
//room.RoomWalls.RemoveAt(room.RoomWalls.Count - 1);
for (int j = 0; j < room.RoomWalls.Count; j++)
{
if (Math.Abs(points[i].X - room.RoomWalls[j].StartPt.X) < 1) //same value vertically
{
if ((points[i].Y < room.RoomWalls[j].StartPt.Y && points[i].Y > room.RoomWalls[j].EndPt.Y) ||
(points[i].Y > room.RoomWalls[j].StartPt.Y && points[i].Y < room.RoomWalls[j].EndPt.Y)) //on the vertical wall
{
int roomnumber = j;
while (roomnumber > 0)
{
supercover_line(room.RoomWalls[0].StartPt, room.RoomWalls[0].EndPt, erasepts);
for (int k = 0; k < erasepts.Count(); k++)
{
bitmapPixelMaker.SetPixel((int)erasepts[k].Y, (int)erasepts[k].X, 105, 105, 105, 255);
//Console.WriteLine(erasepts[k].Y + " " + erasepts[k].X + " Gray 1 in WallMouseDown");
}
erasepts.Clear();
room.RoomWalls.RemoveAt(0);
roomnumber--;
} //now wall originally at j is in slot 0
}
}
else if (Math.Abs(points[i].Y - room.RoomWalls[j].StartPt.Y) < 1) //same value horizontally
{
if ((points[i].X < room.RoomWalls[j].StartPt.X && points[i].X > room.RoomWalls[j].EndPt.X) ||
(points[i].X > room.RoomWalls[j].StartPt.X && points[i].X < room.RoomWalls[j].EndPt.X)) //on the horizontal wall
{
int roomnumber = j;
while (roomnumber > 0)
{
supercover_line(room.RoomWalls[roomnumber].StartPt, room.RoomWalls[roomnumber].EndPt, erasepts);
for (int k = 0; k < erasepts.Count(); k++)
{
bitmapPixelMaker.SetPixel((int)erasepts[k].Y, (int)erasepts[k].X, 105, 105, 105, 255);
//Console.WriteLine(erasepts[k].Y + " " + erasepts[k].X + " Gray 2 in WallMouseDown");
}
erasepts.Clear();
room.RoomWalls.RemoveAt(0);
roomnumber--;
}
}
}
}
room.RoomWalls[0].StartPt.X = (int)points[i].X;
room.RoomWalls[0].StartPt.Y = (int)points[i].Y;
supercover_line(room.RoomWalls[0].StartPt, points[i], erasepts);
for (int k = 0; k < erasepts.Count(); k++)
{
bitmapPixelMaker.SetPixel((int)erasepts[k].Y, (int)erasepts[k].X, 105, 105, 105, 255);
//Console.WriteLine(erasepts[k].Y + " " + erasepts[k].X + " Gray 3 in WallMouseDown");
} //colors extra ends of the lines back to gray
erasepts.Clear();
//set start point of room to be end point of room.
done = true;
room.RoomWalls[0].StartPt = points[i];
room.RoomWalls[room.RoomWalls.Count - 1].EndPt = points[i];
MAP.MouseLeftButtonDown -= Wall_MouseLeftButtonDown;
MAP.MouseMove -= Wall_MouseMove;
MAP.MouseRightButtonDown -= Wall_MouseRightButtonDown;
string messageBoxText = "Click the inside of the room";
string caption = "Room built";
MessageBoxButton button = MessageBoxButton.OK;
MessageBoxImage icon = MessageBoxImage.Warning;
//MessageBox.Show(messageBoxText, caption, button, icon);
// Display message box
MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon);
MAP.MouseLeftButtonDown += InsideRoom_MouseLeftButtonDown; //handler which takes point inside room and colors it white
}
}
points.Clear();
for(int l =0; l erasepts = new List();
if (room.RoomWalls.Count() > 1)
{
supercover_line(room.RoomWalls[room.RoomWalls.Count-1].EndPt, room.RoomWalls[room.RoomWalls.Count - 1].StartPt, erasepts);
for (int k = 0; k < erasepts.Count(); k++)
{
bitmapPixelMaker.SetPixel((int)erasepts[k].Y, (int)erasepts[k].X, 105, 105, 105, 255);
//Console.WriteLine(erasepts[k].Y + " " + erasepts[k].X + " Gray 3 in WallMouseDown");
}
erasepts.Clear();
room.RoomWalls.RemoveAt(room.RoomWalls.Count - 1);
room.RoomWalls[room.RoomWalls.Count - 1].EndPt = mousepoint;
}
else
{
MAP.MouseLeftButtonDown -= Wall_MouseLeftButtonDown;
MAP.MouseMove -= Wall_MouseMove;
MAP.MouseRightButtonDown -= Wall_MouseRightButtonDown;
AddWallBtn.IsEnabled = true;
}
}
private void InsideRoom_MouseLeftButtonDown(object sender, MouseEventArgs e) //gets point for floodFill to do it's work.
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
mousepoint.X = (int)mousepoint.X;
mousepoint.Y = (int)mousepoint.Y;
centerofroom = mousepoint;
MAP.MouseLeftButtonDown -= InsideRoom_MouseLeftButtonDown;
CamerasBtn.IsEnabled = true;
//ObsBtn.IsEnabled = true;
BuildRoom();
}
private void Cam_MouseMove(object sender, MouseEventArgs e) //moves image which represents cam around room so user knows where they are placing cam.
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
mousepoint.X = (int)mousepoint.X;
mousepoint.Y = (int)mousepoint.Y;
Camera cam = room.RoomCameras[room.RoomCameras.Count - 1];
BitmapImage bimp = new BitmapImage();
bimp.BeginInit();
bimp.UriSource= new Uri("C:/Users/mnichols/OneDrive - Nexus Solutions/FULL CAPSTONE/Capstone Docs/Cam360.png", UriKind.RelativeOrAbsolute);
bimp.DecodePixelWidth = 5;
bimp.DecodePixelHeight = 5;
bimp.EndInit();
if(cam.camImage !=null)
{
MAP.Children.Remove(cam.camImage);
}
cam.SetImage(bimp);
byte red, blue, green, alpha;
bitmapPixelMaker.GetPixel((int)mousepoint.Y, (int) mousepoint.X, out red, out green, out blue, out alpha); //obtains current pixel color
Color tempcolor = Color.FromArgb(alpha, red, green, blue);
if (!tempcolor.Equals(Color.FromRgb(0, 0, 0)) && !tempcolor.Equals(Color.FromRgb(105,105,105))) //only move camera within bounds of room
{
cam.camImage.Margin= new Thickness((int)mousepoint.X, (int)mousepoint.Y, 0, 0); //camera is a bitmap image
MAP.Children.Add(cam.camImage);
}
}
private void Cam_MouseLeftButtonDown(object sender, MouseEventArgs e) //places image and locks camera center at mouse location.
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
mousepoint.X = (int)mousepoint.X;
mousepoint.Y = (int)mousepoint.Y;
MAP.MouseLeftButtonDown -= Cam_MouseLeftButtonDown;
MAP.MouseMove -= Cam_MouseMove;
MAP.MouseRightButtonDown -= Cam_MouseRightButtonDown;
AddCamBtn.IsEnabled = true;
MoveCamBtn.IsEnabled = true;
RemoveCamBtn.IsEnabled = true;
Camera cam = room.RoomCameras[room.RoomCameras.Count - 1];
byte red, blue, green, alpha;
bitmapPixelMaker.GetPixel((int)mousepoint.Y, (int)mousepoint.X, out red, out green, out blue, out alpha); //obtains current pixel color
Color tempcolor = Color.FromArgb(alpha, red, green, blue);
if (!tempcolor.Equals(Color.FromRgb(0, 0, 0)) && !tempcolor.Equals(Color.FromRgb(105, 105, 105))) //can only place camera inside room
{
cam.camCenter.X = (int)mousepoint.X;
cam.camCenter.Y = (int)mousepoint.Y;
}
UpdateCams(room.RoomCameras[room.RoomCameras.Count-1].camNum);
if(room.RoomCameras.Count >=6)
{
AddCamBtn.IsEnabled = false;
}
//CalculateRoom();
}
private void Cam_MouseRightButtonDown(object sender, MouseEventArgs e) //cancels placement of current camera
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
MAP.MouseLeftButtonDown -= Cam_MouseLeftButtonDown;
MAP.MouseMove -= Cam_MouseMove;
MAP.MouseRightButtonDown -= Cam_MouseRightButtonDown;
AddCamBtn.IsEnabled = true;
MoveCamBtn.IsEnabled = true;
RemoveCamBtn.IsEnabled = true;
room.RoomCameras.RemoveAt(room.RoomCameras.Count - 1);
}
private void CamMove_MouseMove(object sender, MouseEventArgs e) //handler to capture the movement of camera and update as it goes.
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
mousepoint.X = (int)mousepoint.X;
mousepoint.Y = (int)mousepoint.Y;
bool whitedone = false;
Camera cam = room.RoomCameras[camnummove];
byte red, blue, green, alpha;
bitmapPixelMaker.GetPixel((int)mousepoint.Y, (int)mousepoint.X, out red, out green, out blue, out alpha); //obtains current pixel color
Color tempcolor = Color.FromArgb(alpha, red, green, blue);
if (!tempcolor.Equals(Color.FromRgb(0, 0, 0)) && !tempcolor.Equals(Color.FromRgb(105, 105, 105)))
{
cam.camImage.Margin = new Thickness((int)mousepoint.X, (int)mousepoint.Y, 0, 0);
if(mousemove)
{
for (int i = 0; i < room.RoomCameras.Count; i++)
{
room.RoomCameras[i].SetOn(false);
Color clear = Color.FromArgb(0, 255, 255, 255);
room.RoomCameras[i].SetColor(clear);
}
room.RoomCameras[cam.camNum].camCenter = mousepoint;
//BuildRoom();
for (int i = 0; i < room.RoomCameras.Count; i++) //this loop colors all cameras white, then turns back on the one we are moving
{
if (!room.RoomCameras[i].camOn)
{
UpdateCams(room.RoomCameras[i].camNum);
//BitmapImage bimp = new BitmapImage();
//bimp.BeginInit();
//bimp.UriSource = new Uri("C:/Users/mnichols/OneDrive - Nexus Solutions/FULL CAPSTONE/Capstone Docs/Cam360.png", UriKind.RelativeOrAbsolute);
//bimp.DecodePixelWidth = 5;
//bimp.DecodePixelHeight = 5;
//bimp.EndInit();
//if (room.RoomCameras[i].camImage != null)
//{
// MAP.Children.Remove(room.RoomCameras[i].camImage);
//}
//room.RoomCameras[i].SetImage(bimp);
//room.RoomCameras[i].camImage.Margin = new Thickness((int)(room.RoomCameras[i].camCenter.X - 2), (room.RoomCameras[i].camCenter.Y - 2), 0, 0);
//MAP.Children.Add(room.RoomCameras[i].camImage);
}
}
whitedone = true;
room.RoomCameras[cam.camNum].SetOn(true);
room.RoomCameras[cam.camNum].SetColor();
for (int i = 0; i < room.RoomCameras.Count; i++)
{
if (room.RoomCameras[i].camOn)
{
UpdateCams(room.RoomCameras[i].camNum);
//BitmapImage bimp = new BitmapImage();
//bimp.BeginInit();
//bimp.UriSource = new Uri("C:/Users/mnichols/OneDrive - Nexus Solutions/FULL CAPSTONE/Capstone Docs/Cam360.png", UriKind.RelativeOrAbsolute);
//bimp.DecodePixelWidth = 5;
//bimp.DecodePixelHeight = 5;
//bimp.EndInit();
//if (room.RoomCameras[i].camImage != null)
//{
// MAP.Children.Remove(room.RoomCameras[i].camImage);
//}
//room.RoomCameras[i].SetImage(bimp);
//room.RoomCameras[i].camImage.Margin = new Thickness((int)(room.RoomCameras[i].camCenter.X - 2), (room.RoomCameras[i].camCenter.Y - 2), 0, 0);
//MAP.Children.Add(room.RoomCameras[i].camImage);
}
}
}
}
for (int i = 0; i < room.RoomCameras.Count; i++)
{
room.RoomCameras[i].SetOn(true);
room.RoomCameras[i].SetColor();
}
}
private void CamMove_MouseLeftButtonDown(object sender, MouseEventArgs e) //chooses camera to move OR locks in current camera, then recolors room
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
mousepoint.X = (int)mousepoint.X;
mousepoint.Y = (int)mousepoint.Y;
if (!donecams)
{
for (int i = 0; i < room.RoomCameras.Count(); i++)
{
if (Math.Abs(mousepoint.X - room.RoomCameras[i].camCenter.X) <= 5 && Math.Abs(mousepoint.Y - room.RoomCameras[i].camCenter.Y) <= 5)
{
camnummove = i;
break;
}
}
MAP.MouseMove += CamMove_MouseMove;
donecams = !donecams;
mousemove = true;
}
else
{
Camera cam = room.RoomCameras[camnummove];
MAP.MouseLeftButtonDown -= CamMove_MouseLeftButtonDown;
MAP.MouseMove -= CamMove_MouseMove;
MAP.MouseRightButtonDown -= CamMove_MouseRightButtonDown;
AddCamBtn.IsEnabled = true;
MoveCamBtn.IsEnabled = true;
RemoveCamBtn.IsEnabled = true;
byte red, blue, green, alpha;
bitmapPixelMaker.GetPixel((int)mousepoint.Y, (int)mousepoint.X, out red, out green, out blue, out alpha); //obtains current pixel color
Color tempcolor = Color.FromArgb(alpha, red, green, blue);
if (!tempcolor.Equals(Color.FromRgb(0, 0, 0)) && !tempcolor.Equals(Color.FromRgb(105, 105, 105)))
{
cam.SetColor(Color.FromArgb(0,255, 255, 255));
UpdateCams(room.RoomCameras[camnummove].camNum);
cam.camCenter.X = (int)mousepoint.X;
cam.camCenter.Y = (int)mousepoint.Y;
cam.SetColor();
//for (int i =0; i< room.RoomCameras.Count; i++)
//{
// UpdateCams(room.RoomCameras[i].camNum);
//}
BuildRoom();
donecams = !donecams;
//CalculateRoom();
camnummove = -1;
mousemove = false;
}
}
}
private void CamMove_MouseRightButtonDown(object sender, MouseEventArgs e) //cancels movement of camera
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
MAP.MouseLeftButtonDown -= Cam_MouseLeftButtonDown;
MAP.MouseMove -= Cam_MouseMove;
MAP.MouseRightButtonDown -= Cam_MouseRightButtonDown;
AddCamBtn.IsEnabled = true;
MoveCamBtn.IsEnabled = true;
RemoveCamBtn.IsEnabled = true;
if (camnummove > -1)
{
Camera cam = room.RoomCameras[camnummove];
cam.camImage.Margin = new Thickness((int)cam.camCenter.X, (int)cam.camCenter.Y, 0, 0);
}
donecams = false;
camnummove = -1;
}
private void CamRemove_MouseLeftButtonDown(object sender, MouseEventArgs e) //selects camera to remove then updates room
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
mousepoint.X = (int)mousepoint.X;
mousepoint.Y = (int)mousepoint.Y;
for (int i = 0; i < room.RoomCameras.Count(); i++)
{
if (Math.Abs(mousepoint.X - room.RoomCameras[i].camCenter.X) <= 5 && Math.Abs(mousepoint.Y - room.RoomCameras[i].camCenter.Y) <= 5)
{
camnumremove = i;
donecams = !donecams;
break;
}
}
if(donecams)
{
Camera cam = room.RoomCameras[camnumremove];
MAP.MouseLeftButtonDown -= CamRemove_MouseLeftButtonDown;
MAP.MouseRightButtonDown -= CamRemove_MouseRightButtonDown;
AddCamBtn.IsEnabled = true;
MoveCamBtn.IsEnabled = true;
RemoveCamBtn.IsEnabled = true;
switch (camnumremove + 1)
{
case 1:
rb1on.IsEnabled = false;
rb1off.IsEnabled = false;
break;
case 2:
rb2on.IsEnabled = false;
rb2off.IsEnabled = false;
break;
case 3:
rb3on.IsEnabled = false;
rb3off.IsEnabled = false;
break;
case 4:
rb4on.IsEnabled = false;
rb4off.IsEnabled = false;
break;
case 5:
rb5on.IsEnabled = false;
rb5off.IsEnabled = false;
break;
case 6:
rb6on.IsEnabled = false;
rb6off.IsEnabled = false;
break;
}
for (int i =camnumremove; i< room.RoomCameras.Count(); i++)
{
room.RoomCameras[i].SetColor(Color.FromRgb(255, 255, 255));
//UpdateCams(room.RoomCameras[i].camNum);
BuildRoom();
room.RoomCameras[i].camNum = i-1;
room.RoomCameras[i].SetColor();
}
MAP.Children.Remove(room.RoomCameras[camnumremove].camImage);
room.RoomCameras.RemoveAt(camnumremove);
for (int i = 0; i < room.RoomCameras.Count(); i++)
{
UpdateCams(room.RoomCameras[i].camNum);
}
donecams = !donecams;
//CalculateRoom();
camnumremove = -1;
}
}
private void CamRemove_MouseRightButtonDown(object sender, MouseEventArgs e) //cancels selecting of camera to remove
{
Point mousepoint = e.MouseDevice.GetPosition(MAP);
MAP.MouseLeftButtonDown -= CamRemove_MouseLeftButtonDown;
MAP.MouseRightButtonDown -= CamRemove_MouseRightButtonDown;
AddCamBtn.IsEnabled = true;
MoveCamBtn.IsEnabled = true;
RemoveCamBtn.IsEnabled = true;
camnumremove = -1;
}
public void UpdateCams(int CamNum) //updates a specific camera in the room
{
byte alpha, red, blue, green;
Point center = room.RoomCameras[CamNum].camCenter;
int num = room.RoomCameras[CamNum].camNum;
List wallPoints = new List();
List wall2cam = new List();
for (int j = 0; j < room.RoomWalls.Count; j++) //obtains all points along outside wall
{
Point start = room.RoomWalls[j].StartPt;
Point end = room.RoomWalls[j].EndPt;
int increment = 0;
double current = 0;
supercover_line(start, end, wallPoints);
}
for (int j = 0; j < wallPoints.Count; j++) //iterates through each point along wall and gets an array of points from wall to camera
{
supercover_line(wallPoints[j], room.RoomCameras[CamNum].camCenter, wall2cam); //obtain the array between the points along the wall to the current camera
for (int k = wall2cam.Count() - 1; k >= 0; k--) // counts from the center of the camera back out to the wall
{
bitmapPixelMaker.GetPixel((int)wall2cam[k].Y, (int)wall2cam[k].X, out red, out green, out blue, out alpha); //obtains current pixel color //switches X and Y to be correct based on screen coords
Color tempcolor = Color.FromArgb(alpha, red, green, blue);
if (tempcolor.Equals(Color.FromRgb(0, 0, 0))) //compare to black, if true, empty array, stop coloring, move on
{
wall2cam.Clear();
wall2cam.TrimExcess();
k = -1;
}
else //otherwise color current pixel based on the camera color, using OxFFFFFF, so each camera should give a different color based on a power of 16,
///i.e. camera 0's rgb is 0, 0, 16, or 0x000010, im still working out the details on this.
///Im worried individual bits is too small of a color change to notice, especially when small bits like 1, 2, 4, & 8. Maybe I'll do Octal??
{
Color newcolor = new Color();
if (tempcolor.Equals(Color.FromRgb(255, 255, 255))) //if currently clear i.e. pixel is uncolored with no camera coverage
{
//newcolor = camColor;
newcolor.R = room.RoomCameras[CamNum].camColor.R;
newcolor.G = room.RoomCameras[CamNum].camColor.G;
newcolor.B = room.RoomCameras[CamNum].camColor.B;
}
else //otherwise, take the color it currently is and add it to the new one
//newcolor = tempcolor + camColor;
{
newcolor.R = (byte)((int)tempcolor.R | (int)room.RoomCameras[CamNum].camColor.R);
newcolor.G = (byte)((int)tempcolor.G | (int)room.RoomCameras[CamNum].camColor.G);
newcolor.B = (byte)((int)tempcolor.B | (int)room.RoomCameras[CamNum].camColor.B);
}
bitmapPixelMaker.SetPixel((int)wall2cam[k].Y, (int)wall2cam[k].X, newcolor.R, newcolor.G, newcolor.B, 255); //switches X and Y to be correct based on screen coords
}
}
}
switch (CamNum + 1) //as cameras are added change radiobuttons
{
case 1:
rb1on.IsEnabled = true;
rb1off.IsEnabled = true;
break;
case 2:
rb2on.IsEnabled = true;
rb2off.IsEnabled = true;
break;
case 3:
rb3on.IsEnabled = true;
rb3off.IsEnabled = true;
break;
case 4:
rb4on.IsEnabled = true;
rb4off.IsEnabled = true;
break;
case 5:
rb5on.IsEnabled = true;
rb5off.IsEnabled = true;
break;
case 6:
rb6on.IsEnabled = true;
rb6off.IsEnabled = true;
break;
}
WriteableBitmap tempwbitmap = bitmapPixelMaker.MakeBitmap(96, 96);
img.Stretch = Stretch.None;
img.Margin = new Thickness(0);
if (!MAP.Children.Contains(img))
{
MAP.Children.Add(img); //draws pixels just colored to canvas
}
// Set the Image source
img.Source = tempwbitmap;
CalculateRoom();
}
public void floodFill(int x, int y, Color oldcolor, Color newcolor) //uses stack to color entirety of room white, also calculates area of room pixel by pixel
{
Point p = new Point(x, y);
Stack S = new Stack();
byte red, green, blue, alpha;
bitmapPixelMaker.GetPixel(x,y, out red, out green, out blue, out alpha);
Color tempcolor = Color.FromArgb(255, red, green, blue);
//oldcolor is most often gray used in bg. new color is white. x & y is selected when user clicks inside room.
S.Push(p);
while (S.Count() != 0) //while still in room & not all pixels colored. check each of the four directions and add to stack for BFS
{
Point q = S.Peek();
int tempx = (int)q.X;
int tempy = (int)q.Y;
bitmapPixelMaker.GetPixel(tempx + 1, tempy, out red, out green, out blue, out alpha);
Color tempcolordown = Color.FromArgb(255, red, green, blue);
bitmapPixelMaker.GetPixel(tempx - 1, tempy, out red, out green, out blue, out alpha);
Color tempcolorup = Color.FromArgb(255, red, green, blue);
bitmapPixelMaker.GetPixel(tempx, tempy-1, out red, out green, out blue, out alpha);
Color tempcolorleft = Color.FromArgb(255, red, green, blue);
bitmapPixelMaker.GetPixel(tempx, tempy+1, out red, out green, out blue, out alpha);
Color tempcolorright = Color.FromArgb(255, red, green, blue);
if (x + 1 < maxheight && tempcolordown.Equals(oldcolor))
{
bitmapPixelMaker.SetPixel(tempx+1, tempy, newcolor.R, newcolor.G, newcolor.B, 255);
if (!donearea)
{
area++;
}
S.Push(new Point(tempx + 1, tempy));
}
else if (y + 1 < maxwidth && tempcolorright.Equals(oldcolor))
{
bitmapPixelMaker.SetPixel(tempx, tempy + 1, newcolor.R, newcolor.G, newcolor.B, 255);
if (!donearea)
{
area++;
}
S.Push(new Point(tempx, tempy + 1));
}
else if (y - 1 > minwidth && tempcolorleft.Equals(oldcolor))
{
bitmapPixelMaker.SetPixel(tempx, tempy - 1, newcolor.R, newcolor.G, newcolor.B, 255);
if (!donearea)
{
area++;
}
S.Push(new Point(tempx, tempy - 1));
}
else if (x - 1 > minheight && tempcolorup.Equals(oldcolor))
{
bitmapPixelMaker.SetPixel(tempx - 1, tempy, newcolor.R, newcolor.G, newcolor.B, 255);
if (!donearea)
{
area++;
}
S.Push(new Point(tempx - 1, tempy));
}
else
{
S.Pop();
}
}
WriteableBitmap tempwbitmap = bitmapPixelMaker.MakeBitmap(96, 96);
img.Stretch = Stretch.None;
img.Margin = new Thickness(0);
if (!MAP.Children.Contains(img))
{
MAP.Children.Add(img); //draws pixels just colored to canvas
}
// Set the Image source
img.Source = tempwbitmap;
donearea = true;
}
public void CalculateRoom() //calculates percentage of how much of the room is colored by cameras.
{
int colored = 0;
byte alpha, red, blue, green;
for (int i = (int)minheight; i < maxheight; i++)
{
for (int j = (int)minwidth; j < maxwidth; j++)
{
bitmapPixelMaker.GetPixel(i, j, out red, out green, out blue, out alpha);
Color tempcolor = Color.FromArgb(alpha, red, green, blue);
if (!tempcolor.Equals(Color.FromRgb(255, 255, 255)) && !tempcolor.Equals(Color.FromRgb(0, 0, 0)) && !tempcolor.Equals(Color.FromRgb(105, 105, 105)))
{
colored++;
}
}
}
double covered = ((double)colored / area) * 100.0;
covered = Math.Round(covered, 3);
tb1.Text = "Percent \nCovered: \n" + covered + "% ";
}
private void RB_CheckChange(object sender, RoutedEventArgs e) //as radiobuttons are enabled and changed, turns cameras on and off and colors as such
{
RadioButton rbclicked = (RadioButton) e.Source;
string rbname = rbclicked.Name;
Color clear = Color.FromArgb(0, 255, 255, 255);
switch(rbname)
{
case "rb1on":
room.RoomCameras[0].SetColor();
break;
case "rb1off":
room.RoomCameras[0].SetColor(clear);
room.RoomCameras[0].SetOn(false);
break;
case "rb2on":
room.RoomCameras[1].SetColor();
break;
case "rb2off":
room.RoomCameras[1].SetColor(clear);
room.RoomCameras[1].SetOn(false);
break;
case "rb3on":
room.RoomCameras[2].SetColor();
break;
case "rb3off":
room.RoomCameras[2].SetColor(clear);
room.RoomCameras[2].SetOn(false);
break;
case "rb4on":
room.RoomCameras[3].SetColor();
break;
case "rb4off":
room.RoomCameras[3].SetColor(clear);
room.RoomCameras[3].SetOn(false);
break;
case "rb5on":
room.RoomCameras[4].SetColor();
break;
case "rb5off":
room.RoomCameras[4].SetColor(clear);
room.RoomCameras[4].SetOn(false);
break;
case "rb6on":
room.RoomCameras[5].SetColor();
break;
case "rb6off":
room.RoomCameras[5].SetColor(clear);
room.RoomCameras[5].SetOn(false);
break;
}
//Color oldcolor = Color.FromRgb(105, 105, 105);
//area = 0;
//bitmapPixelMaker.SetColor(105, 105, 105);
//BuildWalls();
//floodFill((int)centerofroom.Y, (int)centerofroom.X, oldcolor, Color.FromRgb(255, 255, 255));
//for (int i = 0; i