NorMIT-nav  22.09
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 
33 namespace cx
34 {
35 
37  RepImpl()
38 {
39  mMapper = vtkPolyDataMapperPtr::New();
40  mProperty = vtkPropertyPtr::New();
41  mActor = vtkActorPtr::New();
42  mActor->SetMapper(mMapper);
43  mActor->SetProperty(mProperty);
44 }
45 
47 {
48 }
49 
51 {
52  return wrap_new(new GeometricRep2D(), uid);
53 }
54 
56 {
57  view->getRenderer()->AddActor(mActor);
58 }
59 
61 {
62  view->getRenderer()->RemoveActor(mActor);
63 }
64 
66 {
67  if (mesh == mMesh)
68  return;
69  if (mMesh)
70  {
71  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
72  disconnect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
73  }
74  mMesh = mesh;
75  if (mMesh)
76  {
77  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
78  connect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
79  this->meshChangedSlot();
80  this->transformChangedSlot();
81  }
82 }
83 
85 {
86  return mMesh;
87 }
89 {
90  return (mMesh == mesh);
91 }
92 
94 {
95  if (mSlicer)
96  {
97  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
98  }
99  mSlicer = slicer;
100  if (mSlicer)
101  {
102  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
103  this->transformChangedSlot();
104  }
105 }
106 
107 void GeometricRep2D::meshChangedSlot()
108 {
109  mMapper->SetInputData(mMesh->getVtkPolyData()); // original - show-all method
110  mMapper->ScalarVisibilityOff();//Don't use the LUT from the VtkPolyData
111  //mNormals->SetInputConnection(mMesh->getVtkPolyData()->Get);
112 
113  //Set mesh color
114  mActor->GetProperty()->SetColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
115  //Set mesh opacity
116  mActor->GetProperty()->SetOpacity(mMesh->getColor().alphaF());
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 
127 void GeometricRep2D::transformChangedSlot()
128 {
129  if (!mSlicer || !mMesh)
130  return;
131 
132  Transform3D rMs = mSlicer->get_sMr().inv();
133  Transform3D dMr = mMesh->get_rMd().inv();
134  Transform3D dMs = dMr * rMs;
135 
136  mActor->SetUserMatrix(dMs.inv().getVtkMatrix());
137 }
138 
139 //---------------------------------------------------------
140 } // namespace cx
141 //---------------------------------------------------------
142 
cx::GeometricRep2D::setMesh
void setMesh(MeshPtr mesh)
sets this reps mesh
Definition: cxGeometricRep2D.cpp:65
cx::GeometricRep2D::~GeometricRep2D
virtual ~GeometricRep2D()
Definition: cxGeometricRep2D.cpp:46
cx::GeometricRep2D::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxGeometricRep2D.cpp:60
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::GeometricRep2D::mSlicer
SliceProxyPtr mSlicer
Definition: cxGeometricRep2D.h:63
cx::GeometricRep2D::New
static GeometricRep2DPtr New(const QString &uid="")
Definition: cxGeometricRep2D.cpp:50
cx::GeometricRep2D::hasMesh
bool hasMesh(MeshPtr mesh) const
checks if this rep has the give mesh
Definition: cxGeometricRep2D.cpp:88
cx::SliceProxyPtr
boost::shared_ptr< class SliceProxy > SliceProxyPtr
Definition: cxForwardDeclarations.h:96
cx::GeometricRep2D::mActor
vtkActorPtr mActor
Definition: cxGeometricRep2D.h:60
cx::GeometricRep2D::setSliceProxy
void setSliceProxy(SliceProxyPtr slicer)
Definition: cxGeometricRep2D.cpp:93
cx::GeometricRep2D::GeometricRep2D
GeometricRep2D()
Definition: cxGeometricRep2D.cpp:36
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:59
cxTypeConversions.h
cxView.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:55
cxSliceProxy.h
cx::GeometricRep2D::mMapper
vtkPolyDataMapperPtr mMapper
Definition: cxGeometricRep2D.h:58
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:62
cx::GeometricRep2D::getMesh
MeshPtr getMesh()
gives this reps mesh
Definition: cxGeometricRep2D.cpp:84