private bool DoRender()
        {
            DebugHelper.AssertUIThread();

            bool result = false;

            {
                if ((this.image != null) && (this.Visibility == System.Windows.Visibility.Visible))
                {
                    result = true;

                    viz.Context context = null;

                    if (this.PluginService != null)
                    {
                        context = this.PluginService.GetContext(this.EventType);
                    }

                    if (this.image != null)
                    {
                        if (context != null)
                        {
                            if (!context.BeginRender())
                            {
                                context = null;
                            }
                        }
                    }

                    if (context != null)
                    {
                        this.OnBeginRender(context);

                        viz.Texture texture = null;

                        foreach (PluginViewState pluginViewState in this.PluginViewStates)
                        {
                            if (pluginViewState.IsEnabled)
                            {
                                IImageVisualPlugin visualPlugin = pluginViewState.Plugin as IImageVisualPlugin;
                                if (visualPlugin != null)
                                {
                                    texture = visualPlugin.GetTexture(this.EventType, pluginViewState.PluginViewSettings);

                                    if (texture != null)
                                    {
                                        break;
                                    }
                                }
                            }
                        }

                        float scaledWidth  = 0;
                        float scaledHeight = 0;

                        this.OnGetLayout(context, texture, ref scaledWidth, ref scaledHeight);

                        if (this.imageHost is Canvas)
                        {
                            uint w = (uint)scaledWidth;
                            uint h = (uint)scaledHeight;

                            if (this.image != null)
                            {
                                this.image.Width  = w;
                                this.image.Height = h;
                            }

                            this.FixRenderTargetSize(w, h);
                        }

                        if (this.renderTarget != null)
                        {
                            if (this.renderTarget.BeginRender(this.ClearColor, 1))
                            {
                                foreach (PluginViewState pluginViewState in this.PluginViewStates)
                                {
                                    if (pluginViewState.IsEnabled)
                                    {
                                        IImageVisualPlugin visualPlugin = pluginViewState.Plugin as IImageVisualPlugin;
                                        if (visualPlugin != null)
                                        {
                                            I2DVisualPlugin visualPlugin2d = visualPlugin as I2DVisualPlugin;
                                            if (visualPlugin2d != null)
                                            {
                                                visualPlugin2d.Render2D(this.EventType, pluginViewState.PluginViewSettings, context, texture, 0, 0, scaledWidth, scaledHeight);
                                            }

                                            I3DVisualPlugin visualPlugin3d = visualPlugin as I3DVisualPlugin;
                                            if (visualPlugin3d != null)
                                            {
                                                visualPlugin3d.Render3D(this.EventType, pluginViewState.PluginViewSettings, context, texture);
                                            }
                                        }
                                    }
                                }

                                this.OnEndRender(context, texture, scaledWidth, scaledHeight);

                                this.renderTarget.EndRender();
                            }
                        }

                        context.EndRender();
                    }
                }
            }

            return(result);
        }