NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxFiberBundleRep.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 "cxFiberBundleRep.h"
14 
15 #include "boost/bind.hpp"
16 #include <vtkActor.h>
17 #include <vtkProperty.h>
18 #include <vtkPolyDataMapper.h>
19 #include <vtkPolyDataNormals.h>
20 #include <vtkMatrix4x4.h>
21 #include <vtkRenderer.h>
22 #include <vtkRibbonFilter.h>
23 
24 #include "cxGraphicalPrimitives.h"
25 #include "cxView.h"
26 #include "cxTypeConversions.h"
27 #include "cxMesh.h"
28 
29 namespace cx
30 {
33  : RepImpl(), mFiberWidth(.5)
34 {
35  mPolyDataMapper = vtkPolyDataMapperPtr::New();
36  mProperty = vtkPropertyPtr::New();
37  // mProperty->SetInterpolationToFlat();
38  // mProperty->SetInterpolationToGouraud();
39 
40  mActor = vtkActorPtr::New();
41 
42  mActor->SetMapper(mPolyDataMapper);
43  mActor->SetProperty(mProperty);
44 }
45 
50 {
51  return wrap_new(new FiberBundleRep(), uid);
52 }
53 
55 QString FiberBundleRep::getType() const
56 {
57  return "FiberBundleRep";
58 }
59 
64 {
65  // Already has this bundle assigned
66  if (hasBundle(bundle)) return;
67 
68  std::cout << "New fiber bundle assigned" << std::endl;
69 
70  if (mBundle)
71  {
72  disconnect(mBundle.get(), SIGNAL(transformChanged()), this, SLOT(bundleTransformChanged()));
73  disconnect(mBundle.get(), SIGNAL(meshChanged()), this, SLOT(bundleChanged()));
74  }
75 
76  mBundle = bundle;
77 
78  if (mBundle)
79  {
80  connect(mBundle.get(), SIGNAL(transformChanged()), this, SLOT(bundleTransformChanged()));
81  connect(mBundle.get(), SIGNAL(meshChanged()), this, SLOT(bundleChanged()));
82  }
83 
84  bundleChanged();
85  this->bundleTransformChanged();
86 }
87 
92 {
93  view->getRenderer()->AddActor(mActor);
94 
95  if (mViewportListener)
96  mViewportListener->startListen(view->getRenderer());
97 }
98 
103 {
104  view->getRenderer()->RemoveActor(mActor);
105 
106  if (mViewportListener)
107  mViewportListener->stopListen();
108 }
109 
111 void FiberBundleRep::bundleChanged()
112 {
113  vtkPolyDataPtr model = mBundle->getVtkPolyData();
114 
115  if (model)
116  {
117  QColor color = mBundle->getColor();
118  mActor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
119  mActor->GetProperty()->SetOpacity(color.alphaF());
120 
121  if (!mBundle->getIsWireframe())
122  {
126  vtkSmartPointer<vtkRibbonFilter> ribbonFilter = vtkSmartPointer<vtkRibbonFilter>::New();
127  ribbonFilter->SetInputData(model);
128  ribbonFilter->SetWidth(mFiberWidth);
129  ribbonFilter->SetWidthFactor(3);
130 
131  mPolyDataMapper->SetInputConnection(ribbonFilter->GetOutputPort());
132  }
133  else
134  {
135  {
136  vtkPolyDataNormalsPtr normals = vtkPolyDataNormalsPtr::New();
137  normals->SetInputData(model);
138  normals->Update();
139  model = normals->GetOutput();
140  }
141  mPolyDataMapper->SetInputData(model);
142  mActor->SetMapper(mPolyDataMapper);
143  }
144 
145  mPolyDataMapper->ScalarVisibilityOn();
146  mPolyDataMapper->SetScalarModeToUsePointFieldData();
147  }
148 
149 }
150 
153 void FiberBundleRep::bundleTransformChanged()
154 {
155  if (!mBundle) return;
156 
157  mActor->SetUserMatrix(mBundle->get_rMd().getVtkMatrix());
158 }
159 
160 } // end namespace
vtkPolyDataNormalsPtr
vtkSmartPointer< class vtkPolyDataNormals > vtkPolyDataNormalsPtr
Definition: vtkForwardDeclarations.h:113
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::FiberBundleRep::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Definition: cxFiberBundleRep.cpp:102
cxGraphicalPrimitives.h
cx::FiberBundleRep::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)
Definition: cxFiberBundleRep.cpp:91
cx::MeshPtr
boost::shared_ptr< class Mesh > MeshPtr
Definition: cxForwardDeclarations.h:48
cxTypeConversions.h
cxView.h
cxFiberBundleRep.h
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl
Default implementation of Rep.
Definition: cxRepImpl.h:42
cx::FiberBundleRep::setBundle
virtual void setBundle(MeshPtr bundle)
Definition: cxFiberBundleRep.cpp:63
cx::FiberBundleRep::FiberBundleRep
FiberBundleRep()
Definition: cxFiberBundleRep.cpp:32
cx::FiberBundleRep::getType
virtual QString getType() const
Definition: cxFiberBundleRep.cpp:55
cx::FiberBundleRep::hasBundle
virtual bool hasBundle(MeshPtr bundle) const
Definition: cxFiberBundleRep.h:52
cx::FiberBundleRep::New
static FiberBundleRepPtr New(const QString &uid="")
Definition: cxFiberBundleRep.cpp:49
cx::RepImpl::wrap_new
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
cxMesh.h
cx::FiberBundleRepPtr
boost::shared_ptr< class FiberBundleRep > FiberBundleRepPtr
Definition: cxForwardDeclarations.h:68