コード例 #1
0
        private void HandlerViewer3DArrowUpPressed(object sender, EventArgs e)
        {
            if (currentSliceIndex == 0)
            {
                return;
            }
            double previousZ = face.HorizontalBezierCurveList[currentSliceIndex].SplineList[0].ControlPointList[0].CoordinateList[2];

            currentSliceIndex--;
            double currentZ = face.HorizontalBezierCurveList[currentSliceIndex].SplineList[0].ControlPointList[0].CoordinateList[2];

            slice.Move(0, 0, currentZ - previousZ); // Translate(0, 0, currentZ - previousZ);
            viewer3D.Invalidate();
            currentSliceLabel.Text    = "Current slice: " + currentSliceIndex.ToString() + " of " + (face.HorizontalBezierCurveList.Count - 1).ToString();
            zLabel.Text               = "z = " + face.HorizontalBezierCurveList[currentSliceIndex].SplineList[0].ControlPointList[0].CoordinateList[2].ToString("0.0000");
            insertSliceButton.Enabled = true;
            moveDownButton.Enabled    = true;
            if (currentSliceIndex == 0)
            {
                moveUpButton.Enabled      = false;
                removeSliceButton.Enabled = false;
            }
            else
            {
                if (face.HorizontalBezierCurveList.Count >= 4)
                {
                    removeSliceButton.Enabled = true;
                }
            }
            bezierCurveViewer.SetBezierCurve(face.HorizontalBezierCurveList[currentSliceIndex]);
        }
コード例 #2
0
        public void Initialize()
        {
            ClearControls();
            this.slice      = new Rectangle3D();
            this.slice.Name = "SlicePlane";
            // First tool strip: Slice position.
            slicePositionToolStrip         = new ToolStrip();
            slicePositionToolStrip.Dock    = DockStyle.Top;
            currentSliceLabel              = new ToolStripLabel();
            currentSliceLabel.DisplayStyle = ToolStripItemDisplayStyle.Text; // NOTE: The text for this label is set below.
            slicePositionToolStrip.Items.Add(currentSliceLabel);
            zLabel = new ToolStripLabel();
            zLabel.DisplayStyle = ToolStripItemDisplayStyle.Text; // NOTE: The text for this label is set below.
            slicePositionToolStrip.Items.Add(zLabel);
            ToolStripSeparator separator1 = new ToolStripSeparator();

            slicePositionToolStrip.Items.Add(separator1);
            moveUpButton              = new ToolStripButton();
            moveUpButton.Click       += new EventHandler(HandleMoveUpButtonClick);
            moveUpButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
            moveUpButton.Text         = "Move up";
            slicePositionToolStrip.Items.Add(moveUpButton);
            moveDownButton              = new ToolStripButton();
            moveDownButton.Click       += new EventHandler(HandleMoveDownButtonClick);
            moveDownButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
            moveDownButton.Text         = "Move down";
            slicePositionToolStrip.Items.Add(moveDownButton);
            zStepLabel = new ToolStripLabel();
            zStepLabel.DisplayStyle = ToolStripItemDisplayStyle.Text;
            zStepLabel.Text         = "Step: ";
            slicePositionToolStrip.Items.Add(zStepLabel);
            zStepTextBox = new ToolStripTextBox();
            zStepTextBox.DisplayStyle = ToolStripItemDisplayStyle.Text;
            zStepTextBox.Text         = "0.01";
            zStepTextBox.AutoSize     = false;
            zStepTextBox.Width        = 50;
            slicePositionToolStrip.Items.Add(zStepTextBox);
            ToolStripSeparator separator2 = new ToolStripSeparator();

            slicePositionToolStrip.Items.Add(separator2);

            insertSliceButton              = new ToolStripButton();
            insertSliceButton.Click       += new EventHandler(HandleInsertSliceButtonClick);
            insertSliceButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
            insertSliceButton.Text         = "Insert slice";
            slicePositionToolStrip.Items.Add(insertSliceButton);
            removeSliceButton              = new ToolStripButton();
            removeSliceButton.Enabled      = false;
            removeSliceButton.Click       += new EventHandler(HandleRemoveSliceButtonClick);
            removeSliceButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
            removeSliceButton.Text         = "Remove slice";
            slicePositionToolStrip.Items.Add(removeSliceButton);

            // Second tool strip: Slice editing
            sliceEditingToolStrip      = new ToolStrip();
            sliceEditingToolStrip.Dock = DockStyle.Top;
            moveButton = new ToolStripButton();
            moveButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            moveButton.Text            = "Move";
            moveButton.CheckOnClick    = true;
            moveButton.Checked         = false;
            moveButton.CheckedChanged += new EventHandler(HandleMoveButtonCheckedChanged);
            sliceEditingToolStrip.Items.Add(moveButton);
            expandButton = new ToolStripButton();
            expandButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            expandButton.Text            = "Expand";
            expandButton.CheckOnClick    = true;
            expandButton.Checked         = false;
            expandButton.CheckedChanged += new EventHandler(HandleExpandButtonCheckedChanged);
            sliceEditingToolStrip.Items.Add(expandButton);
            alignXButton              = new ToolStripButton();
            alignXButton.Enabled      = false;
            alignXButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
            alignXButton.Text         = "Align X";
            alignXButton.Click       += new EventHandler(HandleAlignXButtonClick);
            sliceEditingToolStrip.Items.Add(alignXButton);
            alignYButton              = new ToolStripButton();
            alignYButton.Enabled      = false;
            alignYButton.DisplayStyle = ToolStripItemDisplayStyle.Text;
            alignYButton.Text         = "Align Y";
            alignYButton.Click       += new EventHandler(HandleAlignYButtonClick);
            sliceEditingToolStrip.Items.Add(alignYButton);

            // Third tool strip: Rendering tool strip
            renderingToolStrip                  = new ToolStrip();
            renderingToolStrip.Dock             = DockStyle.Top;
            showWireframeButton                 = new ToolStripButton();
            showWireframeButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            showWireframeButton.Text            = "Show wireframe";
            showWireframeButton.CheckOnClick    = true;
            showWireframeButton.Checked         = false;
            showWireframeButton.CheckedChanged += new EventHandler(HandleShowWireframeButtonCheckedChanged);
            renderingToolStrip.Items.Add(showWireframeButton);
            showSurfacesButton = new ToolStripButton();
            showSurfacesButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            showSurfacesButton.Text            = "Show surfaces";
            showSurfacesButton.CheckOnClick    = true;
            showSurfacesButton.Checked         = true;
            showSurfacesButton.CheckedChanged += new EventHandler(HandleShowSurfacesButtonCheckedChanged);
            renderingToolStrip.Items.Add(showSurfacesButton);
            showVerticesButton = new ToolStripButton();
            showVerticesButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            showVerticesButton.Text            = "Show vertices";
            showVerticesButton.CheckOnClick    = true;
            showVerticesButton.Checked         = false;
            showVerticesButton.CheckedChanged += new EventHandler(HandleShowVerticesButtonCheckedChanged);
            renderingToolStrip.Items.Add(showVerticesButton);
            showSlicePlaneButton = new ToolStripButton();
            showSlicePlaneButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            showSlicePlaneButton.Text            = "Show slice plane";
            showSlicePlaneButton.CheckOnClick    = true;
            showSlicePlaneButton.Checked         = true;
            showSlicePlaneButton.CheckedChanged += new EventHandler(HandleShowSlicePlaneButtonCheckedChanged);
            renderingToolStrip.Items.Add(showSlicePlaneButton);
            showAxesButton = new ToolStripButton();
            showAxesButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            showAxesButton.Text            = "Show axes";
            showAxesButton.CheckOnClick    = true;
            showAxesButton.Checked         = false;
            showAxesButton.CheckedChanged += new EventHandler(HandleShowAxesButtonCheckedChanged);
            renderingToolStrip.Items.Add(showAxesButton);
            ToolStripSeparator separator3 = new ToolStripSeparator();

            renderingToolStrip.Items.Add(separator3);
            numberOfLongitudePointsLabel = new ToolStripLabel();
            numberOfLongitudePointsLabel.DisplayStyle = ToolStripItemDisplayStyle.Text;
            numberOfLongitudePointsLabel.Text         = "Number of longitude points: ";
            renderingToolStrip.Items.Add(numberOfLongitudePointsLabel);
            numberOfLongitudePointsTextBox = new ToolStripTextBox();
            numberOfLongitudePointsTextBox.DisplayStyle = ToolStripItemDisplayStyle.Text;
            numberOfLongitudePointsTextBox.Text         = "32";
            numberOfLongitudePointsTextBox.AutoSize     = false;
            numberOfLongitudePointsTextBox.Width        = 30;
            numberOfLongitudePointsTextBox.TextChanged += new EventHandler(HandleNumberOfLongitudePointsTextBoxTextChanged);
            renderingToolStrip.Items.Add(numberOfLongitudePointsTextBox);
            shadingModelLabel = new ToolStripLabel();
            shadingModelLabel.DisplayStyle = ToolStripItemDisplayStyle.Text;
            shadingModelLabel.Text         = "Shading model";
            renderingToolStrip.Items.Add(shadingModelLabel);
            shadingModelComboBox = new ToolStripComboBox();
            shadingModelComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
            shadingModelComboBox.Items.Add("Flat");
            shadingModelComboBox.Items.Add("Smooth");
            shadingModelComboBox.AutoSize              = false;
            shadingModelComboBox.Width                 = 70;
            shadingModelComboBox.SelectedIndex         = 1; // Default value: Smooth shading
            shadingModelComboBox.SelectedIndexChanged += new EventHandler(HandleShadingModelComboBoxSelectedIndexChanged);
            renderingToolStrip.Items.Add(shadingModelComboBox);
            autoRenderButton = new ToolStripButton();
            autoRenderButton.DisplayStyle    = ToolStripItemDisplayStyle.Text;
            autoRenderButton.Text            = "Autorender";
            autoRenderButton.CheckOnClick    = true;
            autoRenderButton.Checked         = true;
            autoRenderButton.CheckedChanged += new EventHandler(HandleAutoRenderButtonCheckedChanged);
            renderingToolStrip.Items.Add(autoRenderButton);



            splitContainer      = new SplitContainer();
            splitContainer.Dock = DockStyle.Fill;
            this.Controls.Add(splitContainer);
            viewer3D      = new Viewer3D();
            viewer3D.Dock = DockStyle.Fill;
            splitContainer.Panel1.Controls.Add(viewer3D);
            bezierCurveViewer      = new BezierCurveViewer();
            bezierCurveViewer.Dock = DockStyle.Fill;
            splitContainer.Panel2.Controls.Add(bezierCurveViewer);
            splitContainer.SplitterDistance = this.Width / 2;
            bezierCurveViewer.SetRange(-2, 2, -2, 2);
            bezierCurveViewer.SplineCurveChanged  += new EventHandler(HandleBezierSplineViewerSplineCurveChanged);
            bezierCurveViewer.PointsSelected      += new EventHandler(HandleBezierCurveViewerPointsSelected);
            bezierCurveViewer.AllPointsDeSelected += new EventHandler(HandleBezierCurveViewerAllPointsDeSelected);

            // Add the toolstrips in reverse order
            // Strangely enough, they should also apparently be inserted AFTER the SplitContainer, despite
            // the latter's DockStyle (= Fill)!
            this.Controls.Add(renderingToolStrip);
            this.Controls.Add(sliceEditingToolStrip);
            this.Controls.Add(slicePositionToolStrip);

            // MW ToDo: Some ugly hard-coding here...
            scene = new Scene3D();
            Light light = new Light();

            light.Position[1] = -5;
            light.Position[2] = 3;
            light.IsOn        = true;
            scene.LightList.Add(light);
            face.AmbientColor  = Color.FromArgb(255, 205, 148); // Typical skin color approximation
            face.DiffuseColor  = Color.FromArgb(255, 205, 148); // Typical skin color approximation
            face.SpecularColor = Color.White;
            face.Shininess     = 50;                            //  20;
            int numberOfLongitudePoints = int.Parse(numberOfLongitudePointsTextBox.Text);

            face.Generate(new List <double>()
            {
                numberOfLongitudePoints
            });
            scene.AddObject(face);
            slice.AmbientColor  = Color.FromArgb(200, 100, 255, 100);
            slice.DiffuseColor  = Color.FromArgb(200, 100, 255, 100);
            slice.SpecularColor = Color.FromArgb(200, 100, 255, 100);
            slice.Shininess     = 20;
            slice.Generate(new List <double>()
            {
                3.0, 3.0
            });
            scene.AddObject(slice);
            currentSliceIndex = face.HorizontalBezierCurveList.Count / 2;
            slice.Move(0, 0, face.HorizontalBezierCurveList[currentSliceIndex].SplineList[0].ControlPointList[0].CoordinateList[2]);
            //     slice.Translate(0, 0, face.HorizontalBezierCurveList[currentSliceIndex].SplineList[0].ControlPointList[0].CoordinateList[2]);
            bezierCurveViewer.SetBezierCurve(face.HorizontalBezierCurveList[currentSliceIndex]);
            currentSliceLabel.Text    = "Current slice: " + currentSliceIndex.ToString() + " of " + (face.HorizontalBezierCurveList.Count - 1).ToString();
            zLabel.Text               = "z = " + face.HorizontalBezierCurveList[currentSliceIndex].SplineList[0].ControlPointList[0].CoordinateList[2].ToString("0.0000");
            zStepTextBox.TextChanged += new EventHandler(HandleZStepTextBoxTextChanged); // Add the event handler here, AFTER setting the slice index
            viewer3D.Scene            = scene;
            viewer3D.CameraTarget     = new OpenTK.Vector3(0f, 0f, 0.5f);                // The model extends from 0 to 1 in z.

            viewer3D.ArrowUpPressed   -= new EventHandler(HandlerViewer3DArrowUpPressed);
            viewer3D.ArrowUpPressed   += new EventHandler(HandlerViewer3DArrowUpPressed);
            viewer3D.ArrowDownPressed -= new EventHandler(HandleViewer3DArrowDownPressed);
            viewer3D.ArrowDownPressed += new EventHandler(HandleViewer3DArrowDownPressed);
        }