<commit_before>/*=========================================================================

  Program:   OpenIGTLink Library
  Module:    $HeadURL: http://osfe.org/OpenIGTLink/Source/org/medcare/igtl/messages/ImageMessage.java $
  Language:  java
  Date:      $Date: 2010-18-14 10:37:44 +0200 (ven., 13 nov. 2009) $
  Version:   $Revision: 0ab$

  Copyright (c) Absynt Technologies Ltd. All rights reserved.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

package org.medcare.igtl.messages;

import org.medcare.igtl.util.BytesArray;
import org.medcare.igtl.util.Header;
//import com.neuronrobotics.sdk.common.ByteList;

/**
 *** This class create an Transform object from bytes received or help to generate
 * bytes to send from it
 * 
 * @author <NAME>
 * 
 */
public class TransformMessage extends OpenIGTMessage {

        public static int IGTL_TRANSFORM_SIZE = 48;

        private double matrix[][] = new double[4][4];
        private double origin[] = new double[3]; // float 32bits
        // PX_pixels float 32bits origin[0] (matrix[0][3])
        // PY_pixels float 32bits origin[1] (matrix[1][3])
        // PZ_pixels float 32bits origin[2] (matrix[2][3])
        private double normals[][] = new double[3][3];
        private double t[] = new double[3]; // float 32bits
        // TX_pixels float 32bits t[0] (matrix[0][0])
        // TY_pixels float 32bits t[1] (matrix[1][0])
        // TZ_pixels float 32bits t[2] (matrix[2][0])
        private double s[] = new double[3]; // float 32bits
        // SX_pixels float 32bits s[0] (matrix[0][1])
        // SY_pixels float 32bits s[1] (matrix[1][1])
        // SZ_pixels float 32bits s[2] (matrix[2][1])
        private double n[] = new double[3]; // float 32bits
        // NX_pixels // float 32bits n[0] (matrix[0][2])
        // NY_pixels // float 32bits n[1] (matrix[1][2])
        // NZ_pixels // float 32bits n[2] (matrix[2][2])
        private byte[] transform_data;

        /**
         *** Constructor to be used to create message to send them with this
         * constructor you must use method SetImageHeader, then CreateBody and then
         * getBytes to send them
         *** 
         * @param deviceName
         *            Device Name
         **/
        public TransformMessage(String deviceName) {
                super(deviceName);
        }

        /**
         *** Constructor to be used to create message from received data
         * 
         * @param header
         * @param body
         * @throws Exception 
         */
        public TransformMessage(Header header, byte body[]) throws Exception {
                super(header, body);
                }

        /**
         *** To create body from body array
         * 
         *** 
         * @return true if unpacking is ok
         */
        @Override
        public boolean UnpackBody() throws Exception {
        		//System.out.println("Unpacking Transform Body..");
                transform_data = new byte[IGTL_TRANSFORM_SIZE];
                System.arraycopy(body, 0, transform_data, 0, IGTL_TRANSFORM_SIZE);
                SetTransformData(transform_data);
                
               // System.out.println("Unpacking Transform Body OK!");
                return true;
        }

        /**
         *** To create body from image_header and image_data
         *  SetTransformData must have called first
         * 
         *** 
         * @return the bytes array containing the body
         */
        @Override
        public byte[] PackBody() {
                body = new byte[transform_data.length];
                System.arraycopy(transform_data, 0, body, 0, transform_data.length);
                header = new Header(VERSION, "TRANSFORM", deviceName, body);
                return getBytes();
        }

        /**
         *** To create transform_data from image characteristics and to get the byte array to send
         * @param origin
         * @param normals
         *** 
         * @return the bytes array created from the value
         */
        public byte[] SetTransformData(double origin[], double normals[][]) {
                bytesArray = new BytesArray();
                                           
                // the 3x3 rotation matrix
                SetNormals(normals);
                for (int i = 0; i < 3; i++)
                        for (int j = 0; j < 3; j++)
                                bytesArray.putDouble(normals[i][j], 4);
                SetMatrix(origin, normals);
                               
             // the position vector
                SetOrigin(origin);
                SetNormals(normals);
                bytesArray.putDouble(origin[0], 4);
                bytesArray.putDouble(origin[1], 4);
                bytesArray.putDouble(origin[2], 4);
                
                transform_data = bytesArray.getBytes();
                
             //   System.out.println("++++++++++++++++++++++++++++++++++++++");
                return transform_data;
        }

        /**
         *** To extract image characteristics from transform_data byte array
         * @param transform_data
         */
        public void SetTransformData(byte transform_data[]) {
        		//System.out.println("Setting Transform Data: "+new ByteList(transform_data));
                this.transform_data = transform_data;
                bytesArray = new BytesArray();
                bytesArray.putBytes(transform_data);
                
                // the 3x3 rotation matrix
                normals = new double[3][3];
                for (int i = 0; i < 3; i++){
                        for (int j = 0; j < 3; j++){
                                normals[i][j] = bytesArray.getDouble(4); // float32<commit_msg>Packet packing fix<commit_after>/*=========================================================================

  Program:   OpenIGTLink Library
  Module:    $HeadURL: http://osfe.org/OpenIGTLink/Source/org/medcare/igtl/messages/ImageMessage.java $
  Language:  java
  Date:      $Date: 2010-18-14 10:37:44 +0200 (ven., 13 nov. 2009) $
  Version:   $Revision: 0ab$

  Copyright (c) Absynt Technologies Ltd. All rights reserved.

  This software is distributed WITHOUT ANY WARRANTY; without even
  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

package org.medcare.igtl.messages;

import org.medcare.igtl.util.BytesArray;
import org.medcare.igtl.util.Header;
//import com.neuronrobotics.sdk.common.ByteList;

/**
 *** This class create an Transform object from bytes received or help to generate
 * bytes to send from it
 * 
 * @author <NAME>
 * 
 */
public class TransformMessage extends OpenIGTMessage {

        public static int IGTL_TRANSFORM_SIZE = 48;

        private double matrix[][] = new double[4][4];
        private double origin[] = new double[3]; // float 32bits
        // PX_pixels float 32bits origin[0] (matrix[0][3])
        // PY_pixels float 32bits origin[1] (matrix[1][3])
        // PZ_pixels float 32bits origin[2] (matrix[2][3])
        private double normals[][] = new double[3][3];
        private double t[] = new double[3]; // float 32bits
        // TX_pixels float 32bits t[0] (matrix[0][0])
        // TY_pixels float 32bits t[1] (matrix[1][0])
        // TZ_pixels float 32bits t[2] (matrix[2][0])
        private double s[] = new double[3]; // float 32bits
        // SX_pixels float 32bits s[0] (matrix[0][1])
        // SY_pixels float 32bits s[1] (matrix[1][1])
        // SZ_pixels float 32bits s[2] (matrix[2][1])
        private double n[] = new double[3]; // float 32bits
        // NX_pixels // float 32bits n[0] (matrix[0][2])
        // NY_pixels // float 32bits n[1] (matrix[1][2])
        // NZ_pixels // float 32bits n[2] (matrix[2][2])
        private byte[] transform_data;

        /**
         *** Constructor to be used to create message to send them with this
         * constructor you must use method SetImageHeader, then CreateBody and then
         * getBytes to send them
         *** 
         * @param deviceName
         *            Device Name
         **/
        public TransformMessage(String deviceName) {
                super(deviceName);
        }

        /**
         *** Constructor to be used to create message from received data
         * 
         * @param header
         * @param body
         * @throws Exception 
         */
        public TransformMessage(Header header, byte body[]) throws Exception {
                super(header, body);
                }

        public TransformMessage(String deviceName,double[] positionAray, double[][] rotationMatrix) {
        	super(deviceName);
        	SetTransformData(positionAray, rotationMatrix);
		}

		/**
         *** To create body from body array
         * 
         *** 
         * @return true if unpacking is ok
         */
        @Override
        public boolean UnpackBody() throws Exception {
        		//System.out.println("Unpacking Transform Body..");
                transform_data = new byte[IGTL_TRANSFORM_SIZE];
                System.arraycopy(body, 0, transform_data, 0, IGTL_TRANSFORM_SIZE);
                SetTransformData(transform_data);
                
               // System.out.println("Unpacking Transform Body OK!");
                return true;
        }

        /**
         *** To create body from image_header and image_data
         *  SetTransformData must have called first
         * 
         *** 
         * @return the bytes array containing the body
         */
        @Override
        public byte[] PackBody() {
                body = new byte[transform_data.length];
                System.arraycopy(transform_data, 0, body, 0, transform_data.length);
                header = new Header(VERSION, "TRANSFORM", deviceName, body);
                return getBytes();
        }

        /**
         *** To create transform_data from image characteristics and to get the byte array to send
         * @param origin
         * @param normals
         *** 
         * @return the bytes array created from the value
         */
        public byte[] SetTransformData(double origin[], double normals[][]) {
                bytesArray = new BytesArray();
                                           
                // the 3x3 rotation matrix
                SetNormals(normals);
                for (int i = 0; i < 3; i++)
                        for (int j = 0; j < 3; j++)
                                bytesArray.putDouble(normals[i][j], 4);
                SetMatrix(origin, normals);
                               
             // the position vector
                SetOrigin(origin);
                SetNormals(normals);
                bytesArray.putDouble(origin[0], 4);
                bytesArray.putDouble(origin[1], 4);
                bytesArray.putDouble(origin[2], 4);
                
                transform_data = bytesArray.getBytes();
                PackBody();
             //   System.out.println("++++++++++++++++++++++++++++++++++++++");
                return transform_data;
        }

        /**
         *** To extract image characteristics from transform_data byte array
         * @param transform_data
         */
        public void SetTransformData(byte transform_data[]) {
        		//System.out.println("Setting Transform Data: "+new ByteList(transform_data));
                this.transform_data = transform_data;
                bytesArray = new BytesArray();
                bytesArray.putBytes(transform_data);
                
                // the 3x3 rotation matrix
                normals = new double[3][3];
                for (int i = 0; i < 3; i++){
                        for (int j = 0; j < 3; j++){
                                normals[i][j] = bytesArray.getDouble(4); // float32
{'fraction_non_alphanumeric': 0.13293846660085554, 'fraction_numerical': 0.021553142481079302, 'mean_word_length': 1.8043829296424452, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1219102', 'n_tokens_mistral': 3401, 'n_tokens_neox': 3103, 'n_words': 917}