| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 | /*=========================================================================  Library:   CTK   Copyright (c) 2010  Kitware Inc.  Licensed under the Apache License, Version 2.0 (the "License");  you may not use this file except in compliance with the License.  You may obtain a copy of the License at      http://www.commontk.org/LICENSE  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and  limitations under the License. =========================================================================*/// Qt includes#include <QTimer>#include <QVBoxLayout>// CTK includes#include "ctkVTKRenderView.h"#include "ctkVTKRenderView_p.h"// VTK includes#include <vtkRendererCollection.h>#include <vtkRenderWindowInteractor.h>#include <vtkTextProperty.h>// --------------------------------------------------------------------------// ctkVTKRenderViewPrivate methods// --------------------------------------------------------------------------ctkVTKRenderViewPrivate::ctkVTKRenderViewPrivate(){  this->Renderer = vtkSmartPointer<vtkRenderer>::New();  this->RenderWindow = vtkSmartPointer<vtkRenderWindow>::New();  this->Axes = vtkSmartPointer<vtkAxesActor>::New();  this->Orientation = vtkSmartPointer<vtkOrientationMarkerWidget>::New();  this->CornerAnnotation = vtkSmartPointer<vtkCornerAnnotation>::New();  this->RenderPending = false;  this->RenderEnabled = false;}// --------------------------------------------------------------------------void ctkVTKRenderViewPrivate::setupCornerAnnotation(){  if (!this->Renderer->HasViewProp(this->CornerAnnotation))    {    this->Renderer->AddViewProp(this->CornerAnnotation);    this->CornerAnnotation->SetMaximumLineHeight(0.07);    vtkTextProperty *tprop = this->CornerAnnotation->GetTextProperty();    tprop->ShadowOn();    }  this->CornerAnnotation->ClearAllTexts();}//---------------------------------------------------------------------------void ctkVTKRenderViewPrivate::setupRendering(){  Q_ASSERT(this->RenderWindow);  this->RenderWindow->SetAlphaBitPlanes(1);  this->RenderWindow->SetMultiSamples(0);  this->RenderWindow->StereoCapableWindowOn();    this->RenderWindow->GetRenderers()->RemoveAllItems();    // Add renderer  this->RenderWindow->AddRenderer(this->Renderer);    // Setup the corner annotation  this->setupCornerAnnotation();  this->VTKWidget->SetRenderWindow(this->RenderWindow);}//---------------------------------------------------------------------------void ctkVTKRenderViewPrivate::setupDefaultInteractor(){  CTK_P(ctkVTKRenderView);  p->setInteractor(this->RenderWindow->GetInteractor());}//---------------------------------------------------------------------------// ctkVTKRenderView methods// --------------------------------------------------------------------------ctkVTKRenderView::ctkVTKRenderView(QWidget* _parent) : Superclass(_parent){  CTK_INIT_PRIVATE(ctkVTKRenderView);  CTK_D(ctkVTKRenderView);    d->VTKWidget = new QVTKWidget(this);  this->setLayout(new QVBoxLayout);  this->layout()->setMargin(0);  this->layout()->setSpacing(0);  this->layout()->addWidget(d->VTKWidget);  d->setupRendering();  d->setupDefaultInteractor();}// --------------------------------------------------------------------------ctkVTKRenderView::~ctkVTKRenderView(){}//----------------------------------------------------------------------------void ctkVTKRenderView::scheduleRender(){  CTK_D(ctkVTKRenderView);  if (!d->RenderEnabled)    {    return;    }  if (!d->RenderPending)    {    d->RenderPending = true;    QTimer::singleShot(0, this, SLOT(forceRender()));    }}//----------------------------------------------------------------------------void ctkVTKRenderView::forceRender(){  CTK_D(ctkVTKRenderView);  if (!d->RenderEnabled)    {    return;    }  d->RenderWindow->Render();  d->RenderPending = false;}//----------------------------------------------------------------------------CTK_GET_CXX(ctkVTKRenderView, vtkRenderWindow*, renderWindow, RenderWindow);//----------------------------------------------------------------------------CTK_GET_CXX(ctkVTKRenderView, vtkRenderWindowInteractor*, interactor, CurrentInteractor);//----------------------------------------------------------------------------void ctkVTKRenderView::setInteractor(vtkRenderWindowInteractor* newInteractor){  CTK_D(ctkVTKRenderView);  d->RenderWindow->SetInteractor(newInteractor);  d->Orientation->SetOrientationMarker(d->Axes);  d->Orientation->SetInteractor(newInteractor);  d->Orientation->SetEnabled(1);  d->Orientation->InteractiveOff();  d->CurrentInteractor = newInteractor; }//----------------------------------------------------------------------------vtkInteractorObserver* ctkVTKRenderView::interactorStyle(){  CTK_D(ctkVTKRenderView);  if (d->CurrentInteractor)    {    return d->CurrentInteractor->GetInteractorStyle();    }  else    {    return 0;    }}//----------------------------------------------------------------------------void ctkVTKRenderView::setCornerAnnotationText(const QString& text){  CTK_D(ctkVTKRenderView);  d->CornerAnnotation->ClearAllTexts();  d->CornerAnnotation->SetText(2, text.toLatin1());}// --------------------------------------------------------------------------void ctkVTKRenderView::setBackgroundColor(double r, double g, double b){  CTK_D(ctkVTKRenderView);  double background_color[3] = {r, g, b};  d->Renderer->SetBackground(background_color);}//----------------------------------------------------------------------------vtkCamera* ctkVTKRenderView::activeCamera(){  CTK_D(ctkVTKRenderView);  if (d->Renderer->IsActiveCameraCreated())    {    return d->Renderer->GetActiveCamera();    }  else    {    return 0;    }}//----------------------------------------------------------------------------void ctkVTKRenderView::resetCamera(){  CTK_D(ctkVTKRenderView);  d->Renderer->ResetCamera();}//----------------------------------------------------------------------------CTK_GET_CXX(ctkVTKRenderView, vtkRenderer*, renderer, Renderer);//----------------------------------------------------------------------------CTK_SET_CXX(ctkVTKRenderView, bool, setRenderEnabled, RenderEnabled);
 |