NorMIT-nav  18.04
An IGT application
cxMeshPropertyData.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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #include "cxMeshPropertyData.h"
12 
13 #include <QDomDocument>
14 #include "cxTypeConversions.h"
15 #include "cxLogger.h"
16 #include "vtkProperty.h"
17 
18 namespace cx
19 {
20 
22 {
23  this->initialize();
24 }
25 
26 void MeshPropertyData::initialize()
27 {
28  //-------------------------------------------------------------------------
29  mColor = ColorProperty::initialize("Color", "",
30  "Mesh color",
31  QColor("red"));
32  this->addProperty(mColor);
33 
34  //-------------------------------------------------------------------------
35  mUseColorFromPolydataScalars = BoolProperty::initialize( "colorFromPolydataScalars", "Color from polydata scalars",
36  "If your polydata has a scalar array with color data in you can use that to color the mesh.",
37  false);
38  this->addProperty(mUseColorFromPolydataScalars);
39  //-------------------------------------------------------------------------
40  mVisSize = DoubleProperty::initialize("visSize", "Point size",
41  "Visualized size of points, glyphs etc.",
42  2, DoubleRange(1, 20, 1), 0);
43  mVisSize->setGuiRepresentation(DoublePropertyBase::grSLIDER);
44  this->addProperty(mVisSize);
45  //-------------------------------------------------------------------------
46  mBackfaceCulling = BoolProperty::initialize("backfaceCulling", "Backface culling",
47  "Set backface culling on. This makes transparent meshes work, "
48  "but only draws outside mesh walls "
49  "(eg. navigating inside meshes will not work).",
50  false);
51  this->addProperty(mBackfaceCulling);
52  //-------------------------------------------------------------------------
53  mFrontfaceCulling = BoolProperty::initialize("frontfaceCulling", "Frontface culling",
54  "Set frontface culling on. Can be used to make transparent "
55  "meshes work from inside the meshes.",
56  false);
57  this->addProperty(mFrontfaceCulling);
58  //-------------------------------------------------------------------------
59  mRepresentation = StringProperty::initialize("representation", "Representation",
60  "How to represent model visually",
61  QString::number(VTK_SURFACE),
62  QStringList()
63  << QString::number(VTK_SURFACE)
64  << QString::number(VTK_WIREFRAME)
65  << QString::number(VTK_POINTS));
66  std::map<QString,QString> representationNames;
67  representationNames[QString::number(VTK_SURFACE)] = "Surface";
68  representationNames[QString::number(VTK_WIREFRAME)] = "Wireframe";
69  representationNames[QString::number(VTK_POINTS)] = "Points";
70  mRepresentation->setDisplayNames(representationNames);
71  this->addProperty(mRepresentation);
72  //-------------------------------------------------------------------------
73  mEdgeVisibility = BoolProperty::initialize("edgeVisibility", "Show Edges",
74  "Show model edges",
75  false);
76  this->addProperty(mEdgeVisibility);
77  //-------------------------------------------------------------------------
78  mEdgeColor = ColorProperty::initialize("edgeColor", "Edge color",
79  "Edge color, used when edges are visible.",
80  QColor("green"));
81  this->addProperty(mEdgeColor);
82  //-------------------------------------------------------------------------
83  mAmbient = DoubleProperty::initialize("ambient", "Ambient",
84  "Ambient color coefficient",
85  0.2, DoubleRange(0, 1, 0.05), 2);
86  mAmbient->setGuiRepresentation(DoublePropertyBase::grSLIDER);
87  this->addProperty(mAmbient);
88  //-------------------------------------------------------------------------
89  mDiffuse = DoubleProperty::initialize("diffuse", "Diffuse",
90  "Diffuse color coefficient",
91  0.9, DoubleRange(0, 1, 0.05), 2);
92  mDiffuse->setGuiRepresentation(DoublePropertyBase::grSLIDER);
93  this->addProperty(mDiffuse);
94  //-------------------------------------------------------------------------
95  mSpecular = DoubleProperty::initialize("specular", "Specular",
96  "Specular color coefficient",
97  0.3, DoubleRange(0, 1, 0.05), 2);
98  mSpecular->setGuiRepresentation(DoublePropertyBase::grSLIDER);
99  this->addProperty(mSpecular);
100  //-------------------------------------------------------------------------
101  mSpecularPower = DoubleProperty::initialize("specularPower", "Specular Power",
102  "Specular color power",
103  15, DoubleRange(1, 30, 1), 0);
104  mSpecularPower->setGuiRepresentation(DoublePropertyBase::grSLIDER);
105  this->addProperty(mSpecularPower);
106  //-------------------------------------------------------------------------
107 }
108 
109 void MeshPropertyData::addProperty(PropertyPtr property)
110 {
111  mProperties.push_back(property);
112  connect(property.get(), &Property::changed, this, &MeshPropertyData::changed);
113 }
114 
115 void MeshPropertyData::addXml(QDomNode &dataNode)
116 {
117  for (unsigned i=0; i<mProperties.size(); ++i)
118  {
119  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
120  item.writeVariant(mProperties[i]->getValueAsVariant());
121  }
122 }
123 
124 void MeshPropertyData::parseXml(QDomNode dataNode)
125 {
126  for (unsigned i=0; i<mProperties.size(); ++i)
127  {
128  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
129  QVariant orgval = mProperties[i]->getValueAsVariant();
130  mProperties[i]->setValueFromVariant(item.readVariant(orgval));
131  }
132 }
133 
134 } // namespace cx
BoolPropertyBasePtr mUseColorFromPolydataScalars
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
DoublePropertyPtr mVisSize
void writeVariant(const QVariant &val)
void parseXml(QDomNode dataNode)
BoolPropertyPtr mFrontfaceCulling
DoublePropertyPtr mAmbient
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
DoublePropertyPtr mSpecularPower
DoublePropertyPtr mDiffuse
Helper class for storing one string value in an xml document.
StringPropertyPtr mRepresentation
boost::shared_ptr< class Property > PropertyPtr
BoolPropertyPtr mBackfaceCulling
void addXml(QDomNode &dataNode)
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
std::vector< PropertyPtr > mProperties
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
ColorPropertyPtr mEdgeColor
static ColorPropertyPtr initialize(const QString &uid, QString name, QString help, QColor value, QDomNode root=QDomNode())
BoolPropertyPtr mEdgeVisibility
DoublePropertyPtr mSpecular
ColorPropertyPtr mColor
Namespace for all CustusX production code.