PelVis
Public Member Functions | List of all members
MyRenderer Class Reference

#include <MyRenderer.h>

Public Member Functions

 MyRenderer (bool isSplitted, vtkRenderWindow *renderWindow=nullptr)
 
 ~MyRenderer ()
 
void claculateDistanceToActor (int keyMainActor, int keyTumorActor, bool splittedMiddle=false, bool splittedBorder=false)
 
void LoadPolydataFromFile (const char *filename, vtkMatrix4x4 *viewMatrix=NULL)
 
void LoadShaders (QString path)
 
vtkSmartPointer< MyActorCopyActor (vtkSmartPointer< MyActor > actor, QString name)
 
void SplitPolygons ()
 
void LinkLabelToShader (int label, QString name, vtkSmartPointer< MyShaderCallback > callback=0)
 
void SetShadingProperties ()
 
void SetCameraProperties (double cameraPosition[3]=CAMERAPOSITION, double focalPoint[3]=FOCALPOINT, double viewUp[3]=CAMERAVIEWUP, double zoom=ZOOM)
 
void Begin ()
 
void SetDefaults ()
 
vtkSmartPointer< vtkPolyData > FusePolygons (vtkSmartPointer< vtkPolyData > polyData1, vtkSmartPointer< vtkPolyData > polyData2)
 
vtkSmartPointer< vtkPolyData > CloseOpenPolygons (vtkSmartPointer< vtkPolyData > polyData)
 
void showTargetStructure (int keyTargetStructure, int keyRiskStructure)
 
vtkSmartPointer< vtkPolyData > SplitPolygon (int actorID, bool safeToPolyDataMap=true)
 
vtkSmartPointer< vtkRenderWindow > GetRenderWindow () const
 
void ConnectInteractors ()
 
vtkSmartPointer< vtkRenderer > GetRenderer () const
 
void copyData (MyRenderer *renderer)
 
double * GetOriginOfClipping ()
 
double * GetNormalOfClipping ()
 
vtkSmartPointer< vtkPlaneSource > GetClippingPlane ()
 
void CreateClippingPlane (vtkSmartPointer< vtkPlaneSource > from)
 
void CreateClippingPlane ()
 
void UpdateClippingPlane (double normal[3])
 
void UpdateClippingPlane (double step)
 

Detailed Description

Class which takes care of preparing the Data/Information for the shaders

Definition at line 53 of file MyRenderer.h.

Constructor & Destructor Documentation

◆ MyRenderer()

MyRenderer::MyRenderer ( bool  isSplitted,
vtkRenderWindow *  renderWindow = nullptr 
)

Constructor of the RenderObject if the flag isSplitted is true the Renderer is used for the visualization of the clipped data

Definition at line 172 of file MyRenderer.cpp.

173 {
174  if (renderWindow != nullptr)
175  {
176  // does not work properly
177  this->renderWindow = renderWindow;
178  this->renderer = vtkSmartPointer<vtkRenderer>::New();
179  this->isSplitted = isSplitted;
180  }
181  else
182  {
183  this->renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
184  this->renderer = vtkSmartPointer<vtkRenderer>::New();
185  this->isSplitted = isSplitted;
186  }
187 }

◆ ~MyRenderer()

MyRenderer::~MyRenderer ( )

Definition at line 190 of file MyRenderer.cpp.

191 {
192 }

Member Function Documentation

◆ Begin()

void MyRenderer::Begin ( )

starts the renderloop.

Definition at line 827 of file MyRenderer.cpp.

828 {
829  renderWindow->Render();
830  iren->Start();
831 }

◆ claculateDistanceToActor()

void MyRenderer::claculateDistanceToActor ( int  keyMainActor,
int  keyTumorActor,
bool  splittedMiddle = false,
bool  splittedBorder = false 
)

calculates the distance between two actors and stores the minimal distances as scalar value for each Point at the MainActor it also generates a colormap with which the distance values can be decoded as color(red near, white far away) furthermore it shows black isolines at specified distance values

Definition at line 207 of file MyRenderer.cpp.

208 {
209  auto input1 = labeledPolydata.value(keyMainActor);
210  auto input2 = labeledPolydata.value(keyTumorActor);
211 
212  if (isSplitted && splittedMiddle)
213  {
214  input1 = labeledPolydataSplitted.value(keyMainActor);
215  input2 = labeledPolydataSplitted.value(keyTumorActor);
216  }
217 
218  vtkSmartPointer<vtkCleanPolyData> clean1 =
219  vtkSmartPointer<vtkCleanPolyData>::New();
220 
221 
222  clean1->SetInputData(input1);
223 
224  vtkSmartPointer<vtkCleanPolyData> clean2 =
225  vtkSmartPointer<vtkCleanPolyData>::New();
226  clean2->SetInputData(input2);
227 
228  vtkSmartPointer<vtkDistancePolyDataFilter> distanceFilter =
229  vtkSmartPointer<vtkDistancePolyDataFilter>::New();
230 
231  distanceFilter->SetInputConnection(0, clean1->GetOutputPort());
232  distanceFilter->SetInputConnection(1, clean2->GetOutputPort());
233  distanceFilter->SignedDistanceOff();
234  distanceFilter->Update();
235 
236  auto output = distanceFilter->GetOutput();
237 
238  auto labels = output->GetPointData();
239 
240  if (output->GetPointData()->GetScalars() == NULL)
241  return;
242  int idx = vtkDoubleArray::SafeDownCast(output->GetPointData()->GetScalars())->GetSize();
243  double max = 0.0;
244  double min = 10000.0;
245 
246  for (int i = 0; i < idx; i++)
247  {
248  double currentDistance = vtkDoubleArray::SafeDownCast(output->GetPointData()->GetScalars())->GetValue(i);
249  if (currentDistance > max)
250  max = currentDistance;
251  if (currentDistance < min)
252  min = currentDistance;
253 
254  }
255 
256 
257  vtkSmartPointer<vtkPolyDataMapper> mapper =
258  vtkSmartPointer<vtkPolyDataMapper>::New();
259  mapper->SetInputData(output);
260  mapper->SetScalarRange(
261  distanceFilter->GetOutput()->GetPointData()->GetScalars()->GetRange()[0],
262  distanceFilter->GetOutput()->GetPointData()->GetScalars()->GetRange()[1]);
263  mapper->InterpolateScalarsBeforeMappingOn();
264 
265 
266 
267  vtkSmartPointer<vtkActor> actor =
268  vtkSmartPointer<vtkActor>::New();
269  actor->SetMapper(mapper);
270 
271  vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
272 
273  int maxInt = (int)max;
274 
275 
276  vtkSmartPointer<vtkPolyDataMapper> mapperSplitt =
277  vtkSmartPointer<vtkPolyDataMapper>::New();
278  mapperSplitt->SetInputData(output);
279  mapperSplitt->SetScalarRange(
280  distanceFilter->GetOutput()->GetPointData()->GetScalars()->GetRange()[0],
281  distanceFilter->GetOutput()->GetPointData()->GetScalars()->GetRange()[1]);
282  mapperSplitt->InterpolateScalarsBeforeMappingOn();
283 
284  vtkSmartPointer<vtkActor> actorSplitted =
285  vtkSmartPointer<vtkActor>::New();
286  actorSplitted->SetMapper(mapperSplitt);
287 
288  vtkSmartPointer<vtkLookupTable> lookupTableSplitted = vtkSmartPointer<vtkLookupTable>::New();
289  lookupTableSplitted->SetTableRange(0, maxInt * 2);
290  lookupTableSplitted->SetNumberOfTableValues(maxInt * 2);
291 
292  lookupTable->SetTableRange(0, maxInt * 2);
293  lookupTable->SetNumberOfTableValues(maxInt * 2);
294 
295  int count = 0;
296  int countColor = 0;
297 
298  for (int i = 0; i < (maxInt * 2) - 1; i++)
299  {
300  while (count < 2)
301  {
302  if (splittedBorder)
303  {
304  lookupTable->SetTableValue(i, 1.0, (double)countColor / maxInt, (double)countColor / maxInt, 1);
305  }
306  else if (i % isoLineDistance == 0 && i != 0)
307  {
308  if (splittedMiddle)
309  lookupTableSplitted->SetTableValue(i, 0.0, 0.00, 0.00, 1);
310  else
311  lookupTable->SetTableValue(i, 0.0, 0.00, 0.00, 1);
312  }
313  else
314  {
315  if (splittedMiddle)
316  lookupTableSplitted->SetTableValue(i, 0.6, 0.60, 0.60, 1);
317  else
318  lookupTable->SetTableValue(i, 1.0, (double)countColor / maxInt, (double)countColor / maxInt, 1);
319  }
320  count++;
321  i++;
322  }
323  i--;
324  count = 0;
325  countColor++;
326  }
327 
328  lookupTable->Build();
329  lookupTableSplitted->Build();
330 
331  actor->GetMapper()->SetLookupTable(lookupTable);
332  actorSplitted->GetMapper()->SetLookupTable(lookupTableSplitted);
333 
334  if (!splittedMiddle)
335  {
336  renderer->AddActor(actor);
337  }
338  if (splittedMiddle && !splittedBorder)
339  renderer->AddActor(actorSplitted);
340 
341 }

◆ CloseOpenPolygons()

vtkSmartPointer< vtkPolyData > MyRenderer::CloseOpenPolygons ( vtkSmartPointer< vtkPolyData >  polyData)

CloseOpenPolygongs extracts the edges of the polyData and uses the vtkStripper which connects the edges with lines and generate polygons out of the lines to generate a set of Polygons which can be used to close the input polygonData It returns the set of polygons

Definition at line 361 of file MyRenderer.cpp.

362 {
363  vtkSmartPointer<vtkDataSetMapper> clipMapper =
364  vtkSmartPointer<vtkDataSetMapper>::New();
365  clipMapper->SetInputData(polyData);
366 
367  vtkSmartPointer<vtkActor> clipActor =
368  vtkSmartPointer<vtkActor>::New();
369  clipActor->SetMapper(clipMapper);
370  clipActor->GetProperty()->SetInterpolationToFlat();
371 
372  // Now extract feature edges
373  vtkSmartPointer<vtkFeatureEdges> boundaryEdges =
374  vtkSmartPointer<vtkFeatureEdges>::New();
375  boundaryEdges->SetInputData(polyData);
376  boundaryEdges->BoundaryEdgesOn();
377  boundaryEdges->FeatureEdgesOff();
378  boundaryEdges->NonManifoldEdgesOff();
379  boundaryEdges->ManifoldEdgesOff();
380 
381  vtkSmartPointer<vtkStripper> boundaryStrips =
382  vtkSmartPointer<vtkStripper>::New();
383  boundaryStrips->SetInputConnection(boundaryEdges->GetOutputPort());
384  boundaryStrips->Update();
385 
386  // Change the polylines into polygons
387  vtkSmartPointer<vtkPolyData> boundaryPoly =
388  vtkSmartPointer<vtkPolyData>::New();
389  boundaryPoly->SetPoints(boundaryStrips->GetOutput()->GetPoints());
390  boundaryPoly->SetPolys(boundaryStrips->GetOutput()->GetLines());
391 
392  return boundaryPoly;
393 }

◆ ConnectInteractors()

void MyRenderer::ConnectInteractors ( )

adds all actors of actorMap to the renderer and connects iren.

Definition at line 736 of file MyRenderer.cpp.

737 {
738  renderWindow->AddRenderer(renderer.Get());
739 
740  for (auto val : actorMap.values())
741  renderer->AddActor(val);
742 
743  iren->SetRenderWindow(renderWindow.GetPointer());
744 
745  if (!isSplitted)
746  {
747  vtkSmartPointer<KeyPressInteractorStyle> style =
748  vtkSmartPointer<KeyPressInteractorStyle>::New();
749  iren->SetInteractorStyle(style);
750  style->SetCurrentRenderer(renderer);
751  style->renderer = this;
752  renderer->AddActor(clippingActor);
753  }
754 }

◆ CopyActor()

vtkSmartPointer< MyActor > MyRenderer::CopyActor ( vtkSmartPointer< MyActor actor,
QString  name 
)

returns a copy of the MyObject object with a given name. All information about the shaders is also copied

Definition at line 678 of file MyRenderer.cpp.

679 {
680 
681  vtkSmartPointer<vtkOpenGLPolyDataMapper> mapper = vtkSmartPointer<vtkOpenGLPolyDataMapper>::New();
682  vtkSmartPointer<MyActor> actor;
683  actor = CreateActor(GetStructureType(name));
684  mapper->SetVertexShaderCode(reinterpret_cast<vtkOpenGLPolyDataMapper*>(from->GetMapper())->GetVertexShaderCode());
685  mapper->SetFragmentShaderCode(reinterpret_cast<vtkOpenGLPolyDataMapper*>(from->GetMapper())->GetFragmentShaderCode());
686  actor->SetMapper(mapper);
687  actor->LinkCallback();
688  return actor;
689 
690 }

◆ copyData()

void MyRenderer::copyData ( MyRenderer renderer)

copy the actor - data from the renderer to the renderer of the current object

Definition at line 756 of file MyRenderer.cpp.

757 {
758  this->actorMap;
759 
760  for (auto key : renderer->actorMap.keys())
761  {
762  auto actor = renderer->actorMap.find(key).value();
763 
764 
765  this->actorMap.insert(key, CopyActor(actor, key));
766  }
767 
768  this->labeledPolydata = renderer->labeledPolydata;
769 }
vtkSmartPointer< MyActor > CopyActor(vtkSmartPointer< MyActor > actor, QString name)
Definition: MyRenderer.cpp:678

References CopyActor().

◆ CreateClippingPlane() [1/2]

void MyRenderer::CreateClippingPlane ( vtkSmartPointer< vtkPlaneSource >  from)

generates a new clippingPlaneSource with the same values as from

Definition at line 778 of file MyRenderer.cpp.

779 {
780  clippingPlaneSource = vtkSmartPointer<vtkPlaneSource>::New();
781  clippingPlaneSource->SetOrigin(from->GetOrigin());
782  clippingPlaneSource->SetPoint1(from->GetPoint1());
783  clippingPlaneSource->SetPoint2(from->GetPoint2());
784  clippingPlaneSource->Update();
785 }

◆ CreateClippingPlane() [2/2]

void MyRenderer::CreateClippingPlane ( )

generates the ClippingPlaneSource with the default values

Definition at line 787 of file MyRenderer.cpp.

788 {
789 
790  vtkSmartPointer<vtkNamedColors> colors =
791  vtkSmartPointer<vtkNamedColors>::New();
792 
793  clippingPlaneSource = vtkSmartPointer<vtkPlaneSource>::New();
794 
795  clippingPlaneSource->SetOrigin(-150, -150, 0.0);
796  clippingPlaneSource->SetPoint1(150.0, -150.0, 0.0);
797  clippingPlaneSource->SetPoint2(-150.0, 150.0, 0.0);
798 
799  clippingPlaneSource->Update();
800 
801 
802 
803  vtkPolyData* plane = clippingPlaneSource->GetOutput();
804 
805  // Create a mapper and actor
806  vtkSmartPointer<vtkPolyDataMapper> mapper =
807  vtkSmartPointer<vtkPolyDataMapper>::New();
808  mapper->SetInputData(plane);
809 
810  vtkSmartPointer<vtkActor> actor =
811  vtkSmartPointer<vtkActor>::New();
812  actor->SetMapper(mapper);
813  actor->GetProperty()->SetOpacity(0.4);
814  actor->GetProperty()->SetColor(colors->GetColor3d("Cyan").GetData());
815 
816  clippingActor = actor;
817 
818 }

◆ FusePolygons()

vtkSmartPointer< vtkPolyData > MyRenderer::FusePolygons ( vtkSmartPointer< vtkPolyData >  polyData1,
vtkSmartPointer< vtkPolyData >  polyData2 
)

This function is used to combine two different vtkPolyData object which each other. It returns a new vtkPolyData object which contains the information of both input objects

Definition at line 344 of file MyRenderer.cpp.

345 {
346  //Append the two meshes
347  vtkSmartPointer<vtkAppendPolyData> appendFilter =
348  vtkSmartPointer<vtkAppendPolyData>::New();
349  appendFilter->AddInputData(polyData1);
350  appendFilter->AddInputData(polyData2);
351  appendFilter->Update();
352 
353  // Remove any duplicate points.
354  vtkSmartPointer<vtkCleanPolyData> cleanFilter =
355  vtkSmartPointer<vtkCleanPolyData>::New();
356  cleanFilter->SetInputConnection(appendFilter->GetOutputPort());
357  cleanFilter->Update();
358  return cleanFilter->GetOutput();
359 }

◆ GetClippingPlane()

vtkSmartPointer<vtkPlaneSource> MyRenderer::GetClippingPlane ( )
inline

returns the clippingPlaneSource

Definition at line 189 of file MyRenderer.h.

189 { return clippingPlaneSource; }

◆ GetNormalOfClipping()

double* MyRenderer::GetNormalOfClipping ( )
inline

returns the normal of the clippingPlaneSource

Definition at line 184 of file MyRenderer.h.

184 { return clippingPlaneSource->GetNormal(); }

◆ GetOriginOfClipping()

double* MyRenderer::GetOriginOfClipping ( )
inline

returns the Origin of the clippingPlaneSource

Definition at line 179 of file MyRenderer.h.

179 { return clippingPlaneSource->GetOrigin(); }

◆ GetRenderer()

vtkSmartPointer<vtkRenderer> MyRenderer::GetRenderer ( ) const
inline

returns the current renderer

Definition at line 167 of file MyRenderer.h.

167 { return renderer; }

◆ GetRenderWindow()

vtkSmartPointer<vtkRenderWindow> MyRenderer::GetRenderWindow ( ) const
inline

Definition at line 157 of file MyRenderer.h.

157 { return renderWindow; };

◆ LinkLabelToShader()

void MyRenderer::LinkLabelToShader ( int  label,
QString  name,
vtkSmartPointer< MyShaderCallback callback = 0 
)

links the polydata in labeledPolydata with key label to the actor in actorMap of key name and sets a custom callback if callback is not null. if no callback is given, default callback will be set, which depends on class of actor.

Definition at line 704 of file MyRenderer.cpp.

705 {
706  auto entry = actorMap.find(name);
707  if (entry == actorMap.end())
708  {
709  qDebug() << "no " << name << " shader defined.";
710  return;
711  }
712 
713  auto dataEntry = labeledPolydata.find(label);
714  if (dataEntry == labeledPolydata.end())
715  {
716  qDebug() << "no structure of label " << QString::number(label) << " found.";
717  return;
718  }
719 
720  vtkSmartPointer<MyActor> actor = entry.value();
721 
722  actor->LinkRenderer(renderer);
723  actor->LinkPolydata(dataEntry.value());
724  actor->LinkCallback(callback);
725 }

◆ LoadPolydataFromFile()

void MyRenderer::LoadPolydataFromFile ( const char *  filename,
vtkMatrix4x4 *  viewMatrix = NULL 
)

loads the polydata from file and fills the labeledPolydata map

Definition at line 503 of file MyRenderer.cpp.

504 {
505  vtkSmartPointer<vtkGenericDataObjectReader> reader =
506  vtkSmartPointer<vtkGenericDataObjectReader>::New();
507  reader->SetFileName(filename);
508  reader->Update();
509 
510  if (reader->IsFilePolyData())
511  {
512  vtkPolyData* output = reader->GetPolyDataOutput();
513  completeData = reader->GetPolyDataOutput();
514 
515 
516  // translating the polydata to the center of mass to allow easier clipping
517  vtkSmartPointer<vtkCenterOfMass> centerOfMassFilter =
518  vtkSmartPointer<vtkCenterOfMass>::New();
519  centerOfMassFilter->SetInputData(output);
520 
521  centerOfMassFilter->SetUseScalarsAsWeights(false);
522  centerOfMassFilter->Update();
523 
524  double center[3];
525  centerOfMassFilter->GetCenter(center);
526 
527 
528  vtkSmartPointer<vtkTransform> translation =
529  vtkSmartPointer<vtkTransform>::New();
530 
531  translation->Translate(-center[0], -center[1], -center[2]);
532 
533  vtkSmartPointer<vtkTransformPolyDataFilter> transformFilterPoly =
534  vtkSmartPointer<vtkTransformPolyDataFilter>::New();
535  transformFilterPoly->AddInputData(output);
536  transformFilterPoly->SetTransform(translation);
537  transformFilterPoly->Update();
538 
539  output = transformFilterPoly->GetOutput();
540 
541 
542 
543  auto polys = output->GetPolys();
544  vtkSmartPointer<vtkIdList> pts = vtkSmartPointer<vtkIdList>::New();
545 
546  int idx = 0;
547  auto labels = output->GetCellData()->GetArray(0);
548  qDebug() << "output has " << labels->GetSize() << " labels.";
549  int mlabel = 2;
550 
551  vtkSmartPointer<vtkCellArray> carr;
552 
553  QMap<int, vtkSmartPointer<vtkCellArray>> carrs;
554 
555  while (polys->GetNextCell(pts))
556  {
557  int lbl = labels->GetComponent(idx++, 0);
558 
559  auto entry = carrs.find(lbl);
560  if (entry == carrs.end())
561  {
562 
563  qDebug() << "creating new entry for label " << lbl;
564  carr = vtkSmartPointer<vtkCellArray>::New();
565  carrs.insert(lbl, carr);
566 
567  }
568  else
569  {
570  carr = entry.value();
571  }
572 
573  int a = pts->GetId(0);
574  int b = pts->GetId(1);
575  int c = pts->GetId(2);
576  carr->InsertNextCell(3);
577  carr->InsertCellPoint(pts->GetId(0));
578  carr->InsertCellPoint(pts->GetId(1));
579  carr->InsertCellPoint(pts->GetId(2));
580 
581  }
582 
583 
584  for (int key : carrs.keys())
585  {
586  vtkSmartPointer<vtkPolyData> c = vtkSmartPointer<vtkPolyData>::New();
587  c->DeepCopy(output);
588  c->SetPolys(carrs.find(key).value());
589 
590  if (!isSplitted)
591  labeledPolydata.insert(key, c);
592  else
593  {
594  labeledPolydataSplitted.insert(key, c);
595  SplitPolygon(key);
596  }
597  }
598 
599  }
600 }
vtkSmartPointer< vtkPolyData > SplitPolygon(int actorID, bool safeToPolyDataMap=true)
Definition: MyRenderer.cpp:398

References SplitPolygon().

◆ LoadShaders()

void MyRenderer::LoadShaders ( QString  path)

loads shaders from directory path and fills actorMap. if custom class exists for some shader name (i.e. "context", ...) custom actor class will be used. MyActor is used otherwise.

Definition at line 602 of file MyRenderer.cpp.

603 {
604  QDir dir(path);
605  foreach(const QFileInfo &info, dir.entryInfoList(QDir::Files | QDir::NoDotAndDotDot)) {
606  if (info.isFile()) {
607 
608  qDebug() << info.fileName();
609  qDebug() << info.filePath();
610  qDebug() << info.suffix();
611 
612  ShaderType type = GetShaderType(info.suffix());
613  QString name = info.fileName().mid(0, info.fileName().length() - info.suffix().length() - 1);
614 
615  // compile shader code
616  std::string code;
617  filehandling::readFromFile(info.filePath().toUtf8(), code);
618 
619  vtkSmartPointer<vtkOpenGLPolyDataMapper> mapper;
620  vtkSmartPointer<MyActor> actor;
621 
622  auto entry = actorMap.find(name);
623  if (entry == actorMap.end()) {
624  qDebug() << "no actor for " << name << " exists. creating new.";
625 
626  mapper = vtkSmartPointer<vtkOpenGLPolyDataMapper>::New();
627  actor = CreateActor(GetStructureType(name));
628  actor->SetMapper(mapper);
629  actor->LinkCallback();
630  actorMap.insert(name, actor);
631  }
632  else
633  {
634  qDebug() << "adding code to " << name << ".";
635  actor = entry.value();
636  mapper = reinterpret_cast<vtkOpenGLPolyDataMapper*>(actor->GetMapper());
637  }
638 
639  switch (type)
640  {
641  case VERTEX_SHADER:
642  mapper->SetVertexShaderCode(code.c_str());
643  qDebug() << "added shader type " << type;
644  break;
645  case FRAGMENT_SHADER:
646  mapper->SetFragmentShaderCode(code.c_str());
647  qDebug() << "added shader type " << type;
648  break;
649  default:
650  qDebug() << "Invalid shader type " << type;
651  break;
652  }
653 
654  }
655  else {
656  qDebug() << "Unhandled item" << info.filePath();
657  }
658  }
659 }
ShaderType
Definition: MyRenderer.cpp:61
bool readFromFile(const char *path, std::string &text)
Definition: Utils.cpp:140

References filehandling::readFromFile().

◆ SetCameraProperties()

void MyRenderer::SetCameraProperties ( double  cameraPosition[3] = CAMERAPOSITION,
double  focalPoint[3] = FOCALPOINT,
double  viewUp[3] = CAMERAVIEWUP,
double  zoom = ZOOM 
)

Sets the camera properties for the current window

Definition at line 727 of file MyRenderer.cpp.

728 {
729  renderer->GetActiveCamera()->SetPosition(cameraPosition);
730  renderer->GetActiveCamera()->SetFocalPoint(focalPoint);
731  renderer->GetActiveCamera()->SetViewUp(viewUp);
732  renderer->ResetCamera();
733  renderer->GetActiveCamera()->Zoom(zoom);
734 }

◆ SetDefaults()

void MyRenderer::SetDefaults ( )

Sets the properties of the current renderer / windows (for example the size of the window or the background)

Definition at line 661 of file MyRenderer.cpp.

662 {
663  renderer->SetBackground(BACKGROUNDCOLOR);
664  renderWindow->SetSize(RENDERWINDOWSIZE);
666  renderer->GradientBackgroundOn();
667 }
void SetCameraProperties(double cameraPosition[3]=CAMERAPOSITION, double focalPoint[3]=FOCALPOINT, double viewUp[3]=CAMERAVIEWUP, double zoom=ZOOM)
Definition: MyRenderer.cpp:727

References SetCameraProperties().

◆ SetShadingProperties()

void MyRenderer::SetShadingProperties ( )

calls SetProperties for all actors and sets defaults also for renderer, i.e. camera stuff and light.

Definition at line 670 of file MyRenderer.cpp.

671 {
672 
673  for (auto val : actorMap.values())
674  val->SetProperties();
675 
676 }

◆ showTargetStructure()

void MyRenderer::showTargetStructure ( int  keyTargetStructure,
int  keyRiskStructure 
)

This function is used to show the target-structure actors. If the current visualization is not clipped the target structure is colored from red to white, depending on the distance with additionally black lines at the distance 10, 20, 30mm.... If the view is clipped the target structure is shown two times. One time the unclipped target structure in grey, but with the distance lines And one time time clipped target structure colored from red to white.

Definition at line 194 of file MyRenderer.cpp.

195 {
196 
197  if (!isSplitted)
198  claculateDistanceToActor(keyTargetStructure, keyRiskStructure);
199  else
200  {
201  claculateDistanceToActor(keyTargetStructure, keyRiskStructure, true);
202  claculateDistanceToActor(keyTargetStructure, keyRiskStructure, false, true);
203  }
204 
205 }
void claculateDistanceToActor(int keyMainActor, int keyTumorActor, bool splittedMiddle=false, bool splittedBorder=false)
Definition: MyRenderer.cpp:207

References claculateDistanceToActor().

◆ SplitPolygon()

vtkSmartPointer< vtkPolyData > MyRenderer::SplitPolygon ( int  actorID,
bool  safeToPolyDataMap = true 
)

SplitPolygon splits the PolygonData according to the configured clippingPlaneSource. If the flag safeToPolyDataMap is set to true the splitted polyData is added to labeledPolydata map

Definition at line 398 of file MyRenderer.cpp.

399 {
400  auto input1 = labeledPolydata.value(actorID);
401 
402  auto closedBasePoly = CloseOpenPolygons(input1);
403  input1 = FusePolygons(input1, closedBasePoly);
404 
405 
406  vtkSmartPointer<vtkCleanPolyData> clean1 =
407  vtkSmartPointer<vtkCleanPolyData>::New();
408  clean1->SetInputData(input1);
409 
410  QList<vtkSmartPointer<vtkPolyData>> polydataList;
411 
412  for (int i = 0; i < 2; ++i)
413  {
414 
415  vtkSmartPointer<vtkClipPolyData> clip =
416  vtkSmartPointer<vtkClipPolyData>::New();
417  clip->SetValue(0);
418  clip->GenerateClippedOutputOn();
419  clip->SetInputConnection(clean1->GetOutputPort());
420  vtkSmartPointer<vtkPlane> plane =
421  vtkSmartPointer<vtkPlane>::New();
422  plane->SetOrigin(clippingPlaneSource->GetOrigin());
423 
424 
425 
426  double * n = clippingPlaneSource->GetNormal();
427  if (i > 0)
428  plane->SetNormal(-n[0], -n[1], -n[2]);
429  else
430  plane->SetNormal(n[0], n[1], n[2]);
431 
432 
433  clip->SetClipFunction(plane);
434  clip->SetValue(0);
435  clip->Update();
436 
437  vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
438  vtkSmartPointer<vtkPolyData> boundaryPoly = vtkSmartPointer<vtkPolyData>::New();
439 
440  polyData = clip->GetOutput();
441 
442  if (polyData->GetNumberOfPolys() == 0)
443  {
444  if (i == 0)
445  {
446  continue;
447  }
448  break;
449  }
450 
451 
452 
453  boundaryPoly = CloseOpenPolygons(polyData);
454 
455  vtkSmartPointer<vtkTransform> translation =
456  vtkSmartPointer<vtkTransform>::New();
457  if (i > 0)
458  {
459  translation->Translate(-60*n[0], -60*n[1], -60*n[2]);
460  //translation->RotateY(-40.0);
461  //translation->RotateWXYZ(-40, n[0], -60 * n[1], -60 * n[2]);
462  }
463  else
464  {
465  translation->Translate(60 * n[0], 60 * n[1], 60 * n[2]);
466  //translation->RotateY(40.0);
467  //translation->RotateWXYZ(40, n[0], -60 * n[1], -60 * n[2]);
468  }
469 
470  vtkSmartPointer<vtkTransformPolyDataFilter> transformFilterPoly =
471  vtkSmartPointer<vtkTransformPolyDataFilter>::New();
472  transformFilterPoly->AddInputData(polyData);
473  transformFilterPoly->SetTransform(translation);
474  transformFilterPoly->Update();
475 
476 
477  vtkSmartPointer<vtkTransformPolyDataFilter> transformFilterBoundary =
478  vtkSmartPointer<vtkTransformPolyDataFilter>::New();
479  transformFilterBoundary->AddInputData(boundaryPoly);
480  transformFilterBoundary->SetTransform(translation);
481  transformFilterBoundary->Update();
482 
483  polydataList.append(transformFilterPoly->GetOutput());
484  polydataList.append(transformFilterBoundary->GetOutput());
485  }
486 
487  vtkSmartPointer<vtkPolyData> currentPoly =
488  vtkSmartPointer<vtkPolyData>::New();
489 
490  for (vtkSmartPointer<vtkPolyData> poly : polydataList)
491  {
492 
493  currentPoly = FusePolygons(currentPoly, poly);
494  }
495 
496  if (safeToPolyDataMap)
497  labeledPolydata.insert(actorID, currentPoly);
498 
499  return currentPoly;
500 }
vtkSmartPointer< vtkPolyData > CloseOpenPolygons(vtkSmartPointer< vtkPolyData > polyData)
Definition: MyRenderer.cpp:361
vtkSmartPointer< vtkPolyData > FusePolygons(vtkSmartPointer< vtkPolyData > polyData1, vtkSmartPointer< vtkPolyData > polyData2)
Definition: MyRenderer.cpp:344

References CloseOpenPolygons(), and FusePolygons().

◆ SplitPolygons()

void MyRenderer::SplitPolygons ( )

makes a copy of the labeledPolydata - map which is needed in order to perform clipping properly and stores it in the labeledPolydataSplitted - map

Definition at line 692 of file MyRenderer.cpp.

693 {
694  for (int key : labeledPolydata.keys())
695  {
696  vtkSmartPointer<vtkPolyData> c = vtkSmartPointer<vtkPolyData>::New();
697  c->DeepCopy(labeledPolydata.find(key).value());
698  labeledPolydataSplitted.insert(key, c);
699  SplitPolygon(key);
700  }
701 
702 }
vtkSmartPointer< vtkPolyData > SplitPolygon(int actorID, bool safeToPolyDataMap=true)
Definition: MyRenderer.cpp:398

References SplitPolygon().

◆ UpdateClippingPlane() [1/2]

void MyRenderer::UpdateClippingPlane ( double  normal[3])

updates the normal of the ClippingPlaneSource

◆ UpdateClippingPlane() [2/2]

void MyRenderer::UpdateClippingPlane ( double  step)

moves the clipping plan by the value step in the direction of the normal vector

Definition at line 820 of file MyRenderer.cpp.

821 {
822  clippingPlaneSource->Push(step);
823  clippingPlaneSource->Update();
824  reinterpret_cast<vtkOpenGLPolyDataMapper*>(clippingActor->GetMapper())->SetInputData(clippingPlaneSource->GetOutput());
825 }

The documentation for this class was generated from the following files: