CustusX  22.04-rc5
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 
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
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.