QmitkRenderWindow::QmitkRenderWindow(QWidget *parent, QString name, mitk::VtkPropRenderer* /*renderer*/, mitk::RenderingManager* renderingManager, mitk::BaseRenderer::RenderingMode::Type renderingMode) : QVTKWidget(parent), m_ResendQtEvents(true), m_MenuWidget(NULL), m_MenuWidgetActivated(false), m_LayoutIndex(0) { // Needed if QVTKWidget2 is used instead of QVTKWidget //this will be fixed in VTK source if change 18864 is accepted /*QGLFormat newform = this->format(); newform.setSamples(8); this->setFormat(newform);*/ if (renderingMode == mitk::BaseRenderer::RenderingMode::DepthPeeling) { GetRenderWindow()->SetMultiSamples(0); GetRenderWindow()->SetAlphaBitPlanes(1); } else if (renderingMode == mitk::BaseRenderer::RenderingMode::MultiSampling) { GetRenderWindow()->SetMultiSamples(8); } else if (renderingMode == mitk::BaseRenderer::RenderingMode::Standard) { GetRenderWindow()->SetMultiSamples(0); } Initialize(renderingManager, name.toStdString().c_str(), renderingMode); // Initialize mitkRenderWindowBase setFocusPolicy(Qt::StrongFocus); setMouseTracking(true); }
QmitkRenderWindow::QmitkRenderWindow(QWidget *parent, QString name, mitk::VtkPropRenderer* /*renderer*/, mitk::RenderingManager* renderingManager,mitk::BaseRenderer::RenderingMode::Type renderingMode) : QVTKWidget(parent), m_ResendQtEvents(true), m_MenuWidget(NULL), m_MenuWidgetActivated(false), m_LayoutIndex(0) { if(renderingMode == mitk::BaseRenderer::RenderingMode::DepthPeeling) { GetRenderWindow()->SetMultiSamples(0); GetRenderWindow()->SetAlphaBitPlanes(1); } else if(renderingMode == mitk::BaseRenderer::RenderingMode::MultiSampling) { GetRenderWindow()->SetMultiSamples(8); } else if(renderingMode == mitk::BaseRenderer::RenderingMode::Standard) { GetRenderWindow()->SetMultiSamples(0); } Initialize(renderingManager, name.toStdString().c_str(),renderingMode); // Initialize mitkRenderWindowBase setFocusPolicy(Qt::StrongFocus); setMouseTracking(true); }
RenderView3D::RenderView3D( QWidget* parent ) : RenderView( parent ) { this->GetRenderWindow()->GetInteractor()->SetDesiredUpdateRate(30); this->GetRenderWindow()->GetInteractor()->SetStillUpdateRate(0.01); GetRenderWindow()->SetAlphaBitPlanes(0); GetRenderWindow()->SetMultiSamples(0); GetRenderer()->SetUseDepthPeeling(true); GetRenderer()->SetMaximumNumberOfPeels(4); GetRenderer()->SetOcclusionRatio(0); m_bShowSliceFrames = true; m_bShowAxes = true; for ( int i = 0; i < 3; i++ ) { m_actorSliceFrames[i] = vtkSmartPointer<vtkActor>::New(); m_actorSliceFrames[i]->SetMapper( vtkSmartPointer<vtkPolyDataMapper>::New() ); m_actorSliceFrames[i]->GetProperty()->SetRepresentationToWireframe(); m_actorSliceFrames[i]->GetProperty()->SetDiffuse( 0.0 ); m_actorSliceFrames[i]->GetProperty()->SetAmbient( 1.0 ); m_bSliceVisibility[i] = true; m_actorSliceBoundingBox[i] = vtkSmartPointer<vtkActor>::New(); m_cubeSliceBoundingBox[i] = vtkSmartPointer<vtkCubeSource>::New(); vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); mapper->SetInputConnection( m_cubeSliceBoundingBox[i]->GetOutputPort() ); m_actorSliceBoundingBox[i]->SetMapper( mapper ); mapper->Update(); m_actorSliceBoundingBox[i]->GetProperty()->SetRepresentationToWireframe(); } HighlightSliceFrame( -1 ); m_cursor3D = new Cursor3D( this ); m_interactorNavigate = new Interactor3DNavigate( this ); m_interactorMeasure = new Interactor3DMeasure( this ); m_interactorVolumeCrop = new Interactor3DVolumeCrop(this); connect(m_cursor3D, SIGNAL(Updated()), this, SLOT(RequestRedraw())); m_actorScalarBar->SetNumberOfLabels( 4 ); m_actorAxesActor = vtkSmartPointer<vtkCubeAxesActor>::New(); m_actorAxesActor->XAxisLabelVisibilityOn(); m_actorAxesActor->YAxisLabelVisibilityOn(); m_actorAxesActor->ZAxisLabelVisibilityOn(); m_actorAxesActor->SetXTitle(""); m_actorAxesActor->SetYTitle(""); m_actorAxesActor->SetZTitle(""); m_actorAxesActor->SetFlyModeToClosestTriad(); m_actorAxesActor->SetCamera(m_renderer->GetActiveCamera()); SetInteractionMode(IM_Navigate); }
/** Default Constructor. Nothing fancy - just basic setup */ VolumeProjectionWidget::VolumeProjectionWidget(QWidget* parent, Qt::WFlags f): QVTKWidget( parent, f), m_volume(vtkVolume::New()), m_renderer(vtkOpenGLRenderer::New()), m_interactorStyle(InteractorStyleVolumeView::New()), m_volumeMapper(vtkFixedPointVolumeRayCastMapper::New()), m_volumeProperty(vtkVolumeProperty::New()), m_opacityTransferFunction(vtkPiecewiseFunction::New()), m_grayTransferFunction(vtkPiecewiseFunction::New()) { m_opacityTransferFunction->AddPoint( -1000 , 0.0 ); // m_opacityTransferFunction->AddPoint( -50 , 0.0 ); // m_opacityTransferFunction->AddPoint( 350 , 0.1 ); m_opacityTransferFunction->AddPoint( 10000 , 0.001 ); // m_grayTransferFunction->AddSegment( -50 , 0.0 , 350 , 1.0 ); m_grayTransferFunction->AddSegment( -4000 , 1.0 , 4000 , 1.0 ); m_volumeProperty->SetScalarOpacity( m_opacityTransferFunction ); m_volumeProperty->SetColor( m_grayTransferFunction ); m_volumeProperty->SetInterpolationTypeToLinear(); // m_volume->SetUserMatrix( m_projectionTransform ); // m_volumeMapper->SetBlendModeToMaximumIntensity(); dynamic_cast<vtkFixedPointVolumeRayCastMapper*>(m_volumeMapper)->SetFinalColorWindow(0.002); dynamic_cast<vtkFixedPointVolumeRayCastMapper*>(m_volumeMapper)->SetFinalColorLevel(0.925); // dynamic_cast<vtkOpenGLVolumeTextureMapper3D*>(m_volumeMapper)->SetBlendModeToComposite(); // dynamic_cast<vtkVolumeTextureMapper3D*>(m_volumeMapper)->SetSampleDistance(.5); // dynamic_cast<vtkVolumeTextureMapper3D*>(m_volumeMapper)->SetBlendModeToMaximumIntensity(); dynamic_cast<InteractorStyleVolumeView*>(m_interactorStyle)->SetRayCastMapper( dynamic_cast<vtkFixedPointVolumeRayCastMapper*>(m_volumeMapper) ); m_volume->SetMapper( m_volumeMapper ); m_volume->SetProperty( m_volumeProperty ); m_renderer->AddViewProp( m_volume ); // m_renderer->GetActiveCamera()->SetEyeAngle(m_renderer->GetActiveCamera()->GetEyeAngle()*2); // Set up the interaction // m_interactorStyle->SetOrientationMatrix( m_projectionTransform ); vtkRenderWindowInteractor *interactor = this->GetInteractor(); interactor->SetInteractorStyle( m_interactorStyle ); GetRenderWindow()->SetStereoTypeToAnaglyph(); GetRenderWindow()->SetAnaglyphColorSaturation(0.0); int anaglyphColorMask[] = {2,5}; GetRenderWindow()->SetAnaglyphColorMask( anaglyphColorMask ); }
void pcl::modeler::RenderWidget::initRenderer() { vtkSmartPointer<vtkRenderWindow> win = GetRenderWindow(); vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New(); win->AddRenderer(renderer); // FPS callback vtkSmartPointer<vtkTextActor> txt = vtkSmartPointer<vtkTextActor>::New (); typedef pcl::visualization::FPSCallback FPSCallback; vtkSmartPointer<FPSCallback> update_fps = vtkSmartPointer<FPSCallback>::New (); update_fps->setTextActor (txt); renderer->AddObserver (vtkCommand::EndEvent, update_fps); renderer->AddActor (txt); // Set up render window win->AlphaBitPlanesOff (); win->PointSmoothingOff (); win->LineSmoothingOff (); win->PolygonSmoothingOff (); win->SwapBuffersOn (); win->SetStereoTypeToAnaglyph (); win->GetInteractor()->SetDesiredUpdateRate (30.0); return; }
bool DisplayManager::AddViewport(const std::string& name, const std::string& camera_name, bool set_as_main, float left, float top, float width, float height) { // Do not add if a Viewport of the same name already exists. if(mViewports.count(name) != 0) return false; // Cannot assign if there is no such camera. if(mCameras.count(camera_name) == 0) return false; std::string viewport_name = name; mViewports.insert(viewport_name, new dt::Viewport); mViewports[name].Initialize((GetRenderWindow()->addViewport(mCameras[camera_name]->GetCamera(), mNextZOrder, left, top, width, height))); mNextZOrder++; if(set_as_main) { mMainViewport = name; } mViewports[name].setBackgroundColour(Ogre::ColourValue(0, 0, 0)); ActivateCamera(camera_name, name); return true; }
static void SaveSliceOrImageAsPNG(mitk::Image::Pointer image, mitk::Image::Pointer mask, std::string path, int index) { // Create a Standalone Datastorage for the single purpose of saving screenshots.. mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); QmitkRenderWindow renderWindow; renderWindow.GetRenderer()->SetDataStorage(ds); auto nodeI = mitk::DataNode::New(); nodeI->SetData(image); auto nodeM = mitk::DataNode::New(); nodeM->SetData(mask); ds->Add(nodeI); ds->Add(nodeM); auto geo = ds->ComputeBoundingGeometry3D(ds->GetAll()); mitk::RenderingManager::GetInstance()->InitializeViews(geo); mitk::SliceNavigationController::Pointer sliceNaviController = renderWindow.GetSliceNavigationController(); unsigned int numberOfSteps = 1; if (sliceNaviController) { numberOfSteps = sliceNaviController->GetSlice()->GetSteps(); sliceNaviController->GetSlice()->SetPos(0); } renderWindow.show(); renderWindow.resize(256, 256); for (unsigned int currentStep = 0; currentStep < numberOfSteps; ++currentStep) { if (sliceNaviController) { sliceNaviController->GetSlice()->SetPos(currentStep); } renderWindow.GetRenderer()->PrepareRender(); vtkRenderWindow* renderWindow2 = renderWindow.GetVtkRenderWindow(); mitk::BaseRenderer* baserenderer = mitk::BaseRenderer::GetInstance(renderWindow2); auto vtkRender = baserenderer->GetVtkRenderer(); vtkRender->GetRenderWindow()->WaitForCompletion(); vtkRenderLargeImage* magnifier = vtkRenderLargeImage::New(); magnifier->SetInput(vtkRender); magnifier->SetMagnification(3.0); std::stringstream ss; ss << path << "_Idx-" << index << "_Step-"<<currentStep<<".png"; std::string tmpImageName; ss >> tmpImageName; auto fileWriter = vtkPNGWriter::New(); fileWriter->SetInputConnection(magnifier->GetOutputPort()); fileWriter->SetFileName(tmpImageName.c_str()); fileWriter->Write(); fileWriter->Delete(); } }
void FieldDataVisualizer::setActiveScalarBarWidget() { myScalarBarWidget->SetResizable(true); myScalarBarWidget->SetInteractor(GetRenderWindow()->GetInteractor()); myScalarBarWidget->GetScalarBarActor()->SetTitle(myVisualizerSetting->PROPERTY_SCALARBAR_TITLE); myScalarBarWidget->GetScalarBarActor()->SetMaximumWidthInPixels(100); myScalarBarWidget->GetScalarBarActor()->SetNumberOfLabels(4); myScalarBarWidget->GetScalarBarActor()->SetLookupTable(hueLut); myScalarBarWidget->EnabledOn(); }
void visualize_histo(const THisto& input_histo, vtkIdType chart_type = vtkChart::LINE, size_t size_x = 640, size_t size_y = 480) { auto chart = chart_from_histogram(input_histo, chart_type); // Set up the view auto view = vtkSmartPointer<vtkContextView>::New(); view->GetScene()->AddItem(chart); view->GetRenderer()->SetBackground(1.0, 1.0, 1.0); view->GetRenderWindow()->SetSize(size_x, size_y); view->GetInteractor()->Initialize(); view->GetInteractor()->Start(); }
/** Set the distance between Camera and Focal Point*/ void VolumeProjectionWidget::setCameraDistance(double dist) { double oldDist = m_renderer->GetActiveCamera()->GetDistance(); double f = dist / oldDist; double *fp = m_renderer->GetActiveCamera()->GetFocalPoint(); double *cp = m_renderer->GetActiveCamera()->GetPosition(); m_renderer->GetActiveCamera()->SetPosition( fp[0] + (cp[0] - fp[0]) * f, fp[1] + (cp[1] - fp[1]) * f, fp[2] + (cp[2] - fp[2]) * f); GetRenderWindow()->Render(); }
void FieldDataVisualizer::displayCompass(void) { vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New(); myOrientationMarkerWidget = vtkSmartPointer<vtkOrientationMarkerWidget>::New(); myOrientationMarkerWidget->SetOutlineColor(0.9300, 0.5700, 0.1300); myOrientationMarkerWidget->SetOrientationMarker(axes); myOrientationMarkerWidget->SetInteractor(GetRenderWindow()->GetInteractor()); myOrientationMarkerWidget->SetViewport(0.0, 0.0, 0.4, 0.4); myOrientationMarkerWidget->SetEnabled(1); myOrientationMarkerWidget->InteractiveOff(); myRenderer->ResetCamera(); myRenderer->GetRenderWindow()->Render(); }
//--------------------------------------------------------------------------- vtkRenderer * __fastcall TvtkBorlandRenderWindow::GetRenderer(void) { if (!FRenderer) { FRenderer = vtkRenderer::New(); GetRenderWindow()->AddRenderer(FRenderer); FRenderer->ResetCamera(); DWORD L = ColorToRGB(Color); double rgb[3] = { GetRValue(L)/255.0, GetGValue(L)/255.0, GetBValue(L)/255.0 }; FRenderer->SetBackground(rgb); } return FRenderer; }
void VolumeProjectionWidget::setStereoMode(int mode) { int anaglyphColorMask[] = {2,5}; switch(mode) { case int(Anaglyph): GetRenderWindow()->SetStereoTypeToAnaglyph(); GetRenderWindow()->SetAnaglyphColorSaturation(0.0); GetRenderWindow()->SetAnaglyphColorMask( anaglyphColorMask ); GetRenderWindow()->StereoRenderOn(); break; case int(Interlaced): GetRenderWindow()->SetStereoTypeToInterlaced(); GetRenderWindow()->StereoRenderOn(); break; default: GetRenderWindow()->StereoRenderOff(); break; } GetRenderWindow()->Render(); }
FieldDataVisualizer::FieldDataVisualizer(QWidget* parent): QVTKOpenGLWidget(parent){ vtkNew<vtkGenericOpenGLRenderWindow> window; SetRenderWindow(window.Get()); // Camera vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New(); camera->SetViewUp(0, 1, 0); camera->SetPosition(0, 0, 10); camera->SetFocalPoint(0, 0, 0); // Renderer myRenderer = vtkSmartPointer<vtkRenderer>::New(); myRenderer->SetActiveCamera(camera); // Setup the background gradient myRenderer->GradientBackgroundOn(); myBGColor = QColor(255, 235, 100); setBackgroundGradient(myBGColor.red(), myBGColor.green(), myBGColor.blue()); GetRenderWindow()->AddRenderer(myRenderer); //Draw compass displayCompass(); // Some members mySelectedMapper = vtkSmartPointer<vtkDataSetMapper>::New(); mySelectedActor = vtkSmartPointer<vtkActor>::New(); myScalarBarWidget = vtkSmartPointer<vtkScalarBarWidget>::New(); selectedPickActor = vtkActor::New(); //mySelectedProperty = vtkSmartPointer<vtkProperty>::New(); myEdgeActor = vtkActor::New(); edgeExtractor = vtkExtractEdges::New(); edgeMapper = vtkPolyDataMapper::New(); warpFilter = vtkWarpVector::New(); hueLut = vtkLookupTable::New(); //Properties isAnimationSceneInstantiated = false; myVtkViewer = new VtkViewer(*this); setPickerModeNone(); setViewMode(true); myHarmonicScale = 1; myVtkAnimatorActive = false; }
float RiskGameView::GetHeight() { return (float)GetRenderWindow()->getSize().x; }
/** Set the Eye Angle for Stereo-Projections*/ void VolumeProjectionWidget::setEyeAngle(double ang) { m_renderer->GetActiveCamera()->SetEyeAngle( ang ); if (GetRenderWindow()->GetStereoRender()) GetRenderWindow()->Render(); }
void FieldDataVisualizer::plotVectorFieldAtIndex(int _index) { myVtkAnimator->plotVectorFieldAtIndex(_index); getRenderer()->Render(); GetRenderWindow()->Render(); }
vtkSmartPointer<vtkRenderer> pcl::modeler::RenderWidget::getRenderer() { return (GetRenderWindow()->GetRenderers()->GetFirstRenderer()); }
void FieldDataVisualizer::mousePressEvent(QMouseEvent * _event) { // The button mappings can be used as a mask. This code prevents conflicts // when more than one button pressed simultaneously. if (_event->button() & Qt::LeftButton) { if ((!myRotateMode && myCurrentPickerType != STACCATO_Picker_None) && myVisualizerSetting->PROPERTY_RESULTS_AVALABLE) { // Some Picker VtkObjects vtkSmartPointer<vtkDataSetMapper> selectedPickMapper = vtkDataSetMapper::New(); // Remove selectionPickActor static bool mySelectedActorActive = false; if (mySelectedActorActive) { myRenderer->RemoveActor(selectedPickActor); myRenderer->GetRenderWindow()->Render(); } // Get the location of the click (in window coordinates) int* pos = GetRenderWindow()->GetInteractor()->GetEventPosition(); vtkSmartPointer<vtkPointPicker> pointPicker = vtkSmartPointer<vtkPointPicker>::New(); vtkSmartPointer<vtkCellPicker> cellPicker = vtkSmartPointer<vtkCellPicker>::New(); pointPicker->SetTolerance(0.05); cellPicker->SetTolerance(1e-6); // Dettach Renderer from other actors other than Surface // Remove edgeActor if (myVisualizerSetting->myFieldDataSetting->getEdgeProperty()) myRenderer->RemoveActor(myEdgeActor); // Enable Surface Actor myRenderer->AddActor(mySelectedActor); // Pick from this location. pointPicker->Pick(pos[0], pos[1], 0, myRenderer); cellPicker->Pick(pos[0], pos[1], 0, myRenderer); double* worldPosition = pointPicker->GetPickPosition(); std::cout << "Element id is: " << cellPicker->GetCellId() << std::endl; std::cout << "Node id is: " << pointPicker->GetPointId() << std::endl; // Store the Pick mySelectedNodes.push_back(pointPicker->GetPointId()); mySelectedElements.push_back(cellPicker->GetCellId()); if (myCurrentPickerType != STACCATO_Picker_None) { if (pointPicker->GetPointId() != -1 && cellPicker->GetCellId() != -1) { std::cout << "Pick position is: " << worldPosition[0] << " " << worldPosition[1] << " " << worldPosition[2] << endl; vtkSmartPointer<vtkIdTypeArray> ids = vtkSmartPointer<vtkIdTypeArray>::New(); ids->SetNumberOfComponents(1); if (myCurrentPickerType == STACCATO_Picker_Element) { ids->InsertNextValue(cellPicker->GetCellId()); vtkSmartPointer<vtkIdList> ids_points = vtkIdList::New(); } else if (myCurrentPickerType == STACCATO_Picker_Node) { ids->InsertNextValue(pointPicker->GetPointId()); } vtkSmartPointer<vtkSelectionNode> selectionNode = vtkSmartPointer<vtkSelectionNode>::New(); if (myCurrentPickerType == STACCATO_Picker_Element) { selectionNode->SetFieldType(vtkSelectionNode::CELL); } else if (myCurrentPickerType == STACCATO_Picker_Node) { selectionNode->SetFieldType(vtkSelectionNode::POINT); } selectionNode->SetContentType(vtkSelectionNode::INDICES); selectionNode->SetSelectionList(ids); vtkSmartPointer<vtkSelection> selection = vtkSmartPointer<vtkSelection>::New(); selection->AddNode(selectionNode); vtkSmartPointer<vtkExtractSelection> extractSelection = vtkSmartPointer<vtkExtractSelection>::New(); extractSelection->SetInputData(0, myRenderer->GetActors()->GetLastActor()->GetMapper()->GetInput()); extractSelection->SetInputData(1, selection); extractSelection->Update(); // In selection vtkSmartPointer<vtkUnstructuredGrid> selected = vtkSmartPointer<vtkUnstructuredGrid>::New(); selected->ShallowCopy(extractSelection->GetOutput()); std::cout << "There are " << selected->GetNumberOfPoints() << " points in the selection." << std::endl; std::cout << "There are " << selected->GetNumberOfCells() << " cells in the selection." << std::endl; selectedPickMapper->SetInputData(selected); selectedPickActor->SetMapper(selectedPickMapper); if (myCurrentPickerType == STACCATO_Picker_Element) { selectedPickActor->GetProperty()->SetColor(1, 0, 0); selectedPickActor->GetProperty()->SetPointSize(8.0); selectedPickActor->GetProperty()->EdgeVisibilityOff(); selectedPickActor->GetProperty()->SetEdgeColor(0, 0, 1); selectedPickActor->GetProperty()->SetLineWidth(4.0); selectedPickMapper->ScalarVisibilityOff(); } else if (myCurrentPickerType == STACCATO_Picker_Node) { selectedPickActor->GetProperty()->SetColor(0, 0, 1); selectedPickActor->GetProperty()->SetPointSize(10.0); selectedPickMapper->ScalarVisibilityOff(); } myRenderer->AddActor(selectedPickActor); mySelectedActorActive = true; if (observers.size() != 0) { this->notify(); } } } // Attach Model View Properties to Renderer if (myVisualizerSetting->myFieldDataSetting->getSurfaceProperty()) { mySelectedActor->SetMapper(mySelectedMapper); myRenderer->AddActor(mySelectedActor); } else myRenderer->RemoveActor(mySelectedActor); if (myVisualizerSetting->myFieldDataSetting->getEdgeProperty()) myRenderer->AddActor(myEdgeActor); myRenderer->GetRenderWindow()->Render(); } } else if (_event->button() & Qt::RightButton) { } else if (_event->button() & Qt::MidButton) { } QVTKOpenGLWidget::mouseReleaseEvent(_event); }
void QmitkRenderWindow::paintEvent(QPaintEvent* /*event*/) { //We are using our own interaction and thus have to call the rendering manually. this->GetRenderer()->GetRenderingManager()->RequestUpdate(GetRenderWindow()); }
float RiskGameView::GetWidth() { return (float)GetRenderWindow()->getSize().y; }