public void Render( DeviceContext deviceContext, Viewport viewport, RenderTargetView renderTargetView, DepthStencilView depthStencilView ) { deviceContext.ClearRenderTargetView( renderTargetView, Constants.CLEAR_COLOR ); deviceContext.ClearDepthStencilView( depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0x00 ); var centerDataSpace = mTileManager.TiledDatasetView.CenterDataSpace; var extentDataSpace = mTileManager.TiledDatasetView.ExtentDataSpace; var camera = new Camera( new Vector3( 0, 0, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 1, 0 ), Matrix.OrthoOffCenterLH( centerDataSpace.X - ( extentDataSpace.X / 2f ), centerDataSpace.X + ( extentDataSpace.X / 2f ), centerDataSpace.Y + ( extentDataSpace.Y / 2f ), centerDataSpace.Y - ( extentDataSpace.Y / 2f ), 0.1f, 100f ) ); var datasetExtentDataSpaceX = mTileManager.TiledDatasetDescription.TiledVolumeDescriptions.Get( "SourceMap" ).NumTilesX * Constants.ConstParameters.GetInt( "TILE_SIZE_X" ); var datasetExtentDataSpaceY = mTileManager.TiledDatasetDescription.TiledVolumeDescriptions.Get( "SourceMap" ).NumTilesY * Constants.ConstParameters.GetInt( "TILE_SIZE_Y" ); mTileManager.GetTileCache().ToList().ForEach( tileCacheEntry => RenderTileCacheEntry( deviceContext, camera, datasetExtentDataSpaceX, datasetExtentDataSpaceY, tileCacheEntry, viewport ) ); //mTinyTextContext.Print( viewport, "Frame Time: " + FrameTimeString, 10, 10 ); //mTinyTextContext.Print( viewport, "Number of Active Cache Entries: " + mTileManager.GetTileCache().Count, 10, 30 ); //mTinyTextContext.Render(); mStopwatch.Reset(); mStopwatch.Start(); }
private void RenderTileCacheEntry( DeviceContext deviceContext, Camera camera, int datasetExtentDataSpaceX, int datasetExtentDataSpaceY, TileCacheEntry tileCacheEntry, Viewport viewport ) { //Check if this tile is over the edge of the image var tileMinExtentX = tileCacheEntry.CenterDataSpace.X - ( tileCacheEntry.ExtentDataSpace.X / 2f ); var tileMinExtentY = tileCacheEntry.CenterDataSpace.Y - ( tileCacheEntry.ExtentDataSpace.Y / 2f ); var tileMaxExtentX = tileCacheEntry.CenterDataSpace.X + ( tileCacheEntry.ExtentDataSpace.X / 2f ); var tileMaxExtentY = tileCacheEntry.CenterDataSpace.Y + ( tileCacheEntry.ExtentDataSpace.Y / 2f ); var tileProportionClipX = 1f; var tileProportionClipY = 1f; if ( datasetExtentDataSpaceX > 0 && tileMaxExtentX > datasetExtentDataSpaceX ) { tileProportionClipX = 1 - ( ( tileMaxExtentX - datasetExtentDataSpaceX ) / ( tileMaxExtentX - tileMinExtentX ) ); tileMaxExtentX = datasetExtentDataSpaceX; } if ( datasetExtentDataSpaceY > 0 && tileMaxExtentY > datasetExtentDataSpaceY ) { tileProportionClipY = 1 - ( ( tileMaxExtentY - datasetExtentDataSpaceY ) / ( tileMaxExtentY - tileMinExtentY ) ); tileMaxExtentY = datasetExtentDataSpaceY; } var p1 = new Vector3( tileMinExtentX, tileMinExtentY, 0.5f ); var p2 = new Vector3( tileMinExtentX, tileMaxExtentY, 0.5f ); var p3 = new Vector3( tileMaxExtentX, tileMaxExtentY, 0.5f ); var p4 = new Vector3( tileMaxExtentX, tileMinExtentY, 0.5f ); var t1 = new Vector3( 0f, 0f, 0f ); var t2 = new Vector3( 0f, tileProportionClipY, 0f ); var t3 = new Vector3( tileProportionClipX, tileProportionClipY, 0f ); var t4 = new Vector3( tileProportionClipX, 0f, 0f ); DataBox databox; databox = deviceContext.MapSubresource( mPositionVertexBuffer, 0, QUAD_NUM_VERTICES * POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None ); databox.Data.Write( p1 ); databox.Data.Write( p4 ); databox.Data.Write( p2 ); databox.Data.Write( p3 ); deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 ); databox = deviceContext.MapSubresource( mTexCoordVertexBuffer, 0, QUAD_NUM_VERTICES * TEXCOORD_NUM_COMPONENTS_PER_VERTEX * TEXCOORD_NUM_BYTES_PER_COMPONENT, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None ); databox.Data.Write( t1 ); databox.Data.Write( t4 ); databox.Data.Write( t2 ); databox.Data.Write( t3 ); deviceContext.UnmapSubresource( mTexCoordVertexBuffer, 0 ); deviceContext.InputAssembler.InputLayout = mInputLayout; deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT, new VertexBufferBinding( mPositionVertexBuffer, POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, 0 ) ); deviceContext.InputAssembler.SetVertexBuffers( TEXCOORD_SLOT, new VertexBufferBinding( mTexCoordVertexBuffer, TEXCOORD_NUM_COMPONENTS_PER_VERTEX * TEXCOORD_NUM_BYTES_PER_COMPONENT, 0 ) ); mEffect.GetVariableByName( "gSourceTexture3D" ).AsResource().SetResource( tileCacheEntry.D3D11CudaTextures.Get( "SourceMap" ) ); if ( mTileManager.SegmentationLoaded ) { //if ( tileCacheEntry.D3D11CudaTextures.Internal.ContainsKey( "IdMap" ) ) //{ // mEffect.GetVariableByName( "gIdTexture3D" ).AsResource().SetResource( tileCacheEntry.D3D11CudaTextures.Get( "IdMap" ) ); //} //else //{ // System.Console.WriteLine("Warning: expected IdMap not found."); //} mEffect.GetVariableByName( "gIdTexture3D" ).AsResource().SetResource( tileCacheEntry.D3D11CudaTextures.Get( "IdMap" ) ); mEffect.GetVariableByName( "gIdColorMapBuffer" ).AsResource().SetResource( mTileManager.Internal.GetIdColorMap() ); mEffect.GetVariableByName( "gLabelIdMapBuffer" ).AsResource().SetResource( mTileManager.Internal.GetLabelIdMap() ); mEffect.GetVariableByName( "gIdConfidenceMapBuffer" ).AsResource().SetResource( mTileManager.Internal.GetIdConfidenceMap() ); if ( tileCacheEntry.D3D11CudaTextures.Internal.ContainsKey( "OverlayMap" ) ) { mEffect.GetVariableByName( "gOverlayTexture3D" ).AsResource().SetResource( tileCacheEntry.D3D11CudaTextures.Get( "OverlayMap" ) ); } } mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() ); mEffect.GetVariableByName( "gSegmentationRatio" ).AsScalar().Set( mTileManager.SegmentationVisibilityRatio ); mEffect.GetVariableByName( "gBoundaryLinesVisible" ).AsScalar().Set( mTileManager.ShowBoundaryLines ); mEffect.GetVariableByName( "gBrushVisible" ).AsScalar().Set( mTileManager.SelectedSegmentId != 0 ); mEffect.GetVariableByName( "gSelectedSegmentId" ).AsScalar().Set( mTileManager.SelectedSegmentId ); mEffect.GetVariableByName( "gMouseOverSegmentId" ).AsScalar().Set( mTileManager.MouseOverSegmentId ); mEffect.GetVariableByName( "gMouseOverX" ).AsScalar().Set( ( mTileManager.MouseOverX - tileMinExtentX ) / tileCacheEntry.ExtentDataSpace.X ); mEffect.GetVariableByName( "gMouseOverY" ).AsScalar().Set( ( mTileManager.MouseOverY - tileMinExtentY ) / tileCacheEntry.ExtentDataSpace.Y ); mEffect.GetVariableByName( "gMouseHighlightSize" ).AsScalar().Set( mTileManager.BrushSize ); mPass.Apply( deviceContext ); deviceContext.Draw( QUAD_NUM_VERTICES, 0 ); //mDebugRenderer.RenderQuadWireframeOnly( deviceContext, p1, p2, p3, p4, new Vector3( 1, 0, 0 ), camera ); }
public void RenderSphereSolidWireframe( DeviceContext deviceContext, Vector3 p, float radius, Vector3 backgroundColor, Vector3 foregroundColor, Camera camera ) { RenderSphereSolidOnly( deviceContext, p, radius, backgroundColor, camera ); RenderSphereWireframeOnly( deviceContext, p, radius, foregroundColor, camera ); }
public void RenderSphereWireframeOnly( DeviceContext deviceContext, Vector3 p, float radius, Vector3 color, Camera camera ) { var databox = deviceContext.MapSubresource( mPositionVertexBuffer, 0, NUM_VERTICES * POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None ); var currentPoint = new Vector3(); var furtherSouthPoint = new Vector3(); var numVertices = 0; // northSouthTheta traces from north pole to south pole float northSouthTheta = (float)Math.PI / 2; for ( int i = 0; i <= NUM_LATITUDE_LINES; i++ ) { float currentLatitudeRadius = (float)Math.Cos( northSouthTheta ) * radius; float nextLatitudeRadius = (float)Math.Cos( northSouthTheta + LATITUDE_STEP ) * radius; // eastWestTheta traces around each latitude line float eastWestTheta = 0; for ( int j = 0; j <= NUM_LONGITUDE_LINES; j++ ) { currentPoint.X = p.X + ( (float)Math.Cos( eastWestTheta ) * currentLatitudeRadius ); currentPoint.Y = p.Y + ( (float)Math.Sin( northSouthTheta ) * radius ); currentPoint.Z = p.Z + ( (float)Math.Sin( eastWestTheta ) * currentLatitudeRadius ); databox.Data.Write( currentPoint ); numVertices++; furtherSouthPoint.X = p.X + ( (float)Math.Cos( eastWestTheta ) * nextLatitudeRadius ); furtherSouthPoint.Y = p.Y + ( (float)Math.Sin( northSouthTheta + LATITUDE_STEP ) * radius ); furtherSouthPoint.Z = p.Z + ( (float)Math.Sin( eastWestTheta ) * nextLatitudeRadius ); databox.Data.Write( furtherSouthPoint ); numVertices++; eastWestTheta += LONGITUDE_STEP; } northSouthTheta += LATITUDE_STEP; } deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 ); deviceContext.InputAssembler.InputLayout = mRenderWireframeInputLayout; deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT, new VertexBufferBinding( mPositionVertexBuffer, POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, 0 ) ); mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() ); mEffect.GetVariableByName( "gColor" ).AsVector().Set( color ); mRenderWireframePass.Apply( deviceContext ); deviceContext.Draw( numVertices, 0 ); }
public void RenderQuadTexture3DWireframe( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 t4, ShaderResourceView texture, Vector3 color, Camera camera ) { RenderQuadTexture3DOnly( deviceContext, p1, p2, p3, p4, t1, t2, t3, t4, texture, camera ); RenderQuadWireframeOnly( deviceContext, p1, p2, p3, p4, color, camera ); }
public void RenderQuadWireframeOnly( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 color, Camera camera ) { RenderLine( deviceContext, p1, p2, color, camera ); RenderLine( deviceContext, p2, p3, color, camera ); RenderLine( deviceContext, p3, p4, color, camera ); RenderLine( deviceContext, p4, p1, color, camera ); }
public void RenderQuadSolidWireframe( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 backgroundColor, Vector3 foregroundColor, Camera camera ) { RenderQuadSolidOnly( deviceContext, p1, p2, p3, p4, backgroundColor, camera ); RenderQuadWireframeOnly( deviceContext, p1, p2, p3, p4, foregroundColor, camera ); }
public void RenderQuadTexture3DOnly( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 t1, Vector3 t2, Vector3 t3, Vector3 t4, ShaderResourceView texture, Camera camera ) { DataBox databox; databox = deviceContext.MapSubresource( mPositionVertexBuffer, 0, QUAD_NUM_VERTICES * POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None ); databox.Data.Write( p1 ); databox.Data.Write( p4 ); databox.Data.Write( p2 ); databox.Data.Write( p3 ); deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 ); databox = deviceContext.MapSubresource( mTexCoordVertexBuffer, 0, QUAD_NUM_VERTICES * TEXCOORD_NUM_COMPONENTS_PER_VERTEX * TEXCOORD_NUM_BYTES_PER_COMPONENT, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None ); databox.Data.Write( t1 ); databox.Data.Write( t4 ); databox.Data.Write( t2 ); databox.Data.Write( t3 ); deviceContext.UnmapSubresource( mTexCoordVertexBuffer, 0 ); deviceContext.InputAssembler.InputLayout = mRenderTexture3DInputLayout; deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT, new VertexBufferBinding( mPositionVertexBuffer, POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, 0 ) ); deviceContext.InputAssembler.SetVertexBuffers( TEXCOORD_SLOT, new VertexBufferBinding( mTexCoordVertexBuffer, TEXCOORD_NUM_COMPONENTS_PER_VERTEX * TEXCOORD_NUM_BYTES_PER_COMPONENT, 0 ) ); mEffect.GetVariableByName( "gTexture3D" ).AsResource().SetResource( texture ); mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() ); mRenderTexture3DPass.Apply( deviceContext ); deviceContext.Draw( QUAD_NUM_VERTICES, 0 ); }
public void RenderQuadSolidOnly( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, Vector3 color, Camera camera ) { DataBox databox = deviceContext.MapSubresource( mPositionVertexBuffer, 0, QUAD_NUM_VERTICES * POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None ); databox.Data.Write( p1 ); databox.Data.Write( p4 ); databox.Data.Write( p2 ); databox.Data.Write( p3 ); deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 ); deviceContext.InputAssembler.InputLayout = mRenderSolidInputLayout; deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip; deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT, new VertexBufferBinding( mPositionVertexBuffer, POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, 0 ) ); mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() ); mEffect.GetVariableByName( "gColor" ).AsVector().Set( color ); mRenderSolidPass.Apply( deviceContext ); deviceContext.Draw( QUAD_NUM_VERTICES, 0 ); }
public void RenderPoint( DeviceContext deviceContext, Vector3 p, Vector3 color, Camera camera ) { var databox = deviceContext.MapSubresource( mPositionVertexBuffer, 0, POINT_NUM_VERTICES * POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, MapMode.WriteDiscard, SlimDX.Direct3D11.MapFlags.None ); databox.Data.Write( p ); deviceContext.UnmapSubresource( mPositionVertexBuffer, 0 ); deviceContext.InputAssembler.InputLayout = mRenderWireframeInputLayout; deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList; deviceContext.InputAssembler.SetVertexBuffers( POSITION_SLOT, new VertexBufferBinding( mPositionVertexBuffer, POSITION_NUM_COMPONENTS_PER_VERTEX * POSITION_NUM_BYTES_PER_COMPONENT, 0 ) ); mEffect.GetVariableByName( "gColor" ).AsVector().Set( color ); mEffect.GetVariableByName( "gTransform" ).AsMatrix().SetMatrix( camera.GetLookAtMatrix() * camera.GetProjectionMatrix() ); mRenderWireframePass.Apply( deviceContext ); deviceContext.Draw( POINT_NUM_VERTICES, 0 ); }
public void RenderBoxWireframeOnly( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 color, Camera camera ) { var base1 = new Vector3( p1.X, p1.Y, p1.Z ); var base2 = new Vector3( p1.X, p1.Y, p2.Z ); var base3 = new Vector3( p2.X, p1.Y, p2.Z ); var base4 = new Vector3( p2.X, p1.Y, p1.Z ); var lid1 = new Vector3( p1.X, p2.Y, p1.Z ); var lid2 = new Vector3( p1.X, p2.Y, p2.Z ); var lid3 = new Vector3( p2.X, p2.Y, p2.Z ); var lid4 = new Vector3( p2.X, p2.Y, p1.Z ); RenderQuadWireframeOnly( deviceContext, base1, base2, base3, base4, color, camera ); RenderQuadWireframeOnly( deviceContext, lid1, lid2, lid3, lid4, color, camera ); RenderQuadWireframeOnly( deviceContext, base1, base2, lid2, lid1, color, camera ); RenderQuadWireframeOnly( deviceContext, base2, base3, lid3, lid2, color, camera ); RenderQuadWireframeOnly( deviceContext, base3, base4, lid4, lid3, color, camera ); RenderQuadWireframeOnly( deviceContext, base4, base1, lid1, lid4, color, camera ); }
public void RenderBoxTexture3DWireframe( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 t1, Vector3 t2, ShaderResourceView texture, Vector3 color, Camera camera ) { RenderBoxTexture3DOnly( deviceContext, p1, p2, t1, t2, texture, camera ); RenderBoxWireframeOnly( deviceContext, p1, p2, color, camera ); }
public void RenderBoxTexture3DOnly( DeviceContext deviceContext, Vector3 p1, Vector3 p2, Vector3 t1, Vector3 t2, ShaderResourceView texture, Camera camera ) { var pBase1 = new Vector3( p1.X, p1.Y, p1.Z ); var pBase2 = new Vector3( p1.X, p1.Y, p2.Z ); var pBase3 = new Vector3( p2.X, p1.Y, p2.Z ); var pBase4 = new Vector3( p2.X, p1.Y, p1.Z ); var pLid1 = new Vector3( p1.X, p2.Y, p1.Z ); var pLid2 = new Vector3( p1.X, p2.Y, p2.Z ); var pLid3 = new Vector3( p2.X, p2.Y, p2.Z ); var pLid4 = new Vector3( p2.X, p2.Y, p1.Z ); var tBase1 = new Vector3( t1.X, t1.Y, t1.Z ); var tBase2 = new Vector3( t1.X, t1.Y, t2.Z ); var tBase3 = new Vector3( t2.X, t1.Y, t2.Z ); var tBase4 = new Vector3( t2.X, t1.Y, t1.Z ); var tLid1 = new Vector3( t1.X, t2.Y, t1.Z ); var tLid2 = new Vector3( t1.X, t2.Y, t2.Z ); var tLid3 = new Vector3( t2.X, t2.Y, t2.Z ); var tLid4 = new Vector3( t2.X, t2.Y, t1.Z ); RenderQuadTexture3DOnly( deviceContext, pBase1, pBase2, pBase3, pBase4, tBase1, tBase2, tBase3, tBase4, texture, camera ); RenderQuadTexture3DOnly( deviceContext, pLid1, pLid2, pLid3, pLid4, tLid1, tLid2, tLid3, tLid4, texture, camera ); RenderQuadTexture3DOnly( deviceContext, pBase1, pBase2, pLid2, pLid1, tBase1, tBase2, tLid2, tLid1, texture, camera ); RenderQuadTexture3DOnly( deviceContext, pBase2, pBase3, pLid3, pLid2, tBase2, tBase3, tLid3, tLid2, texture, camera ); RenderQuadTexture3DOnly( deviceContext, pBase3, pBase4, pLid4, pLid3, tBase3, tBase4, tLid4, tLid3, texture, camera ); RenderQuadTexture3DOnly( deviceContext, pBase4, pBase1, pLid1, pLid4, tBase4, tBase1, tLid1, tLid4, texture, camera ); }