CustusX  16.5.0-rc9
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 <vtkPointData.h>
38 #include <vtkProperty.h>
39 #include <vtkActor.h>
40 #include <vtkRenderer.h>
41 #include <vtkMatrix4x4.h>
42 #include <vtkArrowSource.h>
43 #include <vtkPlane.h>
44 
45 #include "cxMesh.h"
46 #include "cxView.h"
47 
48 #include "cxTypeConversions.h"
49 
50 namespace cx
51 {
52 
54  RepImpl()
55 {
58 
59 }
61 {
62 }
64 {
65  return wrap_new(new GeometricRep(), uid);
66 }
67 
69 {
70  mGraphicalPolyDataPtr->setRenderer(view->getRenderer());
71  mGraphicalGlyph3DDataPtr->setRenderer(view->getRenderer());
72 }
73 
75 {
76  mGraphicalPolyDataPtr->setRenderer(NULL);
77  mGraphicalGlyph3DDataPtr->setRenderer(NULL);
78 }
79 
81 {
82  if (mesh == mMesh)
83  return;
84  if (mMesh)
85  {
86  disconnect(mMesh.get(), &Mesh::meshChanged, this, &GeometricRep::meshChangedSlot);
87  disconnect(mMesh.get(), &Data::transformChanged, this, &GeometricRep::transformChangedSlot);
88  disconnect(mMesh.get(), &Data::clipPlanesChanged, this, &GeometricRep::clipPlanesChangedSlot);
89  }
90  mMesh = mesh;
91  if (mMesh)
92  {
93  connect(mMesh.get(), &Mesh::meshChanged, this, &GeometricRep::meshChangedSlot);
94  connect(mMesh.get(), &Data::transformChanged, this, &GeometricRep::transformChangedSlot);
95  connect(mMesh.get(), &Data::clipPlanesChanged, this, &GeometricRep::clipPlanesChangedSlot);
96  this->meshChangedSlot();
97  this->transformChangedSlot();
98  this->clipPlanesChangedSlot();
99  }
100 }
101 
102 //Copied from ImageMapperMonitor (used by VolumetricRep)
103 void GeometricRep::clipPlanesChangedSlot()
104 {
105  this->clearClipping();
106 
107  if (!mMesh)
108  return;
109 
110  std::vector<vtkPlanePtr> mPlanes;
111  mPlanes = mMesh->getAllClipPlanes();
112  for (unsigned i=0; i<mPlanes.size(); ++i)
113  {
114  mGraphicalPolyDataPtr->getMapper()->AddClippingPlane(mPlanes[i]);
115  }
116 }
117 
119 {
120  if (!mMesh)
121  return;
122 
123  mGraphicalPolyDataPtr->getMapper()->RemoveAllClippingPlanes();
124 }
125 
127 {
128  return mMesh;
129 }
131 {
132  return (mMesh == mesh);
133 }
134 
135 void GeometricRep::meshChangedSlot()
136 {
137  // mMapper->SetLookupTable(); //mMesh.getLookupTable()
138 
139  mGraphicalGlyph3DDataPtr->setVisibility(mMesh->showGlyph());
140  if(mMesh->showGlyph())
141  {
142  mGraphicalGlyph3DDataPtr->setData(mMesh->getVtkPolyData());
143  mGraphicalGlyph3DDataPtr->setOrientationArray(mMesh->getOrientationArray());
144  mGraphicalGlyph3DDataPtr->setColorArray(mMesh->getColorArray());
145  mGraphicalGlyph3DDataPtr->setColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
146  mGraphicalGlyph3DDataPtr->setLUT(mMesh->getGlyphLUT());
147  mGraphicalGlyph3DDataPtr->setScaleFactor(mMesh->getVisSize());
148  }
149 
150  mGraphicalPolyDataPtr->setData(mMesh->getVtkPolyData());
151  mGraphicalPolyDataPtr->setIsWireFrame(mMesh->getIsWireframe());
152  mGraphicalPolyDataPtr->setPointSize(mMesh->getVisSize());
153  mGraphicalPolyDataPtr->setScalarVisibility(false);//Don't use the LUT from the VtkPolyData
154  //Set mesh color
155  mGraphicalPolyDataPtr->setColor(mMesh->getColor().redF(), mMesh->getColor().greenF(), mMesh->getColor().blueF());
156  //Set mesh opacity
157  mGraphicalPolyDataPtr->setOpacity(mMesh->getColor().alphaF());
158  mGraphicalPolyDataPtr->setRepresentation();
159  //Set backface and frontface culling
160  mGraphicalPolyDataPtr->setBackfaceCulling(mMesh->getBackfaceCulling());
161  mGraphicalPolyDataPtr->setFrontfaceCulling(mMesh->getFrontfaceCulling());
162 }
163 
166 void GeometricRep::transformChangedSlot()
167 {
168  if (!mMesh)
169  {
170  return;
171  }
172  mGraphicalPolyDataPtr->setUserMatrix(mMesh->get_rMd().getVtkMatrix());
173  mGraphicalGlyph3DDataPtr->setUserMatrix(mMesh->get_rMd().getVtkMatrix());
174 }
175 
176 
177 
178 //---------------------------------------------------------
179 }
180 // namespace cx
181 //---------------------------------------------------------
GraphicalPolyData3DPtr mGraphicalPolyDataPtr
void transformChanged()
emitted when transform is changed
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
void clipPlanesChanged()
bool hasMesh(MeshPtr mesh) const
checks if this rep has the give mesh
MeshPtr getMesh()
gives this reps mesh
Helper for rendering a a polydata in 3D.
virtual void addRepActorsToViewRenderer(ViewPtr view)
virtual void removeRepActorsFromViewRenderer(ViewPtr view)
void meshChanged()
static GeometricRepPtr New(const QString &uid="")
Default implementation of Rep.
Definition: cxRepImpl.h:63
Helper for rendering a a glyph in 3D.
boost::shared_ptr< class Mesh > MeshPtr
virtual ~GeometricRep()
GraphicalGlyph3DDataPtr mGraphicalGlyph3DDataPtr
boost::shared_ptr< class GeometricRep > GeometricRepPtr