Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #include <vtkRenderer.h>
35 #include <vtkVolumeMapper.h>
36 #include <vtkImageData.h>
37 
38 #include "cxStreamRep3D.h"
39 #include "cxTrackedStream.h"
40 #include "cxVideoSourceGraphics.h"
41 #include "cxView.h"
42 #include "cxTool.h"
43 #include "cxPatientModelService.h"
44 #include "cxVolumeProperty.h"
45 #include "cxReporter.h"
46 #include "cxSettings.h"
47 
48 //To be removed
49 #include "cxImageTF3D.h"
51 
52 
53 namespace cx
54 {
55 
57 {
58  return wrap_new(new StreamRep3D(spaceProvider, patientModelService), uid);
59 }
60 
61 StreamRep3D::StreamRep3D(SpaceProviderPtr spaceProvider, PatientModelServicePtr patientModelService) :
62  VolumetricRep(),
63  mTrackedStream(TrackedStreamPtr()),
64  mPatientModelService(patientModelService)
65 {
66  this->setVisualizerType();
67 }
68 
70 {
71  if(mTrackedStream)
72  {
73  disconnect(mTrackedStream.get(), &TrackedStream::newTool, this, &StreamRep3D::newTool);
74  disconnect(mTrackedStream.get(), &TrackedStream::newVideoSource, this, &StreamRep3D::newVideoSource);
75  disconnect(mTrackedStream.get(), &TrackedStream::newFrame, this, &StreamRep3D::vtkImageDataChangedSlot);
76  }
77 
78  mTrackedStream = trackedStream;
79 
80  if(mTrackedStream)
81  {
82  connect(mTrackedStream.get(), &TrackedStream::newTool, this, &StreamRep3D::newTool);
83  connect(mTrackedStream.get(), &TrackedStream::newVideoSource, this, &StreamRep3D::newVideoSource);
84  connect(mTrackedStream.get(), &TrackedStream::newFrame, this, &StreamRep3D::vtkImageDataChangedSlot);
85  this->newTool(mTrackedStream->getProbeTool());
86  this->newVideoSource(mTrackedStream->getVideoSource());
87  }
88 }
89 
90 void StreamRep3D::newTool(ToolPtr tool)
91 {
92 }
93 
94 void StreamRep3D::newVideoSource(VideoSourcePtr videoSource)
95 {
96  if(!videoSource)
97  return;
98 
99  ImagePtr image = mTrackedStream->getChangingImage();
100  this->setImage(image);
101 // mPatientModelService->insertData(image);
102 
103  this->initTransferFunction(image);
104 
105  mVideoSource = videoSource;
106 }
107 
108 // Set transfer function so that we can see the volume change.
109 // Should be replaced with GUI for TrackedStream
110 void StreamRep3D::initTransferFunction(ImagePtr image)
111 {
112  ImageTF3DPtr tf3D = image->getTransferFunctions3D();
113  IntIntMap opacity;
114  opacity[90] = 0;
115  opacity[100] = 5;
116  opacity[200] = image->getMaxAlphaValue();
117  tf3D->resetAlpha(opacity);
118  image->setTransferFunctions3D(tf3D);
119 }
120 
122 {
123  return mTrackedStream;
124 }
125 
126 QString StreamRep3D::getType() const
127 {
128  return "StreamRep3D";
129 }
130 
131 void StreamRep3D::setVisualizerType()
132 {
133  QString visualizerType = settings()->value("View3D/ImageRender3DVisualizer").toString();
134  if(visualizerType == "vtkVolumeTextureMapper3D")
136  else if(visualizerType == "vtkGPUVolumeRayCastMapper")
138  else
139  reportError(QString("StreamRep3D::setVisualizerType(): No visualizer found for string=%1").arg(visualizerType));
140 }
141 
142 } //cx
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
void setTrackedStream(TrackedStreamPtr trackedStream)
void reportError(QString msg)
Definition: cxLogger.cpp:92
boost::shared_ptr< class TrackedStream > TrackedStreamPtr
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:87
void newVideoSource(VideoSourcePtr videoSource)
boost::shared_ptr< class StreamRep3D > StreamRep3DPtr
Display a volume in 3D.
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:42
virtual void setImage(ImagePtr image)
set the reps image
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
void setUseGPUVolumeRayCastMapper()
std::map< int, int > IntIntMap
Definition: cxImage.h:56
void setUseVolumeTextureMapper()
Display a 3D stream in 3D.
Definition: cxStreamRep3D.h:52
static StreamRep3DPtr New(SpaceProviderPtr spaceProvider, PatientModelServicePtr patientModelService, const QString &uid="")
boost::shared_ptr< class ImageTF3D > ImageTF3DPtr
TrackedStreamPtr getTrackedStream()
boost::shared_ptr< class Tool > ToolPtr