Fraxinus  17.12
An IGT application
cxSlices3DRep.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 #include "cxSlices3DRep.h"
34 
35 #include <vtkRenderer.h>
36 #include <vtkFloatArray.h>
37 #include <vtkPlaneSource.h>
38 #include <vtkPointData.h>
39 #include <vtkTriangleFilter.h>
40 #include <vtkStripper.h>
41 #include <vtkImageData.h>
42 #include <vtkLookupTable.h>
43 #include "cxLogger.h"
44 #include "cxImage.h"
45 #include "cxView.h"
46 #include "cxImageLUT2D.h"
47 #include "cxSliceProxy.h"
48 #include "cxTypeConversions.h"
49 #include "cxGPUImageBuffer.h"
50 #include "cxTexture3DSlicerProxy.h"
51 
52 
53 //---------------------------------------------------------
54 namespace cx
55 {
56 //---------------------------------------------------------
57 
59  RepImpl(),
60  mSharedOpenGLContext(context)
61 {
62 }
63 
65 {
66 }
67 
69 {
70  return wrap_new(new Slices3DRep(context), uid);
71 }
72 
73 void Slices3DRep::setShaderPath(QString path)
74 {
75  for (unsigned i=0; i<mProxy.size(); ++i)
76  mProxy[i]->setShaderPath(path);
77 }
78 
79 void Slices3DRep::setImages(std::vector<ImagePtr> images)
80 {
81  if (images.empty())
82  {
83  reportWarning("Slices3DRep::setImages: No input images (in ViewGroup)");
84  return;
85  }
86  for (unsigned i=0; i<mProxy.size(); ++i)
87  {
88  mProxy[i]->setImages(images);
89  mProxy[i]->getSliceProxy()->setDefaultCenter(images[0]->get_rMd().coord(images[0]->boundingBox().center()));
90  }
91 }
92 
93 void Slices3DRep::addPlane(PLANE_TYPE plane, PatientModelServicePtr dataManager)
94 {
95  SliceProxyPtr sliceProxy = SliceProxy::create(dataManager);
96  sliceProxy->initializeFromPlane(plane, false, true, 150, 0.25);
97  sliceProxy->setAlwaysUseDefaultCenter(true);
98 
99  Texture3DSlicerProxyPtr current = Texture3DSlicerProxy::New(mSharedOpenGLContext);
100  current->setSliceProxy(sliceProxy);
101  current->setTargetSpaceToR();
102 
103  mProxy.push_back(current);
104 }
105 
107 {
108  for (unsigned i=0; i<mProxy.size(); ++i)
109  mProxy[i]->getSliceProxy()->setTool(tool);
110 }
111 
113 {
114  for (unsigned i=0; i<mProxy.size(); ++i)
115  view->getRenderer()->AddActor(mProxy[i]->getActor());
116 }
117 
119 {
120  for (unsigned i=0; i<mProxy.size(); ++i)
121  view->getRenderer()->RemoveActor(mProxy[i]->getActor());
122 }
123 
124 //---------------------------------------------------------
125 }//end namespace
126 //---------------------------------------------------------
void setShaderPath(QString path)
static SliceProxyPtr create(PatientModelServicePtr dataManager)
Slices3DRep(SharedOpenGLContextPtr context)
boost::shared_ptr< class SliceProxy > SliceProxyPtr
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
boost::shared_ptr< class View > ViewPtr
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
boost::shared_ptr< class SharedOpenGLContext > SharedOpenGLContextPtr
boost::shared_ptr< class Slices3DRep > Slices3DRepPtr
void reportWarning(QString msg)
Definition: cxLogger.cpp:91
virtual ~Slices3DRep()
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Default implementation of Rep.
Definition: cxRepImpl.h:63
boost::shared_ptr< class Texture3DSlicerProxy > Texture3DSlicerProxyPtr
static Slices3DRepPtr New(SharedOpenGLContextPtr context, const QString &uid)
void setImages(std::vector< ImagePtr > images)
virtual void addRepActorsToViewRenderer(ViewPtr view)
void setTool(ToolPtr tool)
void addPlane(PLANE_TYPE plane, PatientModelServicePtr dataManager)
static Texture3DSlicerProxyPtr New(SharedOpenGLContextPtr context)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr