Exemplo n.º 1
0
 public string GetFieldValue(PointField field)
 {
     switch (field)
     {
         case PointField.Id: return this.Id;
         case PointField.Coord1: return this.Coord1.Text;
         case PointField.Coord2: return this.Coord2.Text;
         case PointField.Coord3: return this.Coord3.Text;
         case PointField.Code: return this.Code;
         default:
             throw new ArgumentException("Unsupported field: " + field.ToString());
     }
 }
Exemplo n.º 2
0
 public void SetFieldValue(PointField field, string value)
 {
     switch (field)
     {
         case PointField.Id:
             this.Id = value;
             break;
         case PointField.Coord1:
             this.Coord1.Text = value;
             break;
         case PointField.Coord2:
             this.Coord2.Text = value;
             break;
         case PointField.Coord3:
             this.Coord3.Text = value;
             break;
         case PointField.Code:
             this.Code = value;
             break;
         default:
             throw new ArgumentException("Unsupported field: " + field.ToString());
     }
 }
Exemplo n.º 3
0
 public virtual string GetFieldName(PointField field)
 {
     return field.ToString();
 }
Exemplo n.º 4
0
 public override string GetFieldName(PointField field)
 {
     switch (field)
     {
         case PointField.Coord1: return "ɸ";
         case PointField.Coord2: return "λ";
         case PointField.Coord3: return "H";
         default: return base.GetFieldName(field);
     }
 }
Exemplo n.º 5
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            BGEditorUtility.HelpBox("Curve UI is disabled in settings. All handles are disabled too.", MessageType.Warning, !settings.ShowCurve);

            BGEditorUtility.Assign(ref customUi, () => new TableUi("Custom fields", new[] { "#", "Name", "Type", "?", "Delete" }, new[] { 5, 40, 40, 5, 10 }));
            BGEditorUtility.Assign(ref systemUi, () => new TableUi("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }));

            BGEditorUtility.Assign(ref systemFields, () => new[]
            {
                (SystemField) new SystemFieldPosition(settings),
                new SystemFieldControls(settings),
                new SystemFieldControlsType(settings),
                new SystemFieldTransform(settings),
            });

            var fields    = Curve.Fields;
            var hasFields = fields != null && fields.Length > 0;

            if (hasFields && (customFields == null || customFields.Length != fields.Length) || !hasFields && customFields != null && customFields.Length != fields.Length)
            {
                customFields = new PointField[fields.Length];

                for (var i = 0; i < fields.Length; i++)
                {
                    customFields[i] = new PointField(fields[i], i, deleteIcon);
                }
            }


            //warnings
            BGEditorUtility.HelpBox("All handles for positions are disabled.", MessageType.Warning, settings.HandlesSettings.Disabled);
            BGEditorUtility.HelpBox("All handles for controls are disabled.", MessageType.Warning, settings.ControlHandlesSettings.Disabled);

            //====================== Custom fields
            customUi.Init();
            //add row
            customUi.NextColumn(rect => EditorGUI.LabelField(rect, "Name"), 12);
            customUi.NextColumn(rect => newFieldName = EditorGUI.TextField(rect, newFieldName), 28);
            customUi.NextColumn(rect => BGEditorUtility.PopupField(rect, newFieldType, @enum => newFieldType = (BGCurvePointField.TypeEnum)@enum), 50);
            customUi.NextColumn(rect =>
            {
                if (!GUI.Button(rect, addIcon))
                {
                    return;
                }

                if (NameHasError(Curve, newFieldName))
                {
                    return;
                }

                BGPrivateField.Invoke(Curve, BGCurve.MethodAddField, newFieldName, newFieldType, (Func <BGCurvePointField>)(() => Undo.AddComponent <BGCurvePointField>(Curve.gameObject)));
                GUIUtility.hotControl = 0;
                GUIUtility.ExitGUI();
            }, 10);

            customUi.NextRow();
            var warning = "";

            if (customFields == null || customFields.Length == 0)
            {
                customUi.NextRow("Name should be 16 chars max, starts with a letter and contain English chars and numbers only.");
            }
            else
            {
                //header
                customUi.DrawHeaders();

                //fields
                var quaternionWithHandlesCount = 0;

                BGEditorUtility.ChangeCheck(() =>
                {
                    foreach (var customField in customFields)
                    {
                        if (customField.Field.Type == BGCurvePointField.TypeEnum.Quaternion && BGPrivateField.GetHandlesType(customField.Field) != 0)
                        {
                            quaternionWithHandlesCount++;
                        }
                        customField.Ui(customUi);
                    }
                }, SceneView.RepaintAll);

                if (quaternionWithHandlesCount > 1)
                {
                    warning = "You have more than one Quaternion field with Handles enabled. Only first field will be shown in Scene View";
                }
                //footer
                customUi.NextRow("?- Show in Points Menu/Scene View");
            }
            //inform layout manager
            GUILayoutUtility.GetRect(customUi.Width, customUi.Height);

            BGEditorUtility.HelpBox(warning, MessageType.Warning, warning.Length > 0);

            //====================== System fields
            systemUi.Init();

            BGEditorUtility.ChangeCheck(() =>
            {
                foreach (var field in systemFields)
                {
                    field.Ui(systemUi);
                }
            }, SceneView.RepaintAll);

            //inform layout manager
            GUILayoutUtility.GetRect(systemUi.Width, systemUi.Height);
            GUILayout.Space(4);
        }
        protected override void ReceiveMessage(PointCloud2 message)
        {
            uint x_offset     = 0;
            uint y_offset     = 4;
            uint z_offset     = 8;
            uint color_offset = 16;

            bool colorEnabled = false;

            for (int j = 0; j < message.fields.Length; j++)
            {
                PointField field = message.fields[j];
                if (field.name == "x")
                {
                    x_offset = field.offset;
                }
                else if (field.name == "y")
                {
                    y_offset = field.offset;
                }
                else if (field.name == "z")
                {
                    z_offset = field.offset;
                }
                else if (field.name == "rgb")
                {
                    color_offset = field.offset;
                    colorEnabled = true;
                }
            }

            size = message.data.GetLength(0);
            int i = 0;

            byteArray = new byte[size];
            foreach (byte temp in message.data)
            {
                byteArray[i] = temp;  //byte型を取得
                i++;
            }
            point_step = message.point_step;
            size       = size / (int)point_step;

            // PointCloud2生データをUnity座標系の3次元点群に変換
            Vector3[] pcl    = new Vector3[size];
            Color[]   colors = new Color[size];

            for (int n = 0; n < size; n++)
            {
                // yte型をfloatに変換
                int x_posi     = n * (int)point_step + (int)x_offset;
                int y_posi     = n * (int)point_step + (int)y_offset;
                int z_posi     = n * (int)point_step + (int)z_offset;
                int color_posi = n * (int)point_step + (int)color_offset;

                float x = BitConverter.ToSingle(byteArray, x_posi);
                float y = BitConverter.ToSingle(byteArray, y_posi);
                float z = BitConverter.ToSingle(byteArray, z_posi);

                Vector3 RosPosition   = new Vector3(x, y, z);
                Vector3 UnityPosition = CoordinateConvert.RosToUnity(RosPosition);
                pcl[n] = UnityPosition;

                //
                if (colorEnabled)
                {
                    byte b = byteArray[color_posi];
                    byte g = byteArray[color_posi + 1];
                    byte r = byteArray[color_posi + 2];
                    colors[n] = new Color(r / 255f, g / 255f, b / 255f);
                }
            }
            this.pointCloud = pcl;
            this.rgbColors  = colorEnabled ? colors : null;

            NewPointCloudListeners.Invoke(pointCloud, rgbColors);
        }