CustusX  15.4.0-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxGeometricRep.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 "cxGeometricRep.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 "cxMesh.h"
44 #include "cxView.h"
45 
46 #include "cxTypeConversions.h"
47 
48 namespace cx
49 {
50 
52  RepImpl()
53 {
54  mMapper = vtkPolyDataMapperPtr::New();
55  mProperty = vtkPropertyPtr::New();
56  mActor = vtkActorPtr::New();
57  mActor->SetMapper(mMapper);
58  mActor->SetProperty(mProperty);
59 
60  mProperty->SetPointSize(2);
61 }
63 {
64 }
66 {
67  return wrap_new(new GeometricRep(), uid);
68 }
69 
71 {
72  view->getRenderer()->AddActor(mActor);
73 }
74 
76 {
77  view->getRenderer()->RemoveActor(mActor);
78 }
79 
81 {
82  if (mesh == mMesh)
83  return;
84  if (mMesh)
85  {
86  disconnect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
87  disconnect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
88  }
89  mMesh = mesh;
90  if (mMesh)
91  {
92  connect(mMesh.get(), SIGNAL(meshChanged()), this, SLOT(meshChangedSlot()));
93  connect(mMesh.get(), SIGNAL(transformChanged()), this, SLOT(transformChangedSlot()));
94  this->meshChangedSlot();
95  this->transformChangedSlot();
96  }
97 }
98 
100 {
101  return mMesh;
102 }
104 {
105  return (mMesh == mesh);
106 }
107 
108 void GeometricRep::meshChangedSlot()
109 {
110 // std::cout << "GeometricRep::meshChangedSlot()" << std::endl;
111 // mMesh->connectToRep(mSelf);
112 
113  mMapper->SetInputData(mMesh->getVtkPolyData());
114  mMapper->ScalarVisibilityOff();//Don't use the LUT from the VtkPolyData
115 
116  //Set mesh color
117  mActor->GetProperty()->SetColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
118  //Set mesh opacity
119  mActor->GetProperty()->SetOpacity(mMesh->getColor().alphaF());
120 
121  if (mMesh->getIsWireframe())
122  mActor->GetProperty()->SetRepresentationToWireframe();
123  else
124  mActor->GetProperty()->SetRepresentationToSurface();
125 
126  //Set backface and frontface culling
127  mActor->GetProperty()->SetBackfaceCulling(mMesh->getBackfaceCulling());
128  mActor->GetProperty()->SetFrontfaceCulling(mMesh->getFrontfaceCulling());
129 }
130 
133 void GeometricRep::transformChangedSlot()
134 {
135  if (!mMesh)
136  {
137  return;
138  }
139 
140  mActor->SetUserMatrix(mMesh->get_rMd().getVtkMatrix());
141 }
142 
143 //---------------------------------------------------------
144 }
145 // namespace cx
146 //---------------------------------------------------------
void setMesh(MeshPtr mesh)
sets this reps mesh
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
boost::shared_ptr< class View > ViewPtr
bool hasMesh(MeshPtr mesh) const
checks if this rep has the give mesh
MeshPtr getMesh()
gives this reps mesh
virtual void addRepActorsToViewRenderer(ViewPtr view)
vtkPropertyPtr mProperty
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
static GeometricRepPtr New(const QString &uid="")
Default implementation of Rep.
Definition: cxRepImpl.h:63
vtkActorPtr mActor
vtkPolyDataMapperPtr mMapper
boost::shared_ptr< class Mesh > MeshPtr
virtual ~GeometricRep()
boost::shared_ptr< class GeometricRep > GeometricRepPtr