NorMIT-nav  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 
cx::GeometricRep2D::setMesh
void setMesh(MeshPtr mesh)
sets this reps mesh
Definition: cxGeometricRep2D.cpp:66
cx::GeometricRep2D::~GeometricRep2D
virtual ~GeometricRep2D()
Definition: cxGeometricRep2D.cpp:47
cx::GeometricRep2D::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxGeometricRep2D.cpp:61
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::GeometricRep2D::mSlicer
SliceProxyPtr mSlicer
Definition: cxGeometricRep2D.h:64
cx::GeometricRep2D::New
static GeometricRep2DPtr New(const QString &uid="")
Definition: cxGeometricRep2D.cpp:51
cx::GeometricRep2D::setOpacity
void setOpacity()
Definition: cxGeometricRep2D.cpp:125
cx::GeometricRep2D::hasMesh
bool hasMesh(MeshPtr mesh) const
checks if this rep has the give mesh
Definition: cxGeometricRep2D.cpp:89
cx::SliceProxyPtr
boost::shared_ptr< class SliceProxy > SliceProxyPtr
Definition: cxForwardDeclarations.h:96
cx::GeometricRep2D::mActor
vtkActorPtr mActor
Definition: cxGeometricRep2D.h:61
cx::GeometricRep2D::setSliceProxy
void setSliceProxy(SliceProxyPtr slicer)
Definition: cxGeometricRep2D.cpp:94
cx::GeometricRep2D::GeometricRep2D
GeometricRep2D()
Definition: cxGeometricRep2D.cpp:37
cx::MeshPtr
boost::shared_ptr< class Mesh > MeshPtr
Definition: cxForwardDeclarations.h:48
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::GeometricRep2D::mProperty
vtkPropertyPtr mProperty
Definition: cxGeometricRep2D.h:60
cxTypeConversions.h
cxView.h
cxSettings.h
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl
Default implementation of Rep.
Definition: cxRepImpl.h:42
cx::GeometricRep2DPtr
boost::shared_ptr< class GeometricRep2D > GeometricRep2DPtr
Definition: cxForwardDeclarations.h:69
cx::GeometricRep2D::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxGeometricRep2D.cpp:56
cxSliceProxy.h
cx::GeometricRep2D::mMapper
vtkPolyDataMapperPtr mMapper
Definition: cxGeometricRep2D.h:59
cx::RepImpl::wrap_new
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
cxMesh.h
cxGeometricRep2D.h
cx::GeometricRep2D::mMesh
MeshPtr mMesh
Definition: cxGeometricRep2D.h:63
cx::GeometricRep2D::getMesh
MeshPtr getMesh()
gives this reps mesh
Definition: cxGeometricRep2D.cpp:85
cx::settings
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21