Example #1
0
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
            context = new Context();
            // OpenFileRecordingExを使うように促されるが、使用するとアクセスバイオレーションになる
            context.OpenFileRecording(RECORD_PATH);

            // プレーヤーの作成
            player = context.FindExistingNode(NodeType.Player) as OpenNI.Player;
            if (player == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // 終端に達したら通知するコールバックを登録する
            player.EndOfFileReached += new EventHandler(player_EndOfFileReached);

            // イメージジェネレータの作成
            image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
            if (image == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // デプスジェネレータの作成
            depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (depth == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // ヒストグラムバッファの作成
            histogram = new int[depth.DeviceMaxDepth];
        }
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
              context = new Context();
              // OpenFileRecordingExを使うように促されるが、使用するとアクセスバイオレーションになる
              context.OpenFileRecording(RECORD_PATH);

              // プレーヤーの作成
              player = context.FindExistingNode(NodeType.Player) as OpenNI.Player;
              if (player == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // 終端に達したら通知するコールバックを登録する
              player.EndOfFileReached += new EventHandler(player_EndOfFileReached);

              // イメージジェネレータの作成
              image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
              if (image == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // デプスジェネレータの作成
              depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
              if (depth == null) {
            throw new Exception(context.GlobalErrorState);
              }

              // ヒストグラムバッファの作成
              histogram = new int[depth.DeviceMaxDepth];
        }
Example #3
0
        private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType? type)
        {
            lock (this)
            {
                if (!this.allNodes.ContainsKey(nodeHandle))
                {
                    if (type == null)
                    {
                        IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle);
                        type = NodeInfo.FromNative(pNodeInfo).Description.Type;
                    }

                    ProductionNode node;

                    switch (type)
                    {
                        case NodeType.Device:
                            node = new Device(this, nodeHandle, true);
                            break;
                        case NodeType.Depth:
                            node = new DepthGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Image:
                            node = new ImageGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Audio:
                            node = new AudioGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.IR:
                            node = new IRGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.User:
                            node = new UserGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Recorder:
                            node = new Recorder(this, nodeHandle, true);
                            break;
                        case NodeType.Player:
                            node = new Player(this, nodeHandle, true);
                            break;
                        case NodeType.Gesture:
                            node = new GestureGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Scene:
                            node = new SceneAnalyzer(this, nodeHandle, true);
                            break;
                        case NodeType.Hands:
                            node = new HandsGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.Codec:
                            node = new Codec(this, nodeHandle, true);
                            break;
                        case NodeType.ProductionNode:
                            node = new ProductionNode(this, nodeHandle, true);
                            break;
                        case NodeType.Generator:
                            node = new Generator(this, nodeHandle, true);
                            break;
                        case NodeType.MapGenerator:
                            node = new MapGenerator(this, nodeHandle, true);
                            break;
                        case NodeType.ScriptNode:
                            node = new ScriptNode(this, nodeHandle, true);
                            break;
                        default:
                            throw new NotImplementedException("C# wrapper: Unknown generator type!");
                    }
                    this.allNodes[nodeHandle] = node;
                }

                return this.allNodes[nodeHandle];
            } // lock
        }
Example #4
0
		private ProductionNode CreateProductionNodeObject(IntPtr nodeHandle, NodeType? type)
		{
			lock (this)
			{
				if (!this.allNodes.ContainsKey(nodeHandle))
				{
					if (type == null)
					{
						IntPtr pNodeInfo = SafeNativeMethods.xnGetNodeInfo(nodeHandle);
                        type = NodeInfo.FromNative(pNodeInfo).Description.Type;
					}

					ProductionNode node;

                   	// start with concrete types
                    if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Device))
                    {
                        node = new Device(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Depth))
                    {
                        node = new DepthGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Image))
                    {
                        node = new ImageGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Audio))
                    {
                        node = new AudioGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.IR))
                    {
                        node = new IRGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.User))
                    {
                        node = new UserGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Recorder))
                    {
                        node = new Recorder(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Player))
                    {
                        node = new Player(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Gesture))
                    {
                        node = new GestureGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Scene))
                    {
                        node = new SceneAnalyzer(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Hands))
                    {
                        node = new HandsGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Codec))
                    {
                        node = new Codec(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ScriptNode))
                    {
                        node = new ScriptNode(this, nodeHandle, true);
                    }
                    // move on to abstract types
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.MapGenerator))
                    {
                        node = new MapGenerator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.Generator))
                    {
                        node = new Generator(this, nodeHandle, true);
                    }
                    else if (SafeNativeMethods.xnIsTypeDerivedFrom(type.Value, NodeType.ProductionNode))
                    {
                        node = new ProductionNode(this, nodeHandle, true);
                    }
                    else
                    {
                        throw new NotImplementedException("C# wrapper: Unknown generator type!");
                    }

					this.allNodes[nodeHandle] = node;
				}

				return this.allNodes[nodeHandle];
			} // lock
		}
        /// <summary>
        /// Creates a new control instance with a recording as data
        /// source. The current image data can be obtained by the
        /// <see cref="Image"/>-property. The
        /// <see cref="NewImageDataAvailable"/> event informs about when the
        /// data is updated, the <see cref="ErrorOccured"/>-event about
        /// errors.
        /// </summary>
        /// <exception cref="System.Exception">Thrown if the stream could not
        /// be initialized properly.</exception>
        public OpenNIRecordingController(String recording_filename,
            String movementDataFileName, String userAnnotationFilename)
        {
            // Create a new context and the data-generating nodes.
            context = new Context();
            context.OpenFileRecording(recording_filename);
            this.recording_filename = recording_filename;

            _userInformationReader = new BinaryReader(
                       new FileStream(movementDataFileName, FileMode.Open));

            using (FileStream annotation_stream = File.OpenRead(userAnnotationFilename))
            {
                _userLocationInformation = (ImageDictionary)movementDataSerializer.Deserialize(annotation_stream);
            }

            // Image
            imageGenerator = (ImageGenerator)context.FindExistingNode(NodeType.Image);

            // Depth
            depthGenerator = (DepthGenerator)context.FindExistingNode(NodeType.Depth);
            histogram = new int[depthGenerator.DeviceMaxDepth];

            // Player
            player = (Player)context.FindExistingNode(NodeType.Player);
            player.PlaybackSpeed = 1.0;

            if (depthGenerator == null || imageGenerator == null || player == null)
            {
                throw new Exception("Could not initialize recording stream.");
            }

            // Error handling
            context.ErrorStateChanged += context_ErrorStateChanged;
            context.StartGeneratingAll();
        }