CustusX  16.12
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 #include "cxMeshPropertyData.h"
33 
34 #include <QDomDocument>
35 #include "cxTypeConversions.h"
36 #include "cxLogger.h"
37 #include "vtkProperty.h"
38 
39 namespace cx
40 {
41 
43 {
44  this->initialize();
45 }
46 
47 void MeshPropertyData::initialize()
48 {
49  //-------------------------------------------------------------------------
50  mColor = ColorProperty::initialize("Color", "",
51  "Mesh color",
52  QColor("red"));
53  this->addProperty(mColor);
54  //-------------------------------------------------------------------------
55  mVisSize = DoubleProperty::initialize("visSize", "Point size",
56  "Visualized size of points, glyphs etc.",
57  2, DoubleRange(1, 20, 1), 0);
58  mVisSize->setGuiRepresentation(DoublePropertyBase::grSLIDER);
59  this->addProperty(mVisSize);
60  //-------------------------------------------------------------------------
61  mBackfaceCulling = BoolProperty::initialize("backfaceCulling", "Backface culling",
62  "Set backface culling on. This makes transparent meshes work, "
63  "but only draws outside mesh walls "
64  "(eg. navigating inside meshes will not work).",
65  true);
66  this->addProperty(mBackfaceCulling);
67  //-------------------------------------------------------------------------
68  mFrontfaceCulling = BoolProperty::initialize("frontfaceCulling", "Frontface culling",
69  "Set frontface culling on. Can be used to make transparent "
70  "meshes work from inside the meshes.",
71  true);
72  this->addProperty(mFrontfaceCulling);
73  //-------------------------------------------------------------------------
74  mRepresentation = StringProperty::initialize("representation", "Representation",
75  "How to represent model visually",
76  QString::number(VTK_SURFACE),
77  QStringList()
78  << QString::number(VTK_SURFACE)
79  << QString::number(VTK_WIREFRAME)
80  << QString::number(VTK_POINTS));
81  std::map<QString,QString> representationNames;
82  representationNames[QString::number(VTK_SURFACE)] = "Surface";
83  representationNames[QString::number(VTK_WIREFRAME)] = "Wireframe";
84  representationNames[QString::number(VTK_POINTS)] = "Points";
85  mRepresentation->setDisplayNames(representationNames);
86  this->addProperty(mRepresentation);
87  //-------------------------------------------------------------------------
88  mEdgeVisibility = BoolProperty::initialize("edgeVisibility", "Show Edges",
89  "Show model edges",
90  false);
91  this->addProperty(mEdgeVisibility);
92  //-------------------------------------------------------------------------
93  mEdgeColor = ColorProperty::initialize("edgeColor", "Edge color",
94  "Edge color, used when edges are visible.",
95  QColor("green"));
96  this->addProperty(mEdgeColor);
97  //-------------------------------------------------------------------------
98  mAmbient = DoubleProperty::initialize("ambient", "Ambient",
99  "Ambient color coefficient",
100  0.2, DoubleRange(0, 1, 0.05), 2);
101  mAmbient->setGuiRepresentation(DoublePropertyBase::grSLIDER);
102  this->addProperty(mAmbient);
103  //-------------------------------------------------------------------------
104  mDiffuse = DoubleProperty::initialize("diffuse", "Diffuse",
105  "Diffuse color coefficient",
106  0.9, DoubleRange(0, 1, 0.05), 2);
107  mDiffuse->setGuiRepresentation(DoublePropertyBase::grSLIDER);
108  this->addProperty(mDiffuse);
109  //-------------------------------------------------------------------------
110  mSpecular = DoubleProperty::initialize("specular", "Specular",
111  "Specular color coefficient",
112  0.3, DoubleRange(0, 1, 0.05), 2);
113  mSpecular->setGuiRepresentation(DoublePropertyBase::grSLIDER);
114  this->addProperty(mSpecular);
115  //-------------------------------------------------------------------------
116  mSpecularPower = DoubleProperty::initialize("specularPower", "Specular Power",
117  "Specular color power",
118  15, DoubleRange(1, 30, 1), 0);
119  mSpecularPower->setGuiRepresentation(DoublePropertyBase::grSLIDER);
120  this->addProperty(mSpecularPower);
121  //-------------------------------------------------------------------------
122 }
123 
124 void MeshPropertyData::addProperty(PropertyPtr property)
125 {
126  mProperties.push_back(property);
127  connect(property.get(), &Property::changed, this, &MeshPropertyData::changed);
128 }
129 
130 void MeshPropertyData::addXml(QDomNode &dataNode)
131 {
132  for (unsigned i=0; i<mProperties.size(); ++i)
133  {
134  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
135  item.writeVariant(mProperties[i]->getValueAsVariant());
136  }
137 }
138 
139 void MeshPropertyData::parseXml(QDomNode dataNode)
140 {
141  for (unsigned i=0; i<mProperties.size(); ++i)
142  {
143  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
144  QVariant orgval = mProperties[i]->getValueAsVariant();
145  mProperties[i]->setValueFromVariant(item.readVariant(orgval));
146  }
147 }
148 
149 } // namespace cx
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:53
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