Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
cxStreamRep3D.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 <vtkRenderer.h>
14 #include <vtkVolumeMapper.h>
15 #include <vtkImageData.h>
16 
17 #include "cxStreamRep3D.h"
18 #include "cxTrackedStream.h"
19 #include "cxVideoSourceGraphics.h"
20 #include "cxView.h"
21 #include "cxTool.h"
22 #include "cxPatientModelService.h"
23 #include "cxVolumeProperty.h"
24 #include "cxReporter.h"
25 #include "cxSettings.h"
26 
27 //To be removed
28 #include "cxImageTF3D.h"
30 
31 
32 namespace cx
33 {
34 
35 StreamRep3DPtr StreamRep3D::New(SpaceProviderPtr spaceProvider, PatientModelServicePtr patientModelService, const QString& uid)
36 {
37  return wrap_new(new StreamRep3D(spaceProvider, patientModelService), uid);
38 }
39 
40 StreamRep3D::StreamRep3D(SpaceProviderPtr spaceProvider, PatientModelServicePtr patientModelService) :
41  VolumetricRep(),
42  mTrackedStream(TrackedStreamPtr()),
43  mPatientModelService(patientModelService)
44 {
45  this->setVisualizerType();
46 }
47 
49 {
50  if(mTrackedStream)
51  {
52  disconnect(mTrackedStream.get(), &TrackedStream::newTool, this, &StreamRep3D::newTool);
53  disconnect(mTrackedStream.get(), &TrackedStream::newVideoSource, this, &StreamRep3D::newVideoSource);
54  disconnect(mTrackedStream.get(), &TrackedStream::newFrame, this, &StreamRep3D::vtkImageDataChangedSlot);
55  }
56 
57  mTrackedStream = trackedStream;
58 
59  if(mTrackedStream)
60  {
61  connect(mTrackedStream.get(), &TrackedStream::newTool, this, &StreamRep3D::newTool);
62  connect(mTrackedStream.get(), &TrackedStream::newVideoSource, this, &StreamRep3D::newVideoSource);
63  connect(mTrackedStream.get(), &TrackedStream::newFrame, this, &StreamRep3D::vtkImageDataChangedSlot);
64  this->newTool(mTrackedStream->getProbeTool());
65  this->newVideoSource(mTrackedStream->getVideoSource());
66  }
67 }
68 
69 void StreamRep3D::newTool(ToolPtr tool)
70 {
71 }
72 
73 void StreamRep3D::newVideoSource(VideoSourcePtr videoSource)
74 {
75  if(!videoSource)
76  return;
77 
78  ImagePtr image = mTrackedStream->getChangingImage();
79  this->setImage(image);
80 // mPatientModelService->insertData(image);
81 
82  this->initTransferFunction(image);
83 
84  mVideoSource = videoSource;
85 }
86 
87 // Set transfer function so that we can see the volume change.
88 // Should be replaced with GUI for TrackedStream
89 void StreamRep3D::initTransferFunction(ImagePtr image)
90 {
91  ImageTF3DPtr tf3D = image->getTransferFunctions3D();
92  IntIntMap opacity;
93  opacity[90] = 0;
94  opacity[100] = 5;
95  opacity[200] = image->getMaxAlphaValue();
96  tf3D->resetAlpha(opacity);
97  image->setTransferFunctions3D(tf3D);
98 }
99 
101 {
102  return mTrackedStream;
103 }
104 
105 QString StreamRep3D::getType() const
106 {
107  return "StreamRep3D";
108 }
109 
110 void StreamRep3D::setVisualizerType()
111 {
112  QString visualizerType = settings()->value("View3D/ImageRender3DVisualizer").toString();
113  if(visualizerType == "vtkVolumeTextureMapper3D")
115  else if(visualizerType == "vtkGPUVolumeRayCastMapper")
117  else
118  reportError(QString("StreamRep3D::setVisualizerType(): No visualizer found for string=%1").arg(visualizerType));
119 }
120 
121 } //cx
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
void setTrackedStream(TrackedStreamPtr trackedStream)
void reportError(QString msg)
Definition: cxLogger.cpp:71
boost::shared_ptr< class TrackedStream > TrackedStreamPtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
void newVideoSource(VideoSourcePtr videoSource)
boost::shared_ptr< class StreamRep3D > StreamRep3DPtr
void newTool(ToolPtr tool)
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class VideoSource > VideoSourcePtr
virtual QString getType() const
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
virtual void setImage(ImagePtr image)
set the reps image
void setUseGPUVolumeRayCastMapper()
std::map< int, int > IntIntMap
Definition: cxImage.h:35
void setUseVolumeTextureMapper()
Display a 3D stream in 3D.
Definition: cxStreamRep3D.h:31
static StreamRep3DPtr New(SpaceProviderPtr spaceProvider, PatientModelServicePtr patientModelService, const QString &uid="")
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
TrackedStreamPtr getTrackedStream()
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr