CustusX  22.04-rc5
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  mLineWidth = DoubleProperty::initialize("lineWidth", "Line width",
47  "Width of line.",
48  1, DoubleRange(1, 10, 1), 0);
49  mLineWidth->setGuiRepresentation(DoublePropertyBase::grSLIDER);
50  this->addProperty(mLineWidth);
51  //-------------------------------------------------------------------------
52  mBackfaceCulling = BoolProperty::initialize("backfaceCulling", "Backface culling",
53  "Set backface culling on. This makes transparent meshes work, "
54  "but only draws outside mesh walls "
55  "(eg. navigating inside meshes will not work).",
56  false);
57  this->addProperty(mBackfaceCulling);
58  //-------------------------------------------------------------------------
59  mFrontfaceCulling = BoolProperty::initialize("frontfaceCulling", "Frontface culling",
60  "Set frontface culling on. Can be used to make transparent "
61  "meshes work from inside the meshes.",
62  false);
63  this->addProperty(mFrontfaceCulling);
64  //-------------------------------------------------------------------------
65  mRepresentation = StringProperty::initialize("representation", "Representation",
66  "How to represent model visually",
67  QString::number(VTK_SURFACE),
68  QStringList()
69  << QString::number(VTK_SURFACE)
70  << QString::number(VTK_WIREFRAME)
71  << QString::number(VTK_POINTS));
72  std::map<QString,QString> representationNames;
73  representationNames[QString::number(VTK_SURFACE)] = "Surface";
74  representationNames[QString::number(VTK_WIREFRAME)] = "Wireframe";
75  representationNames[QString::number(VTK_POINTS)] = "Points";
76  mRepresentation->setDisplayNames(representationNames);
77  this->addProperty(mRepresentation);
78  //-------------------------------------------------------------------------
79  mEdgeVisibility = BoolProperty::initialize("edgeVisibility", "Show Edges",
80  "Show model edges",
81  false);
82  this->addProperty(mEdgeVisibility);
83  //-------------------------------------------------------------------------
84  mEdgeColor = ColorProperty::initialize("edgeColor", "Edge color",
85  "Edge color, used when edges are visible.",
86  QColor("green"));
87  this->addProperty(mEdgeColor);
88  //-------------------------------------------------------------------------
89  mAmbient = DoubleProperty::initialize("ambient", "Ambient",
90  "Ambient color coefficient",
91  0.2, DoubleRange(0, 1, 0.05), 2);
92  mAmbient->setGuiRepresentation(DoublePropertyBase::grSLIDER);
93  this->addProperty(mAmbient);
94  //-------------------------------------------------------------------------
95  mDiffuse = DoubleProperty::initialize("diffuse", "Diffuse",
96  "Diffuse color coefficient",
97  0.9, DoubleRange(0, 1, 0.05), 2);
98  mDiffuse->setGuiRepresentation(DoublePropertyBase::grSLIDER);
99  this->addProperty(mDiffuse);
100  //-------------------------------------------------------------------------
101  mSpecular = DoubleProperty::initialize("specular", "Specular",
102  "Specular color coefficient",
103  0.3, DoubleRange(0, 1, 0.05), 2);
104  mSpecular->setGuiRepresentation(DoublePropertyBase::grSLIDER);
105  this->addProperty(mSpecular);
106  //-------------------------------------------------------------------------
107  mSpecularPower = DoubleProperty::initialize("specularPower", "Specular Power",
108  "Specular color power",
109  15, DoubleRange(1, 30, 1), 0);
110  mSpecularPower->setGuiRepresentation(DoublePropertyBase::grSLIDER);
111  this->addProperty(mSpecularPower);
112  //-------------------------------------------------------------------------
113 }
114 
115 void MeshPropertyData::addProperty(PropertyPtr property)
116 {
117  mProperties.push_back(property);
118  connect(property.get(), &Property::changed, this, &MeshPropertyData::changed);
119 }
120 
121 void MeshPropertyData::addXml(QDomNode &dataNode)
122 {
123  for (unsigned i=0; i<mProperties.size(); ++i)
124  {
125  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
126  item.writeVariant(mProperties[i]->getValueAsVariant());
127  }
128 }
129 
130 void MeshPropertyData::parseXml(QDomNode dataNode)
131 {
132  for (unsigned i=0; i<mProperties.size(); ++i)
133  {
134  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
135  QVariant orgval = mProperties[i]->getValueAsVariant();
136  mProperties[i]->setValueFromVariant(item.readVariant(orgval));
137  }
138 }
139 
140 } // 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 mLineWidth
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.