CustusX  15.8
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 
46 //To be removed
47 #include "cxImageTF3D.h"
49 
50 
51 namespace cx
52 {
53 
55 {
56  return wrap_new(new StreamRep3D(spaceProvider, patientModelService), uid);
57 }
58 
59 StreamRep3D::StreamRep3D(SpaceProviderPtr spaceProvider, PatientModelServicePtr patientModelService) :
60  VolumetricRep(),
61  mTrackedStream(TrackedStreamPtr()),
62  mPatientModelService(patientModelService)
63 {
64 }
65 
67 {
68  if(mTrackedStream)
69  {
70  disconnect(mTrackedStream.get(), &TrackedStream::newTool, this, &StreamRep3D::newTool);
71  disconnect(mTrackedStream.get(), &TrackedStream::newVideoSource, this, &StreamRep3D::newVideoSource);
72  disconnect(mTrackedStream.get(), &TrackedStream::newFrame, this, &StreamRep3D::vtkImageDataChangedSlot);
73  }
74 
75  mTrackedStream = trackedStream;
76 
77  if(mTrackedStream)
78  {
79  connect(mTrackedStream.get(), &TrackedStream::newTool, this, &StreamRep3D::newTool);
80  connect(mTrackedStream.get(), &TrackedStream::newVideoSource, this, &StreamRep3D::newVideoSource);
81  connect(mTrackedStream.get(), &TrackedStream::newFrame, this, &StreamRep3D::vtkImageDataChangedSlot);
82  this->newTool(mTrackedStream->getProbeTool());
83  this->newVideoSource(mTrackedStream->getVideoSource());
84  }
85 }
86 
87 void StreamRep3D::newTool(ToolPtr tool)
88 {
89 }
90 
91 void StreamRep3D::newVideoSource(VideoSourcePtr videoSource)
92 {
93  if(!videoSource)
94  return;
95 
96  ImagePtr image = mTrackedStream->getChangingImage();
97  this->setImage(image);
98 // mPatientModelService->insertData(image);
99 
100  this->initTransferFunction(image);
101 
102  mVideoSource = videoSource;
103 }
104 
105 // Set transfer function so that we can see the volume change.
106 // Should be replaced with GUI for TrackedStream
107 void StreamRep3D::initTransferFunction(ImagePtr image)
108 {
109  ImageTF3DPtr tf3D = image->getTransferFunctions3D();
110  IntIntMap opacity;
111  opacity[90] = 0;
112  opacity[100] = 5;
113  opacity[200] = image->getMaxAlphaValue();
114  tf3D->resetAlpha(opacity);
115  image->setTransferFunctions3D(tf3D);
116 }
117 
119 {
120  return mTrackedStream;
121 }
122 
123 QString StreamRep3D::getType() const
124 {
125  return "StreamRep3D";
126 }
127 
128 } //cx
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
void setTrackedStream(TrackedStreamPtr trackedStream)
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
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
virtual void setImage(ImagePtr image)
set the reps image
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
std::map< int, int > IntIntMap
Definition: cxImage.h:56
Display a stream (2D/3D) 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