Fraxinus  17.12
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) 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  //-------------------------------------------------------------------------
56  mUseColorFromPolydataScalars = BoolProperty::initialize( "colorFromPolydataScalars", "Color from polydata scalars",
57  "If your polydata has a scalar array with color data in you can use that to color the mesh.",
58  false);
59  this->addProperty(mUseColorFromPolydataScalars);
60  //-------------------------------------------------------------------------
61  mVisSize = DoubleProperty::initialize("visSize", "Point size",
62  "Visualized size of points, glyphs etc.",
63  2, DoubleRange(1, 20, 1), 0);
64  mVisSize->setGuiRepresentation(DoublePropertyBase::grSLIDER);
65  this->addProperty(mVisSize);
66  //-------------------------------------------------------------------------
67  mBackfaceCulling = BoolProperty::initialize("backfaceCulling", "Backface culling",
68  "Set backface culling on. This makes transparent meshes work, "
69  "but only draws outside mesh walls "
70  "(eg. navigating inside meshes will not work).",
71  false);
72  this->addProperty(mBackfaceCulling);
73  //-------------------------------------------------------------------------
74  mFrontfaceCulling = BoolProperty::initialize("frontfaceCulling", "Frontface culling",
75  "Set frontface culling on. Can be used to make transparent "
76  "meshes work from inside the meshes.",
77  false);
78  this->addProperty(mFrontfaceCulling);
79  //-------------------------------------------------------------------------
80  mRepresentation = StringProperty::initialize("representation", "Representation",
81  "How to represent model visually",
82  QString::number(VTK_SURFACE),
83  QStringList()
84  << QString::number(VTK_SURFACE)
85  << QString::number(VTK_WIREFRAME)
86  << QString::number(VTK_POINTS));
87  std::map<QString,QString> representationNames;
88  representationNames[QString::number(VTK_SURFACE)] = "Surface";
89  representationNames[QString::number(VTK_WIREFRAME)] = "Wireframe";
90  representationNames[QString::number(VTK_POINTS)] = "Points";
91  mRepresentation->setDisplayNames(representationNames);
92  this->addProperty(mRepresentation);
93  //-------------------------------------------------------------------------
94  mEdgeVisibility = BoolProperty::initialize("edgeVisibility", "Show Edges",
95  "Show model edges",
96  false);
97  this->addProperty(mEdgeVisibility);
98  //-------------------------------------------------------------------------
99  mEdgeColor = ColorProperty::initialize("edgeColor", "Edge color",
100  "Edge color, used when edges are visible.",
101  QColor("green"));
102  this->addProperty(mEdgeColor);
103  //-------------------------------------------------------------------------
104  mAmbient = DoubleProperty::initialize("ambient", "Ambient",
105  "Ambient color coefficient",
106  0.2, DoubleRange(0, 1, 0.05), 2);
107  mAmbient->setGuiRepresentation(DoublePropertyBase::grSLIDER);
108  this->addProperty(mAmbient);
109  //-------------------------------------------------------------------------
110  mDiffuse = DoubleProperty::initialize("diffuse", "Diffuse",
111  "Diffuse color coefficient",
112  0.9, DoubleRange(0, 1, 0.05), 2);
113  mDiffuse->setGuiRepresentation(DoublePropertyBase::grSLIDER);
114  this->addProperty(mDiffuse);
115  //-------------------------------------------------------------------------
116  mSpecular = DoubleProperty::initialize("specular", "Specular",
117  "Specular color coefficient",
118  0.3, DoubleRange(0, 1, 0.05), 2);
119  mSpecular->setGuiRepresentation(DoublePropertyBase::grSLIDER);
120  this->addProperty(mSpecular);
121  //-------------------------------------------------------------------------
122  mSpecularPower = DoubleProperty::initialize("specularPower", "Specular Power",
123  "Specular color power",
124  15, DoubleRange(1, 30, 1), 0);
125  mSpecularPower->setGuiRepresentation(DoublePropertyBase::grSLIDER);
126  this->addProperty(mSpecularPower);
127  //-------------------------------------------------------------------------
128 }
129 
130 void MeshPropertyData::addProperty(PropertyPtr property)
131 {
132  mProperties.push_back(property);
133  connect(property.get(), &Property::changed, this, &MeshPropertyData::changed);
134 }
135 
136 void MeshPropertyData::addXml(QDomNode &dataNode)
137 {
138  for (unsigned i=0; i<mProperties.size(); ++i)
139  {
140  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
141  item.writeVariant(mProperties[i]->getValueAsVariant());
142  }
143 }
144 
145 void MeshPropertyData::parseXml(QDomNode dataNode)
146 {
147  for (unsigned i=0; i<mProperties.size(); ++i)
148  {
149  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
150  QVariant orgval = mProperties[i]->getValueAsVariant();
151  mProperties[i]->setValueFromVariant(item.readVariant(orgval));
152  }
153 }
154 
155 } // 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: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
Namespace for all CustusX production code.