public void updateCam(int index, CamData cam_data) { if (cams.Count > 0) { this.cams[index] = cam_data; } }
internal void changeSceneCam(CamTask task) { var cdata = VNNeoController.cameraData; var addata = currentVNData; var cam_data = new CamData(cdata.pos, cdata.rotate, cdata.distance, cdata.parse, addata); if (task == CamTask.ADD) { block.AddCam(cam_data); } else if (task == CamTask.UPDATE) { block.UpdateCam(cam_data); } else if (task == CamTask.DELETE) { var cur_cam = block.DeleteCam(); if (cur_cam > -1) { setCamera(); } } if (!(task == CamTask.UPDATE)) { getSceneCamString(); } }
public void SetCamData(CamData camData) { moveSpeed = camData.moveSpeed; targetDistance = camData.targetDistance; target = camData.target; usePlayerForward = camData.usePlayerForward; }
public static void cam_rotate(VNNeoController game, Vector3 param) { CamData camobj = game.get_camera_num(0); Vector3 v3 = camobj.rotation; camobj.rotation = new Vector3(v3.x + param.x, v3.y + param.y, v3.z + param.z); game.move_camera_obj(camobj); }
public Camera2(float aspectRatio, Renderer renderer) { _aspectRatio = aspectRatio; Data = new CamData(); CalculateProjection(); CalculateView(); }
/* * public static void cam_rotate(VNNeoController game, (Vector3 vec, float duration) param) * { * CamData camobj = game.get_camera_num(0); * Vector3 v3 = camobj.rotation; * // param = ((rot_delta_x, rot_delta_y, rot_delta_z), duration) * camobj.rotation = new Vector3(v3.x + param.vec.x, v3.y + param.vec.y, v3.z + param.vec.z); * game.anim_to_camera_obj(param.duration, camobj); * } * * public static void cam_rotate(VNNeoController game, (Vector3 vec, float duration, string style) param) * { * CamData camobj = game.get_camera_num(0); * Vector3 v3 = camobj.rotation; * // param = ((rot_delta_x, rot_delta_y, rot_delta_z), duration) * camobj.rotation = new Vector3(v3.x + param.vec.x, v3.y + param.vec.y, v3.z + param.vec.z); * game.anim_to_camera_obj(param.duration, camobj, style: param.style); * } * * public static void cam_rotate(VNNeoController game, (Vector3 vec, float duration, string style, GameFunc onCameraEnd) param) * { * CamData camobj = game.get_camera_num(0); * Vector3 v3 = camobj.rotation; * // param = ((rot_delta_x, rot_delta_y, rot_delta_z), duration) * camobj.rotation = new Vector3(v3.x + param.vec.x, v3.y + param.vec.y, v3.z + param.vec.z); * game.anim_to_camera_obj(param.duration, camobj, style: param.style, param.onCameraEnd); * } */ public static void cam_rotate(VNNeoController game, CamData param) { CamData camobj = game.get_camera_num(0); Vector3 v3 = camobj.rotation; // param = ((rot_delta_x, rot_delta_y, rot_delta_z), duration) camobj.rotation = new Vector3(v3.x + param.rotation.x, v3.y + param.rotation.y, v3.z + param.rotation.z); game.anim_to_camera_obj(param.duration, camobj, style: param.style); }
/* * * public static void cam_zoom(VNNeoController game, (float zoom_delta, float duration) param) * { * var camobj = game.get_camera_num(0); * var dv3 = camobj.distance; * // param = zoom_delta, use positive value to zoom in, and negative value for zoom out * camobj.distance = new Vector3(dv3.x, dv3.y, dv3.z + param.zoom_delta); * game.anim_to_camera_obj(param.duration, camobj); * } * * public static void cam_zoom(VNNeoController game, (float zoom_delta, float duration, string style) param) * { * var camobj = game.get_camera_num(0); * var dv3 = camobj.distance; * // param = zoom_delta, use positive value to zoom in, and negative value for zoom out * camobj.distance = new Vector3(dv3.x, dv3.y, dv3.z + param.zoom_delta); * game.anim_to_camera_obj(param.duration, camobj, param.style); * } */ public static void cam_zoom(VNNeoController game, CamData param) { var camobj = game.get_camera_num(0); var dv3 = camobj.distance; // param = zoom_delta, use positive value to zoom in, and negative value for zoom out camobj.distance = new Vector3(dv3.x, dv3.y, dv3.z + param.zoom_delta); game.anim_to_camera_obj(param.duration, camobj, param.style); }
private void HandleChildChanged(object sender, ChildChangedEventArgs args) { if (args.DatabaseError != null) { Debug.LogError(args.DatabaseError.Message); return; } CamData incomingData = JsonUtility.FromJson <CamData>(args.Snapshot.GetRawJsonValue()); _camCollection.CameraUpdate(incomingData); }
override public void move_camera_direct(CamData cam) { Studio.CameraControl.CameraData cdata = cameraData; Studio.CameraControl c = studio.cameraCtrl; cdata.pos = cam.position; cdata.distance = cam.distance; cdata.rotate = cam.rotation; cdata.parse = cam.fov; }
internal void camSetAll(bool state) { foreach (var i in Enumerable.Range(0, block.Count)) { var scene = block[i]; // only process scene if 1 cam is VN cam - other, skip // cam = scene.cams[0] foreach (var j in Enumerable.Range(0, scene.cams.Count)) { CamData cam = scene.cams[j]; cam.addata.enabled = state; } } show_blocking_message_time_sc("Cams changed!"); }
private async Task runBatchConversion() { string[] inFiles = Directory.GetFiles(txtInPath.Text); progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = inFiles.Length; foreach (string filePath in inFiles) { FileInfo inFile = new FileInfo(filePath); if (inFile.Exists) { if (inFile.Extension == ".cam") { CamData[] data = new CamData[DataManipulation.getNumberOfFrames(inFile)]; lstProgress.Items.Add("Processing " + inFile.Name + ": Frames: " + data.Length + " => " + data.Length * 2); lstProgress.TopIndex = lstProgress.Items.Count - 1; lstProgress.Refresh(); await Task.Run(() => { DataManipulation.parse(inFile, ref data); DataManipulation.interpolate(ref data); DataManipulation.dump(txtOutPath.Text + "\\" + inFile.Name, ref data); }); data = null; } else { lstProgress.Items.Add("Skipping " + inFile.Name); lstProgress.TopIndex = lstProgress.Items.Count - 1; lstProgress.Refresh(); } } else { lstProgress.Items.Add("Could not find " + inFile.Name); lstProgress.TopIndex = lstProgress.Items.Count - 1; lstProgress.Refresh(); } progressBar.Value++; } }
private void setup_camera(Camera camera, CamData camData, float rot_around) { camera.transform.position = new Vector3(0, camData.height, camData.distance); camera.transform.RotateAround(Vector3.zero, Vector3.up, rot_around); camera.clearFlags = CameraClearFlags.Color; // camera.backgroundColor = Color.black; // camera.backgroundColor = Color.green; camera.fieldOfView = camData.fov; camera.nearClipPlane = 0.3f; camera.farClipPlane = 20; Vector3 lookat = new Vector3(0, camera.transform.position.y, 0); camera.transform.LookAt(lookat); }
new public VNCamera.CamData get_camera_num(int camnum) { Studio.CameraControl.CameraData cdata; Studio.Studio studio = this.studio; SceneInfo si = studio.sceneInfo; Studio.CameraControl.CameraData[] cdatas = si.cameraData; if (camnum == 0) { // 0 camera is current camera. It may be interested due to some reasons var c = studio.cameraCtrl; cdata = cameraData; } else { cdata = cdatas[camnum - 1]; } var camobj = new CamData(cdata.pos, cdata.rotate, cdata.distance, cdata.parse); //print camobj return(camobj); }
private CamData[] parseData(string text) { CamData[] camData = new CamData[4]; camData[0] = new CamData(); camData[1] = new CamData(); camData[2] = new CamData(); camData[3] = new CamData(); // -- cam1 camData[0].fov = 19.8f; camData[0].height = -Const.height_zylinder / 2f - 0.04f;//-0.085f; camData[0].distance = 1.365f + Const.radius; camData[0].x_rotation = 0; // -- cam2 camData[1].fov = 19.8f; camData[1].height = -Const.height_zylinder / 2f - 0.04f;//+0.085f; camData[1].distance = 1.365f + Const.radius; camData[1].x_rotation = 0; // -- cam3 camData[2].fov = 19.8f; camData[2].height = -Const.height_zylinder / 2f - 0.04f; camData[2].distance = 1.365f + Const.radius; camData[2].x_rotation = 0; // -- cam4 camData[3].fov = 19.8f; camData[3].height = -Const.height_zylinder / 2f - 0.04f; camData[3].distance = -(1.365f + Const.radius); camData[3].x_rotation = 0; return(camData); }
// Formula defined in spec doc private void WriteJerkBetweenSelections(StreamWriter resWriter, List <CamData> cData, List <Selection> sels, string pr) { Vector3[] velocities = new Vector3[cData.Count]; Vector3[] accels = new Vector3[velocities.Length]; Vector3[] jerks = new Vector3[accels.Length]; //velocities[velocities.Length - 1] = Vector3.zero; for (int ci = 1; ci < cData.Count; ci++) { CamData cd1 = cData[ci - 1]; CamData cd2 = cData[ci]; Vector3 cd1Euler = cd1.orientation.normalized.eulerAngles * Mathf.Deg2Rad; Vector3 cd2Euler = cd2.orientation.normalized.eulerAngles * Mathf.Deg2Rad; if (cd2.timeStamp != cd1.timeStamp) { if (Mathf.Abs(cd2Euler.x - cd1Euler.x) > Mathf.PI) { if (cd2Euler.x > cd1Euler.x) { cd1Euler = new Vector3(cd1Euler.x + 2f * Mathf.PI, cd1Euler.y, cd1Euler.z); } else { cd2Euler = new Vector3(cd2Euler.x + 2f * Mathf.PI, cd2Euler.y, cd2Euler.z); } } if (Mathf.Abs(cd2Euler.y - cd1Euler.y) > Mathf.PI) { if (cd2Euler.y > cd1Euler.y) { cd1Euler = new Vector3(cd1Euler.x, cd1Euler.y + 2f * Mathf.PI, cd1Euler.z); } else { cd2Euler = new Vector3(cd2Euler.x, cd2Euler.y + 2f * Mathf.PI, cd2Euler.z); } } if (Mathf.Abs(cd2Euler.z - cd1Euler.z) > Mathf.PI) { if (cd2Euler.z > cd1Euler.z) { cd1Euler = new Vector3(cd1Euler.x, cd1Euler.y, cd1Euler.z + 2f * Mathf.PI); } else { cd2Euler = new Vector3(cd2Euler.x, cd2Euler.y, cd2Euler.z + 2f * Mathf.PI); } } if ((Mathf.Abs(cd2Euler.x - cd1Euler.x) > Mathf.PI) || (Mathf.Abs(cd2Euler.y - cd1Euler.y) > Mathf.PI) || (Mathf.Abs(cd2Euler.z - cd1Euler.z) > Mathf.PI)) { Debug.Log(cd2Euler.ToString("F1") + " - " + cd1Euler.ToString("F1")); } velocities[ci] = cd2Euler / (cd2.timeStamp - cd1.timeStamp) - cd1Euler / (cd2.timeStamp - cd1.timeStamp); if (angleWriter != null) { float x = velocities[ci].x; float y = velocities[ci].y; float z = velocities[ci].z; angleWriter.WriteLine(cd2Euler.x.ToString("F5") + ", " + cd2Euler.y.ToString("F5") + ", " + cd2Euler.z.ToString("F5")); vWriter.WriteLine(velocities[ci].x.ToString("F5") + ", " + velocities[ci].y.ToString("F5") + ", " + velocities[ci].z.ToString("F5")); } } } accels[accels.Length - 1] = Vector3.zero; for (int ci = 1; ci < velocities.Length - 1; ci++) { CamData cd1 = cData[ci - 1]; CamData cd2 = cData[ci]; Vector3 v1 = velocities[ci - 1]; Vector3 v2 = velocities[ci]; if (cd2.timeStamp != cd1.timeStamp) { accels[ci] = (v2 - v1) / (cd2.timeStamp - cd1.timeStamp); } } jerks[jerks.Length - 1] = Vector3.zero; jerks[jerks.Length - 2] = Vector3.zero; for (int ci = 1; ci < cData.Count - 2; ci++) { CamData cd1 = cData[ci - 1]; CamData cd2 = cData[ci]; Vector3 a1 = accels[ci - 1]; Vector3 a2 = accels[ci]; if (cd2.timeStamp != cd1.timeStamp) { jerks[ci] = (a2 - a1) / (cd2.timeStamp - cd1.timeStamp); } } float[] angularJerk = new float[jerks.Length]; angularJerk[angularJerk.Length - 1] = 0f; angularJerk[angularJerk.Length - 2] = 0f; for (int ji = 0; ji < angularJerk.Length; ji++) { CamData cd = cData[ji]; Vector3 cdEuler = cd.orientation.normalized.eulerAngles; float tx = cdEuler.x; float ty = cdEuler.y; float tz = cdEuler.z; float tx1 = velocities[ji].x; float ty1 = velocities[ji].y; float tz1 = velocities[ji].z; float tx2 = accels[ji].x; float ty2 = accels[ji].y; float tz2 = accels[ji].z; float tx3 = jerks[ji].x; float ty3 = jerks[ji].y; float tz3 = jerks[ji].z; angularJerk[ji] = Mathf.Sqrt( Mathf.Pow((2f * Mathf.Cos(ty) * ty1 * tx2 + tx1 * (-Mathf.Sin(ty) * (ty1 * ty1) + Mathf.Cos(ty) * ty2) + tz1 * (-Mathf.Cos(ty) * (Mathf.Cos(tx) * (tx1 * tx1 + ty1 * ty1) + Mathf.Sin(tx) * tx2) + Mathf.Sin(ty) * (2f * Mathf.Sin(tx) * tx1 * ty1 - Mathf.Cos(tx) * ty2)) - 2f * (Mathf.Cos(ty) * Mathf.Sin(tx) * tx1 + Mathf.Cos(tx) * Mathf.Sin(ty) * ty1) * tz2 + Mathf.Sin(ty) * tx3 + Mathf.Cos(tx) * Mathf.Cos(ty) * tz3), 2) + Mathf.Pow((2f * Mathf.Sin(ty) * ty1 * tx2 + tx1 * (Mathf.Cos(ty) * (ty1 * ty1) + Mathf.Sin(ty) * ty2) + tz1 * (-Mathf.Sin(ty) * (Mathf.Cos(tx) * (tx1 * tx1 + ty1 * ty1) + Mathf.Sin(tx) * tx2) + Mathf.Cos(ty) * (-2f * Mathf.Sin(tx) * tx1 * ty1 + Mathf.Cos(tx) * ty2)) + 2f * (-Mathf.Sin(tx) * Mathf.Sin(ty) * tx1 + Mathf.Cos(tx) * Mathf.Cos(ty) * ty1) * tz2 - Mathf.Cos(ty) * tx3 + Mathf.Cos(tx) * Mathf.Sin(ty) * tz3), 2) + Mathf.Pow((Mathf.Cos(tx) * (tz1 * tx2 + 2f * tx1 * tz2) + ty3 + Mathf.Sin(tx) * (-(tx1 * tx1) * tz1 + tz3)), 2) ); } float jerkSum = 0f; for (int ji = 1; ji < angularJerk.Length; ji++) { float timeStep = cData[ji].timeStamp - cData[ji - 1].timeStamp; jerkSum += (angularJerk[ji] * angularJerk[ji]) * timeStep; if (angleWriter != null) { jWriter.WriteLine(String.Format("{0}", (angularJerk[ji] * angularJerk[ji]) * timeStep)); jWriter.Flush(); } } float jerkRMS = Mathf.Sqrt(jerkSum); resWriter.Write(String.Format("{0}, ", jerkRMS)); }
public Vector3 calcTgt(float distance) => default; // 0x0085A3E0-0x0085A500 public void CopyFrom(CamData left) { } // 0x0085A500-0x0085A530
} // 0x0085A1C0-0x0085A2F0 public void Apply_ForSceneGUIPreview(CamData startCam, ActObjCamera actCamera, ActObjectManager actObjManager) { } // 0x0085A2F0-0x0085A360
// Camera Manip public int addCam(CamData cam_data) { this.cams.Add(cam_data); return(this.cams.Count - 1); }
private CamData calcCam_(CamData startCam, float time, ActSnapshotContext context) => default; // 0x00859CB0-0x00859F20 public float CalcMoveDistLen(CamData startCam, ActObjectManager actObjectManager) => default; // 0x00859F20-0x0085A150
public float CalcMoveDistLen(CamData startCam, ActObjectManager actObjectManager) => default; // 0x00859F20-0x0085A150 public void Apply(ActObjCamera actCamera, CamData startCam, float time, ActObjectManager actObjManager) { } // 0x0085A150-0x0085A1C0
private CamData createCamParam_(ActParam_Camera param) => default; // 0x008597E0-0x00859920 private CamData calcCam_(CamData startCam, float time, ActObjectManager actObjectManager) => default; // 0x00859A40-0x00859CB0
private CamData calcCam_(CamData startCam, float time, ActObjectManager actObjectManager) => default; // 0x00859A40-0x00859CB0 private CamData calcCam_(CamData startCam, float time, ActSnapshotContext context) => default; // 0x00859CB0-0x00859F20
public static void cam_goto_preset(VNNeoController game, CamData param) { // param = (set, duration) game.anim_to_camera_num(param.duration, param.camnum); }
public bool CompareValues(CamData otherData) { return(moveSpeed == otherData.moveSpeed && targetDistance == otherData.targetDistance && target == otherData.target); }
public void AddCameraDataToDatabase(Vector3 pos, Vector3 rot) { data = new CamData(_sessionId, _sesionNick, pos, rot); _reference.Child(_sessionId + " " + _sesionNick).SetRawJsonValueAsync(JsonUtility.ToJson(data)); }
/* * public static void cam_goto_pos(VNNeoController game, (Vector3 pos, Vector3 distance, Vector3 rotate) param) * { * game.move_camera(pos: param.pos, distance: param.distance, rotate: param.rotate); * } * * public static void cam_goto_pos(VNNeoController game, (Vector3 pos, Vector3 distance, Vector3 rotate, float duration, string style) param) * { * game.anim_to_camera(param.duration, pos: param.pos, distance: param.distance, rotate: param.rotate, style: param.style); * } * * public static void cam_goto_pos(VNNeoController game, (Vector3 pos, Vector3 distance, Vector3 rotate, float duration) param) * { * game.anim_to_camera(param.duration, pos: param.pos, distance: param.distance, rotate: param.rotate); * } * * public static void cam_goto_pos(VNNeoController game, (Vector3 pos, Vector3 distance, Vector3 rotate, float duration, string style, float fov) param) * { * game.anim_to_camera(param.duration, pos: param.pos, distance: param.distance, rotate: param.rotate, fov: param.fov, style: param.style); * } */ public static void cam_goto_pos(VNNeoController game, CamData param) { game.anim_to_camera(param.duration, pos: param.position, distance: param.distance, rotate: param.rotation, fov: param.fov, style: param.style); }
public IEnumerator<ITask> GetFrame() { //Console.WriteLine("New Frame is ready, fetching and calculating angle"); roborealm.QueryVariablesRequest varReq = new roborealm.QueryVariablesRequest(); roborealm.QueryFrameRequest frameReq = new roborealm.QueryFrameRequest(); varReq._names = new List<String>(); varReq._names.Add("IMAGE_WIDTH"); varReq._names.Add("IMAGE_HEIGHT"); //varReq._names.Add("COG_X"); //varReq._names.Add("COG_Y"); varReq._names.Add("SHAPE_X_COORD"); varReq._names.Add("SHAPE_Y_COORD"); varReq._names.Add("SHAPE_CONFIDENCE"); frameReq.Format = ImageFormat.Bmp.Guid; int x = 0; int y = 0; int width = 0; int height = 0; int confidence = 0; CamData d = new CamData(); d.X = NULL; if (varReq != null) { // send of the request and process the results yield return Arbiter.Choice( _rrPort.QueryVariables(varReq), delegate(roborealm.QueryVariablesResponse res) { // for now just print the results in the command console. You could // use these values to futher partner with a robotic drive system // and move the robot based on COG values. //Console.WriteLine("COG: " + res._values[0] + "," + res._values[1]); try { width = int.Parse(res._values[0]); height = int.Parse(res._values[1]); if (res._values.Count == 5) { x = int.Parse(res._values[2]); y = int.Parse(res._values[3]); confidence = int.Parse(res._values[4]); } } catch (Exception) { }; }, delegate(Fault f) { LogError(LogGroups.Console, "Could not query variables", f); }); frameReq.Size = new Size(width, height); yield return Arbiter.Choice( _rrPort.QueryFrame(frameReq), delegate(roborealm.QueryFrameResponse fres) { d = new CamData(); System.IO.MemoryStream ms = new System.IO.MemoryStream(fres.Frame); d.Image = new Bitmap(ms); d.X = x; d.Y = height - y; if (confidence > CONFIDENCE_THRESHOLD) { d.Detected = true; d.Angle = calculateAngle(x, width); //Console.WriteLine("Cone Detected, " + d.Angle); cone_hits++; dataPacket = d; } cam_frames++; //Console.WriteLine(confidence); //if (!moving) //{ // Console.WriteLine("Not moving, sending notification"); //} }, delegate(Fault f) { LogError(LogGroups.Console, "Could not query frame", f); }); if (cam_frames >= FRAMES_MAX) { if (cone_hits >= CONE_HIT_THRESHOLD) { SendNotification<ConeNotification>(_subMgrPort, dataPacket); } else if (d.X != NULL) { SendNotification<ConeNotification>(_subMgrPort, d); } cone_hits = 0; cam_frames = 0; } } //System.Threading.Thread.Sleep(FRAME_PAUSE); }
static void Main(string[] args) { // Note that if you want to do halfmoon or stonehenge trials, place halfmoon and stonehenge in the center of the tank. // Fill their center with a barrier for the first mode. Then take the barrier out and take the mode again. Use the smallest barrier possible (so the fish can get close to the center) and, like in nb trials, get rid of the tracking restriction on barriers var options = new DataflowBlockOptions(); options.BoundedCapacity = 10; var pipe_buffer = new BufferBlock <CamData>(options); Point tank_center = new Point { X = 640, Y = 512, }; int roidim = 80; string camera_id = "img0"; //this is the ID of the NI-IMAQ board in NI MAX. var _session = new ImaqSession(camera_id); bool reuse_background = false; bool drew_barriers = false; bool halfmoon = false; bool stonehenge = false; bool minefield = false; bool minefield_control = false; Console.WriteLine("Enter FishID "); String fishid = Console.ReadLine(); String home_directory = "C:/Users/Deadpool/Desktop/Results/"; String exp_directory = home_directory + fishid; bool exists_already = System.IO.Directory.Exists(exp_directory); if (!exists_already) { System.IO.Directory.CreateDirectory(exp_directory); } else { Console.WriteLine("Directory Already Exists. Overrite? "); String overwrite = Console.ReadLine(); if (overwrite == "y") { System.IO.Directory.CreateDirectory(exp_directory); } else if (overwrite == "c") { } else { Environment.Exit(0); } } Console.WriteLine("Enter Light X Location "); String lightloc_X = Console.ReadLine(); Console.WriteLine("Enter Light Y Location "); String lightloc_Y = Console.ReadLine(); int light_location_X = Convert.ToInt32(lightloc_X) - 25; int light_location_Y = Convert.ToInt32(lightloc_Y); Console.WriteLine("Enter Experiment Type "); String exp_string = Console.ReadLine(); Console.WriteLine("Use old background? "); String reuse = Console.ReadLine(); if (reuse == "y") { reuse_background = true; } if (exp_string == "n" || exp_string == "t" || exp_string == "v") { minefield_control = true; } else if (exp_string == "b") { minefield = true; } String camerawindow = "Camera Window"; CvInvoke.NamedWindow(camerawindow); int frameWidth = 1280; int frameHeight = 1024; uint bufferCount = 3; // Could try changing this to 2 or 100 // Checked and there is no card memory. It makes a buffer on system mem. Tried increasing virtual memory so // HD can be used as RAM. Allocated an additional 32 GB to virtual mem. uint buff_out = 0; int numchannels = 1; MCvScalar gray = new MCvScalar(128, 128, 128); List <ContourProperties> barrierlist = new List <ContourProperties>(); ContourProperties fishcontour = new ContourProperties(); ContourProperties fishcontour_correct = new ContourProperties(); ContourProperties barrier = new ContourProperties(); System.Drawing.Size framesize = new System.Drawing.Size(frameWidth, frameHeight); System.Drawing.Size roi_size = new System.Drawing.Size(roidim, roidim); Mat cvimage = new Mat(framesize, Emgu.CV.CvEnum.DepthType.Cv8U, numchannels); Mat modeimage_barrier_roi = new Mat(roi_size, Emgu.CV.CvEnum.DepthType.Cv8U, numchannels); Mat modeimage = new Mat(framesize, Emgu.CV.CvEnum.DepthType.Cv8U, numchannels); // Mat modeimage_barrier = new Mat(framesize, Emgu.CV.CvEnum.DepthType.Cv8U, numchannels); Mat maxproj_cv = new Mat(framesize, Emgu.CV.CvEnum.DepthType.Cv8U, numchannels); AutoResetEvent event1 = new AutoResetEvent(true); AutoResetEvent event2 = new AutoResetEvent(false); MCvMoments COM = new MCvMoments(); byte[,] data_2D = new byte[frameHeight, frameWidth]; byte[,] data_2D_roi = new byte[roidim, roidim]; byte[,] imagemode_nobarrier = new byte[frameHeight, frameWidth]; byte[,] maxprojimage = new byte[frameHeight, frameWidth]; ImaqBuffer image = null; ImaqBufferCollection buffcollection = _session.CreateBufferCollection((int)bufferCount, ImaqBufferCollectionType.VisionImage); _session.RingSetup(buffcollection, 0, false); _session.Acquisition.AcquireAsync(); RecordAndStim experiment = new RecordAndStim(event1, event2, pipe_buffer, exp_string); experiment.experiment_directory = exp_directory; var stimthread = new Thread(experiment.StartStim); stimthread.Start(); // THIS GRABS THE MODE FOR THE TANK IN GENERAL BEFORE ALIGNMENT if (!experiment.alignment_complete) { CvInvoke.WaitKey(0); imglist = GetImageList(_session, 500, 10); maxprojimage = FindMaxProjection(imglist); maxproj_cv.SetTo(maxprojimage); imglist.Clear(); CvInvoke.Imshow(camerawindow, maxproj_cv); CvInvoke.WaitKey(0); } // IF CAMERA IS NOT YET ALIGNED TO THE PROJECTOR, THIS LOOP FINDS THE LOCATION OF THE CALIBRATION CONTOUR THE EXPERIMENT CLASS IS PLACING ON THE PROJECTOR. experiment.start_align = true; if (!experiment.alignment_complete) { while (!experiment.alignment_complete) { imglist = GetImageList(_session, 500, 10); data_2D = FindMaxProjection(imglist); cvimage.SetTo(data_2D); Console.WriteLine("Finding Largest Contour"); experiment.projcenter_camcoords = LargestContour(cvimage, maxproj_cv, true).center; CvInvoke.Imshow(camerawindow, cvimage); CvInvoke.WaitKey(1); event2.Set(); event1.WaitOne(); } imglist.Clear(); CvInvoke.WaitKey(0); imglist = GetImageList(_session, 500, 10); data_2D = FindMaxProjection(imglist); cvimage.SetTo(data_2D); experiment.tankwidth = LargestContour(cvimage, maxproj_cv, true).height * 2; Console.WriteLine("Width Of Tank Contour"); Console.WriteLine(experiment.tankwidth); CvInvoke.Imshow(camerawindow, cvimage); CvInvoke.WaitKey(0); imglist.Clear(); } // Next, the opposite thread is going to display a black circle that is the same size as the tank. Do a max projection on this // contour in order to measure width of the tank in projector coordinates. // Now you've put the IR filter back over the camera and are ready to do an experiment. // Get mode of image with no barrier present so you can background subtract and find the barriers and fish. imglist.Clear(); if (reuse_background) { modeimage = CvInvoke.Imread(home_directory + "/background_nobar" + exp_string + ".tif", 0); } else { imglist = GetImageList(_session, 5000, 400); imagemode_nobarrier = FindMode(imglist); modeimage.SetTo(imagemode_nobarrier); imglist.Clear(); CvInvoke.Imshow(camerawindow, modeimage); CvInvoke.WaitKey(0); } // Here you have just added barriers to the tank. Now get a new mode that contains the barriers for use in background subtraction to find fish // and for localizing barriers. if (halfmoon || stonehenge || minefield) { imglist = GetImageList(_session, 5000, 400); if (reuse_background) { modeimage_barrier = CvInvoke.Imread(home_directory + "/background_" + exp_string + ".tif", 0); } else { imagemode = FindMode(imglist); modeimage_barrier.SetTo(imagemode); } modeimage_barrier.Save(exp_directory + "/background_" + exp_string + ".tif"); imglist.Clear(); barrierlist = BarrierLocations(modeimage_barrier, modeimage); for (int ind = 0; ind < barrierlist.Count; ind++) { experiment.barrier_position_list.Add(barrierlist[ind].center); experiment.barrier_radius_list.Add(barrierlist[ind].height / 2); } } else if (minefield_control) { modeimage_barrier.SetTo(imagemode_nobarrier); modeimage_barrier.Save(exp_directory + "/background_" + exp_string + ".tif"); barrierlist = GenerateVirtualBarriers(experiment.tankwidth, tank_center.X, tank_center.Y); for (int ind = 0; ind < barrierlist.Count; ind++) { experiment.barrier_position_list.Add(barrierlist[ind].center); experiment.barrier_radius_list.Add(barrierlist[ind].height / 2); } } using (StreamWriter barrierfile = new StreamWriter(exp_directory + "/barrierstruct_" + exp_string + ".txt")) { for (int bar = 0; bar < barrierlist.Count; bar++) { if (bar == 0) { barrierfile.WriteLine(experiment.templatewidth.ToString()); barrierfile.WriteLine(experiment.tankwidth.ToString()); } barrierfile.WriteLine(barrierlist[bar].center.ToString()); barrierfile.WriteLine(barrierlist[bar].height.ToString()); } } CvInvoke.Imshow(camerawindow, modeimage_barrier); CvInvoke.WaitKey(0); if (halfmoon) //THIS IS BECAUSE YOU TAKE THE BARRIER AWAY AFTER IT FINDS THE HOLE. IE FOR HALFMOON TRIALS, YOU FIRST KEEP THE HALFMOON THERE FOR MODEIMAGE, THEN ADD A BARRIER THE SIZE OF THE HOLE FOR FINDING OF THE HOLE OF THE BARRIER. IF YOU WANT TO RUN STONEHENGE OR HALFMOON, DECLARE MINEFIELD_CONTROL AS TRUE, but don't draw barriers. { modeimage_barrier = modeimage; imagemode = imagemode_nobarrier; } // IMAGE ACQUISITION AND FISH FINDING. // Idea is to first acquire the image and turn it into a cvimage matrix. find the fish by finding the largest contour on a background subtracted and thresholded image (LargestContour function). Each time you find the fish, store its coords so you can just search within a small ROI on the next frame. If you lose the fish, go back out to full frame and find it again. Point f_center = new Point(); Mat cv_roi = new Mat(roi_size, Emgu.CV.CvEnum.DepthType.Cv8U, numchannels); image = _session.Acquisition.Extract((uint)0, out buff_out); uint j = buff_out; int experiment_phase = 0; int xycounter = 0; Console.WriteLine("j followed by buff_out"); Console.WriteLine(j.ToString()); Console.WriteLine(buff_out.ToString()); List <Point> coordlist = new List <Point>(); List <int> phasebounds = new List <int>(); while (true) { if (mode_reset.WaitOne(0)) { Console.WriteLine("Clearing Imagelist"); imglist.Clear(); mode_reset.Reset(); } image = _session.Acquisition.Extract(j, out buff_out); try { data_2D = image.ToPixelArray().U8; } catch (NationalInstruments.Vision.VisionException e) { Console.WriteLine(e); continue; } byte[] stim_pixel_readout = new byte[100]; for (int pix = 0; pix < 100; pix++) { stim_pixel_readout[pix] = data_2D[light_location_Y, light_location_X + pix]; } cvimage.SetTo(data_2D); fishcontour = FishContour(cvimage, modeimage_barrier, tank_center, barrierlist, minefield_control); // com makes sure that the head is near the barrier. if (fishcontour.height != 0) { fishcontour_correct = fishcontour; f_center.X = fishcontour.com.X; f_center.Y = fishcontour.com.Y; } if (!experiment.stim_in_progress) { drew_barriers = false; } if (experiment.stim_in_progress && !drew_barriers) { if (halfmoon || stonehenge || minefield || minefield_control) { for (int ind = 0; ind < barrierlist.Count; ind++) { CvInvoke.Circle(cvimage, barrierlist[ind].center, barrierlist[ind].height / 2, new MCvScalar(255, 0, 0), 1); } } Image <Gray, Byte> d2d = cvimage.ToImage <Gray, Byte>(); data_2D_roi = SliceROIImage(d2d, f_center.X, f_center.Y, roidim); drew_barriers = true; } else { data_2D_roi = SliceROI(data_2D, f_center.X, f_center.Y, roidim); } cv_roi = new Mat(roi_size, Emgu.CV.CvEnum.DepthType.Cv8U, numchannels); cv_roi.SetTo(data_2D_roi); CamData camdat = new CamData(cv_roi, f_center, fishcontour_correct, buff_out, j, stim_pixel_readout); pipe_buffer.Post(camdat); if (j % 10 == 0) { xycounter++; coordlist.Add(camdat.fishcoord); if (experiment.experiment_phase > experiment_phase) { experiment_phase = experiment.experiment_phase; phasebounds.Add(xycounter); } } if (j % 100 == 0 && !experiment.stim_in_progress) { // CvInvoke.Circle(cvimage, fishcontour_correct.center, 2,new MCvScalar(255, 255, 0)); CvInvoke.Circle(cvimage, fishcontour_correct.com, 2, new MCvScalar(255, 255, 255)); if (halfmoon || stonehenge || minefield || minefield_control) { for (int ind = 0; ind < barrierlist.Count; ind++) { CvInvoke.Circle(cvimage, barrierlist[ind].center, barrierlist[ind].height / 2, new MCvScalar(255, 0, 0), 3); } } else { CvInvoke.Circle(cvimage, experiment.barrier_center, barrier.height / 2, new MCvScalar(255, 0, 0), 3); } CvInvoke.Imshow(camerawindow, cvimage); CvInvoke.WaitKey(1); if (j % 1000 == 0) { byte[,] mode_frame = new byte[frameHeight, frameWidth]; Buffer.BlockCopy(data_2D, 0, mode_frame, 0, data_2D.Length); imglist.Add(mode_frame); if (imglist.LongCount() == 40) { var modethread = new Thread(() => ModeWrapper(imglist, mode_reset, experiment, exp_directory)); modethread.Start(); } } } if (experiment.experiment_complete) { break; } j = buff_out + 1; } modeimage_barrier.Save(home_directory + "/background_" + exp_string + ".tif"); modeimage.Save(home_directory + "/background_nobar" + exp_string + ".tif"); string experiment_string = exp_directory + "/all_xycoords_" + exp_string + ".txt"; string phasestring = exp_directory + "/phase_" + exp_string + ".txt"; string numframes_gray = exp_directory + "/numframesgray_" + exp_string + ".txt"; string numframes_gray_dark = exp_directory + "/numframesgray_dark.txt"; using (StreamWriter sr = new StreamWriter(experiment_string)) { foreach (Point fishpoint in coordlist) { sr.WriteLine(fishpoint.ToString()); } } using (StreamWriter sr = new StreamWriter(phasestring)) { foreach (int phase in phasebounds) { sr.WriteLine(phase.ToString()); } } using (StreamWriter sr = new StreamWriter(numframes_gray)) { foreach (int ng in experiment.num_grayframes) { sr.WriteLine(ng.ToString()); } } if (exp_string == "b") { using (StreamWriter sr = new StreamWriter(numframes_gray_dark)) { foreach (int ngd in experiment.num_grayframes_d) { sr.WriteLine(ngd.ToString()); } } } }
} // 0x0085A500-0x0085A530 public bool isEqual(CamData left) => default; // 0x0085A530-0x0085A670
public void SetCamData(CamData camData) { moveSpeed = camData.moveSpeed; targetDistance = camData.targetDistance; target = camData.target; }
private void PortCommand(IPlayer player, string command, string[] args) { if (player.IsServer) { player.Reply(Lang("PlayersOnly", player.Id, command)); return; } if (!player.HasPermission(permUse)) { player.Reply(Lang("NotAllowed", player.Id, command)); return; } #if HURTWORLD || REIGNOFKINGS || RUST || THEFOREST RaycastHit hit = new RaycastHit(); #endif #if HURTWORLD EntityReferenceCache entity = (player.Object as PlayerSession).WorldPlayerEntity; CamData simData = entity.GetComponent <PlayerStatManager>().RefCache.PlayerCamera.SimData; CharacterController controller = entity.GetComponent <CharacterController>(); Vector3 point1 = simData.FirePositionWorldSpace + controller.center + Vector3.up * -controller.height * 0.5f; Vector3 point2 = point1 + Vector3.up * controller.height; Vector3 direction = simData.FireRotationWorldSpace * Vector3.forward; if (!Physics.CapsuleCast(point1, point2, controller.radius, direction, out hit, float.MaxValue, layers)) #elif REIGNOFKINGS CodeHatch.Engine.Core.Cache.Entity entity = (player.Object as Player).Entity; if (!Physics.Raycast(entity.Position, entity.GetOrCreate <LookBridge>().Forward, out hit, float.MaxValue, layers)) #elif RUST BasePlayer basePlayer = player.Object as BasePlayer; if (basePlayer != null && !Physics.Raycast(basePlayer.eyes.HeadRay(), out hit, float.MaxValue, layers)) #elif THEFOREST BoltEntity entity = player.Object as BoltEntity; Physics.Raycast(entity.transform.position, entity.transform.rotation * Vector3.forward, out hit, float.MaxValue, layers); if (hit.collider != null && !hit.collider.CompareTag("TerrainMain") && !hit.collider.CompareTag("structure")) #endif { player.Reply(Lang("NoDestination", player.Id)); return; } #if HURTWORLD Vector3 safePos = simData.FirePositionWorldSpace + direction * hit.distance; GenericPosition destination = new GenericPosition(safePos.x, safePos.y, safePos.z); #elif REIGNOFKINGS || RUST || THEFOREST GenericPosition destination = new GenericPosition(hit.point.x, hit.point.y, hit.point.z); #else GenericPosition destination = new GenericPosition(); #endif if (!IsValidMapCoordinates(destination.X, destination.Y, destination.Z)) { player.Reply(Lang("OutOfBounds", player.Id)); return; } #if DEBUG player.Reply($"Current position: {player.Position()}"); player.Reply($"Destination: {destination}"); #endif protection.Add(player.Id); // TODO: Remove to reset before adding if using timer? player.Teleport(destination.X, destination.Y, destination.Z); }