Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxGeometricRep2D.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 "cxGeometricRep2D.h"
35 
36 #include <vtkPolyData.h>
37 #include <vtkPolyDataMapper.h>
38 #include <vtkProperty.h>
39 #include <vtkActor.h>
40 #include <vtkRenderer.h>
41 #include <vtkMatrix4x4.h>
42 
43 #include <vtkPolyDataNormals.h>
44 #include <vtkPlane.h>
45 #include <vtkStripper.h>
46 #include <vtkCellArray.h>
47 
48 #include "cxMesh.h"
49 #include "cxView.h"
50 
51 #include "cxSliceProxy.h"
52 #include "cxTypeConversions.h"
53 
54 namespace cx
55 {
56 
58  RepImpl()
59 {
60  mMapper = vtkPolyDataMapperPtr::New();
61  mProperty = vtkPropertyPtr::New();
62  mActor = vtkActorPtr::New();
63  mActor->SetMapper(mMapper);
64  mActor->SetProperty(mProperty);
65 }
66 
68 {
69 }
70 
72 {
73  return wrap_new(new GeometricRep2D(), uid);
74 }
75 
77 {
78  view->getRenderer()->AddActor(mActor);
79 }
80 
82 {
83  view->getRenderer()->RemoveActor(mActor);
84 }
85 
87 {
88  if (mesh == mMesh)
89  return;
90  if (mMesh)
91  {
92  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
93  disconnect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
94  }
95  mMesh = mesh;
96  if (mMesh)
97  {
98  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
99  connect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
100  this->meshChangedSlot();
101  this->transformChangedSlot();
102  }
103 }
104 
106 {
107  return mMesh;
108 }
110 {
111  return (mMesh == mesh);
112 }
113 
115 {
116  if (mSlicer)
117  {
118  disconnect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
119  }
120  mSlicer = slicer;
121  if (mSlicer)
122  {
123  connect(mSlicer.get(), SIGNAL(transformChanged(Transform3D)), this, SLOT(transformChangedSlot()));
124  this->transformChangedSlot();
125  }
126 }
127 
128 void GeometricRep2D::meshChangedSlot()
129 {
130  mMapper->SetInputData(mMesh->getVtkPolyData()); // original - show-all method
131  mMapper->ScalarVisibilityOff();//Don't use the LUT from the VtkPolyData
132  //mNormals->SetInputConnection(mMesh->getVtkPolyData()->Get);
133 
134  //Set mesh color
135  mActor->GetProperty()->SetColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
136  //Set mesh opacity
137  mActor->GetProperty()->SetOpacity(mMesh->getColor().alphaF());
138 
139  // Turn lightning off - we dont want 3D effects but a clear view of the slice
140  mActor->GetProperty()->LightingOff();
141 }
142 
145 void GeometricRep2D::transformChangedSlot()
146 {
147  if (!mSlicer || !mMesh)
148  return;
149 
150  Transform3D rMs = mSlicer->get_sMr().inv();
151  Transform3D dMr = mMesh->get_rMd().inv();
152  Transform3D dMs = dMr * rMs;
153 
154  mActor->SetUserMatrix(dMs.inv().getVtkMatrix());
155 }
156 
157 //---------------------------------------------------------
158 } // namespace cx
159 //---------------------------------------------------------
160 
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class SliceProxy > SliceProxyPtr
bool hasMesh(MeshPtr mesh) const
checks if this rep has the give mesh
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
vtkPolyDataMapperPtr mMapper
MeshPtr getMesh()
gives this reps mesh
void setSliceProxy(SliceProxyPtr slicer)
boost::shared_ptr< class View > ViewPtr
virtual void addRepActorsToViewRenderer(ViewPtr view)
void setMesh(MeshPtr mesh)
sets this reps mesh
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
Default implementation of Rep.
Definition: cxRepImpl.h:63
static GeometricRep2DPtr New(const QString &uid="")
vtkPropertyPtr mProperty
boost::shared_ptr< class Mesh > MeshPtr
SliceProxyPtr mSlicer
boost::shared_ptr< class GeometricRep2D > GeometricRep2DPtr