public OptiTrackCamera(OptiTrackCamera newCamera)
        {
            cameraNumber = newCamera.CameraNumber;
            x            = newCamera.xCoordinate;
            y            = newCamera.yCoordinate;
            z            = newCamera.zCoordinate;

            for (int i = 0; i < 9; i++)
            {
                rotationMatrix[i] = newCamera.rotationMatrix[i];
            }
        }
Beispiel #2
0
        public static void UpdateCameraInList(OptiTrackCamera camera)
        {
            listOfCameras[camera.CameraNumber].CameraNumber = camera.CameraNumber;
            listOfCameras[camera.CameraNumber].xCoordinate  = camera.xCoordinate;
            listOfCameras[camera.CameraNumber].yCoordinate  = camera.yCoordinate;
            listOfCameras[camera.CameraNumber].zCoordinate  = camera.zCoordinate;

            for (int i = 0; i < 9; i++)
            {
                listOfCameras[camera.CameraNumber].RotationMatrix[i] = camera.RotationMatrix[i];
            }
        }
        public OptiTrackCamera(OptiTrackCamera newCamera)
        {
            cameraNumber = newCamera.CameraNumber;
            x = newCamera.xCoordinate;
            y = newCamera.yCoordinate;
            z = newCamera.zCoordinate;

            for (int i = 0; i < 9; i++)
            {
                rotationMatrix[i] = newCamera.rotationMatrix[i];
            }

        }
        public static void UpdateCameraInList(OptiTrackCamera camera)
        {

            listOfCameras[camera.CameraNumber].CameraNumber = camera.CameraNumber;
            listOfCameras[camera.CameraNumber].xCoordinate = camera.xCoordinate;
            listOfCameras[camera.CameraNumber].yCoordinate = camera.yCoordinate;
            listOfCameras[camera.CameraNumber].zCoordinate = camera.zCoordinate;

            for (int i = 0; i < 9; i++)
            {
                listOfCameras[camera.CameraNumber].RotationMatrix[i] = camera.RotationMatrix[i];
            }

        }
Beispiel #5
0
        public static void AddCamera(OptiTrackCamera camera)
        {
            bool cameraFound = false;

            foreach (OptiTrackCamera currentCamera in listOfCameras)
            {
                if (camera.CameraNumber == currentCamera.CameraNumber)
                {
                    cameraFound = true;
                    if (currentCamera.CameraNumber != -1)
                    {
                        UpdateCameraInList(currentCamera);
                    }
                }
            }

            if (cameraFound == false)
            {
                listOfCameras.Add(new OptiTrackCamera(camera));
            }
        }
Beispiel #6
0
        public static void UpdateCameraList()
        {
            int             numberOfCameras = pointcloud.CameraCount;
            OptiTrackCamera camera          = new OptiTrackCamera();

            double[] tempRotationMatrix = new double[9];

            for (int i = 0; i < numberOfCameras; i++)
            {
                camera.CameraNumber = i;
                camera.xCoordinate  = pointcloud.GetCamera(i).X * 1000;
                camera.yCoordinate  = pointcloud.GetCamera(i).Y * 1000;
                camera.zCoordinate  = pointcloud.GetCamera(i).Z * 1000;

                for (int j = 0; j < 9; j++)
                {
                    tempRotationMatrix[j] = pointcloud.GetCamera(i).GetRotationMatrix(j);
                }
                camera.RotationMatrix = tempRotationMatrix;
                OptitrackCameraList.AddCamera(camera);
            }
        }
        public static void AddCamera(OptiTrackCamera camera)
        {
            bool cameraFound = false;

            foreach (OptiTrackCamera currentCamera in listOfCameras)
            {
                if (camera.CameraNumber == currentCamera.CameraNumber)
                {
                    cameraFound = true;
                    if (currentCamera.CameraNumber != -1)
                    {
                        UpdateCameraInList(currentCamera);
                    }
                }

              
            }

            if (cameraFound == false)
            {
                listOfCameras.Add(new OptiTrackCamera(camera));
            }
        }
Beispiel #8
0
        /// <summary>
        /// Transmits a camera to the current tcpClient
        /// </summary>
        /// <param name="camera"></param>
        public void Transmit(OptiTrackCamera camera)
        {
            lock (m_lock)
            {
                MotionCapture.CoordinatesAvailableEvent -= new MotionCapture.CoordinatesAvailableHandler(MotionCapture_CoordinatesAvailableEvent);
                //if there is a client connection
                if (clientConnectionList.Count != 0)
                {
                    //and if the client is connected
                    if (clientConnectionList[0].Connected == true)
                    {
                        foreach (TcpClient singleClientConnection in clientConnectionList)
                        {
                            BinaryWriter binaryWriter = new BinaryWriter(new BufferedStream(singleClientConnection.GetStream()));

                            binaryWriter.Write('C');

                            binaryWriter.Write(camera.CameraNumber);
                            binaryWriter.Write(camera.xCoordinate);
                            binaryWriter.Write(camera.yCoordinate);
                            binaryWriter.Write(camera.zCoordinate);

                            double[] rotationMatrixBuffer = camera.RotationMatrix;
                            System.Diagnostics.Debug.WriteLine("Camera rotation matrix: ");
                            for (int i = 0; i < 9; i++)
                            {
                                System.Diagnostics.Debug.WriteLine(rotationMatrixBuffer[i].ToString());
                                binaryWriter.Write(rotationMatrixBuffer[i]);
                            }

                            binaryWriter.Flush();
                        }
                    }
                }
                MotionCapture.CoordinatesAvailableEvent += new MotionCapture.CoordinatesAvailableHandler(MotionCapture_CoordinatesAvailableEvent);
            }
        }
        public static void UpdateCameraList()
        {
            int numberOfCameras = pointcloud.CameraCount;
            OptiTrackCamera camera = new OptiTrackCamera();
            double[] tempRotationMatrix = new double[9];

            for (int i = 0; i < numberOfCameras; i++)
            {
                camera.CameraNumber = i;
                camera.xCoordinate = pointcloud.GetCamera(i).X * 1000;
                camera.yCoordinate = pointcloud.GetCamera(i).Y * 1000;
                camera.zCoordinate = pointcloud.GetCamera(i).Z * 1000;

                for (int j = 0; j < 9; j++)
                {
                    tempRotationMatrix[j] = pointcloud.GetCamera(i).GetRotationMatrix(j);
                }
                camera.RotationMatrix = tempRotationMatrix;
                OptitrackCameraList.AddCamera(camera);

            }

            
        }
Beispiel #10
0
 private void OptitrackCameraList_TransmitCameraEvent(OptiTrackCamera camera)
 {
     Transmit(camera);
 }
        private static void HandleDataFromServer(object client)
        {
            TcpClient serverConnection = (TcpClient)client;
            //NetworkStream serverStream = serverConnection.GetStream();

            Marker receivedMarker = new Marker();
            OptiTrackCamera receivedCamera = new OptiTrackCamera();

            BinaryReader binaryReader = new BinaryReader(new BufferedStream(serverConnection.GetStream()));

            int bytesRead;
            while (true)
            {
                bytesRead = 0;
                bool readTimestamp = false;
                try
                {

                    //blocks until a client sends a message

                    char messageType = binaryReader.ReadChar();
                    bytesRead = 1;

                    switch (messageType)
                    {
                        case 'M': 
                            receivedMarker.MarkerId = binaryReader.ReadInt32();
                            
                            //if have been sent End of Frame indication
                            //TimeStamp field of End of Frame Indicator contains number of markers in the frame
                            //ie. receivedMarker.TimeStamp = number of markers in list
                            if (receivedMarker.MarkerId == -2147483648)
                            {
                                receivedMarker.TimeStamp = binaryReader.ReadInt32();
                                readTimestamp = true;
                                MarkerList.RemoveExcessMarkersFromList(receivedMarker.TimeStamp);

                                //MarkerList.MarkerBinList();

                                if (WholeFrameReceivedEvent != null)
                                {
                                    WholeFrameReceivedEvent();
                                }
                            }

                            if (readTimestamp == false)
                            {
                                receivedMarker.TimeStamp = binaryReader.ReadInt32();
                            }
                            
                            receivedMarker.xCoordinate = binaryReader.ReadDouble();
                            receivedMarker.yCoordinate = binaryReader.ReadDouble();
                            receivedMarker.zCoordinate = binaryReader.ReadDouble();

                            bytesRead = 36;

                            if (receivedMarker.MarkerId != -2147483648)
                            {
                                MarkerList.AddMarker(receivedMarker);
                            }

                            break;

                        case 'C':
                            receivedCamera.CameraNumber = binaryReader.ReadInt32();
                            receivedCamera.xCoordinate = binaryReader.ReadDouble();
                            receivedCamera.yCoordinate = binaryReader.ReadDouble();
                            receivedCamera.zCoordinate = binaryReader.ReadDouble();

                            double[] rotationMatrixBuffer = new double[9];

                            for (int i = 0; i < 9; i++)
                            {
                                rotationMatrixBuffer[i] = binaryReader.ReadDouble();
                            }
                            receivedCamera.RotationMatrix = rotationMatrixBuffer;

                            bytesRead = 108;

                            OptitrackCameraList.AddCamera(receivedCamera);

                            break;

                        case 'T':
                            if (AvatarSpeedChangedEvent != null)
                            {
                                AvatarSpeedChangedEvent((float)binaryReader.ReadDouble());
                                bytesRead = 8;
                            }
                            else
                            {
                                binaryReader.ReadDouble();
                                bytesRead = 8;
                            }
                            break;

                        default:
                            System.Diagnostics.Debug.WriteLine("A transmit error has occured. " + messageType.ToString() + " recieved");
                            bytesRead = 5;
                            break;
                    }


                }
                catch (System.IO.IOException)
                {
                    // a socket error has occured
                    System.Diagnostics.Debug.WriteLine("Socket error has occured in TCPServer.HandleClientComm");
                    break;
                }
                if (bytesRead == 0)
                {
                    // the client has disconnected from the server
                    System.Diagnostics.Debug.WriteLine("The client has disconnected from the server");
                    break;
                }

                //else message has been successfully recieved

                //OptitrackCommandParser commandParser = new OptitrackCommandParser();

                //commandParser.handleCommand(recievedCommand[0]);
            }
        }
 private void OptitrackCameraList_TransmitCameraEvent(OptiTrackCamera camera)
 {
     Transmit(camera);
 }
        /// <summary>
        /// Transmits a camera to the current tcpClient
        /// </summary>
        /// <param name="camera"></param>
        public void Transmit(OptiTrackCamera camera)
        {
            lock (m_lock)
            {
                MotionCapture.CoordinatesAvailableEvent -= new MotionCapture.CoordinatesAvailableHandler(MotionCapture_CoordinatesAvailableEvent);
                //if there is a client connection
                if (clientConnectionList.Count != 0)
                {
                    //and if the client is connected
                    if (clientConnectionList[0].Connected == true)
                    {

                        foreach (TcpClient singleClientConnection in clientConnectionList)
                        {
                            BinaryWriter binaryWriter = new BinaryWriter(new BufferedStream(singleClientConnection.GetStream()));

                            binaryWriter.Write('C');

                            binaryWriter.Write(camera.CameraNumber);
                            binaryWriter.Write(camera.xCoordinate);
                            binaryWriter.Write(camera.yCoordinate);
                            binaryWriter.Write(camera.zCoordinate);

                            double[] rotationMatrixBuffer = camera.RotationMatrix;
                            System.Diagnostics.Debug.WriteLine("Camera rotation matrix: ");
                            for (int i = 0; i < 9; i++)
                            {
                                System.Diagnostics.Debug.WriteLine(rotationMatrixBuffer[i].ToString());
                                binaryWriter.Write(rotationMatrixBuffer[i]);
                            }

                            binaryWriter.Flush();
                        }
                    }
                }
                MotionCapture.CoordinatesAvailableEvent += new MotionCapture.CoordinatesAvailableHandler(MotionCapture_CoordinatesAvailableEvent);
            }
        }