HRESULT HelloShadowVolume::RestoreDeviceObjects() { HRESULT hr; IDirect3DDevice8* device; hr = m_spD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_dpps, &device); if (FAILED(hr)) { MessageBox(0, L"CreateDevice failed", 0, 0); return E_FAIL; } m_spDevice.reset(device, [](IDirect3DDevice8* device) { device->Release(); }); m_spDevice->SetRenderState(D3DRS_ZENABLE, TRUE); m_spDevice->SetRenderState(D3DRS_LIGHTING, FALSE); m_spDevice->SetRenderState(D3DRS_DITHERENABLE, TRUE); D3DVIEWPORT8 viewport = { 0, 0, m_iWidth, m_iHeight }; m_spDevice->SetViewport(&viewport); D3DXVECTOR3 eye(0.0f, 0.0f, 30.0f); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&m_mtView, &eye, &target, &up); D3DXMatrixPerspectiveFovLH(&m_mtProj, 0.2*D3DX_PI, (float)m_iWidth / (float)m_iHeight, 1.0f, 100.f); m_cPlaneTint = { 0.7f, 0.6f, 0.4f, 1.0f }; ID3DXMesh* plane; //D3DXCreatePolygon(m_spDevice.get(), 2.0f, 4, &plane, NULL); CreatePlane(m_spDevice.get(), 15.0f, 10, &plane); //D3DXCreateSphere(m_spDevice.get(), 1.0f,20,20, &plane, NULL); IDirect3DVertexBuffer8* vb; IDirect3DIndexBuffer8* ib; plane->GetVertexBuffer(&vb); plane->GetIndexBuffer(&ib); m_spPlaneVB.reset(vb, [](IDirect3DVertexBuffer8* vb) { vb->Release(); }); m_spPlaneIB.reset(ib, [](IDirect3DIndexBuffer8* ib) { ib->Release(); }); m_dwPlaneNumVertices = plane->GetNumVertices(); m_dwPlaneNumFaces = plane->GetNumFaces(); plane->Release(); DWORD decl[] = { D3DVSD_STREAM(0), D3DVSD_REG(0, D3DVSDT_FLOAT3), D3DVSD_REG(3, D3DVSDT_FLOAT3), D3DVSD_END() }; hr = CreateVSFromBinFile(m_spDevice.get(), decl, L"plane.vso", &m_dwPlaneVSH); if (FAILED(hr)) { MessageBox(0, 0, L"CreateVSFromBinFile failed", 0); return E_FAIL; } hr = CreatePSFromBinFile(m_spDevice.get(), L"plane.pso", &m_dwPlanePSH); if (FAILED(hr)) { MessageBox(0, 0, L"CreatePSFromBinFile failed", 0); return E_FAIL; } D3DXMATRIX Rx, Tz; D3DXMatrixRotationX(&Rx, D3DX_PI*0.5f); D3DXMatrixTranslation(&Tz, 0.0f, -3.0f, 0.0f); m_mtPlaneWorld = Rx * Tz; ID3DXMesh* occluder; CreateOccluder(m_spDevice.get(), &occluder); IDirect3DVertexBuffer8* vbOccluder; IDirect3DIndexBuffer8* ibOccluder; occluder->GetVertexBuffer(&vbOccluder); occluder->GetIndexBuffer(&ibOccluder); m_spOccluderVB.reset(vbOccluder, [](IDirect3DVertexBuffer8* vb) { vb->Release(); }); m_spOccluderIB.reset(ibOccluder, [](IDirect3DIndexBuffer8* ib) { ib->Release(); }); m_dwOccluderNumVertices = occluder->GetNumVertices(); m_dwOccluderNumFaces = occluder->GetNumFaces(); occluder->Release(); hr = CreateVSFromBinFile(m_spDevice.get(), decl, L"occluder.vso", &m_dwOccluderVSH); if (FAILED(hr)) { MessageBox(0, 0, L"CreateVSFromBinFile failed", 0); return E_FAIL; } hr = CreatePSFromBinFile(m_spDevice.get(), L"occluder.pso", &m_dwOccluderPSH); if (FAILED(hr)) { MessageBox(0, 0, L"CreatePSFromBinFile failed", 0); return E_FAIL; } m_cOccluderTint = { 0.3f, 0.0f, 0.8f, 1.0f }; D3DXMATRIX Rz, T; D3DXMatrixTranslation(&T, 5.1f * cosf(0.5), 0.0f, 5.1f * sinf(0.5)); D3DXMatrixIdentity(&m_mtVolumeWorld); D3DXMatrixRotationZ(&Rz, 0.5f); m_mtOccluderWorld = T * Rz; ID3DXMesh* volume; CreateVolume(m_spDevice.get(), &volume); IDirect3DVertexBuffer8* vbVolume; IDirect3DIndexBuffer8* ibVolume; volume->GetVertexBuffer(&vbVolume); volume->GetIndexBuffer(&ibVolume); m_spVolumeVB.reset(vbVolume, [](IDirect3DVertexBuffer8* vb) { vb->Release(); }); m_spVolumeIB.reset(ibVolume, [](IDirect3DIndexBuffer8* ib) { ib->Release(); }); m_dwVolumeNumVertices = volume->GetNumVertices(); m_dwVolumeNumFaces = volume->GetNumFaces(); volume->Release(); hr = CreateVSFromBinFile(m_spDevice.get(), decl, L"volume.vso", &m_dwVolumeVSH); if (FAILED(hr)) { MessageBox(0, 0, L"CreateVSFromBinFile failed", 0); return E_FAIL; } hr = CreatePSFromBinFile(m_spDevice.get(), L"volume.pso", &m_dwVolumePSH); if (FAILED(hr)) { MessageBox(0, 0, L"CreatePSFromBinFile failed", 0); return E_FAIL; } m_cVolumeTint = { 0.7f, 0.0f, 0.0f, 1.0f }; D3DXMATRIX Sx; D3DXMatrixIdentity(&m_mtVolumeWorld); D3DXMatrixScaling(&Sx, 6.0f, 1.0f, 1.0f); D3DXMatrixRotationZ(&Rz, 0.5f); m_mtVolumeWorld = Sx * Rz; return S_OK; }
void VolumeRendering( unsigned char *DstRGB, int ScreenWidth, int ScreenHeight, const int *Data, const int Dims[3], const int *Points, const double ARGB[][4], const int *NumPoints, const int *GradientOpacityThreshold, const double Spacing[3], const int *RendererType, const double *SamplingDistance, const double *ImageSamplingDistance, const double *Ambient, const double *Diffuse, const double *Specular, const int *ParallelProjection ) { try { // ボリュームデータの設定 vtkSmartPointer<vtkImageData> VolumeData = CreateVolume(Data,Dims,Spacing); // ボリュームマッパの設定 vtkSmartPointer<vtkVolumeMapper> VolumeMapper = CreateVolumeMapper(*RendererType,*SamplingDistance,*ImageSamplingDistance); VolumeMapper->SetInput(VolumeData); // 透明度・色の設定 vtkSmartPointer<vtkColorTransferFunction> VolumeColor = vtkSmartPointer<vtkColorTransferFunction>::New(); vtkSmartPointer<vtkPiecewiseFunction> VolumeOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New(); for(int i=0;i<*NumPoints;++i){ VolumeOpacity->AddPoint(Points[i],ARGB[i][0]); VolumeColor->AddRGBPoint(Points[i],ARGB[i][1],ARGB[i][2],ARGB[i][3]); } // 輝度勾配による透明度の設定 vtkSmartPointer<vtkPiecewiseFunction> VolumeGradientOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New(); VolumeGradientOpacity->AddPoint(0, 0.0); VolumeGradientOpacity->AddPoint(*GradientOpacityThreshold, 1.0); // ボリュームデータの属性設定 vtkSmartPointer<vtkVolumeProperty> VolumeProperty = vtkSmartPointer<vtkVolumeProperty>::New(); VolumeProperty->SetColor(VolumeColor); VolumeProperty->SetScalarOpacity(VolumeOpacity); VolumeProperty->SetGradientOpacity(VolumeGradientOpacity); VolumeProperty->SetInterpolationTypeToLinear(); VolumeProperty->ShadeOn(); VolumeProperty->SetAmbient(*Ambient); VolumeProperty->SetDiffuse(*Diffuse); VolumeProperty->SetSpecular(*Specular); // アクタとしてボリュームを作成 vtkSmartPointer<vtkVolume> Volume = vtkSmartPointer<vtkVolume>::New(); Volume->SetMapper(VolumeMapper); Volume->SetProperty(VolumeProperty); // レンダラ・ウィンドウの設定 vtkSmartPointer<vtkRenderer> Renderer = vtkSmartPointer<vtkRenderer>::New(); vtkSmartPointer<vtkRenderWindow> Window = vtkSmartPointer<vtkRenderWindow>::New(); Window->AddRenderer(Renderer); // レンダラにボリュームの追加 Renderer->AddViewProp(Volume); // カメラ位置・方向の設定 vtkCamera *Camera = Renderer->GetActiveCamera(); double *Center = Volume->GetCenter(); Camera->SetFocalPoint(Center[0], Center[1], Center[2]); Camera->SetPosition(Center[0] + Dims[0]*Spacing[0], Center[1], Center[2]); Camera->SetViewUp(0, 0, -1); Camera->SetParallelProjection(*ParallelProjection); // ウィンドウサイズの設定 Window->SetOffScreenRendering(1); Window->SetSize(ScreenWidth, ScreenHeight); vtkSmartPointer<vtkWindowToImageFilter> WtoI = vtkSmartPointer<vtkWindowToImageFilter>::New(); WtoI->SetInput(Window); WtoI->Update(); unsigned char *Image = reinterpret_cast<unsigned char*>(WtoI->GetOutput()->GetScalarPointer()); std::copy(Image,Image+3*ScreenWidth*ScreenHeight,DstRGB); } catch(...) { } }
MockCSIPlugin::MockCSIPlugin() { EXPECT_CALL(*this, GetPluginInfo(_, _, _)) .WillRepeatedly(Return(Status::OK)); // Enable all plugin capabilities by default for testing with the test CSI // plugin in forwarding mode. EXPECT_CALL(*this, GetPluginCapabilities(_, _, _)) .WillRepeatedly(Invoke([]( ServerContext* context, const csi::v0::GetPluginCapabilitiesRequest* request, csi::v0::GetPluginCapabilitiesResponse* response) { response->add_capabilities()->mutable_service()->set_type( csi::v0::PluginCapability::Service::CONTROLLER_SERVICE); return Status::OK; })); EXPECT_CALL(*this, Probe(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, CreateVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, DeleteVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, ControllerPublishVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, ControllerUnpublishVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, ValidateVolumeCapabilities(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, ListVolumes(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, GetCapacity(_, _, _)) .WillRepeatedly(Return(Status::OK)); // Enable all controller capabilities by default for testing with the test CSI // plugin in forwarding mode. EXPECT_CALL(*this, ControllerGetCapabilities(_, _, _)) .WillRepeatedly(Invoke([]( ServerContext* context, const csi::v0::ControllerGetCapabilitiesRequest* request, csi::v0::ControllerGetCapabilitiesResponse* response) { response->add_capabilities()->mutable_rpc()->set_type( csi::v0::ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME); response->add_capabilities()->mutable_rpc()->set_type( csi::v0::ControllerServiceCapability::RPC::PUBLISH_UNPUBLISH_VOLUME); response->add_capabilities()->mutable_rpc()->set_type( csi::v0::ControllerServiceCapability::RPC::GET_CAPACITY); response->add_capabilities()->mutable_rpc()->set_type( csi::v0::ControllerServiceCapability::RPC::LIST_VOLUMES); return Status::OK; })); EXPECT_CALL(*this, NodeStageVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, NodeUnstageVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, NodePublishVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, NodeUnpublishVolume(_, _, _)) .WillRepeatedly(Return(Status::OK)); EXPECT_CALL(*this, NodeGetId(_, _, _)) .WillRepeatedly(Return(Status::OK)); // Enable all node capabilities by default for testing with the test CSI // plugin in forwarding mode. EXPECT_CALL(*this, NodeGetCapabilities(_, _, _)) .WillRepeatedly(Invoke([]( ServerContext* context, const csi::v0::NodeGetCapabilitiesRequest* request, csi::v0::NodeGetCapabilitiesResponse* response) { response->add_capabilities()->mutable_rpc()->set_type( csi::v0::NodeServiceCapability::RPC::STAGE_UNSTAGE_VOLUME); return Status::OK; })); }