Fraxinus  17.12-rc4
An IGT application
cxMeshTextureData.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 "cxMeshTextureData.h"
35 #include "cxDoubleProperty.h"
36 #include "cxBoolProperty.h"
37 
38 namespace cx
39 {
41  : mPatientModelService(patientModelService)
42  , mCylinderText("Cylinder")
43  , mPlaneText("Plane")
44  , mSphereText("Sphere")
45 {
46  this->initialize();
47 }
48 
49 void MeshTextureData::addXml(QDomNode &dataNode)
50 {
51  for (unsigned i=0; i<mProperties.size(); ++i)
52  {
53  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
54  item.writeVariant(mProperties[i]->getValueAsVariant());
55  }
56 }
57 
58 void MeshTextureData::parseXml(QDomNode &dataNode)
59 {
60  for (unsigned i=0; i<mProperties.size(); ++i)
61  {
62  XmlOptionItem item(mProperties[i]->getUid(), dataNode.toElement());
63  QVariant orgval = mProperties[i]->getValueAsVariant();
64  mProperties[i]->setValueFromVariant(item.readVariant(orgval));
65  }
66 }
67 
68 void MeshTextureData::addProperty(PropertyPtr property)
69 {
70  mProperties.push_back(property);
71  connect(property.get(), &Property::changed, this, &MeshTextureData::changed);
72 }
73 
74 void MeshTextureData::initialize()
75 {
76  mTextureImage = StringPropertySelectImage::New(mPatientModelService);
77  mTextureImage->setValueName("Texture image");
78  mTextureImage->setHelp("Select an imported 2D image to use as texture.");
79  mTextureImage->setOnly2DImagesFilter(true);
80  this->addProperty(mTextureImage);
81 
82  mTextureShape = StringProperty::initialize("texture_type", "Texture shape",
83  "The texture is applied in predefined geometric shapes. Select the shape which gives the best fit to your mesh.",
84  "Cylinder",
85  QStringList()
86  << this->getCylinderText()
87  << this->getPlaneText()
88  << this->getSphereText());
89  this->addProperty(mTextureShape);
90 
91  mScaleX = DoubleProperty::initialize("texture_scale_X", "Scale X", "How many times to draw the image along the X axis.", 1, DoubleRange(1,100000,1), 0);
92  this->addProperty(mScaleX);
93 
94  mScaleY = DoubleProperty::initialize("texture_scale_Y", "Scale Y", "How many times to draw the image along the Y axis.", 1, DoubleRange(1,100000,1), 0);
95  this->addProperty(mScaleY);
96 
97  mPositionX = DoubleProperty::initialize("texture_position_X", "Position X", "Where to start drawing the image along the X axis.", 0, DoubleRange(-100000,100000,0.01), 2);
98  this->addProperty(mPositionX);
99 
100  mPositionY = DoubleProperty::initialize("texture_position_Y", "Position Y", "Where to start drawing the image along the Y axis.", 0, DoubleRange(-100000,100000,0.01), 2);
101  this->addProperty(mPositionY);
102 
103  mRepeat = BoolProperty::initialize("repeat", "Repeat", "Repeat texture over surface", true);
104  this->addProperty(mRepeat);
105 }
106 
108 {
109  return mSphereText;
110 }
111 
113 {
114  return mPlaneText;
115 }
116 
118 {
119  return mCylinderText;
120 }
121 
123 {
124  return mPositionY;
125 }
126 
128 {
129  return mPositionX;
130 }
131 
133 {
134  return mRepeat;
135 }
136 
137 std::vector<PropertyPtr> MeshTextureData::getProperties() const
138 {
139  return mProperties;
140 }
141 
143 {
144  return mScaleY;
145 }
146 
148 {
149  return mScaleX;
150 }
151 
153 {
154  return mTextureImage;
155 }
156 
158 {
159  return mTextureShape;
160 }
161 
162 } // namespace cx
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
void writeVariant(const QVariant &val)
void parseXml(QDomNode &dataNode)
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:53
DoublePropertyPtr getPositionY() const
QString getPlaneText() const
DoublePropertyPtr getScaleX() const
StringPropertySelectImagePtr getTextureImage() const
Helper class for storing one string value in an xml document.
DoublePropertyPtr getPositionX() const
boost::shared_ptr< class StringProperty > StringPropertyPtr
QString getSphereText() const
boost::shared_ptr< class Property > PropertyPtr
BoolPropertyPtr getRepeat() const
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class StringPropertySelectImage > StringPropertySelectImagePtr
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())
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
MeshTextureData(PatientModelServicePtr patientModelService)
std::vector< PropertyPtr > getProperties() const
DoublePropertyPtr getScaleY() const
QString getCylinderText() const
void addXml(QDomNode &dataNode)
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
static StringPropertySelectImagePtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class BoolProperty > BoolPropertyPtr
StringPropertyPtr getTextureShape() const
Namespace for all CustusX production code.