NorMIT-nav  22.09
An IGT application
cxGeometricRep.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 "cxGeometricRep.h"
14 
15 #include <vtkPolyData.h>
16 #include <vtkPointData.h>
17 #include <vtkProperty.h>
18 #include <vtkActor.h>
19 #include <vtkRenderer.h>
20 #include <vtkMatrix4x4.h>
21 #include <vtkArrowSource.h>
22 #include <vtkPlane.h>
23 
24 #include "cxMesh.h"
25 #include "cxView.h"
26 #include "cxLogger.h"
27 
28 #include "cxTypeConversions.h"
29 #include "cxVtkHelperClasses.h"
30 
31 namespace cx
32 {
33 
35 {
36  m_rMrr = Transform3D::Identity();
39 }
41 {
42 }
43 
45 {
46  if (mesh == mMesh)
47  return;
48  if (mMesh)
49  {
50  disconnect(mMesh.get(), &Mesh::meshChanged, this, &GraphicalGeometric::meshChangedSlot);
51  disconnect(mMesh.get(), &Data::transformChanged, this, &GraphicalGeometric::transformChangedSlot);
52  disconnect(mMesh.get(), &Data::clipPlanesChanged, this, &GraphicalGeometric::clipPlanesChangedSlot);
53  }
54  mMesh = mesh;
55  if (mMesh)
56  {
57  connect(mMesh.get(), &Mesh::meshChanged, this, &GraphicalGeometric::meshChangedSlot);
58  connect(mMesh.get(), &Data::transformChanged, this, &GraphicalGeometric::transformChangedSlot);
59  connect(mMesh.get(), &Data::clipPlanesChanged, this, &GraphicalGeometric::clipPlanesChangedSlot);
60  this->meshChangedSlot();
61  this->transformChangedSlot();
62  this->clipPlanesChangedSlot();
63  }
64 }
65 
66 //Copied from ImageMapperMonitor (used by VolumetricRep)
67 void GraphicalGeometric::clipPlanesChangedSlot()
68 {
69  this->clearClipping();
70 
71  if (!mMesh)
72  return;
73 
74  std::vector<vtkPlanePtr> mPlanes;
75  mPlanes = mMesh->getAllClipPlanes();
76  for (unsigned i=0; i<mPlanes.size(); ++i)
77  {
78  mGraphicalPolyDataPtr->getMapper()->AddClippingPlane(mPlanes[i]);
79  }
80 }
81 
83 {
84  if (!mMesh)
85  return;
86 
87  mGraphicalPolyDataPtr->getMapper()->RemoveAllClippingPlanes();
88 }
89 
91 {
92  return mMesh;
93 }
94 
96 {
97  mGraphicalPolyDataPtr->setRenderer(renderer);
98  mGraphicalGlyph3DDataPtr->setRenderer(renderer);
99 }
100 
102 {
103  m_rMrr = rMrr;
104  this->transformChangedSlot();
105 }
106 
107 void GraphicalGeometric::meshChangedSlot()
108 {
109  mGraphicalGlyph3DDataPtr->setVisibility(mMesh->showGlyph());
110  if(mMesh->showGlyph())
111  {
112  mGraphicalGlyph3DDataPtr->setData(mMesh->getVtkPolyData());
113  mGraphicalGlyph3DDataPtr->setOrientationArray(mMesh->getOrientationArray());
114  mGraphicalGlyph3DDataPtr->setColorArray(mMesh->getColorArray());
115  mGraphicalGlyph3DDataPtr->setColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
116  mGraphicalGlyph3DDataPtr->setLUT(mMesh->getGlyphLUT());
117  mGraphicalGlyph3DDataPtr->setScaleFactor(mMesh->getVisSize());
118  }
119 
120  mMesh->updateVtkPolyDataWithTexture();
121  mGraphicalPolyDataPtr->setData(mMesh->getVtkPolyData());
122  mGraphicalPolyDataPtr->setTexture(mMesh->getVtkTexture());
123 
124  mGraphicalPolyDataPtr->setOpacity(1.0);
125  if(mMesh->getUseColorFromPolydataScalars())
126  {
127  mGraphicalPolyDataPtr->setScalarVisibility(true);
128  mGraphicalPolyDataPtr->setScalarModeToUseCellData();
129  }
130  else
131  {
132  mGraphicalPolyDataPtr->setScalarVisibility(false);
133  mGraphicalPolyDataPtr->setColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
134  }
135  mGraphicalPolyDataPtr->setOpacity(mMesh->getColor().alphaF());
136 
137  //Set other properties
138  vtkPropertyPtr dest = mGraphicalPolyDataPtr->getProperty();
139  const MeshPropertyData& src = mMesh->getProperties();
140 
141  dest->SetPointSize(src.mVisSize->getValue());
142  dest->SetBackfaceCulling(src.mBackfaceCulling->getValue());
143  dest->SetFrontfaceCulling(src.mFrontfaceCulling->getValue());
144  dest->SetRepresentation(src.mRepresentation->getValue().toInt());
145  dest->SetEdgeVisibility(src.mEdgeVisibility->getValue());
146  dest->SetEdgeColor(cx::getColorAsVector3D(src.mEdgeColor->getValue()).begin());
147  dest->SetAmbient(src.mAmbient->getValue());
148  dest->SetDiffuse(src.mDiffuse->getValue());
149  dest->SetSpecular(src.mSpecular->getValue());
150  dest->SetSpecularPower(src.mSpecularPower->getValue());
151  dest->SetLineWidth(src.mLineWidth->getValue());
152 }
153 
156 void GraphicalGeometric::transformChangedSlot()
157 {
158  if (!mMesh)
159  {
160  return;
161  }
162 
163  Transform3D rrMd = mMesh->get_rMd();
164  Transform3D rMd = m_rMrr * rrMd;
165 
166  mGraphicalPolyDataPtr->setUserMatrix(rMd.getVtkMatrix());
167  mGraphicalGlyph3DDataPtr->setUserMatrix(rMd.getVtkMatrix());
168 }
169 
170 
171 //---------------------------------------------------------
172 //---------------------------------------------------------
173 //---------------------------------------------------------
174 
175 
177  RepImpl()
178 {
179  mGraphics.reset(new GraphicalGeometric());
180 }
182 {
183 }
185 {
186  return wrap_new(new GeometricRep(), uid);
187 }
188 
190 {
191  mGraphics->setRenderer(view->getRenderer());
192 }
193 
195 {
196  mGraphics->setRenderer(NULL);
197 }
198 
200 {
201  mGraphics->setMesh(mesh);
202 }
203 
205 {
206  return mGraphics->getMesh();
207 }
209 {
210  return mGraphics->getMesh() == mesh;
211 }
212 
213 //---------------------------------------------------------
214 }
215 // namespace cx
216 //---------------------------------------------------------
cx::GraphicalGeometric
Display one Mesh in 3D.
Definition: cxGeometricRep.h:38
cxLogger.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::GraphicalGeometric::mMesh
MeshPtr mMesh
Definition: cxGeometricRep.h:58
cx::GraphicalGeometric::mGraphicalGlyph3DDataPtr
GraphicalGlyph3DDataPtr mGraphicalGlyph3DDataPtr
Definition: cxGeometricRep.h:57
cx::GraphicalGeometric::clearClipping
void clearClipping()
Definition: cxGeometricRep.cpp:82
cx::GraphicalGeometric::setTransformOffset
void setTransformOffset(Transform3D rMrr)
Definition: cxGeometricRep.cpp:101
cx::GraphicalGeometric::mGraphicalPolyDataPtr
GraphicalPolyData3DPtr mGraphicalPolyDataPtr
Definition: cxGeometricRep.h:56
cx::GeometricRep::GeometricRep
GeometricRep()
Definition: cxGeometricRep.cpp:176
cxGeometricRep.h
cx::GeometricRep::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxGeometricRep.cpp:194
cx::GeometricRep::setMesh
void setMesh(MeshPtr mesh)
sets this reps mesh
Definition: cxGeometricRep.cpp:199
cx::Data::transformChanged
void transformChanged()
emitted when transform is changed
cx::GraphicalGeometric::setRenderer
void setRenderer(vtkRendererPtr renderer)
Definition: cxGeometricRep.cpp:95
cx::GraphicalGlyph3DData
Helper for rendering a a glyph in 3D.
Definition: cxGraphicalPrimitives.h:102
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::getColorAsVector3D
Vector3D getColorAsVector3D(QColor color)
Definition: cxVtkHelperClasses.cpp:40
cxTypeConversions.h
cxView.h
cx::Mesh::meshChanged
void meshChanged()
cx::GeometricRep::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxGeometricRep.cpp:189
cx::GeometricRep::getMesh
MeshPtr getMesh()
gives this reps mesh
Definition: cxGeometricRep.cpp:204
cx::Data::clipPlanesChanged
void clipPlanesChanged()
cx::GraphicalGeometric::setMesh
void setMesh(MeshPtr mesh)
sets this reps mesh
Definition: cxGeometricRep.cpp:44
vtkPropertyPtr
vtkSmartPointer< class vtkProperty > vtkPropertyPtr
Definition: vtkForwardDeclarations.h:120
cx::GeometricRep::~GeometricRep
virtual ~GeometricRep()
Definition: cxGeometricRep.cpp:181
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl
Default implementation of Rep.
Definition: cxRepImpl.h:42
cx::GeometricRep::hasMesh
bool hasMesh(MeshPtr mesh) const
checks if this rep has the give mesh
Definition: cxGeometricRep.cpp:208
cx::GeometricRep::New
static GeometricRepPtr New(const QString &uid="")
Definition: cxGeometricRep.cpp:184
cx::GraphicalGeometric::getMesh
MeshPtr getMesh()
gives this reps mesh
Definition: cxGeometricRep.cpp:90
cxVtkHelperClasses.h
cx::GraphicalPolyData3D
Helper for rendering a a polydata in 3D.
Definition: cxGraphicalPrimitives.h:83
cx::GraphicalGeometric::~GraphicalGeometric
virtual ~GraphicalGeometric()
Definition: cxGeometricRep.cpp:40
cx::GraphicalGeometric::GraphicalGeometric
GraphicalGeometric()
Definition: cxGeometricRep.cpp:34
cx::RepImpl::wrap_new
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
cxMesh.h
vtkRendererPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Definition: vtkForwardDeclarations.h:122
cx::GeometricRepPtr
boost::shared_ptr< class GeometricRep > GeometricRepPtr
Definition: cxICPRegistrationBaseWidget.h:29
cx::GraphicalGeometric::m_rMrr
Transform3D m_rMrr
Definition: cxGeometricRep.h:59