CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxGeometricRep2D.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxGeometricRep2D.h"
14 
15 #include <vtkPolyData.h>
16 #include <vtkPolyDataMapper.h>
17 #include <vtkProperty.h>
18 #include <vtkActor.h>
19 #include <vtkRenderer.h>
20 #include <vtkMatrix4x4.h>
21 
22 #include <vtkPolyDataNormals.h>
23 #include <vtkPlane.h>
24 #include <vtkStripper.h>
25 #include <vtkCellArray.h>
26 
27 #include "cxMesh.h"
28 #include "cxView.h"
29 
30 #include "cxSliceProxy.h"
31 #include "cxTypeConversions.h"
32 #include "cxSettings.h"
33 
34 namespace cx
35 {
36 
38  RepImpl()
39 {
40  mMapper = vtkPolyDataMapperPtr::New();
41  mProperty = vtkPropertyPtr::New();
42  mActor = vtkActorPtr::New();
43  mActor->SetMapper(mMapper);
44  mActor->SetProperty(mProperty);
45 }
46 
48 {
49 }
50 
52 {
53  return wrap_new(new GeometricRep2D(), uid);
54 }
55 
57 {
58  view->getRenderer()->AddActor(mActor);
59 }
60 
62 {
63  view->getRenderer()->RemoveActor(mActor);
64 }
65 
67 {
68  if (mesh == mMesh)
69  return;
70  if (mMesh)
71  {
72  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
73  disconnect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
74  }
75  mMesh = mesh;
76  if (mMesh)
77  {
78  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
79  connect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
80  this->meshChangedSlot();
81  this->transformChangedSlot();
82  }
83 }
84 
86 {
87  return mMesh;
88 }
90 {
91  return (mMesh == mesh);
92 }
93 
95 {
96  if (mSlicer)
97  {
98  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
99  }
100  mSlicer = slicer;
101  if (mSlicer)
102  {
103  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
104  this->transformChangedSlot();
105  }
106 }
107 
108 void GeometricRep2D::meshChangedSlot()
109 {
110  mMapper->SetInputData(mMesh->getVtkPolyData()); // original - show-all method
111  mMapper->ScalarVisibilityOff();//Don't use the LUT from the VtkPolyData
112  //mNormals->SetInputConnection(mMesh->getVtkPolyData()->Get);
113 
114  //Set mesh color
115  mActor->GetProperty()->SetColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
116  this->setOpacity();
117 
118  // Turn lightning off - we dont want 3D effects but a clear view of the slice
119  mActor->GetProperty()->LightingOff();
120 
121  //Set linewidth of mesh
122  mActor->GetProperty()->SetLineWidth(mMesh->getProperties().mLineWidth->getValue());
123 }
124 
126 {
127  if(settings()->value("View2D/useGPU2DRendering").toBool())
128  {
129  mActor->GetProperty()->SetOpacity(mMesh->getColor().alphaF());
130  }
131  else
132  {
133  //Setting opacity for CPU rendering in 2D cause meshes to disappear
134  mActor->GetProperty()->SetOpacity(1.0);
135  }
136 }
137 
140 void GeometricRep2D::transformChangedSlot()
141 {
142  if (!mSlicer || !mMesh)
143  return;
144 
145  Transform3D rMs = mSlicer->get_sMr().inv();
146  Transform3D dMr = mMesh->get_rMd().inv();
147  Transform3D dMs = dMr * rMs;
148 
149  mActor->SetUserMatrix(dMs.inv().getVtkMatrix());
150 }
151 
152 //---------------------------------------------------------
153 } // namespace cx
154 //---------------------------------------------------------
155 
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
bool hasMesh(MeshPtr mesh) const
checks if this rep has the give mesh
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
vtkPolyDataMapperPtr mMapper
MeshPtr getMesh()
gives this reps mesh
void setSliceProxy(SliceProxyPtr slicer)
boost::shared_ptr< class View > ViewPtr
virtual void addRepActorsToViewRenderer(ViewPtr view)
void setMesh(MeshPtr mesh)
sets this reps mesh
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Default implementation of Rep.
Definition: cxRepImpl.h:42
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
static GeometricRep2DPtr New(const QString &uid="")
vtkPropertyPtr mProperty
boost::shared_ptr< class Mesh > MeshPtr
SliceProxyPtr mSlicer
boost::shared_ptr< class GeometricRep2D > GeometricRep2DPtr
Namespace for all CustusX production code.