Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Drawing/Graphs/ILSceneGraph.cs @ 12448

Last change on this file since 12448 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 8.0 KB
Line 
1///
2///    This file is part of ILNumerics Community Edition.
3///
4///    ILNumerics Community Edition - high performance computing for applications.
5///    Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
6///
7///    ILNumerics Community Edition is free software: you can redistribute it and/or modify
8///    it under the terms of the GNU General Public License version 3 as published by
9///    the Free Software Foundation.
10///
11///    ILNumerics Community Edition is distributed in the hope that it will be useful,
12///    but WITHOUT ANY WARRANTY; without even the implied warranty of
13///    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14///    GNU General Public License for more details.
15///
16///    You should have received a copy of the GNU General Public License
17///    along with ILNumerics Community Edition. See the file License.txt in the root
18///    of your distribution package. If not, see <http://www.gnu.org/licenses/>.
19///
20///    In addition this software uses the following components and/or licenses:
21///
22///    =================================================================================
23///    The Open Toolkit Library License
24///   
25///    Copyright (c) 2006 - 2009 the Open Toolkit library.
26///   
27///    Permission is hereby granted, free of charge, to any person obtaining a copy
28///    of this software and associated documentation files (the "Software"), to deal
29///    in the Software without restriction, including without limitation the rights to
30///    use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
31///    the Software, and to permit persons to whom the Software is furnished to do
32///    so, subject to the following conditions:
33///
34///    The above copyright notice and this permission notice shall be included in all
35///    copies or substantial portions of the Software.
36///
37///    =================================================================================
38///   
39
40using System;
41using System.Collections.Generic;
42using System.Collections;
43using System.Text;
44using ILNumerics.Drawing;
45using ILNumerics.Drawing.Interfaces;
46using ILNumerics.Drawing.Shapes;
47using ILNumerics;
48
49namespace ILNumerics.Drawing.Graphs {
50    /// <summary>
51    /// The class implements a scene graph (tree), capable
52    /// of holding, managing and drawing all kinds of shapes.
53    /// </summary>
54    public class ILSceneGraph : ILGraph {
55
56        #region eventing
57        /// <summary>
58        /// fires, once somewhere in the graph a node was added
59        /// </summary>
60        public event SceneGraphNodeHandler NodeAdded;
61        void OnNodeAdded(ILSceneGraphNodeEventArgs args) {
62            if (NodeAdded != null) {
63                NodeAdded(this, args); 
64            }
65        }
66        public event SceneGraphNodeHandler NodeRemoved;
67        void OnNodeRemoved(ILSceneGraphNodeEventArgs args) {
68            if (NodeRemoved != null) {
69                NodeRemoved(this, args); 
70            }
71        }
72
73        void m_root_Invalidated(object sender, EventArgs e) {
74            base.Invalidate();
75        }
76        void m_root_SizeChanged(object sender, EventArgs e) {
77            m_localClipping.Set(m_root.PositionMin, m_root.PositionMax);
78        }
79        void m_root_NodeAdded(object sender, ILSceneGraphNodeEventArgs args) {
80            OnNodeAdded(args);
81        }
82        void m_root_NodeRemoved(object sender, ILSceneGraphNodeEventArgs args) {
83            OnNodeRemoved(args);
84        }
85
86        #endregion
87
88        #region attributes
89        private ILSceneGraphRoot m_root;
90        #endregion
91
92        #region properties
93        /// <summary>
94        /// root node of the scene graph
95        /// </summary>
96        public ILSceneGraphInnerNode Root {
97            get {return m_root; }
98        }
99        #endregion
100
101        #region constructors
102        /// <summary>
103        /// (internal) create new scene graph
104        /// </summary>
105        /// <param name="panel">panel hosting the scene</param>
106        /// <param name="clipping">clipping data object, usually member of the panel</param>
107        internal ILSceneGraph (ILPanel panel, ILClippingData clipping)
108            : base(panel,clipping) {
109            m_root = new ILSceneGraphRoot(panel);
110            m_root.Invalidated += new EventHandler(m_root_Invalidated);
111            m_root.SizeChanged += new EventHandler(m_root_SizeChanged);
112            m_root.NodeAdded += new SceneGraphNodeHandler(m_root_NodeAdded);
113            m_root.NodeRemoved += new SceneGraphNodeHandler(m_root_NodeRemoved);
114            m_graphType = GraphType.SceneGraph;
115        }
116
117        #endregion
118
119        #region public interface
120        /// <summary>
121        /// Determines if this graph renders in 3D, may overridden in derived class
122        /// </summary>
123        /// <returns></returns>
124        public override bool Is3DGraph() {
125            return true;
126        }
127        /// <summary>
128        /// (internal use) draws the whole scene graph
129        /// </summary>
130        /// <param name="p"></param>
131        public override void Draw(ILRenderProperties p) {
132            m_root.Draw(p);
133        }
134        /// <summary>
135        /// (internal use) configures and prepares the scene graph for rendering
136        /// </summary>
137        internal override void Configure() {
138            if (!m_isReady) {
139                m_root.Configure();
140                m_isReady = true;
141            }
142        }
143        /// <summary>
144        /// add new node to root node
145        /// </summary>
146        /// <param name="node"></param>
147        public void AddNode(ILSceneGraphNode node) {
148            AddNode(node, m_root);
149        }
150        /// <summary>
151        /// add a shape to the root node
152        /// </summary>
153        /// <param name="shape"></param>
154        public void AddNode(ILShape shape) {
155            ILSceneGraphShapedLeaf node = new ILSceneGraphShapedLeaf(m_panel);
156            node.Shape = shape;
157            AddNode(node, m_root);
158        }
159        /// <summary>
160        /// add new node as child of another node
161        /// </summary>
162        /// <param name="node"></param>
163        /// <param name="parent"></param>
164        public void AddNode(ILSceneGraphNode node, ILSceneGraphInnerNode parent) {
165            parent.Add(node);             
166        }
167        /// <summary>
168        /// collect all shapes contained in any scene graph nodes
169        /// </summary>
170        /// <returns></returns>
171        public List<ILShape> GetAllShapes() {
172            List<ILShape> ret = new List<ILShape>();
173            getAllShapes(m_root, ret);
174            return ret; 
175        }
176        #endregion
177
178        #region private helpers
179        private void getAllShapes(ILSceneGraphNode node, List<ILShape> ret) {
180            foreach (ILSceneGraphNode n in node) {
181                if (n is ILSceneGraphShapedLeaf) {
182                    ILSceneGraphShapedLeaf snode = n as ILSceneGraphShapedLeaf;
183                    if (snode.Shape != null)
184                        ret.Add(snode.Shape);
185                }
186                //getAllShapes(n,ret);
187            }
188        }
189
190        #endregion
191
192        #region IEnumerable<ILShape> Member
193
194        //public IEnumerator<ILShape> GetEnumerator() {
195        //    List<ILShape> ret = new List<ILShape>();
196        //    getAllShapes(m_root,ret);
197        //    return ret.GetEnumerator(); 
198        //}
199
200        //#endregion
201
202        //#region IEnumerable Member
203
204        //IEnumerator GetEnumerator() {
205        //    List<ILShape> ret = new List<ILShape>();
206        //    getAllShapes(m_root,ret);
207        //    return ret.GetEnumerator(); 
208        //}
209
210        //#endregion
211
212        //#region IILPanelConfigurator
213        //public override void ConfigurePanel(ILPanel panel) {
214        //    panel.InteractiveMode = InteractiveModes.Rotating;
215        //    panel.DefaultView.Set(5.8f, 1.17f, panel.DefaultView.Distance);
216        //}
217        #endregion
218
219    }
220}
Note: See TracBrowser for help on using the repository browser.