本文整理汇总了C#中OpenNI.Context.WaitAndUpdateAll方法的典型用法代码示例。如果您正苦于以下问题:C# Context.WaitAndUpdateAll方法的具体用法?C# Context.WaitAndUpdateAll怎么用?C# Context.WaitAndUpdateAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenNI.Context
的用法示例。
在下文中一共展示了Context.WaitAndUpdateAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitOpenNI
private void InitOpenNI()
{
// ContextとImageGeneratorの作成
ScriptNode node;
context = Context.CreateFromXmlFile( "SamplesConfig.xml", out node );
context.GlobalMirror = false;
image = context.FindExistingNode( NodeType.Image ) as ImageGenerator;
// 画像更新のためのスレッドを作成
shouldRun = true;
readerThread = new Thread( new ThreadStart( () =>
{
while ( shouldRun ) {
context.WaitAndUpdateAll();
ImageMetaData imageMD = image.GetMetaData();
// ImageMetaDataをBitmapSourceに変換する(unsafeにしなくてもOK!!)
this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () =>
{
imageOpenNI.Source = BitmapSource.Create( imageMD.XRes, imageMD.YRes,
96, 96, PixelFormats.Rgb24, null, imageMD.ImageMapPtr,
imageMD.DataSize, imageMD.XRes * imageMD.BytesPerPixel );
} ) );
}
} ) );
readerThread.Start();
}
示例2: MainWindow
public MainWindow()
{
InitializeComponent();
try {
// ContextとImageGeneratorの作成
ScriptNode node;
context = Context.CreateFromXmlFile( "../../SamplesConfig.xml", out node );
context.GlobalMirror = false;
image = context.FindExistingNode( NodeType.Image ) as ImageGenerator;
audio = context.FindExistingNode( NodeType.Audio ) as AudioGenerator;
wavePlayer = new StreamingWavePlayer( audio.WaveOutputMode.SampleRate,
audio.WaveOutputMode.BitsPerSample, audio.WaveOutputMode.Channels, 100 );
// 画像更新のためのスレッドを作成
shouldRun = true;
readerThread = new Thread( new ThreadStart( () =>
{
while ( shouldRun ) {
context.WaitAndUpdateAll();
ImageMetaData imageMD = image.GetMetaData();
// WAVEデータの出力
wavePlayer.Output( audio.AudioBufferPtr, audio.DataSize );
// ImageMetaDataをBitmapSourceに変換する(unsafeにしなくてもOK!!)
this.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action( () =>
{
image1.Source = BitmapSource.Create( imageMD.XRes, imageMD.YRes,
96, 96, PixelFormats.Rgb24, null, imageMD.ImageMapPtr,
imageMD.DataSize, imageMD.XRes * imageMD.BytesPerPixel );
} ) );
}
} ) );
readerThread.Start();
}
catch ( Exception ex ) {
MessageBox.Show( ex.Message );
}
}
示例3: Sensor
public Sensor(string config)
{
if (string.IsNullOrEmpty(config))
throw new ArgumentNullException();
try
{
_context = Context.CreateFromXmlFile(config, out _scriptNode);
_depthGenerator = _context.FindExistingNode(NodeType.Depth) as DepthGenerator;
_imageGenerator = _context.FindExistingNode(NodeType.Image) as ImageGenerator;
_userGenerator = _context.FindExistingNode(NodeType.User) as UserGenerator;
if (_depthGenerator == null)
throw new ApplicationException("No depth node found.");
if (_imageGenerator == null)
throw new ApplicationException("No image node found.");
if (_userGenerator == null)
throw new ApplicationException("No user node found.");
if (_depthGenerator.MapOutputMode.FPS != _imageGenerator.MapOutputMode.FPS)
throw new ApplicationException("Depth and image node must have common framerates.");
if (_depthGenerator.MapOutputMode.XRes != _imageGenerator.MapOutputMode.XRes)
throw new ApplicationException("Depth and image node must have common horizontal resolutions.");
if (_depthGenerator.MapOutputMode.YRes != _imageGenerator.MapOutputMode.YRes)
throw new ApplicationException("Depth and image node must have common vertical resolutions.");
_depthMetaData = new DepthMetaData();
_imageMetaData = new ImageMetaData();
_imageWidth = _depthGenerator.MapOutputMode.XRes;
_imageHeight = _depthGenerator.MapOutputMode.YRes;
_userGenerator.NewUser += new EventHandler<NewUserEventArgs>(_userGenerator_NewUser);
_userGenerator.LostUser += new EventHandler<UserLostEventArgs>(_userGenerator_LostUser);
_userGenerator.StartGenerating();
_bitmapGenerator = new BitmapGenerator(this);
_readerWaitHandle = new AutoResetEvent(false);
_readerThread = new Thread(delegate()
{
try
{
while (_run)
{
if (_pause)
_readerWaitHandle.WaitOne();
_context.WaitAndUpdateAll();
_depthGenerator.GetMetaData(_depthMetaData);
_imageGenerator.GetMetaData(_imageMetaData);
if (_depthMetaData.XRes != _imageWidth || _imageMetaData.XRes != _imageWidth)
throw new ApplicationException("Image width must not change.");
if (_depthMetaData.YRes != _imageHeight || _imageMetaData.YRes != _imageHeight)
throw new ApplicationException("Image height must not change.");
if (GeneratorUpdate != null)
GeneratorUpdate(this, EventArgs.Empty);
}
}
catch (ThreadInterruptedException)
{
Console.WriteLine("Reader thread interrupted.");
}
catch (Exception e)
{
throw new ApplicationException("Error while processing sensor data.", e);
}
}) { Name = "ONI Reader Thread" };
}
catch (Exception)
{
throw;
}
}